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)
- {
- //$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
- //$GPCHC,1980,4632.64,289.19,-0.42,0.21,-0.23,0.07,-0.06,
- // p p1 p p1 p p1 p p1 p
- //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
- // p1 p p1 p
- if(_run)
- {
- int Temp = ',';
- unsigned char* p = NULL, * p1 = NULL;
- p = (unsigned char*)strchr((const char*)buffer, Temp); //header
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //Gpsweek
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //gpsTIME
- float headingAngle = strtof((const char*)p + 1, NULL); //heading
- //std::cout << "angle" <<headingAngle << std::endl;
- //����IMU
- ImuData m_imu;
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);//pithch
- // m_imu.rx = strtof((const char*)p1 + 1, NULL);
-
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);//roll
- // m_imu.ry = strtof((const char*)p + 1, NULL);
- // _count++;
- // if (_count > 20)
- // {
- // _message->WriteIMUData(&m_imu);
- // //std::cout << "Send Date" << std::endl;
- // _count = 0;
- // }
-
-
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //gyro x
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //gyro y
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //gyro z
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //acc x
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //acc y
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //acc z
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //lat
- float lat = strtof((const char*)p1 + 1, NULL);
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //lon
- float lon = strtof((const char*)p + 1, NULL);
- //增加
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //alti
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //Ve
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //Vn
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //Vu
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //V
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //NSV1
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp); //NSV2
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp); //STATUS
- float loc_status = strtof((const char*)p + 1, NULL); //
- // std::cout << "loc status" << loc_status << std::endl;
- m_imu.rx = strtof((const char*)p + 1, NULL); //
- if(m_imu.rx == 42)
- m_imu.ry =1;
- else
- m_imu.ry = 0;
- // m_imu.ry = strtof((const char*)p + 1, NULL); //
- _message ->WriteIMUData((&m_imu));
-
- /*_count++;
- if (_count > 10)
- {
- if(CMqttSensor::_run)
- Send_ZGJ_Rtk(headingAngle, lat, lon);
- _count = 0;
- }*/
- 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;
- //std::cout << sw.write(Source) << std::endl << std::endl;
- //CMqttSensor::sendMessage((char*)sw.write(Source).c_str(), 1, (char*)*(CMqttSensor::subTopic));
- 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;
- //std::cout << sw.write(Source) << std::endl << std::endl;
- 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);
- }
- }
|