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.

101 lines
4.3 KiB

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