task_ec800_upload(1404).c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  33. * @brief 上传任务内容
  34. * @param None
  35. * @note None
  36. * @retval None
  37. */
  38. void task_ec800_content(void)
  39. {
  40. // unsigned long times = 0;
  41. static uint8_t firstFlag = 0; // 初次标志
  42. messageDate *p_messageDate = &s_messageDate; // 定义消息指针
  43. uint8_t recBack = 0;
  44. // 拷贝485接收道德数据到待发送的消息中
  45. Task_Ec800_Uplaod_CopyRs485Date(&s_rs485RecDate, &s_messageDate);
  46. // 4G模块的操作
  47. EC800_stateTransition_use();
  48. // 陀螺仪姿态初始化
  49. // 速度达到25km/s往上,判断手把握正
  50. if((p_messageDate->vehicleSpeed > SPEED_Go_STRAIGHT) && (firstFlag == 0)){
  51. recBack = atk_ms6050_init();
  52. if(recBack != 0){
  53. printf("ATK-MS6050 init failed!\r\n");
  54. return;
  55. }
  56. printf("ATK-MS6050 init\r\n");
  57. recBack = atk_ms6050_dmp_init();
  58. if(recBack != 0){
  59. printf("ATK-MS6050 DMP init failed!\r\n");
  60. return;
  61. }
  62. printf("ATK-MS6050 DMP init!\r\n");
  63. firstFlag = 1;
  64. }
  65. // 判断车辆是否正在转弯 陀螺仪数据
  66. if((firstFlag == 1) && (s_ec800Date.hardwareUpdate != 1)){
  67. if (isTurning()) {
  68. printf("The vehicle is turning.\r\n");
  69. } else {
  70. printf("Vehicle not turning.\r\n");
  71. }
  72. }
  73. // times = getRunTimeCounterValue();
  74. // printf("任务运行时间: %ld\r\n", times);
  75. osDelay(100);
  76. }