Browse Source

1

nodeinfo-routing-update
jeka 1 month ago
parent
commit
0b4e5960cf
  1. 72
      src/etcp_debug.c
  2. 8
      src/etcp_debug.h

72
src/etcp_debug.c

@ -0,0 +1,72 @@
#define DEBUG_CATEGORY_ETCP 1
#include "etcp_debug.h"
#include "etcp.h"
#include "../lib/debug_config.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
void etcp_dump_pkt_sections(struct ETCP_DGRAM* pkt, struct ETCP_LINK* link, int is_send) {
if (!pkt) return;
char buf[256];
int pos = 0;
const char* dir = is_send ? "SEND" : "RECV";
pos += snprintf(buf + pos, sizeof(buf) - pos, "ETCP PKT: %s ts=%u", dir, pkt->timestamp);
uint8_t* data = pkt->data;
uint16_t len = pkt->data_len;
uint32_t ack_last_delivered = 0;
int ack_count = 0;
uint16_t ch_ret_ts = 0;
uint16_t ch_recv_ts = 0;
uint32_t payload_seq = 0;
uint16_t payload_size = 0;
int has_channel_ts = 0;
int has_payload = 0;
uint16_t offset = 0;
while (offset < len) {
if (offset >= len) break;
uint8_t type = data[offset];
switch (type) {
case ETCP_SECTION_ACK: {
if (offset + 2 > len) { offset = len; break; }
ack_count = data[offset + 1];
if (offset + 6 > len) { offset = len; break; }
ack_last_delivered = data[offset + 2] | (data[offset + 3] << 8) |
(data[offset + 4] << 16) | (data[offset + 5] << 24);
pos += snprintf(buf + pos, sizeof(buf) - pos, " ack=%u/%d", ack_last_delivered, ack_count);
offset += 6 + ack_count * 8;
break;
}
case ETCP_SECTION_TIMESTAMP: {
if (offset + 5 > len) { offset = len; break; }
ch_ret_ts = data[offset + 1] | (data[offset + 2] << 8);
ch_recv_ts = data[offset + 3] | (data[offset + 4] << 8);
has_channel_ts = 1;
pos += snprintf(buf + pos, sizeof(buf) - pos, " ch_ts=%u/%u", ch_ret_ts, ch_recv_ts);
offset += 5;
break;
}
case ETCP_SECTION_PAYLOAD: {
if (offset + 5 > len) { offset = len; break; }
payload_seq = data[offset + 1] | (data[offset + 2] << 8) |
(data[offset + 3] << 16) | (data[offset + 4] << 24);
payload_size = len - offset - 5;
has_payload = 1;
pos += snprintf(buf + pos, sizeof(buf) - pos, " payload=%u(seq=%u)", payload_size, payload_seq);
offset = len;
break;
}
default:
offset = len;
break;
}
}
DEBUG_INFO(DEBUG_CATEGORY_DUMP, "%s", buf);
}

8
src/etcp_debug.h

@ -0,0 +1,8 @@
#ifndef ETCP_DEBUG_H
#define ETCP_DEBUG_H
#include "etcp_connections.h"
void etcp_dump_pkt_sections(struct ETCP_DGRAM* pkt, struct ETCP_LINK* link, int is_send);
#endif
Loading…
Cancel
Save