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
6.1 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
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 "objectSystemAnchor.h"
  13. #include "../base/basicSettingsProvider.h"
  14. #include "../../alg/lgs/mask.h"
  15. #include "../../data/net/clientPort.h"
  16. #include "../../data/protocol/protocolLGS.h"
  17. #include "../../hardware/soc/general/3DLRF.h"
  18. #include <stdint.h>
  19. #define LGS_TIMEOUT_COUNT 100
  20. #define LGS_MAX_IDLE_DELAY 40 // x10 msec
  21. #define LGS_MIN_IDLE_DELAY 1 // x10 msec
  22. #define USE_MUTEX true
  23. #define DONT_USE_MUTEX false
  24. #define LGS_SETTINGS_NODE_MASTER "LGS_DEVICE_MASTER"
  25. #define LGS_SETTINGS_NODE_SLAVE "LGS_DEVICE_SLAVE"
  26. #define LGS_SET_FLIP "FLIP_SIZE"
  27. #define LGS_SET_OFFSET "OFFSET_SIZE"
  28. #define LGS_SET_ORDER "ORDER_SIZE"
  29. #define LGS_SET_DELTA "DELTA_SIZE"
  30. #define LGS_SET_SST "SST_SIZE"
  31. #define LGS_SET_ADDRESS "IP_ADDRESS"
  32. #define LGS_SET_PORT "IP_PORT"
  33. class GLRadar;
  34. class RangeMapWidget;
  35. typedef struct S_DEVICE_STATUS{
  36. E_LGS_DATA_INTEGRITY_FLAG ErrorOpStatus;
  37. E_LGS_CMD ErrorOpCode;
  38. E_LGS_CMD CurrentOperation;
  39. E_LGS_CMD PendingOperation;
  40. E_LGS_STAGE ComStatus;
  41. E_LGS_STAGE Status;
  42. uint8_t DoneByPercents;
  43. bool ProgressIsActive;
  44. } DEVICE_STATUS, *PDEVICE_STATUS;
  45. class objectLGS : public basicObject, basicDualThread, protocolLGS_CLIENT{
  46. private:
  47. basicLogCollection * m_pLog;
  48. basicEventHeap * m_pEventHeap;
  49. config_setting_t * m_pSettings;
  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. TARGET_DATA * prepareTargetData(CLIENT_EVENT* CE);
  89. protected:
  90. void m_fThreadAProc(void);
  91. void m_fThreadBProc(void);
  92. bool packetHandler( protocolPackage* Package );
  93. public:
  94. //explicit objectLGS( PLGS_PARAMETERS Settings, basicTransport *Transport);
  95. explicit objectLGS( config_setting_t *Settings = NULL, bool Master = true );
  96. ~objectLGS();
  97. bool create( void );
  98. bool startGetScanData( uint8_t kID = 0, uint32_t *th_zone = NULL );
  99. bool startGetParameters( uint32_t timeout=0 );
  100. bool startUploadMask(void);
  101. bool startDeviceReset( bool FullReset = true );
  102. bool startStopMotors( void );
  103. bool startStartMotors( void );
  104. bool startMasksStatus(bool Active);
  105. uint8_t getCompelition(void);
  106. SOFTWARE_INFO * getSoftwareInfo(void){
  107. return &m_sDeviceSoftNFO;
  108. };
  109. E_LGS_CMD getCurrentCMD(void){
  110. E_LGS_CMD tVal;
  111. m_mStatusMutex.lock();
  112. tVal = m_sDeviceStatus.CurrentOperation;
  113. m_mStatusMutex.unlock();
  114. return tVal;
  115. };
  116. E_LGS_STAGE getCurrentSTG(void){
  117. E_LGS_STAGE tVal;
  118. m_mStatusMutex.lock();
  119. tVal = m_sDeviceStatus.Status;
  120. m_mStatusMutex.unlock();
  121. return tVal;
  122. };
  123. PLGS_PARAMETERS getSettings(void){ return m_pLGS_PARAMETERS; };
  124. CSTR getHost( void ){ return m_pHost; };
  125. int getPort( void ){ return m_nPort; };
  126. bool getDeviceStatus(DEVICE_STATUS &STAT);
  127. ShadowMask * getMask( void ){ return m_pShadow; };
  128. bool setHost( CSTR Host );
  129. bool setPort( int Port );
  130. bool setSettings( PLGS_PARAMETERS Params );
  131. bool isMaster( void ){
  132. return m_bIsMaster;
  133. };
  134. bool areMasksLoadded(void){
  135. if( !m_bMasksAreLoadded ) SLEEP(10);
  136. return m_bMasksAreLoadded;
  137. };
  138. bool areMasksActive( void ){
  139. if( m_bMasksAreLoadded ){
  140. if( m_pShadow!= NULL ){
  141. return m_pShadow->isActive();
  142. };
  143. };
  144. return false;
  145. };
  146. bool isConnected(void){
  147. bool tVal;
  148. m_mStatusMutex.lock();
  149. tVal = (m_sDeviceStatus.Status > STG_DISCONNECTED);
  150. m_mStatusMutex.unlock();
  151. return tVal;
  152. };
  153. void attachRadarWidget( GLRadar *ptr ){ m_pRadarWidget = ptr;};
  154. void attachMapWidget( RangeMapWidget *ptr ){ m_pMapWidget = ptr;};
  155. basicPosition * getPosition(void){ return m_pPosition; };
  156. void updateSettings(void);
  157. // New Order
  158. thresholdNode * grabDataAccess( void );
  159. void releaseDataAccess( void );
  160. bool lastTaskComplete( void );
  161. void cleanLastTaskStatus( void );
  162. };
  163. typedef struct S_SENSOR_INFO{
  164. uint8_t deviceType;
  165. uint16_t portID;
  166. uint32_t addressIP;
  167. }SENSOR_INFO;
  168. typedef std::vector<objectLGS *> vectorSensors;
  169. #endif