mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-06-25 15:20:31 -04:00
Formatted code (#1007)
* Updated style * Updated files * fixed new line * Updated spacing * File fix WIP * Updated to clang 13 * updated comment style * Removed old comment code
This commit is contained in:
parent
7aca7ce74d
commit
033c4e9a5b
599 changed files with 70746 additions and 66896 deletions
|
@ -19,7 +19,7 @@
|
|||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ADSB_FRAME_H__
|
||||
#define __ADSB_FRAME_H__
|
||||
|
||||
|
@ -28,104 +28,104 @@
|
|||
|
||||
namespace adsb {
|
||||
|
||||
alignas(4) const uint8_t adsb_preamble[16] = { 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 };
|
||||
alignas(4) const uint8_t adsb_preamble[16] = {1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0};
|
||||
alignas(4) const char icao_id_lut[65] = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ##### ###############0123456789######";
|
||||
|
||||
class ADSBFrame {
|
||||
public:
|
||||
uint8_t get_DF() {
|
||||
return (raw_data[0] >> 3);
|
||||
}
|
||||
public:
|
||||
uint8_t get_DF() {
|
||||
return (raw_data[0] >> 3);
|
||||
}
|
||||
|
||||
uint8_t get_msg_type() {
|
||||
return (raw_data[4] >> 3);
|
||||
}
|
||||
uint8_t get_msg_type() {
|
||||
return (raw_data[4] >> 3);
|
||||
}
|
||||
|
||||
uint8_t get_msg_sub() {
|
||||
return (raw_data[4] & 7);
|
||||
}
|
||||
uint8_t get_msg_sub() {
|
||||
return (raw_data[4] & 7);
|
||||
}
|
||||
|
||||
uint32_t get_ICAO_address() {
|
||||
return (raw_data[1] << 16) + (raw_data[2] << 8) + raw_data[3];
|
||||
}
|
||||
|
||||
void set_rx_timestamp(uint32_t timestamp) {
|
||||
rx_timestamp = timestamp;
|
||||
}
|
||||
uint32_t get_rx_timestamp() {
|
||||
return rx_timestamp;
|
||||
}
|
||||
uint32_t get_ICAO_address() {
|
||||
return (raw_data[1] << 16) + (raw_data[2] << 8) + raw_data[3];
|
||||
}
|
||||
|
||||
void clear() {
|
||||
index = 0;
|
||||
memset(raw_data, 0, 14);
|
||||
}
|
||||
void set_rx_timestamp(uint32_t timestamp) {
|
||||
rx_timestamp = timestamp;
|
||||
}
|
||||
uint32_t get_rx_timestamp() {
|
||||
return rx_timestamp;
|
||||
}
|
||||
|
||||
void push_byte(uint8_t byte) {
|
||||
if (index >= 14)
|
||||
return;
|
||||
|
||||
raw_data[index++] = byte;
|
||||
}
|
||||
void clear() {
|
||||
index = 0;
|
||||
memset(raw_data, 0, 14);
|
||||
}
|
||||
|
||||
uint8_t * get_raw_data() const {
|
||||
return (uint8_t* )raw_data;
|
||||
}
|
||||
|
||||
void make_CRC() {
|
||||
uint32_t computed_CRC = compute_CRC();
|
||||
|
||||
// Insert CRC in frame
|
||||
raw_data[11] = (computed_CRC >> 16) & 0xFF;
|
||||
raw_data[12] = (computed_CRC >> 8) & 0xFF;
|
||||
raw_data[13] = computed_CRC & 0xFF;
|
||||
}
|
||||
void push_byte(uint8_t byte) {
|
||||
if (index >= 14)
|
||||
return;
|
||||
|
||||
bool check_CRC() {
|
||||
uint32_t computed_CRC = compute_CRC();
|
||||
|
||||
if ((raw_data[11] != ((computed_CRC >> 16) & 0xFF)) ||
|
||||
(raw_data[12] != ((computed_CRC >> 8) & 0xFF)) ||
|
||||
(raw_data[13] != (computed_CRC & 0xFF))) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
return (index == 0);
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint8_t adsb_preamble[16];
|
||||
static const char icao_id_lut[65];
|
||||
alignas(4) uint8_t index { 0 };
|
||||
alignas(4) uint8_t raw_data[14] { }; // 112 bits at most
|
||||
uint32_t rx_timestamp { };
|
||||
raw_data[index++] = byte;
|
||||
}
|
||||
|
||||
uint32_t compute_CRC() {
|
||||
uint8_t adsb_crc[14] = { 0 }; // Temp buffer
|
||||
uint8_t b, c, s, bitn;
|
||||
const uint32_t crc_poly = 0x1205FFF;
|
||||
|
||||
// Copy frame data
|
||||
memcpy(adsb_crc, raw_data, 11);
|
||||
|
||||
// Compute CRC
|
||||
for (c = 0; c < 11; c++) {
|
||||
for (b = 0; b < 8; b++) {
|
||||
if ((adsb_crc[c] << b) & 0x80) {
|
||||
for (s = 0; s < 25; s++) {
|
||||
bitn = (c * 8) + b + s;
|
||||
if ((crc_poly >> s) & 1) adsb_crc[bitn >> 3] ^= (0x80 >> (bitn & 7));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (adsb_crc[11] << 16) + (adsb_crc[12] << 8) + adsb_crc[13];
|
||||
}
|
||||
uint8_t* get_raw_data() const {
|
||||
return (uint8_t*)raw_data;
|
||||
}
|
||||
|
||||
void make_CRC() {
|
||||
uint32_t computed_CRC = compute_CRC();
|
||||
|
||||
// Insert CRC in frame
|
||||
raw_data[11] = (computed_CRC >> 16) & 0xFF;
|
||||
raw_data[12] = (computed_CRC >> 8) & 0xFF;
|
||||
raw_data[13] = computed_CRC & 0xFF;
|
||||
}
|
||||
|
||||
bool check_CRC() {
|
||||
uint32_t computed_CRC = compute_CRC();
|
||||
|
||||
if ((raw_data[11] != ((computed_CRC >> 16) & 0xFF)) ||
|
||||
(raw_data[12] != ((computed_CRC >> 8) & 0xFF)) ||
|
||||
(raw_data[13] != (computed_CRC & 0xFF))) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
return (index == 0);
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint8_t adsb_preamble[16];
|
||||
static const char icao_id_lut[65];
|
||||
alignas(4) uint8_t index{0};
|
||||
alignas(4) uint8_t raw_data[14]{}; // 112 bits at most
|
||||
uint32_t rx_timestamp{};
|
||||
|
||||
uint32_t compute_CRC() {
|
||||
uint8_t adsb_crc[14] = {0}; // Temp buffer
|
||||
uint8_t b, c, s, bitn;
|
||||
const uint32_t crc_poly = 0x1205FFF;
|
||||
|
||||
// Copy frame data
|
||||
memcpy(adsb_crc, raw_data, 11);
|
||||
|
||||
// Compute CRC
|
||||
for (c = 0; c < 11; c++) {
|
||||
for (b = 0; b < 8; b++) {
|
||||
if ((adsb_crc[c] << b) & 0x80) {
|
||||
for (s = 0; s < 25; s++) {
|
||||
bitn = (c * 8) + b + s;
|
||||
if ((crc_poly >> s) & 1) adsb_crc[bitn >> 3] ^= (0x80 >> (bitn & 7));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (adsb_crc[11] << 16) + (adsb_crc[12] << 8) + adsb_crc[13];
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace adsb */
|
||||
|
||||
#endif/*__ADSB_FRAME_H__*/
|
||||
#endif /*__ADSB_FRAME_H__*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue