DeviceGasV1.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef _DEVICEGASV1_HPP_
  2. #define _DEVICEGASV1_HPP_
  3. #include "UtilBase.hpp"
  4. namespace gsd{
  5. class DeviceGasV1: public ContorlSerialBase
  6. {
  7. private:
  8. enum RECV_STEP{
  9. STEP_HEAD = 0,
  10. STEP_1 = 1,
  11. STEP_2 = 2,
  12. STEP_TYPE = 3,
  13. STEP_ADDR = 4,
  14. STEP_COM = 5,
  15. STEP_ACK = 6,
  16. STEP_STA = 7,
  17. STEP_DATA = 8,
  18. STEP_RLC = 9
  19. };
  20. typedef struct {
  21. uint8_t dataCount;
  22. uint8_t dataLength;
  23. uint8_t dataCheckSum;
  24. uint8_t data[40];
  25. enum RECV_STEP step = STEP_HEAD;
  26. }ExpelComm;
  27. ExpelComm _comm;
  28. public:
  29. DeviceGasV1():ContorlSerialBase(){
  30. this->DeviceInfo = "兰州中川机场 煤气炮驱动板协议";
  31. this->tool = DeviceTools::serial;
  32. this->baudRate = 38400;
  33. }
  34. // 电压
  35. float voltage = 0;
  36. // 气压
  37. float pressure = 0;
  38. // 状态
  39. int state = 0;
  40. // 纬度
  41. float latitude = 0;
  42. // 经度
  43. float longitude = 0;
  44. /**
  45. * @description: 判定msg是否为status
  46. * @param {int} &msg_id
  47. * @return {*}
  48. */
  49. bool getStatusMsg(int &msg_id);
  50. /**
  51. * @description: 消费数据
  52. * @param {uint8_t} *data
  53. * @param {int} len
  54. * @param {int} &msg_id
  55. * @return {*}
  56. */
  57. bool Consumer(uint8_t *data, int len, int &msg_id);
  58. /**
  59. * @description: 反序列化
  60. * @param {uint8_t} *data
  61. * @param {int} len
  62. * @param {int} &msg_id
  63. * @return {*}
  64. */
  65. virtual bool deserialization(const uint8_t *data, int len, int &msg_id);
  66. // 常规操作
  67. int8_t Open(std::string _deviceId, uint8_t* data, int& length);
  68. int8_t Close(std::string _deviceId, uint8_t* data, int&length);
  69. int8_t Fire(std::string _deviceId, uint8_t* data, int& length);
  70. int8_t Status(std::string _deviceId, uint8_t* data, int& length);
  71. /**
  72. * @description: 构建设备信息
  73. * @param {SendDevice&} sendDevice
  74. * @return {*}
  75. */
  76. virtual void BuildDeviceInfo(SendDevice& sendDevice);
  77. /**
  78. * @description: 序列化
  79. * @param {GasV1Control} gasV1Control
  80. * @param {char} *data
  81. * @return {*}
  82. */
  83. static void serialization(const ControlerMsg gasV1Control,char *data);
  84. // LRC校验
  85. static unsigned char LRC_check(unsigned char *pSendBuf,unsigned char num);
  86. ~DeviceGasV1(){}
  87. };
  88. }
  89. #endif