(hopefully) better msg tracking
This commit is contained in:
parent
3ffaf5554d
commit
ed19a5758d
2 changed files with 40 additions and 10 deletions
|
@ -36,6 +36,8 @@ enum lora_msg_type {
|
||||||
ROUTING,
|
ROUTING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern uint8_t lormac[3];
|
||||||
|
|
||||||
void lorcomm_handle_receive(uint8_t size);
|
void lorcomm_handle_receive(uint8_t size);
|
||||||
void lorcomm_send_message(lora32_cfg_t *lora, char *text);
|
void lorcomm_send_message(lora32_cfg_t *lora, char *text);
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,23 @@
|
||||||
|
|
||||||
#define MSG_ID_TRACK (16)
|
#define MSG_ID_TRACK (16)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t mac[3];
|
||||||
|
uint8_t ids[MSG_ID_TRACK];
|
||||||
|
} id_cache_t;
|
||||||
|
|
||||||
uint8_t mac[6] = {0};
|
uint8_t mac[6] = {0};
|
||||||
static uint8_t msg_id = 1;
|
static uint8_t msg_id = 1;
|
||||||
uint8_t msg_track[MSG_ID_TRACK] = { 0 };
|
|
||||||
|
id_cache_t id_cache[MSG_ID_TRACK] = { 0 };
|
||||||
|
|
||||||
|
uint8_t acmp(uint8_t a[], uint8_t b[], uint8_t len) {
|
||||||
|
for(uint8_t i = 0; i < len; i++) {
|
||||||
|
if(a[i] != b[i]) return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void lorcomm_handle_receive(uint8_t size) {
|
void lorcomm_handle_receive(uint8_t size) {
|
||||||
printf("packet size: %d\n", size);
|
printf("packet size: %d\n", size);
|
||||||
|
@ -27,21 +41,35 @@ void lorcomm_handle_receive(uint8_t size) {
|
||||||
ESP_LOGI(TAG, "[%02X:%02X:%02X] id: %02d type: %02X", packet->src[0], packet->src[1], packet->src[2], packet->id, packet->type);
|
ESP_LOGI(TAG, "[%02X:%02X:%02X] id: %02d type: %02X", packet->src[0], packet->src[1], packet->src[2], packet->id, packet->type);
|
||||||
|
|
||||||
for(uint8_t i = 0; i < MSG_ID_TRACK; i++) {
|
for(uint8_t i = 0; i < MSG_ID_TRACK; i++) {
|
||||||
if(msg_track[i] == packet->id) {
|
if(id_cache[i].mac[0]+id_cache[i].mac[1]+id_cache[i].mac[2] == 0) {
|
||||||
ESP_LOGI(TAG, "already seen packet, not relaying");
|
memcpy(id_cache[i].mac, &packet->src, 3);
|
||||||
goto receive_cleanup;
|
|
||||||
} else if(msg_track[i] == 0) {
|
|
||||||
ESP_LOGI(TAG, "adding id to tracking");
|
|
||||||
|
|
||||||
// add id to array
|
// this is assumed to be empty
|
||||||
msg_track[i] = packet->id;
|
id_cache[i].ids[0] = packet->id;
|
||||||
// set next in queue to zero, rolling over as needed
|
ESP_LOGI(TAG, "adding new tracking entity");
|
||||||
msg_track[(i + 1) % MSG_ID_TRACK] = 0;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(uint8_t j = 0; j < MSG_ID_TRACK; j++) {
|
||||||
|
if(id_cache[i].ids[j] == packet->id) {
|
||||||
|
ESP_LOGI(TAG, "already seen packet, not relaying");
|
||||||
|
goto receive_cleanup;
|
||||||
|
} else if(id_cache[i].ids[j] == 0) {
|
||||||
|
ESP_LOGI(TAG, "adding id to tracking");
|
||||||
|
|
||||||
|
// add id to array
|
||||||
|
id_cache[i].ids[i] = packet->id;
|
||||||
|
// set next in queue to zero, rolling over as needed
|
||||||
|
id_cache[i].ids[(i + 1) % MSG_ID_TRACK] = 0;
|
||||||
|
|
||||||
|
goto break_outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break_outer:
|
||||||
|
|
||||||
// update local msg id to incoming +1
|
// update local msg id to incoming +1
|
||||||
// this will give a rolling local area id
|
// this will give a rolling local area id
|
||||||
if(packet->id < msg_id) {
|
if(packet->id < msg_id) {
|
||||||
|
|
Loading…
Reference in a new issue