A dsPIC33 MCU (16-bit) is being used for data collection.
I add a value on "Sample ID" to a buffer format containing real time measurements.
The sample ID is 16bits, so wraps after 2^16 samples,
The schema is as so
enum DevStatus:ubyte {None = 0, OK = 2}
table Sample{
status:SampleStatus;
id:ushort;
digital:ushort;
channels:[short];
}
table SamplesPacket {
status: DevStatus;
samples: [Sample];
}
The Code takes the data from a rolling buffer of samples, assembling it into packets and transmitting it.
ns(SamplesPacket_start_as_root_with_size(B));
//Index to read sample data from
i_sample = PACKET_GetFirstInPacket();
//Start samples vector and add up to Packet_sample_per_packet samples
ns(SamplesPacket_samples_start(B));
for(uint16_t i=0; i<PACKET_sample_per_packet; i++){
sample_t* sample = &(committed_samples[i_sample]);
// Write sample data into flatbuffer
ns(Sample_vec_push_start(B));
ns(Sample_id_add(B, PACKET_GetSampleCount(i_sample)));
ns(Sample_digital_add(B, sample->digital.DigitalChannels));
ns(Sample_channels_start(B));
for(unsigned int j=0; j<SAMPLE_channel_count; j++){
ns(Sample_channels_push(B, &(sample->channel[j])));
}
ns(Sample_channels_end(B));
// Update read index
i_sample = PACKET_AddOverflow(i_sample, 1, PACKET_buffer_l);
ns(Sample_vec_push_end(B));
}
ns(SamplesPacket_samples_end(B));
ns(SamplesPacket_end_as_root(B));
// Write samples buffer for transmitting
void* buf;
size_t size;
buf = flatcc_builder_finalize_buffer(B, &size);
During finalize_buffer, if the one of the samples has a sample_id == 0;, an assertion failure will sometimes happen.
I'm not able to pinpoint at what point in the finalise it happens as I don't know where to look to find it quickly.
Doing ns(Sample_id_force_add(....) appears to solve the problem but I'm not satisfied that something else isn't going on.
Why is the possibility of it being zero causing a assertion failure (and program crash!)?
Why doesn't the same happen with digital_add(...) when the values are also zero, should I used force add there too?
How do I pinpoint the issue?
A dsPIC33 MCU (16-bit) is being used for data collection.
I add a value on "Sample ID" to a buffer format containing real time measurements.
The sample ID is 16bits, so wraps after 2^16 samples,
The schema is as so
The Code takes the data from a rolling buffer of samples, assembling it into packets and transmitting it.
During
finalize_buffer, if the one of the samples has asample_id == 0;, an assertion failure will sometimes happen.I'm not able to pinpoint at what point in the finalise it happens as I don't know where to look to find it quickly.
Doing
ns(Sample_id_force_add(....)appears to solve the problem but I'm not satisfied that something else isn't going on.Why is the possibility of it being zero causing a assertion failure (and program crash!)?
Why doesn't the same happen with
digital_add(...)when the values are also zero, should I used force add there too?How do I pinpoint the issue?