dispatch_communication.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // Created by huli on 2020/9/25.
  3. //
  4. #ifndef NNXX_TESTS_DISPATCH_COMMUNICATION_H
  5. #define NNXX_TESTS_DISPATCH_COMMUNICATION_H
  6. #include "../tool/singleton.h"
  7. #include "../snap7_communication/snap7_communication_base.h"
  8. class Dispatch_communication:public Singleton<Dispatch_communication>, public Snap7_communication_base
  9. {
  10. public:
  11. #pragma pack(push, 1) //struct按照1个byte对齐
  12. //调度模块给plc发送请求消息的DB编号
  13. #define REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER 100
  14. //调度模块给plc发送请求消息的指令结构体
  15. struct Request_from_dispatch_to_plc
  16. {
  17. unsigned char m_reserved0 = 0; //预留
  18. unsigned char m_command_flag = 0; //指令标志位, 0bit==1:流程开始, 1bit==1:校验无误
  19. unsigned char m_task_status = 0; //流程状态, 0=正常,1=可恢复型故障,2=不可恢复故障
  20. unsigned char m_reserved3_11[9] = {0}; //预留
  21. //指令信息
  22. unsigned short m_block_id = 0; //单位编号(区域编号), 1~3
  23. unsigned short m_floor_id = 0; //楼层编号, 1~14
  24. unsigned short m_parkspace_id = 0; //同层的车位索引, 一楼为1~4, 楼上为1~6
  25. unsigned char m_command_key[256] = {0}; //指令key(任务唯一码), 作为通信标志位
  26. unsigned char m_is_entrance_flag = 0; //是否为入口, 1=入口,0=非入口, (如果是入口, 中跑车需要按照汽车的旋转角进行偏移)
  27. unsigned char m_reserved275_289[15] = {0}; //预留
  28. //汽车定位信息
  29. float m_center_x = 0; //整车的中心点x值, 四轮的中心
  30. float m_center_y = 0; //整车的中心点y值, 四轮的中心
  31. float m_car_angle = 0; //整车的车身旋转角,
  32. float m_car_length = 0; //整车的长度, 用于规避碰撞
  33. float m_car_width = 0; //整车的宽度, 用于规避碰撞
  34. float m_car_height = 0; //整车的高度, 用于规避碰撞
  35. float m_wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
  36. float m_wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
  37. unsigned char m_voucher_number[256] = {0}; //停取凭证号
  38. unsigned char m_plate_number[512] = {0}; //车牌号
  39. unsigned char m_phone_number[256] = {0}; //电话号码
  40. unsigned char m_reserved1346_1377[32] = {0}; //预留
  41. };
  42. //plc给调度模块发送答复消息的DB编号
  43. #define RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER 101
  44. //plc给调度模块发送答复消息的指令结构体
  45. struct Response_from_plc_to_dispatch
  46. {
  47. unsigned char m_reserved0 = 0; //预留
  48. unsigned char m_command_flag = 0; //指令标志位, 0bit==1:流程结束
  49. unsigned char m_task_status = 0; //流程状态, 0=正常,1=可恢复型故障,2=不可恢复故障
  50. unsigned char m_reserved3_11[9] = {0}; //预留
  51. //指令信息
  52. unsigned short m_block_id = 0; //单位编号(区域编号), 1~3
  53. unsigned short m_floor_id = 0; //楼层编号, 1~14
  54. unsigned short m_parkspace_id = 0; //同层的车位索引, 一楼为1~4, 楼上为1~6
  55. unsigned char m_command_key[256] = {0}; //指令key(任务唯一码), 作为通信标志位
  56. unsigned char m_is_entrance_flag = 0; //是否为入口, 1=入口,0=非入口, (如果是入口, 中跑车需要按照汽车的旋转角进行偏移)
  57. unsigned char m_reserved275_289[15] = {0}; //预留
  58. //汽车定位信息
  59. float m_center_x = 0; //整车的中心点x值, 四轮的中心
  60. float m_center_y = 0; //整车的中心点y值, 四轮的中心
  61. float m_car_angle = 0; //整车的车身旋转角,
  62. float m_car_length = 0; //整车的长度, 用于规避碰撞
  63. float m_car_width = 0; //整车的宽度, 用于规避碰撞
  64. float m_car_height = 0; //整车的高度, 用于规避碰撞
  65. float m_wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
  66. float m_wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
  67. unsigned char m_voucher_number[256] = {0}; //停取凭证号
  68. unsigned char m_plate_number[512] = {0}; //车牌号
  69. unsigned char m_phone_number[256] = {0}; //电话号码
  70. unsigned char m_reserved1346_1377[32] = {0}; //预留
  71. };
  72. //调度模块给plc发送状态消息的DB编号
  73. #define STATUS_FROM_DISPATCH_TO_PLC_DBNUMBER 110
  74. //调度模块给plc发送状态消息的指令结构体
  75. struct Status_from_dispatch_to_plc
  76. {
  77. unsigned char m_heartbeat = 0; //心跳位, 0-255循环
  78. unsigned char m_check_flag = 0; //校验标志位
  79. unsigned char m_reserved2_9[8] = {0}; //预留
  80. //时钟
  81. unsigned short m_year = 0; //年
  82. unsigned char m_month = 0; //月
  83. unsigned char m_day = 0; //日
  84. unsigned char m_weekday = 0; //周
  85. unsigned char m_hour = 0; //时
  86. unsigned char m_minute = 0; //分
  87. unsigned char m_second = 0; //秒
  88. unsigned int m_nanosecond = 0; //纳秒
  89. unsigned char m_reserved22_29[8] = {0}; //预留
  90. };
  91. //plc给调度模块发送状态消息的DB编号
  92. #define STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER 111
  93. //plc给调度模块发送状态消息的指令结构体
  94. struct Status_from_plc_to_dispatch
  95. {
  96. unsigned char m_heartbeat = 0; //心跳位, 0-255循环
  97. unsigned char m_check_flag = 0; //校验标志位
  98. unsigned char m_reserved2_9[8] = {0}; //预留
  99. //时钟
  100. unsigned short m_year = 0; //年
  101. unsigned char m_month = 0; //月
  102. unsigned char m_day = 0; //日
  103. unsigned char m_weekday = 0; //周
  104. unsigned char m_hour = 0; //时
  105. unsigned char m_minute = 0; //分
  106. unsigned char m_second = 0; //秒
  107. unsigned int m_nanosecond = 0; //纳秒
  108. unsigned char m_reserved22_29[8] = {0}; //预留
  109. //升降机状态, (楚天项目代指电梯)
  110. //升降机信息, 0bit==1:急停正常, 1bit==1:处于安全位置, 2bit==1:静止状态, 3bit==1:可执行新指令, 4bit==1:存在故障,
  111. unsigned char m_elevator_information = 0; //升降机信息,
  112. unsigned char m_reserved31 = 0; //预留
  113. double m_elevator_coordinates = 0; //升降机坐标
  114. unsigned char m_reserved40_73[34] = {0}; //预留
  115. //搬运器状态, (楚天项目代指中跑车)
  116. //搬运器信息, 0bit==1:急停正常, 1bit==1:处于安全位置, 2bit==1:静止状态, 3bit==1:可执行新指令, 4bit==1:存在故障,
  117. unsigned char m_carrier_information = 0; //搬运器信息,
  118. unsigned char m_reserved75 = 0; //预留
  119. double m_carrier_coordinates = 0; //搬运器坐标
  120. double m_carrier_angle = 0; //搬运器角度
  121. unsigned char m_reserved92_125[34] = {0}; //预留
  122. //故障信息
  123. unsigned char m_carrier_error_code[50] = {0}; //搬运器错误码
  124. unsigned char m_carrier_error_string[512] = {0}; //搬运器错误描述
  125. unsigned char m_elevator_error_code[50] = {0}; //升降机错误码
  126. unsigned char m_elevator_error_string[512] = {0}; //升降机错误描述
  127. };
  128. #pragma pack(pop) //取消对齐
  129. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  130. friend class Singleton<Dispatch_communication>;
  131. private:
  132. // 父类的构造函数必须保护,子类的构造函数必须私有。
  133. Dispatch_communication();
  134. public:
  135. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  136. Dispatch_communication(const Dispatch_communication& other) = delete;
  137. Dispatch_communication& operator =(const Dispatch_communication& other) = delete;
  138. ~Dispatch_communication();
  139. public://API functions
  140. //初始化 通信 模块。如下三选一
  141. virtual Error_manager communication_init();
  142. //反初始化 通信 模块。
  143. virtual Error_manager communication_uninit();
  144. public://get or set member variable
  145. std::mutex * get_data_lock();
  146. Request_from_dispatch_to_plc * get_request_from_dispatch_to_plc();
  147. Response_from_plc_to_dispatch * get_response_from_plc_to_dispatch();
  148. Status_from_dispatch_to_plc * get_status_from_dispatch_to_plc();
  149. Status_from_plc_to_dispatch * get_status_from_plc_to_dispatch();
  150. protected://member functions
  151. //更新数据
  152. virtual Error_manager updata_receive_buf();
  153. virtual Error_manager updata_send_buf();
  154. protected://member variable
  155. std::mutex m_data_lock; //数据锁
  156. Request_from_dispatch_to_plc m_request_from_dispatch_to_plc; //调度模块给plc发送请求消息的指令结构体
  157. Response_from_plc_to_dispatch m_response_from_plc_to_dispatch; //plc给调度模块发送答复消息的指令结构体
  158. Status_from_dispatch_to_plc m_status_from_dispatch_to_plc; //调度模块给plc发送状态消息的指令结构体
  159. Status_from_plc_to_dispatch m_status_from_plc_to_dispatch; //plc给调度模块发送状态消息的指令结构体
  160. private:
  161. };
  162. #endif //NNXX_TESTS_DISPATCH_COMMUNICATION_H