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.

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