DIOSBoardProtocolParser.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. #include "stdafx.h"
  2. #include "DIOSBoardProtocolParser.h"
  3. #include "IOInterfaceMapper.h"
  4. #include "PacketDefine.h"
  5. #include "ICollimatorHandler.h"
  6. #include "DeviceDataDef.h"
  7. using namespace DIOS::Dev::Detail::MachineryECOM;
  8. PacketClass DIOSBoardProtocolParser::IdentifyPacketClass(SCFPacket *packet)
  9. {
  10. if (packet)
  11. {
  12. CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet));
  13. if (
  14. (pReceiveHead->FrameSize == 6
  15. || pReceiveHead->FrameSize == 7
  16. || pReceiveHead->FrameSize == 9
  17. || pReceiveHead->FrameSize == 10
  18. || pReceiveHead->FrameSize == 11)
  19. && pReceiveHead->FrameCmd == 0xFE
  20. )
  21. {
  22. return PC_NOTIFY;
  23. }
  24. }
  25. return PC_NAN;
  26. }
  27. PacketNotifyType DIOSBoardProtocolParser::IdentifyPacketNotifyType(SCFPacket *packet)
  28. {
  29. PacketNotifyType pnt = PNT_NAN;
  30. if (packet)
  31. {
  32. CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet));
  33. if (pReceiveHead->FuncId == IOInterfaceMapper::ID_HAND_SWITCH_GEAR_FIRST)
  34. {
  35. if (pReceiveHead->Data2 == 0x01)
  36. {
  37. pnt = PNT_HANDSWITCH_FIRST_PRESSED;
  38. }
  39. else
  40. {
  41. pnt = PNT_HANDSWITCH_FIRST_RELEASE;
  42. }
  43. }
  44. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_HAND_SWITCH_GEAR_SECOND)
  45. {
  46. if (pReceiveHead->Data2 == 0x01)
  47. {
  48. pnt = PNT_HANDSWITCH_SECOND_PRESSED;
  49. }
  50. else
  51. {
  52. pnt = PNT_HANDSWITCH_SECOND_RELEASE;
  53. }
  54. }
  55. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_SYSTEM_RESET)
  56. {
  57. if (pReceiveHead->Data2 == 0x01)
  58. {
  59. pnt = PNT_SYSTEM_RESET_START;
  60. }
  61. else
  62. {
  63. pnt = PNT_SYSTEM_RESET_STOP;
  64. }
  65. }
  66. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_SYSTEM_RESET_SWING)
  67. {
  68. if (pReceiveHead->Data2 == 0x01)
  69. {
  70. pnt = PNT_SYSTEM_RESET_SWING_START;
  71. }
  72. else
  73. {
  74. pnt = PNT_SYSTEM_RESET_SWING_STOP;
  75. }
  76. }
  77. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_SYSTEM_RESET_CIRCULAR)
  78. {
  79. if (pReceiveHead->Data2 == 0x01)
  80. {
  81. pnt = PNT_SYSTEM_RESET_CIRCULAR_START;
  82. }
  83. else
  84. {
  85. pnt = PNT_SYSTEM_RESET_CIRCULAR_STOP;
  86. }
  87. }
  88. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_PULSE)
  89. {
  90. pnt = PNT_PWM_OFFSET;
  91. }
  92. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_XRAYON_NOTIFY)
  93. {
  94. if (pReceiveHead->Data2 == 0x01)
  95. {
  96. pnt = PNT_XRAY_ON;
  97. }
  98. else
  99. {
  100. pnt = PNT_XRAY_OFF;
  101. }
  102. }
  103. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_LOW_LIMIT)
  104. {
  105. if (pReceiveHead->Data1 == 0x01)
  106. {
  107. if (pReceiveHead->Data2 == 0x1)
  108. {
  109. pnt = PNT_TUBE_ANGLE_LOW_LIMIT;
  110. }
  111. else
  112. {
  113. pnt = PNT_TUBE_ANGLE_LEAVE_LOW_LIMIT;
  114. }
  115. }
  116. }
  117. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_HIGH_LIMIT)
  118. {
  119. if (pReceiveHead->Data1 == 0x01)
  120. {
  121. if (pReceiveHead->Data2 == 0x1)
  122. {
  123. pnt = PNT_TUBE_ANGLE_HIGH_LIMIT;
  124. }
  125. else
  126. {
  127. pnt = PNT_TUBE_ANGLE_LEAVE_HIGH_LIMIT;
  128. }
  129. }
  130. }
  131. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_ENCODER)
  132. {
  133. if (pReceiveHead->Data1 == 0x01)
  134. {
  135. pnt = PNT_TUBE_ANGLE_ENCODER;
  136. }
  137. else if (pReceiveHead->Data1 == 0x02 && pReceiveHead->Data2 == 0x01)
  138. {
  139. pnt = PNT_TUBE_ANGLE_ENCODER_Z_CLEAR;
  140. }
  141. }
  142. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_AD)
  143. {
  144. pnt = PNT_TUBE_HEIGHT_AD;
  145. }
  146. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_ENCODER)
  147. {
  148. if (pReceiveHead->Data1 == 0x01)
  149. {
  150. pnt = PNT_TUBE_HEIGHT_ENCODER;
  151. }
  152. else if (pReceiveHead->Data1 == 0x02 && pReceiveHead->Data2 == 0x01)
  153. {
  154. pnt = PNT_TUBE_HEIGHT_ENCODER_Z_CLEAR;
  155. }
  156. }
  157. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_HIGH_LIMIT)
  158. {
  159. if (pReceiveHead->Data1 == 0x01)
  160. {
  161. if (pReceiveHead->Data2 == 0x01)
  162. {
  163. pnt = PNT_TUBE_HEIGHT_HIGH_LIMIT;
  164. }
  165. else
  166. {
  167. pnt = PNT_TUBE_HEIGHT_LEAVE_HIGH_LIMIT;
  168. }
  169. }
  170. }
  171. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_LOW_LIMIT)
  172. {
  173. if (pReceiveHead->Data1 == 0x01)
  174. {
  175. if (pReceiveHead->Data2 == 0x01)
  176. {
  177. pnt = PNT_TUBE_HEIGHT_LOW_LIMIT;
  178. }
  179. else
  180. {
  181. pnt = PNT_TUBE_HEIGHT_LEAVE_LOW_LIMIT;
  182. }
  183. }
  184. }
  185. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_CAN)
  186. {
  187. pnt = PNT_CAN;
  188. }
  189. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_CONTROLLER_DIRECTION_1)
  190. {
  191. if (pReceiveHead->Data2 == 0x01)
  192. {
  193. pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_1_START;
  194. }
  195. else
  196. {
  197. pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_1_STOP;
  198. }
  199. }
  200. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_CONTROLLER_DIRECTION_2)
  201. {
  202. if (pReceiveHead->Data2 == 0x01)
  203. {
  204. pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_2_START;
  205. }
  206. else
  207. {
  208. pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_2_STOP;
  209. }
  210. }
  211. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_CONTROLLER_DIRECTION_1)
  212. {
  213. if (pReceiveHead->Data2 == 0x01)
  214. {
  215. pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_1_START;
  216. }
  217. else
  218. {
  219. pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_1_STOP;
  220. }
  221. }
  222. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_CONTROLLER_DIRECTION_2)
  223. {
  224. if (pReceiveHead->Data2 == 0x01)
  225. {
  226. pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_2_START;
  227. }
  228. else
  229. {
  230. pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_2_STOP;
  231. }
  232. }
  233. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_CARM_SCANNING_SWITCH)
  234. {
  235. if (pReceiveHead->Data2 == 0x01)
  236. {
  237. pnt = PNT_CARM_SCANNING_SWITCH_SWING;
  238. }
  239. else
  240. {
  241. pnt = PNT_CARM_SCANNING_SWITCH_CIRCULAR;
  242. }
  243. }
  244. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_1)
  245. {
  246. if (pReceiveHead->Data2 == 0x01)
  247. {
  248. pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_1_START;
  249. }
  250. else
  251. {
  252. pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_1_STOP;
  253. }
  254. }
  255. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_2)
  256. {
  257. if (pReceiveHead->Data2 == 0x01)
  258. {
  259. pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_2_START;
  260. }
  261. else
  262. {
  263. pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_2_STOP;
  264. }
  265. }
  266. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_ENCODER)
  267. {
  268. if (pReceiveHead->Data1 == 0x01)
  269. {
  270. pnt = PNT_TUBE_HORIZONTAL_ENCODER;
  271. }
  272. else if (pReceiveHead->Data1 == 0x02 && pReceiveHead->Data2 == 0x01)
  273. {
  274. pnt = PNT_TUBE_HORIZONTAL_ENCODER_Z_CLEAR;
  275. }
  276. }
  277. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_LEFT_LIMIT)
  278. {
  279. if (pReceiveHead->Data1 == 0x01)
  280. {
  281. if (pReceiveHead->Data2 == 0x01)
  282. {
  283. pnt = PNT_TUBE_HORIZONTAL_LEFT_LIMIT;
  284. }
  285. else
  286. {
  287. pnt = PNT_TUBE_HORIZONTAL_LEAVE_LEFT_LIMIT;
  288. }
  289. }
  290. }
  291. else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_RIGHT_LIMIT)
  292. {
  293. if (pReceiveHead->Data1 == 0x01)
  294. {
  295. if (pReceiveHead->Data2 == 0x01)
  296. {
  297. pnt = PNT_TUBE_HORIZONTAL_RIGHT_LIMIT;
  298. }
  299. else
  300. {
  301. pnt = PNT_TUBE_HORIZONTAL_LEAVE_RIGHT_LIMIT;
  302. }
  303. }
  304. }
  305. }
  306. return pnt;
  307. }
  308. bool DIOSBoardProtocolParser::ParsePWMOffsetPacket(SCFPacket *packet, PWMOffsetPacket *outpacket)
  309. {
  310. SHORTDATA data;
  311. SHORTDATA Timedata;
  312. CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet));
  313. data.Low = pReceiveHead->Data1;
  314. data.High = pReceiveHead->Data2;
  315. Timedata.Low = pReceiveHead->Data3;
  316. Timedata.High = pReceiveHead->Data4;
  317. outpacket->pwmoffset = data.ShortPart;
  318. outpacket->timeoffset = Timedata.ShortPart;
  319. return true;
  320. }
  321. bool DIOSBoardProtocolParser::ParseTubeHeightADPacket(SCFPacket *packet, TubeLineADPacket *outpacket)
  322. {
  323. SHORTDATA data;
  324. SHORTDATA Timedata;
  325. CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet));
  326. data.Low = pReceiveHead->Data1;
  327. data.High = pReceiveHead->Data2;
  328. Timedata.Low = pReceiveHead->Data3;
  329. Timedata.High = pReceiveHead->Data4;
  330. outpacket->posoffset = data.ShortPart;
  331. outpacket->timeoffset = data.ShortPart;
  332. return true;
  333. }
  334. bool DIOSBoardProtocolParser::ParseEncoderPacket(SCFPacket *packet, EncoderPacket *outpacket)
  335. {
  336. Integer data;
  337. CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet));
  338. if (pReceiveHead->Data1 != 0x01)
  339. {
  340. return false;
  341. }
  342. data.integer_byte.integer_lowbyte_0 = pReceiveHead->Data2;
  343. data.integer_byte.integer_lowbyte_1 = pReceiveHead->Data3;
  344. data.integer_byte.integer_highbyte_0 = pReceiveHead->Data4;
  345. data.integer_byte.integer_highbyte_1 = pReceiveHead->Data5;
  346. outpacket->encoder = data.integer_int;
  347. return true;
  348. }
  349. typedef struct _CtrlPacketCan
  350. {
  351. unsigned char szTitle[2];
  352. unsigned char FrameSize;
  353. unsigned char FrameId;
  354. unsigned char FrameCmd;
  355. unsigned char FuncId;
  356. unsigned char Data1;
  357. unsigned char stdid;
  358. unsigned char dlc;
  359. unsigned char data[8];
  360. }CTRLPACKETCAN;
  361. bool DIOSBoardProtocolParser::ParseCanPacket(SCFPacket *packet, CanDeviceData *outpacket)
  362. {
  363. CTRLPACKETCAN *pReceiveHead = (CTRLPACKETCAN *)((char *)(*packet));
  364. if (pReceiveHead->Data1 != 0x01)
  365. {
  366. return false;
  367. }
  368. outpacket->stdid = pReceiveHead->stdid;
  369. outpacket->dlc = pReceiveHead->dlc;
  370. memcpy_s(outpacket->data, sizeof(outpacket->data), pReceiveHead->data, sizeof(pReceiveHead->data));
  371. return true;
  372. }