1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #ifndef TBOX_H
- #define TBOX_H
- #include <QTcpSocket>
- #include <QTcpServer>
- #include <QTimer>
- #include <QDateTime>
- #include <QQueue>
- struct DataPackageHead//数据包结构
- {
- unsigned char startSymbol1;//起始符1
- unsigned char startSymbol2;//起始符2
- unsigned char commentSymbol;//命令标识
- unsigned char responseSymbol;//应答标识
- char vin[17];//车辆识别码
- unsigned char encryptionType;//数据加密方式
- char dataLength[2];//数据单元长度
- // unsigned char *data;//数据单元
- // unsigned char verifyCode;//校验码
- };
- struct CarFormationInfoData //车况数据
- {
- unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
- 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 electrical_voltage;//电量 有效值范围:0~100(表示0%~100%),最小计量单元:1%;“0xFE”表示异常,“0xFF”表示无效
- unsigned char error;//车辆故障状态 0x01:存在故障;0x02:不存在故障;“0xFE”表示异常,“0xFF”表示无效
- };
- struct CarVinChangeData //车况数据
- {
- unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
- char vin[17];//车辆识别码
- };
- struct Memory
- {
- float gps_lng;
- float gps_lat;
- float speed;
- float yaw;
- float ele_voltage;
- unsigned char error;//车辆故障状态 0x01:存在故障;0x02:不存在故障;“0xFE”表示异常,“0xFF”表示无效
- };
- class Tbox:public QObject
- {
- Q_OBJECT
- public:
- Tbox();
- void connectPlatform();
- void disconnectPlatform();
- void upDataStream();
- void upVinChangeData();
- void upVinChangeDataRaw();
- int PackagetHeadInfo(unsigned char commendID, int dataLen);
- char BCCEncode(char sbuf[],int len);//计算校验
- bool BCCDecode(char sbuf[], int len);
- void ReceiveDecode(QByteArray &data);
- void replyMessage();
- void setTboxConnectEnable(bool isEnable);
- void setTboxMemmory(Memory m);
- void setTboxNewVin(std::string str);
- //void setTboxUpData();
- private:
- QTcpServer *server;
- QTcpSocket *client;
- QTimer *timer;
- bool m_bIsConnect;
- bool m_bEnablePlatform;
- DataPackageHead packageDataHead;
- int m_iVinChange;
- QQueue<QByteArray> readData;
- bool m_bEnConnect;
- std::string m_strVin;
- Memory m_structM;
- private slots:
- void heartBeat();
- void newConnectionSlot();
- void readDataSlot();
- void disconnectedSlot();
- };
- #endif // TBOX_H
|