Skip to content

Commit

Permalink
Add support of non-standart callsigns with prefixes
Browse files Browse the repository at this point in the history
Closes kgoba#44
  • Loading branch information
gdyuldin committed Jan 3, 2025
1 parent 7a53c62 commit 117022b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 35 deletions.
75 changes: 63 additions & 12 deletions ft8/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ ftx_message_rc_t ftx_message_encode(ftx_message_t* msg, ftx_callsign_hash_interf
rc = ftx_message_encode_nonstd(msg, hash_if, call_to, call_de, extra);
if (rc == FTX_MESSAGE_RC_OK)
return rc;

// rc = ftx_message_encode_telemetry_hex(msg, hash_if, call_to, call_de, extra);
rc = ftx_message_encode_free(msg, message_text);
if (rc == FTX_MESSAGE_RC_OK)
return rc;

return rc;
}
Expand Down Expand Up @@ -176,6 +177,13 @@ ftx_message_rc_t ftx_message_encode_std(ftx_message_t* msg, ftx_callsign_hash_in
}
}

char *slash_de = strchr(call_de, '/');
uint8_t icq = (uint8_t)equals(call_to, "CQ");
if (slash_de && (slash_de - call_de >= 2) && icq && !(equals(slash_de, "/P") || equals(slash_de, "/R")))
{
return FTX_MESSAGE_RC_ERROR_CALLSIGN2; // nonstandard call: need a type 4 message
}

uint16_t igrid4 = packgrid(extra);
LOG(LOG_DEBUG, "igrid4 = %d\n", igrid4);

