Important Update:
- CLiteProtocol: - Set input string on methods to const char * - Simplify checking for verification - Ensure Length parameter can be left out on all methods - Add quick functions for structured commands: To, From, Command - CLogCore: - Use only "\n", not "\r\n" - SignalCore: - Use std::endl instead of "\r\n"
This commit is contained in:
@@ -50,7 +50,7 @@ class CLiteProtocol
|
||||
// Internal tools
|
||||
bool IncCommandStr( int pLength );
|
||||
bool UpdateCommandStr();
|
||||
bool VerifyStr( char * pString, int pLength, int &ParamCount, char * pError );
|
||||
bool VerifyStr( const char * pString, int pLength, int &ParamCount, char * pError );
|
||||
|
||||
public:
|
||||
// Constructor & Destructor
|
||||
@@ -58,29 +58,41 @@ class CLiteProtocol
|
||||
~CLiteProtocol();
|
||||
|
||||
// Set Command string
|
||||
bool ClearCommandStr();
|
||||
bool NewCommandStr();
|
||||
bool SetCommandStr( char * pString, int pLength, char * Error );
|
||||
bool AppendCommandStr( char *pString, int &pLength );
|
||||
bool VerifyCommandStr();
|
||||
bool ClearCommandStr(); // Set command string to empty
|
||||
bool NewCommandStr(); // Create new empty command string with headers (length, param count)
|
||||
bool SetCommandStr( const char * pString, int pLength ); // Set complete command string (as received)
|
||||
bool AppendCommandStr( char *pString, int &pLength ); // Build up command string in chunks as it is received
|
||||
bool VerifyCommandStr(); // Validate received command string
|
||||
|
||||
// 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; };
|
||||
char* GetCommandStr( char ** pString = NULL, int * pLength = NULL ); // Return command string
|
||||
int GetCommandLen() { return Length; }; // Return length of command string
|
||||
int GetNoOfParams() { return NoOfParams; }; // Returns total number of parameters
|
||||
bool isVerified() { return Verified; }; // Returns whether command has been validated
|
||||
char* GetError() { return Error; }; // Return reason for not being valid
|
||||
|
||||
// Set Parameters
|
||||
bool AppendParam( const char * pString, const int pLength );
|
||||
bool AppendParam( long pValue );
|
||||
bool AppendParam( double pValue, int pDigits );
|
||||
bool AppendParam( const char * pString, const int pLength = -1 ); // Add string param to command string
|
||||
bool AppendParam( const long pValue ); // Add long param as text to command string
|
||||
bool AppendParam( const double pValue, const int pDigits ); // Add real param as text to command string
|
||||
|
||||
// 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 );
|
||||
bool GotoParam( int ParamNo ); // Reset pointer to specific parameter
|
||||
bool NextParam(); // Move pointer to next parameter
|
||||
char const * GetParam( char ** pString = NULL, int * pLength = NULL ); // Read parameter at pointer (always text)
|
||||
char const * GetParamNo( int ParamNo, char ** pString = NULL, int * pLength = NULL ); // Get total no of parameters in command string
|
||||
|
||||
// Create & Read Structured Command string
|
||||
bool CreateCommand( char const * From, char const * To, char const * Command ); // Create new command string with core params: To, From & Command
|
||||
bool ReadCommand( char ** From, char ** To, char ** Command, int * DataParams,
|
||||
int * FromLen = NULL, int * ToLen = NULL, int * CommandLen = NULL ); // Read core parameters from structured command: To, From & Command
|
||||
|
||||
// Read structured Command string
|
||||
inline int GetNoOfDataParams() { return (NoOfParams - 3); }; // Return number for data (additional) params
|
||||
inline bool GotoDataParam( int ParamNo ) { return (GotoParam( ParamNo+3 )); }; // Goto specific data (additional) param
|
||||
inline char const * GetDataParamNo( int ParamNo, char ** pString = NULL, int * pLength = NULL ) { // Read specific data param (by number)
|
||||
return (GetParamNo( ParamNo+3, pString, pLength ));
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* LITE_PROTOCOL_CORE */
|
||||
|
||||
Reference in New Issue
Block a user