Include sender error counters in batch payload
This commit is contained in:
@@ -108,7 +108,7 @@ bool encode_batch(const BatchInput &in, uint8_t *out, size_t out_cap, size_t *ou
|
||||
return false;
|
||||
}
|
||||
size_t pos = 0;
|
||||
if (!ensure_capacity(16, out_cap, pos)) {
|
||||
if (!ensure_capacity(20, out_cap, pos)) {
|
||||
return false;
|
||||
}
|
||||
write_u16_le(&out[pos], kMagic);
|
||||
@@ -125,6 +125,10 @@ bool encode_batch(const BatchInput &in, uint8_t *out, size_t out_cap, size_t *ou
|
||||
out[pos++] = in.n;
|
||||
write_u16_le(&out[pos], in.battery_mV);
|
||||
pos += 2;
|
||||
out[pos++] = in.err_m;
|
||||
out[pos++] = in.err_d;
|
||||
out[pos++] = in.err_tx;
|
||||
out[pos++] = in.err_last;
|
||||
|
||||
if (!ensure_capacity(4, out_cap, pos)) {
|
||||
return false;
|
||||
@@ -179,7 +183,7 @@ bool decode_batch(const uint8_t *buf, size_t len, BatchInput *out) {
|
||||
return false;
|
||||
}
|
||||
size_t pos = 0;
|
||||
if (len < 16) {
|
||||
if (len < 20) {
|
||||
return false;
|
||||
}
|
||||
uint16_t magic = read_u16_le(&buf[pos]);
|
||||
@@ -199,6 +203,10 @@ bool decode_batch(const uint8_t *buf, size_t len, BatchInput *out) {
|
||||
out->n = buf[pos++];
|
||||
out->battery_mV = read_u16_le(&buf[pos]);
|
||||
pos += 2;
|
||||
out->err_m = buf[pos++];
|
||||
out->err_d = buf[pos++];
|
||||
out->err_tx = buf[pos++];
|
||||
out->err_last = buf[pos++];
|
||||
|
||||
if (out->n == 0 || out->n > kMaxSamples || out->dt_s == 0) {
|
||||
return false;
|
||||
@@ -271,6 +279,10 @@ bool payload_codec_self_test() {
|
||||
in.dt_s = 1;
|
||||
in.n = 5;
|
||||
in.battery_mV = 3750;
|
||||
in.err_m = 2;
|
||||
in.err_d = 1;
|
||||
in.err_tx = 3;
|
||||
in.err_last = 2;
|
||||
in.energy_wh[0] = 100000;
|
||||
in.energy_wh[1] = 100001;
|
||||
in.energy_wh[2] = 100050;
|
||||
@@ -306,7 +318,8 @@ bool payload_codec_self_test() {
|
||||
}
|
||||
|
||||
if (out.sender_id != in.sender_id || out.batch_id != in.batch_id || out.t_last != in.t_last ||
|
||||
out.dt_s != in.dt_s || out.n != in.n || out.battery_mV != in.battery_mV) {
|
||||
out.dt_s != in.dt_s || out.n != in.n || out.battery_mV != in.battery_mV ||
|
||||
out.err_m != in.err_m || out.err_d != in.err_d || out.err_tx != in.err_tx || out.err_last != in.err_last) {
|
||||
Serial.println("payload_codec_self_test: header mismatch");
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user