BLE Rx parsing improvements (#1566)

* Running simple state machine to better catch in between buffers. 
* Fixed buffer size 2048 was too large for a decimated before only containing 512 (2048/4 Decimation) Bytes.
* attempt at trying to minimize uncleared str buffers
This commit is contained in:
Netro 2023-11-07 12:10:18 -05:00 committed by GitHub
parent 7a87e3f3af
commit a9df9dde69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 189 additions and 164 deletions

View File

@ -201,11 +201,12 @@ void BleRecentEntryDetailView::set_entry(const BleRecentEntry& entry) {
void BleRecentEntryDetailView::launch_bletx(BleRecentEntry packetEntry) { void BleRecentEntryDetailView::launch_bletx(BleRecentEntry packetEntry) {
BLETxPacket bleTxPacket; BLETxPacket bleTxPacket;
memset(&bleTxPacket, 0, sizeof(BLETxPacket));
std::string macAddressStr = to_string_mac_address(packetEntry.packetData.macAddress, 6, true); std::string macAddressStr = to_string_mac_address(packetEntry.packetData.macAddress, 6, true);
strncpy(bleTxPacket.macAddress, macAddressStr.c_str(), 13); strncpy(bleTxPacket.macAddress, macAddressStr.c_str(), 12);
strncpy(bleTxPacket.advertisementData, packetEntry.dataString.c_str(), (packetEntry.packetData.dataLen * 2) + 1); strncpy(bleTxPacket.advertisementData, packetEntry.dataString.c_str(), packetEntry.packetData.dataLen * 2);
strncpy(bleTxPacket.packetCount, "50", 3); strncpy(bleTxPacket.packetCount, "50", 3);
bleTxPacket.packet_count = 50; bleTxPacket.packet_count = 50;

View File

@ -302,6 +302,7 @@ void BTLERxProcessor::execute(const buffer_c8_t& buffer) {
//--------------Start Parsing For Access Address---------------// //--------------Start Parsing For Access Address---------------//
if (parseState == Parse_State_Begin) {
static uint8_t demod_buf_access[SAMPLE_PER_SYMBOL][LEN_DEMOD_BUF_ACCESS]; static uint8_t demod_buf_access[SAMPLE_PER_SYMBOL][LEN_DEMOD_BUF_ACCESS];
uint32_t uint32_tmp = DEFAULT_ACCESS_ADDR; uint32_t uint32_tmp = DEFAULT_ACCESS_ADDR;
@ -378,17 +379,19 @@ void BTLERxProcessor::execute(const buffer_c8_t& buffer) {
symbols_eaten += 8 * num_demod_byte * SAMPLE_PER_SYMBOL; symbols_eaten += 8 * num_demod_byte * SAMPLE_PER_SYMBOL;
parseState = Parse_State_PDU_Header;
}
if (parseState == Parse_State_PDU_Header) {
if (symbols_eaten > (int)dst_buffer.count) { if (symbols_eaten > (int)dst_buffer.count) {
return; return;
} }
// //Demod the PDU Header // //Demod the PDU Header
uint8_t bit_decision;
// Jump back down to beginning of PDU header. // Jump back down to beginning of PDU header.
int sample_idx = symbols_eaten - (8 * num_demod_byte * SAMPLE_PER_SYMBOL); sample_idx = symbols_eaten - (8 * num_demod_byte * SAMPLE_PER_SYMBOL);
uint16_t packet_index = 0; packet_index = 0;
for (i = 0; i < num_demod_byte; i++) { for (i = 0; i < num_demod_byte; i++) {
rb_buf[packet_index] = 0; rb_buf[packet_index] = 0;
@ -412,13 +415,14 @@ void BTLERxProcessor::execute(const buffer_c8_t& buffer) {
scramble_byte(rb_buf, num_demod_byte, scramble_table[channel_number], rb_buf); scramble_byte(rb_buf, num_demod_byte, scramble_table[channel_number], rb_buf);
uint8_t pdu_type = (ADV_PDU_TYPE)(rb_buf[0] & 0x0F); pdu_type = (ADV_PDU_TYPE)(rb_buf[0] & 0x0F);
// uint8_t tx_add = ((rb_buf[0] & 0x40) != 0); // uint8_t tx_add = ((rb_buf[0] & 0x40) != 0);
// uint8_t rx_add = ((rb_buf[0] & 0x80) != 0); // uint8_t rx_add = ((rb_buf[0] & 0x80) != 0);
uint8_t payload_len = (rb_buf[1] & 0x3F); payload_len = (rb_buf[1] & 0x3F);
// Not valid Advertise Payload. // Not valid Advertise Payload.
if ((payload_len < 6) || (payload_len > 37)) { if ((payload_len < 6) || (payload_len > 37)) {
parseState = Parse_State_Begin;
return; return;
} }
@ -427,6 +431,10 @@ void BTLERxProcessor::execute(const buffer_c8_t& buffer) {
num_demod_byte = (payload_len + 3); num_demod_byte = (payload_len + 3);
symbols_eaten += 8 * num_demod_byte * SAMPLE_PER_SYMBOL; symbols_eaten += 8 * num_demod_byte * SAMPLE_PER_SYMBOL;
parseState = Parse_State_PDU_Payload;
}
if (parseState == Parse_State_PDU_Payload) {
if (symbols_eaten > (int)dst_buffer.count) { if (symbols_eaten > (int)dst_buffer.count) {
return; return;
} }
@ -451,6 +459,8 @@ void BTLERxProcessor::execute(const buffer_c8_t& buffer) {
packet_index++; packet_index++;
} }
parseState = Parse_State_Begin;
// demod_byte(num_demod_byte, rb_buf + 2); // demod_byte(num_demod_byte, rb_buf + 2);
scramble_byte(rb_buf + 2, num_demod_byte, scramble_table[channel_number] + 2, rb_buf + 2); scramble_byte(rb_buf + 2, num_demod_byte, scramble_table[channel_number] + 2, rb_buf + 2);
@ -499,6 +509,7 @@ void BTLERxProcessor::execute(const buffer_c8_t& buffer) {
} }
} }
} }
}
void BTLERxProcessor::on_message(const Message* const message) { void BTLERxProcessor::on_message(const Message* const message) {
if (message->id == Message::ID::BTLERxConfigure) if (message->id == Message::ID::BTLERxConfigure)

View File

@ -48,6 +48,12 @@ class BTLERxProcessor : public BasebandProcessor {
static constexpr uint32_t DEFAULT_ACCESS_ADDR{0x8E89BED6}; static constexpr uint32_t DEFAULT_ACCESS_ADDR{0x8E89BED6};
static constexpr int NUM_ACCESS_ADDR_BYTE{4}; static constexpr int NUM_ACCESS_ADDR_BYTE{4};
enum Parse_State {
Parse_State_Begin = 0,
Parse_State_PDU_Header,
Parse_State_PDU_Payload
};
enum ADV_PDU_TYPE { enum ADV_PDU_TYPE {
ADV_IND = 0, ADV_IND = 0,
ADV_DIRECT_IND = 1, ADV_DIRECT_IND = 1,
@ -111,13 +117,13 @@ class BTLERxProcessor : public BasebandProcessor {
// void demod_byte(int num_byte, uint8_t *out_byte); // void demod_byte(int num_byte, uint8_t *out_byte);
int parse_adv_pdu_payload_byte(uint8_t* payload_byte, int num_payload_byte, ADV_PDU_TYPE pdu_type, void* adv_pdu_payload); int parse_adv_pdu_payload_byte(uint8_t* payload_byte, int num_payload_byte, ADV_PDU_TYPE pdu_type, void* adv_pdu_payload);
std::array<complex16_t, 1024> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
dst.size()}; dst.size()};
static constexpr int RB_SIZE = 2048; static constexpr int RB_SIZE = 512;
uint8_t rb_buf[2048]; uint8_t rb_buf[RB_SIZE];
dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0{}; dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0{};
@ -131,6 +137,13 @@ class BTLERxProcessor : public BasebandProcessor {
bool configured{false}; bool configured{false};
BlePacketData blePacketData{}; BlePacketData blePacketData{};
Parse_State parseState{};
uint16_t packet_index{0};
int sample_idx{0};
uint8_t bit_decision{0};
uint8_t payload_len{0};
uint8_t pdu_type{0};
/* NB: Threads should be the last members in the class definition. */ /* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive}; BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{}; RSSIThread rssi_thread{};