deviceBase.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #pragma once
  2. #include <iostream>
  3. #include "SendDevice.h"
  4. #include "CSerialPort/SerialPort.h"
  5. #include <iostream>
  6. #include <rapidjson/document.h>
  7. #include <rapidjson/rapidjson.h>
  8. #include <rapidjson/stringbuffer.h>
  9. #include <rapidjson/writer.h>
  10. #include <vector>
  11. #include <unistd.h>
  12. #include <atomic>
  13. #include <bitset>
  14. #include <functional>
  15. #include <list>
  16. #include <memory>
  17. #include <string>
  18. #include <thread>
  19. #include <typeinfo>
  20. #include <unordered_map>
  21. #include <utility>
  22. #include <vector>
  23. using namespace toolkit;
  24. using namespace std;
  25. using namespace itas109;
  26. typedef struct{
  27. int deviceId;
  28. uint8_t msgId;
  29. uint8_t data;
  30. }GasV1Control;
  31. // 设备Token
  32. enum DeviceToken {
  33. serial = 0,
  34. http = 1,
  35. tcp = 2
  36. };
  37. class deviceBase
  38. {
  39. protected:
  40. std::string deviceId;
  41. enum DeviceToken deviceToken = serial;
  42. std::string DeviceInfo = "";
  43. // deviceToken为serial时有效
  44. int baudRate = itas109::BaudRate115200;
  45. std::string ServerIp;
  46. std::string ServerCname;
  47. std::string ServerCpwd;
  48. int Type = 0;
  49. public:
  50. deviceBase(){}
  51. ~deviceBase(){}
  52. virtual void serialization(){}
  53. virtual bool deserialization(){}
  54. virtual bool Consumer(uint8_t *data, int len, int &msg_id){return true;}
  55. virtual bool getStatusMsg(int &msg_id){ return false;};
  56. virtual void BuildDeviceInfo(SendDevice& sendDevice) {};
  57. virtual void setControlType(int type){
  58. this->Type = type;
  59. };
  60. virtual int32_t Open(std::string DeviceId,uint8_t* data, int& length){return 0;};
  61. virtual int32_t Close(std::string DeviceId, uint8_t* data, int&length){return 0;};
  62. virtual int32_t Fire(std::string DeviceId, uint8_t* data, int& length){return 0;};
  63. virtual int32_t Status(std::string DeviceId, uint8_t* data, int& length){return 0;};
  64. void setDeviceId(std::string DeviceId){
  65. deviceId = DeviceId;
  66. }
  67. std::string getDeviceId(){
  68. return deviceId;
  69. }
  70. void setDeviceToken(enum DeviceToken mdeviceToken){
  71. deviceToken = mdeviceToken;
  72. }
  73. enum DeviceToken getDevcieToken(){
  74. return deviceToken;
  75. }
  76. void setDeviceInfo(std::string deviceInfo){
  77. this->DeviceInfo = deviceInfo;
  78. }
  79. std::string getDeviceInfo(){
  80. return this->DeviceInfo;
  81. }
  82. void setBaudRate(int BaudRate){
  83. this->baudRate = BaudRate;
  84. }
  85. int getBaudRate(){
  86. return this->baudRate;
  87. }
  88. void setServerIp(std::string serverIp){
  89. ServerIp = serverIp;
  90. }
  91. void setServerCname(std::string serverCname){
  92. ServerCname = serverCname;
  93. }
  94. void setServerCpwd(std::string serverCpwd){
  95. ServerCpwd = serverCpwd;
  96. }
  97. };