123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- #include <stdint.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,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);
- 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);
- //����IMU
- ImuData m_imu;
- p1 = (unsigned char*)strchr((const char*)p + 1, Temp);
- m_imu.rx = strtof((const char*)p1 + 1, NULL);
-
- p = (unsigned char*)strchr((const char*)p1 + 1, Temp);
- 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);
- 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);
- /*_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);
- 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)//ץ�ֻ�λ����Ϣ�ϱ�
- {
- 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;
- 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));
- 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);
- }
- }
|