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.

143 lines
5.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_DEFENDER_HEADER__
  2. #define __PROTOCOL_DEFENDER_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_NOTIFY "/simple-event/notify"
  20. #define SERVICE_URL_TEMPLATE_STATUS "/sensors/lidar%dd/%s/status"
  21. #define SERVICE_URL_TEMPLATE_FAULT "/sensors/lidar%dd/%s/fault"
  22. #define SERVICE_URL_TEMPLATE_EVENT "/sensors/lidar%dd/%s/event"
  23. #define SERVICE_URL_TEMPLATE_CALLBACK "/sensors/lidar%dd/%s/httpcallback"
  24. #define SERVICE_URL_TEMPLATE_CLOCKSYNC "/sensors/lidar%dd/%s/clocksync"
  25. #define DFSL_HARDWARE_TYPE "SensorNode"
  26. #ifdef PRU_SLAVE
  27. #define DFSL_SOURCE_NAME_ "SLAVE_SENSOR"
  28. #else
  29. #define DFSL_SOURCE_NAME_ "MASTER_SENSOR"
  30. #endif
  31. #define DFSL_CATEGORY_ALARM_3D "dfsl#intruder-drone-detected"
  32. #define DFSL_CATEGORY_ALARM_2D "dfsl#intruder-human-detected"
  33. #define DFSL_CATEGORY_STATUS "dfsl#sensor-status-message"
  34. #define DFSL_CATEGORY_ERROR "dfsl#sensor-error-message"
  35. #define DFRL_PROVIDER_ID "DFSL"
  36. #define DFSL_DATA_TYPE_TARGET "EventLidarTarget"
  37. #define DFSL_DATA_TYPE_STATUS "EventLidarStatus"
  38. #define DFSL_DATA_TYPE_ERROR "EventLidarFault"
  39. //defender-eps.eng.it
  40. #define DFSL_DEFENDER_DEFAULT_URL "http://%s:%d/defender-eps/rest/simple-event/notify"
  41. typedef enum E_DEFENDER_CATEGORY{
  42. DC_ERROR = 0,
  43. DC_STATUS = 1,
  44. DC_ALARM = 2,
  45. DC_ALARM_3D = 3
  46. } defenderCategoryTypes;
  47. #define DFSL_DEVICE_ "DFSL Lidar Sensor"
  48. #define DFSL_LOCATION_DTO "{\"point\": [ %2.5f, %2.5f ] }"
  49. #define DFSL_SENSOR_SOURCE_DTO "{ \"type\": \"%s\", \"providerId\": \"%s\", \"sensorNodeId\" : \"%s\" }"
  50. #define DFSL_2D_TARGET_DTO "{ \"AZ\": %d, \"Range\": %d, \"Width\": %d }"
  51. #define DFSL_3D_TARGET_DTO "{ \"AZ\": %d, \"EL\": %d, \"Range\": %d }"
  52. #define DFSL_STATUS_DTO "{ \"created\": \"%s\", \"name\": \"status\", \"value\": \"%s\" }"
  53. #define DFSL_ERROR_DTO "{ \"created\": \"%s\", \"name\": \"code\", \"value\": \"%d\", \"description\": \"%s\" }"
  54. #define DFSL_SE_ENVELOPE "{\"category\": \"%s\",\"severity\": \"%s\"," \
  55. "\"ceiId\": \"ENGIE_CEI\"," \
  56. "\"startTime\": \"%s\",\"endTime\": \"%s\", \"location\": %s, " \
  57. "\"radius\": 0, \"data\": [ %s ]}"
  58. #define PACKAGE_SE_TARGET_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s," \
  59. " \"name\": \"%s\", \"type\": \"%s\", \"lidarSensorEventId\": \"%s\", \"targets\": [%s] }"
  60. #define PACKAGE_SE_STATUS_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s, " \
  61. " \"name\": \"%s\", \"type\": \"%s\", \"lidarSensorEventId\": \"%s\", \"measurements\": [%s] }"
  62. #define OS_SCANNER_NAME_SIZE 128
  63. #define OS_CEP_ADDRESS_SIZE 128
  64. /**
  65. * TODO: Add class description
  66. *
  67. * @author gagua
  68. */
  69. class protocolDefender : public protocolHTTP {
  70. private:
  71. basicLogCollection *m_pLog;
  72. config_setting_t *m_pSettings;
  73. int m_nScannerDimentions;
  74. CSTR m_pScannerName;
  75. CSTR m_pServerIP;
  76. float m_fLon;
  77. float m_fLat;
  78. int m_nServerPort;
  79. bool m_bCurrentStatus;
  80. CSTR buildURL( CSTR templ, int dim, CSTR devID );
  81. CSTR buildUniqID( void );
  82. bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize );
  83. bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath );
  84. bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status );
  85. bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description );
  86. bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width );
  87. bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range );
  88. CSTR assembleStatusData( bool StatusOK );
  89. CSTR assembleFaultData( uint8_t Code, CSTR Desc );
  90. CSTR assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation = 0 );
  91. size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data );
  92. protected:
  93. virtual bool packetHandler( protocolPackage *Package );
  94. public:
  95. // Constructor
  96. explicit protocolDefender( config_setting_t *Settings = NULL );
  97. //ToDo: change Serial to BaseClass of some kind of socket
  98. //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL );
  99. // Destructor
  100. virtual ~protocolDefender();
  101. virtual bool init(){ return true; };
  102. bool Alarm2D( float Angle, float Range, float Width, int ID=0 );
  103. bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 );
  104. bool VisibilityChanged( bool Worsened );
  105. bool StatusUpdate( void );
  106. void SetStatus( bool A ){ m_bCurrentStatus = A; };
  107. bool ErrorReporting( int lvl, CSTR Descr );
  108. bool StartTimeSynch( void );
  109. #ifdef __linux__
  110. //bool FinishTimeSynch( unsigned long long *tVals );
  111. #else
  112. //bool FinishTimeSynch( unsigned __int64 *tVals );
  113. #endif
  114. bool SetupCallBack( CSTR CallBackPath );
  115. void setProtocolType( bool DeviceIs3D );
  116. void setScannerName( CSTR Name );
  117. void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; };
  118. };
  119. #ifdef __linux__
  120. unsigned long long getSHTimeValue( void );
  121. #else
  122. unsigned __int64 getSHTimeValue( void );
  123. #endif
  124. #endif