From b2341695aa396815d3a6d24f725ceba86c1f48e7 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Sun, 7 Jan 2024 07:43:11 -0800 Subject: [PATCH] Remote Server Support stage 1 (proto) --- lib/App/common/kernelModuleRemoteServer.h | 57 ++++++++++ lib/data/protocol/protocolREST.h | 128 ++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 lib/App/common/kernelModuleRemoteServer.h create mode 100644 lib/data/protocol/protocolREST.h diff --git a/lib/App/common/kernelModuleRemoteServer.h b/lib/App/common/kernelModuleRemoteServer.h new file mode 100644 index 00000000..f95ca754 --- /dev/null +++ b/lib/App/common/kernelModuleRemoteServer.h @@ -0,0 +1,57 @@ +#ifndef __KERNEL_KAFKA_MODULE_HEADERS__ +#define __KERNEL_KAFKA_MODULE_HEADERS__ + + +#include "kernelModule.h" +#include "../components/base/basicThread.h" +#include "../components/base/basicEventHeap.h" +#include "../data/protocol/protocolREST.h" + +class kernelModuleRemoteServer: public kernelModule, public basicThread { + private: + //KAFKA_SETTINGS *m_pSettings; + protocolREST *m_pProtocol; + bool m_bConsumerEnabled; + basicEventHeap *m_pEventHeap; + //KAFKA_TEMPLATE ***m_pEvtTemplates; + + int32_t partition; + int64_t start_offset; + char m_sServerIP[48]; + char m_sServerName[48]; + unsigned long long m_llTicks; + CSTR buildTemplate( CSTR tpl, + uint32_t source_id, + CSTR ts, + CSTR uuid = NULL, + CSTR az = NULL, + CSTR range = NULL, + CSTR width = NULL, + CSTR el = NULL, + CSTR lat = NULL, + CSTR lon = NULL, + CSTR alt = NULL, + CSTR extID = NULL, + CSTR src_Name = NULL, + CSTR src_IP = NULL, + CSTR src_lat = NULL, + CSTR src_lon = NULL, + CSTR src_alt = NULL, + CSTR src_rot_x = NULL, + CSTR src_rot_y = NULL, + CSTR src_rot_z = NULL + ); + protected: + virtual void m_fThreadProc( void ); + public: + explicit kernelModuleKafka( uint32_t ModuleID ); + virtual ~kernelModuleKafka(); + + virtual bool reloadSettings(); + virtual bool startService(); + virtual bool stopService( bool force = false ); + virtual void dispatchEvent(EVENT_CONTAINER *Evt); +}; + + +#endif diff --git a/lib/data/protocol/protocolREST.h b/lib/data/protocol/protocolREST.h new file mode 100644 index 00000000..0e05b03e --- /dev/null +++ b/lib/data/protocol/protocolREST.h @@ -0,0 +1,128 @@ +#ifndef __PROTOCOL_RESTAPI_HEADER__ +#define __PROTOCOL_RESTAPI_HEADER__ + +#ifdef __linux__ + #include +#endif + +#include "protocolHTTP.h" + +#include +#include +#include +#include +#include +#include + +#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 "" \ + "%s" \ + "%s" \ + "" + +#define PACKAGE_ENVELOPE_TEMPLATE_FAULT "" \ + "%s" \ + "%s" \ + "%s" \ + "" + +#define PACKAGE_ENVELOPE_TEMPLATE_EVT2D "" \ + "%s" \ + "%s" \ + "%d" \ + "%d%d" \ + "%d" \ + "" + +#define PACKAGE_ENVELOPE_TEMPLATE_EVT3D "" \ + "%s" \ + "%s" \ + "%d" \ + "%d%d%d" \ + "" \ + "" + +#define PACKAGE_ENVELOPE_TEMPLATE_REG_CALL "" \ + "%s" \ + "" + +#define PACKAGE_ENVELOPE_TEMPLATE_CLOCKSYNC "" \ + "%s" \ + "" + +#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 \ No newline at end of file