tbox.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef TBOX_H
  2. #define TBOX_H
  3. #include <QTcpSocket>
  4. #include <QTcpServer>
  5. #include <QTimer>
  6. #include <QDateTime>
  7. #include <QQueue>
  8. struct DataPackageHead//数据包结构
  9. {
  10. unsigned char startSymbol1;//起始符1
  11. unsigned char startSymbol2;//起始符2
  12. unsigned char commentSymbol;//命令标识
  13. unsigned char responseSymbol;//应答标识
  14. char vin[17];//车辆识别码
  15. unsigned char encryptionType;//数据加密方式
  16. char dataLength[2];//数据单元长度
  17. // unsigned char *data;//数据单元
  18. // unsigned char verifyCode;//校验码
  19. };
  20. struct CarFormationInfoData //车况数据
  21. {
  22. unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
  23. unsigned char type;//0A
  24. unsigned char gps_lng[4];//经度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
  25. unsigned char gps_lat[4];//维度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
  26. unsigned char car_speed;//车速 有效值范围:0~200(表示0km/h~200km/h),最小计量单元:1km/h;“0xFE”表示异常,“0xFF”表示无效
  27. unsigned char car_yaw[4];//航向角 有效值范围:0~360(表示0°~360°);“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
  28. unsigned char electrical_voltage;//电量 有效值范围:0~100(表示0%~100%),最小计量单元:1%;“0xFE”表示异常,“0xFF”表示无效
  29. unsigned char error;//车辆故障状态 0x01:存在故障;0x02:不存在故障;“0xFE”表示异常,“0xFF”表示无效
  30. };
  31. struct CarVinChangeData //车况数据
  32. {
  33. unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
  34. char vin[17];//车辆识别码
  35. };
  36. struct Memory
  37. {
  38. float gps_lng;
  39. float gps_lat;
  40. float speed;
  41. float yaw;
  42. float ele_voltage;
  43. unsigned char error;//车辆故障状态 0x01:存在故障;0x02:不存在故障;“0xFE”表示异常,“0xFF”表示无效
  44. };
  45. class Tbox:public QObject
  46. {
  47. Q_OBJECT
  48. public:
  49. Tbox();
  50. void connectPlatform();
  51. void disconnectPlatform();
  52. void upDataStream();
  53. void upVinChangeData();
  54. void upVinChangeDataRaw();
  55. int PackagetHeadInfo(unsigned char commendID, int dataLen);
  56. char BCCEncode(char sbuf[],int len);//计算校验
  57. bool BCCDecode(char sbuf[], int len);
  58. void ReceiveDecode(QByteArray &data);
  59. void replyMessage();
  60. void setTboxConnectEnable(bool isEnable);
  61. void setTboxMemmory(Memory m);
  62. void setTboxNewVin(std::string str);
  63. //void setTboxUpData();
  64. private:
  65. QTcpServer *server;
  66. QTcpSocket *client;
  67. QTimer *timer;
  68. bool m_bIsConnect;
  69. bool m_bEnablePlatform;
  70. DataPackageHead packageDataHead;
  71. int m_iVinChange;
  72. QQueue<QByteArray> readData;
  73. bool m_bEnConnect;
  74. std::string m_strVin;
  75. Memory m_structM;
  76. private slots:
  77. void heartBeat();
  78. void newConnectionSlot();
  79. void readDataSlot();
  80. void disconnectedSlot();
  81. };
  82. #endif // TBOX_H