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.

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