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.

243 lines
5.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __OBJECT_MASTBAUM_HEADERS__
  2. #define __OBJECT_MASTBAUM_HEADERS__
  3. #include "../../alg/lgs/mask.h"
  4. #include "../../data/net/clientPort.h"
  5. #include "../../data/protocol/protocolLGS.h"
  6. #include "../../hardware/soc/general/3DLRF.h"
  7. #include "../base/basicDualThread.h"
  8. #include "../base/basicEventHeap.h"
  9. #include "../base/basicLogCollection.h"
  10. #include "../base/basicMutex.h"
  11. #include "../base/basicObject.h"
  12. #include "../base/basicPosition.h"
  13. #include "../base/basicSettingsProvider.h"
  14. #include <stdint.h>
  15. #include <WinSock2.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. {
  34. E_LGS_DATA_INTEGRITY_FLAG ErrorOpStatus;
  35. E_LGS_CMD ErrorOpCode;
  36. E_LGS_CMD CurrentOperation;
  37. E_LGS_CMD PendingOperation;
  38. E_LGS_STAGE ComStatus;
  39. E_LGS_STAGE Status;
  40. uint8_t DoneByPercents;
  41. bool ProgressIsActive;
  42. } DEVICE_STATUS, *PDEVICE_STATUS;
  43. class objectMASTBAUM : public basicObject, basicDualThread
  44. {
  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 objectMASTBAUM(config_setting_t * Settings = NULL, bool Master = true);
  94. ~objectMASTBAUM();
  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. {
  106. return &m_sDeviceSoftNFO;
  107. }
  108. E_LGS_CMD getCurrentCMD(void)
  109. {
  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. {
  118. E_LGS_STAGE tVal;
  119. m_mStatusMutex.lock();
  120. tVal = m_sDeviceStatus.Status;
  121. m_mStatusMutex.unlock();
  122. return tVal;
  123. }
  124. PLGS_PARAMETERS getSettings(void)
  125. {
  126. return m_pLGS_PARAMETERS;
  127. }
  128. CSTR getHost(void)
  129. {
  130. return m_pHost;
  131. }
  132. int getPort(void)
  133. {
  134. return m_nPort;
  135. }
  136. bool getDeviceStatus(DEVICE_STATUS & STAT);
  137. ShadowMask * getMask(void)
  138. {
  139. return m_pShadow;
  140. }
  141. bool setHost(CSTR Host);
  142. bool setPort(int Port);
  143. bool setSettings(PLGS_PARAMETERS Params);
  144. bool isMaster(void)
  145. {
  146. return m_bIsMaster;
  147. }
  148. bool areMasksLoadded(void)
  149. {
  150. if (! m_bMasksAreLoadded)
  151. {
  152. SLEEP(10);
  153. }
  154. return m_bMasksAreLoadded;
  155. }
  156. bool areMasksActive(void)
  157. {
  158. if (m_bMasksAreLoadded)
  159. {
  160. if (m_pShadow != NULL)
  161. {
  162. return m_pShadow->isActive();
  163. };
  164. };
  165. return false;
  166. }
  167. bool isConnected(void)
  168. {
  169. bool tVal;
  170. m_mStatusMutex.lock();
  171. tVal = (m_sDeviceStatus.Status > STG_DISCONNECTED);
  172. m_mStatusMutex.unlock();
  173. return tVal;
  174. }
  175. void attachRadarWidget(GLRadar * ptr)
  176. {
  177. m_pRadarWidget = ptr;
  178. }
  179. void attachMapWidget(RangeMapWidget * ptr)
  180. {
  181. m_pMapWidget = ptr;
  182. }
  183. basicPosition * getPosition(void)
  184. {
  185. return m_pPosition;
  186. }
  187. void updateSettings(void);
  188. // New Order
  189. thresholdNode * grabDataAccess(void);
  190. void releaseDataAccess(void);
  191. bool lastTaskComplete(void);
  192. void cleanLastTaskStatus(void);
  193. };
  194. typedef struct S_SENSOR_INFO
  195. {
  196. uint8_t deviceType;
  197. uint16_t portID;
  198. uint32_t addressIP;
  199. } SENSOR_INFO;
  200. typedef std::vector<objectMASTBAUM *> vectorMBSensors;
  201. #endif