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.
884 lines
22 KiB
884 lines
22 KiB
#include "protocolInfoStress.h"
|
|
|
|
#include "../../alg/generic/md5.h"
|
|
#include "../json/json_tool.h"
|
|
|
|
#include <json/reader.h>
|
|
#include <json/value.h>
|
|
#include <json/writer.h>
|
|
#include <strings.h>
|
|
// https://il.iherb.com/pr/KAL-Blood-Sugar-Defense-60-Tablets/70138
|
|
|
|
#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 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, "INFOSTRESS_CONNECTION");
|
|
m_pKafka = NULL;
|
|
m_pKafkaBrokerSTR = (CSTR) malloc(CLOG);
|
|
if (m_pKafkaBrokerSTR == NULL)
|
|
{
|
|
return;
|
|
}
|
|
memset(m_pKafkaBrokerSTR, 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;
|
|
m_bEnabled = false;
|
|
m_bEnableStatus = false;
|
|
|
|
if (m_pSettings != NULL)
|
|
{
|
|
int intVar;
|
|
double floatVar;
|
|
config_setting_t * pSetting;
|
|
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("SSL 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_bool(m_pSettings, "ENABLE_STATUS_REPORT", &intVar))
|
|
{
|
|
intVar = m_bEnableStatus = false;
|
|
LOG("Status Report DISABLED[default]");
|
|
pSetting = config_setting_add(m_pSettings, "ENABLE_STATUS_REPORT", CONFIG_TYPE_BOOL);
|
|
config_setting_set_bool(pSetting, intVar);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
}
|
|
else
|
|
{
|
|
m_bEnableStatus = (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, "KAFKA_BROKER_IP", (const char **) &m_pServerIP))
|
|
{
|
|
strncpy(m_pServerIP, "192.168.200.204", 16);
|
|
LOG(m_pServerIP);
|
|
pSetting = config_setting_add(m_pSettings, "KAFKA_BROKER_IP", CONFIG_TYPE_STRING);
|
|
config_setting_set_string(pSetting, m_pServerIP);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
LOG(m_pServerIP);
|
|
if (! config_setting_lookup_int(m_pSettings, "KAFKA_BROKER_PORT", &m_nServerPort))
|
|
{
|
|
m_nServerPort = 80;
|
|
pSetting = config_setting_add(m_pSettings, "KAFKA_BROKER_PORT", CONFIG_TYPE_INT);
|
|
config_setting_set_int(pSetting, m_nServerPort);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
sprintf(m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort);
|
|
LOG(m_pKafkaBrokerSTR);
|
|
if (! config_setting_lookup_string(m_pSettings, "KAFKA_TOPIC", (const char **) &m_pKafkaTopicSTR))
|
|
{
|
|
strncpy(m_pKafkaTopicSTR, DFSL_INFOSTRESS_DEFAULT_KAFKA_TOPIC, CTEXT);
|
|
pSetting = config_setting_add(m_pSettings, "KAFKA_TOPIC", CONFIG_TYPE_STRING);
|
|
config_setting_set_string(pSetting, m_pKafkaTopicSTR);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
LOG(m_pKafkaTopicSTR);
|
|
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()
|
|
{
|
|
m_bEnabled = false;
|
|
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..");
|
|
m_pKafka->flush(3000 /* wait for max 3 seconds */);
|
|
/* If the output queue is still not empty there is an issue
|
|
* with producing messages to the clusters. */
|
|
if (m_pKafka->outq_len() > 0)
|
|
{
|
|
LOG_ERROR("Some messages are not delivered!");
|
|
}
|
|
delete m_pKafka;
|
|
};
|
|
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()
|
|
{
|
|
RdKafka::Conf * tProducerConf;
|
|
RdKafka::Conf * tTopicConf;
|
|
|
|
std::string tBuffer;
|
|
std::string brokers = m_pKafkaBrokerSTR;
|
|
std::string topic = m_pKafkaTopicSTR;
|
|
|
|
LOG("Begin Init");
|
|
if (strlen(m_pKafkaBrokerSTR) == 0)
|
|
{
|
|
LOG_ERROR("No Kafka Brokers are defined!");
|
|
return false;
|
|
};
|
|
tProducerConf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
|
|
if (tProducerConf == NULL)
|
|
{
|
|
LOG_ERROR("Eror Creating Producer Conf!");
|
|
return false;
|
|
};
|
|
LOG("RdKafka::Conf::CONF_GLOBAL Created");
|
|
tTopicConf = RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC);
|
|
if (tTopicConf == NULL)
|
|
{
|
|
LOG_ERROR("Eror Creating Topic Conf!");
|
|
delete(tProducerConf);
|
|
tProducerConf = NULL;
|
|
return false;
|
|
};
|
|
LOG("RdKafka::Conf::CONF_TOPIC Created");
|
|
|
|
if (tProducerConf->set("bootstrap.servers", brokers, tBuffer) != RdKafka::Conf::CONF_OK)
|
|
{
|
|
LOG_ERROR(tBuffer.c_str());
|
|
delete(tProducerConf);
|
|
delete(tTopicConf);
|
|
tProducerConf = NULL;
|
|
tTopicConf = NULL;
|
|
return false;
|
|
};
|
|
LOG("bootstrap.servers is SET");
|
|
|
|
if (tProducerConf->set("metadata.broker.list", brokers, tBuffer) != RdKafka::Conf::CONF_OK)
|
|
{
|
|
LOG_ERROR(tBuffer.c_str());
|
|
delete(tProducerConf);
|
|
delete(tTopicConf);
|
|
tProducerConf = NULL;
|
|
tTopicConf = NULL;
|
|
return false;
|
|
};
|
|
LOG("metadata.broker.list is SET");
|
|
/* 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(). */
|
|
// tProducerConf->set("queue.buffering.max.ms", "100", tBuffer );
|
|
// tProducerConf->set("socket.blocking.max.ms", "100", tBuffer );
|
|
if (tProducerConf->set("dr_cb", this, tBuffer) != RdKafka::Conf::CONF_OK)
|
|
{
|
|
LOG_ERROR(tBuffer.c_str());
|
|
delete(tProducerConf);
|
|
delete(tTopicConf);
|
|
tProducerConf = NULL;
|
|
tTopicConf = NULL;
|
|
return false;
|
|
};
|
|
LOG("dr_cb is SET");
|
|
if (tProducerConf->set("default_topic_conf", tTopicConf, tBuffer) != RdKafka::Conf::CONF_OK)
|
|
{
|
|
LOG_ERROR(tBuffer.c_str());
|
|
delete(tProducerConf);
|
|
delete(tTopicConf);
|
|
tProducerConf = NULL;
|
|
tTopicConf = NULL;
|
|
return false;
|
|
};
|
|
LOG("default_topic_conf is SET");
|
|
/*
|
|
* 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 = RdKafka::Producer::create(tProducerConf, tBuffer);
|
|
if (m_pKafka == NULL)
|
|
{
|
|
LOG_ERROR(tBuffer.c_str());
|
|
delete(tProducerConf);
|
|
delete(tTopicConf);
|
|
tProducerConf = NULL;
|
|
tTopicConf = NULL;
|
|
return false;
|
|
};
|
|
LOG("RdKafka::Producer Created");
|
|
m_pKafkaTopic = RdKafka::Topic::create(m_pKafka, topic, tTopicConf, tBuffer);
|
|
if (m_pKafkaTopic == NULL)
|
|
{
|
|
LOG_ERROR(tBuffer.c_str());
|
|
delete(tProducerConf);
|
|
delete(tTopicConf);
|
|
tProducerConf = NULL;
|
|
tTopicConf = NULL;
|
|
return false;
|
|
};
|
|
LOG("RdKafka::Topic Created");
|
|
delete(tProducerConf);
|
|
delete(tTopicConf);
|
|
tProducerConf = NULL;
|
|
tTopicConf = NULL;
|
|
LOG("INIT Complete");
|
|
m_bEnabled = true;
|
|
return true;
|
|
}
|
|
|
|
bool protocolInfoStress::issuePost(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;
|
|
LOG_ERROR("Failed to produce to topic");
|
|
if (err == RdKafka::ERR__QUEUE_FULL)
|
|
{
|
|
LOG("Internal queue is 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 Queued 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(100);
|
|
// uint8_t cnt = 100;
|
|
// while ( cnt && m_pKafka->outq_len() > 0) {
|
|
// LOG("Wait ...");
|
|
// cnt--;
|
|
// m_pKafka->poll(100);
|
|
// };
|
|
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 = getTimeStamp();
|
|
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 = getTimeStamp();
|
|
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(bool is3D, int targetID, int Range, int Width, int Azimuth, int Elevation)
|
|
{
|
|
CSTR RetVal = NULL;
|
|
RetVal = (CSTR) malloc(CLOG);
|
|
if (RetVal != NULL)
|
|
{
|
|
CSTR TIME_STAMP = NULL;
|
|
TIME_STAMP = getTStr();
|
|
if (TIME_STAMP != NULL)
|
|
{
|
|
char tID[64];
|
|
float Az;
|
|
float Ra;
|
|
sprintf(tID, "%s", MD5String(TIME_STAMP));
|
|
free(TIME_STAMP);
|
|
Ra = Range;
|
|
Az = Azimuth;
|
|
if (is3D)
|
|
{
|
|
float El;
|
|
El = Elevation;
|
|
sprintf(RetVal, PACKAGE_INFOSTRESS_DATA_3D, tID, m_pScannerName, Az, El, Ra);
|
|
}
|
|
else
|
|
{
|
|
sprintf(RetVal, PACKAGE_INFOSTRESS_DATA_2D, tID, m_pScannerName, Az, Ra, Width);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
free(RetVal);
|
|
RetVal = NULL;
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
static uint32_t INFOSTRESS_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 = getTimeStamp();
|
|
INFOSTRESS_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(false, targetID, Range, Width, Angle, 0);
|
|
if (tBuf != NULL)
|
|
{
|
|
BufferSize = strlen(tBuf);
|
|
strncpy((char *) Buffer, tBuf, BufferSize);
|
|
Buffer[BufferSize] = (char) 0;
|
|
#ifdef DEBUG
|
|
LOG((CSTR) Buffer);
|
|
#endif
|
|
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(true, targetID, Range, 0, Angle1, Angle2);
|
|
if (tBuf != NULL)
|
|
{
|
|
BufferSize = strlen(tBuf);
|
|
strncpy((char *) Buffer, tBuf, BufferSize);
|
|
Buffer[BufferSize] = (char) 0;
|
|
#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 UID;
|
|
if (! m_bEnabled)
|
|
{
|
|
return false;
|
|
}
|
|
UID = getUniqID_MD5();
|
|
if (UID != NULL)
|
|
{
|
|
RetVal = buildEvent2DPackage((unsigned char *) Buffer, BufferSize, UID, ID, Angle, Range, Width);
|
|
RetVal = issuePost(Buffer, BufferSize);
|
|
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 UID;
|
|
if (! m_bEnabled)
|
|
{
|
|
return false;
|
|
}
|
|
UID = getUniqID_MD5();
|
|
if (UID != NULL)
|
|
{
|
|
RetVal = buildEvent3DPackage((unsigned char *) Buffer, BufferSize, UID, ID, Angle1, Angle2, Range);
|
|
RetVal = issuePost(Buffer, BufferSize);
|
|
free(UID);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
bool protocolInfoStress::VisibilityChanged(bool Worsened)
|
|
{
|
|
if (! m_bEnableStatus)
|
|
{
|
|
return true;
|
|
}
|
|
bool RetVal = false;
|
|
char Buffer[1024];
|
|
int BufferSize = 0;
|
|
if (! m_bEnabled)
|
|
{
|
|
return false;
|
|
}
|
|
RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, ! Worsened);
|
|
RetVal = issuePost(Buffer, BufferSize);
|
|
return RetVal;
|
|
}
|
|
|
|
bool protocolInfoStress::StatusUpdate(void)
|
|
{
|
|
if (! m_bEnableStatus)
|
|
{
|
|
return true;
|
|
}
|
|
bool RetVal = false;
|
|
char Buffer[1024];
|
|
int BufferSize = 0;
|
|
if (! m_bEnabled)
|
|
{
|
|
return false;
|
|
}
|
|
RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, m_bCurrentStatus);
|
|
RetVal = issuePost(Buffer, BufferSize);
|
|
return RetVal;
|
|
}
|
|
|
|
bool protocolInfoStress::ErrorReporting(int lvl, CSTR Descr)
|
|
{
|
|
if (! m_bEnableStatus)
|
|
{
|
|
return true;
|
|
}
|
|
bool RetVal = false;
|
|
char Buffer[1024];
|
|
int BufferSize = 0;
|
|
if (! m_bEnabled)
|
|
{
|
|
return false;
|
|
}
|
|
RetVal = buildFaultPackage((unsigned char *) Buffer, BufferSize, lvl, Descr);
|
|
RetVal = issuePost(Buffer, BufferSize);
|
|
return RetVal;
|
|
}
|
|
|
|
bool protocolInfoStress::StartTimeSynch(void)
|
|
{
|
|
if (! m_bEnableStatus)
|
|
{
|
|
return true;
|
|
}
|
|
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
|