From 2019718b3f84daee751018de7b0593815e81d5b5 Mon Sep 17 00:00:00 2001 From: Manolis Surligas Date: Thu, 19 Sep 2019 21:09:22 +0300 Subject: [PATCH] Support frame tagging on the IEEE 802.15.4 decoder --- include/satnogs/ieee802_15_4_variant_decoder.h | 1 + lib/ax25_decoder.cc | 4 ++-- lib/ieee802_15_4_variant_decoder.cc | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/satnogs/ieee802_15_4_variant_decoder.h b/include/satnogs/ieee802_15_4_variant_decoder.h index 48b9aa0..ddb9a39 100644 --- a/include/satnogs/ieee802_15_4_variant_decoder.h +++ b/include/satnogs/ieee802_15_4_variant_decoder.h @@ -126,6 +126,7 @@ private: size_t d_length_field_len; decoding_state_t d_state; size_t d_cnt; + uint64_t d_frame_start_idx; uint8_t *d_pdu; decoder_status_t diff --git a/lib/ax25_decoder.cc b/lib/ax25_decoder.cc index de76564..a1e993a 100644 --- a/lib/ax25_decoder.cc +++ b/lib/ax25_decoder.cc @@ -112,7 +112,7 @@ ax25_decoder::_decode(decoder_status_t &status) d_bitstream.erase(d_bitstream.begin(), d_bitstream.begin() + i + 1); /* Increment the number of items read so far */ - incr_nitems_read(i); + incr_nitems_read(i + 1); enter_sync_state(); /* Mark possible start of the frame */ d_frame_start = nitems_read(); @@ -162,7 +162,7 @@ ax25_decoder::_decode(decoder_status_t &status) d_bitstream.erase(d_bitstream.begin(), d_bitstream.begin() + i + 1); /* Increment the number of items read so far */ - incr_nitems_read(i); + incr_nitems_read(i + 1); d_start_idx = d_bitstream.size(); return true; } diff --git a/lib/ieee802_15_4_variant_decoder.cc b/lib/ieee802_15_4_variant_decoder.cc index 4e0d014..29796c2 100644 --- a/lib/ieee802_15_4_variant_decoder.cc +++ b/lib/ieee802_15_4_variant_decoder.cc @@ -73,6 +73,7 @@ ieee802_15_4_variant_decoder::ieee802_15_4_variant_decoder( d_length_field_len(0), d_state(SEARCHING), d_cnt(0), + d_frame_start_idx(0), d_pdu(new uint8_t[max_len]) { for (uint8_t b : preamble) { @@ -173,6 +174,7 @@ ieee802_15_4_variant_decoder::decode_var_len(const void *in, int len) default: throw std::runtime_error("ieee802_15_4_variant_decoder: Invalid state"); } + incr_nitems_read(static_cast(status.consumed)); return status; } @@ -193,6 +195,7 @@ ieee802_15_4_variant_decoder::decode_const_len(const void *in, int len) default: throw std::runtime_error("ieee802_15_4_variant_decoder: Invalid state"); } + incr_nitems_read(static_cast(status.consumed)); return status; } @@ -215,6 +218,7 @@ ieee802_15_4_variant_decoder::search_preamble(const uint8_t *in, int len) shift_reg tmp = d_preamble_shift_reg ^ d_preamble; if (tmp.count() <= d_preamble_thrsh) { d_state = SEARCHING_SYNC; + d_frame_start_idx = nitems_read() + i + 1; d_cnt = 0; return i + 1; } @@ -304,8 +308,11 @@ ieee802_15_4_variant_decoder::decode_payload(decoder_status_t &status, status.decode_success = true; status.consumed = (i + 1) * 8; + metadata::add_time_iso8601(status.data); + metadata::add_sample_start(status.data, d_frame_start_idx); + metadata::add_sample_cnt(status.data, + nitems_read() + (i + 1) * 8 - d_frame_start_idx); if (check_crc()) { - metadata::add_time_iso8601(status.data); metadata::add_pdu(status.data, d_pdu + d_length_field_len, d_len - crc::crc_size(d_crc)); metadata::add_crc_valid(status.data, true);