123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- //
- // 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:
- #pragma pack(push, 1) //struct按照1个byte对齐
- //调度模块给plc发送请求消息的DB编号
- #define REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER 100
- //调度模块给plc发送请求消息的指令结构体
- struct Request_from_dispatch_to_plc
- {
- unsigned char m_reserved0 = 0; //预留
- unsigned char m_command_flag = 0; //指令标志位, 0bit==1:流程开始, 1bit==1:校验无误
- unsigned char m_task_status = 0; //流程状态, 0=正常,1=可恢复型故障,2=不可恢复故障
- unsigned char m_reserved3_11[9] = {0}; //预留
- //指令信息
- unsigned short m_block_id = 0; //单位编号(区域编号), 1~3
- unsigned short m_floor_id = 0; //楼层编号, 1~14
- unsigned short m_parkspace_id = 0; //同层的车位索引, 一楼为1~4, 楼上为1~6
- unsigned char m_command_key[256] = {0}; //指令key(任务唯一码), 作为通信标志位
- unsigned char m_is_entrance_flag = 0; //是否为入口, 1=入口,0=非入口, (如果是入口, 中跑车需要按照汽车的旋转角进行偏移)
- unsigned char m_reserved275_289[15] = {0}; //预留
- //汽车定位信息
- float m_center_x = 0; //整车的中心点x值, 四轮的中心
- float m_center_y = 0; //整车的中心点y值, 四轮的中心
- float m_car_angle = 0; //整车的车身旋转角,
- float m_car_length = 0; //整车的长度, 用于规避碰撞
- float m_car_width = 0; //整车的宽度, 用于规避碰撞
- float m_car_height = 0; //整车的高度, 用于规避碰撞
- float m_wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
- float m_wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
- unsigned char m_voucher_number[256] = {0}; //停取凭证号
- unsigned char m_plate_number[512] = {0}; //车牌号
- unsigned char m_phone_number[256] = {0}; //电话号码
- unsigned char m_reserved1346_1377[32] = {0}; //预留
- };
- //plc给调度模块发送答复消息的DB编号
- #define RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER 101
- //plc给调度模块发送答复消息的指令结构体
- struct Response_from_plc_to_dispatch
- {
- unsigned char m_reserved0 = 0; //预留
- unsigned char m_command_flag = 0; //指令标志位, 0bit==1:流程结束
- unsigned char m_task_status = 0; //流程状态, 0=正常,1=可恢复型故障,2=不可恢复故障
- unsigned char m_reserved3_11[9] = {0}; //预留
- //指令信息
- unsigned short m_block_id = 0; //单位编号(区域编号), 1~3
- unsigned short m_floor_id = 0; //楼层编号, 1~14
- unsigned short m_parkspace_id = 0; //同层的车位索引, 一楼为1~4, 楼上为1~6
- unsigned char m_command_key[256] = {0}; //指令key(任务唯一码), 作为通信标志位
- unsigned char m_is_entrance_flag = 0; //是否为入口, 1=入口,0=非入口, (如果是入口, 中跑车需要按照汽车的旋转角进行偏移)
- unsigned char m_reserved275_289[15] = {0}; //预留
- //汽车定位信息
- float m_center_x = 0; //整车的中心点x值, 四轮的中心
- float m_center_y = 0; //整车的中心点y值, 四轮的中心
- float m_car_angle = 0; //整车的车身旋转角,
- float m_car_length = 0; //整车的长度, 用于规避碰撞
- float m_car_width = 0; //整车的宽度, 用于规避碰撞
- float m_car_height = 0; //整车的高度, 用于规避碰撞
- float m_wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
- float m_wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
- unsigned char m_voucher_number[256] = {0}; //停取凭证号
- unsigned char m_plate_number[512] = {0}; //车牌号
- unsigned char m_phone_number[256] = {0}; //电话号码
- unsigned char m_reserved1346_1377[32] = {0}; //预留
- };
- //调度模块给plc发送状态消息的DB编号
- #define STATUS_FROM_DISPATCH_TO_PLC_DBNUMBER 110
- //调度模块给plc发送状态消息的指令结构体
- struct Status_from_dispatch_to_plc
- {
- unsigned char m_heartbeat = 0; //心跳位, 0-255循环
- unsigned char m_check_flag = 0; //校验标志位
- unsigned char m_reserved2_9[8] = {0}; //预留
- //时钟
- unsigned short m_year = 0; //年
- unsigned char m_month = 0; //月
- unsigned char m_day = 0; //日
- unsigned char m_weekday = 0; //周
- unsigned char m_hour = 0; //时
- unsigned char m_minute = 0; //分
- unsigned char m_second = 0; //秒
- unsigned int m_nanosecond = 0; //纳秒
- unsigned char m_reserved22_29[8] = {0}; //预留
- };
- //plc给调度模块发送状态消息的DB编号
- #define STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER 111
- //plc给调度模块发送状态消息的指令结构体
- struct Status_from_plc_to_dispatch
- {
- unsigned char m_heartbeat = 0; //心跳位, 0-255循环
- unsigned char m_check_flag = 0; //校验标志位
- unsigned char m_reserved2_9[8] = {0}; //预留
- //时钟
- unsigned short m_year = 0; //年
- unsigned char m_month = 0; //月
- unsigned char m_day = 0; //日
- unsigned char m_weekday = 0; //周
- unsigned char m_hour = 0; //时
- unsigned char m_minute = 0; //分
- unsigned char m_second = 0; //秒
- unsigned int m_nanosecond = 0; //纳秒
- unsigned char m_reserved22_29[8] = {0}; //预留
- //升降机状态, (楚天项目代指电梯)
- //升降机信息, 0bit==1:急停正常, 1bit==1:处于安全位置, 2bit==1:静止状态, 3bit==1:可执行新指令, 4bit==1:存在故障,
- unsigned char m_elevator_information = 0; //升降机信息,
- unsigned char m_reserved31 = 0; //预留
- double m_elevator_coordinates = 0; //升降机坐标
- unsigned char m_reserved40_73[34] = {0}; //预留
- //搬运器状态, (楚天项目代指中跑车)
- //搬运器信息, 0bit==1:急停正常, 1bit==1:处于安全位置, 2bit==1:静止状态, 3bit==1:可执行新指令, 4bit==1:存在故障,
- unsigned char m_carrier_information = 0; //搬运器信息,
- unsigned char m_reserved75 = 0; //预留
- double m_carrier_coordinates = 0; //搬运器坐标
- double m_carrier_angle = 0; //搬运器角度
- unsigned char m_reserved92_125[34] = {0}; //预留
- //故障信息
- unsigned char m_carrier_error_code[50] = {0}; //搬运器错误码
- unsigned char m_carrier_error_string[512] = {0}; //搬运器错误描述
- unsigned char m_elevator_error_code[50] = {0}; //升降机错误码
- unsigned char m_elevator_error_string[512] = {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
- std::mutex m_data_lock; //数据锁
- Request_from_dispatch_to_plc m_request_from_dispatch_to_plc; //调度模块给plc发送请求消息的指令结构体
- Response_from_plc_to_dispatch m_response_from_plc_to_dispatch; //plc给调度模块发送答复消息的指令结构体
- Status_from_dispatch_to_plc m_status_from_dispatch_to_plc; //调度模块给plc发送状态消息的指令结构体
- Status_from_plc_to_dispatch m_status_from_plc_to_dispatch; //plc给调度模块发送状态消息的指令结构体
- private:
- };
- #endif //NNXX_TESTS_DISPATCH_COMMUNICATION_H
|