pc5.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #ifndef PC5_H
  2. #define PC5_H
  3. //#include <QWidget>
  4. //#include <QAbstractSocket>
  5. //#include <QDialog>
  6. #include <QTimer>
  7. #include <QDateTime>
  8. #include <QQueue>
  9. //#include <QUdpSocket>
  10. #include <QTcpServer>
  11. #include <QSerialPort>
  12. #include "ivlog.h"
  13. //std::string VIN="A1000000CATARCS01";
  14. #define TrafficLight (0x01)
  15. #define RealtimeTraffic (0x02)
  16. #define CollisionEarlyWarning (0x03)
  17. #define CongestionIdentification (0x04)
  18. #define AutoDriveSystemOpenFlag (0x21)
  19. #define VehicleBaseInfo (0x80)
  20. #define ResponseMessage (0x81)
  21. #define VirtualVehicle (0x82)
  22. #define commentsend (0xFE)//命令
  23. #define resuccess (0x01)//成功
  24. #define reerror (0x02)//错误
  25. #define periodic_send (0x00)
  26. struct realtimeTrafficMessage
  27. {
  28. bool isEnable=false;
  29. double lng;
  30. double lat;
  31. int scope;
  32. int trafficInfo;//0x01:塌方;0x02:施工;0x03:道路结冰;0x04:前方限速;“0xFE”表示异常,“0xFF”表示无效
  33. int speedLimit;
  34. };
  35. struct upResponseInfo
  36. {
  37. char vin[17];//车辆识别码
  38. unsigned char reponseType;//0x01:减速;0x02:停车;“0xFE”表示异常,“0xFF”表示无效
  39. };
  40. struct collisionEarlyWarningMessage
  41. {
  42. bool isEnable=false;
  43. std::string vin;//17位vin码
  44. unsigned char warningType;//0x01:减速;0x02:停车;“0xFE”表示异常,“0xFF”表示无效
  45. int speedLimit;
  46. };
  47. struct congestionIdentificationMessage
  48. {
  49. bool isEnable=false;
  50. std::string vin;//17位vin码
  51. unsigned char openCommand;//0x01:开启;“0xFE”表示异常,“0xFF”表示无效
  52. };
  53. struct lightMessage//红绿灯状态
  54. {
  55. bool isEnable=false;
  56. unsigned char myface=0;
  57. unsigned char light1face;//0x01横向 0x02纵向
  58. float light1head=0;//面朝方向
  59. unsigned char light1Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
  60. int light1timeRemaining=200;//红绿灯时间
  61. unsigned char light2face;//0x01横向 0x02纵向
  62. float light2head=0;//面朝方向
  63. unsigned char light2Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
  64. int light2timeRemaining=200;//红绿灯时间
  65. unsigned char light3face;//0x01横向 0x02纵向
  66. float light3head=0;//面朝方向
  67. unsigned char light3Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
  68. int light3timeRemaining=200;//红绿灯时间
  69. unsigned char light4face;//0x01横向 0x02纵向
  70. float light4head=0;//面朝方向
  71. unsigned char light4Type=0x00;//0x01:绿灯;0x02:红灯;0x03:黄灯;
  72. int light4timeRemaining=200;//红绿灯时间
  73. };
  74. struct gpsImuM//车辆状态传输
  75. {
  76. float gps_lng;//real value
  77. float gps_lat;
  78. float speed;//real value
  79. float yaw;//real value
  80. float accx;//real value
  81. float accy;
  82. };
  83. //struct responseCollisionEarlyWarningInfo
  84. //{
  85. // char vin[17];//车辆识别码
  86. // unsigned char warningType;
  87. // unsigned char speedLimit;
  88. //};
  89. struct DataPackageHead//数据包结构
  90. {
  91. unsigned char startSymbol1;//起始符1
  92. unsigned char startSymbol2;//起始符2
  93. char RSU_Vin[2];//路测系统编码
  94. unsigned char featureSymbol;//功能识别码
  95. unsigned char commentSymbol;//命令标识
  96. unsigned char responseSymbol;//应答标识
  97. unsigned char encryptionType;//数据加密方式
  98. unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
  99. char dataLength[2];//数据单元长度
  100. // unsigned char *data;//数据单元
  101. // unsigned char verifyCode;//校验码
  102. };
  103. struct CarFormationInfoData //车况数据
  104. {
  105. char vin[17];//车辆识别码
  106. unsigned char type;//0A
  107. unsigned char gps_lng[4];//经度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
  108. unsigned char gps_lat[4];//维度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
  109. unsigned char car_speed;//车速 有效值范围:0~200(表示0km/h~200km/h),最小计量单元:1km/h;“0xFE”表示异常,“0xFF”表示无效
  110. unsigned char car_yaw[4];//航向角 有效值范围:0~360(表示0°~360°);“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
  111. unsigned char electricalVoltage;
  112. unsigned char acc_x;//-6.0~6.0(表示0m/s2~4m/s2),最小计量单元:0.1 m/s2;
  113. unsigned char acc_y;
  114. unsigned char error;
  115. };
  116. struct ui_set_virtualVehicleM//虚拟车范围设置
  117. {
  118. double lngMax;
  119. double lngMin;
  120. double latMax;
  121. double latMin;
  122. float yawMax;
  123. float yawMin;
  124. int virtualVehicleNum;//虚拟车数量
  125. float speedMax;
  126. float speedMin;
  127. };
  128. struct virtualVehicleM
  129. {
  130. std::string vin;
  131. double gps_lng;//real value
  132. double gps_lat;
  133. float speed;//real value
  134. float yaw;//real value
  135. };
  136. struct upVirtualVehicleInfo
  137. {
  138. char vin[17];//车辆识别码
  139. unsigned char lng[4];//*1000000
  140. unsigned char lat[4];
  141. unsigned char speed;
  142. unsigned char yaw[4];
  143. };
  144. class PC5:public QObject
  145. {
  146. Q_OBJECT
  147. public:
  148. PC5();
  149. ~PC5();
  150. void connectPlatform();
  151. void disconnectPlatform();
  152. void setobu(QString str,int port);
  153. void serialPortInit();//串口初始化
  154. void openSerial();//打开串口
  155. void closeSerial();//关闭串口
  156. void setSerial(QString str1,int num1);//串口设置
  157. void setConnectEnable(bool isEnable);//主界面调用以开关串口
  158. bool isLinked();//返回连接状态
  159. void setVin(std::string vin);//设置车辆vin
  160. void setobuNewVin(int vin);//设置obu编号
  161. void initRadio();//随机虚拟车vin
  162. void getRandomNum();//抽取虚拟vin
  163. void sendData();//车况数据发送
  164. void replyMessage();//接受数据解析
  165. QByteArray show_error();//主界面调用显示错误信息
  166. QByteArray show_readdata();//主界面调用显示收到数据
  167. int PackagetHeadInfo( unsigned char featureID,unsigned char commendID, unsigned char respondID,int dataLen);//包头写入
  168. void upVirtualVehicleRaw();//发送虚拟车数据
  169. void setGpsImuMemory(gpsImuM m);//接收车辆状态信息
  170. char BCCEncode(char sbuf[],int len);//计算校验
  171. bool BCCDecode(char sbuf[], int len);//核实校验位
  172. void upVirtualVehicle(ui_set_virtualVehicleM ui_set);//生成虚拟车信息
  173. ui_set_virtualVehicleM my_ui_set;
  174. void upRespondMessage(unsigned char featureId);//发送应答回复
  175. realtimeTrafficMessage ui_RealtimeTraffic();//主界面调用显示车况
  176. lightMessage ui_Light();//主界面调用显示红绿灯
  177. collisionEarlyWarningMessage ui_Warning();//主界面调用显示碰撞预警
  178. congestionIdentificationMessage ui_identification();//主界面调用显示交通拥堵
  179. bool show_warn_driver();//主界面调用显示危险驾驶
  180. bool upRunMod();
  181. bool m_runmod=false;
  182. bool eth_enable = false;
  183. private:
  184. QByteArray error_data;//程序状态
  185. QByteArray datahex;//接收数据显示
  186. QSerialPort *m_serialPort_Radio;
  187. QString portname;//串口号
  188. int Baud;//波特率
  189. int obuport;
  190. QString obuip;
  191. QTcpServer *server;
  192. QTcpSocket *client;
  193. QTimer *timer;
  194. bool isConnected=false;//连接状态
  195. std::string m_strVin;//车辆vin
  196. int m_obuVin;//路测编号
  197. gpsImuM m_structMGpsImu;
  198. DataPackageHead packageDataHead;
  199. realtimeTrafficMessage realtimeTraffic;
  200. lightMessage light;
  201. collisionEarlyWarningMessage collisionWarning;
  202. congestionIdentificationMessage congestionIdenti;
  203. virtualVehicleM m_structMVirtualVehicle;
  204. int m_iVirtualVehicle;
  205. std::vector<std::string> m_vectorVin;
  206. std::vector<int> m_vectorRandom;
  207. QByteArray m_data;
  208. QQueue<QByteArray> readData;
  209. bool m_bIsConnect;
  210. bool m_bEnableRadio;
  211. bool m_bEnConnect;
  212. int m_traffic_heart;
  213. int m_light_heart;
  214. int m_WarningMessage_heart;
  215. int m_IdentificationMessage_heart;
  216. int m_warndriver_heart;
  217. unsigned char m_responseType;
  218. bool warn_driver;
  219. private slots:
  220. void recvData();
  221. // void newConnectionSlot();
  222. void readDataSlot();
  223. // void disconnectedSlot();
  224. void heartBeat();
  225. };
  226. #endif // PC5_H