12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- void ReaddataTask02(void *argument)
- {
- /* USER CODE BEGIN ReaddataTask02 */
- /* Infinite loop */
- uint8_t fdc2214_ready = 0;
- float cap1 =0;
- uint16_t deviceID = 0;
- uint8_t deviceValid = 0; // 设备ID是否有效的标志
- uint32_t lastCheckTime = 0; // 记录上次检查时间
- const uint32_t checkInterval = 5000; // 5秒检查间隔(毫秒)
- static int dropped_cnt = 0; // 监测未消费数据丢弃计数器
- Filter_msg1 msg;
- for(;;)
- {
- // 初始化检查
- if (!fdc2214_ready)
- {
- fdc2214_ready = (FDC2214_Init() == 0) ? 1 : 0;
- if (!fdc2214_ready)
- {
- FDC_PRINTF("\r\nRetrying FDC2214 init in 1s ...");
- osDelay(1000);
- continue;
- }else{
- deviceValid = 1;
- }
- }
- // 每5秒检查一次设备ID
- uint32_t currentTime = osKernelGetTickCount();
- if (currentTime - lastCheckTime >= checkInterval)
- {
- deviceID = FDC2214_Read16(FDC2214_Addr, FDC2214_DEVICE_ID); //读器件ID
- FDC_PRINTF("\r\nDevice ID: 0x%04X", deviceID);
-
- if (deviceID == 0x3055)
- {
- deviceValid = 1;
- }
- else
- {
- deviceValid = 0;
- fdc2214_ready = 0; // 重新初始化
- FDC_PRINTF("\r\nDevice ID ERROR!");
- osDelay(1000);
- }
-
- lastCheckTime = currentTime;
- }
-
- // 只有设备ID有效时才采集数据
- if (deviceValid)
- {
- cap1 = getcap(0, 18, 13) - 43.1f; // 采集数据 通道0,电感,电容 /* 并联 18uh - 13pf : 测量47pf , -30.6 , 并联 18uh - 33pf : 测量47pf , -43.1 */
- Filter_msg1 msg;
- msg.data = cap1;
- // 将数据放入队列
- if (xQueueSend(filterqueue1Handle, &msg, pdMS_TO_TICKS(1)) != pdPASS) {
- dropped_cnt++;
- FDC_PRINTF("\r\nQueue full, cap=%.3f not sent. Dropped=%d", cap1, dropped_cnt);
- }
- }
-
- osDelay(10);
- }
- /* USER CODE END ReaddataTask02 */
- }
|