Support frame tagging on the IEEE 802.15.4 decoder

This commit is contained in:
Manolis Surligas 2019-09-19 21:09:22 +03:00
parent ab442833c2
commit 2019718b3f
3 changed files with 11 additions and 3 deletions

View File

@ -126,6 +126,7 @@ private:
size_t d_length_field_len; size_t d_length_field_len;
decoding_state_t d_state; decoding_state_t d_state;
size_t d_cnt; size_t d_cnt;
uint64_t d_frame_start_idx;
uint8_t *d_pdu; uint8_t *d_pdu;
decoder_status_t decoder_status_t

View File

@ -112,7 +112,7 @@ ax25_decoder::_decode(decoder_status_t &status)
d_bitstream.erase(d_bitstream.begin(), d_bitstream.erase(d_bitstream.begin(),
d_bitstream.begin() + i + 1); d_bitstream.begin() + i + 1);
/* Increment the number of items read so far */ /* Increment the number of items read so far */
incr_nitems_read(i); incr_nitems_read(i + 1);
enter_sync_state(); enter_sync_state();
/* Mark possible start of the frame */ /* Mark possible start of the frame */
d_frame_start = nitems_read(); d_frame_start = nitems_read();
@ -162,7 +162,7 @@ ax25_decoder::_decode(decoder_status_t &status)
d_bitstream.erase(d_bitstream.begin(), d_bitstream.erase(d_bitstream.begin(),
d_bitstream.begin() + i + 1); d_bitstream.begin() + i + 1);
/* Increment the number of items read so far */ /* Increment the number of items read so far */
incr_nitems_read(i); incr_nitems_read(i + 1);
d_start_idx = d_bitstream.size(); d_start_idx = d_bitstream.size();
return true; return true;
} }

View File

@ -73,6 +73,7 @@ ieee802_15_4_variant_decoder::ieee802_15_4_variant_decoder(
d_length_field_len(0), d_length_field_len(0),
d_state(SEARCHING), d_state(SEARCHING),
d_cnt(0), d_cnt(0),
d_frame_start_idx(0),
d_pdu(new uint8_t[max_len]) d_pdu(new uint8_t[max_len])
{ {
for (uint8_t b : preamble) { for (uint8_t b : preamble) {
@ -173,6 +174,7 @@ ieee802_15_4_variant_decoder::decode_var_len(const void *in, int len)
default: default:
throw std::runtime_error("ieee802_15_4_variant_decoder: Invalid state"); throw std::runtime_error("ieee802_15_4_variant_decoder: Invalid state");
} }
incr_nitems_read(static_cast<uint64_t>(status.consumed));
return status; return status;
} }
@ -193,6 +195,7 @@ ieee802_15_4_variant_decoder::decode_const_len(const void *in, int len)
default: default:
throw std::runtime_error("ieee802_15_4_variant_decoder: Invalid state"); throw std::runtime_error("ieee802_15_4_variant_decoder: Invalid state");
} }
incr_nitems_read(static_cast<uint64_t>(status.consumed));
return status; 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; shift_reg tmp = d_preamble_shift_reg ^ d_preamble;
if (tmp.count() <= d_preamble_thrsh) { if (tmp.count() <= d_preamble_thrsh) {
d_state = SEARCHING_SYNC; d_state = SEARCHING_SYNC;
d_frame_start_idx = nitems_read() + i + 1;
d_cnt = 0; d_cnt = 0;
return i + 1; return i + 1;
} }
@ -304,8 +308,11 @@ ieee802_15_4_variant_decoder::decode_payload(decoder_status_t &status,
status.decode_success = true; status.decode_success = true;
status.consumed = (i + 1) * 8; 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()) { if (check_crc()) {
metadata::add_time_iso8601(status.data);
metadata::add_pdu(status.data, d_pdu + d_length_field_len, metadata::add_pdu(status.data, d_pdu + d_length_field_len,
d_len - crc::crc_size(d_crc)); d_len - crc::crc_size(d_crc));
metadata::add_crc_valid(status.data, true); metadata::add_crc_valid(status.data, true);