mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-15 08:47:51 +00:00
Added basic APRS transmit
Added goertzel algo Updated binary
This commit is contained in:
@@ -29,17 +29,20 @@ using namespace ax25;
|
||||
|
||||
namespace aprs {
|
||||
|
||||
void make_aprs_frame(char * address_dest, char * address_src) {
|
||||
void make_aprs_frame(const char * src_address, const uint32_t src_ssid,
|
||||
const char * dest_address, const uint32_t dest_ssid,
|
||||
const std::string& payload) {
|
||||
|
||||
AX25Frame frame;
|
||||
|
||||
char address[14] = { 0 };
|
||||
uint8_t info[7] = { 0 }; //{ 'F','U','R','R','T','E','K' };
|
||||
|
||||
// Both SSIDs are 0
|
||||
memcpy(&address[0], address_dest, 6);
|
||||
memcpy(&address[7], address_src, 6);
|
||||
memcpy(&address[0], dest_address, 6);
|
||||
address[6] = (dest_ssid & 15) << 1;
|
||||
memcpy(&address[7], src_address, 6);
|
||||
address[13] = (src_ssid & 15) << 1;
|
||||
|
||||
frame.make_ui_frame(address, 0x03, protocol_id_t::NO_LAYER3, info, sizeof(info));
|
||||
frame.make_ui_frame(address, 0x03, protocol_id_t::NO_LAYER3, payload);
|
||||
}
|
||||
|
||||
} /* namespace aprs */
|
||||
|
@@ -28,7 +28,10 @@
|
||||
|
||||
namespace aprs {
|
||||
|
||||
void make_aprs_frame();
|
||||
void make_aprs_frame(
|
||||
const char * src_address, const uint32_t src_ssid,
|
||||
const char * dest_address, const uint32_t dest_ssid,
|
||||
const std::string& payload);
|
||||
|
||||
} /* namespace aprs */
|
||||
|
||||
|
@@ -35,39 +35,42 @@ void AX25Frame::make_extended_field(char * const data, size_t length) {
|
||||
add_data((data[i] << 1) | 1);
|
||||
}
|
||||
|
||||
void AX25Frame::add_byte(uint8_t byte, bool is_flag, bool is_data) {
|
||||
size_t i;
|
||||
void AX25Frame::NRZI_add_bit(const uint32_t bit) {
|
||||
if (!bit)
|
||||
current_bit ^= 1; // Zero: flip
|
||||
|
||||
for (i = 0; i < 8; ) {
|
||||
current_byte <<= 1;
|
||||
current_byte |= current_bit;
|
||||
|
||||
bit_counter++;
|
||||
|
||||
if (bit_counter == 8) {
|
||||
bit_counter = 0;
|
||||
*bb_data_ptr = current_byte;
|
||||
bb_data_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
void AX25Frame::add_byte(uint8_t byte, bool is_flag, bool is_data) {
|
||||
uint32_t bit;
|
||||
|
||||
if (is_data)
|
||||
crc_ccitt.process_byte(byte);
|
||||
|
||||
for (uint32_t i = 0; i < 8; i++) {
|
||||
bit = (byte >> i) & 1;
|
||||
|
||||
if (!(byte & 1)) {
|
||||
current_bit ^= 1; // Zero: flip
|
||||
ones_counter = 0;
|
||||
byte >>= 1;
|
||||
i++;
|
||||
} else {
|
||||
if (bit)
|
||||
ones_counter++;
|
||||
if ((ones_counter == 5) && (!is_flag)) {
|
||||
current_bit ^= 1; // Stuff zero: flip
|
||||
ones_counter = 0;
|
||||
} else {
|
||||
byte >>= 1;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
ones_counter = 0;
|
||||
|
||||
if ((ones_counter == 6) && (!is_flag)) {
|
||||
NRZI_add_bit(0);
|
||||
ones_counter = 0;
|
||||
}
|
||||
|
||||
if (is_data)
|
||||
crc_ccitt.process_bit(current_bit);
|
||||
current_byte <<= 1;
|
||||
current_byte |= current_bit;
|
||||
|
||||
if (bit_counter == 7) {
|
||||
bit_counter = 0;
|
||||
*bb_data_ptr = current_byte;
|
||||
bb_data_ptr++;
|
||||
} else {
|
||||
bit_counter++;
|
||||
}
|
||||
NRZI_add_bit(bit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,32 +89,38 @@ void AX25Frame::add_data(uint8_t byte) {
|
||||
|
||||
void AX25Frame::add_checksum() {
|
||||
auto checksum = crc_ccitt.checksum();
|
||||
add_byte(checksum >> 8, false, false);
|
||||
add_byte(checksum, false, false);
|
||||
add_byte(checksum >> 8, false, false);
|
||||
}
|
||||
|
||||
void AX25Frame::make_ui_frame(char * const address, const uint8_t control,
|
||||
const uint8_t protocol, uint8_t * const info, size_t length) {
|
||||
const uint8_t protocol, const std::string& info) {
|
||||
|
||||
size_t i;
|
||||
|
||||
bb_data_ptr = shared_memory.bb_data.data;
|
||||
bb_data_ptr = (uint16_t*)shared_memory.bb_data.data;
|
||||
memset(bb_data_ptr, 0, sizeof(shared_memory.bb_data.data));
|
||||
bit_counter = 0;
|
||||
current_bit = 0;
|
||||
current_byte = 0;
|
||||
ones_counter = 0;
|
||||
crc_ccitt.reset();
|
||||
|
||||
add_flag();
|
||||
add_flag();
|
||||
add_flag();
|
||||
add_flag();
|
||||
|
||||
make_extended_field(address, 14);
|
||||
add_data(control);
|
||||
add_data(protocol);
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
for (i = 0; i < info.size(); i++)
|
||||
add_data(info[i]);
|
||||
|
||||
add_checksum();
|
||||
|
||||
add_flag();
|
||||
add_flag();
|
||||
|
||||
flush();
|
||||
|
@@ -44,9 +44,10 @@ enum protocol_id_t {
|
||||
class AX25Frame {
|
||||
public:
|
||||
void make_ui_frame(char * const address, const uint8_t control, const uint8_t protocol,
|
||||
uint8_t * const info, size_t length);
|
||||
const std::string& info);
|
||||
|
||||
private:
|
||||
void NRZI_add_bit(const uint32_t bit);
|
||||
void make_extended_field(char * const data, size_t length);
|
||||
void add_byte(uint8_t byte, bool is_flag, bool is_data);
|
||||
void add_data(uint8_t byte);
|
||||
@@ -54,13 +55,13 @@ private:
|
||||
void add_flag();
|
||||
void flush();
|
||||
|
||||
uint8_t * bb_data_ptr { nullptr };
|
||||
uint16_t * bb_data_ptr { nullptr };
|
||||
uint8_t current_bit { 0 };
|
||||
uint8_t current_byte { 0 };
|
||||
size_t bit_counter { 0 };
|
||||
uint8_t ones_counter { 0 };
|
||||
|
||||
CRC<16> crc_ccitt { 0x1021, 0xFFFF };
|
||||
CRC<16, true, true> crc_ccitt { 0x1021, 0xFFFF, 0xFFFF };
|
||||
};
|
||||
|
||||
} /* namespace ax25 */
|
||||
|
Reference in New Issue
Block a user