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.

143 lines
5.2 KiB

​
​
​
​
​
6 years ago
6 years ago
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
6 years ago
​
​
​
​
​
​
6 years ago
6 years ago
6 years ago
​
6 years ago
6 years ago
​
​
​
6 years ago
6 years ago
6 years ago
​
​
​
6 years ago
​
​
6 years ago
6 years ago
6 years ago
​
  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 <queue>
  6. #include "protocol.h"
  7. #include "../../hardware/soc/general/3DLRF.h"
  8. #ifdef PRU_SLAVE
  9. #define SEND_TAG 0x00
  10. #else
  11. #define SEND_TAG 0x80
  12. #endif
  13. #define TWI_TARGET_QUEUE_SIZE 128
  14. #define TWI_MAX_PACKAGE_SIZE_BYTES ( PROTOCOL_PARSER_BUFFER_SIZE >> 1 )
  15. typedef enum E_TWIN_COMMAND{
  16. TWC_NO_COMMAND = 0,
  17. TWC_GET_STATUS = 1,
  18. TWC_ACK_STATUS = 2,
  19. TWC_GET_TARGETS = 3,
  20. TWC_ACK_TARGETS = 4,
  21. TWC_GET_CONFIG = 5,
  22. TWC_SET_CONFIG = 6,
  23. TWC_ACK_CONFIG = 7,
  24. TWC_GET_THDRAW = 8,
  25. TWC_SET_THDRAW = 9,
  26. TWC_PUSH_TARGET = 10,
  27. TWC_TH_DATA = 11,
  28. TWC_TARGETS_DATA = 12,
  29. TWC_GET_VERSION = 13,
  30. TWC_ACK_VERSION = 14,
  31. TWC_GET_SHADOW = 15,
  32. TWC_ACK_SHADOW = 16,
  33. TWC_SET_SHADOW = 17,
  34. TWC_DO_REBOOT = 255
  35. } TWIN_COMMAND;
  36. typedef struct S_TWIN_CMD_RECORD{
  37. TWIN_COMMAND CMD;
  38. void * PTR;
  39. } TWIN_CMD_REC;
  40. typedef std::queue<TWIN_CMD_REC *> TWIN_COMMAND_QUEUE;
  41. #define TWI_STATUS_ERROR_MASK 0x000000ff
  42. #define TWI_STATUS_TARGET_MASK 0x0000ff00
  43. #define TWI_STATUS_KERNEL_MASK 0xffff0000
  44. #define TWI_STATUS_KERNEL_00_RDY 0x00010000
  45. #define TWI_STATUS_KERNEL_01_RDY 0x00020000
  46. #define TWI_STATUS_KERNEL_02_RDY 0x00040000
  47. #define TWI_STATUS_KERNEL_03_RDY 0x00080000
  48. #define TWI_STATUS_KERNEL_04_RDY 0x00100000
  49. #define TWI_STATUS_KERNEL_05_RDY 0x00200000
  50. #define TWI_STATUS_KERNEL_06_RDY 0x00400000
  51. #define TWI_STATUS_KERNEL_07_RDY 0x00800000
  52. #define TWI_STATUS_KERNEL_08_RDY 0x01000000
  53. #define TWI_STATUS_KERNEL_09_RDY 0x02000000
  54. #define TWI_STATUS_KERNEL_10_RDY 0x04000000
  55. #define TWI_STATUS_KERNEL_11_RDY 0x08000000
  56. #define TWI_STATUS_KERNEL_12_RDY 0x10000000
  57. #define TWI_STATUS_KERNEL_13_RDY 0x20000000
  58. #define TWI_STATUS_KERNEL_14_RDY 0x40000000
  59. #define TWI_STATUS_KERNEL_15_RDY 0x80000000
  60. class protocolInternalLRF3D: public protocolParser {
  61. private:
  62. basicLogCollection *m_pLog;
  63. protected:
  64. uint32_t m_nStatus;
  65. basicMutex m_mStatusProtector;
  66. int packetChecker( U8 *Buffer, size_t BufferSize );
  67. protocolPackage *packetExtractor( U8 *Buffer, size_t BufferSize );
  68. inline int FinishUpPackage( U8 *Buffer, size_t Size ){
  69. Buffer[0] = 0xAA;
  70. Buffer[1] = ((Size - 3) >> 8) | SEND_TAG;
  71. Buffer[2] = (Size - 3) & 0xFF;
  72. Buffer[Size] = checksumLGS(Buffer, Size);
  73. return Size + 1;
  74. };
  75. public:
  76. protocolInternalLRF3D();
  77. virtual ~protocolInternalLRF3D();
  78. virtual bool create(){ return protocolParser::create(); };
  79. uint32_t getStatus();
  80. };
  81. #ifdef PRU_SLAVE
  82. class protocolInternalLRF3D_SLAVE: public protocolInternalLRF3D{
  83. private:
  84. basicLogCollection *m_pLog;
  85. thresholdNode *m_pThresholds[16]; // 8 - learning 8 - working
  86. basicMutex m_mData;
  87. bool sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx = 0 );
  88. bool sendTargets( void );
  89. bool sendStatus( void );
  90. protected:
  91. virtual bool packetHandler( protocolPackage *Package );
  92. public:
  93. protocolInternalLRF3D_SLAVE();
  94. virtual ~protocolInternalLRF3D_SLAVE();
  95. virtual bool create( void );
  96. bool resetChannel(void);
  97. bool setTrasholdData( uint8_t lrf_id, uint32_t *ptr );
  98. bool pushTarget( targetRecord *ptr );
  99. };
  100. #else //!PRU_SLAVE
  101. class protocolInternalLRF3D_MASTER: public protocolInternalLRF3D{
  102. private:
  103. basicLogCollection * m_pLog;
  104. TWIN_COMMAND m_bLastPackageType;
  105. basicMutex m_mLastTypeProtector;
  106. thresholdNode * m_pTrashold;
  107. targetRecord m_pTargets[TWI_TARGET_QUEUE_SIZE];
  108. uint8_t m_nTargetCount;
  109. basicMutex m_mTargetProtector;
  110. protected:
  111. bool packetHandler( protocolPackage *Package );
  112. public:
  113. protocolInternalLRF3D_MASTER();
  114. virtual ~protocolInternalLRF3D_MASTER();
  115. virtual bool create(void);
  116. bool resetChannel(void);
  117. bool ackDataSegment( uint32_t dataIdx = 0 );
  118. bool ackTargets( uint32_t pkgId );
  119. TWIN_COMMAND getLastPackageType( void );
  120. bool requestCurrentSettings( void );
  121. bool requestShadow( void );
  122. bool requestSoftwareVersion(void);
  123. bool requestStatus( void );
  124. bool requestTargets(void);
  125. bool requestTrasholdData( uint8_t lrf_id );
  126. bool sendSoftwareUpdate( uint8_t *ptr );
  127. //bool setTData( targetRecord *ptr ){ m_pTargets = ptr; return m_pTargets!=NULL; };
  128. bool setTHData( thresholdNode *ptr ){ m_pTrashold = ptr; return m_pTrashold!=NULL; };
  129. };
  130. #endif //!PRU_SLAVE
  131. //https://www.exler.ru/blog/kak-vernut-staryy-interfeys-facebook.htm
  132. #endif