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.
 
 
 
 
 
 

128 lines
5.0 KiB

#ifndef __PROTOCOL_RESTAPI_HEADER__
#define __PROTOCOL_RESTAPI_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_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 PACKAGE_ENVELOPE_TEMPLATE_STATUS "<lcu:SystemStatus xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
"<lcu:Mode>%s</lcu:Mode>" \
"<lcu:Timestamp>%s</lcu:Timestamp>" \
"</lcu:SystemStatus>"
#define PACKAGE_ENVELOPE_TEMPLATE_FAULT "<lcu:FaultDescription xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
"<lcu:Level>%s</lcu:Level>" \
"<lcu:Timestamp>%s</lcu:Timestamp>" \
"<lcu:Description>%s</lcu:Description>" \
"</lcu:FaultDescription>"
#define PACKAGE_ENVELOPE_TEMPLATE_EVT2D "<lcu:EventLidar2D xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
"<lcu:UniqueId>%s</lcu:UniqueId>" \
"<lcu:Timestamp>%s</lcu:Timestamp>" \
"<lcu:Target><lcu:Id>%d</lcu:Id>" \
"<lcu:Coordinates><lcu:Azimuth>%d</lcu:Azimuth><lcu:Distance>%d</lcu:Distance></lcu:Coordinates>" \
"<lcu:Width>%d</lcu:Width></lcu:Target>" \
"</lcu:EventLidar2D>"
#define PACKAGE_ENVELOPE_TEMPLATE_EVT3D "<lcu:EventLidar3D xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
"<lcu:UniqueId>%s</lcu:UniqueId>" \
"<lcu:Timestamp>%s</lcu:Timestamp>" \
"<lcu:Target><lcu:Id>%d</lcu:Id>" \
"<lcu:Coordinates><lcu:Azimuth>%d</lcu:Azimuth><lcu:Elevation>%d</lcu:Elevation><lcu:Distance>%d</lcu:Distance></lcu:Coordinates>" \
"</lcu:Target>" \
"</lcu:EventLidar3D>"
#define PACKAGE_ENVELOPE_TEMPLATE_REG_CALL "<lcu:Callback xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
"<lcu:XAddr>%s</lcu:XAddr>" \
"</lcu:Callback>"
#define PACKAGE_ENVELOPE_TEMPLATE_CLOCKSYNC "<lcu:ClockSyncQuery xmlns:lcu=\"http://www.safeshore.eu/lcu/schema\">" \
"<lcu:t0>%s</lcu:t0>" \
"</lcu:ClockSyncQuery>"
#define OS_SCANNER_NAME_SIZE 128
#define OS_LCU_ADDRESS_SIZE 16
/**
* TODO: Add class description
*
* @author gagua
*/
class protocolREST : public protocolHTTP {
private:
basicLogCollection * m_pLog;
config_setting_t * m_pSettings;
bool m_bEnabled;
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 );
protected:
virtual bool packetHandler( protocolPackage *Package );
public:
// Constructor
explicit protocolREST( config_setting_t *Settings = NULL );
//ToDo: change Serial to BaseClass of some kind of socket
//protocolREST( clientPort *SocketTransport, config_setting_t *Settings = NULL );
// Destructor
virtual ~protocolREST();
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