123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- #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;
- }
- gtime_t CRtkSensor::timeadd(gtime_t t, double sec)
- {
- double tt;
-
- t.sec+=sec; tt=floor(t.sec); t.time+=(int)tt; t.sec-=tt;
- return t;
- }
- double CRtkSensor::timediff(gtime_t t1, gtime_t t2)
- {
- return difftime(t1.time,t2.time)+t1.sec-t2.sec;
- }
- gtime_t CRtkSensor::epoch2time(const double *ep)
- {
- const int doy[]={1,32,60,91,121,152,182,213,244,274,305,335};
- gtime_t time={0};
- int days,sec,year=(int)ep[0],mon=(int)ep[1],day=(int)ep[2];
-
- if (year<1970||2099<year||mon<1||12<mon) return time;
-
-
- days=(year-1970)*365+(year-1969)/4+doy[mon-1]+day-2+(year%4==0&&mon>=3?1:0);
- sec=(int)floor(ep[5]);
- time.time=(time_t)days*86400+(int)ep[3]*3600+(int)ep[4]*60+sec;
- time.sec=ep[5]-sec;
- return time;
- }
- gtime_t CRtkSensor::gpst2utc(gtime_t t)
- {
- gtime_t tu;
- int i;
-
- for (i=0;leaps[i][0]>0;i++) {
- tu=timeadd(t,leaps[i][6]);
- if (timediff(tu,epoch2time(leaps[i]))>=0.0) return tu;
- }
- return t;
- }
- 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);
- float gpsweek = strtof((const char*)p1 + 1, NULL);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- float gpsTime = strtof((const char*)p + 1, NULL);
- 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(gpsweek,gpsTime,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 gpsweek,float gpsTime,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, "%f", rtk_time.time * 1000 + rtk_time.sec);
-
- 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);
-
- rtk_time.time = gpsweek * 604800 + int(gpsTime);
- rtk_time.sec = gpsTime - int(gpsTime);
- char Dst[16];
- memset(Dst, 0, 16);
-
- sprintf((char*)Dst, "%f", rtk_time.time*1000 + rtk_time.sec*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);
- }
- }
|