123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- #ifndef PC5_H
- #define PC5_H
- //#include <QWidget>
- //#include <QAbstractSocket>
- //#include <QDialog>
- #include <QTimer>
- #include <QDateTime>
- #include <QQueue>
- //#include <QUdpSocket>
- #include <QTcpServer>
- #include <QSerialPort>
- #include "ivlog.h"
- //std::string VIN="A1000000CATARCS01";
- #define TrafficLight (0x01)
- #define RealtimeTraffic (0x02)
- #define CollisionEarlyWarning (0x03)
- #define CongestionIdentification (0x04)
- #define AutoDriveSystemOpenFlag (0x21)
- #define VehicleBaseInfo (0x80)
- #define ResponseMessage (0x81)
- #define VirtualVehicle (0x82)
- #define commentsend (0xFE)//命令
- #define resuccess (0x01)//成功
- #define reerror (0x02)//错误
- #define periodic_send (0x00)
- struct realtimeTrafficMessage
- {
- bool isEnable=false;
- double lng;
- double lat;
- int scope;
- int trafficInfo;//0x01:塌方;0x02:施工;0x03:道路结冰;0x04:前方限速;“0xFE”表示异常,“0xFF”表示无效
- int speedLimit;
- };
- struct upResponseInfo
- {
- char vin[17];//车辆识别码
- unsigned char reponseType;//0x01:减速;0x02:停车;“0xFE”表示异常,“0xFF”表示无效
- };
- struct collisionEarlyWarningMessage
- {
- bool isEnable=false;
- std::string vin;//17位vin码
- unsigned char warningType;//0x01:减速;0x02:停车;“0xFE”表示异常,“0xFF”表示无效
- int speedLimit;
- };
- struct congestionIdentificationMessage
- {
- bool isEnable=false;
- std::string vin;//17位vin码
- unsigned char openCommand;//0x01:开启;“0xFE”表示异常,“0xFF”表示无效
- };
- struct lightMessage//红绿灯状态
- {
- bool isEnable=false;
- unsigned char myface=0;
- unsigned char light1face;//0x01横向 0x02纵向
- float light1head=0;//面朝方向
- unsigned char light1Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
- int light1timeRemaining=200;//红绿灯时间
- unsigned char light2face;//0x01横向 0x02纵向
- float light2head=0;//面朝方向
- unsigned char light2Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
- int light2timeRemaining=200;//红绿灯时间
- unsigned char light3face;//0x01横向 0x02纵向
- float light3head=0;//面朝方向
- unsigned char light3Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
- int light3timeRemaining=200;//红绿灯时间
- unsigned char light4face;//0x01横向 0x02纵向
- float light4head=0;//面朝方向
- unsigned char light4Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
- int light4timeRemaining=200;//红绿灯时间
- };
- struct gpsImuM//车辆状态传输
- {
- float gps_lng;//real value
- float gps_lat;
- float speed;//real value
- float yaw;//real value
- float accx;//real value
- float accy;
- };
- //struct responseCollisionEarlyWarningInfo
- //{
- // char vin[17];//车辆识别码
- // unsigned char warningType;
- // unsigned char speedLimit;
- //};
- struct DataPackageHead//数据包结构
- {
- unsigned char startSymbol1;//起始符1
- unsigned char startSymbol2;//起始符2
- char RSU_Vin[2];//路测系统编码
- unsigned char featureSymbol;//功能识别码
- unsigned char commentSymbol;//命令标识
- unsigned char responseSymbol;//应答标识
- unsigned char encryptionType;//数据加密方式
- unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
- char dataLength[2];//数据单元长度
- // unsigned char *data;//数据单元
- // unsigned char verifyCode;//校验码
- };
- struct CarFormationInfoData //车况数据
- {
- char vin[17];//车辆识别码
- unsigned char type;//0A
- unsigned char gps_lng[4];//经度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
- unsigned char gps_lat[4];//维度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
- unsigned char car_speed;//车速 有效值范围:0~200(表示0km/h~200km/h),最小计量单元:1km/h;“0xFE”表示异常,“0xFF”表示无效
- unsigned char car_yaw[4];//航向角 有效值范围:0~360(表示0°~360°);“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
- unsigned char electricalVoltage;
- unsigned char acc_x;//-6.0~6.0(表示0m/s2~4m/s2),最小计量单元:0.1 m/s2;
- unsigned char acc_y;
- unsigned char error;
- };
- struct ui_set_virtualVehicleM//虚拟车范围设置
- {
- double lngMax;
- double lngMin;
- double latMax;
- double latMin;
- float yawMax;
- float yawMin;
- int virtualVehicleNum;//虚拟车数量
- float speedMax;
- float speedMin;
- };
- struct virtualVehicleM
- {
- std::string vin;
- double gps_lng;//real value
- double gps_lat;
- float speed;//real value
- float yaw;//real value
- };
- struct upVirtualVehicleInfo
- {
- char vin[17];//车辆识别码
- unsigned char lng[4];//*1000000
- unsigned char lat[4];
- unsigned char speed;
- unsigned char yaw[4];
- };
- class PC5:public QObject
- {
- Q_OBJECT
- public:
- PC5();
- ~PC5();
- void connectPlatform();
- void disconnectPlatform();
- void setobu(QString str,int port);
- void serialPortInit();//串口初始化
- void openSerial();//打开串口
- void closeSerial();//关闭串口
- void setSerial(QString str1,int num1);//串口设置
- void setConnectEnable(bool isEnable);//主界面调用以开关串口
- bool isLinked();//返回连接状态
- void setVin(std::string vin);//设置车辆vin
- void setobuNewVin(int vin);//设置obu编号
- void initRadio();//随机虚拟车vin
- void getRandomNum();//抽取虚拟vin
- void sendData();//车况数据发送
- void replyMessage();//接受数据解析
- QByteArray show_error();//主界面调用显示错误信息
- QByteArray show_readdata();//主界面调用显示收到数据
- int PackagetHeadInfo( unsigned char featureID,unsigned char commendID, unsigned char respondID,int dataLen);//包头写入
- void upVirtualVehicleRaw();//发送虚拟车数据
- void setGpsImuMemory(gpsImuM m);//接收车辆状态信息
- char BCCEncode(char sbuf[],int len);//计算校验
- bool BCCDecode(char sbuf[], int len);//核实校验位
- void upVirtualVehicle(ui_set_virtualVehicleM ui_set);//生成虚拟车信息
- ui_set_virtualVehicleM my_ui_set;
- void upRespondMessage(unsigned char featureId);//发送应答回复
- realtimeTrafficMessage ui_RealtimeTraffic();//主界面调用显示车况
- lightMessage ui_Light();//主界面调用显示红绿灯
- collisionEarlyWarningMessage ui_Warning();//主界面调用显示碰撞预警
- congestionIdentificationMessage ui_identification();//主界面调用显示交通拥堵
- bool show_warn_driver();//主界面调用显示危险驾驶
- bool upRunMod();
- bool m_runmod=false;
- bool eth_enable = false;
- private:
- QByteArray error_data;//程序状态
- QByteArray datahex;//接收数据显示
- QSerialPort *m_serialPort_Radio;
- QString portname;//串口号
- int Baud;//波特率
- int obuport;
- QString obuip;
- QTcpServer *server;
- QTcpSocket *client;
- QTimer *timer;
- bool isConnected=false;//连接状态
- std::string m_strVin;//车辆vin
- int m_obuVin;//路测编号
- gpsImuM m_structMGpsImu;
- DataPackageHead packageDataHead;
- realtimeTrafficMessage realtimeTraffic;
- lightMessage light;
- collisionEarlyWarningMessage collisionWarning;
- congestionIdentificationMessage congestionIdenti;
- virtualVehicleM m_structMVirtualVehicle;
- int m_iVirtualVehicle;
- std::vector<std::string> m_vectorVin;
- std::vector<int> m_vectorRandom;
- QByteArray m_data;
- QQueue<QByteArray> readData;
- bool m_bIsConnect;
- bool m_bEnableRadio;
- bool m_bEnConnect;
- int m_traffic_heart;
- int m_light_heart;
- int m_WarningMessage_heart;
- int m_IdentificationMessage_heart;
- int m_warndriver_heart;
- unsigned char m_responseType;
- bool warn_driver;
- private slots:
- void recvData();
- // void newConnectionSlot();
- void readDataSlot();
- // void disconnectedSlot();
- void heartBeat();
- };
- #endif // PC5_H
|