Refactor LoRa protocol to batch+ack with ACK-based time bootstrap
This commit is contained in:
@@ -101,7 +101,7 @@ bool encode_batch(const BatchInput &in, uint8_t *out, size_t out_cap, size_t *ou
|
||||
if (!out || !out_len) {
|
||||
return false;
|
||||
}
|
||||
if (in.n == 0 || in.n > kMaxSamples) {
|
||||
if (in.n > kMaxSamples) {
|
||||
return false;
|
||||
}
|
||||
if (in.dt_s == 0) {
|
||||
@@ -131,6 +131,11 @@ bool encode_batch(const BatchInput &in, uint8_t *out, size_t out_cap, size_t *ou
|
||||
out[pos++] = in.err_last;
|
||||
out[pos++] = in.err_rx_reject;
|
||||
|
||||
if (in.n == 0) {
|
||||
*out_len = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ensure_capacity(4, out_cap, pos)) {
|
||||
return false;
|
||||
}
|
||||
@@ -210,9 +215,18 @@ bool decode_batch(const uint8_t *buf, size_t len, BatchInput *out) {
|
||||
out->err_last = buf[pos++];
|
||||
out->err_rx_reject = buf[pos++];
|
||||
|
||||
if (out->n == 0 || out->n > kMaxSamples || out->dt_s == 0) {
|
||||
if (out->n > kMaxSamples || out->dt_s == 0) {
|
||||
return false;
|
||||
}
|
||||
if (out->n == 0) {
|
||||
for (uint8_t i = 0; i < kMaxSamples; ++i) {
|
||||
out->energy_wh[i] = 0;
|
||||
out->p1_w[i] = 0;
|
||||
out->p2_w[i] = 0;
|
||||
out->p3_w[i] = 0;
|
||||
}
|
||||
return pos == len;
|
||||
}
|
||||
if (pos + 4 > len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user