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.

247 lines
5.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __OBJECT_LGS_HEADERS__
  2. #define __OBJECT_LGS_HEADERS__
  3. #ifndef __linux__
  4. #include <WinSock2.h>
  5. #endif
  6. #include "../../alg/lgs/mask.h"
  7. #include "../../data/net/clientPort.h"
  8. #include "../../data/protocol/protocolLGS.h"
  9. #include "../../hardware/soc/general/3DLRF.h"
  10. #include "../base/basicDualThread.h"
  11. #include "../base/basicEventHeap.h"
  12. #include "../base/basicLogCollection.h"
  13. #include "../base/basicMutex.h"
  14. #include "../base/basicObject.h"
  15. #include "../base/basicPosition.h"
  16. #include "../base/basicSettingsProvider.h"
  17. #include "objectSystemAnchor.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. {
  37. E_LGS_DATA_INTEGRITY_FLAG ErrorOpStatus;
  38. E_LGS_CMD ErrorOpCode;
  39. E_LGS_CMD CurrentOperation;
  40. E_LGS_CMD PendingOperation;
  41. E_LGS_STAGE ComStatus;
  42. E_LGS_STAGE Status;
  43. uint8_t DoneByPercents;
  44. bool ProgressIsActive;
  45. } DEVICE_STATUS, *PDEVICE_STATUS;
  46. class objectLGS : public basicObject, basicDualThread, protocolLGS_CLIENT
  47. {
  48. private:
  49. basicLogCollection * m_pLog;
  50. basicEventHeap * m_pEventHeap;
  51. config_setting_t * m_pSettings;
  52. clientPort * m_pTransport;
  53. CSTR m_pHost;
  54. int m_nPort;
  55. PLGS_PARAMETERS m_pLGS_PARAMETERS;
  56. E_CLIENT_WORK_MODE m_eWorkMode;
  57. DEVICE_STATUS m_sDeviceStatus;
  58. SOFTWARE_INFO m_sDeviceSoftNFO;
  59. // bool m_bGetParamBusyFlag;
  60. // bool m_bDeviceIsSynched;
  61. bool m_bTransportStatus;
  62. bool m_bMasksAreLoadded;
  63. bool m_bIsMaster;
  64. int m_nBusyCounter;
  65. int m_nIdleCounter;
  66. int m_nIdleTarget;
  67. basicMutex m_mPackageMutex;
  68. basicMutex m_mStatusMutex;
  69. basicMutex m_mDataMutex;
  70. basicPosition * m_pPosition;
  71. thresholdNode * m_pThresholdData;
  72. uint32_t m_nFullBorderDataIndex;
  73. uint8_t m_nFullBorderKernelIndex;
  74. GLRadar * m_pRadarWidget;
  75. RangeMapWidget * m_pMapWidget;
  76. uint8_t m_nDevicePolyCount;
  77. uint8_t m_nCurrentPolyID;
  78. ShadowMask * m_pShadow;
  79. bool setOperation(E_LGS_CMD opCode, bool fNOW = false);
  80. bool forceOperation(E_LGS_CMD opCode);
  81. void setCompelition(uint8_t Perc);
  82. E_LGS_CMD getOperation(void);
  83. void promoteOperation(void);
  84. void completeOperation(bool success = true);
  85. void cleanOperation(void);
  86. void comSetIdle(bool useMutex = true);
  87. void comSetBusy(bool useMutex = true);
  88. bool comIsIdle(void);
  89. void cleanDataTH(void);
  90. TARGET_DATA * prepareTargetData(CLIENT_EVENT * CE);
  91. protected:
  92. void m_fThreadAProc(void);
  93. void m_fThreadBProc(void);
  94. bool packetHandler(protocolPackage * Package);
  95. public:
  96. // explicit objectLGS( PLGS_PARAMETERS Settings, basicTransport *Transport);
  97. explicit objectLGS(config_setting_t * Settings = NULL, bool Master = true);
  98. ~objectLGS();
  99. bool create(void);
  100. bool startGetScanData(uint8_t kID = 0, uint32_t * th_zone = NULL);
  101. bool startGetParameters(uint32_t timeout = 0);
  102. bool startUploadMask(void);
  103. bool startDeviceReset(bool FullReset = true);
  104. bool startStopMotors(void);
  105. bool startStartMotors(void);
  106. bool startMasksStatus(bool Active);
  107. uint8_t getCompelition(void);
  108. SOFTWARE_INFO * getSoftwareInfo(void)
  109. {
  110. return &m_sDeviceSoftNFO;
  111. }
  112. E_LGS_CMD getCurrentCMD(void)
  113. {
  114. E_LGS_CMD tVal;
  115. m_mStatusMutex.lock();
  116. tVal = m_sDeviceStatus.CurrentOperation;
  117. m_mStatusMutex.unlock();
  118. return tVal;
  119. }
  120. E_LGS_STAGE getCurrentSTG(void)
  121. {
  122. E_LGS_STAGE tVal;
  123. m_mStatusMutex.lock();
  124. tVal = m_sDeviceStatus.Status;
  125. m_mStatusMutex.unlock();
  126. return tVal;
  127. }
  128. PLGS_PARAMETERS getSettings(void)
  129. {
  130. return m_pLGS_PARAMETERS;
  131. }
  132. CSTR getHost(void)
  133. {
  134. return m_pHost;
  135. }
  136. int getPort(void)
  137. {
  138. return m_nPort;
  139. }
  140. bool getDeviceStatus(DEVICE_STATUS & STAT);
  141. ShadowMask * getMask(void)
  142. {
  143. return m_pShadow;
  144. }
  145. bool setHost(CSTR Host);
  146. bool setPort(int Port);
  147. bool setSettings(PLGS_PARAMETERS Params);
  148. bool isMaster(void)
  149. {
  150. return m_bIsMaster;
  151. }
  152. bool areMasksLoadded(void)
  153. {
  154. if (! m_bMasksAreLoadded)
  155. {
  156. SLEEP(10);
  157. }
  158. return m_bMasksAreLoadded;
  159. }
  160. bool areMasksActive(void)
  161. {
  162. if (m_bMasksAreLoadded)
  163. {
  164. if (m_pShadow != NULL)
  165. {
  166. return m_pShadow->isActive();
  167. };
  168. };
  169. return false;
  170. }
  171. bool isConnected(void)
  172. {
  173. bool tVal;
  174. m_mStatusMutex.lock();
  175. tVal = (m_sDeviceStatus.Status > STG_DISCONNECTED);
  176. m_mStatusMutex.unlock();
  177. return tVal;
  178. }
  179. void attachRadarWidget(GLRadar * ptr)
  180. {
  181. m_pRadarWidget = ptr;
  182. }
  183. void attachMapWidget(RangeMapWidget * ptr)
  184. {
  185. m_pMapWidget = ptr;
  186. }
  187. basicPosition * getPosition(void)
  188. {
  189. return m_pPosition;
  190. }
  191. void updateSettings(void);
  192. // New Order
  193. thresholdNode * grabDataAccess(void);
  194. void releaseDataAccess(void);
  195. bool lastTaskComplete(void);
  196. void cleanLastTaskStatus(void);
  197. };
  198. typedef struct S_SENSOR_INFO
  199. {
  200. uint8_t deviceType;
  201. uint16_t portID;
  202. uint32_t addressIP;
  203. } SENSOR_INFO;
  204. typedef std::vector<objectLGS *> vectorSensors;
  205. #endif