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.

150 lines
6.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_INFOSTRESS_HEADER__
  2. #define __PROTOCOL_INFOSTRESS_HEADER__
  3. #ifdef __linux__
  4. #include <features.h>
  5. #endif
  6. #include <time.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <sys/types.h>
  10. #include <sys/timeb.h>
  11. #include <string>
  12. #include <librdkafka/rdkafka.h>
  13. #include "../../components/base/basicFunctionality.h"
  14. #include "../../components/base/basicLogCollection.h"
  15. #include "../../components/base/basicSettingsProvider.h"
  16. #define PROTOCOL_TYPE_3D true
  17. #define PROTOCOL_TYPE_2D false
  18. #define SERVICE_URL_TEMPLATE_NOTIFY "/simple-event/notify"
  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 DFSL_HARDWARE_TYPE "SensorNode"
  25. #ifdef PRU_SLAVE
  26. #define DFSL_SOURCE_NAME_ "SLAVE_SENSOR"
  27. #else
  28. #define DFSL_SOURCE_NAME_ "MASTER_SENSOR"
  29. #endif
  30. #define DFSL_CATEGORY_ALARM_3D "dfsl#intruder-drone-detected"
  31. #define DFSL_CATEGORY_ALARM_2D "dfsl#intruder-human-detected"
  32. #define DFSL_CATEGORY_STATUS "dfsl#sensor-status-message"
  33. #define DFSL_CATEGORY_ERROR "dfsl#sensor-error-message"
  34. #define DFRL_PROVIDER_ID "DFSL"
  35. #define DFSL_DATA_TYPE_TARGET "EventLidarTarget"
  36. #define DFSL_DATA_TYPE_STATUS "EventLidarStatus"
  37. #define DFSL_DATA_TYPE_ERROR "EventLidarFault"
  38. //defender-eps.eng.it
  39. #define DFSL_DEFENDER_DEFAULT_URL "/defender-eps/rest/simple-event/notify"
  40. typedef enum E_DEFENDER_CATEGORY{
  41. DC_ERROR = 0,
  42. DC_STATUS = 1,
  43. DC_ALARM = 2,
  44. DC_ALARM_3D = 3
  45. } defenderCategoryTypes;
  46. #define DFSL_DEVICE_ "DFSL Lidar Sensor"
  47. #define DFSL_LOCATION_DTO "{\"point\": [ %2.5f, %2.5f ] }"
  48. #define DFSL_SENSOR_SOURCE_DTO "{ \"type\": \"%s\", \"providerId\": \"%s\", \"sensorNodeId\" : \"%s\" }"
  49. #define DFSL_2D_TARGET_DTO "{ \"AZ\": %d, \"Range\": %d, \"Width\": %d }"
  50. #define DFSL_3D_TARGET_DTO "{ \"AZ\": %d, \"EL\": %d, \"Range\": %d }"
  51. #define DFSL_STATUS_DTO "{ \"created\": \"%s\", \"name\": \"status\", \"value\": \"%s\" }"
  52. #define DFSL_ERROR_DTO "{ \"created\": \"%s\", \"name\": \"code\", \"value\": \"%d\", \"description\": \"%s\" }"
  53. #define DFSL_SE_ENVELOPE "{\"category\": \"%s\",\"severity\": \"%s\"," \
  54. "\"ceiId\": \"ENGIE_CEI\"," \
  55. "\"startTime\": \"%s\",\"endTime\": \"%s\", \"location\": %s, " \
  56. "\"radius\": 0, \"data\": [ %s ]}"
  57. #define PACKAGE_SE_TARGET_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s," \
  58. " \"name\": \"%s\", \"type\": \"%s\", \"lidarSensorEventId\": \"%s\", \"targets\": [%s] }"
  59. #define PACKAGE_SE_STATUS_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s, " \
  60. " \"name\": \"%s\", \"type\": \"%s\", \"lidarSensorEventId\": \"%s\", \"measurements\": [%s] }"
  61. #define OS_SCANNER_NAME_SIZE 128
  62. #define OS_CEP_ADDRESS_SIZE 128
  63. /**
  64. * TODO: Add class description
  65. *
  66. * @author gagua
  67. */
  68. class protocolInfoStress {
  69. private:
  70. basicLogCollection * m_pLog;
  71. config_setting_t * m_pSettings;
  72. rd_kafka_t * m_pKafka; /* Producer instance handle */
  73. rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */
  74. CSTR m_pKafkaBrokers;
  75. //uint8_t m_bKafkaBrokersCount;
  76. int m_nScannerDimentions;
  77. CSTR m_pScannerName;
  78. CSTR m_pServerIP;
  79. CSTR m_pAccessURL;
  80. bool m_bEnabled;
  81. bool m_bUseSSL;
  82. bool m_bMitigationStatus;
  83. float m_fLon;
  84. float m_fLat;
  85. int m_nServerPort;
  86. bool m_bCurrentStatus;
  87. CSTR buildURL( CSTR templ, int dim, CSTR devID );
  88. CSTR buildUniqID( void );
  89. bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize );
  90. bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath );
  91. bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status );
  92. bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description );
  93. bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width );
  94. bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range );
  95. CSTR assembleStatusData( bool StatusOK );
  96. CSTR assembleFaultData( uint8_t Code, CSTR Desc );
  97. CSTR assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation = 0 );
  98. size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data );
  99. public:
  100. // Constructor
  101. explicit protocolInfoStress( config_setting_t *Settings = NULL );
  102. //ToDo: change Serial to BaseClass of some kind of socket
  103. //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL );
  104. // Destructor
  105. virtual ~protocolInfoStress();
  106. bool init();
  107. bool Alarm2D( float Angle, float Range, float Width, int ID=0 );
  108. bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 );
  109. bool VisibilityChanged( bool Worsened );
  110. bool StatusUpdate( void );
  111. void SetStatus( bool A ){ m_bCurrentStatus = A; };
  112. bool ErrorReporting( int lvl, CSTR Descr );
  113. bool StartTimeSynch( void );
  114. #ifdef __linux__
  115. //bool FinishTimeSynch( unsigned long long *tVals );
  116. #else
  117. //bool FinishTimeSynch( unsigned __int64 *tVals );
  118. #endif
  119. bool SetupCallBack( CSTR CallBackPath );
  120. void setProtocolType( bool DeviceIs3D );
  121. void setScannerName( CSTR Name );
  122. void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; };
  123. bool getMitigationStatus(void) { return m_bMitigationStatus; };
  124. };
  125. #ifdef __linux__
  126. unsigned long long getSHTimeValue( void );
  127. #else
  128. unsigned __int64 getSHTimeValue( void );
  129. #endif
  130. #endif