|
|
|
@ -23,11 +23,14 @@ argusKafkaModule::argusKafkaModule( uint32_t ModuleID ): argusKernelModule( Modu |
|
|
|
|
|
|
|
argusKafkaModule::~argusKafkaModule(){ |
|
|
|
|
|
|
|
m_bEnabled = false; |
|
|
|
|
|
|
|
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 ){ |
|
|
|
@ -45,17 +48,55 @@ argusKafkaModule::~argusKafkaModule(){ |
|
|
|
}; |
|
|
|
/* Periodical Job Handler */ |
|
|
|
void argusKafkaModule::m_fThreadProc( void ){ |
|
|
|
#ifdef SIMULATOR
|
|
|
|
float sim_Az = 0.f; |
|
|
|
float sim_El = 20.f; |
|
|
|
float sim_Ran = 80.35f; |
|
|
|
float tr_Az_step = 0.3f; |
|
|
|
uint32_t src = 128; |
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Pereodical Jobs Started"); |
|
|
|
#endif
|
|
|
|
m_bThreadStatus = TH_WORKING; |
|
|
|
if( !m_bEnabled ) m_bThreadStatus = TH_ENDED; |
|
|
|
if( !m_bEnabled ) { |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Module is Disabled!"); |
|
|
|
#endif
|
|
|
|
}; |
|
|
|
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 ) );
|
|
|
|
sim_Az += tr_Az_step; |
|
|
|
#ifdef SIMULATOR
|
|
|
|
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 ){ |
|
|
|
CSTR tpl; |
|
|
|
CSTR ts; |
|
|
|
CSTR uuid; |
|
|
|
char AZ[10]; |
|
|
|
char EL[10]; |
|
|
|
char RN[10]; |
|
|
|
sprintf( AZ, "%.3f", sim_Az); |
|
|
|
sprintf( EL, "%.3f", sim_El); |
|
|
|
sprintf( RN, "%.3f", sim_Ran); |
|
|
|
uuid = getUniqID_UUID(); |
|
|
|
ts = getTimeStamp(); |
|
|
|
tpl = buildTemplate( m_pEvtTemplates[i][j]->tpl, src, ts, uuid, AZ, RN, EL ); |
|
|
|
if( tpl ) { |
|
|
|
m_pProtocol->issuePost( m_pEvtTemplates[i][j]->topic, tpl, strlen( tpl ) ); |
|
|
|
free( tpl ); |
|
|
|
}; |
|
|
|
if( uuid ) free( uuid ); |
|
|
|
if( ts ) free( ts ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
#endif
|
|
|
|
}; |
|
|
|
/* No need for time Sync
|
|
|
|
if( m_llTicks % 350 == 0 ) { // each 35 seconds
|
|
|
|
@ -68,14 +109,18 @@ void argusKafkaModule::m_fThreadProc( void ){ |
|
|
|
}; |
|
|
|
|
|
|
|
bool argusKafkaModule::startService(){ |
|
|
|
if(! m_bEnabled) return false; |
|
|
|
if(!m_bEnabled) return false; |
|
|
|
if( reloadSettings() ) { |
|
|
|
if( m_pSettings!= NULL ){ |
|
|
|
m_pProtocol = new protocolKAFKA( m_pSettings ); |
|
|
|
if( m_pProtocol->init() ){ |
|
|
|
// No need pereodical jobs
|
|
|
|
//return init();
|
|
|
|
// No need pereodical jobs unless SIMULATOR
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
LOG("Start PJ"); |
|
|
|
return init(); |
|
|
|
#else
|
|
|
|
return true; |
|
|
|
#endif
|
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -135,46 +180,47 @@ CSTR argusKafkaModule::buildTemplate( |
|
|
|
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 ); |
|
|
|
char sid[64]; |
|
|
|
if( tpl ) { |
|
|
|
sprintf( sid, "%d", source_id ); |
|
|
|
ct1 = strReplace( tpl, KAFKA_TPL_SUBST_ID, sid ); |
|
|
|
if( ct1 ) { |
|
|
|
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_TS, ts ); |
|
|
|
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; |
|
|
|
}; |
|
|
|
}; |
|
|
|
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 ct1; |
|
|
|
}; |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
}; |
|
|
|
|
|
|
|
|