task_ec800_upload(6643).c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. comData *p_comData = &s_comData;
  51. // 检查是否存在故障
  52. if (p_comData->Malfunction == 0) {
  53. return; // 如果没有故障,直接返回
  54. }
  55. // 如果计数器达到上传间隔,上传故障报告
  56. if (upload_interval_counter % 10 == 0) {
  57. EC800_uploadFaultReport();
  58. }
  59. // 更新计数器
  60. if (upload_interval_counter < 250) {
  61. upload_interval_counter++;
  62. } else {
  63. upload_interval_counter = 0;
  64. }
  65. }
  66. /**
  67. * @brief 上传任务内容
  68. * @param None
  69. * @note None
  70. * @retval None
  71. */
  72. void task_ec800_content(void)
  73. {
  74. // unsigned long times = 0;
  75. // 蜂鸣器响应
  76. // control_beep_response();
  77. // 检测是否正在升级固件
  78. if(s_ec800Date.hardwareUpdate == 1){
  79. osDelay(100);
  80. return;
  81. }
  82. // // 拷贝485接收道德数据到待发送的消息中
  83. // Task_Ec800_Uplaod_CopyRs485Date(&s_rs485RecDate, &s_messageDate);
  84. //
  85. // // MQTT服务器数据接收处理
  86. // handleReceive();
  87. //
  88. // // 4G模块的操作
  89. // EC800_stateTransition_use();
  90. //
  91. // // 上传故障信息
  92. // upload_fault_info();
  93. // times = getRunTimeCounterValue();
  94. // printf("task run time: %ld\r\n", times);
  95. osDelay(100);
  96. }