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.

191 lines
5.8 KiB

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