ReaddataTask02.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. void ReaddataTask02(void *argument)
  2. {
  3. /* USER CODE BEGIN ReaddataTask02 */
  4. /* Infinite loop */
  5. uint8_t fdc2214_ready = 0;
  6. float cap1 =0;
  7. uint16_t deviceID = 0;
  8. uint8_t deviceValid = 0; // 设备ID是否有效的标志
  9. uint32_t lastCheckTime = 0; // 记录上次检查时间
  10. const uint32_t checkInterval = 5000; // 5秒检查间隔(毫秒)
  11. static int dropped_cnt = 0; // 监测未消费数据丢弃计数器
  12. Filter_msg1 msg;
  13. for(;;)
  14. {
  15. // 初始化检查
  16. if (!fdc2214_ready)
  17. {
  18. fdc2214_ready = (FDC2214_Init() == 0) ? 1 : 0;
  19. if (!fdc2214_ready)
  20. {
  21. FDC_PRINTF("\r\nRetrying FDC2214 init in 1s ...");
  22. osDelay(1000);
  23. continue;
  24. }else{
  25. deviceValid = 1;
  26. }
  27. }
  28. // 每5秒检查一次设备ID
  29. uint32_t currentTime = osKernelGetTickCount();
  30. if (currentTime - lastCheckTime >= checkInterval)
  31. {
  32. deviceID = FDC2214_Read16(FDC2214_Addr, FDC2214_DEVICE_ID); //读器件ID
  33. FDC_PRINTF("\r\nDevice ID: 0x%04X", deviceID);
  34. if (deviceID == 0x3055)
  35. {
  36. deviceValid = 1;
  37. }
  38. else
  39. {
  40. deviceValid = 0;
  41. fdc2214_ready = 0; // 重新初始化
  42. FDC_PRINTF("\r\nDevice ID ERROR!");
  43. osDelay(1000);
  44. }
  45. lastCheckTime = currentTime;
  46. }
  47. // 只有设备ID有效时才采集数据
  48. if (deviceValid)
  49. {
  50. cap1 = getcap(0, 18, 13) - 43.1f; // 采集数据 通道0,电感,电容 /* 并联 18uh - 13pf : 测量47pf , -30.6 , 并联 18uh - 33pf : 测量47pf , -43.1 */
  51. Filter_msg1 msg;
  52. msg.data = cap1;
  53. // 将数据放入队列
  54. if (xQueueSend(filterqueue1Handle, &msg, pdMS_TO_TICKS(1)) != pdPASS) {
  55. dropped_cnt++;
  56. FDC_PRINTF("\r\nQueue full, cap=%.3f not sent. Dropped=%d", cap1, dropped_cnt);
  57. }
  58. }
  59. osDelay(10);
  60. }
  61. /* USER CODE END ReaddataTask02 */
  62. }