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.
 
 
 
 
 
 

896 lines
27 KiB

#include "protocolInfoStress.h"
#include "../../alg/generic/md5.h"
#include "../json/json_tool.h"
#include <strings.h>
#include <json/value.h>
#include <json/writer.h>
#include <json/reader.h>
#define LOG( X ) m_pLog->Log( "InfoStress", this, X )
#define LOGS( X ) basicLogCollection::getInstance()->Log( "InfoStress", NULL, X )
#define LOG_ERROR( X ) m_pLog->Log( "InfoStress", this, _LOG_ERROR, X )
CSTR defenderStatusMode[] = {
"OPERATIONAL",
"DEGRADED"
};
CSTR defenderFaultCode[] = {
"Critical",
"Warning",
"Info"
};
CSTR defenderCategories[] = {
DFSL_CATEGORY_ERROR,
DFSL_CATEGORY_STATUS,
DFSL_CATEGORY_ALARM_2D,
DFSL_CATEGORY_ALARM_3D
};
CSTR defenderTypeDescription[] = {
"Fault Event",
"Status Message",
"Target Detection Event",
"Target Detection Event"
};
CSTR defenderTypeSeverity[] = {
"very-low",
"low",
"medium",
"high",
"very-high"
};
/* Global Time Diff Value to correct Timestamps */
static int g_iTimeDiff = 0;
/**
* number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
*/
//#define EPOCH_DIFF 11644473600LL
#define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
#ifdef __linux__
unsigned long long getSHDTimeValue( void ){
unsigned long long tMilliseconds;
struct timeval tData;
struct timezone tTZ;
tMilliseconds = 0;
tTZ.tz_minuteswest = 0;
tTZ.tz_dsttime = 0;
if( gettimeofday( &tData, &tTZ ) == -1 ){
} else {
tMilliseconds = tData.tv_sec;
tMilliseconds = tMilliseconds *1000;
tMilliseconds += tData.tv_usec / 1000;
};
#else
/*
void TimetToFileTime( time_t t, LPFILETIME pft ){
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD) ll;
pft->dwHighDateTime = ll >>32;
}*/
unsigned __int64 getSHDTimeValue( void ){
unsigned __int64 tMilliseconds;
SYSTEMTIME Ztime;
GetSystemTime(&Ztime);
SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
tMilliseconds -= UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT;
tMilliseconds = tMilliseconds / 10000;
#endif
tMilliseconds += g_iTimeDiff;
return tMilliseconds;
};
CSTR getSHDTimeStamp( void ){
CSTR RetVal = NULL;
time_t rawtime;
uint32_t msec;
struct tm * ptm = NULL;
time ( &rawtime );
ptm = gmtime ( &rawtime );
msec = getSHTimeValue() % 1000;
//2019-03-24T12:32:59.670Z
if( ptm != NULL ) {
RetVal = (CSTR) malloc( 128 );
if( RetVal!=NULL ){
sprintf( RetVal, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
(ptm->tm_year+1900),
(ptm->tm_mon+1),
ptm->tm_mday,
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
msec
);
};
};
return RetVal;
};
bool correctSHDTime( int diff ){
#ifdef __linux__
struct timeval tData;
struct timezone tTZ;
tTZ.tz_minuteswest = 0;
tTZ.tz_dsttime = 0;
if( gettimeofday( &tData, &tTZ ) == -1 ){
return false;
} else {
tData.tv_sec += diff / 1000;
tData.tv_usec += ( diff * 1000 ) % 1000000;
};
if( settimeofday( &tData, &tTZ ) == -1 ){
return false;
};
#else
unsigned __int64 tMilliseconds;
SYSTEMTIME Ztime;
GetSystemTime(&Ztime);
SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
tMilliseconds += diff * 10000;
FileTimeToSystemTime( (FILETIME*) &tMilliseconds, &Ztime );
if( 0 == SetSystemTime(&Ztime) ) return false;
#endif
return true;
};
CSTR protocolInfoStress::buildURL( CSTR templ, int dim, CSTR devID ){
CSTR RetVal;
RetVal = (CSTR) malloc( 256 );
if (RetVal != NULL) {
if (m_bUseSSL) {
sprintf(RetVal, "https://%s:%d%s", m_pServerIP, m_nServerPort, m_pAccessURL);
} else {
sprintf(RetVal, "http://%s:%d%s", m_pServerIP, m_nServerPort, m_pAccessURL);
};
};
return RetVal;
};
CSTR protocolInfoStress::buildUniqID( void ){
CSTR RetVal;
RetVal = (CSTR) malloc(64);
if(RetVal) sprintf( RetVal, "%s", MD5String( getSHDTimeStamp() ) );
return RetVal;
};
/* Default Constructor */
protocolInfoStress::protocolInfoStress( config_setting_t *Settings ){
m_pLog = basicLogCollection::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "INOSTRESS_CONNECTION");
m_pKafka = NULL;
m_pKafkaConf = NULL;
m_pKafkaBrokers = (CSTR)malloc(CLOG);
if( m_pKafkaBrokers == NULL ) return;
memset( m_pKafkaBrokers, 0 , CLOG);
m_pKafkaTopicSTR= (CSTR)malloc(CLOG);
if( m_pKafkaTopicSTR == NULL ) return;
memset( m_pKafkaTopicSTR, 0 , CLOG);
m_pKafkaTopic = NULL;
m_pScannerName = (CSTR)malloc(OS_SCANNER_NAME_SIZE);
if( m_pScannerName == NULL ) return;
memset( m_pScannerName, 0 , OS_SCANNER_NAME_SIZE);
m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE);
if( m_pServerIP == NULL ) return;
memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE);
m_pAccessURL = (CSTR)malloc(CTEXT);
if (m_pAccessURL == NULL) return;
memset(m_pAccessURL, 0, CTEXT);
m_bCurrentStatus = false;
m_bMitigationStatus = false;
if( m_pSettings != NULL ){
int intVar;
double floatVar;
config_setting_t *pSetting;
if (Settings != NULL) {
m_bEnabled = true;
} else {
if (!config_setting_lookup_bool(m_pSettings, "ENABLE", &intVar)) {
intVar = m_bEnabled = false;
LOG("PROTOCOL DISABLED[default]");
pSetting = config_setting_add(m_pSettings, "ENABLE", CONFIG_TYPE_BOOL);
config_setting_set_bool(pSetting, intVar);
basicSettingsProvider::getInstance()->compromise();
} else {
m_bEnabled = (bool)intVar;
};
};
if ( m_bEnabled ) {
if (!config_setting_lookup_float(m_pSettings, "LOCATION_LON", &floatVar)) {
m_fLon = floatVar = 35.0938962;
pSetting = config_setting_add(m_pSettings, "LOCATION_LON", CONFIG_TYPE_FLOAT);
config_setting_set_float(pSetting, floatVar);
basicSettingsProvider::getInstance()->compromise();
} else {
m_fLon = floatVar;
};
if (!config_setting_lookup_float(m_pSettings, "LOCATION_LAT", &floatVar)) {
m_fLat = floatVar = 32.904208;
pSetting = config_setting_add(m_pSettings, "LOCATION_LAT", CONFIG_TYPE_FLOAT);
config_setting_set_float(pSetting, floatVar);
basicSettingsProvider::getInstance()->compromise();
} else {
m_fLat = floatVar;
};
if (!config_setting_lookup_bool(m_pSettings, "USE_SSL", &intVar)) {
intVar = m_bUseSSL = false;
LOG("PROTOCOL DISABLED[default]");
pSetting = config_setting_add(m_pSettings, "USE_SSL", CONFIG_TYPE_BOOL);
config_setting_set_bool(pSetting, intVar);
basicSettingsProvider::getInstance()->compromise();
} else {
m_bUseSSL = (bool)intVar;
};
if (!config_setting_lookup_string(m_pSettings, "SCANNER_NAME", (const char**)&m_pScannerName)) {
strncpy(m_pScannerName, "LRF_2D_001", 64);
LOG(m_pScannerName);
pSetting = config_setting_add(m_pSettings, "SCANNER_NAME", CONFIG_TYPE_STRING);
config_setting_set_string(pSetting, m_pScannerName);
basicSettingsProvider::getInstance()->compromise();
};
if (!config_setting_lookup_int(m_pSettings, "SCANNER_DIMENTIONS", &m_nScannerDimentions)) {
m_nScannerDimentions = 2;
pSetting = config_setting_add(m_pSettings, "SCANNER_DIMENTIONS", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, m_nScannerDimentions);
basicSettingsProvider::getInstance()->compromise();
};
if (!config_setting_lookup_string(m_pSettings, "CEP_IP_ADDRESS", (const char**)&m_pServerIP)) {
strncpy(m_pServerIP, "192.168.200.204", 16);
LOG(m_pServerIP);
pSetting = config_setting_add(m_pSettings, "CEP_IP_ADDRESS", CONFIG_TYPE_STRING);
config_setting_set_string(pSetting, m_pServerIP);
basicSettingsProvider::getInstance()->compromise();
};
LOG(m_pServerIP);
if (!config_setting_lookup_int(m_pSettings, "CEP_IP_PORT", &m_nServerPort)) {
m_nServerPort = 80;
pSetting = config_setting_add(m_pSettings, "CEP_IP_PORT", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, m_nServerPort);
basicSettingsProvider::getInstance()->compromise();
};
if (!config_setting_lookup_string(m_pSettings, "ACCESS_URL", (const char**)&m_pAccessURL)) {
strncpy( m_pAccessURL, DFSL_DEFENDER_DEFAULT_URL, CTEXT );
pSetting = config_setting_add(m_pSettings, "ACCESS_URL", CONFIG_TYPE_STRING);
config_setting_set_string(pSetting, m_pAccessURL);
basicSettingsProvider::getInstance()->compromise();
};
LOG(m_pAccessURL);
};
basicSettingsProvider::getInstance()->validate();
};
};
/**
* @brief Message delivery report callback.
*
* This callback is called exactly once per message, indicating if
* the message was succesfully delivered
* (rkmessage->err == RD_KAFKA_RESP_ERR_NO_ERROR) or permanently
* failed delivery (rkmessage->err != RD_KAFKA_RESP_ERR_NO_ERROR).
*
* The callback is triggered from rd_kafka_poll() and executes on
* the application's thread.
*/
/*
static void dr_msg_cb( rd_kafka_t *rk, const rd_kafka_message_t *rkmessage, void *opaque ){
if (rkmessage->err)
fprintf(stderr, "%% Message delivery failed: %s\n",
rd_kafka_err2str(rkmessage->err));
else
fprintf(stderr,
"%% Message delivered (%zd bytes, "
"partition %"PRId32")\n",
rkmessage->len, rkmessage->partition);
// The rkmessage is destroyed automatically by librdkafka
};
*/
protocolInfoStress::~protocolInfoStress(){
if(m_pKafka!=NULL){
/* Wait for final messages to be delivered or fail.
* rd_kafka_flush() is an abstraction over rd_kafka_poll() which
* waits for all messages to be delivered. */
LOG("Flushing final messages..");
//rd_kafka_flush( m_pKafka, 3000 );
m_pKafka->flush(3*1000 /* wait for max 3 seconds */);
/* If the output queue is still not empty there is an issue
* with producing messages to the clusters. */
//if( rd_kafka_outq_len( m_pKafka ) > 0 ) LOG_ERROR("Some messages are not delivered!");
if (m_pKafka->outq_len() > 0) LOG_ERROR("Some messages are not delivered!");
//rd_kafka_destroy(m_pKafka);
delete m_pKafka;
};
//if(m_pKafkaConf!=NULL)rd_kafka_destroy(m_pKafkaConf);
if(m_pScannerName!=NULL)free(m_pScannerName);
if(m_pServerIP!=NULL)free(m_pServerIP);
if( m_pAccessURL != NULL)free(m_pAccessURL);
};
//https://github.com/edenhill/librdkafka/blob/master/examples/producer.c
//https://github.com/edenhill/librdkafka/blob/master/examples/producer.cpp
void protocolInfoStress::dr_cb( RdKafka::Message &message ){
/* If message.err() is non-zero the message delivery failed permanently
* for the message. */
char tBuffer[1024];
if( message.err() ){
sprintf(tBuffer,"Message delivery failed: %s", message.errstr().c_str() );
LOG_ERROR( tBuffer );
}
#ifdef DEBUG
else {
sprintf(tBuffer,"Message delivered to topic: %s [%d] at offset %d", message.topic_name().c_str(), message.partition(), message.offset() );
LOG( tBuffer );
}
#endif
;
};
bool protocolInfoStress::init(){
//char tBuffer[CLOG];
std::string tBuffer;
std::string brokers = m_pKafkaBrokers;
std::string topic = m_pKafkaTopicSTR;
if( strlen( m_pKafkaBrokers ) == 0 ) {
LOG_ERROR("No Kafka Brokers are defined!");
return false;
};
//m_pKafkaConf = rd_kafka_conf_new();
m_pKafkaConf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
if( m_pKafkaConf == NULL ) {
LOG_ERROR("Eror Creating Kafka Conf!");
return false;
};
if( m_pKafkaConf->set("bootstrap.servers", m_pKafkaBrokers, tBuffer ) != RdKafka::Conf::CONF_OK ){
LOG_ERROR( tBuffer.c_str() );
return false;
};
//if( rd_kafka_conf_set( m_pKafkaConf, "bootstrap.servers", m_pKafkaBrokers, tBuffer, CLOG ) != RD_KAFKA_CONF_OK ){
// LOG_ERROR( tBuffer );
// return false;
//};
/* Set the delivery report callback.
* This callback will be called once per message to inform
* the application if delivery succeeded or failed.
* See dr_msg_cb() above.
* The callback is only triggered from rd_kafka_poll() and
* rd_kafka_flush(). */
//rd_kafka_conf_set_dr_msg_cb( m_pKafkaConf, dr_msg_cb );
if( m_pKafkaConf->set( "dr_cb", this, tBuffer ) != RdKafka::Conf::CONF_OK ){
LOG_ERROR( tBuffer.c_str() );
return false;
};
/*
* Create producer instance.
*
* NOTE: rd_kafka_new() takes ownership of the conf object
* and the application must not reference it again after
* this call.
*/
//m_pKafka = rd_kafka_new( RD_KAFKA_PRODUCER, m_pKafkaConf, tBuffer, CLOG );
m_pKafka = RdKafka::Producer::create( m_pKafkaConf, tBuffer );
if( m_pKafka == NULL ){
LOG_ERROR( tBuffer.c_str() );
return false;
};
m_pKafkaTopic = RdKafka::Topic::create( m_pKafka, topic, m_pKafkaConf, tBuffer );
if( m_pKafkaTopic == NULL ) {
LOG_ERROR( tBuffer.c_str() );
return false;
};
//??
delete( m_pKafkaConf );
m_pKafkaConf = NULL;
return true;
};
bool protocolInfoStress::issuePost( CSTR URL, CSTR Buffer, int BufferSize ){
if( m_pKafka == NULL) return false;
RdKafka::ErrorCode err;
retry:
err = m_pKafka->produce(
m_pKafkaTopic,
RdKafka::Topic::PARTITION_UA,
RdKafka::Producer::RK_MSG_COPY,
(void *)Buffer,
BufferSize,
NULL,
NULL
);
if( err != RdKafka::ERR_NO_ERROR ) {
///std::cerr << "% Failed to produce to topic " << topic << ": " << RdKafka::err2str(err) << std::endl;
if( err == RdKafka::ERR__QUEUE_FULL ){
/* If the internal queue is full, wait for
* messages to be delivered and then retry.
* The internal queue represents both
* messages to be sent and messages that have
* been sent or failed, awaiting their
* delivery report callback to be called.
*
* The internal queue is limited by the
* configuration property
* queue.buffering.max.messages */
m_pKafka->poll(1000/*block for max 1000ms*/);
goto retry;
};
}
#ifdef DEBUG
else {
LOG("MSG OK");
//std::cerr << "% Enqueued message (" << line.size() << " bytes) " << "for topic " << topic << std::endl;
}
#endif
;
/* A producer application should continually serve
* the delivery report queue by calling poll()
* at frequent intervals.
* Either put the poll call in your main loop, or in a
* dedicated thread, or call it after every produce() call.
* Just make sure that poll() is still called
* during periods where you are not producing any messages
* to make sure previously produced messages have their
* delivery report callback served (and any other callbacks
* you register). */
m_pKafka->poll(0);
return true;
};
void protocolInfoStress::setScannerName( CSTR Name ){
sprintf( m_pScannerName, "%s", Name );
};
void protocolInfoStress::setProtocolType( bool DeviceIs3D ){
if( DeviceIs3D ) {
m_nScannerDimentions = 3;
} else {
m_nScannerDimentions = 2;
};
};
CSTR protocolInfoStress::assembleStatusData( bool StatusOK ){
CSTR RetVal = NULL;
CSTR TIME_STAMP;
CSTR tSRC;
CSTR tTARGET;
CSTR tID;
RetVal = (CSTR) malloc(CLOG);
if ( RetVal != NULL ) {
TIME_STAMP = getSHDTimeStamp();
if( TIME_STAMP != NULL ) {
tTARGET = (CSTR) malloc(128);
if( tTARGET!= NULL) {
tSRC = (CSTR) malloc(128);
if( tSRC ) {
tID = (CSTR) malloc(64);
if( tID != NULL ) {
sprintf( tID, "%s", MD5String( TIME_STAMP ) );
sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName );
sprintf( tTARGET, DFSL_STATUS_DTO, TIME_STAMP , defenderStatusMode[((StatusOK)?1:0)] );
sprintf( RetVal,
PACKAGE_SE_STATUS_DATA_ELEMENT,
defenderTypeDescription[DC_STATUS],
TIME_STAMP,
tSRC,
"DFSL_LIDAR_SENSOR_STATUS",
DFSL_DATA_TYPE_STATUS,
tID,
tTARGET
);
free( tID );
free( tSRC );
free( tTARGET );
free( TIME_STAMP );
} else {
free( tSRC );
free( tTARGET );
free( TIME_STAMP );
free( RetVal );
}
} else {
free( tTARGET );
free( TIME_STAMP );
free( RetVal );
};
} else {
free( TIME_STAMP );
free( RetVal );
};
} else {
free( RetVal );
RetVal = NULL;
};
};
return RetVal;
};
CSTR protocolInfoStress::assembleFaultData( uint8_t Code, CSTR Desc ){
CSTR RetVal;
CSTR TIME_STAMP;
CSTR tSRC;
CSTR tTARGET;
CSTR tID;
RetVal = (CSTR) malloc(CLOG);
if ( RetVal != NULL ) {
TIME_STAMP = getSHDTimeStamp();
if( TIME_STAMP != NULL ) {
tTARGET = (CSTR) malloc(128);
if( tTARGET!= NULL) {
tSRC = (CSTR) malloc(128);
if( tSRC ) {
tID = (CSTR) malloc(64);
if( tID != NULL ) {
sprintf( tID, "%s", MD5String( TIME_STAMP ) );
sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName );
sprintf( tTARGET, DFSL_ERROR_DTO, TIME_STAMP, Code, Desc );
sprintf( RetVal,
PACKAGE_SE_STATUS_DATA_ELEMENT,
Desc,
TIME_STAMP,
tSRC,
"DFSL_LIDARE_SENSOR_FAULT_DATA",
DFSL_DATA_TYPE_ERROR,
tID,
tTARGET
);
free( tID );
free( tSRC );
free( tTARGET );
free( TIME_STAMP );
} else {
free( tSRC );
free( tTARGET );
free( TIME_STAMP );
free( RetVal );
}
} else {
free( tTARGET );
free( TIME_STAMP );
free( RetVal );
};
} else {
free( TIME_STAMP );
free( RetVal );
};
} else {
free( RetVal );
RetVal = NULL;
};
};
return RetVal;
};
CSTR protocolInfoStress::assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation ){
CSTR RetVal;
CSTR TIME_STAMP;
CSTR tSRC;
CSTR tTARGET;
CSTR tID;
RetVal = (CSTR) malloc(CLOG);
if ( RetVal != NULL ) {
TIME_STAMP = getSHDTimeStamp();
if( TIME_STAMP != NULL ) {
tTARGET = (CSTR) malloc(128);
if( tTARGET!= NULL) {
tSRC = (CSTR) malloc(128);
if( tSRC ) {
tID = (CSTR) malloc(64);
if( tID != NULL ) {
sprintf( tID, "%s", MD5String( TIME_STAMP ) );
sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName );
if( m_nScannerDimentions > 2 ) {
sprintf( tTARGET, DFSL_3D_TARGET_DTO, Azimuth, Elevation, Range );
} else {
sprintf( tTARGET, DFSL_2D_TARGET_DTO, Azimuth, Range, Width );
};
sprintf( RetVal,
PACKAGE_SE_TARGET_DATA_ELEMENT,
defenderTypeDescription[DC_ALARM],
TIME_STAMP,
tSRC,
"DFSL_TARGET_DATA",
DFSL_DATA_TYPE_TARGET,
tID,
tTARGET
);
free( tID );
free( tSRC );
free( tTARGET );
free( TIME_STAMP );
} else {
free( tSRC );
free( tTARGET );
free( TIME_STAMP );
free( RetVal );
}
} else {
free( tTARGET );
free( TIME_STAMP );
free( RetVal );
};
} else {
free( TIME_STAMP );
free( RetVal );
};
} else {
free( RetVal );
RetVal = NULL;
};
};
return RetVal;
};
static uint32_t DEFENDER_MESSAGE_ID = 0;
size_t protocolInfoStress::assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data ){
char tBuffer[CLOG];
size_t RetVal;
CSTR tBuf;
RetVal = 0;
tBuf = getSHDTimeStamp();
DEFENDER_MESSAGE_ID++;
//memset( tBuffer, 0, CLOG );
if( tBuf != NULL ){
//char ID[64];
switch ( Type ) {
case DC_STATUS:
Severity = 0;
break;
case DC_ERROR:
Severity = 2;
break;
case DC_ALARM:
Severity = 4;
break;
default:
Severity = 2;
};
//sprintf( ID, "%s", MD5String( tBuf ) );
if( (m_nScannerDimentions > 2) && ( Type == DC_ALARM ) ) Type = DC_ALARM_3D;
sprintf( tBuffer,
DFSL_SE_ENVELOPE,
//DEFENDER_MESSAGE_ID,
defenderCategories[Type],
defenderTypeSeverity[Severity],
tBuf, tBuf,
Location,
Data
);
RetVal = strlen(tBuffer);
memcpy( Buffer, tBuffer, RetVal );
Buffer[RetVal] = (char) 0;
free( tBuf );
};
return RetVal;
};
bool protocolInfoStress::buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status ){
if( Buffer!= NULL ){
CSTR tBuf;
tBuf = assembleStatusData( Status );
#ifdef DEBUG
//LOG(tBuf);
#endif
if( tBuf != NULL ) {
char DFSL_LOCATION[256];
sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat );
BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_STATUS, ((Status)?0:2), DFSL_LOCATION, tBuf );
#ifdef DEBUG
LOG((CSTR)Buffer);
#endif
free( tBuf );
return true;
}
};
return false;
};
bool protocolInfoStress::buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description ){
if( Buffer!= NULL ){
CSTR tBuf;
tBuf = assembleFaultData( Type, Description );
if( tBuf != NULL ){
char DFSL_LOCATION[256];
sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat );
BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ERROR, 3, DFSL_LOCATION, tBuf );
free( tBuf );
return true;
};
};
return false;
};
bool protocolInfoStress::buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width){
if( Buffer!= NULL ){
CSTR tBuf;
tBuf = assembleTargetData( targetID, Range, Width, Angle, 0 );
if( tBuf != NULL ){
char DFSL_LOCATION[256];
sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat );
BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ALARM, 3, DFSL_LOCATION, tBuf );
free( tBuf );
return true;
};
};
return false;
};
bool protocolInfoStress::buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range ){
if( Buffer!= NULL ){
CSTR tBuf;
tBuf = assembleTargetData( targetID, Range, 0, Angle1, Angle2 );
#ifdef DEBUG
//LOG(tBuf);
#endif
if( tBuf != NULL ){
char DFSL_LOCATION[256];
sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat );
BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ALARM, 3, DFSL_LOCATION, tBuf );
#ifdef DEBUG
LOG((CSTR)Buffer);
#endif
free( tBuf );
return true;
};
};
return false;
};
bool protocolInfoStress::buildClockSyncPackage( unsigned char *Buffer, int &BufferSize ){
/*if( Buffer!= NULL ){
CSTR tBuf;
tBuf = getSHTimeStamp();
if( tBuf != NULL ){
sprintf(
((char *)(Buffer+BufferSize)),
PACKAGE_ENVELOPE_TEMPLATE_CLOCKSYNC,
tBuf
);
BufferSize = strlen( (char *)Buffer );
free( tBuf );
return true;
};
};*/
return false;
};
bool protocolInfoStress::buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ){
/*if( Buffer!= NULL ){
sprintf(
((char *)(Buffer+BufferSize)),
PACKAGE_ENVELOPE_TEMPLATE_REG_CALL,
CallBackPath
);
BufferSize = strlen( (char *)Buffer );
return true;
};*/
return false;
};
bool protocolInfoStress::Alarm2D( float Angle, float Range, float Width, int ID ){
bool RetVal= false;
char Buffer[1024];
int BufferSize = 0;
CSTR URL;
CSTR UID;
if(!m_bEnabled) return false;
UID = buildUniqID();
if( UID!= NULL ){
URL = buildURL( SERVICE_URL_TEMPLATE_EVENT, m_nScannerDimentions, m_pScannerName );
#ifdef DEBUG
LOG(URL);
#endif
RetVal = buildEvent2DPackage( ( unsigned char *) Buffer, BufferSize, UID, ID, Angle, Range, Width );
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );
free( URL );
};
free( UID );
};
return RetVal;
};
bool protocolInfoStress::Alarm3D( float Angle1, float Angle2, float Range, int ID ){
bool RetVal= false;
char Buffer[1024];
int BufferSize = 0;
CSTR URL;
CSTR UID;
if(!m_bEnabled) return false;
UID = buildUniqID();
if( UID!= NULL ){
URL = buildURL( SERVICE_URL_TEMPLATE_EVENT, m_nScannerDimentions, m_pScannerName );
#ifdef DEBUG
LOG(URL);
#endif
RetVal = buildEvent3DPackage( ( unsigned char *) Buffer, BufferSize, UID, ID, Angle1, Angle2, Range );
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );
free( URL );
};
free( UID );
};
return RetVal;
};
bool protocolInfoStress::VisibilityChanged( bool Worsened ){
bool RetVal= false;
char Buffer[1024];
int BufferSize = 0;
CSTR URL;
if(!m_bEnabled) return false;
URL = buildURL( SERVICE_URL_TEMPLATE_STATUS, m_nScannerDimentions, m_pScannerName );
#ifdef DEBUG
LOG(URL);
#endif
RetVal = buildStatusPackage( ( unsigned char *) Buffer, BufferSize, !Worsened );
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );
free( URL );
};
return RetVal;
};
bool protocolInfoStress::StatusUpdate( void ){
bool RetVal= false;
char Buffer[1024];
int BufferSize = 0;
CSTR URL;
if(!m_bEnabled) return false;
URL = buildURL( SERVICE_URL_TEMPLATE_STATUS, m_nScannerDimentions, m_pScannerName );
#ifdef DEBUG
LOG(URL);
#endif
RetVal = buildStatusPackage( ( unsigned char *) Buffer, BufferSize, m_bCurrentStatus );
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );
free( URL );
};
return RetVal;
};
bool protocolInfoStress::ErrorReporting( int lvl, CSTR Descr ){
bool RetVal= false;
char Buffer[1024];
int BufferSize = 0;
CSTR URL;
if(!m_bEnabled) return false;
URL = buildURL( SERVICE_URL_TEMPLATE_FAULT, m_nScannerDimentions, m_pScannerName );
#ifdef DEBUG
LOG(URL);
#endif
RetVal = buildFaultPackage( ( unsigned char *) Buffer, BufferSize, lvl, Descr );
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );
free( URL );
};
return RetVal;
};
bool protocolInfoStress::StartTimeSynch( void ){
bool RetVal= false;
//LOG("TimeSYnc");
/*char Buffer[1024];
int BufferSize = 0;
CSTR URL = NULL;
URL = buildURL( SERVICE_URL_TEMPLATE_CLOCKSYNC, m_nScannerDimentions, m_pScannerName );
RetVal = buildClockSyncPackage(( unsigned char *) Buffer, BufferSize );
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );
free( URL );
};*/
return RetVal;
};
#undef LOG
#undef LOG_ERROR