100
This commit is contained in:
@@ -176,7 +176,7 @@ void qdx_port_sock_recv_notify(uint8_t sockid)
|
||||
total += len;
|
||||
if (err != WCHNET_ERR_SUCCESS) break;
|
||||
}
|
||||
DBG_PORT("recv_notify sock%d: %u bytes, ring=%u\r\n",
|
||||
DBG_HB("recv_notify sock%d: %u bytes, ring=%u\r\n",
|
||||
sockid, (unsigned)total, (unsigned)ring_available(&ctx->rx_ring));
|
||||
/* Wake blocking recv thread */
|
||||
xSemaphoreGive(ctx->rx_sem);
|
||||
@@ -187,7 +187,7 @@ void qdx_port_sock_connect_notify(uint8_t sockid)
|
||||
SocketCtx_t *ctx = find_ctx_by_wchnet_id(sockid);
|
||||
if (!ctx) return;
|
||||
ctx->connected = 1;
|
||||
DBG_PORT("connect_notify sock%d\r\n", sockid);
|
||||
DBG_NET("connect_notify sock%d\r\n", sockid);
|
||||
xSemaphoreGive(ctx->connect_sem);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ void qdx_port_sock_disconnect_notify(uint8_t sockid)
|
||||
SocketCtx_t *ctx = find_ctx_by_wchnet_id(sockid);
|
||||
if (!ctx) return;
|
||||
ctx->connected = 0;
|
||||
DBG_PORT("disconnect_notify sock%d\r\n", sockid);
|
||||
DBG_NET("disconnect_notify sock%d\r\n", sockid);
|
||||
/* Wake recv thread so it can detect disconnect */
|
||||
xSemaphoreGive(ctx->rx_sem);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ void qdx_port_init(void)
|
||||
{
|
||||
memset(g_sock_ctx, 0, sizeof(g_sock_ctx));
|
||||
g_wchnet_mutex = xSemaphoreCreateMutex();
|
||||
DBG_PORT("init done, mutex=%p\r\n", g_wchnet_mutex);
|
||||
DBG_INIT("qdx_port init done, mutex=%p\r\n", g_wchnet_mutex);
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
@@ -268,7 +268,7 @@ int8_t qdx_port_thread_create(const char *name, qdx_thread_entry_t entry,
|
||||
BaseType_t ret = xTaskCreate((TaskFunction_t)entry, name,
|
||||
(uint16_t)stack_words, arg,
|
||||
(UBaseType_t)priority, NULL);
|
||||
DBG_PORT("thread_create \"%s\" stack=%d pri=%d -> %s\r\n",
|
||||
DBG_INIT("thread_create \"%s\" stack=%d pri=%d -> %s\r\n",
|
||||
name, (int)stack_words, (int)priority, (ret == pdPASS) ? "OK" : "FAIL");
|
||||
return (ret == pdPASS) ? 0 : -1;
|
||||
}
|
||||
@@ -281,15 +281,15 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
||||
{
|
||||
uint8_t dest_ip[4];
|
||||
if (parse_ip(ip, dest_ip) != 0) {
|
||||
DBG_PORT("bad IP \"%s\"\r\n", ip);
|
||||
DBG_ERR("bad IP \"%s\"\r\n", ip);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBG_PORT("connecting to %s:%d\r\n", ip, port);
|
||||
DBG_NET("connecting to %s:%d\r\n", ip, port);
|
||||
|
||||
SocketCtx_t *ctx = alloc_sock_ctx();
|
||||
if (!ctx) {
|
||||
DBG_PORT("no free SocketCtx\r\n");
|
||||
DBG_ERR("no free SocketCtx\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
||||
sock_inf.DesPort = port;
|
||||
memcpy(sock_inf.IPAddr, dest_ip, 4);
|
||||
|
||||
DBG_PORT("SOCK_INF: proto=%d dst=%d.%d.%d.%d:%d\r\n",
|
||||
DBG_NET("SOCK_INF: proto=%d dst=%d.%d.%d.%d:%d\r\n",
|
||||
sock_inf.ProtoType,
|
||||
sock_inf.IPAddr[0], sock_inf.IPAddr[1],
|
||||
sock_inf.IPAddr[2], sock_inf.IPAddr[3],
|
||||
@@ -313,11 +313,11 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
||||
xSemaphoreGive(g_wchnet_mutex);
|
||||
|
||||
if (err != WCHNET_ERR_SUCCESS) {
|
||||
DBG_PORT("SocketCreat fail %02X\r\n", err);
|
||||
DBG_ERR("SocketCreat fail %02X\r\n", err);
|
||||
free_sock_ctx(ctx);
|
||||
return NULL;
|
||||
}
|
||||
DBG_PORT("SocketCreat OK, wchnet_id=%d\r\n", wchnet_id);
|
||||
DBG_NET("SocketCreat OK, wchnet_id=%d\r\n", wchnet_id);
|
||||
|
||||
ctx->wchnet_sock_id = wchnet_id;
|
||||
|
||||
@@ -330,12 +330,12 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
||||
xSemaphoreGive(g_wchnet_mutex);
|
||||
|
||||
if (err != WCHNET_ERR_SUCCESS) {
|
||||
DBG_PORT("SocketConnect fail %02X\r\n", err);
|
||||
DBG_ERR("SocketConnect fail %02X\r\n", err);
|
||||
WCHNET_SocketClose(wchnet_id, TCP_CLOSE_RST);
|
||||
free_sock_ctx(ctx);
|
||||
return NULL;
|
||||
}
|
||||
DBG_PORT("SocketConnect OK (err=0x%02X), waiting connect_sem (5s)...\r\n", err);
|
||||
DBG_NET("SocketConnect OK (err=0x%02X), waiting connect_sem (5s)...\r\n", err);
|
||||
|
||||
/* Block until SINT_STAT_CONNECT or 5s timeout */
|
||||
uint32_t t0 = xTaskGetTickCount();
|
||||
@@ -343,14 +343,14 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
||||
uint32_t elapsed = (xTaskGetTickCount() - t0) * portTICK_PERIOD_MS;
|
||||
|
||||
if (sem_ret != pdTRUE) {
|
||||
DBG_PORT("connect_sem TIMEOUT after %d ms -> %d.%d.%d.%d:%d\r\n",
|
||||
DBG_ERR("connect_sem TIMEOUT after %d ms -> %d.%d.%d.%d:%d\r\n",
|
||||
(int)elapsed, dest_ip[0], dest_ip[1], dest_ip[2], dest_ip[3], port);
|
||||
DBG_PORT(" ctx->connected=%d wchnet_id=%d\r\n", ctx->connected, wchnet_id);
|
||||
DBG_ERR(" ctx->connected=%d wchnet_id=%d\r\n", ctx->connected, wchnet_id);
|
||||
WCHNET_SocketClose(wchnet_id, TCP_CLOSE_RST);
|
||||
free_sock_ctx(ctx);
|
||||
return NULL;
|
||||
}
|
||||
DBG_PORT("connect_sem got after %d ms, connected=%d\r\n", (int)elapsed, ctx->connected);
|
||||
DBG_NET("connect_sem got after %d ms, connected=%d\r\n", (int)elapsed, ctx->connected);
|
||||
|
||||
if (!ctx->connected) {
|
||||
WCHNET_SocketClose(wchnet_id, TCP_CLOSE_RST);
|
||||
@@ -362,7 +362,7 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
||||
WCHNET_SocketSetKeepLive(wchnet_id, ENABLE);
|
||||
#endif
|
||||
|
||||
DBG_PORT("connected sock %d -> %d.%d.%d.%d:%d\r\n",
|
||||
DBG_NET("connected sock %d -> %d.%d.%d.%d:%d\r\n",
|
||||
wchnet_id, dest_ip[0], dest_ip[1], dest_ip[2], dest_ip[3], port);
|
||||
return (qdx_socket_t)ctx;
|
||||
}
|
||||
@@ -388,7 +388,7 @@ int32_t qdx_port_tcp_send(qdx_socket_t sock, const uint8_t *data, uint32_t len)
|
||||
if (err != WCHNET_ERR_SUCCESS && send_len == 0) {
|
||||
/* WCHNET send buffer full — yield so wchnet task can flush */
|
||||
if (++retries > 50) {
|
||||
DBG_PORT("send fail after retries, err=0x%02X\r\n", err);
|
||||
DBG_ERR("send fail after retries, err=0x%02X\r\n", err);
|
||||
return -1;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(2));
|
||||
|
||||
@@ -18,29 +18,48 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* ============================================================
|
||||
* Debug Print Macros (set to 0 to disable, 1 to enable)
|
||||
* Multi-Level Debug Print System
|
||||
*
|
||||
* Verbosity levels (set DBG_LEVEL to control output volume):
|
||||
* 0 = NONE — all debug prints disabled
|
||||
* 1 = ERR — errors only
|
||||
* 2 = BRIEF — + server config / network events (recommended)
|
||||
* 3 = NORMAL — + trigger / data / init events (default)
|
||||
* 4 = VERBOSE — + heartbeat / detailed internals
|
||||
*
|
||||
* Category macros — each prints when DBG_LEVEL >= its threshold:
|
||||
* DBG_ERR (>=1) Errors, HardFault, CRC fail, bad frames
|
||||
* DBG_CFG (>=2) Server-received config (Config2D/1D/Common, DevID, ACK, DetResult)
|
||||
* DBG_NET (>=2) TCP connect/disconnect, PHY change, socket events
|
||||
* DBG_TRIG (>=3) Trigger events (ext/int), burst start/complete
|
||||
* DBG_DATA (>=3) Frame send results (2D/1D/TEMP_REQ)
|
||||
* DBG_INIT (>=3) Boot-time init messages (sensor, DVP, WCHNET)
|
||||
* DBG_HB (>=4) Heartbeat prints (high-frequency, debug only)
|
||||
* ============================================================ */
|
||||
#define QDX_DEBUG_PORT 1 /* qdx_port.c: socket/mutex/thread ops */
|
||||
#define QDX_DEBUG_LOGIC 1 /* qdx_tcp_logic.c: protocol/TLV parsing */
|
||||
#define QDX_DEBUG_APP 1 /* main.c: application-level events */
|
||||
#define DBG_LEVEL_NONE 0
|
||||
#define DBG_LEVEL_ERR 1
|
||||
#define DBG_LEVEL_BRIEF 2
|
||||
#define DBG_LEVEL_NORMAL 3
|
||||
#define DBG_LEVEL_VERBOSE 4
|
||||
|
||||
#if QDX_DEBUG_PORT
|
||||
#define DBG_PORT(fmt, ...) printf("[PORT] " fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DBG_PORT(fmt, ...) ((void)0)
|
||||
#endif
|
||||
/* >>> Change this single value to control output volume <<< */
|
||||
#define DBG_LEVEL DBG_LEVEL_NORMAL
|
||||
|
||||
#if QDX_DEBUG_LOGIC
|
||||
#define DBG_LOGIC(fmt, ...) printf("[LOGIC] " fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DBG_LOGIC(fmt, ...) ((void)0)
|
||||
#endif
|
||||
#define DBG_PRINT_(threshold, tag, fmt, ...) \
|
||||
do { if (DBG_LEVEL >= (threshold)) printf(tag fmt, ##__VA_ARGS__); } while(0)
|
||||
|
||||
#if QDX_DEBUG_APP
|
||||
#define DBG_APP(fmt, ...) printf("[APP] " fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DBG_APP(fmt, ...) ((void)0)
|
||||
#endif
|
||||
#define DBG_ERR(fmt, ...) DBG_PRINT_(DBG_LEVEL_ERR, "[ERR] ", fmt, ##__VA_ARGS__)
|
||||
#define DBG_CFG(fmt, ...) DBG_PRINT_(DBG_LEVEL_BRIEF, "[CFG] ", fmt, ##__VA_ARGS__)
|
||||
#define DBG_NET(fmt, ...) DBG_PRINT_(DBG_LEVEL_BRIEF, "[NET] ", fmt, ##__VA_ARGS__)
|
||||
#define DBG_TRIG(fmt, ...) DBG_PRINT_(DBG_LEVEL_NORMAL, "[TRIG] ", fmt, ##__VA_ARGS__)
|
||||
#define DBG_DATA(fmt, ...) DBG_PRINT_(DBG_LEVEL_NORMAL, "[DATA] ", fmt, ##__VA_ARGS__)
|
||||
#define DBG_INIT(fmt, ...) DBG_PRINT_(DBG_LEVEL_NORMAL, "[INIT] ", fmt, ##__VA_ARGS__)
|
||||
#define DBG_HB(fmt, ...) DBG_PRINT_(DBG_LEVEL_VERBOSE, "[HB] ", fmt, ##__VA_ARGS__)
|
||||
|
||||
/* Legacy compatibility aliases — avoid using in new code */
|
||||
#define DBG_PORT(fmt, ...) DBG_INIT(fmt, ##__VA_ARGS__)
|
||||
#define DBG_LOGIC(fmt, ...) DBG_CFG(fmt, ##__VA_ARGS__)
|
||||
#define DBG_APP(fmt, ...) DBG_DATA(fmt, ##__VA_ARGS__)
|
||||
|
||||
/* ============================================================
|
||||
* Time & Delay
|
||||
|
||||
@@ -109,7 +109,7 @@ int8_t Preprocess_Execute(const RawImageBuffer_t *input,
|
||||
tgt_w = (tgt_w + 1) / 2;
|
||||
tgt_h = (tgt_h + 1) / 2;
|
||||
}
|
||||
DBG_PORT("PP: target clamped %dx%d -> %dx%d (buf=%d)\r\n",
|
||||
DBG_INIT("PP: target clamped %dx%d -> %dx%d (buf=%d)\r\n",
|
||||
(int)orig_w, (int)orig_h, (int)tgt_w, (int)tgt_h, (int)max_payload);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ static void tcp_stream_init(TcpStreamCtx_t *ctx, const char *label) {
|
||||
}
|
||||
|
||||
static void tcp_stream_disconnect(TcpStreamCtx_t *ctx) {
|
||||
DBG_LOGIC("!! [%s] Disconnected\r\n", ctx->label);
|
||||
DBG_NET("[%s] Disconnected\r\n", ctx->label);
|
||||
ctx->is_connected = 0;
|
||||
if (ctx->sock) {
|
||||
qdx_port_tcp_close(ctx->sock);
|
||||
@@ -79,10 +79,10 @@ static void tcp_stream_disconnect(TcpStreamCtx_t *ctx) {
|
||||
|
||||
static int8_t tcp_stream_connect(TcpStreamCtx_t *ctx, const char *ip,
|
||||
uint16_t port) {
|
||||
DBG_LOGIC("[%s] connecting %s:%d...\r\n", ctx->label, ip, port);
|
||||
DBG_NET("[%s] connecting %s:%d...\r\n", ctx->label, ip, port);
|
||||
ctx->sock = qdx_port_tcp_connect(ip, port);
|
||||
if (ctx->sock == NULL) {
|
||||
DBG_LOGIC("[%s] connect FAILED\r\n", ctx->label);
|
||||
DBG_ERR("[%s] connect FAILED\r\n", ctx->label);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ static int8_t tcp_stream_connect(TcpStreamCtx_t *ctx, const char *ip,
|
||||
ctx->last_activity_ms = qdx_port_get_tick_ms();
|
||||
ctx->last_heartbeat_ms = ctx->last_activity_ms;
|
||||
ctx->recv_len = 0;
|
||||
DBG_LOGIC(">> [%s] Connected to %s:%d\r\n", ctx->label, ip, port);
|
||||
DBG_NET("[%s] Connected to %s:%d\r\n", ctx->label, ip, port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ static int32_t tcp_send_frame(TcpStreamCtx_t *ctx, uint8_t msg_class,
|
||||
}
|
||||
|
||||
static void tcp_send_handshake(TcpStreamCtx_t *ctx) {
|
||||
DBG_LOGIC(">> [%s] Handshake (DevID=%d)\r\n", ctx->label, (int)g_TcpLogic.dev_id);
|
||||
DBG_NET("[%s] Handshake (DevID=%d)\r\n", ctx->label, (int)g_TcpLogic.dev_id);
|
||||
uint8_t payload[54];
|
||||
memset(payload, 0, sizeof(payload));
|
||||
qdx_write_u16_le(payload + 0, 0x0200);
|
||||
@@ -250,17 +250,17 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
|
||||
uint8_t cfg_updated = 0;
|
||||
|
||||
DBG_LOGIC("[%s] TLV pkt: Seq=%d, PayloadLen=%d\r\n", ctx->label,
|
||||
DBG_HB("[%s] TLV pkt: Seq=%d Len=%d\r\n", ctx->label,
|
||||
hdr_seq, payload_len);
|
||||
|
||||
while (parsed_len <= payload_len - 3) {
|
||||
uint8_t type = packet[offset];
|
||||
uint16_t len = qdx_read_u16_le(packet + offset + 1);
|
||||
|
||||
DBG_LOGIC("[%s] TLV: Type=0x%02X, Len=%d\r\n", ctx->label, type, len);
|
||||
DBG_HB("[%s] TLV: Type=0x%02X Len=%d\r\n", ctx->label, type, len);
|
||||
|
||||
if (parsed_len + 3 + len > payload_len) {
|
||||
DBG_LOGIC("[%s] ! TLV truncated (need %d, have %d)\r\n",
|
||||
DBG_ERR("[%s] TLV truncated (need %d, have %d)\r\n",
|
||||
ctx->label, len, payload_len - parsed_len - 3);
|
||||
break; /* Malformed */
|
||||
}
|
||||
@@ -278,16 +278,16 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
uint16_t ack_seq = qdx_read_u16_le(value);
|
||||
uint8_t status = value[2];
|
||||
uint16_t err_code = (len >= 5) ? qdx_read_u16_le(value + 3) : 0;
|
||||
DBG_LOGIC("<< [%s] ACK: seq=%d status=%d err=0x%04x\r\n",
|
||||
ctx->label, (int)ack_seq, (int)status, (int)err_code);
|
||||
DBG_CFG("<< ACK: seq=%d status=%d err=0x%04x\r\n",
|
||||
(int)ack_seq, (int)status, (int)err_code);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TYPE_DEVID_ASSIGN: {
|
||||
if (len >= sizeof(DevIDAssignment_t)) {
|
||||
uint16_t new_id = qdx_read_u16_le(value);
|
||||
DBG_LOGIC("<< [%s] DevID assigned: %d -> %d\r\n",
|
||||
ctx->label, (int)g_TcpLogic.dev_id, (int)new_id);
|
||||
DBG_CFG("<< DevID assigned: %d -> %d\r\n",
|
||||
(int)g_TcpLogic.dev_id, (int)new_id);
|
||||
g_TcpLogic.pending_new_dev_id = new_id;
|
||||
tcp_send_ack(ctx, hdr_seq, 0, 0);
|
||||
}
|
||||
@@ -300,8 +300,7 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
g_TcpLogic.has_valid_config = 1;
|
||||
cfg_updated = 1;
|
||||
qdx_port_mutex_unlock(g_TcpLogic.config_mutex);
|
||||
DBG_LOGIC("<< [%s] ConfigCommon: Mode=%d Tag=%d Strict=%d\r\n",
|
||||
ctx->label,
|
||||
DBG_CFG("<< ConfigCommon: Mode=%d Tag=%d Strict=%d\r\n",
|
||||
(int)g_TcpLogic.cached_common.WorkMode,
|
||||
(int)g_TcpLogic.cached_common.ConfigTag,
|
||||
(int)g_TcpLogic.cached_common.StrictnessLevel);
|
||||
@@ -315,10 +314,9 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
g_TcpLogic.has_valid_config = 1;
|
||||
cfg_updated = 1;
|
||||
qdx_port_mutex_unlock(g_TcpLogic.config_mutex);
|
||||
DBG_LOGIC("<< [%s] Config2D: En=%d %dx%d Tgt=%dx%d Fps=%d "
|
||||
DBG_CFG("<< Config2D: En=%d %dx%d Tgt=%dx%d Fps=%d "
|
||||
"Trig=%d Burst=%d Intv=%d Thresh=%d "
|
||||
"ROI(%d,%d,%d,%d) NGio=%d\r\n",
|
||||
ctx->label,
|
||||
(int)g_TcpLogic.cached_cfg2d.Enabled,
|
||||
(int)g_TcpLogic.cached_cfg2d.Width,
|
||||
(int)g_TcpLogic.cached_cfg2d.Height,
|
||||
@@ -335,8 +333,8 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
(int)g_TcpLogic.cached_cfg2d.TriggerRoiH,
|
||||
(int)g_TcpLogic.cached_cfg2d.NGioDelay);
|
||||
} else {
|
||||
DBG_LOGIC("<< [%s] Config2D bad len=%d (need %d)\r\n",
|
||||
ctx->label, len, (int)sizeof(Config2D_t));
|
||||
DBG_ERR("<< Config2D bad len=%d (need %d)\r\n",
|
||||
len, (int)sizeof(Config2D_t));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -347,9 +345,8 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
g_TcpLogic.has_valid_config = 1;
|
||||
cfg_updated = 1;
|
||||
qdx_port_mutex_unlock(g_TcpLogic.config_mutex);
|
||||
DBG_LOGIC("<< [%s] Config1D: En=%d RunMode=%d TrigType=%d "
|
||||
DBG_CFG("<< Config1D: En=%d RunMode=%d TrigType=%d "
|
||||
"BufSz=%d TempLim=%d NGio=%d\r\n",
|
||||
ctx->label,
|
||||
(int)g_TcpLogic.cached_cfg1d.Enabled,
|
||||
(int)g_TcpLogic.cached_cfg1d.RunMode,
|
||||
(int)g_TcpLogic.cached_cfg1d.TriggerType,
|
||||
@@ -360,13 +357,13 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
break;
|
||||
}
|
||||
case TYPE_TEMP_FRAME: {
|
||||
DBG_LOGIC("<< [%s] TempFrame request (len=%d)\r\n", ctx->label, (int)len);
|
||||
DBG_CFG("<< TempFrame request (len=%d)\r\n", (int)len);
|
||||
if (g_TcpLogic.temp_req_cb) {
|
||||
uint8_t is2d = 0;
|
||||
if (len >= 18) {
|
||||
is2d = value[18];
|
||||
}
|
||||
DBG_LOGIC(" -> callback: is2D=%d\r\n", (int)is2d);
|
||||
DBG_CFG(" -> callback: is2D=%d\r\n", (int)is2d);
|
||||
g_TcpLogic.temp_req_cb(is2d);
|
||||
}
|
||||
break;
|
||||
@@ -375,8 +372,8 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
if (len >= sizeof(DetectionResult_t)) {
|
||||
uint32_t frame_num = qdx_read_u32_le(value);
|
||||
uint8_t result_status = value[4];
|
||||
DBG_LOGIC("<< [%s] DetectionResult: frm=%d result=%d\r\n",
|
||||
ctx->label, (int)frame_num, (int)result_status);
|
||||
DBG_CFG("<< DetectionResult: frm=%d result=%d\r\n",
|
||||
(int)frame_num, (int)result_status);
|
||||
if (g_TcpLogic.detect_cb)
|
||||
g_TcpLogic.detect_cb(frame_num, result_status);
|
||||
}
|
||||
@@ -386,8 +383,7 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
/* Server echoes handshake info — safe to ignore */
|
||||
break;
|
||||
default:
|
||||
DBG_LOGIC("<< [%s] Unknown TLV type=0x%02x len=%d\r\n",
|
||||
ctx->label, (int)type, (int)len);
|
||||
DBG_ERR("Unknown TLV type=0x%02x len=%d\r\n", (int)type, (int)len);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -396,7 +392,7 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
|
||||
}
|
||||
|
||||
if (cfg_updated && g_TcpLogic.config_cb && g_TcpLogic.has_valid_config) {
|
||||
DBG_LOGIC("<< [%s] Config updated -> notify app\r\n", ctx->label);
|
||||
DBG_CFG("Config updated -> notify app\r\n");
|
||||
qdx_port_mutex_lock(g_TcpLogic.config_mutex);
|
||||
g_TcpLogic.config_cb(&g_TcpLogic.cached_common, &g_TcpLogic.cached_cfg2d,
|
||||
&g_TcpLogic.cached_cfg1d);
|
||||
@@ -438,7 +434,7 @@ static void tcp_process_rx_buffer(TcpStreamCtx_t *ctx) {
|
||||
uint16_t length = qdx_read_u16_le(ctx->recv_buffer + 3);
|
||||
|
||||
if (version != PROTO_VERSION || length < HEADER_SIZE + CRC_SIZE) {
|
||||
DBG_LOGIC("[%s] bad header: ver=0x%02X(exp 0x%02X) len=%d\r\n",
|
||||
DBG_ERR("[%s] bad header: ver=0x%02X(exp 0x%02X) len=%d\r\n",
|
||||
ctx->label, version, PROTO_VERSION, length);
|
||||
memmove(ctx->recv_buffer, ctx->recv_buffer + 2, ctx->recv_len - 2);
|
||||
ctx->recv_len -= 2;
|
||||
@@ -446,7 +442,7 @@ static void tcp_process_rx_buffer(TcpStreamCtx_t *ctx) {
|
||||
}
|
||||
|
||||
if (length > sizeof(ctx->recv_buffer)) {
|
||||
DBG_LOGIC("[%s] frame too large: %d > %d\r\n", ctx->label,
|
||||
DBG_ERR("[%s] frame too large: %d > %d\r\n", ctx->label,
|
||||
length, (int)sizeof(ctx->recv_buffer));
|
||||
ctx->recv_len = 0;
|
||||
break;
|
||||
@@ -464,7 +460,7 @@ static void tcp_process_rx_buffer(TcpStreamCtx_t *ctx) {
|
||||
/* 3. Dispatch */
|
||||
parse_and_dispatch_tlv(ctx, ctx->recv_buffer, length);
|
||||
} else {
|
||||
DBG_LOGIC("[%s] CRC fail: calc=0x%04X recv=0x%04X len=%d\r\n",
|
||||
DBG_ERR("[%s] CRC fail: calc=0x%04X recv=0x%04X len=%d\r\n",
|
||||
ctx->label, calculated_crc, received_crc, length);
|
||||
}
|
||||
|
||||
@@ -642,6 +638,22 @@ void TcpLogic_RegisterTempFrameRequestCallback(TempFrameRequestCallback_t cb) {
|
||||
g_TcpLogic.temp_req_cb = cb;
|
||||
}
|
||||
|
||||
void TcpLogic_InjectTestConfig(const ConfigCommon_t *common,
|
||||
const Config2D_t *cfg2d,
|
||||
const Config1D_t *cfg1d) {
|
||||
qdx_port_mutex_lock(g_TcpLogic.config_mutex);
|
||||
if (common) memcpy(&g_TcpLogic.cached_common, common, sizeof(*common));
|
||||
if (cfg2d) memcpy(&g_TcpLogic.cached_cfg2d, cfg2d, sizeof(*cfg2d));
|
||||
if (cfg1d) memcpy(&g_TcpLogic.cached_cfg1d, cfg1d, sizeof(*cfg1d));
|
||||
g_TcpLogic.has_valid_config = 1;
|
||||
qdx_port_mutex_unlock(g_TcpLogic.config_mutex);
|
||||
if (g_TcpLogic.config_cb) {
|
||||
g_TcpLogic.config_cb(&g_TcpLogic.cached_common,
|
||||
&g_TcpLogic.cached_cfg2d,
|
||||
&g_TcpLogic.cached_cfg1d);
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* Zero-Copy Frame Building & Fragmentation for Temperature Data
|
||||
* ============================================================ */
|
||||
@@ -658,7 +670,7 @@ TcpLogic_BuildAndSendTemperatureFrame(TcpTxBuffer_t *io_buffer,
|
||||
|
||||
g_TcpLogic.frame_count++;
|
||||
|
||||
DBG_LOGIC(">> [Data] TempFrame #%d: %dx%d type=%d is2D=%d payload=%d\r\n",
|
||||
DBG_DATA(">> TempFrame #%d: %dx%d type=%d is2D=%d payload=%d\r\n",
|
||||
(int)processMeta->FrameNumber,
|
||||
(int)processMeta->ValidWidth, (int)processMeta->ValidHeight,
|
||||
(int)frameType, (int)is2D, (int)io_buffer->ValidPayloadLen);
|
||||
@@ -725,7 +737,7 @@ TcpLogic_BuildAndSendTemperatureFrame(TcpTxBuffer_t *io_buffer,
|
||||
uint32_t frag_count =
|
||||
(total_tlv_len + MAX_FRAGMENT_PAYLOAD - 1) / MAX_FRAGMENT_PAYLOAD;
|
||||
|
||||
DBG_LOGIC(">> [Data] Fragmented: %d frags, total=%d\r\n",
|
||||
DBG_DATA(">> Fragmented: %d frags, total=%d\r\n",
|
||||
(int)frag_count, (int)total_tlv_len);
|
||||
|
||||
for (uint32_t i = 0; i < frag_count; i++) {
|
||||
|
||||
@@ -105,6 +105,16 @@ typedef void (*TempFrameRequestCallback_t)(uint8_t is2dRequest);
|
||||
*/
|
||||
void TcpLogic_RegisterTempFrameRequestCallback(TempFrameRequestCallback_t cb);
|
||||
|
||||
/**
|
||||
* @brief Inject configuration directly (for test mode without server).
|
||||
*
|
||||
* Sets the internal config cache and fires the config callback.
|
||||
* Only non-NULL parameters are updated.
|
||||
*/
|
||||
void TcpLogic_InjectTestConfig(const ConfigCommon_t *common,
|
||||
const Config2D_t *cfg2d,
|
||||
const Config1D_t *cfg1d);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user