Rtk.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include <stdint.h>
  2. #include "../common/comm.h"
  3. #include "../common/iobuffer.h"
  4. #include "../common/sensor_socket.h"
  5. #include "Rtk.h"
  6. #include "message_queue.h"
  7. #include "MqttClient.h"
  8. #include "imu_sensor.h"
  9. #include <string.h>
  10. #include <sys/time.h>
  11. CRtkSensor::CRtkSensor(CMessageQueue* q) :_message(q)
  12. {
  13. F_SendDate = false;
  14. _run = false;
  15. }
  16. void CRtkSensor::Notify(int8_t* buffer, int32_t size)
  17. {
  18. //$GPCHC,1980,4632.64,289.19,-0.42,0.21,-0.23,0.07,-0.06,
  19. // p p1 p p1 p p1 p p1 p
  20. //0.0009,0.0048,-1.0037,38.8594969,121.5150073,121.51,-0.023,0.011,0.011,1.500,14,6,42,0,2*67
  21. // p1 p p1 p
  22. if(_run)
  23. {
  24. int Temp = ',';
  25. unsigned char* p = NULL, * p1 = NULL;
  26. p = (unsigned char*)strchr((const char*)buffer, Temp);
  27. p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
  28. p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
  29. float headingAngle = strtof((const char*)p + 1, NULL);
  30. //����IMU
  31. ImuData m_imu;
  32. p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
  33. m_imu.rx = strtof((const char*)p1 + 1, NULL);
  34. p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
  35. m_imu.ry = strtof((const char*)p + 1, NULL);
  36. _count++;
  37. if (_count > 20)
  38. {
  39. _message->WriteIMUData(&m_imu);
  40. //std::cout << "Send Date" << std::endl;
  41. _count = 0;
  42. }
  43. p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
  44. p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
  45. p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
  46. p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
  47. p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
  48. p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
  49. p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
  50. float lat = strtof((const char*)p1 + 1, NULL);
  51. p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
  52. float lon = strtof((const char*)p + 1, NULL);
  53. /*_count++;
  54. if (_count > 10)
  55. {
  56. if(CMqttSensor::_run)
  57. Send_ZGJ_Rtk(headingAngle, lat, lon);
  58. _count = 0;
  59. }*/
  60. if (!F_SendDate)
  61. {
  62. _curTick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  63. F_SendDate = true;
  64. }
  65. else
  66. {
  67. long long tick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  68. if (_curTick != 0 && tick - _curTick > 300)
  69. {
  70. if (CMqttSensor::_run && (CMqttSensor::m_mqttClient != NULL))
  71. Send_ZGJ_Rtk(headingAngle, lat, lon);
  72. F_SendDate = false;
  73. }
  74. }
  75. }
  76. }
  77. void CRtkSensor::Start()
  78. {
  79. _run = true;
  80. }
  81. void CRtkSensor::Run()
  82. {
  83. }
  84. void CRtkSensor::SetSensorSocket(SensorSocket<CRtkSensor>* udp)
  85. {
  86. _socket = udp;
  87. }
  88. void CRtkSensor::Stop()
  89. {
  90. F_SendDate = false;
  91. _run = false;
  92. }
  93. #include "../thirdparty/jsoncpp/include/json/json.h"
  94. void CRtkSensor::Send_ZGJ_Rtk(float headingAngle,float lat,float lon)//ץ�ֻ�λ����Ϣ�ϱ�
  95. {
  96. struct timeval tv;
  97. gettimeofday(&tv, NULL);
  98. char m_Send[16],Dst[16];
  99. memset(Dst, 0, 16);
  100. sprintf((char*)Dst, "%ld", tv.tv_sec * 1000 + tv.tv_usec / 1000);
  101. Json::Value root;
  102. Json::Value Source;
  103. Json::FastWriter writer;
  104. std::string SendTime;
  105. std::string m_headingAngle;
  106. std::string m_lon;
  107. std::string m_lat;
  108. Source["deviceEsn"] = "";
  109. Source["cloudEsn"] = CMqttSensor::_Esn;
  110. Source["sendTime"] = SendTime.assign(Dst,strlen(Dst));
  111. Source["ack"] = false;
  112. Source["seqNum"] = CMqttSensor::_Esn + SendTime.assign(Dst,strlen(Dst));
  113. Json::Value GraspGPS;
  114. GraspGPS["graspEsn"] = CMqttSensor::_Esn;
  115. memset(m_Send, 0, 16);
  116. sprintf((char*)m_Send, "%.7f", lon);
  117. GraspGPS["lon"] = m_lon.assign(m_Send);
  118. memset(m_Send, 0, 16);
  119. sprintf((char*)m_Send, "%.7f", lat);
  120. GraspGPS["lat"] = m_lat.assign(m_Send);
  121. memset(m_Send, 0, 16);
  122. sprintf((char*)m_Send, "%.2f", headingAngle);
  123. GraspGPS["headingAngle"] = m_headingAngle.assign(m_Send);
  124. GraspGPS["timeStamp"] = SendTime.assign(Dst,strlen(Dst));
  125. Source["graspInfoList"].append(GraspGPS);
  126. Json::StyledWriter sw;
  127. //std::cout << sw.write(Source) << std::endl << std::endl;
  128. //CMqttSensor::sendMessage((char*)sw.write(Source).c_str(), 1, (char*)*(CMqttSensor::subTopic));
  129. char Topic[64];
  130. memset(Topic, 0, 64);
  131. sprintf(Topic, "v2x/v1/grasp/%s/info/up", CMqttSensor::_Esn.c_str());
  132. CMqttSensor::sendMessage((char*)sw.write(Source).c_str(), 0, (char*)Topic);
  133. }
  134. void CRtkSensor::Send_ZGJ_status(int Status)//ץ�ֻ�״̬��Ϣ�ϱ�
  135. {
  136. if (CMqttSensor::_run)
  137. {
  138. struct timeval tv;
  139. gettimeofday(&tv, NULL);
  140. char Dst[16];
  141. memset(Dst, 0, 16);
  142. sprintf((char*)Dst, "%ld", tv.tv_sec * 1000 + tv.tv_usec / 1000);
  143. Json::Value root;
  144. Json::Value Source;
  145. Json::FastWriter writer;
  146. std::string SendTime;
  147. Source["deviceEsn"] = "";
  148. Source["cloudEsn"] = CMqttSensor::_Esn;
  149. Source["sendTime"] = SendTime.assign(Dst,strlen(Dst));
  150. Source["ack"] = true;
  151. Source["seqNum"] = CMqttSensor::_Esn + SendTime.assign(Dst,strlen(Dst));
  152. Json::Value GraspStatus;
  153. GraspStatus["graspEsn"] = CMqttSensor::_Esn;
  154. GraspStatus["status"] = Status;
  155. GraspStatus["timeStamp"] = SendTime.assign(Dst,strlen(Dst));
  156. Source["graspStatusList"].append(GraspStatus);
  157. Json::StyledWriter sw;
  158. //std::cout << sw.write(Source) << std::endl << std::endl;
  159. char Topic[64];
  160. memset(Topic, 0, 64);
  161. sprintf(Topic, "v2x/v1/grasp/%s/status/up", CMqttSensor::_Esn.c_str());
  162. CMqttSensor::sendMessage((char*)sw.write(Source).c_str(), 0, (char*)Topic);
  163. }
  164. }