Files
redAcore/LiteProtocolCore.h
Charl Wentzel 9677052042 Important Update:
- Bug fix JSONparseCore: Allow for blank path in file name
- Added new Class LiteProtocolCore for basic protocol
2017-04-30 17:32:19 +02:00

87 lines
2.8 KiB
C++

/******************************************************
* Rapid Embedded Development Architecture (redA) *
* Copyright (C) 2008 RecoSys *
* -------------- *
* TLiteProtcol: *
* Simplified protocol object to allow for fast *
* communications between componets *
* *
* Contents: *
* CLiteProtocol - Core of simple protocol *
* *
******************************************************/
#ifndef LITE_PROTOCOL_CORE
#define LITE_PROTOCOL_CORE
using namespace std;
// redA Libraries
/* none */
// Standard C/C++ Libraries
#include <unistd.h>
//---------------------------------------------------------------------------
// Very Simple Lightweight Protcol
class CLiteProtocol
{
protected:
// Parameters
int BufferInc;
char StartChar;
char EndChar;
char Separator;
char *CommandStr;
int BufferSize;
long Length;
int NoOfParams;
bool Verified;
char Error[100];
int CurrPos;
int CurrParam;
// Internal tools
bool IncCommandStr( int pLength );
bool UpdateCommandStr();
bool VerifyStr( char * pString, int pLength, int &ParamCount, char * pError );
public:
// Constructor & Destructor
CLiteProtocol( int pBufferInc, char pStartChar = 0x02, char pEndChar = 0x03, char pSeparator = 0x00 );
~CLiteProtocol();
// Set Command string
bool ClearCommandStr();
bool NewCommandStr();
bool SetCommandStr( char * pString, int pLength, char * Error );
bool AppendCommandStr( char *pString, int &pLength );
bool VerifyCommandStr();
// Get Command String
char* GetCommandStr( char ** pString = NULL, int * pLength = NULL );
int GetCommandLen() { return Length; };
int GetNoOfParams() { return NoOfParams; };
bool isVerified() { return Verified; };
char* GetError() { return Error; };
// Set Parameters
bool AppendParam( const char * pString, const int pLength );
bool AppendParam( long pValue );
bool AppendParam( double pValue, int pDigits );
// Get Parameters
char const * GetParamNo( int ParamNo, char ** pString = NULL, int * pLength = NULL );
bool GotoParam( int ParamNo );
bool NextParam();
char const * GetParam( char ** pString = NULL, int * pLength = NULL );
};
#endif /* LITE_PROTOCOL_CORE */