123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- //
- // 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_reserved50 = 0; //预留
- unsigned char m_reserved51_69[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_reserved87_89[3] = {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_reserved51_69[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_reserved87_89[3] = {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_reserved50 = 0; //预留
- unsigned char m_reserved51_71[21] = {0}; //预留
- //请求的目标坐标和动作
- float m_request_x; //搬运器坐标x轴, 中跑车控制横向移动
- float m_request_y; //搬运器坐标y轴, 小跑车控制纵向移动
- float m_request_z; //搬运器坐标z轴, 电梯控制上下移动
- float m_request_y1; //搬运器坐标y1轴, 小跑车控制纵向移动(前轮抓杆)
- float m_request_y2; //搬运器坐标y2轴, 小跑车控制纵向移动(后轮抓杆)
- unsigned char m_request_clamp_motion; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_request_joint_motion_x; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
- unsigned char m_request_joint_motion_y; //小跑车与Y轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
- unsigned char m_reserved95 = 0; //预留
- int m_request_space_id; //搬运器空间位置的id.
- int m_request_floor_id; //搬运器楼层位置的id.
- float m_request_wheelbase; //搬运器小跑车的抓车杆前后轮距.
- };
- //搬运器给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_3 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_reserved51_71[21] = {0}; //预留
- //请求的目标坐标和动作
- float m_respons_x; //搬运器坐标x轴, 中跑车控制横向移动
- float m_respons_y; //搬运器坐标y轴, 小跑车控制纵向移动
- float m_respons_z; //搬运器坐标z轴, 电梯控制上下移动
- float m_respons_y1; //搬运器坐标y1轴, 小跑车控制纵向移动(前轮抓杆)
- float m_respons_y2; //搬运器坐标y2轴, 小跑车控制纵向移动(后轮抓杆)
- unsigned char m_respons_clamp_motion; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_respons_joint_motion_x; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
- unsigned char m_respons_joint_motion_y; //小跑车与Y轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
- unsigned char m_reserved95 = 0; //预留
- int m_respons_space_id; //搬运器空间位置的id.
- int m_respons_floor_id; //搬运器楼层位置的id.
- float m_respons_wheelbase; //搬运器小跑车的抓车杆前后轮距.
- };
- //plc给搬运器发送状态消息的DB编号
- #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 203
- #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 273
- #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_3 233
- //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_z = 0; //搬运器坐标z轴,
- float m_actual_y1 = 0; //搬运器坐标y1轴, 小跑车控制纵向移动(前轮抓杆)
- float m_actual_y2 = 0; //搬运器坐标y2轴, 小跑车控制纵向移动(前轮抓杆)
- unsigned char m_actual_clamp_motion1 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_clamp_motion2 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
- unsigned char m_actual_small_sports_car_motion = 0; //小跑车的位置,是否在中跑车上面, 0=无动作,1=出发到位,2=返回到位
- unsigned char m_actual_joint_motion_x1 = 0; //电梯与X轴的横向轨道对接,0=无动作,1=伸出到位,2=收回到位
- unsigned char m_actual_joint_motion_x2 = 0; //电梯与X轴的横向轨道对接,0=无动作,1=伸出到位,2=收回到位
- unsigned char m_reserved63_101[39] = {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 PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_0 300
- #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_1 310
- #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_2 320
- #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_3 330
- #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_4 340
- #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_5 350
- #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_6 360
- #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_7 370
- //通道口给plc发送请求消息的指令结构体
- struct Passageway_request_from_dispatch_to_plc_for_data
- {
- //指令信息
- unsigned char m_reserved50 = 0; //预留
- unsigned char m_reserved51_69[19] = {0}; //预留
- // 请求的目标坐标和动作
- unsigned char m_request_inside_door_motion = 0; //通道口 内门动作
- unsigned char m_request_outside_door_motion = 0; //通道口 外门动作
- unsigned char m_request_turntable_direction = 0; //通道口 转台方向
- };
- //通道口给plc发送请求消息的指令结构体
- struct Passageway_request_from_dispatch_to_plc_for_key
- {
- //指令信息
- unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
- };
- //plc给通道口发送答复消息的DB编号
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_0 301
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 311
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 321
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_3 331
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_4 341
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_5 351
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_6 361
- #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_7 371
- //plc给通道口发送答复消息的指令结构体
- struct Passageway_response_from_plc_to_dispatch
- {
- //指令信息
- unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
- unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
- unsigned char m_reserved51_69[19] = {0}; //预留
- unsigned char m_respons_inside_door_motion = 0; //通道口 内门动作
- unsigned char m_respons_outside_door_motion = 0; //通道口 外门动作
- unsigned char m_respons_turntable_direction = 0; //通道口 转台方向
- };
- //plc给通道口发送状态消息的DB编号
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_0 303
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 313
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 323
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_3 333
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_4 343
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_5 353
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_6 363
- #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_7 373
- //plc给通道口发送状态消息的指令结构体
- struct Passageway_status_from_plc_to_dispatch
- {
- unsigned char m_heartbeat = 0; //心跳位, 0-255循环
- unsigned char m_safe_status = 0; //设备的安全状态
- unsigned char m_sensor_status1 = 0; //设备的传感器状态1
- unsigned char m_sensor_status2 = 0; //设备的传感器状态2
- unsigned char m_reserved4_35[32] = {0}; //预留
- unsigned char m_actual_turntable_direction; //通道口 转台方向
- unsigned char m_reserved37 = 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[3]; //搬运器给plc发送请求消息的指令结构体
- Carrier_request_from_dispatch_to_plc_for_key m_carrier_request_from_dispatch_to_plc_for_key[3]; //搬运器给plc发送请求消息的指令结构体
- Carrier_response_from_plc_to_dispatch m_carrier_response_from_plc_to_dispatch[3]; //plc给搬运器发送答复消息的指令结构体
- Carrier_status_from_plc_to_dispatch m_carrier_status_from_plc_to_dispatch[3]; //plc给搬运器发送状态消息的指令结构体
- Passageway_request_from_dispatch_to_plc_for_data m_passageway_request_from_dispatch_to_plc_for_data[8]; //通道口给plc发送请求消息的指令结构体
- Passageway_request_from_dispatch_to_plc_for_key m_passageway_request_from_dispatch_to_plc_for_key[8]; //通道口给plc发送请求消息的指令结构体
- Passageway_response_from_plc_to_dispatch m_passageway_response_from_plc_to_dispatch[8]; //plc给通道口发送答复消息的指令结构体
- Passageway_status_from_plc_to_dispatch m_passageway_status_from_plc_to_dispatch[8]; //plc给通道口发送状态消息的指令结构体
- private:
- };
- #endif //NNXX_TESTS_DISPATCH_COMMUNICATION_H
|