task_ec800_upload(5150).c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. void gyroscope_fault_deal(void){
  44. uint8_t recBack = 0;
  45. if(BIT_CHECK(s_comData.Malfunction, gyroscope)){
  46. recBack = atk_ms6050_init();
  47. if(recBack != 0){
  48. printf("ATK-MS6050 init failed!\r\n");
  49. return;
  50. }
  51. printf("ATK-MS6050 init\r\n");
  52. recBack = atk_ms6050_dmp_init();
  53. if(recBack != 0){
  54. printf("ATK-MS6050 DMP init failed!\r\n");
  55. return;
  56. }
  57. printf("ATK-MS6050 DMP init!\r\n");
  58. BIT_CLEAR(s_comData.Malfunction, gyroscope);
  59. }
  60. }
  61. /**
  62. * @brief 上传故障信息
  63. * @note 如果存在故障,每秒上传一次故障报告
  64. * @param 无
  65. * @retval 无
  66. */
  67. void upload_fault_info(void) {
  68. static uint8_t upload_interval_counter = 0; // 上传间隔计数器
  69. comData *p_comData = &s_comData;
  70. // 检查是否存在故障
  71. if (p_comData->Malfunction == 0) {
  72. return; // 如果没有故障,直接返回
  73. }
  74. // 如果计数器达到上传间隔,上传故障报告
  75. if (upload_interval_counter % 10 == 0) {
  76. EC800_uploadFaultReport();
  77. }
  78. // 更新计数器
  79. if (upload_interval_counter < 250) {
  80. upload_interval_counter++;
  81. } else {
  82. upload_interval_counter = 0;
  83. }
  84. }
  85. /**
  86. * @brief 上传任务内容
  87. * @param None
  88. * @note None
  89. * @retval None
  90. */
  91. void task_ec800_content(void)
  92. {
  93. // unsigned long times = 0;
  94. // 蜂鸣器响应
  95. control_beep_response();
  96. // 检测是否正在升级固件
  97. if(s_ec800Date.hardwareUpdate == 1){
  98. osDelay(100);
  99. return;
  100. }
  101. // 拷贝485接收道德数据到待发送的消息中
  102. Task_Ec800_Uplaod_CopyRs485Date(&s_rs485RecDate, &s_messageDate);
  103. // MQTT服务器数据接收处理
  104. handleReceive();
  105. // 4G模块的操作
  106. EC800_stateTransition_use();
  107. // 上传故障信息
  108. upload_fault_info();
  109. // 陀螺仪故障处理 尝试重新连接
  110. gyroscope_fault_deal();
  111. // 判断车辆是否正在转弯 陀螺仪数据
  112. if (isTurning()) {
  113. printf("The vehicle is turning.\r\n");
  114. } else {
  115. printf("Vehicle not turning.\r\n");
  116. }
  117. // times = getRunTimeCounterValue();
  118. // printf("任务运行时间: %ld\r\n", times);
  119. osDelay(100);
  120. }