12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #ifndef NNXX_TESTS_SNAP7_BUF_H
- #define NNXX_TESTS_SNAP7_BUF_H
- #include <string>
- #include <map>
- #include <vector>
- #include <iostream>
- //Snap7协议的数据结构
- class Snap7_buf
- {
- public:
- //通信模式
- enum Communication_mode
- {
- NO_COMMUNICATION = 0, //不通信
- ONCE_COMMUNICATION = 1, //一次通信
- LOOP_COMMUNICATION = 2, //循环通信
- };
- //变量信息
- struct Variable_information
- {
- std::string m_variable_name; //变量名称
- std::string m_variable_type; //变量类型, 使用 typeid(a).name() 获取
- int m_variable_index; //变量下标, 偏移量
- int m_variable_size; //变量类型大小
- int m_variable_count; //变量个数
- };
- public:
- Snap7_buf();
- Snap7_buf(const Snap7_buf& other);
- Snap7_buf& operator =(const Snap7_buf& other);
- ~Snap7_buf();
- public://API functions
- Snap7_buf(int id, int start_index, int size,
- std::vector<Snap7_buf::Variable_information>& variable_information_vector,Communication_mode communication_mode = NO_COMMUNICATION);
- Snap7_buf(int id, int start_index, int size, void* p_buf_obverse, void* p_buf_reverse,
- std::vector<Snap7_buf::Variable_information>& variable_information_vector, Communication_mode communication_mode = NO_COMMUNICATION);
- //正序数据 转为 倒序数据
- void obverse_to_reverse();
- //倒序数据 转为 正序数据
- void reverse_to_obverse();
- public://get or set member variable
- int get_id();
- int get_start_index();
- int get_size();
- void* get_buf_obverse();
- void* get_buf_reverse();
- Communication_mode get_communication_mode();
- void set_communication_mode(Communication_mode communication_mode);
- protected://member functions
- public://member variable
- int m_id; //Snap7协议的数据块的编号
- int m_start_index; //Snap7协议的数据起始位下标
- int m_size; //Snap7协议的数据字节大小
- void* mp_buf_obverse; //Snap7协议的正序数据指针, 和数据结构体进行强转, 内存由本类管理
- void* mp_buf_reverse; //Snap7协议的倒序数据指针, 用作s7通信, 内存由本类管理
- //注:s7的通信的数据必须要倒序之后才能进行通信,
- // std::map<std::string, Variable_information> m_variable_information_map;
- std::vector<Variable_information> m_variable_information_vector;
- Communication_mode m_communication_mode; //Snap7协议的通信模式
- //注:s7协议传输很慢, 防止相同的数据重复发送...
- private:
- };
- #endif //NNXX_TESTS_SNAP7_BUF_H
|