This commit is contained in:
2026-03-14 20:54:11 +08:00
parent e3d08f7f26
commit b8dbaa619d
3 changed files with 1895 additions and 0 deletions
+111
View File
@@ -61,6 +61,17 @@ static void NG_GPIO_Init(void)
GPIO_ResetBits(NG_GPIO_PORT, NG_GPIO_PIN);
}
/* Flag set by TempFrameRequest callback; consumed by business task */
static volatile uint8_t g_temp_req_pending = 0;
static volatile uint8_t g_temp_req_is2d = 1;
void OnTempFrameRequest(uint8_t is2dRequest)
{
g_temp_req_is2d = is2dRequest;
g_temp_req_pending = 1;
DBG_APP("TempFrameReq is2d=%d\r\n", (int)is2dRequest);
}
void OnDetectionResult(uint32_t frameNumber, uint8_t resultStatus)
{
(void)frameNumber;
@@ -341,6 +352,58 @@ static void task_test_pattern_entry(void *pvParameters)
}
#endif /* TEST_PATTERN_MODE */
/* ============================================================
* 1D mode: build and send a single 1D temperature frame from
* the current raw image. Scans the center row and packs
* TempPoint1D_t (2B time_offset + 2B temp, little-endian).
* ============================================================ */
static void send_1d_frame_from_raw(const RawImageBuffer_t *raw, TcpTxBuffer_t *tx_buf)
{
uint16_t w = raw->Width;
uint16_t h = raw->Height;
uint16_t *src = raw->pData;
uint16_t row = h / 2; /* center row */
tx_buf->ValidPayloadLen = 0;
uint8_t *dest = tx_buf->pBuffer + tx_buf->HeadOffset;
uint32_t capacity = tx_buf->TotalCapacity - tx_buf->HeadOffset;
uint16_t points = w;
if ((uint32_t)points * 4 > capacity)
points = (uint16_t)(capacity / 4);
int16_t min_t = 32767, max_t = -32768;
int32_t sum_t = 0;
for (uint16_t i = 0; i < points; i++) {
uint16_t temp = src[row * w + i];
uint16_t time_offset = (uint16_t)((uint32_t)i * 600 / (points > 1 ? points - 1 : 1));
int16_t t = (int16_t)temp;
if (t < min_t) min_t = t;
if (t > max_t) max_t = t;
sum_t += t;
dest[0] = (uint8_t)(time_offset & 0xFF);
dest[1] = (uint8_t)((time_offset >> 8) & 0xFF);
dest[2] = (uint8_t)(temp & 0xFF);
dest[3] = (uint8_t)((temp >> 8) & 0xFF);
dest += 4;
}
tx_buf->ValidPayloadLen = (uint32_t)points * 4;
PreprocessResult_t meta;
memset(&meta, 0, sizeof(meta));
meta.pValidData = tx_buf->pBuffer + tx_buf->HeadOffset;
meta.DataLength = tx_buf->ValidPayloadLen;
meta.ValidWidth = points;
meta.ValidHeight = 1;
meta.MinTemp = min_t;
meta.MaxTemp = max_t;
meta.AvgTemp = (int16_t)(sum_t / (points > 0 ? points : 1));
meta.RoiTemp = meta.AvgTemp;
meta.FrameNumber = raw->FrameNumber;
TcpLogic_BuildAndSendTemperatureFrame(tx_buf, &meta, 0x01, 0 /* IS_1D */);
}
static void task_business_entry(void *pvParameters)
{
(void)pvParameters;
@@ -358,6 +421,29 @@ static void task_business_entry(void *pvParameters)
DVP_Task();
#endif
/* Handle on-demand frame request from server */
if (g_temp_req_pending)
{
g_temp_req_pending = 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;
TcpTxBuffer_t *tx_buf = use_buffer_A ? &g_TxNetBuffer_A : &g_TxNetBuffer_B;
use_buffer_A = !use_buffer_A;
tx_buf->ValidPayloadLen = 0;
if (g_temp_req_is2d) {
PreprocessResult_t meta;
if (Preprocess_Execute(&raw_img, tx_buf, &meta) == 0)
TcpLogic_BuildAndSendTemperatureFrame(tx_buf, &meta, 0x02 /* REQUEST */, 1);
} else {
send_1d_frame_from_raw(&raw_img, tx_buf);
}
}
if (Frame_Ready_Flag)
{
Frame_Ready_Flag = 0;
@@ -475,9 +561,34 @@ int main(void)
qdx_port_init();
Preprocess_Init(SENSOR_WIDTH, SENSOR_HEIGHT);
#if TEST_PATTERN_MODE
/* Set default preprocess config so trigger fires with test patterns.
* Without this, all Config2D_t fields are 0 and trigger never fires
* (roi_w==0 → immediate return 0). */
{
Config2D_t test_cfg2d;
memset(&test_cfg2d, 0, sizeof(test_cfg2d));
test_cfg2d.TargetWidth = 64; /* ROI extraction 64x64 */
test_cfg2d.TargetHeight = 64;
test_cfg2d.TriggerRoiX = 0; /* Full-frame trigger area */
test_cfg2d.TriggerRoiY = 0;
test_cfg2d.TriggerRoiW = SENSOR_WIDTH;
test_cfg2d.TriggerRoiH = SENSOR_HEIGHT;
test_cfg2d.TriggerCondition = 1; /* Max temperature */
test_cfg2d.TriggerTemperatureThreshold = 8000; /* 80.00°C */
test_cfg2d.TriggerBurstCount = 3;
test_cfg2d.TriggerInternalIntervalMs = 200;
test_cfg2d.NGioDelay = 200;
Preprocess_Settings_Change(&test_cfg2d, NULL, NULL);
printf("Test default config loaded: trigger thresh=8000 ROI=full burst=3\r\n");
}
#endif
TcpLogic_Init(MACAddr, NULL);
TcpLogic_RegisterConfigCallback(OnConfigUpdate);
TcpLogic_RegisterDetectionCallback(OnDetectionResult);
TcpLogic_RegisterTempFrameRequestCallback(OnTempFrameRequest);
DBG_APP("TcpLogic_Start...\r\n");
TcpLogic_Start();