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.

146 lines
5.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_RESTAPI_HEADER__
  2. #define __PROTOCOL_RESTAPI_HEADER__
  3. #ifdef __linux__
  4. #include <features.h>
  5. #endif
  6. #include "../../components/base/basicFunctionality.h"
  7. #include "../../components/base/basicLogCollection.h"
  8. #include "../../components/base/basicSettingsProvider.h"
  9. #include "protocolHTTP.h"
  10. #include "xmlParser.h"
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string>
  14. #include <sys/timeb.h>
  15. #include <sys/types.h>
  16. #include <time.h>
  17. #define PROTOCOL_TYPE_3D true
  18. #define PROTOCOL_TYPE_2D false
  19. #define SERVICE_URL_TEMPLATE_STATUS "/sensors/lidar%dd/%s/status"
  20. #define SERVICE_URL_TEMPLATE_FAULT "/sensors/lidar%dd/%s/fault"
  21. #define SERVICE_URL_TEMPLATE_EVENT "/sensors/lidar%dd/%s/event"
  22. #define SERVICE_URL_TEMPLATE_CALLBACK "/sensors/lidar%dd/%s/httpcallback"
  23. #define SERVICE_URL_TEMPLATE_CLOCKSYNC "/sensors/lidar%dd/%s/clocksync"
  24. #define PACKAGE_ENVELOPE_TEMPLATE_STATUS \
  25. "<lcu:SystemStatus xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
  26. "<lcu:Mode>%s</lcu:Mode>" \
  27. "<lcu:Timestamp>%s</lcu:Timestamp>" \
  28. "</lcu:SystemStatus>"
  29. #define PACKAGE_ENVELOPE_TEMPLATE_FAULT \
  30. "<lcu:FaultDescription xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
  31. "<lcu:Level>%s</lcu:Level>" \
  32. "<lcu:Timestamp>%s</lcu:Timestamp>" \
  33. "<lcu:Description>%s</lcu:Description>" \
  34. "</lcu:FaultDescription>"
  35. #define PACKAGE_ENVELOPE_TEMPLATE_EVT2D \
  36. "<lcu:EventLidar2D xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
  37. "<lcu:UniqueId>%s</lcu:UniqueId>" \
  38. "<lcu:Timestamp>%s</lcu:Timestamp>" \
  39. "<lcu:Target><lcu:Id>%d</lcu:Id>" \
  40. "<lcu:Coordinates><lcu:Azimuth>%d</lcu:Azimuth><lcu:Distance>%d</lcu:Distance></lcu:Coordinates>" \
  41. "<lcu:Width>%d</lcu:Width></lcu:Target>" \
  42. "</lcu:EventLidar2D>"
  43. #define PACKAGE_ENVELOPE_TEMPLATE_EVT3D \
  44. "<lcu:EventLidar3D xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
  45. "<lcu:UniqueId>%s</lcu:UniqueId>" \
  46. "<lcu:Timestamp>%s</lcu:Timestamp>" \
  47. "<lcu:Target><lcu:Id>%d</lcu:Id>" \
  48. "<lcu:Coordinates><lcu:Azimuth>%d</lcu:Azimuth><lcu:Elevation>%d</lcu:Elevation><lcu:Distance>%d</lcu:Distance></lcu:Coordinates>" \
  49. "</lcu:Target>" \
  50. "</lcu:EventLidar3D>"
  51. #define PACKAGE_ENVELOPE_TEMPLATE_REG_CALL \
  52. "<lcu:Callback xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
  53. "<lcu:XAddr>%s</lcu:XAddr>" \
  54. "</lcu:Callback>"
  55. #define PACKAGE_ENVELOPE_TEMPLATE_CLOCKSYNC \
  56. "<lcu:ClockSyncQuery xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
  57. "<lcu:t0>%s</lcu:t0>" \
  58. "</lcu:ClockSyncQuery>"
  59. #define OS_SCANNER_NAME_SIZE 128
  60. #define OS_LCU_ADDRESS_SIZE 16
  61. /**
  62. * TODO: Add class description
  63. *
  64. * @author gagua
  65. */
  66. class protocolREST : public protocolHTTP
  67. {
  68. private:
  69. basicLogCollection * m_pLog;
  70. config_setting_t * m_pSettings;
  71. bool m_bEnabled;
  72. int m_nScannerDimentions;
  73. CSTR m_pScannerName;
  74. CSTR m_pServerIP;
  75. int m_nServerPort;
  76. bool m_bCurrentStatus;
  77. CSTR buildURL(CSTR templ, int dim, CSTR devID);
  78. CSTR buildUniqID(void);
  79. bool buildClockSyncPackage(unsigned char * Buffer, int & BufferSize);
  80. bool buildCallBackPackage(unsigned char * Buffer, int & BufferSize, CSTR CallBackPath);
  81. bool buildStatusPackage(unsigned char * Buffer, int & BufferSize, bool Status);
  82. bool buildFaultPackage(unsigned char * Buffer, int & BufferSize, unsigned char Type, CSTR Description);
  83. bool buildEvent2DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, int Angle, int Range, int Width);
  84. bool buildEvent3DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, int Angle1, int Angle2, int Range);
  85. protected:
  86. virtual bool packetHandler(protocolPackage * Package);
  87. public:
  88. // Constructor
  89. explicit protocolREST(config_setting_t * Settings = NULL);
  90. // ToDo: change Serial to BaseClass of some kind of socket
  91. // protocolREST( clientPort *SocketTransport, config_setting_t *Settings = NULL );
  92. // Destructor
  93. virtual ~protocolREST();
  94. virtual bool init()
  95. {
  96. return true;
  97. }
  98. bool Alarm2D(int Angle, int Range, int Width, int ID = 0);
  99. bool Alarm3D(int Angle1, int Angle2, int Range, int ID = 0);
  100. bool VisibilityChanged(bool Worsened);
  101. bool StatusUpdate(void);
  102. void SetStatus(bool A)
  103. {
  104. m_bCurrentStatus = A;
  105. }
  106. bool ErrorReporting(int lvl, CSTR Descr);
  107. bool StartTimeSynch(void);
  108. #ifdef __linux__
  109. // bool FinishTimeSynch( unsigned long long *tVals );
  110. #else
  111. // bool FinishTimeSynch( unsigned __int64 *tVals );
  112. #endif
  113. bool SetupCallBack(CSTR CallBackPath);
  114. void setProtocolType(bool DeviceIs3D);
  115. void setScannerName(CSTR Name);
  116. };
  117. #ifdef __linux__
  118. unsigned long long getSHTimeValue(void);
  119. #else
  120. unsigned __int64 getSHTimeValue(void);
  121. #endif
  122. #endif