Browse Source

Device Connection (Socket) Changed to Linux Way

AGP
poocka 7 years ago
parent
commit
b85b15ea80
  1. 2
      lib/alg/lgs/mask.cpp
  2. 2
      lib/alg/lgs/mask.h
  3. 530
      lib/components/object/objectLGS.cpp
  4. 5
      lib/components/object/objectLGS.h
  5. 29
      lib/data/net/clientPort.cpp
  6. 32
      lib/data/net/transportSocket.cpp
  7. 1
      lib/data/protocol/protocol.cpp
  8. 14
      lib/data/protocol/protocolLGS.cpp
  9. 10
      lib/data/protocol/protocolLGS.h

2
lib/alg/lgs/mask.cpp

@ -6,7 +6,7 @@
ShadowMask::ShadowMask(){
m_pLog = basicLogCollection::getInstance();
m_bActive = false;
#if defined( WIN32 ) || defined( __GUI__ )
#if defined( __linux__ ) && !defined( __GUI__ )
m_pVertexFileName = (CSTR)malloc(256);
m_pRasterFileName = (CSTR)malloc(256);
sprintf( m_pVertexFileName, "masking.dat" );

2
lib/alg/lgs/mask.h

@ -76,6 +76,8 @@ class ShadowMask{
#if defined( WIN32 ) || defined( __GUI__ )
bool loadRastered(CSTR fName = NULL);
bool saveRastered(CSTR fName = NULL);
#endif
#if defined( __linux__ ) && !defined( __GUI__ )
bool saveVertexes(CSTR fName = NULL);
bool loadVertexes(CSTR fName = NULL);
#endif

530
lib/components/object/objectLGS.cpp

@ -15,7 +15,7 @@ inline void make3D( uint32_t sid, float &az, float &el, bool master = true ){
az = ( sid % TH_LINE_NODES ) * 360.f / TH_LINE_NODES;
};
objectLGS::objectLGS(config_setting_t *Settings, bool Master) : basicObject(),
objectLGS::objectLGS(config_setting_t *Settings, bool Master) : basicObject(), basicDualThread(), protocolLGS_CLIENT(),
m_mStatusMutex(),
m_mPackageMutex(),
m_mDataMutex(){
@ -71,9 +71,9 @@ objectLGS::~objectLGS(){
if (m_pTransport != NULL){
delete(m_pTransport);
};
if( m_oProtocol != NULL ){
delete( m_oProtocol );
};
//if( m_oProtocol != NULL ){
// delete( m_oProtocol );
//};
if ( m_pLGS_PARAMETERS != NULL) free(m_pLGS_PARAMETERS);
//OLD THPLACE
cleanDataTH();
@ -152,12 +152,11 @@ bool objectLGS::create( void ){
m_pTransport = new clientPort( m_pHost, m_nPort );
if( m_pTransport!= NULL ){
m_oProtocol = new protocolLGS_CLIENT( m_pTransport, 0 );
if (m_oProtocol != NULL) {
m_oProtocol->create();
init();
return true;
};
//m_oProtocol = new protocolLGS_CLIENT( m_pTransport, 0 );
//if (m_oProtocol != NULL)
if( setTransport(m_pTransport))
if(protocolLGS_CLIENT::create() )
return basicDualThread::init();
};
};
m_eStatus = OS_STATUS_DEAD;
@ -345,7 +344,7 @@ void objectLGS::m_fThreadAProc(void){
if( comIsIdle() ){
switch( m_eWorkMode ){
case CWM_INIT:
if( m_oProtocol->getState() ){
if( getState() ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -354,7 +353,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CWM_INITIAL_PARAM:
if( m_oProtocol->getParameters() ){
if( getParameters() ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -363,7 +362,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CWM_INITIAL_MASKS_INFO:
if( m_oProtocol->getShadowInfo() ){
if( getShadowInfo() ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -372,7 +371,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CWM_INITIAL_MASKS_DATA:
if( m_oProtocol->getShadowPoly( m_nCurrentPolyID ) ){
if( getShadowPoly( m_nCurrentPolyID ) ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -381,7 +380,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CWM_BORDER:
if( m_oProtocol->getDraw( 0, m_nFullBorderKernelIndex ) ){
if( getDraw( 0, m_nFullBorderKernelIndex ) ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -390,7 +389,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CWM_MASK:
if( m_oProtocol->setShadowPoly(NULL) ){
if( setShadowPoly(NULL) ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -401,7 +400,7 @@ void objectLGS::m_fThreadAProc(void){
case CWM_PARAMS:
switch( getOperation() ){
case CMD_GET_PARAMETERS:
if( m_oProtocol->getParameters() ){
if( getParameters() ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -410,7 +409,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CMD_SET_PARAMETERS:
if( m_oProtocol->setParameters( m_pLGS_PARAMETERS )){
if( setParameters( m_pLGS_PARAMETERS )){
comSetBusy();
} else {
completeOperation( false );
@ -425,7 +424,7 @@ void objectLGS::m_fThreadAProc(void){
default:
switch( getOperation() ){
case CMD_RESET:
if( m_oProtocol->doReset()){
if( doReset()){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -434,7 +433,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CMD_FULL_RESET:
if( m_oProtocol->doFullReset()){
if( doFullReset()){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -447,7 +446,7 @@ void objectLGS::m_fThreadAProc(void){
case CMD_FULL_BORDER: m_eWorkMode = CWM_BORDER; break;
case CMD_SET_HZ_POLY: m_eWorkMode = CWM_MASK; break;
case CMD_DHWM_START_MOTORS:
if( m_oProtocol->doStartMotors()){
if( doStartMotors()){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -456,7 +455,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CMD_DHWM_STOP_MOTORS:
if( m_oProtocol->doStopMotors()){
if( doStopMotors()){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -465,7 +464,7 @@ void objectLGS::m_fThreadAProc(void){
};
break;
case CMD_SET_HZ_STATUS:
if (m_oProtocol->setShadowStatus( m_pShadow->isActive(), 0xFF)){
if (setShadowStatus( m_pShadow->isActive(), 0xFF)){
comSetBusy(USE_MUTEX);
} else {
completeOperation(false);
@ -480,7 +479,7 @@ void objectLGS::m_fThreadAProc(void){
SLEEP( 50 );
} else {
m_nIdleCounter = 0;
if( m_oProtocol->getState2() ){
if( getState2() ){
comSetBusy( USE_MUTEX );
} else {
completeOperation( false );
@ -548,7 +547,488 @@ void objectLGS::cleanDataTH( void ){
void objectLGS::releaseDataAccess( void ){
m_mDataMutex.unlock();
};
#ifndef _BABAABBA_
void objectLGS::m_fThreadBProc(void) {
m_bThreadBStatus = TH_ENDED;
};
bool objectLGS::packetHandler(protocolPackage* Package) {
U8* pReceivedPackage = NULL;
size_t nReceivedPackageSize = 0;
bool bPackageIsArived = false;
basicEvent* tEVT;
CLIENT_EVENT* tData;
if( Package == NULL ) return false;
pReceivedPackage = Package->m_pData;
nReceivedPackageSize = Package->m_nSize;
if (pReceivedPackage != NULL) {
uint8_t CUR_CMD;
uint16_t PKG_LEN;
uint8_t index;
uint8_t SUB_LEN;
uint8_t SUB_CMD;
uint16_t Range;
uint32_t Angle;
uint32_t Width;
bool State;
uint8_t Status;
uint8_t Code;
PKG_LEN = ((pReceivedPackage[SIZE_IDX_A] & 0x7F) << 8) | pReceivedPackage[SIZE_IDX_B];
CUR_CMD = pReceivedPackage[CMD_IDX];
SUB_CMD = pReceivedPackage[SUB_CMD_IDX];
m_nBusyCounter = 0;
switch (CUR_CMD) {
case CMD_STATE:
if (SUB_CMD > WM_INIT) {
uint8_t* ptr;
ptr = (uint8_t*)& m_sDeviceSoftNFO;
for (uint8_t i = 0; i < sizeof(SOFTWARE_INFO); i++) ptr[i] = pReceivedPackage[SUB_CMD_IDX + 1 + i];
};
LOG("CMD_STATE");
completeOperation();
break;
case CMD_QUIT:
break;
case CMD_RESET:
LOG("Reset ACK");
completeOperation();
break;
case CMD_FULL_BORDER:
case CMD_BORDER:
LOG("CMD_BORDER");
if (SUB_CMD == BD_ERRORMODE) {
LOG_ERROR("BOARD DATA ERROR!");
m_nFullBorderDataIndex = 0;
completeOperation(false);
}
else if (SUB_CMD == BD_NOTREADY) {
LOG_ERROR("BOARD DATA NOT READY!");
m_nFullBorderDataIndex = 0;
completeOperation(false);
}
else {
uint16_t index = 6;
m_mDataMutex.lock();
while (index < (nReceivedPackageSize - 7) && m_nFullBorderDataIndex < TH_SIZE_NODES) {
m_pThresholdData[m_nFullBorderDataIndex].data = pReceivedPackage[index++];
m_pThresholdData[m_nFullBorderDataIndex].data = (m_pThresholdData[m_nFullBorderDataIndex].data << 8) | pReceivedPackage[index++];
m_pThresholdData[m_nFullBorderDataIndex].data = (m_pThresholdData[m_nFullBorderDataIndex].data << 8) | pReceivedPackage[index++];
m_pThresholdData[m_nFullBorderDataIndex].data = (m_pThresholdData[m_nFullBorderDataIndex].data << 8) | pReceivedPackage[index++];
m_nFullBorderDataIndex++;
};
m_mDataMutex.unlock();
if (m_nFullBorderDataIndex < TH_SIZE_NODES) {
int proc;
proc = (int)(100.f * ((float)m_nFullBorderDataIndex / (float)TH_SIZE_NODES));
setCompelition(proc);
getDraw(m_nFullBorderDataIndex, m_nFullBorderKernelIndex);
comSetBusy(USE_MUTEX);
}
else {
LOG("FINISH GET BOARD DATA");
m_mDataMutex.lock();
//if( m_pThresholdData!= NULL ){
// if( m_nFullBorderDataIndex > 0 ){
// FILE *fd;
// fd = fopen( "test.raw", "wb");
// if( fd!= NULL ){
// fwrite( &m_nFullBorderDataIndex, sizeof(uint32_t), 1, fd );
// fwrite( m_pThresholdData, sizeof( thresholdNode ), m_nFullBorderDataIndex, fd );
// fclose( fd );
// };
// };
//};
m_mDataMutex.unlock();
//m_pMapWidget->updateRanges( (uint32_t *) m_pThresholdData, m_nFullBorderDataIndex );
//m_pRadarWidget->updateRanges( (uint32_t *) m_pThresholdData, m_nFullBorderDataIndex );
completeOperation();
};
};
break;
case CMD_GETFILE:
break;
case CMD_RESTART:
break;
case CMD_GET_PARAMETERS:
case CMD_PARAMETERS:
case CMD_SET_PARAMETERS: {
LOG("Finish Get Params");
if (SUB_CMD == SUB_DATA_INTEGRITY_VALID) {
PLGS_PARAMETERS tParam;
if (m_pLGS_PARAMETERS != NULL) {
tParam = (PLGS_PARAMETERS)(pReceivedPackage + 6);
/*
m_pLGS_PARAMETERS->bSST = tParam->bSST;
for( int index = 0; index < 26; index++ )
m_pLGS_PARAMETERS->flags_binary[index] = tParam->flags_binary[index];
m_pLGS_PARAMETERS->nDelta = tParam->nDelta;
m_pLGS_PARAMETERS->nFlip = tParam->nFlip;
m_pLGS_PARAMETERS->nGPointSamples = tParam->nGPointSamples;
m_pLGS_PARAMETERS->nOffset = tParam->nOffset;
m_pLGS_PARAMETERS->nOrder = tParam->nOrder;
m_pLGS_PARAMETERS->nSun = tParam->nSun;
m_pLGS_PARAMETERS->nWidth = tParam->nWidth;
*/
memcpy(m_pLGS_PARAMETERS, tParam, sizeof(LGS_PARAMETERS));
m_bIsMaster = m_pLGS_PARAMETERS->flags.isMaster;
SLEEP(500);
completeOperation();
}
else completeOperation();
}
else {
LOG_ERROR("Data Integrity Error(on Get Parameters)!");
completeOperation(false);
};
};
break;
case CMD_HZ_INFO: {
LOG("Finish Get HZ INFO");
m_nDevicePolyCount = pReceivedPackage[6];
// Clear Existed Masks
m_pShadow->clear();
if (m_nDevicePolyCount) {
m_pShadow->setActive((SUB_CMD > 0));
}
else {
m_pShadow->setActive(false);
};
completeOperation();
};
break;
case CMD_SET_HZ_POLY: {
LOG("Finish Get HZ POLY");
simplePolygone* tPolygone;
tPolygone = new simplePolygone();
if (tPolygone != NULL) {
tPolygone->count = pReceivedPackage[5];
tPolygone->color[0] = pReceivedPackage[6];
tPolygone->color[1] = pReceivedPackage[7];
tPolygone->color[2] = pReceivedPackage[8];
#ifdef __linux__
tPolygone->points = (simplePoint*)malloc(sizeof(simplePoint) * tPolygone->count);
#else
tPolygone->points = (QPoint*)malloc(sizeof(QPoint) * tPolygone->count);
#endif
if (tPolygone->count && tPolygone->points != NULL) {
uint16_t x, y;
int index = 9;
for (int i = 0; i < tPolygone->count; i++) {
x = pReceivedPackage[index++];
x = (x << 8) | pReceivedPackage[index++];
y = pReceivedPackage[index++];
y = (y << 8) | pReceivedPackage[index++];
tPolygone->points[i].setX(x);
tPolygone->points[i].setY(y);
};
m_pShadow->addPoly(tPolygone);
}
else {
free(tPolygone);
};
};
m_nCurrentPolyID++;
completeOperation();
};
break;
case CMD_SET_HZ_POLY_ACK: {
m_nCurrentPolyID = SUB_CMD;
if (m_nCurrentPolyID < m_pShadow->getPolyCount()) {
simplePolygone* tPoly;
tPoly = m_pShadow->getPoly(m_nCurrentPolyID);
if (tPoly != NULL) {
setShadowPoly(tPoly);
comSetBusy(USE_MUTEX);
}
else {
completeOperation(false);
};
}
else {
LOG("Send RayTraces");
vectorZoneMask VZ;
if (m_pShadow->getZoneMask(VZ)) {
if (setShadowTrace(&VZ)) {
completeOperation();
}
else {
completeOperation(false);
};
}
else {
completeOperation();
};
};
};
break;
case CMD_GET_SERIAL_NUMBER:
break;
case CMD_SET_ADDRESS:
break;
case CMD_GET_SOFTWARE_VERSION:
break;
case CMD_UNSUPPORTED:
break;
case CMD_SET_COMM_SPEED:
break;
case CMD_FULL_RESET:
LOG("Full Reset ACK");
completeOperation();
break;
case CMD_CAMERA:
break;
case CMD_SET_SERIAL_NUMBER:
break;
case CMD_BOARDDATA:
break;
case CMD_GET_CAMERA_PARAMETERS:
break;
case CMD_SET_CAMERA_PARAMETERS:
break;
case CMD_RELAY:
break;
case CMD_GET_RELAY_PARAMETERS:
break;
case CMD_SET_RELAY_PARAMETERS:
break;
case CMD_FS_SUB_PACKET:
break;
case CMD_STATE_2:
m_mStatusMutex.lock();
if (SUB_CMD != m_sDeviceStatus.Status) {
m_sDeviceStatus.Status = (E_LGS_STAGE)SUB_CMD;
switch (m_sDeviceStatus.Status) {
case STG_STUDY: {
m_mStatusMutex.unlock();
basicEvent* tEVT;
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_STUDY, "Device in STUDY mode");
m_pEventHeap->broadcast(tEVT);
break;
};
case STG_REDY: {
m_mStatusMutex.unlock();
basicEvent* tEVT;
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Device in DETECTION mode");
m_pEventHeap->broadcast(tEVT);
break;
};
case STG_BUSY: {
m_mStatusMutex.unlock();
basicEvent* tEVT;
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Device in BUSY mode");
m_pEventHeap->broadcast(tEVT);
break;
};
default: m_mStatusMutex.unlock();
};
}
else m_mStatusMutex.unlock();
if (pReceivedPackage[DATA_BEGIN_IDX] > 0) {
uint8_t tCount = 0;
tCount = pReceivedPackage[DATA_BEGIN_IDX];
CLIENT_EVENT* tEVT = NULL;
tEVT = (CLIENT_EVENT*)& pReceivedPackage[DATA_BEGIN_IDX + 1];
for (uint8_t xindex = 0; xindex < tCount; xindex++) {
switch (tEVT[xindex].type) {
case EVT_TARGET_BLACK:
case EVT_TARGET_WHITE: {
char tBuffer[256];
float fRange, fAzimuth, fElevation;
uint16_t cX, cY;
bool lMaster;
uint8_t kid;
kid = tEVT[xindex].k_id & 0x07;
lMaster = ((tEVT[xindex].k_id & 0x08) == 0x08);
fRange = 300.0 / 4095.0 * tEVT[xindex].range;
//makeCds( tData->mStartID, sX, sY, m_bIsMaster );
//makeCds( tData->mEndID, eX, eY, m_bIsMaster );
//cX = ((sX+eX)>>1);
//cY = ((sY+eY)>>1);
makeXY(tEVT[xindex].th_id, cX, cY, m_bIsMaster);
fAzimuth = 360.0 - (360.0 / TH_LINE_NODES) * cX;
fElevation = 90.0 - (Q_DEGREE_FOV / Q_SCAN_COUNT) * cY + Q_SHIFT_DOWN_FOV;
sprintf(tBuffer, "%s[%d] %s target \tRange: %.2fm. \tAzimuth: %.2f \tElevation: %.2f \tTS: %d@%d W:%d",
(lMaster ? "M" : "S"),
kid,
((tEVT[xindex].type == EVT_TARGET_WHITE) ? "White" : "Black"),
fRange,
fAzimuth,
fElevation,
tEVT[xindex].uts,
tEVT[xindex].ums,
tEVT[xindex].w_cnt * tEVT[xindex].range
);
basicEvent* bEVT = NULL;
CLIENT_EVENT* tData = NULL;
tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT));
if (tData != NULL) {
memcpy(tData, &tEVT[xindex], sizeof(CLIENT_EVENT));
bEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData);
if (bEVT != NULL) m_pEventHeap->broadcast(bEVT);
};
};
};
};
//set new stage2
m_nIdleTarget = m_nIdleTarget >> 1;
if (m_nIdleTarget < LGS_MIN_IDLE_DELAY) m_nIdleTarget = LGS_MIN_IDLE_DELAY;
//m_oProtocol->getState2();
//comSetBusy(USE_MUTEX);
}
else {
m_nIdleTarget = m_nIdleTarget << 1;
if (m_nIdleTarget > LGS_MAX_IDLE_DELAY) m_nIdleTarget = LGS_MAX_IDLE_DELAY;
};
completeOperation();
break;
case CMD_GET_WIDTH_TABLE:
break;
case CMD_SET_WIDTH_TABLE:
break;
case CMD_GET_VOLTAGE:
break;
case CMD_GET_VOLTAGE_PARAMETERS:
break;
case CMD_SET_VOLTAGE_PARAMETERS:
break;
case CMD_GET_HZ_DATA:
break;
case CMD_SET_HZ_DATA:
break;
case CMD_GET_CALIBRATION_TABLE:
break;
case CMD_SET_CALIBRATION_TABLE:
break;
case CMD_GET_LRF_DISABLE:
break;
case CMD_SET_LRF_DISABLE:
break;
case CMD_GET_ZOOM_TABLE:
break;
case CMD_SET_ZOOM_TABLE:
break;
case CMD_GET_TILT_TABLE:
break;
case CMD_SET_TILT_TABLE:
break;
case CMD_GET_HZ_ENABLE:
break;
case CMD_SET_HZ_ENABLE:
break;
case CMD_EVT:
break;
case CMD_FLIP_COMPLETE: {
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_FLIP, "Flip Complete");
m_pEventHeap->broadcast(tEVT);
break;
};
case CMD_SCAN_COMPLETE: {
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_SCAN, "Scan Complete");
m_pEventHeap->broadcast(tEVT);
break;
};
case CMD_TARGET: {
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target");
m_pEventHeap->broadcast(tEVT);
break;
};
case CMD_TARGET_WW: {
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target with Width");
m_pEventHeap->broadcast(tEVT);
break;
};
case CMD_TARGET_MW: {
tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT));
if (tData != NULL) {
/*
tData->mSampleID = (pReceivedPackage[5] << 24) + (pReceivedPackage[6] << 16) + (pReceivedPackage[7] << 8) + pReceivedPackage[8];
tData->mInfo = pReceivedPackage[9];
tData->mRange = (pReceivedPackage[12] << 8) + pReceivedPackage[11];
tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15];
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID );
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster );
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, "White Intruder Detection", tData );
m_pEventHeap->broadcast( tEVT );
*/
};
break;
};
case CMD_TARGET_MB: {
tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT));
if (tData != NULL) {
/*
tData->mSampleID = (pReceivedPackage[5] << 24) + (pReceivedPackage[6] << 16) + (pReceivedPackage[7] << 8) + pReceivedPackage[8];
tData->mInfo = pReceivedPackage[9];
tData->mRange = (pReceivedPackage[12] << 8) + pReceivedPackage[11];
tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15];
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID, m_bIsMaster );
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster );
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, "Target Black", tData );
m_pEventHeap->broadcast( tEVT );
*/
};
break;
};
case CMD_TARGET_ZZ: {
if (m_eWorkMode == CWM_PINGPONG) {
tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT));
if (tData != NULL) {
/*
char tBuffer[256];
float fRange, fAzimuth, fElevation;
int sX, sY, eX, eY, cX, cY;
for( int index = 0; index < sizeof(CLIENT_EVENT); index++ ){
((uint8_t*)tData)[index] = pReceivedPackage[5+index];
};
fRange = 300.0 / 4095.0 * tData->mRange;
makeCds( tData->mStartID, sX, sY, ( tData->mInfo & 0xFF000000 ) > 0 );
makeCds( tData->mEndID, eX, eY, ( tData->mInfo & 0xFF000000 ) > 0 );
cX = ((sX+eX)>>1);
cY = ((sY+eY)>>1);
fAzimuth = (360.0 / TH_LINE_NODES )*cX;
fElevation = 90.0 - (90.0/Q_SCAN_COUNT )*cY;
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget( makeIds( cX, cY ), m_bIsMaster );
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget( makeIds( cX, cY ), tData->mRange, m_bIsMaster );
if( ( tData->mInfo & 0x00FF0000 ) > 0 ){
sprintf( tBuffer, "[%s]:%.2fm. Azimuth: %.2f Elevation: %.2f",
(m_bIsMaster?"M":"S"),
fRange,
fAzimuth,
fElevation
);
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, tBuffer, tData );
} else {
sprintf( tBuffer, "[%s]:%.2fm. Azimuth: %.2f Elevation: %.2f",
(m_bIsMaster?"M":"S"),
fRange,
fAzimuth,
fElevation
);
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, tBuffer, tData );
};
m_pEventHeap->broadcast( tEVT );
*/
};
};
break;
};
default:
completeOperation(false);
break;
};
free(pReceivedPackage);
pReceivedPackage = NULL;
nReceivedPackageSize = 0;
bPackageIsArived = false;
};
return true;
};
#else
void objectLGS::m_fThreadBProc(void){
U8 *pReceivedPackage = NULL;
size_t nReceivedPackageSize = 0;
@ -1021,7 +1501,7 @@ void objectLGS::m_fThreadBProc(void){
};
};
};
#endif
bool objectLGS::startGetScanData( uint8_t kID, uint32_t *th_zone ){
if( getOperation() == CMD_FULL_BORDER ) return true;
m_mDataMutex.lock();

5
lib/components/object/objectLGS.h

@ -54,13 +54,13 @@ typedef struct S_DEVICE_STATUS{
} DEVICE_STATUS, *PDEVICE_STATUS;
class objectLGS : public basicObject, basicDualThread{
class objectLGS : public basicObject, basicDualThread, protocolLGS_CLIENT{
private:
basicLogCollection *m_pLog;
basicEventHeap *m_pEventHeap;
config_setting_t *m_pSettings;
protocolLGS_CLIENT *m_oProtocol;
//protocolLGS_CLIENT *m_oProtocol;
clientPort *m_pTransport;
CSTR m_pHost;
int m_nPort;
@ -108,6 +108,7 @@ class objectLGS : public basicObject, basicDualThread{
protected:
void m_fThreadAProc(void);
void m_fThreadBProc(void);
bool packetHandler(protocolPackage* Package);
public:
//explicit objectLGS( PLGS_PARAMETERS Settings, basicTransport *Transport);
explicit objectLGS( config_setting_t *Settings = NULL, bool Master = true );

29
lib/data/net/clientPort.cpp

@ -9,6 +9,7 @@ clientPort::clientPort():transportSocket(){
m_sHostName = NULL;
m_bKeepAlive = true;
};
clientPort::clientPort(CSTR URI):transportSocket(){
m_pLog = basicLogCollection::getInstance();
m_bKeepAlive = true;
@ -196,7 +197,8 @@ int clientPort::sendBlock(unsigned char *Data, int DataSize){
RetVal = send(m_nSocketFD, (const char *)Data, DataSize, NULL);
if (RetVal == SOCKET_ERROR) {
char cBuffer[CLOG];
m_bConnected = false;
//m_bConnected = false;
setConnectionStatus(CS_DISCONNECTED);
sprintf(cBuffer,"send failed with error: %d", WSAGetLastError());
LOG_ERROR(cBuffer);
closesocket(m_nSocketFD);
@ -206,13 +208,15 @@ int clientPort::sendBlock(unsigned char *Data, int DataSize){
//sprintf(cBuffer,"Bytes Sent: %ld", RetVal);
//LOG(cBuffer);
if (!m_bKeepAlive){
setConnectionStatus(CS_DISCONNECTED);
closesocket(m_nSocketFD);
WSACleanup();
m_bConnected = false;
//m_bConnected = false;
m_nSocketFD = INVALID_SOCKET;
};
} else {
m_bConnected = false;
setConnectionStatus(CS_DISCONNECTED);
//m_bConnected = false;
return -1;
};
#endif
@ -220,7 +224,7 @@ int clientPort::sendBlock(unsigned char *Data, int DataSize){
};
int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){
if( m_eConnectionStatus != CS_CONNECTED ) return 0; // Exit after unsuccess reconnect
if( m_eConnectionStatus != CS_CONNECTED ) return -1; // Exit after unsuccess reconnect
#ifdef __linux__
int RetVal;
if( m_nSocketFD > -1 ) {
@ -257,31 +261,34 @@ int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){
RetVal = recv(m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, 0);
if( RetVal < 1 ){
if( errno!=EAGAIN && errno!=EINTR ) {
setConnectionStatus(CS_DISCONNECTED);
closesocket(m_nSocketFD);
WSACleanup();
*BufferLength = 0;
m_bConnected = false;
//m_bConnected = false;
m_nSocketFD = INVALID_SOCKET;
return -1;
};
};
if (!m_bKeepAlive){
setConnectionStatus(CS_DISCONNECTED);
closesocket(m_nSocketFD);
WSACleanup();
m_bConnected = false;
//m_bConnected = false;
m_nSocketFD = INVALID_SOCKET;
};
} else {
setConnectionStatus(CS_DISCONNECTED);
LOG_ERROR("Not Connected!");
*BufferLength = 0;
m_bConnected = false;
//m_bConnected = false;
return 0;
};
#endif
if (RetVal > 0) {
//char cBuffer[165];
//sprintf(cBuffer, "Bytes received: %d", RetVal);
//LOG(cBuffer);
char cBuffer[165];
sprintf(cBuffer, "Bytes received: %d", RetVal);
LOG(cBuffer);
*BufferLength = RetVal;
return RetVal;
};
@ -302,6 +309,7 @@ int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){
};
bool clientPort::disconnect(void){
if( m_eConnectionStatus == CS_CONNECTED ){
setConnectionStatus(CS_DISCONNECTED);
#ifdef __linux__
shutdown( m_nSocketFD, SHUT_RDWR ); //SD_RECEIVE
close( m_nSocketFD );
@ -311,7 +319,6 @@ bool clientPort::disconnect(void){
WSACleanup();
m_nSocketFD = INVALID_SOCKET;
#endif
setConnectionStatus(CS_DISCONNECTED);
};
return true;
};

32
lib/data/net/transportSocket.cpp

@ -71,19 +71,19 @@ void transportSocket::m_fThreadAProc(void){
RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index);
if( RetVal > 0 ) index += RetVal;
if( RetVal == -1 ){
//m_bThreadBStatus = TH_ENDED;
//m_bThreadAStatus = TH_ENDED;
m_bThreadBStatus = TH_ENDED;
m_bThreadAStatus = TH_ENDED;
LOG_ERROR("Connection Error[send]");
//setConnectionStatus( CS_DISCONNECTED );
setConnectionStatus( CS_DISCONNECTED );
m_nOutputBufferSize = 0;
};
};
m_nOutputBufferSize = 0;
//m_mBufferProtectorMutex.unlock();
};// else {
m_mBufferProtectorMutex.unlock();
SLEEP(5);
//};
m_mBufferProtectorMutex.unlock();
} else {
m_mBufferProtectorMutex.unlock();
SLEEP(5);
};
};
};
@ -97,17 +97,21 @@ void transportSocket::m_fThreadBProc(void){
LOG_ERROR("Connection Error[rcpt]");
m_nInputBufferSize = 0;
if(!getStatus()) {
setConnectionStatus(CS_DISCONNECTED);
m_bThreadBStatus = TH_ENDED;
m_bThreadAStatus = TH_ENDED;
setConnectionStatus( CS_DISCONNECTED );
} else SLEEP(100);
} else if( m_nInputBufferSize > 0 ){
m_mQueueProtectorMutex.lock();
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++){
(*index)->parse(m_pInputBuffer, m_nInputBufferSize);
if (m_vParsers.size()) {
m_mQueueProtectorMutex.lock();
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) {
(*index)->parse(m_pInputBuffer, m_nInputBufferSize);
};
m_nInputBufferSize = 0;
m_mQueueProtectorMutex.unlock();
} else {
LOG_ERROR("Try to parse data but No Parsers Assigned!");
};
m_nInputBufferSize = 0;
m_mQueueProtectorMutex.unlock();
} else {
SLEEP(5);
};

1
lib/data/protocol/protocol.cpp

@ -39,6 +39,7 @@ bool protocolParser::create(void){
};
void protocolParser::setConnectionStatus( CONNECTION_STATUS cStatus ){
LOG("Connection Status Changed!");
m_eConnectionStatus = cStatus;
};
CONNECTION_STATUS protocolParser::getConnectionStatus( void ){

14
lib/data/protocol/protocolLGS.cpp

@ -31,6 +31,16 @@ protocolLGS::~protocolLGS(){
# endif
};
bool protocolLGS::setTransport(basicTransport* Transport){
if (Transport == NULL) return false;
if (m_oDataTransport != NULL) {
LOG_ERROR("Transport Already Assigned!");
return false;
};
m_oDataTransport = Transport;
return m_oDataTransport->addRecipient(this);
};
int protocolLGS::packetChecker(U8 *Buffer, size_t BufferSize ){
#ifdef DUBUG_COMMUNICATION
char tmp[32];
@ -122,7 +132,9 @@ protocolPackage *protocolLGS::packetExtractor(U8 *Buffer, size_t BufferSize ){
#endif
return NULL;
};
//LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)");
#ifdef DUBUG_COMMUNICATION
LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)");
#endif
return NULL;
};

10
lib/data/protocol/protocolLGS.h

@ -795,10 +795,12 @@ class protocolLGS: public protocolParser{
protocolPackage *packetExtractor( uint8_t *Buffer, size_t BufferSize);
public:
explicit protocolLGS( basicTransport *Transport = NULL, uint8_t DeviceID = 0 );
virtual ~protocolLGS();
virtual bool create(void){ return protocolParser::create(); };
bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; };
uint8_t getDeviceID( void ){ return m_bDeviceID; };
virtual ~protocolLGS();
virtual bool create(void){ return protocolParser::create(); };
uint8_t getDeviceID(void) { return m_bDeviceID; };
basicTransport * getTransport(void) { return m_oDataTransport; };
bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; };
bool setTransport(basicTransport* m_oDataTransport);
};
class protocolLGS_CLIENT: public protocolLGS{

Loading…
Cancel
Save