Aprs tx gps added, and save config added, path added (#2937)

This commit is contained in:
Totoo
2026-01-25 10:01:33 +01:00
committed by GitHub
parent 44d9ce00cd
commit 2319dcd0d6
11 changed files with 290 additions and 42 deletions
+55 -8
View File
@@ -31,20 +31,67 @@ using namespace ax25;
namespace aprs {
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) {
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, const std::string& path) {
AX25Frame frame;
char address[14] = {0};
memset(address, ' ', 14);
memcpy(&address[0], dest_address, 6);
memcpy(&address[7], src_address, 6);
size_t dest_len = strlen(dest_address);
if (dest_len > 6) dest_len = 6;
memcpy(&address[0], dest_address, dest_len);
size_t src_len = strlen(src_address);
if (src_len > 6) src_len = 6;
memcpy(&address[7], src_address, src_len);
// euquiq: According to ax.25 doc section 2.2.13.x.x and 2.4.1.2
// SSID need bits 5.6 set, so later when shifted it will end up being 011xxxx0 (xxxx = SSID number)
// Notice that if need to signal usage of AX.25 V2.0, (dest_ssid | 112); (MSb will need to be set at the end)
address[6] = (dest_ssid | 48);
address[13] = (src_ssid | 48);
// SSID need bits 5.6 set, so later when shifted it will end up being 011xxxx0 (xxxx = SSID number)
// Notice that if need to signal usage of AX.25 V2.0, (dest_ssid | 112); (MSb will need to be set at the end)
address[6] = (dest_ssid | 0x30);
address[13] = (src_ssid | 0x30);
frame.make_ui_frame(address, 0x03, protocol_id_t::NO_LAYER3, payload);
// fix path ssid bits. the result will be the same as above
std::string fixed_path = "";
const char* p = path.c_str();
while (*p) {
while (*p == ' ') p++;
if (!*p) break;
char call[6] = {' ', ' ', ' ', ' ', ' ', ' '};
int idx = 0;
while (*p && *p != '-' && *p != ',') {
if (*p != ' ') {
if (idx < 6) {
char c = *p;
if (c >= 'a' && c <= 'z') c -= 32;
call[idx++] = c;
}
}
p++;
}
int ssid = 0;
if (*p == '-') {
p++;
while (*p == ' ') p++;
while (*p >= '0' && *p <= '9') {
ssid = ssid * 10 + (*p - '0');
p++;
}
}
if (ssid >= 0 && ssid <= 15) {
for (int i = 0; i < 6; i++) fixed_path += call[i];
fixed_path += (char)(ssid | 0x30);
}
while (*p && *p != ',') p++;
if (*p == ',') p++;
}
frame.make_ui_frame(address, 0x03, protocol_id_t::NO_LAYER3, payload, fixed_path);
}
} /* namespace aprs */
+2 -1
View File
@@ -33,7 +33,8 @@ void make_aprs_frame(
const uint32_t src_ssid,
const char* dest_address,
const uint32_t dest_ssid,
const std::string& payload);
const std::string& payload,
const std::string& path = "");
} /* namespace aprs */
+21 -13
View File
@@ -26,13 +26,16 @@
namespace ax25 {
void AX25Frame::make_extended_field(char* const data, size_t length) {
void AX25Frame::make_extended_field(char* const data, size_t length, bool is_last) {
size_t i = 0;
for (i = 0; i < length - 1; i++)
add_data(data[i] << 1);
add_data((data[i] << 1) | 1);
if (is_last)
add_data((data[i] << 1) | 1);
else
add_data((data[i] << 1));
}
void AX25Frame::NRZI_add_bit(const uint32_t bit) {
@@ -92,7 +95,7 @@ void AX25Frame::add_checksum() {
add_byte(checksum >> 8, false, false);
}
void AX25Frame::make_ui_frame(char* const address, const uint8_t control, const uint8_t protocol, const std::string& info) {
void AX25Frame::make_ui_frame(char* const address, const uint8_t control, const uint8_t protocol, const std::string& info, const std::string& path) {
size_t i;
bb_data_ptr = (uint16_t*)shared_memory.bb_data.data;
@@ -103,22 +106,27 @@ void AX25Frame::make_ui_frame(char* const address, const uint8_t control, const
ones_counter = 0;
crc_ccitt.reset();
add_flag();
add_flag();
add_flag();
add_flag();
add_flag(); // 0x73
add_flag(); // 0x73
add_flag(); // 0x73
add_flag(); // 0x73
make_extended_field(address, 14);
add_data(control);
add_data(protocol);
// path must not contain the - character! just the callsign and SSID next to each other
bool has_path = (path.size() > 0 && path.size() <= 63 && path.size() % 7 == 0);
make_extended_field(address, 14, !has_path);
if (has_path) {
make_extended_field(const_cast<char*>(path.data()), path.size(), true);
}
add_data(control); // 0x03
add_data(protocol); // 0xf0
for (i = 0; i < info.size(); i++)
add_data(info[i]);
add_checksum();
add_checksum(); // fcs
add_flag();
add_flag();
add_flag(); // 0x73
add_flag(); // 0x73
flush();
}
+2 -2
View File
@@ -43,11 +43,11 @@ enum protocol_id_t {
class AX25Frame {
public:
void make_ui_frame(char* const address, const uint8_t control, const uint8_t protocol, const std::string& info);
void make_ui_frame(char* const address, const uint8_t control, const uint8_t protocol, const std::string& info, const std::string& path = "");
private:
void NRZI_add_bit(const uint32_t bit);
void make_extended_field(char* const data, size_t length);
void make_extended_field(char* const data, size_t length, bool is_last = false);
void add_byte(uint8_t byte, bool is_flag, bool is_data);
void add_data(uint8_t byte);
void add_checksum();