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.
 
 
 
 
 
 

417 lines
8.9 KiB

#include "protocolBVMS.h"
#include "../../alg/generic/md5.h"
#define LOG(X) m_pLog->Log("PBVMS", this, X)
#define LOG_ERROR(X) m_pLog->Log("PBVMS", this, _LOG_ERROR, X)
CSTR systemStatusMode[] = {"Operational", "Degraded"};
CSTR systemFaultCode[] = {"Critical", "Warning", "Info"};
CSTR getSHTimeStamp(void){
CSTR RetVal;
#ifdef __linux__
RetVal = (CSTR) malloc(64);
if (RetVal != NULL){
sprintf(RetVal, "%llu", getTimeValue());
};
#else
RetVal = (CSTR) malloc(64);
if (RetVal != NULL){
sprintf(RetVal, "%I64d", getTimeValue());
};
#endif
return RetVal;
}
CSTR protocolBVMS::buildURL(CSTR templ, int dim, CSTR devID){
CSTR RetVal;
char tpl[256];
RetVal = (CSTR) malloc(256);
sprintf(tpl, "http://%s:%d%s", m_pServerIP, m_nServerPort, templ);
sprintf(RetVal, tpl, dim, devID);
return RetVal;
}
CSTR protocolBVMS::buildUniqID(void){
CSTR RetVal;
RetVal = (CSTR) malloc(64);
sprintf(RetVal, "%s", MD5String(getSHTimeStamp()));
return RetVal;
}
protocolBVMS::protocolBVMS( CSTR server, uint16_t port ){
m_pServerIP = strdup( server );
m_nServerPort = port;
}
/*
1.2 GHz
Number of Cores
Quad-Core
Type
Tegra 3
Processor Number
T30SL
Manufacturer
NVIDIA
Verify that you have the following installed on your system
Ubuntu 16.04 LTS (with GCC 5.4)
NVIDIA Display Driver ver. 375
NVIDIA VideoSDK 7.1
cuDNN 6 & TensorRT 2.1
NVIDIA CUDA 8.0
Download the DeepStream 1.0 tar file (below)
Extract the package at the location of your choice
Follow the usage instructions from the Deepstream_User_guide.pdf in the downloaded package.
*/
protocolBVMS::~protocolBVMS()
{
//if (m_pScannerName != NULL)
//{
// free(m_pScannerName);
//}
//if (m_pServerIP != NULL)
//{
// free(m_pServerIP);
//}
}
void protocolBVMS::setScannerName(CSTR Name)
{
//sprintf(m_pScannerName, "%s", Name);
}
void protocolBVMS::setProtocolType(bool DeviceIs3D)
{
// if (DeviceIs3D)
// {
// m_nScannerDimentions = 3;
// }
// else
// {
// m_nScannerDimentions = 2;
// };
}
bool protocolBVMS::buildStatusPackage(unsigned char * Buffer, int & BufferSize, bool Status)
{
if (Buffer != NULL)
{
CSTR tBuf;
tBuf = getSHTimeStamp();
if (tBuf != NULL)
{
if (Status)
{
// sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_STATUS, systemStatusMode[0], tBuf);
}
else
{
// sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_STATUS, systemStatusMode[1], tBuf);
};
BufferSize = strlen((char *) Buffer);
free(tBuf);
return true;
};
};
return false;
}
bool protocolBVMS::buildFaultPackage(unsigned char * Buffer, int & BufferSize, unsigned char Type, CSTR Description)
{
if (Buffer != NULL)
{
CSTR tBuf;
tBuf = getSHTimeStamp();
if (tBuf != NULL)
{
// sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_FAULT, systemFaultCode[Type], tBuf, Description);
BufferSize = strlen((char *) Buffer);
free(tBuf);
return true;
};
};
return false;
}
/*
bool protocolBVMS::buildEvent2DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, int Angle, int Range, int Width)
{
if (Buffer != NULL)
{
CSTR tBuf;
tBuf = getSHTimeStamp();
if (tBuf != NULL)
{
// sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_EVT2D, msgUID, tBuf, targetID, Angle, Range, Width);
BufferSize = strlen((char *) Buffer);
free(tBuf);
return true;
};
};
return false;
}
bool protocolBVMS::buildEvent3DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, int Angle1, int Angle2, int Range)
{
if (Buffer != NULL)
{
CSTR tBuf;
tBuf = getSHTimeStamp();
if (tBuf != NULL)
{
//sprintf((char *) (Buffer + BufferSize), PACKAGE_ENVELOPE_TEMPLATE_EVT3D, msgUID, tBuf, targetID, Angle1, Angle2, Range);
BufferSize = strlen((char *) Buffer);
free(tBuf);
return true;
};
};
return false;
}
*/
bool protocolBVMS::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 protocolBVMS::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 protocolBVMS::Alarm2D(int Angle, int Range, int 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);
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 protocolBVMS::Alarm3D(int Angle1, int Angle2, int 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);
LOG(URL);
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 protocolBVMS::VisibilityChanged(bool Worsened)
{
bool RetVal = false;
char Buffer[1024];
int BufferSize = 0;
CSTR URL;
//URL = buildURL(SERVICE_URL_TEMPLATE_STATUS, m_nScannerDimentions, m_pScannerName);
RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, ! Worsened);
if (URL != NULL)
{
RetVal = issuePost(URL, Buffer, BufferSize);
free(URL);
};
return RetVal;
}
bool protocolBVMS::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);
RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, m_bCurrentStatus);
if (URL != NULL)
{
RetVal = issuePost(URL, Buffer, BufferSize);
free(URL);
};
return RetVal;
}
bool protocolBVMS::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);
RetVal = buildFaultPackage((unsigned char *) Buffer, BufferSize, lvl, Descr);
if (URL != NULL)
{
RetVal = issuePost(URL, Buffer, BufferSize);
free(URL);
};
return RetVal;
}
bool protocolBVMS::StartTimeSynch(void)
{
bool RetVal = false;
char Buffer[1024];
int BufferSize = 0;
CSTR URL = NULL;
//if (! m_bEnabled)
//{
// return false;
//}
//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;
}
bool protocolBVMS::packetHandler(protocolPackage * Package)
{
// LOG("PACKET HANDLER");
//if (! m_bEnabled)
//{
// return false;
//}
if (Package == NULL)
{
return false;
}
if (Package->m_nSize == 0)
{
return false;
}
if (Package->m_pData == NULL)
{
return false;
}
if (Package->m_nCode != 200)
{
return false;
}
/*
try
{
XMLNode node1 = XMLNode::parseString((const char *) Package->m_pData, "root");
if (node1.isEmpty())
{
// char BUBU[128];
// sprintf( BUBU, "The package[%d:%d] XML data is not a valid XML data. Cann't find root element.", strlen(pPackage), Package->m_nSize );
// LOG_ERROR(BUBU);
}
else
{
LOG(node1.getName());
if (strstr(node1.getName(), "ClockSync") != NULL)
{
#ifdef __linux__
unsigned long long t0, t1, t2, t3;
#else
unsigned __int64 t0, t1, t2, t3;
#endif
XMLNode node3 = node1.getChildNode("t0", 0);
XMLNode node4 = node1.getChildNode("t1", 0);
XMLNode node5 = node1.getChildNode("t2", 0);
t3 = getTimeValue();
#ifdef __linux__
t0 = atoll(node3.getText(0));
t1 = atoll(node4.getText(0));
t2 = atoll(node5.getText(0));
#else
t0 = _atoi64(node3.getText(0));
t1 = _atoi64(node4.getText(0));
t2 = _atoi64(node5.getText(0));
#endif
int offset = ((t1 - t0) + (t2 - t3)) / 2;
int latency = (t3 - t0) - (t2 - t1);
int jagajaga = offset + latency;
// if( 0 & correctSHTime( jagajaga ) ){
// LOG("Time is Synced");
// g_iTimeDiff = 0;
// } else {
// LOG_ERROR("Time Sync Unucessfull - Will use DIFF!");
correctSoftTime(jagajaga);
//};
};
};
}
catch (exception e)
{
};
*/
return true;
}
#undef LOG
#undef LOG_ERROR