task_communication(114).c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "task_communication.h"
  2. /* typedef -----------------------------------------------------------*/
  3. comData s_comData = {
  4. .maxFeed = 60,
  5. .maxRunFeed = 0,
  6. };
  7. // 定义测试函数
  8. void test_isPointInPolygon(comData *p_comData) {
  9. // 定义多边形的经纬度坐标集合
  10. double polygonLat[] = {34.34934, 34.25916, 34.36221, 34.21619};
  11. double polygonLng[] = {108.84569, 108.80257, 109.03829, 109.05611};
  12. // 测试点在多边形内部的情况
  13. double point1Lat = 34.33312;
  14. double point1Lng = 108.8531;
  15. /* 尝试获取互斥量,等待无限长时间 */
  16. if(osMutexAcquire(s_messageDate_locationHandle, osWaitForever) == osOK)
  17. {
  18. /* 安全地访问s_rs485RecDate结构体 */
  19. point1Lat = s_messageDate.latitude / 100000;
  20. point1Lng = s_messageDate.longitude / 100000;
  21. /* 访问完成,释放互斥量 */
  22. osMutexRelease(s_messageDate_locationHandle);
  23. }
  24. bool result1 = isPointInPolygon(point1Lat, point1Lng, polygonLat, polygonLng);
  25. printf("Test case 1: Point (%f, %f) is%s inside the polygon.\n", point1Lat, point1Lng, result1 ? "" : " not");
  26. if(result1){ // 处于围栏内
  27. p_comData->fenceStatus = 0;
  28. }else{ // 处于围栏外
  29. p_comData->fenceStatus = 1;
  30. }
  31. // 从初始态转为中间静止态
  32. if(p_comData->driveStatus == 0){
  33. p_comData->driveStatus = 1;
  34. }
  35. }
  36. // 下发的车时速控制,运行状态的切换
  37. // 初始化时
  38. // 时速为0的情况 :1. MQTT通信超时 2. 围栏未初始化时
  39. // 时速为max的情况:在围栏内行驶
  40. // 运行中超出围栏 以每秒减1km/h的速度下调直至超出围栏
  41. void Speed_Control(comData *p_comData, ec800Date *p_ec800Date, rs485RecDate *p_rs485RecDate){
  42. // 1. 判断时速为0的情况
  43. if((p_ec800Date->fenceRecSuccess == 0) || (p_comData->Malfunction == 0x04)){ // 围栏未初始化时
  44. p_comData->maxRunFeed = 0;
  45. }else{ // 2. 时速为max的情况
  46. if(p_comData->fenceStatus == 0){ // 围栏内行驶
  47. p_comData->maxRunFeed = p_comData->maxFeed;
  48. }else{
  49. if(p_comData->driveStatus == 1){ // 如果初始态超出围栏
  50. p_comData->maxRunFeed = 0;
  51. }else { // 运行态超出围栏
  52. if(p_comData->maxRunFeed > 0){
  53. p_comData->maxRunFeed = p_comData->maxRunFeed - 1;
  54. }else{
  55. p_comData->maxRunFeed = 0;
  56. }
  57. }
  58. // 车速判断 判断车的运行状态
  59. if(p_rs485RecDate->vehicleSpeed == 0){
  60. p_comData->driveStatus = 2;
  61. }else if(p_rs485RecDate->vehicleSpeed >= 10){
  62. p_comData->driveStatus = 3;
  63. }
  64. }
  65. }
  66. }
  67. /* USER CODE BEGIN Header_Task_communication */
  68. /**
  69. * @brief Function implementing the communication thread.
  70. * @param argument: Not used
  71. * @retval None
  72. */
  73. /* USER CODE END Header_Task_communication */
  74. void task_communication_content(void)
  75. {
  76. // unsigned long times = 0;
  77. LED0_TOGGLE(); // 灯翻转
  78. EC800_FTP_OTA_Upgrade(); // OTA升级
  79. // 固件升级时不做其他操作,保证固件更新的完成
  80. if(s_ec800Date.hardwareUpdate != 0){
  81. HAL_NVIC_DisableIRQ(USART3_IRQn); // 避免被中斷
  82. // HAL_NVIC_DisableIRQ(USART1_IRQn);
  83. vTaskSuspend(ec800_dataUploaHandle); // 挂起任务
  84. osDelay(200);
  85. }else{
  86. if(s_ec800Date.fenceRecSuccess == 1){ // 围栏数据接收完成 执行围栏判断
  87. test_isPointInPolygon(&s_comData); // 电子围栏
  88. }
  89. Speed_Control(&s_comData, &s_ec800Date, &s_rs485RecDate); // 速度控制
  90. rs485_poll_sendReceive(s_comData.maxRunFeed); // 与车进行通信
  91. osDelay(1000);
  92. }
  93. // times = getRunTimeCounterValue();
  94. // printf("test_isPointInPolygon:%ld\r\n", times);
  95. }