snap7_buf.h 2.9 KB

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