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.

106 lines
4.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_KAFKA_HEADER__
  2. #define __PROTOCOL_KAFKA_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 "protocolEuropeanGeneral.h"
  15. #include "../../components/base/basicLogCollection.h"
  16. #include "../../components/base/basicSettingsProvider.h"
  17. typedef struct S_KAFKA_SETTINGS{
  18. char brocker_addr[128];
  19. uint16_t brocker_port;
  20. }KAFKA_SETTINGS;
  21. /**
  22. * TODO: Add class description
  23. *
  24. * @author gagua
  25. */
  26. class protocolKAFKA:public RdKafka::DeliveryReportCb {
  27. private:
  28. basicLogCollection * m_pLog;
  29. config_setting_t * m_pSettings;
  30. //rd_kafka_t * m_pKafka; /* Producer instance handle */
  31. RdKafka::Producer * m_pKafka; /* Producer instance handle */
  32. //rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */
  33. //RdKafka::Conf * m_pKafkaConf; /* Temporary configuration object */
  34. CSTR m_pKafkaBrokerSTR;
  35. CSTR m_pKafkaTopicSTR;
  36. RdKafka::Topic * m_pKafkaTopic;
  37. bool m_bUseCompression;
  38. bool m_bEnableStatus;
  39. //uint8_t m_bKafkaBrokersCount;
  40. int m_nScannerDimentions;
  41. CSTR m_pScannerName;
  42. CSTR m_pServerIP;
  43. CSTR m_pAccessURL;
  44. bool m_bEnabled;
  45. bool m_bUseSSL;
  46. bool m_bMitigationStatus;
  47. float m_fLon;
  48. float m_fLat;
  49. int m_nServerPort;
  50. bool m_bCurrentStatus;
  51. //CSTR buildURL( CSTR templ, int dim, CSTR devID );
  52. CSTR buildUniqID( void );
  53. bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize );
  54. bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath );
  55. bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status );
  56. bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description );
  57. bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width );
  58. bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range );
  59. CSTR assembleStatusData( bool StatusOK );
  60. CSTR assembleFaultData( uint8_t Code, CSTR Desc );
  61. CSTR assembleTargetData( bool is3D, int targetID, int Range, int Width, int Azimuth, int Elevation = 0 );
  62. size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data );
  63. bool issuePost( CSTR Buffer, int BufferSize );
  64. public:
  65. // Constructor
  66. explicit protocolKAFKA( config_setting_t *Settings );
  67. explicit protocolKAFKA( KAFKA_SETTINGS *Settings );
  68. //ToDo: change Serial to BaseClass of some kind of socket
  69. //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL );
  70. // Destructor
  71. virtual ~protocolKAFKA();
  72. bool init();
  73. bool Alarm2D( float Angle, float Range, float Width, int ID=0 );
  74. bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 );
  75. bool VisibilityChanged( bool Worsened );
  76. bool StatusUpdate( void );
  77. void SetStatus( bool A ){ m_bCurrentStatus = A; };
  78. bool ErrorReporting( int lvl, CSTR Descr );
  79. bool StartTimeSynch( void );
  80. /* Implementation of RdKafka::DeliveryReportCb */
  81. virtual void dr_cb( RdKafka::Message &message );
  82. #ifdef __linux__
  83. //bool FinishTimeSynch( unsigned long long *tVals );
  84. #else
  85. //bool FinishTimeSynch( unsigned __int64 *tVals );
  86. #endif
  87. bool SetupCallBack( CSTR CallBackPath );
  88. void setProtocolType( bool DeviceIs3D );
  89. void setScannerName( CSTR Name );
  90. void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; };
  91. bool getMitigationStatus(void) { return m_bMitigationStatus; };
  92. };
  93. #ifdef __linux__
  94. unsigned long long getSHTimeValue( void );
  95. #else
  96. unsigned __int64 getSHTimeValue( void );
  97. #endif
  98. #endif