diff --git a/horusdemodlib/__init__.py b/horusdemodlib/__init__.py index bbab024..1276d02 100755 --- a/horusdemodlib/__init__.py +++ b/horusdemodlib/__init__.py @@ -1 +1 @@ -__version__ = "0.1.4" +__version__ = "0.1.5" diff --git a/horusdemodlib/decoder.py b/horusdemodlib/decoder.py index e9969c1..bdfe322 100644 --- a/horusdemodlib/decoder.py +++ b/horusdemodlib/decoder.py @@ -217,11 +217,21 @@ def parse_ukhas_string(sentence:str) -> dict: # Perform some sanity checks on the data. # Attempt to parse the time string. This will throw an error if any values are invalid. - try: - _time_dt = datetime.datetime.strptime(_time, "%H:%M:%S") - except: - raise ValueError("Could not parse RTTY Sentence - Invalid Time.") + if ':' in _time: + try: + _time_dt = datetime.datetime.strptime(_time, "%H:%M:%S") + except: + raise ValueError("Could not parse RTTY Sentence - Invalid Time.") + else: + # Also handle cases where no :'s are used. + try: + _time_dt = datetime.datetime.strptime(_time, "%H%M%S") + except: + raise ValueError("Could not parse RTTY Sentence - Invalid Time.") + # Convert time back to something consistent. + _time = _time_dt.strftime("%H:%M:%S") + # Check if the lat/long is 0.0,0.0 - no point passing this along. # Commented out for now... passing through no-lock sentences is useful for debugging. #if _latitude == 0.0 or _longitude == 0.0: @@ -311,7 +321,8 @@ if __name__ == "__main__": # RTTY Decoder Tests tests = [ - '$$HORUS,6,06:43:16,0.000000,0.000000,0,0,0,1801,20*1DA2' + '$$HORUS,6,06:43:16,0.000000,0.000000,0,0,0,1801,20*1DA2', + '$$$DirkDuyvel,416,143957,53.15629,7.29188,10925,14,2.88,11,2640,1,80*3C6C' ] for _test in tests: diff --git a/pyproject.toml b/pyproject.toml index ab1e5f3..43b11eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "horusdemodlib" -version = "0.1.4" +version = "0.1.5" description = "Project Horus HAB Telemetry Demodulators" authors = ["Mark Jessop"] license = "LGPL-2.1-or-later" diff --git a/src/horus_api.c b/src/horus_api.c index b432433..f9d18c7 100644 --- a/src/horus_api.c +++ b/src/horus_api.c @@ -64,9 +64,9 @@ struct horus { int8_t uw_horus_rtty_7N2[] = { 0,0,1,0,0,1,0,1,1,0, 0,0,1,0,0,1,0,1,1,0, - 0,0,1,0,0,1,0,1,1,0, - 0,0,1,0,0,1,0,1,1,0, - 0,0,1,0,0,1,0,1,1,0 +// 0,0,1,0,0,1,0,1,1,0, +// 0,0,1,0,0,1,0,1,1,0, +// 0,0,1,0,0,1,0,1,1,0 }; /* Unique word for Horus Binary V1 */ @@ -330,7 +330,7 @@ int extract_horus_rtty(struct horus *hstates, char ascii_out[], int uw_loc) { int st = uw_loc; /* first bit of first char */ int en = hstates->max_packet_len - nfield; /* last bit of max length packet */ - int i, j, endpacket, nout, crc_ok; + int i, j, k, endpacket, nout, crc_ok, rtty_start; uint8_t char_dec; char *pout, *ptx_crc; uint16_t rx_crc, tx_crc; @@ -357,7 +357,19 @@ int extract_horus_rtty(struct horus *hstates, char ascii_out[], int uw_loc) { if (!endpacket && (char_dec == 42)) { endpacket = 1; - rx_crc = horus_l2_gen_crc16((uint8_t*)&ascii_out[5], nout-5); + rtty_start = 0; + // Find the end of the $$s + for(k = 0; k<8; k++){ + if(ascii_out[k] != 36){ + rtty_start = k; + break; + } + } + if(hstates->verbose){ + fprintf(stderr, " Found %d $s\n", rtty_start); + } + + rx_crc = horus_l2_gen_crc16((uint8_t*)&ascii_out[rtty_start], nout-rtty_start); ptx_crc = pout + 1; /* start of tx CRC */ if (hstates->verbose){ fprintf(stderr, " begin endpacket\n"); @@ -692,6 +704,16 @@ int horus_rx(struct horus *hstates, char ascii_out[], short demod_in[], int quad if (hstates->mode == HORUS_MODE_RTTY_7N2) { packet_detected = extract_horus_rtty(hstates, ascii_out, uw_loc); + + if (packet_detected){ + // If we have found a packet, advance the bits enough that we don't detect the + // same packet again, if it has more than 2x $$s. + // NEED TO CHECK THIS DOESN'T CAUSE SEGFAULTS! + for(i=0,j=100; i<100; i++,j++) { + hstates->rx_bits[i] = hstates->rx_bits[j]; + hstates->soft_bits[i] = hstates->soft_bits[j]; + } + } } if (hstates->mode == HORUS_MODE_BINARY_V1) { packet_detected = extract_horus_binary_v1(hstates, ascii_out, uw_loc);