|
|
|
@ -879,6 +879,9 @@ static void encode_digits(const uint8_t *digits, char *bits) |
|
|
|
|
bits[(i << 1) + 1] = x[i - 6] + '0'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* debug parity check */ |
|
|
|
|
//#define DEBUG_DECODE
|
|
|
|
|
|
|
|
|
|
/* decode digits from 140 bits (not including sync) */ |
|
|
|
|
// FIXME: do real convolutional decoding
|
|
|
|
|
static int decode_digits(uint8_t *digits, const char *bits, int callack) |
|
|
|
@ -888,8 +891,12 @@ static int decode_digits(uint8_t *digits, const char *bits, int callack) |
|
|
|
|
|
|
|
|
|
/* information bits */ |
|
|
|
|
for (i = 0; i < 6; i++) { |
|
|
|
|
if (bits[(i << 1) + 1] != '0') |
|
|
|
|
if (bits[(i << 1) + 1] != '0') { |
|
|
|
|
#ifdef DEBUG_DECODE |
|
|
|
|
PDEBUG(DFRAME, DEBUG_DEBUG, "Frame bad at information bit #%d.\n", i); |
|
|
|
|
#endif |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (i = 6; i < 70; i++) |
|
|
|
|
x[i - 6] = bits[(i << 1) + 1] - '0'; |
|
|
|
@ -908,13 +915,22 @@ static int decode_digits(uint8_t *digits, const char *bits, int callack) |
|
|
|
|
digits[14] = 0; |
|
|
|
|
digits[15] = 0; |
|
|
|
|
short_frame = 1; |
|
|
|
|
#ifdef DEBUG_DECODE |
|
|
|
|
PDEBUG(DFRAME, DEBUG_DEBUG, "Received shortened frame\n"); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* parity check bits */ |
|
|
|
|
for (i = 0; i < 3; i++) { |
|
|
|
|
if (bits[(i << 1)] != '1' - x[i]) |
|
|
|
|
if (bits[(i << 1)] != '1' - x[i]) { |
|
|
|
|
#ifdef DEBUG_DECODE |
|
|
|
|
PDEBUG(DFRAME, DEBUG_DEBUG, "Frame bad at parity bit #%d.\n", i); |
|
|
|
|
#endif |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#if 0 |
|
|
|
|
#warning this check does not work, since we get error even at bit 50 |
|
|
|
|
for (i = 3; i < ((short_frame) ? 52 : 64); i++) { |
|
|
|
|
if (bits[(i << 1)] != '1' - (x[i] ^ x[i - 3])) { |
|
|
|
|
/* According to NMT Doc 450-3, bits after Y(114) shall
|
|
|
|
@ -930,18 +946,43 @@ static int decode_digits(uint8_t *digits, const char *bits, int callack) |
|
|
|
|
digits[13] = 0; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
#ifdef DEBUG_DECODE |
|
|
|
|
PDEBUG(DFRAME, DEBUG_DEBUG, "Frame bad at parity bit #%d.\n", i); |
|
|
|
|
#endif |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
/* Tests showed corrupt frame at parity #50 (i == 50)
|
|
|
|
|
* We just ignore whatever we receive after 48 bits of checksum. |
|
|
|
|
* This is not the correct approach, but in case of a corrupt |
|
|
|
|
* frame 10.a, we would drop it, if it failes later checks. |
|
|
|
|
*/ |
|
|
|
|
for (i = 3; i < ((short_frame) ? 48 : 64); i++) { |
|
|
|
|
if (bits[(i << 1)] != '1' - (x[i] ^ x[i - 3])) { |
|
|
|
|
#ifdef DEBUG_DECODE |
|
|
|
|
PDEBUG(DFRAME, DEBUG_DEBUG, "Frame bad at parity bit #%d.\n", i); |
|
|
|
|
#endif |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (short_frame) |
|
|
|
|
return 0; |
|
|
|
|
for (i = 64; i < 67; i++) { |
|
|
|
|
if (bits[(i << 1)] != '1' - x[i - 3]) |
|
|
|
|
if (bits[(i << 1)] != '1' - x[i - 3]) { |
|
|
|
|
#ifdef DEBUG_DECODE |
|
|
|
|
PDEBUG(DFRAME, DEBUG_DEBUG, "Frame bad at parity bit #%d.\n", i); |
|
|
|
|
#endif |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (i = 67; i < 70; i++) { |
|
|
|
|
if (bits[(i << 1)] != '1') |
|
|
|
|
if (bits[(i << 1)] != '1') { |
|
|
|
|
#ifdef DEBUG_DECODE |
|
|
|
|
PDEBUG(DFRAME, DEBUG_DEBUG, "Frame bad at parity bit #%d.\n", i); |
|
|
|
|
#endif |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|