Skip to content

Commit f215ced

Browse files
kholiaDhiru Kholia
authored andcommitted
Restore 'free text' encoding support
1 parent fc87d96 commit f215ced

2 files changed

Lines changed: 74 additions & 3 deletions

File tree

demo/gen_ft8.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void usage()
111111
printf("(Note that you might have to enclose your message in quote marks if it contains spaces)\n");
112112
}
113113

114+
void packtext77(const char* text, uint8_t* b77);
115+
114116
int main(int argc, char** argv)
115117
{
116118
// Expect two command-line arguments
@@ -134,9 +136,14 @@ int main(int argc, char** argv)
134136
ftx_message_rc_t rc = ftx_message_encode(&msg, NULL, message);
135137
if (rc != FTX_MESSAGE_RC_OK)
136138
{
137-
printf("Cannot parse message!\n");
138-
printf("RC = %d\n", (int)rc);
139-
return -2;
139+
// Try 'free text' encoding
140+
if (strlen(message) <= 13)
141+
packtext77(message, (uint8_t *)&msg.payload);
142+
else {
143+
printf("Cannot parse message!\n");
144+
printf("RC = %d\n", (int)rc);
145+
return -2;
146+
}
140147
}
141148

142149
printf("Packed data: ");

ft8/message.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,3 +992,67 @@ static int unpackgrid(uint16_t igrid4, uint8_t ir, char* extra)
992992

993993
return 0;
994994
}
995+
996+
void packtext77(const char* text, uint8_t* b77)
997+
{
998+
int length = strlen(text);
999+
1000+
// Skip leading and trailing spaces
1001+
while (*text == ' ' && *text != 0)
1002+
{
1003+
++text;
1004+
--length;
1005+
}
1006+
while (length > 0 && text[length - 1] == ' ')
1007+
{
1008+
--length;
1009+
}
1010+
1011+
// Clear the first 72 bits representing a long number
1012+
for (int i = 0; i < 9; ++i)
1013+
{
1014+
b77[i] = 0;
1015+
}
1016+
1017+
// Now express the text as base-42 number stored
1018+
// in the first 72 bits of b77
1019+
for (int j = 0; j < 13; ++j)
1020+
{
1021+
// Multiply the long integer in b77 by 42
1022+
uint16_t x = 0;
1023+
for (int i = 8; i >= 0; --i)
1024+
{
1025+
x += b77[i] * (uint16_t)42;
1026+
b77[i] = (x & 0xFF);
1027+
x >>= 8;
1028+
}
1029+
1030+
// Get the index of the current char
1031+
if (j < length)
1032+
{
1033+
int q = nchar(text[j], FT8_CHAR_TABLE_FULL);
1034+
x = (q > 0) ? q : 0;
1035+
}
1036+
else
1037+
{
1038+
x = 0;
1039+
}
1040+
// Here we double each added number in order to have the result multiplied
1041+
// by two as well, so that it's a 71 bit number left-aligned in 72 bits (9 bytes)
1042+
x <<= 1;
1043+
1044+
// Now add the number to our long number
1045+
for (int i = 8; i >= 0; --i)
1046+
{
1047+
if (x == 0)
1048+
break;
1049+
x += b77[i];
1050+
b77[i] = (x & 0xFF);
1051+
x >>= 8;
1052+
}
1053+
}
1054+
1055+
// Set n3=0 (bits 71..73) and i3=0 (bits 74..76)
1056+
b77[8] &= 0xFE;
1057+
b77[9] &= 0x00;
1058+
}

0 commit comments

Comments
 (0)