CarCmd.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Converters;
  3. namespace AmrControl.Common
  4. {
  5. [JsonObject]
  6. public class MessagePacket
  7. {
  8. static int msgID = 1;
  9. /**
  10. * 消息ID,建议使用雪花或者uuid之类的唯一id
  11. * 若没有手动设置,消息发送端自动生成,大家想用string传值
  12. */
  13. //[JsonProperty(PropertyName = "newName")]
  14. //[JsonConverter(typeof(IntStringConverter))]
  15. public string id;
  16. /**
  17. * 终端id,连接时自定义,设备端建议同设备id,若工控机为主要控制端,即为工控机id
  18. */
  19. public string clientId;
  20. /**
  21. * 设备id
  22. */
  23. public string deviceId;
  24. /**
  25. * 消息体摘要,防止消息篡改
  26. */
  27. public string md5;
  28. /**
  29. * 加密算法,可为空,默认不加密
  30. * 所有加密类型必须为软件维护的具体参见EncryptAlgEnum
  31. */
  32. [JsonConverter(typeof(StringEnumConverter))]
  33. public EncryptAlgEnum encryptType;
  34. /**
  35. * 客户端类型
  36. * 不作为传输使用
  37. */
  38. public byte clientType;
  39. /**
  40. * 源消息id,用于响应请求
  41. */
  42. public string sourceId;
  43. /**
  44. * 附带消息
  45. */
  46. public Dictionary<string, string> attachments;
  47. /**
  48. * 发送时间
  49. */
  50. public DateTime sendTime;
  51. public MessagePacket()
  52. {
  53. id = msgID.ToString();
  54. msgID = (msgID + 1) % int.MaxValue;
  55. clientId = "AmrManager";
  56. attachments = new Dictionary<string, string>();
  57. sendTime = DateTime.Now;
  58. encryptType = EncryptAlgEnum.NOT;
  59. }
  60. }
  61. public enum EncryptAlgEnum : byte
  62. {
  63. /**
  64. * 不加密
  65. */
  66. NOT = 1,
  67. /**
  68. * aes对称加密算法
  69. */
  70. AES128 = 2,
  71. }
  72. //车辆控制相关
  73. public class CallCarCmd : MessagePacket
  74. {
  75. /**
  76. * 小车id
  77. */
  78. public string carId;
  79. /**
  80. * 小车类型;0-agv;1-amr
  81. */
  82. public CarType type;
  83. /**
  84. * 目标位置
  85. */
  86. public Position destPos;
  87. /* (non-Javadoc)
  88. * @see com.jg.network.common.requests.ICmd#msgType()
  89. */
  90. public MessageType msgType;
  91. /* (non-Javadoc)
  92. * @see com.jg.network.common.requests.ICmd#md5Str()
  93. */
  94. public string md5Str;
  95. }
  96. public class StopCarCmd : MessagePacket
  97. {
  98. /**
  99. * 小车id
  100. */
  101. public string carId;
  102. /**
  103. * 小车类型;0-agv;1-amr
  104. */
  105. public CarType type;
  106. /* (non-Javadoc)
  107. * @see com.jg.network.common.requests.ICmd#msgType()
  108. */
  109. public MessageType msgType;
  110. /* (non-Javadoc)
  111. * @see com.jg.network.common.requests.ICmd#md5Str()
  112. */
  113. public string md5Str;
  114. }
  115. public class EnableCarCmd : MessagePacket
  116. {
  117. /**
  118. * 小车id
  119. */
  120. public string carId;
  121. /**
  122. * 小车类型;0-agv;1-amr
  123. */
  124. public CarType type;
  125. /* (non-Javadoc)
  126. * @see com.jg.network.common.requests.ICmd#msgType()
  127. */
  128. public MessageType msgType;
  129. /* (non-Javadoc)
  130. * @see com.jg.network.common.requests.ICmd#md5Str()
  131. */
  132. public string md5Str;
  133. }
  134. public class DisableCarCmd : MessagePacket
  135. {
  136. /**
  137. * 小车id
  138. */
  139. public string carId;
  140. /**
  141. * 小车类型;0-agv;1-amr
  142. */
  143. public CarType type;
  144. /* (non-Javadoc)
  145. * @see com.jg.network.common.requests.ICmd#msgType()
  146. */
  147. public MessageType msgType;
  148. /* (non-Javadoc)
  149. * @see com.jg.network.common.requests.ICmd#md5Str()
  150. */
  151. public string md5Str;
  152. }
  153. public class CarShowCmd : MessagePacket
  154. {
  155. /**
  156. * 小车id
  157. */
  158. public string carId;
  159. /**
  160. * 小车类型;0-agv;1-amr
  161. */
  162. public CarType type;
  163. /**
  164. * 通道id集合,2个字节,车上有两块屏
  165. */
  166. public byte[] channelIds;
  167. /**
  168. * 图片代码集合,二者长度必须一致,2个字节,车上有两块屏
  169. */
  170. public byte[] picCodes;
  171. /* (non-Javadoc)
  172. * @see com.jg.network.common.requests.ICmd#msgType()
  173. */
  174. public MessageType msgType;
  175. /* (non-Javadoc)
  176. * @see com.jg.network.common.requests.ICmd#md5Str()
  177. */
  178. public string md5Str;
  179. }
  180. [JsonObject]
  181. public class CarStateCmd : MessagePacket
  182. {
  183. //内部使用的一个id号,也算是车的地址,以0xfe01,0xfe02,0xfe03,0xfe04等地址
  184. [JsonIgnore]
  185. internal int iCarID;
  186. /**
  187. * 小车id
  188. */
  189. public string carId;
  190. /**
  191. * 小车类型;0-agv;1-amr
  192. */
  193. public CarType type;
  194. /**
  195. * 电量
  196. */
  197. public string powerLevel;
  198. /**
  199. * 车辆状态;
  200. * 1-运动状态
  201. * 2-停止状态
  202. * 3-中断状态
  203. * 4-故障状态
  204. * 5-到位状态
  205. */
  206. public CarState state;
  207. /**
  208. * 当前是否载货, 默认false
  209. */
  210. public bool loading;
  211. /**
  212. * 当前是否使能, 默认false
  213. */
  214. public bool isEnable;
  215. /**
  216. * 速度;m/s
  217. */
  218. public string speed;
  219. /**
  220. * 当前位置
  221. */
  222. public Position curPos;
  223. /**
  224. * 目标位置
  225. */
  226. public Position destPos;
  227. /* (non-Javadoc)
  228. * @see com.jg.network.common.requests.ICmd#msgType()
  229. */
  230. public MessageType msgType;
  231. /* (non-Javadoc)
  232. * @see com.jg.network.common.requests.ICmd#md5Str()
  233. */
  234. public string md5Str;
  235. }
  236. public enum CarType : byte
  237. {
  238. AMR = 0,
  239. AGV = 1,
  240. }
  241. public enum MessageType : int
  242. {
  243. /**
  244. * ping 消息
  245. */
  246. MSG_TYPE_PING = 1,
  247. /**
  248. * pong 消息
  249. */
  250. MSG_TYPE_PONG = 10001,
  251. /**
  252. * 请求授权消息
  253. */
  254. MSG_TYPE_LOGIN = 2,
  255. /**
  256. * 小车上报状态信息
  257. */
  258. MSG_TYPE_CAR_REPORT = 3,
  259. /**
  260. * 呼叫小车
  261. */
  262. MSG_TYPE_CALL_CAR = 4,
  263. /**
  264. * 停止小车命令
  265. */
  266. MSG_TYPE_STOP_CAR = 5,
  267. /**
  268. * 小车使能
  269. */
  270. MSG_TYPE_ENABLE_CAR = 6,
  271. /**
  272. * 小车停止使能
  273. */
  274. MSG_TYPE_DISABLE_CAR = 7,
  275. /**
  276. * 机械臂状态上报
  277. */
  278. MSG_TYPE_ROBOT_STATE_REPORT = 8,
  279. /**
  280. * 通知小车展示图片
  281. */
  282. MSG_TYPE_CAR_SHOW = 9,
  283. //车上线
  284. MSG_TYPE_CAR_Connected = 10,
  285. //车下线
  286. MSG_TYPE_CAR_Disconnected = 11,
  287. //车到达
  288. MSG_TYPE_CAR_Arrived = 12,
  289. /**
  290. * 登录返回消息类型
  291. * 此处规定所有返回消息均为原请求消息的类型前面+1,消息保留4位防止正常消息不足
  292. */
  293. MSG_TYPE_LOGIN_RESULT = 10002,
  294. /**
  295. * 错误响应消息类型
  296. */
  297. MSG_TYPE_ERR_RESULT = -1,
  298. /**
  299. * 通用消息回执类型
  300. */
  301. MSG_TYPE_RETURN_RESULT = 0,
  302. /**
  303. * 停止小车后的回执消息
  304. */
  305. MSG_TYPE_CAR_STOP_RESULT = 10005,
  306. }
  307. public class Position
  308. {
  309. public int x;
  310. public int y;
  311. public int z;
  312. public string yaw;
  313. public Position(int x, int y, int z, string yaw)
  314. {
  315. this.x = x;
  316. this.y = y;
  317. this.z = z;
  318. this.yaw = yaw;
  319. }
  320. }
  321. public enum CarState : byte
  322. {
  323. //1-运动状态
  324. Moving = 1,
  325. // * 2-停止状态
  326. Stoped = 2,
  327. // * 3-中断状态,运行过程中被打断
  328. Interrupt = 3,
  329. // * 4-故障状态
  330. Error = 4,
  331. // * 5-到达状态
  332. Arrived,
  333. }
  334. }