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.

194 lines
5.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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, protocolLGS_CLIENT{
  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. bool packetHandler(protocolPackage* Package);
  92. public:
  93. //explicit objectLGS( PLGS_PARAMETERS Settings, basicTransport *Transport);
  94. explicit objectLGS( config_setting_t *Settings = NULL, bool Master = true );
  95. ~objectLGS();
  96. bool create( void );
  97. bool startGetScanData( uint8_t kID = 0, uint32_t *th_zone = NULL );
  98. bool startGetParameters( uint32_t timeout=0 );
  99. bool startUploadMask(void);
  100. bool startDeviceReset( bool FullReset = true );
  101. bool startStopMotors( void );
  102. bool startStartMotors( void );
  103. bool startMasksStatus(bool Active);
  104. uint8_t getCompelition(void);
  105. SOFTWARE_INFO *getSoftwareInfo(void){
  106. return &m_sDeviceSoftNFO;
  107. };
  108. E_LGS_CMD getCurrentCMD(void){
  109. E_LGS_CMD tVal;
  110. m_mStatusMutex.lock();
  111. tVal = m_sDeviceStatus.CurrentOperation;
  112. m_mStatusMutex.unlock();
  113. return tVal;
  114. };
  115. E_LGS_STAGE getCurrentSTG(void){
  116. E_LGS_STAGE tVal;
  117. m_mStatusMutex.lock();
  118. tVal = m_sDeviceStatus.Status;
  119. m_mStatusMutex.unlock();
  120. return tVal;
  121. };
  122. PLGS_PARAMETERS getSettings(void){ return m_pLGS_PARAMETERS; };
  123. CSTR getHost( void ){ return m_pHost; };
  124. int getPort( void ){ return m_nPort; };
  125. bool getDeviceStatus(DEVICE_STATUS &STAT);
  126. ShadowMask *getMask( void ){ return m_pShadow; };
  127. bool setHost( CSTR Host );
  128. bool setPort( int Port );
  129. bool setSettings( PLGS_PARAMETERS Params );
  130. bool isMaster( void ){
  131. return m_bIsMaster;
  132. };
  133. bool areMasksLoadded(void){
  134. if( !m_bMasksAreLoadded ) SLEEP(10);
  135. return m_bMasksAreLoadded;
  136. };
  137. bool areMasksActive( void ){
  138. if( m_bMasksAreLoadded ){
  139. if( m_pShadow!= NULL ){
  140. return m_pShadow->isActive();
  141. };
  142. };
  143. return false;
  144. };
  145. bool isConnected(void){
  146. bool tVal;
  147. m_mStatusMutex.lock();
  148. tVal = (m_sDeviceStatus.Status > STG_DISCONNECTED);
  149. m_mStatusMutex.unlock();
  150. return tVal;
  151. };
  152. void attachRadarWidget( GLRadar *ptr ){ m_pRadarWidget = ptr;};
  153. void attachMapWidget( RangeMapWidget *ptr ){ m_pMapWidget = ptr;};
  154. basicPosition *getPosition(void){ return m_pPosition; };
  155. void updateSettings(void);
  156. // New Order
  157. thresholdNode *grabDataAccess( void );
  158. void releaseDataAccess( void );
  159. bool lastTaskComplete( void );
  160. void cleanLastTaskStatus( void );
  161. };
  162. typedef struct S_SENSOR_INFO{
  163. uint8_t deviceType;
  164. uint16_t portID;
  165. uint32_t addressIP;
  166. }SENSOR_INFO;
  167. typedef std::vector<objectLGS *> vectorSensors;
  168. #endif