This commit is contained in:
2026-03-14 08:12:17 +08:00
parent 82d672a2d3
commit 31191a4156
61 changed files with 32384 additions and 64 deletions
+74 -31
View File
@@ -2,6 +2,42 @@
#include "string.h"
#include "eth_driver.h"
#include "dvp.h"
#include "qdx_port.h"
#include "qdx_preprocess.h"
#include "qdx_tcp_logic.h"
#define MAX_TCP_PAYLOAD_SIZE 10240
uint8_t g_TxNetBuffer_A_Mem[MAX_TCP_PAYLOAD_SIZE];
uint8_t g_TxNetBuffer_B_Mem[MAX_TCP_PAYLOAD_SIZE];
TcpTxBuffer_t g_TxNetBuffer_A = {
.pBuffer = g_TxNetBuffer_A_Mem,
.TotalCapacity = MAX_TCP_PAYLOAD_SIZE,
.HeadOffset = 64,
.ValidPayloadLen = 0
};
TcpTxBuffer_t g_TxNetBuffer_B = {
.pBuffer = g_TxNetBuffer_B_Mem,
.TotalCapacity = MAX_TCP_PAYLOAD_SIZE,
.HeadOffset = 64,
.ValidPayloadLen = 0
};
void OnConfigUpdate(const ConfigCommon_t *common, const Config2D_t *cfg2d, const Config1D_t *cfg1d)
{
// Update preprocessing thresholds
// Preprocess_Settings_Change(...); // Assuming this needs to be implemented or already exists
}
void OnDetectionResult(uint8_t frameType, uint8_t isOK)
{
// If not OK, trigger GPIO NG cylinder
if (!isOK) {
// trigger GPIO action
}
}
#define KEEPALIVE_ENABLE 1
@@ -38,37 +74,9 @@ void TIM2_Init(void)
NVIC_EnableIRQ(TIM2_IRQn);
}
void WCHNET_CreateTcpSocket(void)
{
u8 i;
SOCK_INF TmpSocketInf;
memset((void *)&TmpSocketInf, 0, sizeof(SOCK_INF));
memcpy((void *)TmpSocketInf.IPAddr, DESIP, 4);
TmpSocketInf.DesPort = desport;
TmpSocketInf.SourPort = srcport++;
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
TmpSocketInf.RecvBufLen = RECE_BUF_LEN;
i = WCHNET_SocketCreat(&SocketId, &TmpSocketInf);
printf("SocketId %d\r\n", SocketId);
mStopIfError(i);
i = WCHNET_SocketConnect(SocketId);
mStopIfError(i);
}
/* PC -> MCU 收到数据后回环,同时可在此处理PC下发的指令 */
void WCHNET_DataLoopback(u8 id)
{
u32 len;
u32 endAddr = SocketInf[id].RecvStartPoint + SocketInf[id].RecvBufLen;
if ((SocketInf[id].RecvReadPoint + SocketInf[id].RecvRemLen) > endAddr)
len = endAddr - SocketInf[id].RecvReadPoint;
else
len = SocketInf[id].RecvRemLen;
if (WCHNET_SocketSend(id, (u8 *)SocketInf[id].RecvReadPoint, &len) == WCHNET_ERR_SUCCESS)
WCHNET_SocketRecv(id, NULL, &len);
}
void WCHNET_HandleSockInt(u8 socketid, u8 intstat)
{
@@ -76,7 +84,7 @@ void WCHNET_HandleSockInt(u8 socketid, u8 intstat)
if (intstat & SINT_STAT_RECV)
{
WCHNET_DataLoopback(socketid);
/* DataLoopback removed, handled in qdx_tcp_logic */
}
if (intstat & SINT_STAT_CONNECT)
{
@@ -102,7 +110,7 @@ void WCHNET_HandleSockInt(u8 socketid, u8 intstat)
if (socket[i] == socketid) { socket[i] = 0xff; break; }
}
printf("TCP Timeout\r\n");
WCHNET_CreateTcpSocket();
TcpLogic_Init(MACAddr);
}
}
@@ -156,13 +164,48 @@ int main(void)
#endif
memset(socket, 0xff, WCHNET_MAX_SOCKET_NUM);
WCHNET_CreateTcpSocket();
Preprocess_Init(SENSOR_WIDTH, SENSOR_HEIGHT);
TcpLogic_Init(MACAddr, NULL);
TcpLogic_RegisterConfigCallback(OnConfigUpdate);
TcpLogic_RegisterDetectionCallback(OnDetectionResult);
TcpLogic_Start();
while (1)
{
DVP_Task();
if (Frame_Ready_Flag)
{
Frame_Ready_Flag = 0;
RawImageBuffer_t raw_img;
raw_img.pData = (uint16_t *)FrameBuffer;
raw_img.Width = SENSOR_WIDTH;
raw_img.Height = SENSOR_HEIGHT;
raw_img.FrameNumber = Ready_Frame_Count;
if (Preprocess_CheckInternalTrigger2D(&raw_img) == 1)
{
PreprocessResult_t meta;
// Toggle between A and B
static uint8_t use_buffer_A = 1;
TcpTxBuffer_t *tx_buf = use_buffer_A ? &g_TxNetBuffer_A : &g_TxNetBuffer_B;
use_buffer_A = !use_buffer_A;
if (Preprocess_Execute(&raw_img, tx_buf, &meta) == 0)
{
TcpLogic_BuildAndSendTemperatureFrame(tx_buf, &meta, 1, 1);
}
}
}
WCHNET_MainTask();
if (WCHNET_QueryGlobalInt())
WCHNET_HandleGlobalInt();
}
}