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.
252 lines
8.0 KiB
252 lines
8.0 KiB
#include "rgooseKafkaModule.h"
|
|
#include "../hardware/soc/general/3DLRF.h"
|
|
|
|
#define LOG( X ) argusKernelModule::m_pLog->Log( "KM", this, X )
|
|
|
|
#ifdef DEBUG
|
|
#define LOG_ERROR( X ) {\
|
|
char _tBfrErrMSG2w34[256];\
|
|
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
|
|
argusKernelModule::m_pLog->Log( "KM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
|
|
}
|
|
#else
|
|
#define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "KM", this, _LOG_ERROR, X );
|
|
#endif
|
|
|
|
argusKafkaModule::argusKafkaModule( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_KAFKA ){
|
|
m_pProtocol = NULL;
|
|
m_pEvtTemplates = (KAFKA_TEMPLATE***) calloc(EVT_CLASS_COUNT, sizeof(KAFKA_TEMPLATE**));
|
|
if( m_pEvtTemplates!= NULL ) {
|
|
memset( m_pEvtTemplates, 0, EVT_CLASS_COUNT * sizeof(KAFKA_TEMPLATE**));
|
|
} else LOG_ERROR("EVT Templates Memory Allocation Error!");
|
|
};
|
|
|
|
argusKafkaModule::~argusKafkaModule(){
|
|
|
|
waitThreadEnd( true );
|
|
|
|
if( m_pProtocol!= NULL ) {
|
|
delete( m_pProtocol );
|
|
};
|
|
if( m_pEvtTemplates!= NULL ) {
|
|
for(int i=0; i < EVT_CLASS_COUNT; i++ ) {
|
|
if( m_pEvtTemplates[i] != NULL ){
|
|
for( int j=0; j< EVT_COUNT; j++ ) {
|
|
if( m_pEvtTemplates[i][j] != NULL ){
|
|
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl );
|
|
free( m_pEvtTemplates[i][j] );
|
|
};
|
|
};
|
|
free( m_pEvtTemplates[i] );
|
|
};
|
|
};
|
|
free( m_pEvtTemplates );
|
|
};
|
|
};
|
|
/* Periodical Job Handler */
|
|
void argusKafkaModule::m_fThreadProc( void ){
|
|
m_bThreadStatus = TH_WORKING;
|
|
while( m_bThreadStatus < TH_ENDED ) {
|
|
m_llTicks ++;//= getMilliseconds();
|
|
if( m_llTicks % 20 == 0 ) { // each 2 seconds
|
|
//m_pProtocol->StatusUpdate();
|
|
//m_lCycleCounter == 0;
|
|
//char tBuff[256];
|
|
//sprintf(tBuff,"MY MESSAGE %dd", m_llTicks );
|
|
//LOG( tBuff );
|
|
//m_pProtocol->issuePost( "My_TEST_TOPIC", tBuff, strlen( tBuff ) );
|
|
};
|
|
/* No need for time Sync
|
|
if( m_llTicks % 350 == 0 ) { // each 35 seconds
|
|
StartTimeSynch();
|
|
//m_lCycleCounter == 0;
|
|
};
|
|
*/
|
|
SLEEP(100);
|
|
};
|
|
};
|
|
|
|
bool argusKafkaModule::startService(){
|
|
if( reloadSettings() ) {
|
|
if( m_pSettings!= NULL ){
|
|
m_pProtocol = new protocolKAFKA( m_pSettings );
|
|
if( m_pProtocol->init() ){
|
|
// No need pereodical jobs
|
|
//return init();
|
|
return true;
|
|
};
|
|
};
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool argusKafkaModule::stopService(){
|
|
waitThreadEnd( true );
|
|
return true;
|
|
};
|
|
|
|
bool argusKafkaModule::reloadSettings(){
|
|
if( m_pDBC==NULL ) return false;
|
|
m_pSettings = m_pDBC->getSettingsKAFKA( m_nDBAUXID );
|
|
if( m_pSettings != NULL ) {
|
|
if( m_pEvtTemplates != NULL ) {
|
|
// Clear Templates
|
|
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){
|
|
for(int j = 0; j < EVT_COUNT; j++ ){
|
|
if( m_pEvtTemplates[i] != NULL ){
|
|
if( m_pEvtTemplates[i][j] != NULL ){
|
|
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl );
|
|
free( m_pEvtTemplates[i][j] );
|
|
m_pEvtTemplates[i][j] = NULL;
|
|
};
|
|
};
|
|
};
|
|
free( m_pEvtTemplates[i] );
|
|
m_pEvtTemplates[i] = NULL;
|
|
};
|
|
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){
|
|
for(int j = 0; j < EVT_COUNT; j++ ){
|
|
KAFKA_TEMPLATE * tT;
|
|
tT = m_pDBC->getKafkaTemplateForEvent( m_nDBID, i, j );
|
|
if( tT != NULL ) {
|
|
if( m_pEvtTemplates[i]== NULL ) {
|
|
m_pEvtTemplates[i]=(KAFKA_TEMPLATE**)calloc(EVT_COUNT,sizeof(KAFKA_TEMPLATE*));
|
|
memset( m_pEvtTemplates[i], 0, EVT_COUNT * sizeof(KAFKA_TEMPLATE*));
|
|
};
|
|
m_pEvtTemplates[i][j] = tT;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
CSTR argusKafkaModule::buildTemplate(
|
|
CSTR tpl,
|
|
uint32_t source_id,
|
|
CSTR ts,
|
|
CSTR uuid,
|
|
CSTR az,
|
|
CSTR range,
|
|
CSTR el
|
|
){
|
|
CSTR ct1, ct2;
|
|
char tVar[64];
|
|
if( tpl == NULL ) return NULL;
|
|
sprintf( tVar, "%d", source_id );
|
|
ct1 = strReplace( tpl, KAFKA_TPL_SUBST_ID, tVar );
|
|
if( ct1 ) {
|
|
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_TS, ts );
|
|
if( ct2 ) {
|
|
free( ct1 );
|
|
ct1 = ct2;
|
|
};
|
|
if( uuid ){
|
|
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_UUID, uuid );
|
|
if( ct2 ) {
|
|
free( ct1 );
|
|
ct1 = ct2;
|
|
};
|
|
};
|
|
if( az ){
|
|
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_AZ, az );
|
|
if( ct2 ) {
|
|
free( ct1 );
|
|
ct1 = ct2;
|
|
};
|
|
};
|
|
if( range ){
|
|
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_RANGE, range );
|
|
if( ct2 ) {
|
|
free( ct1 );
|
|
ct1 = ct2;
|
|
};
|
|
};
|
|
if( el ){
|
|
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_EL, el );
|
|
if( ct2 ) {
|
|
free( ct1 );
|
|
ct1 = ct2;
|
|
};
|
|
};
|
|
return ct1;
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
void argusKafkaModule::dispatchEvent( basicEvent *Evt ){
|
|
#ifdef DEBUG
|
|
LOG( "EVT DISPATCHER");
|
|
#endif
|
|
if( Evt == NULL ) {
|
|
LOG( "Evt NULL");
|
|
return;
|
|
};
|
|
if( m_pEvtTemplates[ Evt->m_eClass ]!= NULL ) {
|
|
// We have defined Channel for that class Events
|
|
#ifdef DEBUG
|
|
char tBuffer[256];
|
|
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType );
|
|
LOG( tBuffer );
|
|
#endif
|
|
// Skip Event Handling by flags
|
|
if( !m_bEvtFlags[ Evt->m_eType ] ) return;
|
|
// Hadle Event
|
|
CSTR tDATA;
|
|
if( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ] != NULL ) {
|
|
CLIENT_EVENT *tCEVT;
|
|
tCEVT = ( CLIENT_EVENT *) Evt->m_pEvtData;
|
|
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl,
|
|
Evt->m_nSourceUID,
|
|
getUniqID_MD5()
|
|
);
|
|
|
|
if( tDATA!= NULL ) {
|
|
m_pProtocol->issuePost( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->topic, tDATA, strlen( tDATA ) );
|
|
};
|
|
};
|
|
/*
|
|
switch( Evt->m_eType ) {
|
|
case EVT_TARGET_1D:
|
|
case EVT_TARGET_2D_WHITE:
|
|
case EVT_TARGET_2D_BLACK:
|
|
case EVT_TARGET_3D_WHITE:
|
|
case EVT_TARGET_3D_BLACK:{
|
|
CLIENT_EVENT *tCEVT;
|
|
tCEVT = ( CLIENT_EVENT *) Evt->m_pEvtData;
|
|
if( tCEVT != NULL ){
|
|
float Az, El;
|
|
uint32_t cRange;
|
|
cRange = (uint32_t)(((float) tCEVT->range ) * 0.0732421875f ) ; // To meters
|
|
#ifdef PRU_SLAVE
|
|
make3Ddeg( tCEVT->th_id, Az, El, false );
|
|
#else
|
|
make3Ddeg( tCEVT->th_id, Az, El, true );
|
|
#endif
|
|
m_pProtocol->Alarm3D( (int)Az, (int)El, cRange , tCEVT->k_id );
|
|
};
|
|
};
|
|
break;
|
|
case EVT_ERROR:
|
|
m_pProtocol->SetStatus( false );
|
|
break;
|
|
case EVT_SCAN:
|
|
//StatusUpdate();
|
|
//break;
|
|
case EVT_FLIP:
|
|
m_pProtocol->SetStatus( true );
|
|
//StatusUpdate();
|
|
break;
|
|
case EVT_COMMAND:
|
|
break;
|
|
default:
|
|
LOG_ERROR("Unknown Event!");
|
|
};
|
|
*/
|
|
};
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|