Expand Down Expand Up @@ -215,14 +223,11 @@ ftx_message_rc_t ftx_message_encode_nonstd(ftx_message_t* msg, ftx_callsign_hash
int len_call_to = strlen(call_to);
int len_call_de = strlen(call_de);

// if ((icq != 0) || (pack_basecall(call_to, len_call_to) >= 0))
// {
// if (pack_basecall(call_de, len_call_de) >= 0)
// {
// // no need for encode_nonstd, should use encode_std
// return FTX_MESSAGE_RC_ERROR_CALLSIGN2;
// }
// }
if ((icq != 0) || (pack_basecall(call_to, len_call_to) < 0))
{
// CQ with non-std call, should use free text (without hash)
return FTX_MESSAGE_RC_ERROR_CALLSIGN2;
}

if ((icq == 0) && ((len_call_to < 3)))
return FTX_MESSAGE_RC_ERROR_CALLSIGN1;
Expand Down Expand Up @@ -293,6 +298,53 @@ ftx_message_rc_t ftx_message_encode_nonstd(ftx_message_t* msg, ftx_callsign_hash
return FTX_MESSAGE_RC_OK;
}

ftx_message_rc_t ftx_message_encode_free(ftx_message_t* msg, const char* text)
{
uint8_t str_len = strlen(text);
if (str_len > 13) {
// Too long text
return FTX_MESSAGE_RC_ERROR_TYPE;
}

uint8_t b71[9];
memset(b71, 0, 9);
int8_t cid;
char c;

for (int idx = 0; idx < 13; idx++)
{
if (idx < str_len) {
c = text[idx];
} else {
c = ' ';
}
cid = nchar(c, FT8_CHAR_TABLE_FULL);
if (cid == -1) {
return FTX_MESSAGE_RC_ERROR_TYPE;
}
uint16_t rem = cid;
for (int i = 8; i >= 0; i--)
{
rem += b71[i] * 42;
b71[i] = rem & 0xff;
rem = rem >> 8;
}
}
return ftx_message_encode_telemetry(msg, b71);
}

ftx_message_rc_t ftx_message_encode_telemetry(ftx_message_t* msg, const uint8_t* telemetry)
{
// Shift bits in telemetry left by 1 bit to right-align the data
uint8_t carry = 0;
for (int i = 8; i >= 0; --i)
{
msg->payload[i] = (telemetry[i] << 1) | (carry >> 7);
carry = telemetry[i] & 0x80;
}
return FTX_MESSAGE_RC_OK;
}

ftx_message_rc_t ftx_message_decode(const ftx_message_t* msg, ftx_callsign_hash_interface_t* hash_if, char* message)
{
ftx_message_rc_t rc;
Expand Down Expand Up @@ -340,7 +392,7 @@ ftx_message_rc_t ftx_message_decode(const ftx_message_t* msg, ftx_callsign_hash_
{
message = append_string(message, " ");
message = append_string(message, field2);
if (field3 != NULL)
if ((field3 != NULL) && (field3[0] != NULL))
{
message = append_string(message, " ");
message = append_string(message, field3);
Expand Down Expand Up @@ -452,7 +504,6 @@ ftx_message_rc_t ftx_message_decode_nonstd(const ftx_message_t* msg, ftx_callsig
extra[0] = '\0';
}
strcpy(call_de, call_2);

LOG(LOG_INFO, "Decoded non-standard (type %d) message [%s] [%s] [%s]\n", i3, call_to, call_de, extra);
return FTX_MESSAGE_RC_OK;
}
Expand Down
5 changes: 2 additions & 3 deletions ft8/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ ftx_message_rc_t ftx_message_encode_std(ftx_message_t* msg, ftx_callsign_hash_in
/// Pack Type 4 (One nonstandard call and one hashed call) message
ftx_message_rc_t ftx_message_encode_nonstd(ftx_message_t* msg, ftx_callsign_hash_interface_t* hash_if, const char* call_to, const char* call_de, const char* extra);

void ftx_message_encode_free(const char* text);
void ftx_message_encode_telemetry_hex(const char* telemetry_hex);
void ftx_message_encode_telemetry(const uint8_t* telemetry);
ftx_message_rc_t ftx_message_encode_free(ftx_message_t* msg, const char* text);
ftx_message_rc_t ftx_message_encode_telemetry(ftx_message_t* msg, const uint8_t* telemetry);

ftx_message_rc_t ftx_message_decode(const ftx_message_t* msg, ftx_callsign_hash_interface_t* hash_if, char* message);
ftx_message_rc_t ftx_message_decode_std(const ftx_message_t* msg, ftx_callsign_hash_interface_t* hash_if, char* call_to, char* call_de, char* extra);
Expand Down
31 changes: 11 additions & 20 deletions test/test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -136,34 +137,21 @@ void test_std_msg(const char* call_to_tx, const char* call_de_tx, const char* ex
TEST_END;
}

void test_msg(const char* call_to_tx, const char* call_de_tx, const char* extra_tx)
void test_msg(const char* message_text, const char* expected, ftx_callsign_hash_interface_t *hash_if)
{
char message_text[12 + 12 + 20];
char* copy_ptr = message_text;
copy_ptr = stpcpy(copy_ptr, call_to_tx);
copy_ptr = stpcpy(copy_ptr, " ");
copy_ptr = stpcpy(copy_ptr, call_de_tx);
if (strlen(extra_tx) > 0)
{
copy_ptr = stpcpy(copy_ptr, " ");
copy_ptr = stpcpy(copy_ptr, extra_tx);
}
printf("Testing [%s]\n", message_text);

ftx_message_t msg;
ftx_message_init(&msg);

ftx_message_rc_t rc_encode = ftx_message_encode(&msg, NULL, message_text);
ftx_message_rc_t rc_encode = ftx_message_encode(&msg, hash_if, message_text);
CHECK(rc_encode == FTX_MESSAGE_RC_OK);

char call_to[14];
char call_de[14];
char extra[14];
ftx_message_rc_t rc_decode = ftx_message_decode_std(&msg, NULL, call_to, call_de, extra);
char message_decoded[12+12+20];
ftx_message_rc_t rc_decode = ftx_message_decode(&msg, hash_if, message_decoded);
CHECK(rc_decode == FTX_MESSAGE_RC_OK);
CHECK(0 == strcmp(call_to, call_to_tx));
CHECK(0 == strcmp(call_de, call_de_tx));
CHECK(0 == strcmp(extra, extra_tx));
printf("Decoded [%s]\n", message_decoded);
CHECK(0 == strcmp(expected, message_decoded));
// CHECK(1 == 2);
TEST_END;
}
Expand All @@ -175,7 +163,7 @@ int main()
hashtable_init(256);
// test1();
// test4();
const char* callsigns[] = { "YL3JG", "W1A", "W1A/R", "W5AB", "W8ABC", "DE6ABC", "DE6ABC/R", "DE7AB", "DE9A", "3DA0X", "3DA0XYZ", "3DA0XYZ/R", "3XZ0AB", "3XZ0A" };
const char* callsigns[] = { "YL3JG", "W1A", "W1A/R", "W5AB", "W8ABC", "DE6ABC", "DE6ABC/R", "DE7AB", "DE9A", "3DA0X", "3DA0XYZ", "3DA0XYZ/R", "3XZ0AB", "3XZ0A"};
const char* tokens[] = { "CQ", "QRZ", "CQ_123", "CQ_000", "CQ_POTA", "CQ_SA", "CQ_O", "CQ_ASD" };
const char* grids[] = { "KO26", "RR99", "AA00", "RR09", "AA01", "RRR", "RR73", "73", "R+10", "R+05", "R-12", "R-02", "+10", "+05", "-02", "-02", "" };

Expand All @@ -196,6 +184,9 @@ int main()
}
}
}
test_msg("CQ EA8/G5LSI", "CQ EA8/G5LSI", NULL);
test_msg("EA8/G5LSI R2RFE RR73", "<EA8/G5LSI> R2RFE RR73", &hash_if);
test_msg("R2RFE/P EA8/G5LSI R+12", "R2RFE/P <EA8/G5LSI> R+12", &hash_if);

// test_std_msg("YOMAMA", "MYMAMA/QRP", "73");

Expand Down

0 comments on commit 117022b

Please sign in to comment.