From 7818b0f5e0826a77344c0d6aa3f7929a0f042394 Mon Sep 17 00:00:00 2001 From: Karlis Goba Date: Wed, 2 Jan 2019 20:24:44 +0200 Subject: [PATCH] Added CRC checking --- Makefile | 4 ++-- decode_ft8.cpp | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 1046037..bf0e4cb 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,10 @@ run_tests: test gen_ft8: gen_ft8.o ft8/constants.o ft8/text.o ft8/pack_v2.o ft8/encode_v2.o common/wave.o $(CXX) $(LDFLAGS) -o $@ $^ -test: test.o ft8/v1/encode.o ft8/v1/pack.o ft8/v1/unpack.o ft8/pack_v2.o ft8/encode_v2.o ft8/text.o ft8/constants.o +test: test.o ft8/v1/encode.o ft8/v1/pack.o ft8/v1/unpack.o ft8/pack_v2.o ft8/encode_v2.o ft8/text.o ft8/constants.o fft/kiss_fftr.o fft/kiss_fft.o $(CXX) $(LDFLAGS) -o $@ $^ -decode_ft8: decode_ft8.o fft/kiss_fftr.o fft/kiss_fft.o ft8/decode.o ft8/ldpc.o ft8/unpack_v2.o ft8/text.o ft8/constants.o common/wave.o +decode_ft8: decode_ft8.o fft/kiss_fftr.o fft/kiss_fft.o ft8/decode.o ft8/encode_v2.o ft8/ldpc.o ft8/unpack_v2.o ft8/text.o ft8/constants.o common/wave.o $(CXX) $(LDFLAGS) -o $@ $^ clean: diff --git a/decode_ft8.cpp b/decode_ft8.cpp index ed0646a..a89adb4 100644 --- a/decode_ft8.cpp +++ b/decode_ft8.cpp @@ -7,6 +7,7 @@ #include "ft8/ldpc.h" #include "ft8/decode.h" #include "ft8/constants.h" +#include "ft8/encode_v2.h" #include "common/wave.h" #include "common/debug.h" @@ -202,23 +203,24 @@ int main(int argc, char **argv) { //ldpc_decode(log174, kLDPC_iterations, plain, &n_errors); if (n_errors > 0) { - //printf("ldpc_decode() = %d\n", n_errors); + LOG(LOG_DEBUG, "ldpc_decode() = %d (%.0f Hz)\n", n_errors, freq_hz); continue; } // Extract payload + CRC (first FT8_K bits) - uint8_t a91[12]; + uint8_t a91[FT8_K_BYTES]; pack_bits(plain, FT8_K, a91); - // TODO: check CRC - - // printf("%03d: score = %d freq = %.1f time = %.2f\n", idx, - // cand.score, freq_hz, time_sec); - // print_tones(kGray_map, log174); - // for (int i = 0; i < 12; ++i) { - // printf("%02x ", a91[i]); - // } - // printf("\n"); + // Extract CRC and check it + uint16_t chksum = ((a91[9] & 0x07) << 11) | (a91[10] << 3) | (a91[11] >> 5); + a91[9] &= 0xF8; + a91[10] = 0; + a91[11] = 0; + uint16_t chksum2 = ft8_v2::ft8_crc(a91, 96 - 14); + if (chksum != chksum2) { + LOG(LOG_DEBUG, "Checksum: message = %04x, CRC = %04x\n", chksum, chksum2); + continue; + } char message[kMax_message_length]; unpack77(a91, message);