mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 08:57:38 +00:00
BLE Tx App / BLE Rx Filtering. (#1543)
BLE TX app creation BLE RX and TX app improvements
This commit is contained in:
@@ -360,6 +360,14 @@ set(MODE_CPPSRC
|
||||
proc_btlerx.cpp
|
||||
)
|
||||
DeclareTargets(PBTR btlerx)
|
||||
|
||||
### BTLE TX
|
||||
|
||||
set(MODE_CPPSRC
|
||||
proc_ble_tx.cpp
|
||||
)
|
||||
DeclareTargets(PBTT btletx)
|
||||
|
||||
### AIS
|
||||
|
||||
set(MODE_CPPSRC
|
||||
|
422
firmware/baseband/proc_ble_tx.cpp
Normal file
422
firmware/baseband/proc_ble_tx.cpp
Normal file
@@ -0,0 +1,422 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) TJ Baginski
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "proc_ble_tx.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "sine_table_int8.hpp"
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define new_way
|
||||
|
||||
int BTLETxProcessor::gen_sample_from_phy_bit(char* bit, char* 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;
|
||||
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1); i++) {
|
||||
tmp_phy_bit_over_sampling_int8[i] = 0;
|
||||
}
|
||||
for (i = (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1 + num_bit * SAMPLE_PER_SYMBOL); i < (2 * LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 2 + num_bit * SAMPLE_PER_SYMBOL); i++) {
|
||||
tmp_phy_bit_over_sampling_int8[i] = 0;
|
||||
}
|
||||
for (i = 0; i < (num_bit * SAMPLE_PER_SYMBOL); i++) {
|
||||
if (i % SAMPLE_PER_SYMBOL == 0) {
|
||||
tmp_phy_bit_over_sampling_int8[i + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1)] = (bit[i / SAMPLE_PER_SYMBOL]) * 2 - 1;
|
||||
} else {
|
||||
tmp_phy_bit_over_sampling_int8[i + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int16_t tmp = 0;
|
||||
sample[0] = cos_table_int8[tmp];
|
||||
sample[1] = sin_table_int8[tmp];
|
||||
|
||||
int len_conv_result = num_sample - 1;
|
||||
for (i = 0; i < len_conv_result; i++) {
|
||||
int16_t acc = 0;
|
||||
for (j = 3; j < (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 4); j++) {
|
||||
acc = acc + gauss_coef_int8[(LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL) - j - 1] * tmp_phy_bit_over_sampling_int8[i + j];
|
||||
}
|
||||
|
||||
tmp = (tmp + acc) & 1023;
|
||||
sample[(i + 1) * 2 + 0] = cos_table_int8[tmp];
|
||||
sample[(i + 1) * 2 + 1] = sin_table_int8[tmp];
|
||||
}
|
||||
|
||||
return (num_sample);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::octet_hex_to_bit(char* hex, char* bit) {
|
||||
char tmp_hex[3];
|
||||
|
||||
tmp_hex[0] = hex[0];
|
||||
tmp_hex[1] = hex[1];
|
||||
tmp_hex[2] = 0;
|
||||
|
||||
int n = strtol(tmp_hex, NULL, 16);
|
||||
|
||||
bit[0] = 0x01 & (n >> 0);
|
||||
bit[1] = 0x01 & (n >> 1);
|
||||
bit[2] = 0x01 & (n >> 2);
|
||||
bit[3] = 0x01 & (n >> 3);
|
||||
bit[4] = 0x01 & (n >> 4);
|
||||
bit[5] = 0x01 & (n >> 5);
|
||||
bit[6] = 0x01 & (n >> 6);
|
||||
bit[7] = 0x01 & (n >> 7);
|
||||
}
|
||||
|
||||
int BTLETxProcessor::convert_hex_to_bit(char* hex, char* bit, int stream_flip, int octet_limit) {
|
||||
int num_hex_orig = strlen(hex);
|
||||
|
||||
int i, num_hex;
|
||||
num_hex = num_hex_orig;
|
||||
for (i = 0; i < num_hex_orig; i++) {
|
||||
if (!((hex[i] >= 48 && hex[i] <= 57) || (hex[i] >= 65 && hex[i] <= 70) || (hex[i] >= 97 && hex[i] <= 102))) // not a hex
|
||||
num_hex--;
|
||||
}
|
||||
|
||||
if (num_hex % 2 != 0) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (num_hex > (octet_limit * 2)) {
|
||||
return (-1);
|
||||
}
|
||||
if (num_hex <= 1) { // NULL data
|
||||
return (-1);
|
||||
}
|
||||
|
||||
char tmp_str[max_char];
|
||||
|
||||
if (stream_flip == 1) {
|
||||
strcpy(tmp_str, hex);
|
||||
for (i = 0; i < num_hex; i = i + 2) {
|
||||
hex[num_hex - i - 2] = tmp_str[i];
|
||||
hex[num_hex - i - 1] = tmp_str[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
int num_bit = num_hex * 4;
|
||||
|
||||
int j;
|
||||
for (i = 0; i < num_hex; i = i + 2) {
|
||||
j = i * 4;
|
||||
octet_hex_to_bit(hex + i, bit + j);
|
||||
}
|
||||
|
||||
return (num_bit);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::crc24(char* bit_in, int num_bit, char* init_hex, char* crc_result) {
|
||||
char bit_store[24], bit_store_update[24];
|
||||
int i;
|
||||
convert_hex_to_bit(init_hex, bit_store, 0, 3);
|
||||
|
||||
for (i = 0; i < num_bit; i++) {
|
||||
char new_bit = (bit_store[23] + bit_in[i]) % 2;
|
||||
bit_store_update[0] = new_bit;
|
||||
bit_store_update[1] = (bit_store[0] + new_bit) % 2;
|
||||
bit_store_update[2] = bit_store[1];
|
||||
bit_store_update[3] = (bit_store[2] + new_bit) % 2;
|
||||
bit_store_update[4] = (bit_store[3] + new_bit) % 2;
|
||||
bit_store_update[5] = bit_store[4];
|
||||
bit_store_update[6] = (bit_store[5] + new_bit) % 2;
|
||||
|
||||
bit_store_update[7] = bit_store[6];
|
||||
bit_store_update[8] = bit_store[7];
|
||||
|
||||
bit_store_update[9] = (bit_store[8] + new_bit) % 2;
|
||||
bit_store_update[10] = (bit_store[9] + new_bit) % 2;
|
||||
|
||||
memcpy(bit_store_update + 11, bit_store + 10, 13);
|
||||
|
||||
memcpy(bit_store, bit_store_update, 24);
|
||||
}
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
crc_result[i] = bit_store[23 - i];
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::scramble(char* bit_in, int num_bit, int channel_number, char* bit_out) {
|
||||
char bit_store[7], bit_store_update[7];
|
||||
int i;
|
||||
|
||||
bit_store[0] = 1;
|
||||
bit_store[1] = 0x01 & (channel_number >> 5);
|
||||
bit_store[2] = 0x01 & (channel_number >> 4);
|
||||
bit_store[3] = 0x01 & (channel_number >> 3);
|
||||
bit_store[4] = 0x01 & (channel_number >> 2);
|
||||
bit_store[5] = 0x01 & (channel_number >> 1);
|
||||
bit_store[6] = 0x01 & (channel_number >> 0);
|
||||
|
||||
for (i = 0; i < num_bit; i++) {
|
||||
bit_out[i] = (bit_store[6] + bit_in[i]) % 2;
|
||||
|
||||
bit_store_update[0] = bit_store[6];
|
||||
|
||||
bit_store_update[1] = bit_store[0];
|
||||
bit_store_update[2] = bit_store[1];
|
||||
bit_store_update[3] = bit_store[2];
|
||||
|
||||
bit_store_update[4] = (bit_store[3] + bit_store[6]) % 2;
|
||||
|
||||
bit_store_update[5] = bit_store[4];
|
||||
bit_store_update[6] = bit_store[5];
|
||||
|
||||
memcpy(bit_store, bit_store_update, 7);
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::disp_bit_in_hex(char* bit, int num_bit) {
|
||||
int i, a;
|
||||
|
||||
for (i = 0; i < num_bit; i = i + 8) {
|
||||
a = bit[i] + bit[i + 1] * 2 + bit[i + 2] * 4 + bit[i + 3] * 8 + bit[i + 4] * 16 + bit[i + 5] * 32 + bit[i + 6] * 64 + bit[i + 7] * 128;
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = (uint8_t)a;
|
||||
shared_memory.application_queue.push(data_message);
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::crc24_and_scramble_to_gen_phy_bit(char* crc_init_hex, PKT_INFO* pkt) {
|
||||
crc24(pkt->info_bit + 5 * 8, pkt->num_info_bit - 5 * 8, crc_init_hex, pkt->info_bit + pkt->num_info_bit);
|
||||
|
||||
// disp_bit_in_hex(pkt->info_bit, pkt->num_info_bit + 3*8);
|
||||
|
||||
scramble(pkt->info_bit + 5 * 8, pkt->num_info_bit - 5 * 8 + 24, pkt->channel_number, pkt->phy_bit + 5 * 8);
|
||||
memcpy(pkt->phy_bit, pkt->info_bit, 5 * 8);
|
||||
pkt->num_phy_bit = pkt->num_info_bit + 24;
|
||||
|
||||
// disp_bit_in_hex(pkt->phy_bit, pkt->num_phy_bit);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::fill_adv_pdu_header(PKT_INFO* pkt, int txadd, int rxadd, int payload_len, char* bit_out) {
|
||||
if (pkt->pkt_type == ADV_IND || pkt->pkt_type == IBEACON) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 0;
|
||||
} else if (pkt->pkt_type == ADV_DIRECT_IND) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 1;
|
||||
} else if (pkt->pkt_type == ADV_NONCONN_IND || pkt->pkt_type == DISCOVERY) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 0;
|
||||
} else if (pkt->pkt_type == SCAN_REQ) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 1;
|
||||
} else if (pkt->pkt_type == SCAN_RSP) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 0;
|
||||
} else if (pkt->pkt_type == CONNECT_REQ) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 1;
|
||||
} else if (pkt->pkt_type == ADV_SCAN_IND) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 0;
|
||||
} else {
|
||||
bit_out[3] = 1;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 1;
|
||||
}
|
||||
|
||||
bit_out[4] = 0;
|
||||
bit_out[5] = 0;
|
||||
|
||||
bit_out[6] = txadd;
|
||||
bit_out[7] = rxadd;
|
||||
|
||||
bit_out[8] = 0x01 & (payload_len >> 0);
|
||||
bit_out[9] = 0x01 & (payload_len >> 1);
|
||||
bit_out[10] = 0x01 & (payload_len >> 2);
|
||||
bit_out[11] = 0x01 & (payload_len >> 3);
|
||||
bit_out[12] = 0x01 & (payload_len >> 4);
|
||||
bit_out[13] = 0x01 & (payload_len >> 5);
|
||||
|
||||
bit_out[14] = 0;
|
||||
bit_out[15] = 0;
|
||||
}
|
||||
|
||||
int BTLETxProcessor::calculate_sample_for_ADV_IND(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);
|
||||
|
||||
// get txadd and rxadd
|
||||
int txadd = 1, rxadd = 0;
|
||||
|
||||
pkt->num_info_bit = pkt->num_info_bit + 16; // 16 is header length
|
||||
|
||||
// get AdvA and AdvData
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit(macAddress, pkt->info_bit + pkt->num_info_bit, 1, 6);
|
||||
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit(advertisementData, pkt->info_bit + pkt->num_info_bit, 0, 31);
|
||||
|
||||
int payload_len = (pkt->num_info_bit / 8) - 7;
|
||||
|
||||
fill_adv_pdu_header(pkt, txadd, rxadd, payload_len, pkt->info_bit + 5 * 8);
|
||||
const char* checksumInit = "555555";
|
||||
crc24_and_scramble_to_gen_phy_bit((char*)checksumInit, pkt);
|
||||
|
||||
#ifdef new_way
|
||||
pkt->num_phy_sample = gen_sample_from_phy_bit(pkt->phy_bit, pkt->phy_sample, pkt->num_phy_bit);
|
||||
#endif
|
||||
|
||||
// disp_bit_in_hex(pkt->phy_sample, pkt->num_phy_sample);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
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) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int BTLETxProcessor::calculate_pkt_info(PKT_INFO* pkt) {
|
||||
if (calculate_sample_from_pkt_type(pkt) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
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;
|
||||
} 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};
|
||||
}
|
||||
}
|
||||
|
||||
txprogress_message.done = true;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::on_message(const Message* const message) {
|
||||
if (message->id == Message::ID::BTLETxConfigure) {
|
||||
configure(*reinterpret_cast<const BTLETxConfigureMessage*>(message));
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::configure(const BTLETxConfigureMessage& message) {
|
||||
channel_number = message.channel_number;
|
||||
|
||||
memcpy(macAddress, message.macAddress, sizeof(macAddress));
|
||||
memcpy(advertisementData, message.advertisementData, sizeof(advertisementData));
|
||||
|
||||
packets.channel_number = channel_number;
|
||||
packets.pkt_type = packetType;
|
||||
|
||||
// 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);
|
||||
#else
|
||||
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;
|
||||
progress_notice = 64;
|
||||
|
||||
txprogress_message.progress = 0;
|
||||
txprogress_message.done = false;
|
||||
configured = true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher{std::make_unique<BTLETxProcessor>()};
|
||||
event_dispatcher.run();
|
||||
return 0;
|
||||
}
|
239
firmware/baseband/proc_ble_tx.hpp
Normal file
239
firmware/baseband/proc_ble_tx.hpp
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PROC_BLE_TX_H__
|
||||
#define __PROC_BLE_TX_H__
|
||||
|
||||
#include "baseband_processor.hpp"
|
||||
#include "baseband_thread.hpp"
|
||||
|
||||
class BTLETxProcessor : public BasebandProcessor {
|
||||
public:
|
||||
void execute(const buffer_c8_t& buffer) override;
|
||||
void on_message(const Message* const message) override;
|
||||
void configure(const BTLETxConfigureMessage& message);
|
||||
|
||||
private:
|
||||
static constexpr int max_char{256};
|
||||
static constexpr int SAMPLE_PER_SYMBOL{4};
|
||||
static constexpr float AMPLITUDE{127.0};
|
||||
static constexpr float MOD_IDX{0.5};
|
||||
static constexpr int LEN_GAUSS_FILTER{4};
|
||||
static constexpr int MAX_NUM_INFO_BYTE{43};
|
||||
static constexpr int MAX_NUM_PHY_BYTE{47};
|
||||
static constexpr int MAX_NUM_PHY_SAMPLE{(MAX_NUM_PHY_BYTE * 8 * SAMPLE_PER_SYMBOL) + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL)};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
struct PKT_INFO {
|
||||
int channel_number;
|
||||
PKT_TYPE pkt_type;
|
||||
|
||||
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)
|
||||
|
||||
int space; // how many millisecond null signal shouwl be padded after this packet
|
||||
};
|
||||
|
||||
PKT_INFO packets{};
|
||||
|
||||
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);
|
||||
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);
|
||||
void scramble(char* bit_in, int num_bit, int channel_number, char* bit_out);
|
||||
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);
|
||||
bool configured = false;
|
||||
|
||||
float tmp_phy_bit_over_sampling[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 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 phase{0}, sphase{0};
|
||||
|
||||
uint8_t cur_bit{0};
|
||||
uint16_t bit_pos{0};
|
||||
|
||||
uint16_t process{0};
|
||||
|
||||
// clang-format off
|
||||
const int8_t gauss_coef_int8[16] = {
|
||||
0, 0, 0, 0, 2, 11, 32, 53, 60, 53, 32, 11, 2, 0, 0, 0, };
|
||||
|
||||
const int8_t cos_table_int8[1024] = {
|
||||
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 126, 126,
|
||||
126, 126, 125, 125, 125, 125, 125, 125, 125, 124, 124, 124, 124, 124, 124, 123, 123, 123, 123, 123, 122, 122, 122, 122,
|
||||
122, 121, 121, 121, 121, 120, 120, 120, 120, 119, 119, 119, 118, 118, 118, 118, 117, 117, 117, 116, 116, 116, 115, 115,
|
||||
115, 114, 114, 114, 113, 113, 113, 112, 112, 112, 111, 111, 111, 110, 110, 109, 109, 109, 108, 108, 107, 107, 106, 106,
|
||||
106, 105, 105, 104, 104, 103, 103, 102, 102, 102, 101, 101, 100, 100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95,
|
||||
94, 94, 93, 93, 92, 91, 91, 90, 90, 89, 89, 88, 88, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81,
|
||||
81, 80, 79, 79, 78, 78, 77, 76, 76, 75, 74, 74, 73, 72, 72, 71, 71, 70, 69, 69, 68, 67, 67, 66,
|
||||
65, 65, 64, 63, 63, 62, 61, 61, 60, 59, 58, 58, 57, 56, 56, 55, 54, 54, 53, 52, 51, 51, 50, 49,
|
||||
49, 48, 47, 46, 46, 45, 44, 44, 43, 42, 41, 41, 40, 39, 38, 38, 37, 36, 35, 35, 34, 33, 32, 32,
|
||||
31, 30, 29, 29, 28, 27, 26, 26, 25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 17, 16, 16, 15, 14, 13,
|
||||
12, 12, 11, 10, 9, 9, 8, 7, 6, 5, 5, 4, 3, 2, 2, 1, 0, -1, -2, -2, -3, -4, -5, -5,
|
||||
-6, -7, -8, -9, -9, -10, -11, -12, -12, -13, -14, -15, -16, -16, -17, -18, -19, -19, -20, -21, -22, -22, -23, -24,
|
||||
-25, -26, -26, -27, -28, -29, -29, -30, -31, -32, -32, -33, -34, -35, -35, -36, -37, -38, -38, -39, -40, -41, -41, -42,
|
||||
-43, -44, -44, -45, -46, -46, -47, -48, -49, -49, -50, -51, -51, -52, -53, -54, -54, -55, -56, -56, -57, -58, -58, -59,
|
||||
-60, -61, -61, -62, -63, -63, -64, -65, -65, -66, -67, -67, -68, -69, -69, -70, -71, -71, -72, -72, -73, -74, -74, -75,
|
||||
-76, -76, -77, -78, -78, -79, -79, -80, -81, -81, -82, -82, -83, -84, -84, -85, -85, -86, -86, -87, -88, -88, -89, -89,
|
||||
-90, -90, -91, -91, -92, -93, -93, -94, -94, -95, -95, -96, -96, -97, -97, -98, -98, -99, -99, -100, -100, -101, -101, -102,
|
||||
-102, -102, -103, -103, -104, -104, -105, -105, -106, -106, -106, -107, -107, -108, -108, -109, -109, -109, -110, -110, -111, -111, -111, -112,
|
||||
-112, -112, -113, -113, -113, -114, -114, -114, -115, -115, -115, -116, -116, -116, -117, -117, -117, -118, -118, -118, -118, -119, -119, -119,
|
||||
-120, -120, -120, -120, -121, -121, -121, -121, -122, -122, -122, -122, -122, -123, -123, -123, -123, -123, -124, -124, -124, -124, -124, -124,
|
||||
-125, -125, -125, -125, -125, -125, -125, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -127, -127, -127, -127, -127, -127,
|
||||
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -126,
|
||||
-126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -125, -125, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124, -124, -123,
|
||||
-123, -123, -123, -123, -122, -122, -122, -122, -122, -121, -121, -121, -121, -120, -120, -120, -120, -119, -119, -119, -118, -118, -118, -118,
|
||||
-117, -117, -117, -116, -116, -116, -115, -115, -115, -114, -114, -114, -113, -113, -113, -112, -112, -112, -111, -111, -111, -110, -110, -109,
|
||||
-109, -109, -108, -108, -107, -107, -106, -106, -106, -105, -105, -104, -104, -103, -103, -102, -102, -102, -101, -101, -100, -100, -99, -99,
|
||||
-98, -98, -97, -97, -96, -96, -95, -95, -94, -94, -93, -93, -92, -91, -91, -90, -90, -89, -89, -88, -88, -87, -86, -86,
|
||||
-85, -85, -84, -84, -83, -82, -82, -81, -81, -80, -79, -79, -78, -78, -77, -76, -76, -75, -74, -74, -73, -72, -72, -71,
|
||||
-71, -70, -69, -69, -68, -67, -67, -66, -65, -65, -64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56, -55,
|
||||
-54, -54, -53, -52, -51, -51, -50, -49, -49, -48, -47, -46, -46, -45, -44, -44, -43, -42, -41, -41, -40, -39, -38, -38,
|
||||
-37, -36, -35, -35, -34, -33, -32, -32, -31, -30, -29, -29, -28, -27, -26, -26, -25, -24, -23, -22, -22, -21, -20, -19,
|
||||
-19, -18, -17, -16, -16, -15, -14, -13, -12, -12, -11, -10, -9, -9, -8, -7, -6, -5, -5, -4, -3, -2, -2, -1,
|
||||
0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 16, 17, 18,
|
||||
19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
|
||||
37, 38, 38, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 54,
|
||||
54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69, 70,
|
||||
71, 71, 72, 72, 73, 74, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 84, 84, 85,
|
||||
85, 86, 86, 87, 88, 88, 89, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 95, 96, 96, 97, 97, 98,
|
||||
98, 99, 99, 100, 100, 101, 101, 102, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 106, 107, 107, 108, 108, 109,
|
||||
109, 109, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, 116, 117, 117,
|
||||
117, 118, 118, 118, 118, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 122, 122, 123, 123, 123,
|
||||
123, 123, 124, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126,
|
||||
126, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, };
|
||||
|
||||
const int8_t sin_table_int8[1024] = {
|
||||
0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 16, 17, 18,
|
||||
19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
|
||||
37, 38, 38, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 54,
|
||||
54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69, 70,
|
||||
71, 71, 72, 72, 73, 74, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 84, 84, 85,
|
||||
85, 86, 86, 87, 88, 88, 89, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 95, 96, 96, 97, 97, 98,
|
||||
98, 99, 99, 100, 100, 101, 101, 102, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 106, 107, 107, 108, 108, 109,
|
||||
109, 109, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, 116, 117, 117,
|
||||
117, 118, 118, 118, 118, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 122, 122, 123, 123, 123,
|
||||
123, 123, 124, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126,
|
||||
126, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||
127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 125, 125, 125, 125, 125, 125,
|
||||
125, 124, 124, 124, 124, 124, 124, 123, 123, 123, 123, 123, 122, 122, 122, 122, 122, 121, 121, 121, 121, 120, 120, 120,
|
||||
120, 119, 119, 119, 118, 118, 118, 118, 117, 117, 117, 116, 116, 116, 115, 115, 115, 114, 114, 114, 113, 113, 113, 112,
|
||||
112, 112, 111, 111, 111, 110, 110, 109, 109, 109, 108, 108, 107, 107, 106, 106, 106, 105, 105, 104, 104, 103, 103, 102,
|
||||
102, 102, 101, 101, 100, 100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 91, 91, 90,
|
||||
90, 89, 89, 88, 88, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81, 81, 80, 79, 79, 78, 78, 77, 76,
|
||||
76, 75, 74, 74, 73, 72, 72, 71, 71, 70, 69, 69, 68, 67, 67, 66, 65, 65, 64, 63, 63, 62, 61, 61,
|
||||
60, 59, 58, 58, 57, 56, 56, 55, 54, 54, 53, 52, 51, 51, 50, 49, 49, 48, 47, 46, 46, 45, 44, 44,
|
||||
43, 42, 41, 41, 40, 39, 38, 38, 37, 36, 35, 35, 34, 33, 32, 32, 31, 30, 29, 29, 28, 27, 26, 26,
|
||||
25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 17, 16, 16, 15, 14, 13, 12, 12, 11, 10, 9, 9, 8, 7,
|
||||
6, 5, 5, 4, 3, 2, 2, 1, 0, -1, -2, -2, -3, -4, -5, -5, -6, -7, -8, -9, -9, -10, -11, -12,
|
||||
-12, -13, -14, -15, -16, -16, -17, -18, -19, -19, -20, -21, -22, -22, -23, -24, -25, -26, -26, -27, -28, -29, -29, -30,
|
||||
-31, -32, -32, -33, -34, -35, -35, -36, -37, -38, -38, -39, -40, -41, -41, -42, -43, -44, -44, -45, -46, -46, -47, -48,
|
||||
-49, -49, -50, -51, -51, -52, -53, -54, -54, -55, -56, -56, -57, -58, -58, -59, -60, -61, -61, -62, -63, -63, -64, -65,
|
||||
-65, -66, -67, -67, -68, -69, -69, -70, -71, -71, -72, -72, -73, -74, -74, -75, -76, -76, -77, -78, -78, -79, -79, -80,
|
||||
-81, -81, -82, -82, -83, -84, -84, -85, -85, -86, -86, -87, -88, -88, -89, -89, -90, -90, -91, -91, -92, -93, -93, -94,
|
||||
-94, -95, -95, -96, -96, -97, -97, -98, -98, -99, -99, -100, -100, -101, -101, -102, -102, -102, -103, -103, -104, -104, -105, -105,
|
||||
-106, -106, -106, -107, -107, -108, -108, -109, -109, -109, -110, -110, -111, -111, -111, -112, -112, -112, -113, -113, -113, -114, -114, -114,
|
||||
-115, -115, -115, -116, -116, -116, -117, -117, -117, -118, -118, -118, -118, -119, -119, -119, -120, -120, -120, -120, -121, -121, -121, -121,
|
||||
-122, -122, -122, -122, -122, -123, -123, -123, -123, -123, -124, -124, -124, -124, -124, -124, -125, -125, -125, -125, -125, -125, -125, -126,
|
||||
-126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127,
|
||||
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -126, -126, -126, -126, -126, -126, -126, -126, -126,
|
||||
-126, -126, -125, -125, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124, -124, -123, -123, -123, -123, -123, -122, -122, -122, -122,
|
||||
-122, -121, -121, -121, -121, -120, -120, -120, -120, -119, -119, -119, -118, -118, -118, -118, -117, -117, -117, -116, -116, -116, -115, -115,
|
||||
-115, -114, -114, -114, -113, -113, -113, -112, -112, -112, -111, -111, -111, -110, -110, -109, -109, -109, -108, -108, -107, -107, -106, -106,
|
||||
-106, -105, -105, -104, -104, -103, -103, -102, -102, -102, -101, -101, -100, -100, -99, -99, -98, -98, -97, -97, -96, -96, -95, -95,
|
||||
-94, -94, -93, -93, -92, -91, -91, -90, -90, -89, -89, -88, -88, -87, -86, -86, -85, -85, -84, -84, -83, -82, -82, -81,
|
||||
-81, -80, -79, -79, -78, -78, -77, -76, -76, -75, -74, -74, -73, -72, -72, -71, -71, -70, -69, -69, -68, -67, -67, -66,
|
||||
-65, -65, -64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56, -55, -54, -54, -53, -52, -51, -51, -50, -49,
|
||||
-49, -48, -47, -46, -46, -45, -44, -44, -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -35, -35, -34, -33, -32, -32,
|
||||
-31, -30, -29, -29, -28, -27, -26, -26, -25, -24, -23, -22, -22, -21, -20, -19, -19, -18, -17, -16, -16, -15, -14, -13,
|
||||
-12, -12, -11, -10, -9, -9, -8, -7, -6, -5, -5, -4, -3, -2, -2, -1, };
|
||||
// clang-format on
|
||||
|
||||
PKT_TYPE packetType = ADV_IND;
|
||||
|
||||
TXProgressMessage txprogress_message{};
|
||||
|
||||
/* NB: Threads should be the last members in the class definition. */
|
||||
|
||||
// BasebandThread baseband_thread{4000000, this, baseband::Direction::Transmit};
|
||||
// Rx for now because trying to test formulation of packet.
|
||||
AFSKDataMessage data_message{false, 0};
|
||||
BasebandThread baseband_thread{4000000, this, baseband::Direction::Transmit};
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user