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.

422 lines
8.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolBVMS.h"
  2. #include "../../alg/generic/md5.h"
  3. #define LOG(X) m_pLog->Log("PBVMS", this, X)
  4. #define LOG_ERROR(X) m_pLog->Log("PBVMS", this, _LOG_ERROR, X)
  5. CSTR systemStatusMode[] = {"Operational", "Degraded"};
  6. CSTR systemFaultCode[] = {"Critical", "Warning", "Info"};
  7. CSTR getSHTimeStamp(void)
  8. {
  9. CSTR RetVal;
  10. #ifdef __linux__
  11. RetVal = (CSTR) malloc(64);
  12. if (RetVal != NULL)
  13. {
  14. sprintf(RetVal, "%llu", getTimeValue());
  15. };
  16. #else
  17. RetVal = (CSTR) malloc(64);
  18. if (RetVal != NULL)
  19. {
  20. sprintf(RetVal, "%I64d", getTimeValue());
  21. };
  22. #endif
  23. return RetVal;
  24. }
  25. CSTR protocolBVMS::buildURL(CSTR templ, int dim, CSTR devID)
  26. {
  27. CSTR RetVal;
  28. char tpl[256];
  29. RetVal = (CSTR) malloc(256);
  30. sprintf(tpl, "http://%s:%d%s", m_pServerIP, m_nServerPort, templ);
  31. sprintf(RetVal, tpl, dim, devID);
  32. return RetVal;
  33. }
  34. CSTR protocolBVMS::buildUniqID(void)
  35. {
  36. CSTR RetVal;
  37. RetVal = (CSTR) malloc(64);
  38. sprintf(RetVal, "%s", MD5String(getSHTimeStamp()));
  39. return RetVal;
  40. }
  41. protocolBVMS::protocolBVMS( CSTR server, uint16_t port ){
  42. m_pServerIP = strdup( server );
  43. m_nServerPort = port;
  44. }
  45. /*
  46. 1.2 GHz
  47. Number of Cores
  48. Quad-Core
  49. Type
  50. Tegra 3
  51. Processor Number
  52. T30SL
  53. Manufacturer
  54. NVIDIA
  55. Verify that you have the following installed on your system
  56. Ubuntu 16.04 LTS (with GCC 5.4)
  57. NVIDIA Display Driver ver. 375
  58. NVIDIA VideoSDK 7.1
  59. cuDNN 6 & TensorRT 2.1
  60. NVIDIA CUDA 8.0
  61. Download the DeepStream 1.0 tar file (below)
  62. Extract the package at the location of your choice
  63. Follow the usage instructions from the Deepstream_User_guide.pdf in the downloaded package.
  64. */
  65. protocolBVMS::~protocolBVMS()
  66. {
  67. //if (m_pScannerName != NULL)
  68. //{
  69. // free(m_pScannerName);
  70. //}
  71. //if (m_pServerIP != NULL)
  72. //{
  73. // free(m_pServerIP);
  74. //}
  75. }
  76. void protocolBVMS::setScannerName(CSTR Name)
  77. {
  78. //sprintf(m_pScannerName, "%s", Name);
  79. }
  80. void protocolBVMS::setProtocolType(bool DeviceIs3D)
  81. {
  82. // if (DeviceIs3D)
  83. // {
  84. // m_nScannerDimentions = 3;
  85. // }
  86. // else
  87. // {
  88. // m_nScannerDimentions = 2;
  89. // };
  90. }
  91. bool protocolBVMS::buildStatusPackage(unsigned char * Buffer, int & BufferSize, bool Status)
  92. {
  93. if (Buffer != NULL)
  94. {
  95. CSTR tBuf;
  96. tBuf = getSHTimeStamp();
  97. if (tBuf != NULL)
  98. {
  99. if (Status)
  100. {
  101. // sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_STATUS, systemStatusMode[0], tBuf);
  102. }
  103. else
  104. {
  105. // sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_STATUS, systemStatusMode[1], tBuf);
  106. };
  107. BufferSize = strlen((char *) Buffer);
  108. free(tBuf);
  109. return true;
  110. };
  111. };
  112. return false;
  113. }
  114. bool protocolBVMS::buildFaultPackage(unsigned char * Buffer, int & BufferSize, unsigned char Type, CSTR Description)
  115. {
  116. if (Buffer != NULL)
  117. {
  118. CSTR tBuf;
  119. tBuf = getSHTimeStamp();
  120. if (tBuf != NULL)
  121. {
  122. // sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_FAULT, systemFaultCode[Type], tBuf, Description);
  123. BufferSize = strlen((char *) Buffer);
  124. free(tBuf);
  125. return true;
  126. };
  127. };
  128. return false;
  129. }
  130. /*
  131. bool protocolBVMS::buildEvent2DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, int Angle, int Range, int Width)
  132. {
  133. if (Buffer != NULL)
  134. {
  135. CSTR tBuf;
  136. tBuf = getSHTimeStamp();
  137. if (tBuf != NULL)
  138. {
  139. // sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_EVT2D, msgUID, tBuf, targetID, Angle, Range, Width);
  140. BufferSize = strlen((char *) Buffer);
  141. free(tBuf);
  142. return true;
  143. };
  144. };
  145. return false;
  146. }
  147. bool protocolBVMS::buildEvent3DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, int Angle1, int Angle2, int Range)
  148. {
  149. if (Buffer != NULL)
  150. {
  151. CSTR tBuf;
  152. tBuf = getSHTimeStamp();
  153. if (tBuf != NULL)
  154. {
  155. //sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_EVT3D, msgUID, tBuf, targetID, Angle1, Angle2, Range);
  156. BufferSize = strlen((char *) Buffer);
  157. free(tBuf);
  158. return true;
  159. };
  160. };
  161. return false;
  162. }
  163. */
  164. bool protocolBVMS::buildClockSyncPackage(unsigned char * Buffer, int & BufferSize)
  165. {
  166. if (Buffer != NULL)
  167. {
  168. CSTR tBuf;
  169. tBuf = getSHTimeStamp();
  170. if (tBuf != NULL)
  171. {
  172. //sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_CLOCKSYNC, tBuf);
  173. BufferSize = strlen((char *) Buffer);
  174. free(tBuf);
  175. return true;
  176. };
  177. };
  178. return false;
  179. }
  180. bool protocolBVMS::buildCallBackPackage(unsigned char * Buffer, int & BufferSize, CSTR CallBackPath)
  181. {
  182. if (Buffer != NULL)
  183. {
  184. //sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_REG_CALL, CallBackPath);
  185. BufferSize = strlen((char *) Buffer);
  186. return true;
  187. };
  188. return false;
  189. }
  190. /*
  191. bool protocolBVMS::Alarm2D(int Angle, int Range, int Width, int ID)
  192. {
  193. bool RetVal = false;
  194. char Buffer[1024];
  195. int BufferSize = 0;
  196. CSTR URL;
  197. CSTR UID;
  198. if (! m_bEnabled)
  199. {
  200. return false;
  201. }
  202. UID = buildUniqID();
  203. if (UID != NULL)
  204. {
  205. //URL = buildURL(SERVICE_URL_TEMPLATE_EVENT, m_nScannerDimentions, m_pScannerName);
  206. RetVal = buildEvent2DPackage((unsigned char *) Buffer, BufferSize, UID, ID, Angle, Range, Width);
  207. if (URL != NULL)
  208. {
  209. RetVal = issuePost(URL, Buffer, BufferSize);
  210. free(URL);
  211. };
  212. free(UID);
  213. };
  214. return RetVal;
  215. }
  216. bool protocolBVMS::Alarm3D(int Angle1, int Angle2, int Range, int ID)
  217. {
  218. bool RetVal = false;
  219. char Buffer[1024];
  220. int BufferSize = 0;
  221. CSTR URL;
  222. CSTR UID;
  223. if (! m_bEnabled)
  224. {
  225. return false;
  226. }
  227. UID = buildUniqID();
  228. if (UID != NULL)
  229. {
  230. //URL = buildURL(SERVICE_URL_TEMPLATE_EVENT, m_nScannerDimentions, m_pScannerName);
  231. LOG(URL);
  232. RetVal = buildEvent3DPackage((unsigned char *) Buffer, BufferSize, UID, ID, Angle1, Angle2, Range);
  233. if (URL != NULL)
  234. {
  235. RetVal = issuePost(URL, Buffer, BufferSize);
  236. free(URL);
  237. };
  238. free(UID);
  239. };
  240. return RetVal;
  241. }
  242. */
  243. bool protocolBVMS::VisibilityChanged(bool Worsened)
  244. {
  245. bool RetVal = false;
  246. char Buffer[1024];
  247. int BufferSize = 0;
  248. CSTR URL;
  249. //URL = buildURL(SERVICE_URL_TEMPLATE_STATUS, m_nScannerDimentions, m_pScannerName);
  250. RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, ! Worsened);
  251. if (URL != NULL)
  252. {
  253. RetVal = issuePost(URL, Buffer, BufferSize);
  254. free(URL);
  255. };
  256. return RetVal;
  257. }
  258. bool protocolBVMS::StatusUpdate(void)
  259. {
  260. bool RetVal = false;
  261. char Buffer[1024];
  262. int BufferSize = 0;
  263. CSTR URL;
  264. //if (! m_bEnabled)
  265. //{
  266. // return false;
  267. //}
  268. //URL = buildURL(SERVICE_URL_TEMPLATE_STATUS, m_nScannerDimentions, m_pScannerName);
  269. RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, m_bCurrentStatus);
  270. if (URL != NULL)
  271. {
  272. RetVal = issuePost(URL, Buffer, BufferSize);
  273. free(URL);
  274. };
  275. return RetVal;
  276. }
  277. bool protocolBVMS::ErrorReporting(int lvl, CSTR Descr)
  278. {
  279. bool RetVal = false;
  280. char Buffer[1024];
  281. int BufferSize = 0;
  282. CSTR URL;
  283. //if (! m_bEnabled)
  284. //{
  285. // return false;
  286. //}
  287. //URL = buildURL(SERVICE_URL_TEMPLATE_FAULT, m_nScannerDimentions, m_pScannerName);
  288. RetVal = buildFaultPackage((unsigned char *) Buffer, BufferSize, lvl, Descr);
  289. if (URL != NULL)
  290. {
  291. RetVal = issuePost(URL, Buffer, BufferSize);
  292. free(URL);
  293. };
  294. return RetVal;
  295. }
  296. bool protocolBVMS::StartTimeSynch(void)
  297. {
  298. bool RetVal = false;
  299. char Buffer[1024];
  300. int BufferSize = 0;
  301. CSTR URL = NULL;
  302. //if (! m_bEnabled)
  303. //{
  304. // return false;
  305. //}
  306. //URL = buildURL(SERVICE_URL_TEMPLATE_CLOCKSYNC, m_nScannerDimentions, m_pScannerName);
  307. RetVal = buildClockSyncPackage((unsigned char *) Buffer, BufferSize);
  308. if (URL != NULL)
  309. {
  310. RetVal = issuePost(URL, Buffer, BufferSize);
  311. free(URL);
  312. };
  313. return RetVal;
  314. }
  315. bool protocolBVMS::packetHandler(protocolPackage * Package)
  316. {
  317. // LOG("PACKET HANDLER");
  318. //if (! m_bEnabled)
  319. //{
  320. // return false;
  321. //}
  322. if (Package == NULL)
  323. {
  324. return false;
  325. }
  326. if (Package->m_nSize == 0)
  327. {
  328. return false;
  329. }
  330. if (Package->m_pData == NULL)
  331. {
  332. return false;
  333. }
  334. if (Package->m_nCode != 200)
  335. {
  336. return false;
  337. }
  338. /*
  339. try
  340. {
  341. XMLNode node1 = XMLNode::parseString((const char *) Package->m_pData, "root");
  342. if (node1.isEmpty())
  343. {
  344. // char BUBU[128];
  345. // sprintf( BUBU, "The package[%d:%d] XML data is not a valid XML data. Cann't find root element.", strlen(pPackage), Package->m_nSize );
  346. // LOG_ERROR(BUBU);
  347. }
  348. else
  349. {
  350. LOG(node1.getName());
  351. if (strstr(node1.getName(), "ClockSync") != NULL)
  352. {
  353. #ifdef __linux__
  354. unsigned long long t0, t1, t2, t3;
  355. #else
  356. unsigned __int64 t0, t1, t2, t3;
  357. #endif
  358. XMLNode node3 = node1.getChildNode("t0", 0);
  359. XMLNode node4 = node1.getChildNode("t1", 0);
  360. XMLNode node5 = node1.getChildNode("t2", 0);
  361. t3 = getTimeValue();
  362. #ifdef __linux__
  363. t0 = atoll(node3.getText(0));
  364. t1 = atoll(node4.getText(0));
  365. t2 = atoll(node5.getText(0));
  366. #else
  367. t0 = _atoi64(node3.getText(0));
  368. t1 = _atoi64(node4.getText(0));
  369. t2 = _atoi64(node5.getText(0));
  370. #endif
  371. int offset = ((t1 - t0) + (t2 - t3)) / 2;
  372. int latency = (t3 - t0) - (t2 - t1);
  373. int jagajaga = offset + latency;
  374. // if( 0 & correctSHTime( jagajaga ) ){
  375. // LOG("Time is Synced");
  376. // g_iTimeDiff = 0;
  377. // } else {
  378. // LOG_ERROR("Time Sync Unucessfull - Will use DIFF!");
  379. correctSoftTime(jagajaga);
  380. //};
  381. };
  382. };
  383. }
  384. catch (exception e)
  385. {
  386. };
  387. */
  388. return true;
  389. }
  390. #undef LOG
  391. #undef LOG_ERROR