Use compact binary payload for LoRa batches
This commit is contained in:
32
src/payload_codec.h
Normal file
32
src/payload_codec.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
struct BatchInput {
|
||||
uint16_t sender_id;
|
||||
uint16_t batch_id;
|
||||
uint32_t t_last;
|
||||
uint8_t dt_s;
|
||||
uint8_t n;
|
||||
uint16_t battery_mV;
|
||||
uint32_t energy_wh[30];
|
||||
int16_t p1_w[30];
|
||||
int16_t p2_w[30];
|
||||
int16_t p3_w[30];
|
||||
};
|
||||
|
||||
bool encode_batch(const BatchInput &in, uint8_t *out, size_t out_cap, size_t *out_len);
|
||||
bool decode_batch(const uint8_t *buf, size_t len, BatchInput *out);
|
||||
|
||||
size_t uleb128_encode(uint32_t v, uint8_t *out, size_t cap);
|
||||
bool uleb128_decode(const uint8_t *in, size_t len, size_t *pos, uint32_t *v);
|
||||
|
||||
uint32_t zigzag32(int32_t x);
|
||||
int32_t unzigzag32(uint32_t u);
|
||||
|
||||
size_t svarint_encode(int32_t x, uint8_t *out, size_t cap);
|
||||
bool svarint_decode(const uint8_t *in, size_t len, size_t *pos, int32_t *x);
|
||||
|
||||
#ifdef PAYLOAD_CODEC_TEST
|
||||
bool payload_codec_self_test();
|
||||
#endif
|
||||
Reference in New Issue
Block a user