task_ec800_upload(6646).c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "task_ec800_upload.h"
  2. /* define ------------------------------------------------------------*/
  3. #define ANGLE_UPDATE_TIME 50 // 角度更新时间 2s 单位100ms
  4. #define SPEED_Go_STRAIGHT 25 // 直行速度 25KM/H 用来判断手把扶正 初始化姿态
  5. /* variables ---------------------------------------------------------*/
  6. // 拷贝数据
  7. void Task_Ec800_Uplaod_CopyRs485Date(rs485RecDate *p_rs485RecDate, messageDate *p_messageDate){
  8. /* 尝试获取互斥量,等待无限长时间 */
  9. if(osMutexAcquire(mutex_rs485RecDateHandle, osWaitForever) == osOK)
  10. {
  11. /* 安全地访问s_rs485RecDate结构体 */
  12. memcpy(&p_messageDate->vehicleSpeed, &p_rs485RecDate->vehicleSpeed, sizeof(p_rs485RecDate->vehicleSpeed));
  13. memcpy(&p_messageDate->dailyDrivTime, &p_rs485RecDate->dailyDrivTime, sizeof(p_rs485RecDate->dailyDrivTime));
  14. memcpy(&p_messageDate->dailyDrivMileage, &p_rs485RecDate->dailyDrivMileage, sizeof(p_rs485RecDate->dailyDrivMileage));
  15. memcpy(&p_messageDate->accTotalDrivTime_day, &p_rs485RecDate->accTotalDrivTime_day, sizeof(p_rs485RecDate->accTotalDrivTime_day));
  16. memcpy(&p_messageDate->accTotalDrivTime_h_min, &p_rs485RecDate->accTotalDrivTime_h_min, sizeof(p_rs485RecDate->accTotalDrivTime_h_min));
  17. memcpy(&p_messageDate->accTotalMileage_h, &p_rs485RecDate->accTotalMileage_h, sizeof(p_rs485RecDate->accTotalMileage_h));
  18. memcpy(&p_messageDate->accTotalMileage_l, &p_rs485RecDate->accTotalMileage_l, sizeof(p_rs485RecDate->accTotalMileage_l));
  19. memcpy(&p_messageDate->runTime, &p_rs485RecDate->runTime, sizeof(p_rs485RecDate->runTime));
  20. memcpy(&p_messageDate->batCompartmentTemp, &p_rs485RecDate->batCompartmentTemp, sizeof(p_rs485RecDate->batCompartmentTemp));
  21. memcpy(&p_messageDate->demandCur, &p_rs485RecDate->demandCur, sizeof(p_rs485RecDate->demandCur));
  22. memcpy(&p_messageDate->demandVol, &p_rs485RecDate->demandVol, sizeof(p_rs485RecDate->demandVol));
  23. memcpy(&p_messageDate->alarmLevel, &p_rs485RecDate->alarmLevel, sizeof(p_rs485RecDate->alarmLevel));
  24. memcpy(&p_messageDate->alarmType, &p_rs485RecDate->alarmType, sizeof(p_rs485RecDate->alarmType));
  25. memcpy(&p_messageDate->batSn, &p_rs485RecDate->batSn, sizeof(p_rs485RecDate->batSn));
  26. memcpy(&p_messageDate->Vehicle_Num, &p_rs485RecDate->Vehicle_Num, sizeof(p_rs485RecDate->Vehicle_Num));
  27. memcpy(&p_messageDate->VIN, &p_rs485RecDate->VIN, sizeof(p_rs485RecDate->VIN));
  28. /* 访问完成,释放互斥量 */
  29. osMutexRelease(mutex_rs485RecDateHandle);
  30. }
  31. // 车辆状态判断
  32. if(s_comData.driveStatus == 2){
  33. p_messageDate->vehicleStatus = 0;
  34. }else if(s_comData.driveStatus == 3){
  35. p_messageDate->vehicleStatus = 1;
  36. }
  37. // 故障数据copy
  38. p_messageDate->malfunction = s_comData.Malfunction;
  39. // 角度数据赋值
  40. p_messageDate->drivDirection = previousYaw;
  41. }
  42. /**
  43. * @brief 上传故障信息
  44. * @note 如果存在故障,每秒上传一次故障报告
  45. * @param 无
  46. * @retval 无
  47. */
  48. void upload_fault_info(void) {
  49. static uint8_t upload_interval_counter = 0; // 上传间隔计数器
  50. uint32_t faultCode = 0; // 临时的故障变量存储
  51. nmea_utc_time time = {0}; // 临时时间存储
  52. char storeFaultData[30] = {0};
  53. uint32_t time_stamp = 0; // 临时的时间戳
  54. // 检查存在MQTT故障,4G模块故障,或者未完成初始化,且记录索引等于上传索引 -- 不进行故障上传
  55. if((s_ec800Date.ec800InitFlag == 0)
  56. // || (BIT_CHECK(s_comData.Malfunction, init_4G_error))
  57. // || (BIT_CHECK(s_comData.Malfunction, errorMqtt))
  58. || (s_param_boot.faultRecordIndex == s_param_boot.faultUploadIndex)){
  59. return;
  60. }
  61. // 更新计数器
  62. if (upload_interval_counter < 250) {
  63. upload_interval_counter++;
  64. } else {
  65. upload_interval_counter = 0;
  66. }
  67. // 如果计数器达到上传间隔,上传故障报告
  68. if (upload_interval_counter % 10 != 0) {
  69. return;
  70. }
  71. // 从flash中获取故障
  72. norflash_read((uint8_t *)storeFaultData, s_param_boot.faultUploadAddr, 27);
  73. // 分解故障数据
  74. // 使用sscanf函数将字符串解析为指定的格式
  75. sscanf(storeFaultData, "%4hu%2hhu%2hhu-%2hhu%2hhu%2hhu:0x%x,",
  76. &time.year, &time.month, &time.date, &time.hour, &time.min, &time.sec, &faultCode);
  77. // 计算时间戳
  78. time_stamp = EC800_mktime(time.year, time.month, time.date, time.hour - 8, time.min, time.sec);
  79. // 上传故障
  80. EC800_uploadFaultReport(time_stamp, faultCode);
  81. // 更新索引和获取地址
  82. s_param_boot.faultUploadIndex = (s_param_boot.faultUploadIndex < MAX_RECORDS) ? (s_param_boot.faultUploadIndex + 1) : 0 ;
  83. // 更新地址
  84. s_param_boot.faultUploadAddr += 27;
  85. if(s_param_boot.faultUploadIndex == 0){
  86. s_param_boot.faultUploadAddr = 0;
  87. }
  88. // 保存最新的索引和地址数据
  89. Write_paramArea();
  90. }
  91. /**
  92. * @brief 上传任务内容
  93. * @param None
  94. * @note None
  95. * @retval None
  96. */
  97. void task_ec800_content(void)
  98. {
  99. // unsigned long times = 0;
  100. // 蜂鸣器响应
  101. // control_beep_response();
  102. // 检测是否正在升级固件
  103. if(s_ec800Date.hardwareUpdate == 1){
  104. osDelay(100);
  105. return;
  106. }
  107. // 拷贝485接收道德数据到待发送的消息中
  108. Task_Ec800_Uplaod_CopyRs485Date(&s_rs485RecDate, &s_messageDate);
  109. // MQTT服务器数据接收处理
  110. handleReceive();
  111. // 4G模块的操作
  112. EC800_stateTransition_use();
  113. // 上传故障信息
  114. upload_fault_info();
  115. // times = getRunTimeCounterValue();
  116. // printf("task run time: %ld\r\n", times);
  117. osDelay(100);
  118. }