tbox.h 3.1 KB

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