Added free-text encoding (as a fallback)
This commit is contained in:
parent
3f84b984fe
commit
dd6599bee6
2 changed files with 27 additions and 14 deletions
38
ft8/pack.cpp
38
ft8/pack.cpp
|
@ -223,7 +223,7 @@ int pack77_1(const char *msg, uint8_t *b77) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void packtext77(const char *text, uint8_t *b71) {
|
void packtext77(const char *text, uint8_t *b77) {
|
||||||
int length = strlen(text);
|
int length = strlen(text);
|
||||||
|
|
||||||
// Skip leading and trailing spaces
|
// Skip leading and trailing spaces
|
||||||
|
@ -235,20 +235,23 @@ void packtext77(const char *text, uint8_t *b71) {
|
||||||
--length;
|
--length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the first 72 bits representing a long number
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
b71[i] = 0;
|
b77[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now express the text as base-42 number stored
|
||||||
|
// in the first 72 bits of b77
|
||||||
for (int j = 0; j < 13; ++j) {
|
for (int j = 0; j < 13; ++j) {
|
||||||
// Multiply the long integer in b71 by 42
|
// Multiply the long integer in b77 by 42
|
||||||
uint16_t x = 0;
|
uint16_t x = 0;
|
||||||
for (int i = 8; i >= 0; --i) {
|
for (int i = 8; i >= 0; --i) {
|
||||||
x += b71[i] * (uint16_t)42;
|
x += b77[i] * (uint16_t)42;
|
||||||
b71[i] = (x & 0xFF);
|
b77[i] = (x & 0xFF);
|
||||||
x >>= 8;
|
x >>= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add index of the current char
|
// Get the index of the current char
|
||||||
if (j < length) {
|
if (j < length) {
|
||||||
int q = char_index(A0, text[j]);
|
int q = char_index(A0, text[j]);
|
||||||
x = (q > 0) ? q : 0;
|
x = (q > 0) ? q : 0;
|
||||||
|
@ -256,21 +259,30 @@ void packtext77(const char *text, uint8_t *b71) {
|
||||||
else {
|
else {
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
|
// Here we double each added number in order to have the result multiplied
|
||||||
|
// by two as well, so that it's a 71 bit number left-aligned in 72 bits (9 bytes)
|
||||||
|
x <<= 1;
|
||||||
|
|
||||||
|
// Now add the number to our long number
|
||||||
for (int i = 8; i >= 0; --i) {
|
for (int i = 8; i >= 0; --i) {
|
||||||
if (x == 0) break;
|
if (x == 0) break;
|
||||||
x += b71[i];
|
x += b77[i];
|
||||||
b71[i] = (x & 0xFF);
|
b77[i] = (x & 0xFF);
|
||||||
x >>= 8;
|
x >>= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set n3=0 (bits 71..73) and i3=0 (bits 74..76)
|
||||||
|
b77[8] &= 0xFE;
|
||||||
|
b77[9] &= 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int pack77(const char *msg, uint8_t *c77) {
|
int pack77(const char *msg, uint8_t *c77) {
|
||||||
// Check Type 1 (Standard 77-bit message) or Type 2, with optional "/P"
|
// Check Type 1 (Standard 77-bit message) or Type 2, with optional "/P"
|
||||||
//if (starts_with(msg, "CQ ")) {
|
if (0 == pack77_1(msg, c77)) {
|
||||||
return pack77_1(msg, c77);
|
return 0;
|
||||||
//}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// Check 0.5 (telemetry)
|
// Check 0.5 (telemetry)
|
||||||
|
@ -281,8 +293,8 @@ int pack77(const char *msg, uint8_t *c77) {
|
||||||
|
|
||||||
// Default to free text
|
// Default to free text
|
||||||
// i3=0 n3=0
|
// i3=0 n3=0
|
||||||
// packtext77(msg(1:13),c77(1:71))
|
packtext77(msg, c77);
|
||||||
// write(c77(72:77),'(2b3.3)') n3,i3
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace
|
}; // namespace
|
||||||
|
|
|
@ -285,7 +285,8 @@ int unpack_telemetry(const uint8_t *a71, char *telemetry) {
|
||||||
int unpack77(const uint8_t *a77, char *message) {
|
int unpack77(const uint8_t *a77, char *message) {
|
||||||
uint8_t n3, i3;
|
uint8_t n3, i3;
|
||||||
|
|
||||||
n3 = (a77[9] >> 6) & 0x07;
|
// Extract n3 (bits 71..73) and i3 (bits 74..76)
|
||||||
|
n3 = ((a77[8] << 2) & 0x04) | ((a77[9] >> 6) & 0x03);
|
||||||
i3 = (a77[9] >> 3) & 0x07;
|
i3 = (a77[9] >> 3) & 0x07;
|
||||||
|
|
||||||
if (i3 == 0 && n3 == 0) {
|
if (i3 == 0 && n3 == 0) {
|
||||||
|
|
Loading…
Reference in a new issue