diff --git a/SP5WWP/m17-packet/m17-packet-decode.c b/SP5WWP/m17-packet/m17-packet-decode.c index c444d03..530e41d 100644 --- a/SP5WWP/m17-packet/m17-packet-decode.c +++ b/SP5WWP/m17-packet/m17-packet-decode.c @@ -9,9 +9,6 @@ #include "viterbi.h" #include "crc.h" -#define DECODE_CALLSIGNS -//#define SHOW_VITERBI_ERRS - float sample; //last raw sample from the stdin float last[8]; //look-back buffer for finding syncwords float dist; //Euclidean distance for finding syncwords in the symbol stream @@ -28,6 +25,11 @@ uint8_t fl=0; //Frame=0 of LSF=1 int8_t last_fn; //last received frame number (-1 when idle) uint8_t pushed; //counter for pushed symbols +uint8_t skip_payload_crc_check=0; //skip payload CRC check +uint8_t callsigns=0; //decode callsigns? +uint8_t show_viterbi=0; //show Viterbi errors? +uint8_t text_only=0; //display text only (for text message mode) + //decodes a 6-byte long array to a callsign void decode_callsign(uint8_t *outp, const uint8_t *inp) { @@ -75,8 +77,51 @@ float eucl_norm(const float* in1, const int8_t* in2, uint8_t len) return sqrt(tmp); } -int main(void) +int main(int argc, char* argv[]) { + //scan command line options - if there are any + //TODO: support for strings with spaces, the code below is NOT foolproof! + if(argc>1) + { + for(uint8_t i=1; i>2)&0x1F; @@ -206,97 +247,117 @@ int main(void) //dump data if(packet_data[0]==0x05) //if a text message { - fprintf(stderr, "%s", &packet_data[1]); + if(skip_payload_crc_check) + { + fprintf(stderr, "%s\n", &packet_data[1]); + } + else + { + uint16_t p_len=strlen((const char*)packet_data); + uint16_t p_crc=CRC_M17(packet_data, p_len+1); + //fprintf(stderr, "rx=%02X%02X calc=%04X", packet_data[p_len+1], packet_data[p_len+2], p_crc); + if(p_crc==(uint16_t)packet_data[p_len+1]*256+(uint16_t)packet_data[p_len+2]) + { + fprintf(stderr, "%s\n", &packet_data[1]); + } + } } else { - fprintf(stderr, "PKT: "); - for(uint16_t i=0; i=4) { - for(uint8_t i=1; i