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.

148 lines
6.1 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 "/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. CSTR m_pAccessURL;
  77. bool m_bEnabled;
  78. bool m_bUseSSL;
  79. bool m_bMitigationStatus;
  80. float m_fLon;
  81. float m_fLat;
  82. int m_nServerPort;
  83. bool m_bCurrentStatus;
  84. CSTR buildURL( CSTR templ, int dim, CSTR devID );
  85. CSTR buildUniqID( void );
  86. bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize );
  87. bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath );
  88. bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status );
  89. bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description );
  90. bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width );
  91. bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range );
  92. CSTR assembleStatusData( bool StatusOK );
  93. CSTR assembleFaultData( uint8_t Code, CSTR Desc );
  94. CSTR assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation = 0 );
  95. size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data );
  96. protected:
  97. virtual bool packetHandler( protocolPackage *Package );
  98. public:
  99. // Constructor
  100. explicit protocolDefender( config_setting_t *Settings = NULL );
  101. //ToDo: change Serial to BaseClass of some kind of socket
  102. //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL );
  103. // Destructor
  104. virtual ~protocolDefender();
  105. virtual bool init(){ return true; };
  106. bool Alarm2D( float Angle, float Range, float Width, int ID=0 );
  107. bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 );
  108. bool VisibilityChanged( bool Worsened );
  109. bool StatusUpdate( void );
  110. void SetStatus( bool A ){ m_bCurrentStatus = A; };
  111. bool ErrorReporting( int lvl, CSTR Descr );
  112. bool StartTimeSynch( void );
  113. #ifdef __linux__
  114. //bool FinishTimeSynch( unsigned long long *tVals );
  115. #else
  116. //bool FinishTimeSynch( unsigned __int64 *tVals );
  117. #endif
  118. bool SetupCallBack( CSTR CallBackPath );
  119. void setProtocolType( bool DeviceIs3D );
  120. void setScannerName( CSTR Name );
  121. void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; };
  122. bool getMitigationStatus(void) { return m_bMitigationStatus; };
  123. };
  124. #ifdef __linux__
  125. unsigned long long getSHTimeValue( void );
  126. #else
  127. unsigned __int64 getSHTimeValue( void );
  128. #endif
  129. #endif