123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #include <stdint.h>
- #include <stdlib.h>
- #include "../common/comm.h"
- #include "../common/iobuffer.h"
- #include "../common/sensor_socket.h"
- #include "Rtk.h"
- #include "message_queue.h"
- #include "MqttClient.h"
- #include "imu_sensor.h"
- #include <string.h>
- #include <sys/time.h>
- CRtkSensor::CRtkSensor(CMessageQueue* q) :_message(q)
- {
- F_SendDate = false;
- _run = false;
- }
- void CRtkSensor::Notify(int8_t* buffer, int32_t size)
- {
-
-
-
-
-
- if(_run)
- {
- int Temp = ',';
- unsigned char* p = NULL, * p1 = NULL;
- p = (unsigned char*)strchr((const char*)buffer, Temp);
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- float headingAngle = strtof((const char*)p + 1, NULL);
-
-
- ImuData m_imu;
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
-
-
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
-
-
-
-
-
-
-
-
-
-
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- float lat = strtof((const char*)p1 + 1, NULL);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- float lon = strtof((const char*)p + 1, NULL);
-
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- float loc_status = strtof((const char*)p + 1, NULL);
-
- m_imu.rx = strtof((const char*)p + 1, NULL);
- if(m_imu.rx == 42)
- m_imu.ry =1;
- else
- m_imu.ry = 0;
-
- _message ->WriteIMUData((&m_imu));
-
-
- if (!F_SendDate)
- {
- _curTick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- F_SendDate = true;
- }
- else
- {
- long long tick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- if (_curTick != 0 && tick - _curTick > 300)
- {
- if (CMqttSensor::_run && (CMqttSensor::m_mqttClient != NULL))
- Send_ZGJ_Rtk(headingAngle, lat, lon,loc_status);
- F_SendDate = false;
- }
- }
- }
-
- }
- void CRtkSensor::Start()
- {
- _run = true;
- }
- void CRtkSensor::Run()
- {
- }
- void CRtkSensor::SetSensorSocket(SensorSocket<CRtkSensor>* udp)
- {
- _socket = udp;
- }
- void CRtkSensor::Stop()
- {
- F_SendDate = false;
- _run = false;
- }
- #include "../thirdparty/jsoncpp/include/json/json.h"
- void CRtkSensor::Send_ZGJ_Rtk(float headingAngle,float lat,float lon,float loc_status)
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- char m_Send[16],Dst[16];
- memset(Dst, 0, 16);
- sprintf((char*)Dst, "%ld", tv.tv_sec * 1000 + tv.tv_usec / 1000);
- Json::Value root;
- Json::Value Source;
- Json::FastWriter writer;
- std::string SendTime;
- std::string m_headingAngle;
- std::string m_lon;
- std::string m_lat;
- std::string m_loc_status;
- Source["deviceEsn"] = "";
- Source["cloudEsn"] = CMqttSensor::_Esn;
- Source["sendTime"] = SendTime.assign(Dst,strlen(Dst));
- Source["ack"] = false;
- Source["seqNum"] = CMqttSensor::_Esn + SendTime.assign(Dst,strlen(Dst));
- Json::Value GraspGPS;
- GraspGPS["graspEsn"] = CMqttSensor::_Esn;
- memset(m_Send, 0, 16);
- sprintf((char*)m_Send, "%.7f", lon);
- GraspGPS["lon"] = m_lon.assign(m_Send);
- memset(m_Send, 0, 16);
- sprintf((char*)m_Send, "%.7f", lat);
- GraspGPS["lat"] = m_lat.assign(m_Send);
- memset(m_Send, 0, 16);
- sprintf((char*)m_Send, "%.2f", headingAngle);
- GraspGPS["headingAngle"] = m_headingAngle.assign(m_Send);
- GraspGPS["timeStamp"] = SendTime.assign(Dst,strlen(Dst));
- memset(m_Send, 0, 16);
- sprintf((char*)m_Send, "%.0f", loc_status);
- GraspGPS["loc_status"] = m_loc_status.assign(m_Send);
- Source["graspInfoList"].append(GraspGPS);
- Json::StyledWriter sw;
-
-
- char Topic[64];
- memset(Topic, 0, 64);
- sprintf(Topic, "v2x/v1/grasp/%s/info/up", CMqttSensor::_Esn.c_str());
- CMqttSensor::sendMessage((char*)sw.write(Source).c_str(), 0, (char*)Topic);
- }
- void CRtkSensor::Send_ZGJ_status(int Status)
- {
- if (CMqttSensor::_run)
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- char Dst[16];
- memset(Dst, 0, 16);
- sprintf((char*)Dst, "%ld", tv.tv_sec * 1000 + tv.tv_usec / 1000);
- Json::Value root;
- Json::Value Source;
- Json::FastWriter writer;
- std::string SendTime;
- Source["deviceEsn"] = "";
- Source["cloudEsn"] = CMqttSensor::_Esn;
- Source["sendTime"] = SendTime.assign(Dst,strlen(Dst));
- Source["ack"] = true;
- Source["seqNum"] = CMqttSensor::_Esn + SendTime.assign(Dst,strlen(Dst));
- Json::Value GraspStatus;
- GraspStatus["graspEsn"] = CMqttSensor::_Esn;
- GraspStatus["status"] = Status;
- GraspStatus["timeStamp"] = SendTime.assign(Dst,strlen(Dst));
- Source["graspStatusList"].append(GraspStatus);
- Json::StyledWriter sw;
-
- char Topic[64];
- memset(Topic, 0, 64);
- sprintf(Topic, "v2x/v1/grasp/%s/status/up", CMqttSensor::_Esn.c_str());
- CMqttSensor::sendMessage((char*)sw.write(Source).c_str(), 0, (char*)Topic);
- }
- }
|