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.

158 lines
6.8 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 <librdkafka/rdkafkacpp.h>
  14. #include "../../components/base/basicFunctionality.h"
  15. #include "../../components/base/basicLogCollection.h"
  16. #include "../../components/base/basicSettingsProvider.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 protocolInfoStress:public RdKafka::DeliveryReportCb {
  70. private:
  71. basicLogCollection * m_pLog;
  72. config_setting_t * m_pSettings;
  73. //rd_kafka_t * m_pKafka; /* Producer instance handle */
  74. RdKafka::Producer * m_pKafka; /* Producer instance handle */
  75. //rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */
  76. RdKafka::Conf * m_pKafkaConf; /* Temporary configuration object */
  77. CSTR m_pKafkaBrokers;
  78. CSTR m_pKafkaTopicSTR;
  79. RdKafka::Topic * m_pKafkaTopic;
  80. //uint8_t m_bKafkaBrokersCount;
  81. int m_nScannerDimentions;
  82. CSTR m_pScannerName;
  83. CSTR m_pServerIP;
  84. CSTR m_pAccessURL;
  85. bool m_bEnabled;
  86. bool m_bUseSSL;
  87. bool m_bMitigationStatus;
  88. float m_fLon;
  89. float m_fLat;
  90. int m_nServerPort;
  91. bool m_bCurrentStatus;
  92. CSTR buildURL( CSTR templ, int dim, CSTR devID );
  93. CSTR buildUniqID( void );
  94. bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize );
  95. bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath );
  96. bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status );
  97. bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description );
  98. bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width );
  99. bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range );
  100. CSTR assembleStatusData( bool StatusOK );
  101. CSTR assembleFaultData( uint8_t Code, CSTR Desc );
  102. CSTR assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation = 0 );
  103. size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data );
  104. bool issuePost( CSTR URL, CSTR Buffer, int BufferSize );
  105. public:
  106. // Constructor
  107. explicit protocolInfoStress( config_setting_t *Settings = NULL );
  108. //ToDo: change Serial to BaseClass of some kind of socket
  109. //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL );
  110. // Destructor
  111. virtual ~protocolInfoStress();
  112. bool init();
  113. bool Alarm2D( float Angle, float Range, float Width, int ID=0 );
  114. bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 );
  115. bool VisibilityChanged( bool Worsened );
  116. bool StatusUpdate( void );
  117. void SetStatus( bool A ){ m_bCurrentStatus = A; };
  118. bool ErrorReporting( int lvl, CSTR Descr );
  119. bool StartTimeSynch( void );
  120. /* Implementation of RdKafka::DeliveryReportCb */
  121. virtual void dr_cb( RdKafka::Message &message );
  122. #ifdef __linux__
  123. //bool FinishTimeSynch( unsigned long long *tVals );
  124. #else
  125. //bool FinishTimeSynch( unsigned __int64 *tVals );
  126. #endif
  127. bool SetupCallBack( CSTR CallBackPath );
  128. void setProtocolType( bool DeviceIs3D );
  129. void setScannerName( CSTR Name );
  130. void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; };
  131. bool getMitigationStatus(void) { return m_bMitigationStatus; };
  132. };
  133. #ifdef __linux__
  134. unsigned long long getSHTimeValue( void );
  135. #else
  136. unsigned __int64 getSHTimeValue( void );
  137. #endif
  138. #endif