123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- //
- // Created by huli on 2020/9/25.
- //
- #ifndef NNXX_TESTS_DISPATCH_COMMUNICATION_H
- #define NNXX_TESTS_DISPATCH_COMMUNICATION_H
- #include "../tool/singleton.h"
- #include "../snap7_communication/snap7_communication_base.h"
- class Dispatch_communication:public Singleton<Dispatch_communication>, public Snap7_communication_base
- {
- public:
- //发送db快的标记位, 保证先发数据再发唯一码
- enum Send_database_flag
- {
- E_SEND_UNKNOW = 0,
- E_SEND_DATA_START = 1, //开始发送数据
- E_SEND_DATA_END = 2, //结束发送数据
- E_SEND_KEY_START = 3, //开始发送唯一码
- E_SEND_KEY_END = 4, //结束发送唯一码
- };
- #pragma pack(push, 1) //struct按照1个byte对齐
- //抓车模块给plc发送请求消息的DB编号
- #define CATCHER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_1 110
- #define CATCHER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_2 120
- //抓车模块给plc发送请求消息的指令结构体
- struct Catcher_request_from_dispatch_to_plc_for_data
- {
- //指令信息
- unsigned char m_reserved = 0; //预留
- unsigned char m_reserved257_275[19] = {0}; //预留
- // 请求的目标坐标和动作
- float m_request_x = 0; //机器人坐标x轴,
- float m_request_y = 0; //机器人坐标y轴,
- float m_request_b = 0; //机器人坐标b轴, 旋转范围80~280
- float m_request_z = 0; //机器人坐标z轴,
- unsigned char m_request_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_reserved293 = 0; //预留
- unsigned char m_reserved294 = 0; //预留
- unsigned char m_reserved295 = 0; //预留
- float m_request_wheelbase = 0; //机器人抓车杆前后轮距.
- float m_request_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
- float m_request_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
- };
- //抓车模块给plc发送请求消息的指令结构体
- struct Catcher_request_from_dispatch_to_plc_for_key
- {
- //指令信息
- unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
- };
- //plc给抓车模块发送答复消息的DB编号
- #define CATCHER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 111
- #define CATCHER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 121
- //plc给抓车模块发送答复消息的指令结构体
- struct Catcher_response_from_plc_to_dispatch
- {
- //指令信息
- unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
- unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
- unsigned char m_reserved257_275[19] = {0}; //预留
- //请求的目标坐标和动作
- float m_respons_x = 0; //机器人坐标x轴,
- float m_respons_y = 0; //机器人坐标y轴,
- float m_respons_b = 0; //机器人坐标b轴, 旋转范围80~280
- float m_respons_z = 0; //机器人坐标z轴,
- unsigned char m_respons_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_reserved293 = 0; //预留
- unsigned char m_reserved294 = 0; //预留
- unsigned char m_reserved295 = 0; //预留
- float m_respons_wheelbase = 0; //机器人抓车杆前后轮距.
- float m_respons_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
- float m_respons_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
- };
- //plc给抓车模块发送状态消息的DB编号
- #define CATCHER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 113
- #define CATCHER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 123
- //plc给抓车模块发送状态消息的指令结构体
- struct Catcher_status_from_plc_to_dispatch
- {
- unsigned char m_heartbeat = 0; //心跳位, 0-255循环
- unsigned char m_safe_status = 0; //设备的安全状态
- unsigned char m_work_status = 0; //机器人的硬件设备状态
- unsigned char m_actual_load_status = 0; //机器人的负载状态, 小跑车上面是否有车.
- unsigned char m_reserved4_37[34] = {0}; //预留
- float m_actual_x = 0; //机器人坐标x轴,
- float m_actual_y = 0; //机器人坐标y轴,
- float m_actual_b = 0; //机器人坐标b轴, 旋转范围80~280
- float m_actual_z = 0; //机器人坐标z轴,
- float m_actual_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
- float m_actual_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
- unsigned char m_actual_clamp_motion1 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_clamp_motion2 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_clamp_motion3 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_clamp_motion4 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_reserved66_99[34] = {0}; //预留
- //故障信息
- unsigned char m_actual_error_code[50] = {0}; //搬运器错误码
- unsigned char m_actual_warning_code[50] = {0}; //升降机错误码
- unsigned char m_actual_error_description[256] = {0}; //升降机错误描述
- };
- //搬运器给plc发送请求消息的DB编号
- #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_1 200
- #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_2 270
- #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_3 230
- //搬运器给plc发送请求消息的指令结构体
- struct Carrier_request_from_dispatch_to_plc_for_data
- {
- //指令信息
- unsigned char m_reserved = 0; //预留
- unsigned char m_reserved257_275[19] = {0}; //预留
- // 请求的目标坐标和动作
- float m_request_x = 0; //机器人坐标x轴,
- float m_request_y = 0; //机器人坐标y轴,
- float m_request_b = 0; //机器人坐标b轴, 旋转范围80~280
- float m_request_z = 0; //机器人坐标z轴,
- unsigned char m_request_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_reserved293 = 0; //预留
- unsigned char m_reserved294 = 0; //预留
- unsigned char m_reserved295 = 0; //预留
- float m_request_wheelbase = 0; //机器人抓车杆前后轮距.
- float m_request_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
- float m_request_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
- };
- //搬运器给plc发送请求消息的指令结构体
- struct Carrier_request_from_dispatch_to_plc_for_key
- {
- //指令信息
- unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
- };
- //plc给搬运器发送答复消息的DB编号
- #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 201
- #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 271
- #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 231
- //plc给搬运器发送答复消息的指令结构体
- struct Carrier_response_from_plc_to_dispatch
- {
- //指令信息
- unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
- unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
- unsigned char m_reserved257_275[19] = {0}; //预留
- //请求的目标坐标和动作
- float m_respons_x = 0; //机器人坐标x轴,
- float m_respons_y = 0; //机器人坐标y轴,
- float m_respons_b = 0; //机器人坐标b轴, 旋转范围80~280
- float m_respons_z = 0; //机器人坐标z轴,
- unsigned char m_respons_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_reserved293 = 0; //预留
- unsigned char m_reserved294 = 0; //预留
- unsigned char m_reserved295 = 0; //预留
- float m_respons_wheelbase = 0; //机器人抓车杆前后轮距.
- float m_respons_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
- float m_respons_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
- };
- //plc给搬运器发送状态消息的DB编号
- #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 113
- #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 123
- //plc给搬运器发送状态消息的指令结构体
- struct Carrier_status_from_plc_to_dispatch
- {
- unsigned char m_heartbeat = 0; //心跳位, 0-255循环
- unsigned char m_safe_status = 0; //设备的安全状态
- unsigned char m_work_status = 0; //机器人的硬件设备状态
- unsigned char m_actual_load_status = 0; //机器人的负载状态, 小跑车上面是否有车.
- unsigned char m_reserved4_37[34] = {0}; //预留
- float m_actual_x = 0; //机器人坐标x轴,
- float m_actual_y = 0; //机器人坐标y轴,
- float m_actual_b = 0; //机器人坐标b轴, 旋转范围80~280
- float m_actual_z = 0; //机器人坐标z轴,
- float m_actual_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
- float m_actual_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
- unsigned char m_actual_clamp_motion1 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_clamp_motion2 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_clamp_motion3 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_clamp_motion4 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_reserved66_99[34] = {0}; //预留
- //故障信息
- unsigned char m_actual_error_code[50] = {0}; //搬运器错误码
- unsigned char m_actual_warning_code[50] = {0}; //升降机错误码
- unsigned char m_actual_error_description[256] = {0}; //升降机错误描述
- };
- #pragma pack(pop) //取消对齐
- // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
- friend class Singleton<Dispatch_communication>;
- private:
- // 父类的构造函数必须保护,子类的构造函数必须私有。
- Dispatch_communication();
- public:
- //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
- Dispatch_communication(const Dispatch_communication& other) = delete;
- Dispatch_communication& operator =(const Dispatch_communication& other) = delete;
- ~Dispatch_communication();
- public://API functions
- //初始化 通信 模块。如下三选一
- virtual Error_manager communication_init();
- //反初始化 通信 模块。
- virtual Error_manager communication_uninit();
- public://get or set member variable
- // std::mutex * get_data_lock();
- // Request_from_dispatch_to_plc * get_request_from_dispatch_to_plc();
- // Response_from_plc_to_dispatch * get_response_from_plc_to_dispatch();
- // Status_from_dispatch_to_plc * get_status_from_dispatch_to_plc();
- // Status_from_plc_to_dispatch * get_status_from_plc_to_dispatch();
- protected://member functions
- //更新数据
- virtual Error_manager updata_receive_buf();
- virtual Error_manager updata_send_buf();
- protected://member variable
- public:
- std::mutex m_data_lock; //数据锁
- Catcher_request_from_dispatch_to_plc_for_data m_catcher_request_from_dispatch_to_plc_for_data[2]; //抓车模块给plc发送请求消息的指令结构体
- Catcher_request_from_dispatch_to_plc_for_key m_catcher_request_from_dispatch_to_plc_for_key[2]; //抓车模块给plc发送请求消息的指令结构体
- Catcher_response_from_plc_to_dispatch m_catcher_response_from_plc_to_dispatch[2]; //plc给抓车模块发送答复消息的指令结构体
- Catcher_status_from_plc_to_dispatch m_catcher_status_from_plc_to_dispatch[2]; //plc给抓车模块发送状态消息的指令结构体
- Carrier_request_from_dispatch_to_plc_for_data m_carrier_request_from_dispatch_to_plc_for_data[2]; //搬运器给plc发送请求消息的指令结构体
- Carrier_request_from_dispatch_to_plc_for_key m_carrier_request_from_dispatch_to_plc_for_key[2]; //搬运器给plc发送请求消息的指令结构体
- Carrier_response_from_plc_to_dispatch m_carrier_response_from_plc_to_dispatch[2]; //plc给搬运器发送答复消息的指令结构体
- Carrier_status_from_plc_to_dispatch m_carrier_status_from_plc_to_dispatch[2]; //plc给搬运器发送状态消息的指令结构体
- private:
- };
- #endif //NNXX_TESTS_DISPATCH_COMMUNICATION_H
|