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.

193 lines
5.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __OBJECT_LGS_HEADERS__
  2. #define __OBJECT_LGS_HEADERS__
  3. #ifndef __linux__
  4. #include <WinSock2.h>
  5. #endif
  6. #include "../base/basicObject.h"
  7. #include "../base/basicMutex.h"
  8. #include "../base/basicDualThread.h"
  9. #include "../base/basicLogCollection.h"
  10. #include "../base/basicEventHeap.h"
  11. #include "../base/basicPosition.h"
  12. #include "../base/basicSettingsProvider.h"
  13. #include "../../alg/lgs/mask.h"
  14. #include "../../data/net/clientPort.h"
  15. #include "../../data/protocol/protocolLGS.h"
  16. #include "../../hardware/soc/general/3DLRF.h"
  17. #include <stdint.h>
  18. #define LGS_TIMEOUT_COUNT 100
  19. #define LGS_MAX_IDLE_DELAY 40 // x10 msec
  20. #define LGS_MIN_IDLE_DELAY 1 // x10 msec
  21. #define USE_MUTEX true
  22. #define DONT_USE_MUTEX false
  23. #define LGS_SETTINGS_NODE_MASTER "LGS_DEVICE_MASTER"
  24. #define LGS_SETTINGS_NODE_SLAVE "LGS_DEVICE_SLAVE"
  25. #define LGS_SET_FLIP "FLIP_SIZE"
  26. #define LGS_SET_OFFSET "OFFSET_SIZE"
  27. #define LGS_SET_ORDER "ORDER_SIZE"
  28. #define LGS_SET_DELTA "DELTA_SIZE"
  29. #define LGS_SET_SST "SST_SIZE"
  30. #define LGS_SET_ADDRESS "IP_ADDRESS"
  31. #define LGS_SET_PORT "IP_PORT"
  32. class GLRadar;
  33. class RangeMapWidget;
  34. typedef struct S_DEVICE_STATUS{
  35. E_LGS_DATA_INTEGRITY_FLAG ErrorOpStatus;
  36. E_LGS_CMD ErrorOpCode;
  37. E_LGS_CMD CurrentOperation;
  38. E_LGS_CMD PendingOperation;
  39. E_LGS_STAGE ComStatus;
  40. E_LGS_STAGE Status;
  41. uint8_t DoneByPercents;
  42. bool ProgressIsActive;
  43. } DEVICE_STATUS, *PDEVICE_STATUS;
  44. class objectLGS : public basicObject, basicDualThread{
  45. private:
  46. basicLogCollection *m_pLog;
  47. basicEventHeap *m_pEventHeap;
  48. config_setting_t *m_pSettings;
  49. protocolLGS_CLIENT *m_oProtocol;
  50. clientPort *m_pTransport;
  51. CSTR m_pHost;
  52. int m_nPort;
  53. PLGS_PARAMETERS m_pLGS_PARAMETERS;
  54. E_CLIENT_WORK_MODE m_eWorkMode;
  55. DEVICE_STATUS m_sDeviceStatus;
  56. SOFTWARE_INFO m_sDeviceSoftNFO;
  57. //bool m_bGetParamBusyFlag;
  58. //bool m_bDeviceIsSynched;
  59. bool m_bTransportStatus;
  60. bool m_bMasksAreLoadded;
  61. bool m_bIsMaster;
  62. int m_nBusyCounter;
  63. int m_nIdleCounter;
  64. int m_nIdleTarget;
  65. basicMutex m_mPackageMutex;
  66. basicMutex m_mStatusMutex;
  67. basicMutex m_mDataMutex;
  68. basicPosition *m_pPosition;
  69. thresholdNode *m_pThresholdData;
  70. uint32_t m_nFullBorderDataIndex;
  71. uint8_t m_nFullBorderKernelIndex;
  72. GLRadar *m_pRadarWidget;
  73. RangeMapWidget *m_pMapWidget;
  74. uint8_t m_nDevicePolyCount;
  75. uint8_t m_nCurrentPolyID;
  76. ShadowMask *m_pShadow;
  77. bool setOperation( E_LGS_CMD opCode, bool fNOW = false );
  78. bool forceOperation( E_LGS_CMD opCode );
  79. void setCompelition( uint8_t Perc );
  80. E_LGS_CMD getOperation( void );
  81. void promoteOperation( void );
  82. void completeOperation( bool success = true );
  83. void cleanOperation( void );
  84. void comSetIdle( bool useMutex = true );
  85. void comSetBusy( bool useMutex = true );
  86. bool comIsIdle( void );
  87. void cleanDataTH( void );
  88. protected:
  89. void m_fThreadAProc(void);
  90. void m_fThreadBProc(void);
  91. public:
  92. //explicit objectLGS( PLGS_PARAMETERS Settings, basicTransport *Transport);
  93. explicit objectLGS( config_setting_t *Settings = NULL, bool Master = true );
  94. ~objectLGS();
  95. bool create( void );
  96. bool startGetScanData( uint8_t kID = 0, uint32_t *th_zone = NULL );
  97. bool startGetParameters( uint32_t timeout=0 );
  98. bool startUploadMask(void);
  99. bool startDeviceReset( bool FullReset = true );
  100. bool startStopMotors( void );
  101. bool startStartMotors( void );
  102. bool startMasksStatus(bool Active);
  103. uint8_t getCompelition(void);
  104. SOFTWARE_INFO *getSoftwareInfo(void){
  105. return &m_sDeviceSoftNFO;
  106. };
  107. E_LGS_CMD getCurrentCMD(void){
  108. E_LGS_CMD tVal;
  109. m_mStatusMutex.lock();
  110. tVal = m_sDeviceStatus.CurrentOperation;
  111. m_mStatusMutex.unlock();
  112. return tVal;
  113. };
  114. E_LGS_STAGE getCurrentSTG(void){
  115. E_LGS_STAGE tVal;
  116. m_mStatusMutex.lock();
  117. tVal = m_sDeviceStatus.Status;
  118. m_mStatusMutex.unlock();
  119. return tVal;
  120. };
  121. PLGS_PARAMETERS getSettings(void){ return m_pLGS_PARAMETERS; };
  122. CSTR getHost( void ){ return m_pHost; };
  123. int getPort( void ){ return m_nPort; };
  124. bool getDeviceStatus(DEVICE_STATUS &STAT);
  125. ShadowMask *getMask( void ){ return m_pShadow; };
  126. bool setHost( CSTR Host );
  127. bool setPort( int Port );
  128. bool setSettings( PLGS_PARAMETERS Params );
  129. bool isMaster( void ){
  130. return m_bIsMaster;
  131. };
  132. bool areMasksLoadded(void){
  133. if( !m_bMasksAreLoadded ) SLEEP(10);
  134. return m_bMasksAreLoadded;
  135. };
  136. bool areMasksActive( void ){
  137. if( m_bMasksAreLoadded ){
  138. if( m_pShadow!= NULL ){
  139. return m_pShadow->isActive();
  140. };
  141. };
  142. return false;
  143. };
  144. bool isConnected(void){
  145. bool tVal;
  146. m_mStatusMutex.lock();
  147. tVal = (m_sDeviceStatus.Status > STG_DISCONNECTED);
  148. m_mStatusMutex.unlock();
  149. return tVal;
  150. };
  151. void attachRadarWidget( GLRadar *ptr ){ m_pRadarWidget = ptr;};
  152. void attachMapWidget( RangeMapWidget *ptr ){ m_pMapWidget = ptr;};
  153. basicPosition *getPosition(void){ return m_pPosition; };
  154. void updateSettings(void);
  155. // New Order
  156. thresholdNode *grabDataAccess( void );
  157. void releaseDataAccess( void );
  158. bool lastTaskComplete( void );
  159. void cleanLastTaskStatus( void );
  160. };
  161. typedef struct S_SENSOR_INFO{
  162. uint8_t deviceType;
  163. uint16_t portID;
  164. uint32_t addressIP;
  165. }SENSOR_INFO;
  166. typedef std::vector<objectLGS *> vectorSensors;
  167. #endif