snap7_buf.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef NNXX_TESTS_SNAP7_BUF_H
  2. #define NNXX_TESTS_SNAP7_BUF_H
  3. #include <string>
  4. #include <map>
  5. #include <vector>
  6. #include <iostream>
  7. //Snap7协议的数据结构
  8. class Snap7_buf {
  9. public:
  10. //通信模式
  11. enum Communication_mode {
  12. NO_COMMUNICATION = 0, //不通信
  13. ONCE_COMMUNICATION = 1, //一次通信
  14. LOOP_COMMUNICATION = 2, //循环通信
  15. };
  16. //变量信息
  17. struct Variable_information {
  18. std::string m_variable_name; //变量名称
  19. std::string m_variable_type; //变量类型, 使用 typeid(a).name() 获取
  20. int m_variable_index; //变量下标, 偏移量
  21. int m_variable_size; //变量类型大小
  22. int m_variable_count; //变量个数
  23. };
  24. public:
  25. Snap7_buf();
  26. Snap7_buf(const Snap7_buf &other);
  27. Snap7_buf &operator=(const Snap7_buf &other);
  28. ~Snap7_buf();
  29. public://API functions
  30. Snap7_buf(int id, int start_index, int size,
  31. std::vector<Snap7_buf::Variable_information> &variable_information_vector,
  32. Communication_mode communication_mode = NO_COMMUNICATION);
  33. Snap7_buf(int id, int start_index, int size, void *p_buf_obverse, void *p_buf_reverse,
  34. std::vector<Snap7_buf::Variable_information> &variable_information_vector,
  35. Communication_mode communication_mode = NO_COMMUNICATION);
  36. void init(int id, int start_index, int size,
  37. std::vector<Snap7_buf::Variable_information> &variable_information_vector,
  38. Communication_mode communication_mode = NO_COMMUNICATION);
  39. void init(int id, int start_index, int size, void *p_buf_obverse, void *p_buf_reverse,
  40. std::vector<Snap7_buf::Variable_information> &variable_information_vector,
  41. Communication_mode communication_mode = NO_COMMUNICATION);
  42. //正序数据 转为 倒序数据
  43. void obverse_to_reverse();
  44. //倒序数据 转为 正序数据
  45. void reverse_to_obverse();
  46. public://get or set member variable
  47. int get_id();
  48. int get_start_index();
  49. int get_size();
  50. void *get_buf_obverse();
  51. void *get_buf_reverse();
  52. Communication_mode get_communication_mode();
  53. void set_communication_mode(Communication_mode communication_mode);
  54. protected://member functions
  55. public://member variable
  56. int m_id; //Snap7协议的数据块的编号
  57. int m_start_index; //Snap7协议的数据起始位下标
  58. int m_size; //Snap7协议的数据字节大小
  59. void *mp_buf_obverse; //Snap7协议的正序数据指针, 和数据结构体进行强转, 内存由本类管理
  60. void *mp_buf_reverse; //Snap7协议的倒序数据指针, 用作s7通信, 内存由本类管理
  61. //注:s7的通信的数据必须要倒序之后才能进行通信,
  62. // std::map<std::string, Variable_information> m_variable_information_map;
  63. std::vector<Variable_information> m_variable_information_vector;
  64. Communication_mode m_communication_mode; //Snap7协议的通信模式
  65. //注:s7协议传输很慢, 防止相同的数据重复发送...
  66. private:
  67. };
  68. #endif //NNXX_TESTS_SNAP7_BUF_H