Rtk.cpp 6.8 KB

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