|
|
#ifndef __PROTOCOL_DEFENDER_HEADER__
#define __PROTOCOL_DEFENDER_HEADER__
#ifdef __linux__
#include <features.h>
#endif
#include "protocolHTTP.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string>
#include "../../components/base/basicFunctionality.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicSettingsProvider.h"
#include "xmlParser.h"
#define PROTOCOL_TYPE_3D true
#define PROTOCOL_TYPE_2D false
#define SERVICE_URL_TEMPLATE_NOTIFY "/simple-event/notify"
#define SERVICE_URL_TEMPLATE_STATUS "/sensors/lidar%dd/%s/status"
#define SERVICE_URL_TEMPLATE_FAULT "/sensors/lidar%dd/%s/fault"
#define SERVICE_URL_TEMPLATE_EVENT "/sensors/lidar%dd/%s/event"
#define SERVICE_URL_TEMPLATE_CALLBACK "/sensors/lidar%dd/%s/httpcallback"
#define SERVICE_URL_TEMPLATE_CLOCKSYNC "/sensors/lidar%dd/%s/clocksync"
#define DFSL_HARDWARE_TYPE "DFSL_3D_LIDAR"
#ifdef PRU_SLAVE
#define DFSL_SOURCE_NAME "SLAVE_SENSOR"
#else
#define DFSL_SOURCE_NAME "MASTER_SENSOR"
#endif
typedef enum E_DEFENDER_CATEGORY{ DC_STATUS = 0, DC_ALARM = 1, DC_ERROR = 2} defenderCategoryTypes;
#define DFSL_DEVICE "DFSL Lidar Sensor"
#define DFSL_DEFAULT_LOCATION "{\"point\": [ 32.878, 35.999 ], \"heading\": 128, \"area\": [] }"
#define DFSL_SensorSourceDto "{ \"providerId\": \"%s\", \"sensorNodeId\" : \"%s\", \"sensorId\": \"%s\" }"
#define DFSL_LidarTargetDto "{ \"id\": %d, \"AZ\": %d, \"EL\": %d, \"Range\": %d, \"Width\": %d }"
#define DFSL_LocationDto "{\"point\": [ %s ],\"area\": [ %s ] }"
#define DFSL_SE_ENVELOPE "{\"id\": %d,\"category\": \"%s\",\"severity\": \"%s\"," \
"\"receivedTS\": \"%s\",\"lastChangeTS\": \"%s\"," \ "\"startTime\": \"%s\",\"endTime\": \"%s\", \"location\": %s, " \ "\"radius\": 0, \"data\": [ %s ]}"
#define PACKAGE_SE_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s," \
" \"name\": \"%s\", \"type\": \"%s\", \"eventId\": \"%s\", \"targets\": [%s] }"
#define PACKAGE_SE_DATA_STATUS_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s, " \
" \"name\": \"%s\", \"type\": \"%s\", \"eventId\": \"%s\", \"payload\": [%s] }"
#define OS_SCANNER_NAME_SIZE 128
#define OS_CEP_ADDRESS_SIZE 16
/**
* TODO: Add class description** @author gagua*/class protocolRGoose : public protocolHTTP {private: basicLogCollection *m_pLog; config_setting_t *m_pSettings; int m_nScannerDimentions; CSTR m_pScannerName; CSTR m_pServerIP; int m_nServerPort; bool m_bCurrentStatus; CSTR buildURL( CSTR templ, int dim, CSTR devID ); CSTR buildUniqID( void ); bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize ); bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ); bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status ); bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description ); bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle, int Range, int Width ); bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle1, int Angle2, int Range );
CSTR assembleStatusData( bool StatusOK ); CSTR assembleFaultData( uint8_t Code, CSTR Desc ); CSTR assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation = 0 ); size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data );protected: virtual bool packetHandler( protocolPackage *Package );public: // Constructor
explicit protocolRGoose( config_setting_t *Settings = NULL ); //ToDo: change Serial to BaseClass of some kind of socket
//protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL );
// Destructor
virtual ~protocolRGoose(); virtual bool init(){ return true; }; bool Alarm2D( int Angle, int Range, int Width, int ID=0 ); bool Alarm3D( int Angle1, int Angle2, int Range, int ID=0 ); bool VisibilityChanged( bool Worsened ); bool StatusUpdate( void ); void SetStatus( bool A ){ m_bCurrentStatus = A; }; bool ErrorReporting( int lvl, CSTR Descr ); bool StartTimeSynch( void );#ifdef __linux__
//bool FinishTimeSynch( unsigned long long *tVals );
#else
//bool FinishTimeSynch( unsigned __int64 *tVals );
#endif
bool SetupCallBack( CSTR CallBackPath ); void setProtocolType( bool DeviceIs3D ); void setScannerName( CSTR Name );};
#ifdef __linux__
unsigned long long getSHTimeValue( void );#else
unsigned __int64 getSHTimeValue( void );#endif
#endif
|