You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
6.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__
  2. #define __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__
  3. // aliona
  4. // https://www.pornhub.com/view_video.php?viewkey=ph5dffcb1983567
  5. #include "../../alg/lgs/detectorStructures.h"
  6. #include "../../alg/lgs/mask.h"
  7. #include "../../hardware/soc/general/3DLRF.h"
  8. #include "protocol.h"
  9. #include <queue>
  10. #ifdef PRU_SLAVE
  11. #define SEND_TAG 0x00
  12. #else
  13. #define SEND_TAG 0x80
  14. #endif
  15. #define TWI_TARGET_QUEUE_SIZE 128
  16. #define TWI_CMD_INDEX 3
  17. #define TWI_PLS_INDEX 4
  18. #define TWI_MAX_PACKAGE_SIZE_BYTES 0x8002
  19. #define TWI_MAX_PAYLOAD_SIZE_BYTES 0x7fff
  20. typedef enum E_TWIN_COMMAND
  21. {
  22. TWC_NO_COMMAND = 0,
  23. TWC_SET_CMD_MODE = 1,
  24. TWC_SET_EVT_MODE,
  25. TWC_ACK_CMD,
  26. TWC_NACK_CMD,
  27. TWC_GET_MODE,
  28. TWC_CURRENT_MODE,
  29. TWC_GET_STATUS,
  30. TWC_CURRENT_STATUS,
  31. TWC_GET_CONFIG,
  32. TWC_SET_CONFIG,
  33. TWC_GET_VERSION,
  34. TWC_CURRENT_VERSION,
  35. TWC_GET_SHADOW_INFO,
  36. TWC_SHADOW_INFO,
  37. TWC_GET_SHADOW_POLY,
  38. TWC_SET_SHADOW_POLY,
  39. TWC_GET_SHADOW_TRACE,
  40. TWC_SET_SHADOW_TRACE,
  41. TWC_SHADOW_DATA_POLY,
  42. TWC_SHADOW_DATA_RAY,
  43. TWC_GET_THRESHOLD,
  44. TWC_TH_DATA,
  45. TWC_INIT_TSINC,
  46. TWC_TSINC_1,
  47. TWC_TSINC_2,
  48. TWC_PUSH_TARGET,
  49. TWC_DO_REBOOT
  50. } TWIN_COMMAND;
  51. typedef struct S_TWI_CMD_CONTAINER
  52. {
  53. TWIN_COMMAND CMD;
  54. size_t SIZE;
  55. void * DATA;
  56. } TWI_CMD_CONTAINER;
  57. typedef struct S_TWI_MASK_INFO
  58. {
  59. uint32_t active : 1;
  60. uint32_t poly_cnt : 8;
  61. uint32_t nouse : 7;
  62. uint32_t ray_cnt : 16;
  63. } TWI_MASK_INFO;
  64. typedef struct S_TWI_PEER_STATUS
  65. {
  66. LRF3D_WORK_MODE KRNL_WM;
  67. uint8_t ENABLED;
  68. uint8_t DETECTION;
  69. uint8_t TH_READY;
  70. } TWI_PEER_STATUS;
  71. typedef struct S_TWIN_STATUS
  72. {
  73. TWI_PEER_STATUS MASTER_STATUS;
  74. SOFTWARE_INFO MASTER_NFO;
  75. LGS_3D_PARAMETERS MASTER_PARAMS;
  76. TWI_PEER_STATUS SLAVE_STATUS;
  77. SOFTWARE_INFO SLAVE_NFO;
  78. LGS_3D_PARAMETERS SLAVE_PARAMS;
  79. bool VERSION_IS_SYNCED;
  80. bool SETTINGS_IS_SYNCED;
  81. bool SHADOW_IS_SYNCED;
  82. } TWIN_STATUS;
  83. typedef std::queue<TWI_CMD_CONTAINER *> TWI_CMD_QUEUE;
  84. #define TWI_STATUS_ERROR_MASK 0x000000ff
  85. #define TWI_STATUS_TARGET_MASK 0x0000ff00
  86. #define TWI_STATUS_KERNEL_MASK 0xffff0000
  87. #define TWI_STATUS_MASTER_KERNEL_MASK 0x00ff0000
  88. #define TWI_STATUS_SLAVE_KERNEL_MASK 0xff000000
  89. #define TWI_STATUS_KERNEL_00_RDY 0x00000001
  90. #define TWI_STATUS_KERNEL_01_RDY 0x00000002
  91. #define TWI_STATUS_KERNEL_02_RDY 0x00000004
  92. #define TWI_STATUS_KERNEL_03_RDY 0x00000008
  93. #define TWI_STATUS_KERNEL_04_RDY 0x00000010
  94. #define TWI_STATUS_KERNEL_05_RDY 0x00000020
  95. #define TWI_STATUS_KERNEL_06_RDY 0x00000040
  96. #define TWI_STATUS_KERNEL_07_RDY 0x00000080
  97. #define TWI_STATUS_KERNEL_08_RDY 0x00000100
  98. #define TWI_STATUS_KERNEL_09_RDY 0x00000200
  99. #define TWI_STATUS_KERNEL_10_RDY 0x00000400
  100. #define TWI_STATUS_KERNEL_11_RDY 0x00000800
  101. #define TWI_STATUS_KERNEL_12_RDY 0x00001000
  102. #define TWI_STATUS_KERNEL_13_RDY 0x00002000
  103. #define TWI_STATUS_KERNEL_14_RDY 0x00004000
  104. #define TWI_STATUS_KERNEL_15_RDY 0x00008000
  105. #define TWI_STATUS_KERNEL_16_RDY 0x00010000
  106. #define TWI_STATUS_KERNEL_17_RDY 0x00020000
  107. #define TWI_STATUS_KERNEL_18_RDY 0x00040000
  108. #define TWI_STATUS_KERNEL_19_RDY 0x00080000
  109. #define TWI_STATUS_KERNEL_20_RDY 0x00100000
  110. #define TWI_STATUS_KERNEL_21_RDY 0x00200000
  111. #define TWI_STATUS_KERNEL_22_RDY 0x00400000
  112. #define TWI_STATUS_KERNEL_23_RDY 0x00800000
  113. #define TWI_STATUS_KERNEL_24_RDY 0x01000000
  114. #define TWI_STATUS_KERNEL_25_RDY 0x02000000
  115. #define TWI_STATUS_KERNEL_26_RDY 0x04000000
  116. #define TWI_STATUS_KERNEL_27_RDY 0x08000000
  117. #define TWI_STATUS_KERNEL_28_RDY 0x10000000
  118. #define TWI_STATUS_KERNEL_29_RDY 0x20000000
  119. #define TWI_STATUS_KERNEL_30_RDY 0x40000000
  120. #define TWI_STATUS_KERNEL_31_RDY 0x80000000
  121. class protocolInternalLRF3D : public protocolParser
  122. {
  123. private:
  124. basicLogCollection * m_pLog;
  125. protected:
  126. int packetChecker(U8 * Buffer, size_t BufferSize);
  127. protocolPackage * packetExtractor(U8 * Buffer, size_t BufferSize);
  128. inline int FinishUpPackage(U8 * Buffer, size_t Size)
  129. {
  130. Buffer[0] = 0xAA;
  131. Buffer[1] = ((Size - 3) >> 8) | SEND_TAG;
  132. Buffer[2] = (Size - 3) & 0xFF;
  133. Buffer[Size] = checksumLGS(Buffer, Size);
  134. return Size + 1;
  135. }
  136. bool sendACK(TWIN_COMMAND ACK_CMD);
  137. bool sendNACK(TWIN_COMMAND ACK_CMD);
  138. bool sendPlainCMD(TWIN_COMMAND ACK_CMD);
  139. bool sendDetectionParameters(PLGS_3D_PARAMETERS ptr);
  140. bool sendPolygone(uint8_t polyID, simplePolygone * SP);
  141. bool sendShadowTrace(vectorZoneMask * ZM);
  142. public:
  143. protocolInternalLRF3D();
  144. virtual ~protocolInternalLRF3D();
  145. virtual bool create()
  146. {
  147. return protocolParser::create();
  148. }
  149. };
  150. #ifdef PRU_SLAVE
  151. class protocolInternalLRF3D_SLAVE : public protocolInternalLRF3D
  152. {
  153. private:
  154. basicLogCollection * m_pLog;
  155. protected:
  156. // thresholdNode * m_pThresholds[16]; // 8 - learning 8 - working
  157. basicMutex m_mData;
  158. virtual bool packetHandler(protocolPackage * Package)
  159. {
  160. return true;
  161. }
  162. public:
  163. protocolInternalLRF3D_SLAVE();
  164. virtual ~protocolInternalLRF3D_SLAVE();
  165. virtual bool create(void);
  166. bool ackShadowSegment(uint32_t dataIdx = 0);
  167. bool resetChannel(void);
  168. bool sendShadowInfo(TWI_MASK_INFO * ptr);
  169. bool sendTarget(targetRecord * ptr);
  170. bool sendTrasholdData(thresholdNode * data, uint32_t dataIdx = 0);
  171. bool sendCurrentParameters(PLGS_3D_PARAMETERS ptr);
  172. bool sendMode(uint8_t mode);
  173. bool sendStatus(TWI_PEER_STATUS * ptr);
  174. bool sendVersion(SOFTWARE_INFO * sv);
  175. };
  176. #else //! PRU_SLAVE
  177. class protocolInternalLRF3D_MASTER : public protocolInternalLRF3D
  178. {
  179. private:
  180. basicLogCollection * m_pLog;
  181. protected:
  182. virtual bool packetHandler(protocolPackage * Package)
  183. {
  184. return true;
  185. }
  186. bool synchTimeStage2();
  187. public:
  188. protocolInternalLRF3D_MASTER();
  189. virtual ~protocolInternalLRF3D_MASTER();
  190. virtual bool create(void);
  191. bool resetChannel(void);
  192. bool getShadowPoly(uint8_t polyID);
  193. bool ackThresholdSegment(uint32_t dataIdx = 0);
  194. bool ackShadowSegment(uint32_t dataIdx = 0);
  195. bool getTHData(uint8_t lrf_id);
  196. bool sendMode(uint8_t Mode);
  197. bool sendSoftwareUpdate(uint8_t * ptr);
  198. bool sendShadowData(uint8_t * ptr);
  199. };
  200. #endif //! PRU_SLAVE
  201. // https://www.exler.ru/blog/kak-vernut-staryy-interfeys-facebook.htm
  202. #endif