From b5c244a09b753ca24f5697e1f5973811fa5ab6a3 Mon Sep 17 00:00:00 2001 From: Netro <146584182+iNetro@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:24:55 -0400 Subject: [PATCH] Ble tx improvements (#1546) --- firmware/application/apps/ble_tx_app.cpp | 9 +++-- firmware/application/apps/ble_tx_app.hpp | 43 ++++++++++++++++++++++++ firmware/application/baseband_api.cpp | 5 +-- firmware/application/baseband_api.hpp | 2 +- firmware/baseband/proc_ble_tx.cpp | 21 +++--------- firmware/baseband/proc_ble_tx.hpp | 3 +- firmware/common/message.hpp | 7 ++-- sdcard/BLETX/Discovery Packet.txt | 1 + 8 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 sdcard/BLETX/Discovery Packet.txt diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index 84e3722d..11b7df0c 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -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&) { diff --git a/firmware/application/apps/ble_tx_app.hpp b/firmware/application/apps/ble_tx_app.hpp index 50caae93..674fbb2c 100644 --- a/firmware/application/apps/ble_tx_app.hpp +++ b/firmware/application/apps/ble_tx_app.hpp @@ -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()}}; diff --git a/firmware/application/baseband_api.cpp b/firmware/application/baseband_api.cpp index fc970d98..e71cb923 100644 --- a/firmware/application/baseband_api.cpp +++ b/firmware/application/baseband_api.cpp @@ -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); } diff --git a/firmware/application/baseband_api.hpp b/firmware/application/baseband_api.hpp index 846b5b80..82c80050 100644 --- a/firmware/application/baseband_api.hpp +++ b/firmware/application/baseband_api.hpp @@ -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); diff --git a/firmware/baseband/proc_ble_tx.cpp b/firmware/baseband/proc_ble_tx.cpp index a73c0842..71c77d6e 100644 --- a/firmware/baseband/proc_ble_tx.cpp +++ b/firmware/baseband/proc_ble_tx.cpp @@ -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; diff --git a/firmware/baseband/proc_ble_tx.hpp b/firmware/baseband/proc_ble_tx.hpp index e028c876..57f22abe 100644 --- a/firmware/baseband/proc_ble_tx.hpp +++ b/firmware/baseband/proc_ble_tx.hpp @@ -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); diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index 4c7ad5d0..1a321359 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -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 { diff --git a/sdcard/BLETX/Discovery Packet.txt b/sdcard/BLETX/Discovery Packet.txt new file mode 100644 index 00000000..4b6d80a3 --- /dev/null +++ b/sdcard/BLETX/Discovery Packet.txt @@ -0,0 +1 @@ +010203040506 190953445220426c7565746f6f7468204c6f7720456e65726779 1000 \ No newline at end of file