Skip to content

Commit

Permalink
Detect nonstandard callsigns, use ftx_message_encode_nonstd() (type 4)
Browse files Browse the repository at this point in the history
The code was there already, but ftx_message_encode_std() needs to fail,
so that ftx_message_encode() will fall through and call
ftx_message_encode_nonstd(). This is the same check as in
packjt77.f90 line 1144:
  if(nwords.eq.2 .and. (.not.ok2 .or. index(w(2),'/').ge.2)) RETURN

And test.c tests ftx_message_encode(); however, a lot of messages have
the nonstandard callsign hashed then. Not sure if that's correct or if
we should expect the test to expand the hashed callsigns. Might fix kgoba#44
  • Loading branch information
ec1oud committed Oct 6, 2024
1 parent 50ee0c0 commit 822ff3a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
8 changes: 8 additions & 0 deletions ft8/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ ftx_message_rc_t ftx_message_encode_std(ftx_message_t* msg, ftx_callsign_hash_in
if (n28b < 0)
return FTX_MESSAGE_RC_ERROR_CALLSIGN2;

char *slash_de = strchr(call_de, '/');
uint8_t i3 = 1; // No suffix or /R
if (ends_with(call_to, "/P") || ends_with(call_de, "/P"))
{
Expand All @@ -175,6 +176,13 @@ ftx_message_rc_t ftx_message_encode_std(ftx_message_t* msg, ftx_callsign_hash_in
return FTX_MESSAGE_RC_ERROR_SUFFIX;
}
}
else
{
if ((!extra || !extra[0]) && slash_de && slash_de - call_de >= 2)
{
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
25 changes: 19 additions & 6 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,23 @@ void test_msg(const char* call_to_tx, const char* call_de_tx, const char* extra_
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);
ftx_message_rc_t rc_decode;
ftx_message_type_t msg_type = ftx_message_get_type(&msg);
switch (msg_type)
{
case FTX_MESSAGE_TYPE_STANDARD:
rc_decode = ftx_message_decode_std(&msg, NULL, call_to, call_de, extra);
break;
case FTX_MESSAGE_TYPE_NONSTD_CALL:
rc_decode = ftx_message_decode_nonstd(&msg, NULL, call_to, call_de, extra);
break;
default:
printf("msg_type %d isn't testable yet\n", msg_type);
break;
}
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(call_to, call_to_tx) || 0 == strcmp(call_to, "<...>"));
CHECK(0 == strcmp(call_de, call_de_tx) || 0 == strcmp(call_de, "<...>"));
CHECK(0 == strcmp(extra, extra_tx));
// CHECK(1 == 2);
TEST_END;
Expand All @@ -232,7 +245,7 @@ int main()
{
// 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", "LA/K7IHZ" };
const char* tokens[] = { "CQ", "QRZ" };
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 @@ -242,14 +255,14 @@ int main()
{
for (int idx_callsign2 = 0; idx_callsign2 < SIZEOF_ARRAY(callsigns); ++idx_callsign2)
{
test_std_msg(callsigns[idx_callsign], callsigns[idx_callsign2], grids[idx_grid]);
test_msg(callsigns[idx_callsign], callsigns[idx_callsign2], grids[idx_grid]);
}
}
for (int idx_token = 0; idx_token < SIZEOF_ARRAY(tokens); ++idx_token)
{
for (int idx_callsign2 = 0; idx_callsign2 < SIZEOF_ARRAY(callsigns); ++idx_callsign2)
{
test_std_msg(tokens[idx_token], callsigns[idx_callsign2], grids[idx_grid]);
test_msg(tokens[idx_token], callsigns[idx_callsign2], grids[idx_grid]);
}
}
}
Expand Down

0 comments on commit 822ff3a

Please sign in to comment.