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.

126 lines
4.9 KiB

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