mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-13 10:47:44 +00:00
BLE RX/TX Changes (#2752)
* Work on BLE Rx Tx improvements. * Working on compile size. * cleanup * Formatting * Fixes * More Improvements + Custom Parsing for Tags * Moving ERT to external apps. * Fix Icon.
This commit is contained in:
@@ -30,10 +30,10 @@
|
||||
|
||||
#define new_way
|
||||
|
||||
int BTLETxProcessor::gen_sample_from_phy_bit(char* bit, char* sample, int num_bit) {
|
||||
int BTLETxProcessor::gen_sample_from_phy_bit(char* bit, int8_t* sample, int num_bit) {
|
||||
int num_sample = (num_bit * SAMPLE_PER_SYMBOL) + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL);
|
||||
|
||||
int8_t* tmp_phy_bit_over_sampling_int8 = (int8_t*)tmp_phy_bit_over_sampling;
|
||||
memset(tmp_phy_bit_over_sampling_int8, 0, sizeof(tmp_phy_bit_over_sampling_int8));
|
||||
|
||||
int i, j;
|
||||
|
||||
@@ -242,6 +242,7 @@ void BTLETxProcessor::fill_adv_pdu_header(PKT_INFO* pkt, int txadd, int rxadd, i
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 0;
|
||||
rxadd = 1; // Scan response assumed to be with random address.
|
||||
} else if (pkt->pkt_type == CONNECT_REQ) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 1;
|
||||
@@ -279,14 +280,12 @@ void BTLETxProcessor::fill_adv_pdu_header(PKT_INFO* pkt, int txadd, int rxadd, i
|
||||
int BTLETxProcessor::calculate_sample_for_ADV(PKT_INFO* pkt) {
|
||||
pkt->num_info_bit = 0;
|
||||
|
||||
// gen preamble and access address
|
||||
const char* AA = "AA";
|
||||
const char* AAValue = "D6BE898E";
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit((char*)AA, pkt->info_bit, 0, 1);
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit((char*)AAValue, pkt->info_bit + pkt->num_info_bit, 0, 4);
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit(AA, pkt->info_bit, 0, 1);
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit(AAValue, pkt->info_bit + pkt->num_info_bit, 0, 4);
|
||||
|
||||
// get txadd and rxadd
|
||||
int txadd = 0, rxadd = 0;
|
||||
// Tx assumed to be random address.
|
||||
int txadd = 1, rxadd = 0;
|
||||
|
||||
pkt->num_info_bit = pkt->num_info_bit + 16; // 16 is header length
|
||||
|
||||
@@ -332,39 +331,56 @@ int BTLETxProcessor::calculate_pkt_info(PKT_INFO* pkt) {
|
||||
void BTLETxProcessor::execute(const buffer_c8_t& buffer) {
|
||||
int8_t re, im;
|
||||
|
||||
// This is called at 4M/2048 = 1953Hz
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
if (configured) {
|
||||
// This is going to loop through each sample bit and push it to the output buffer.
|
||||
if (sample_count > length) {
|
||||
configured = false;
|
||||
sample_count = 0;
|
||||
|
||||
txprogress_message.done = true;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
} else {
|
||||
// Real and imaginary was already calculated in gen_sample_from_phy_bit.
|
||||
// It was processed from each data bit, run through a Gaussian Filter, and then ran through sin and cos table to get each IQ bit.
|
||||
re = (int8_t)packets.phy_sample[sample_count++];
|
||||
im = (int8_t)packets.phy_sample[sample_count++];
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
|
||||
if (progress_count >= progress_notice) {
|
||||
progress_count = 0;
|
||||
txprogress_message.progress++;
|
||||
txprogress_message.done = false;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
} else {
|
||||
progress_count++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
re = 0;
|
||||
im = 0;
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
if (!configured) {
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
buffer.p[i] = {0, 0}; // Fill the buffer with zeros if not configured
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (configured) {
|
||||
switch (txprogress_message.progress) {
|
||||
case 1:
|
||||
case 2: {
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
buffer.p[i] = {0, 0}; // Pre and Post pad BLE Packet.
|
||||
}
|
||||
} break;
|
||||
|
||||
case 0: {
|
||||
size_t i = 0;
|
||||
for (i = 0; (i < buffer.count) && (sample_count < length); i++) {
|
||||
re = packets.phy_sample[sample_count++];
|
||||
im = packets.phy_sample[sample_count++];
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
}
|
||||
|
||||
if (sample_count >= length && i < buffer.count) {
|
||||
// Fill the rest of the buffer with zeros if we reach the end of the packet
|
||||
for (; i < buffer.count; i++) {
|
||||
buffer.p[i] = {0, 0};
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case 3: {
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
buffer.p[i] = {0, 0}; // Pre and Post pad BLE Packet.
|
||||
}
|
||||
|
||||
if (sample_count >= length) {
|
||||
sample_count = 0;
|
||||
configured = false;
|
||||
|
||||
doneSending = true;
|
||||
txprogress_message.done = true;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
txprogress_message.progress++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,11 +413,13 @@ void BTLETxProcessor::configure(const BTLETxConfigureMessage& message) {
|
||||
// Starting at sample_count 0 since packets.num_phy_sample contains every sample needed to be sent out.
|
||||
sample_count = 0;
|
||||
progress_count = 0;
|
||||
repeatCount = 0;
|
||||
progress_notice = 64;
|
||||
|
||||
txprogress_message.progress = 0;
|
||||
txprogress_message.done = false;
|
||||
configured = true;
|
||||
doneSending = false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
@@ -80,18 +80,11 @@ class BTLETxProcessor : public BasebandProcessor {
|
||||
int num_info_bit;
|
||||
char info_bit[MAX_NUM_PHY_BYTE * 8]; // without CRC and whitening
|
||||
|
||||
int num_info_byte;
|
||||
uint8_t info_byte[MAX_NUM_PHY_BYTE];
|
||||
|
||||
int num_phy_bit;
|
||||
char phy_bit[MAX_NUM_PHY_BYTE * 8]; // all bits which will be fed to GFSK modulator
|
||||
|
||||
int num_phy_byte;
|
||||
uint8_t phy_byte[MAX_NUM_PHY_BYTE];
|
||||
|
||||
int num_phy_sample;
|
||||
char phy_sample[2 * MAX_NUM_PHY_SAMPLE]; // GFSK output to D/A (hackrf board)
|
||||
int8_t phy_sample1[2 * MAX_NUM_PHY_SAMPLE]; // GFSK output to D/A (hackrf board)
|
||||
int8_t phy_sample[2 * MAX_NUM_PHY_SAMPLE]; // GFSK output to D/A (hackrf board)
|
||||
|
||||
int space; // how many millisecond null signal shouwl be padded after this packet
|
||||
};
|
||||
@@ -108,22 +101,27 @@ class BTLETxProcessor : public BasebandProcessor {
|
||||
void crc24(char* bit_in, int num_bit, char* init_hex, char* crc_result);
|
||||
int convert_hex_to_bit(char* hex, char* bit, int stream_flip, int octet_limit);
|
||||
void octet_hex_to_bit(char* hex, char* bit);
|
||||
int gen_sample_from_phy_bit(char* bit, char* sample, int num_bit);
|
||||
int gen_sample_from_phy_bit(char* bit, int8_t* sample, int num_bit);
|
||||
bool configured = false;
|
||||
|
||||
float tmp_phy_bit_over_sampling[MAX_NUM_PHY_SAMPLE + 2 * LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL];
|
||||
int8_t tmp_phy_bit_over_sampling_int8[MAX_NUM_PHY_SAMPLE + 2 * LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL];
|
||||
float gauss_coef[LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL] = {7.561773e-09, 1.197935e-06, 8.050684e-05, 2.326833e-03, 2.959908e-02, 1.727474e-01, 4.999195e-01, 8.249246e-01, 9.408018e-01, 8.249246e-01, 4.999195e-01, 1.727474e-01, 2.959908e-02, 2.326833e-03, 8.050684e-05, 1.197935e-06};
|
||||
|
||||
uint32_t samples_per_bit{4};
|
||||
uint32_t channel_number{37};
|
||||
char macAddress[13] = "FFFFFFFFFF";
|
||||
char AA[3] = "AA";
|
||||
char AAValue[9] = "D6BE898E";
|
||||
char advertisementData[63] = {0};
|
||||
|
||||
uint32_t length{0};
|
||||
uint32_t shift_zero{}, shift_one{};
|
||||
uint32_t progress_notice{}, progress_count{0};
|
||||
uint32_t sample_count{0};
|
||||
uint32_t paddingCount{0};
|
||||
uint32_t repeatCount{0};
|
||||
uint32_t phase{0}, sphase{0};
|
||||
bool doneSending{false};
|
||||
|
||||
uint8_t cur_bit{0};
|
||||
uint16_t bit_pos{0};
|
||||
|
Reference in New Issue
Block a user