22
This commit is contained in:
+58
-10
@@ -17,6 +17,20 @@
|
||||
* ============================================================ */
|
||||
#define TEST_PATTERN_MODE 1
|
||||
|
||||
/* ============================================================
|
||||
* Feature Test Switches — set to 1 to enable, 0 to disable.
|
||||
* Allows testing each feature independently.
|
||||
* ============================================================ */
|
||||
#define TEST_ENABLE_HEARTBEAT 1 /* Periodic heartbeat debug print task */
|
||||
#define TEST_ENABLE_TRIGGER 1 /* Internal trigger + burst upload */
|
||||
#define TEST_ENABLE_NG_GPIO 1 /* NG GPIO pulse output on detection */
|
||||
#define TEST_ENABLE_TEMP_REQ 1 /* On-demand frame upload from server */
|
||||
#define TEST_ENABLE_TCP_SEND 1 /* TCP data channel sending */
|
||||
|
||||
/* Default burst parameters — used when server hasn't sent config yet */
|
||||
#define DEFAULT_BURST_COUNT 3
|
||||
#define DEFAULT_BURST_INTERVAL_MS 200
|
||||
|
||||
#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];
|
||||
@@ -41,6 +55,9 @@ void OnConfigUpdate(const ConfigCommon_t *common, const Config2D_t *cfg2d, const
|
||||
Preprocess_Settings_Change(cfg2d, cfg1d, common);
|
||||
}
|
||||
|
||||
extern volatile uint32_t sys_tick_ms;
|
||||
|
||||
#if TEST_ENABLE_NG_GPIO
|
||||
/* NG output GPIO: PA8 push-pull, active-high when NG detected */
|
||||
#define NG_GPIO_PORT GPIOA
|
||||
#define NG_GPIO_PIN GPIO_Pin_8
|
||||
@@ -48,7 +65,6 @@ void OnConfigUpdate(const ConfigCommon_t *common, const Config2D_t *cfg2d, const
|
||||
#define NG_PULSE_MS 200 /* default NG pulse width */
|
||||
|
||||
static volatile uint32_t g_ng_off_time = 0;
|
||||
extern volatile uint32_t sys_tick_ms;
|
||||
|
||||
static void NG_GPIO_Init(void)
|
||||
{
|
||||
@@ -60,7 +76,9 @@ static void NG_GPIO_Init(void)
|
||||
GPIO_Init(NG_GPIO_PORT, &gpio);
|
||||
GPIO_ResetBits(NG_GPIO_PORT, NG_GPIO_PIN);
|
||||
}
|
||||
#endif /* TEST_ENABLE_NG_GPIO */
|
||||
|
||||
#if TEST_ENABLE_TEMP_REQ
|
||||
/* 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;
|
||||
@@ -71,7 +89,9 @@ void OnTempFrameRequest(uint8_t is2dRequest)
|
||||
g_temp_req_pending = 1;
|
||||
DBG_APP("TempFrameReq is2d=%d\r\n", (int)is2dRequest);
|
||||
}
|
||||
#endif /* TEST_ENABLE_TEMP_REQ */
|
||||
|
||||
#if TEST_ENABLE_NG_GPIO
|
||||
void OnDetectionResult(uint32_t frameNumber, uint8_t resultStatus)
|
||||
{
|
||||
(void)frameNumber;
|
||||
@@ -89,6 +109,7 @@ void OnDetectionResult(uint32_t frameNumber, uint8_t resultStatus)
|
||||
g_ng_off_time = sys_tick_ms + pulse_ms;
|
||||
}
|
||||
}
|
||||
#endif /* TEST_ENABLE_NG_GPIO */
|
||||
|
||||
#define KEEPALIVE_ENABLE 1
|
||||
|
||||
@@ -219,6 +240,7 @@ void WCHNET_HandleGlobalInt(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if TEST_ENABLE_HEARTBEAT
|
||||
/* ============================================================
|
||||
* RTOS Task: Heartbeat (periodic print for debug)
|
||||
* ============================================================ */
|
||||
@@ -240,6 +262,7 @@ static void task_heartbeat_entry(void *pvParameters)
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
}
|
||||
}
|
||||
#endif /* TEST_ENABLE_HEARTBEAT */
|
||||
|
||||
/* ============================================================
|
||||
* RTOS Task: WCHNET protocol stack driver (highest priority)
|
||||
@@ -261,12 +284,14 @@ static void task_wchnet_entry(void *pvParameters)
|
||||
/* ============================================================
|
||||
* RTOS Task: Business logic (DVP + preprocess + send)
|
||||
* ============================================================ */
|
||||
#if TEST_ENABLE_TRIGGER
|
||||
/* ============================================================
|
||||
* Burst capture state machine
|
||||
* ============================================================ */
|
||||
static uint8_t burst_active = 0; /* 1 = currently in burst */
|
||||
static uint8_t burst_remaining = 0; /* frames left to capture */
|
||||
static uint32_t burst_next_time_ms = 0; /* next burst frame time */
|
||||
#endif /* TEST_ENABLE_TRIGGER */
|
||||
|
||||
#if TEST_PATTERN_MODE
|
||||
/* ============================================================
|
||||
@@ -356,6 +381,7 @@ static void task_test_pattern_entry(void *pvParameters)
|
||||
}
|
||||
#endif /* TEST_PATTERN_MODE */
|
||||
|
||||
#if TEST_ENABLE_TEMP_REQ
|
||||
/* ============================================================
|
||||
* 1D mode: build and send a single 1D temperature frame from
|
||||
* the current raw image. Scans the center row and packs
|
||||
@@ -407,6 +433,7 @@ static void send_1d_frame_from_raw(const RawImageBuffer_t *raw, TcpTxBuffer_t *t
|
||||
|
||||
TcpLogic_BuildAndSendTemperatureFrame(tx_buf, &meta, 0x01, 0 /* IS_1D */);
|
||||
}
|
||||
#endif /* TEST_ENABLE_TEMP_REQ */
|
||||
|
||||
static void task_business_entry(void *pvParameters)
|
||||
{
|
||||
@@ -415,16 +442,19 @@ static void task_business_entry(void *pvParameters)
|
||||
|
||||
while (1)
|
||||
{
|
||||
#if TEST_ENABLE_NG_GPIO
|
||||
/* NG pulse off check */
|
||||
if (g_ng_off_time && sys_tick_ms >= g_ng_off_time) {
|
||||
GPIO_ResetBits(NG_GPIO_PORT, NG_GPIO_PIN);
|
||||
g_ng_off_time = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !TEST_PATTERN_MODE
|
||||
DVP_Task();
|
||||
#endif
|
||||
|
||||
#if TEST_ENABLE_TEMP_REQ
|
||||
/* Handle on-demand frame request from server */
|
||||
if (g_temp_req_pending)
|
||||
{
|
||||
@@ -447,6 +477,7 @@ static void task_business_entry(void *pvParameters)
|
||||
send_1d_frame_from_raw(&raw_img, tx_buf);
|
||||
}
|
||||
}
|
||||
#endif /* TEST_ENABLE_TEMP_REQ */
|
||||
|
||||
if (Frame_Ready_Flag)
|
||||
{
|
||||
@@ -458,6 +489,7 @@ static void task_business_entry(void *pvParameters)
|
||||
raw_img.Height = SENSOR_HEIGHT;
|
||||
raw_img.FrameNumber = Ready_Frame_Count;
|
||||
|
||||
#if TEST_ENABLE_TRIGGER
|
||||
if (burst_active)
|
||||
{
|
||||
/* Burst mode: wait for interval, then capture & send */
|
||||
@@ -477,10 +509,10 @@ static void task_business_entry(void *pvParameters)
|
||||
burst_active = 0;
|
||||
DBG_APP("Burst complete\r\n");
|
||||
} else {
|
||||
/* Read interval from config */
|
||||
ConfigCommon_t tc; Config2D_t t2; Config1D_t t1;
|
||||
uint16_t interval_ms = 0;
|
||||
if (TcpLogic_GetLatestConfig(&tc, &t2, &t1) == 0)
|
||||
uint16_t interval_ms = DEFAULT_BURST_INTERVAL_MS;
|
||||
if (TcpLogic_GetLatestConfig(&tc, &t2, &t1) == 0
|
||||
&& t2.TriggerInternalIntervalMs > 0)
|
||||
interval_ms = t2.TriggerInternalIntervalMs;
|
||||
burst_next_time_ms = sys_tick_ms + interval_ms;
|
||||
}
|
||||
@@ -506,14 +538,15 @@ static void task_business_entry(void *pvParameters)
|
||||
DBG_APP("PP fail ret=%d\r\n", (int)pp_ret);
|
||||
}
|
||||
|
||||
/* Determine burst count from config */
|
||||
/* Determine burst count from config (fall back to defaults) */
|
||||
ConfigCommon_t tc; Config2D_t t2; Config1D_t t1;
|
||||
uint8_t total_burst = 1;
|
||||
uint16_t interval_ms = 0;
|
||||
uint8_t total_burst = DEFAULT_BURST_COUNT;
|
||||
uint16_t interval_ms = DEFAULT_BURST_INTERVAL_MS;
|
||||
if (TcpLogic_GetLatestConfig(&tc, &t2, &t1) == 0) {
|
||||
if (t2.TriggerBurstCount > 1)
|
||||
if (t2.TriggerBurstCount >= 1)
|
||||
total_burst = t2.TriggerBurstCount;
|
||||
interval_ms = t2.TriggerInternalIntervalMs;
|
||||
if (t2.TriggerInternalIntervalMs > 0)
|
||||
interval_ms = t2.TriggerInternalIntervalMs;
|
||||
}
|
||||
if (total_burst > 1) {
|
||||
burst_active = 1;
|
||||
@@ -523,6 +556,7 @@ static void task_business_entry(void *pvParameters)
|
||||
(int)total_burst, (int)interval_ms);
|
||||
}
|
||||
}
|
||||
#endif /* TEST_ENABLE_TRIGGER */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -536,8 +570,12 @@ int main(void)
|
||||
u8 i;
|
||||
SystemCoreClockUpdate();
|
||||
Delay_Init();
|
||||
USART_Printf_Init(115200);
|
||||
USART_Printf_Init(921600);
|
||||
printf("TCPClient Test\r\nSystemClk:%d\r\n", SystemCoreClock);
|
||||
printf("=== Feature Switches ===\r\n");
|
||||
printf(" PATTERN=%d TRIGGER=%d NG_GPIO=%d TEMP_REQ=%d TCP_SEND=%d HB=%d\r\n",
|
||||
TEST_PATTERN_MODE, TEST_ENABLE_TRIGGER, TEST_ENABLE_NG_GPIO,
|
||||
TEST_ENABLE_TEMP_REQ, TEST_ENABLE_TCP_SEND, TEST_ENABLE_HEARTBEAT);
|
||||
printf("UserByte: %02x\r\n", FLASH_GetUserOptionByte() & 0xFF);
|
||||
Config_Flash_SRAM(FLASH_128_SRAM_192);
|
||||
printf("net version:%x\n", WCHNET_GetVer());
|
||||
@@ -556,7 +594,9 @@ int main(void)
|
||||
DVP_Init();
|
||||
#endif
|
||||
TIM2_Init();
|
||||
#if TEST_ENABLE_NG_GPIO
|
||||
NG_GPIO_Init();
|
||||
#endif
|
||||
|
||||
i = ETH_LibInit(IPAddr, GWIPAddr, IPMask, MACAddr);
|
||||
mStopIfError(i);
|
||||
@@ -598,15 +638,23 @@ int main(void)
|
||||
|
||||
TcpLogic_Init(MACAddr, NULL);
|
||||
TcpLogic_RegisterConfigCallback(OnConfigUpdate);
|
||||
#if TEST_ENABLE_NG_GPIO
|
||||
TcpLogic_RegisterDetectionCallback(OnDetectionResult);
|
||||
#endif
|
||||
#if TEST_ENABLE_TEMP_REQ
|
||||
TcpLogic_RegisterTempFrameRequestCallback(OnTempFrameRequest);
|
||||
#endif
|
||||
DBG_APP("TcpLogic_Start...\r\n");
|
||||
TcpLogic_Start();
|
||||
|
||||
DBG_APP("Creating RTOS tasks...\r\n");
|
||||
xTaskCreate(task_wchnet_entry, "wchnet", 512, NULL, 6, NULL);
|
||||
#if TEST_ENABLE_TCP_SEND
|
||||
xTaskCreate(task_business_entry, "business", 512, NULL, 5, NULL);
|
||||
#endif
|
||||
#if TEST_ENABLE_HEARTBEAT
|
||||
xTaskCreate(task_heartbeat_entry, "hb", 256, NULL, 3, NULL);
|
||||
#endif
|
||||
#if TEST_PATTERN_MODE
|
||||
xTaskCreate(task_test_pattern_entry, "testpat", 256, NULL, 4, NULL);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user