Ble tx improvements (#1546)

This commit is contained in:
Netro 2023-11-01 18:24:55 -04:00 committed by GitHub
parent dceb7255b0
commit b5c244a09b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 24 deletions

View File

@ -187,14 +187,14 @@ void BLETxView::start() {
// Send first or single packet.
progressbar.set_max(packet_count);
button_play.set_bitmap(&bitmap_stop);
baseband::set_btletx(channel_number, macAddress, advertisementData);
baseband::set_btletx(channel_number, macAddress, advertisementData, pduType);
transmitter_model.enable();
is_running = true;
}
} else {
// Send next packet.
baseband::set_btletx(channel_number, macAddress, advertisementData);
baseband::set_btletx(channel_number, macAddress, advertisementData, pduType);
}
if ((packet_counter % 10) == 0) {
@ -246,6 +246,7 @@ BLETxView::BLETxView(NavigationView& nav)
&label_speed,
&options_speed,
&options_channel,
&options_adv_type,
&label_packets_sent,
&text_packets_sent,
&label_mac_address,
@ -268,6 +269,10 @@ BLETxView::BLETxView(NavigationView& nav)
timer_period = i;
};
options_adv_type.on_change = [this](size_t, int32_t i) {
pduType = (PKT_TYPE)i;
};
options_speed.set_selected_index(0);
button_open.on_select = [this, &nav](Button&) {

View File

@ -104,11 +104,43 @@ class BLETxView : public View {
uint32_t packet_count{0};
uint32_t packet_counter{0};
enum PKT_TYPE {
INVALID_TYPE,
RAW,
DISCOVERY,
IBEACON,
ADV_IND,
ADV_DIRECT_IND,
ADV_NONCONN_IND,
ADV_SCAN_IND,
SCAN_REQ,
SCAN_RSP,
CONNECT_REQ,
LL_DATA,
LL_CONNECTION_UPDATE_REQ,
LL_CHANNEL_MAP_REQ,
LL_TERMINATE_IND,
LL_ENC_REQ,
LL_ENC_RSP,
LL_START_ENC_REQ,
LL_START_ENC_RSP,
LL_UNKNOWN_RSP,
LL_FEATURE_REQ,
LL_FEATURE_RSP,
LL_PAUSE_ENC_REQ,
LL_PAUSE_ENC_RSP,
LL_VERSION_IND,
LL_REJECT_IND,
NUM_PKT_TYPE
};
static constexpr uint8_t mac_address_size_str{12};
static constexpr uint8_t max_packet_size_str{62};
static constexpr uint8_t max_packet_count_str{10};
static constexpr uint32_t max_packet_count{UINT32_MAX};
PKT_TYPE pduType = {RAW};
static constexpr auto header_height = 8 * 16;
Button button_open{
@ -161,6 +193,17 @@ class BLETxView : public View {
{"Ch.38", 38},
{"Ch.39", 39}}};
OptionsField options_adv_type{
{17 * 8, 6 * 8},
14,
{{"DISCOVERY ", DISCOVERY},
{"ADV_IND", ADV_IND},
{"ADV_DIRECT", ADV_DIRECT_IND},
{"ADV_NONCONN", ADV_NONCONN_IND},
{"SCAN_REQ", SCAN_REQ},
{"SCAN_RSP", SCAN_RSP},
{"CONNECT_REQ", CONNECT_REQ}}};
Labels label_packets_sent{
{{0 * 8, 10 * 8}, "Packets Left:", Color::light_grey()}};

View File

@ -155,11 +155,12 @@ void set_btle(uint8_t channel_number) {
send_message(&message);
}
void set_btletx(uint8_t channel_number, char* macAddress, char* advertisementData) {
void set_btletx(uint8_t channel_number, char* macAddress, char* advertisementData, uint8_t pduType) {
const BTLETxConfigureMessage message{
channel_number,
macAddress,
advertisementData};
advertisementData,
pduType};
send_message(&message);
}

View File

@ -73,7 +73,7 @@ void set_fsk(const size_t deviation);
void set_aprs(const uint32_t baudrate);
void set_btle(uint8_t channel_number);
void set_btletx(uint8_t channel_number, char* macAddress, char* advertisementData);
void set_btletx(uint8_t channel_number, char* macAddress, char* advertisementData, uint8_t pduType);
void set_nrf(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word);

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
* Copyright (C) TJ Baginski
* Copyright (C) 2023 TJ Baginski
*
* This file is part of PortaPack.
*
@ -276,7 +276,7 @@ void BTLETxProcessor::fill_adv_pdu_header(PKT_INFO* pkt, int txadd, int rxadd, i
bit_out[15] = 0;
}
int BTLETxProcessor::calculate_sample_for_ADV_IND(PKT_INFO* pkt) {
int BTLETxProcessor::calculate_sample_for_ADV(PKT_INFO* pkt) {
pkt->num_info_bit = 0;
// gen preamble and access address
@ -286,7 +286,7 @@ int BTLETxProcessor::calculate_sample_for_ADV_IND(PKT_INFO* pkt) {
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit((char*)AAValue, pkt->info_bit + pkt->num_info_bit, 0, 4);
// get txadd and rxadd
int txadd = 1, rxadd = 0;
int txadd = 0, rxadd = 0;
pkt->num_info_bit = pkt->num_info_bit + 16; // 16 is header length
@ -314,7 +314,7 @@ int BTLETxProcessor::calculate_sample_from_pkt_type(PKT_INFO* pkt) {
// Todo: Handle other Enum values.
// if (packetType == ADV_IND);
if (calculate_sample_for_ADV_IND(pkt) == -1) {
if (calculate_sample_for_ADV(pkt) == -1) {
return (-1);
}
@ -376,6 +376,7 @@ void BTLETxProcessor::on_message(const Message* const message) {
void BTLETxProcessor::configure(const BTLETxConfigureMessage& message) {
channel_number = message.channel_number;
packetType = (PKT_TYPE)message.pduType;
memcpy(macAddress, message.macAddress, sizeof(macAddress));
memcpy(advertisementData, message.advertisementData, sizeof(advertisementData));
@ -386,14 +387,6 @@ void BTLETxProcessor::configure(const BTLETxConfigureMessage& message) {
// Calculates the samples based on the BLE packet data and generates IQ values into an array to be sent out.
calculate_pkt_info(&packets);
// Todo: determine if we need to copy these values to shared_memory.bb_data.data. I suspect that we might.
// I think once we add the UI level, only the generated BLE payload will be sent down. This layer will take care of PHY sample generation
// using the bits sent in by the UI level. In short, we will seperate this implementation to the UI level.
// memcpy(shared_memory.bb_data.data, (uint8_t *)packets.phy_sample, packets.num_phy_sample);
// 2 Sample buffers for each IQ data.
samples_per_bit = 8;
#ifdef new_way
// This is because each sample contains I and Q, but packet.num_phy_samples just returns the total samples.
length = (uint32_t)(packets.num_phy_sample * 2);
@ -401,10 +394,6 @@ void BTLETxProcessor::configure(const BTLETxConfigureMessage& message) {
length = (uint32_t)packets.num_phy_bit;
#endif
// 200kHz shift frequency of BLE
shift_one = 200000 * (0xFFFFFFFFULL / 4000000);
shift_zero = -shift_one;
// Starting at sample_count 0 since packets.num_phy_sample contains every sample needed to be sent out.
sample_count = 0;
progress_count = 0;

View File

@ -1,6 +1,7 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
* Copyright (C) 2023 TJ Baginski
*
* This file is part of PortaPack.
*
@ -99,7 +100,7 @@ class BTLETxProcessor : public BasebandProcessor {
int calculate_pkt_info(PKT_INFO* pkt);
int calculate_sample_from_pkt_type(PKT_INFO* pkt);
int calculate_sample_for_ADV_IND(PKT_INFO* pkt);
int calculate_sample_for_ADV(PKT_INFO* pkt);
void fill_adv_pdu_header(PKT_INFO* pkt, int txadd, int rxadd, int payload_len, char* bit_out);
void crc24_and_scramble_to_gen_phy_bit(char* crc_init_hex, PKT_INFO* pkt);
void disp_bit_in_hex(char* bit, int num_bit);

View File

@ -761,15 +761,18 @@ class BTLETxConfigureMessage : public Message {
constexpr BTLETxConfigureMessage(
const uint8_t channel_number,
char* macAddress,
char* advertisementData)
char* advertisementData,
const uint8_t pduType)
: Message{ID::BTLETxConfigure},
channel_number(channel_number),
macAddress(macAddress),
advertisementData(advertisementData) {
advertisementData(advertisementData),
pduType(pduType) {
}
const uint8_t channel_number;
char* macAddress;
char* advertisementData;
const uint8_t pduType;
};
class NRFRxConfigureMessage : public Message {

View File

@ -0,0 +1 @@
010203040506 190953445220426c7565746f6f7468204c6f7720456e65726779 1000