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.

141 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
​
  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. int packetChecker( U8 *Buffer, size_t BufferSize );
  65. protocolPackage *packetExtractor( U8 *Buffer, size_t BufferSize );
  66. inline int FinishUpPackage( U8 *Buffer, size_t Size ){
  67. Buffer[0] = 0xAA;
  68. Buffer[1] = ((Size - 3) >> 8) | SEND_TAG;
  69. Buffer[2] = (Size - 3) & 0xFF;
  70. Buffer[Size] = checksumLGS(Buffer, Size);
  71. return Size + 1;
  72. };
  73. public:
  74. protocolInternalLRF3D();
  75. virtual ~protocolInternalLRF3D();
  76. virtual bool create(){ return protocolParser::create(); };
  77. //uint32_t getStatus();
  78. };
  79. #ifdef PRU_SLAVE
  80. class protocolInternalLRF3D_SLAVE: public protocolInternalLRF3D{
  81. private:
  82. basicLogCollection *m_pLog;
  83. protected:
  84. thresholdNode *m_pThresholds[16]; // 8 - learning 8 - working
  85. basicMutex m_mData;
  86. bool sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx = 0 );
  87. bool sendTargets( void );
  88. bool sendStatus( void );
  89. virtual bool packetHandler( protocolPackage *Package ){ return true; };
  90. public:
  91. protocolInternalLRF3D_SLAVE();
  92. virtual ~protocolInternalLRF3D_SLAVE();
  93. virtual bool create( void );
  94. bool resetChannel(void);
  95. bool setTrasholdData( uint8_t lrf_id, uint32_t *ptr );
  96. bool pushTarget( targetRecord *ptr );
  97. };
  98. #else //!PRU_SLAVE
  99. class protocolInternalLRF3D_MASTER: public protocolInternalLRF3D{
  100. private:
  101. basicLogCollection * m_pLog;
  102. protected:
  103. virtual bool packetHandler( protocolPackage *Package ){ return true; };
  104. basicMutex m_mLastTypeProtector;
  105. TWIN_COMMAND m_bLastPackageType;
  106. thresholdNode * m_pTrashold;
  107. targetRecord m_pTargets[TWI_TARGET_QUEUE_SIZE];
  108. uint8_t m_nTargetCount;
  109. basicMutex m_mTargetProtector;
  110. public:
  111. protocolInternalLRF3D_MASTER();
  112. virtual ~protocolInternalLRF3D_MASTER();
  113. virtual bool create(void);
  114. bool resetChannel(void);
  115. bool ackDataSegment( uint32_t dataIdx = 0 );
  116. bool ackTargets( uint32_t pkgId );
  117. TWIN_COMMAND getLastPackageType( void );
  118. bool requestCurrentSettings( void );
  119. bool requestShadow( void );
  120. bool requestSoftwareVersion(void);
  121. bool requestStatus( void );
  122. bool requestTargets(void);
  123. bool requestTrasholdData( uint8_t lrf_id );
  124. bool sendSoftwareUpdate( uint8_t *ptr );
  125. //bool setTData( targetRecord *ptr ){ m_pTargets = ptr; return m_pTargets!=NULL; };
  126. bool setTHData( thresholdNode *ptr ){ m_pTrashold = ptr; return m_pTrashold!=NULL; };
  127. };
  128. #endif //!PRU_SLAVE
  129. //https://www.exler.ru/blog/kak-vernut-staryy-interfeys-facebook.htm
  130. #endif