Merge branch 'master' of /home/development/source/core/redAcore into BaslerCamera
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
PROJECT(lib_redAcore)
|
PROJECT(lib_redAcore)
|
||||||
|
|
||||||
ADD_LIBRARY(redAcore TimingCore.cpp LogCore.cpp SignalCore.cpp BufferCore.cpp FunctionCore.cpp DeviceCore.cpp FileCore.cpp SelectCore.cpp SelectableCore.cpp)
|
ADD_LIBRARY(redAcore TimingCore.cpp DateTimeCore.cpp LogCore.cpp SignalCore.cpp BufferCore.cpp FunctionCore.cpp DeviceCore.cpp FileCore.cpp SelectCore.cpp SelectableCore.cpp)
|
||||||
|
|||||||
175
DateTimeCore.cpp
Normal file
175
DateTimeCore.cpp
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
* DateTimeCore.cpp
|
||||||
|
*
|
||||||
|
* Created on: 3 March 2017
|
||||||
|
* Author: wentzelc
|
||||||
|
*/
|
||||||
|
|
||||||
|
// redA Libraries
|
||||||
|
#include "DateTimeCore.h"
|
||||||
|
|
||||||
|
// Standard C/C++ Libraries
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Variable used to temp values with
|
||||||
|
static char ReturnStr[20];
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Set current time on real-time clock
|
||||||
|
bool SetTime( unsigned char Hours, unsigned char Minutes, unsigned char Seconds )
|
||||||
|
{
|
||||||
|
struct tm NewTime;
|
||||||
|
struct timeval tv;
|
||||||
|
struct timezone tz;
|
||||||
|
|
||||||
|
// Get current date and time
|
||||||
|
gettimeofday( &tv, &tz);
|
||||||
|
|
||||||
|
// Change to new time
|
||||||
|
localtime_r( &tv.tv_sec, &NewTime );
|
||||||
|
|
||||||
|
NewTime.tm_hour = Hours;
|
||||||
|
NewTime.tm_min = Minutes;
|
||||||
|
NewTime.tm_sec = Seconds;
|
||||||
|
|
||||||
|
// Convert back
|
||||||
|
tv.tv_sec = mktime( &NewTime );
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
// Set date and new time
|
||||||
|
settimeofday( &tv, &tz);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Get current time from real-time clock
|
||||||
|
bool GetTime( unsigned char &Hours, unsigned char &Minutes, unsigned char &Seconds )
|
||||||
|
{
|
||||||
|
struct tm CurrentTime;
|
||||||
|
time_t UTC;
|
||||||
|
|
||||||
|
// Get current date and time
|
||||||
|
time( &UTC );
|
||||||
|
localtime_r( &UTC, &CurrentTime );
|
||||||
|
|
||||||
|
// Extract time
|
||||||
|
Hours = CurrentTime.tm_hour;
|
||||||
|
Minutes = CurrentTime.tm_min;
|
||||||
|
Seconds = CurrentTime.tm_sec;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Set current date on real-time clock
|
||||||
|
bool SetDate( unsigned char Day, unsigned char Month, unsigned Year )
|
||||||
|
{
|
||||||
|
struct tm NewDate;
|
||||||
|
struct timeval tv;
|
||||||
|
struct timezone tz;
|
||||||
|
|
||||||
|
// Get current date and time
|
||||||
|
gettimeofday( &tv, &tz );
|
||||||
|
|
||||||
|
// Change to new time
|
||||||
|
localtime_r( &tv.tv_sec, &NewDate );
|
||||||
|
|
||||||
|
NewDate.tm_year = Year - 1900;
|
||||||
|
NewDate.tm_mon = Month - 1;
|
||||||
|
NewDate.tm_mday = Day;
|
||||||
|
|
||||||
|
// Convert back
|
||||||
|
tv.tv_sec = mktime( &NewDate );
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
// Set date and new time
|
||||||
|
settimeofday( &tv, &tz);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Get current data from real-time clock
|
||||||
|
bool GetDate( unsigned char &Day, unsigned char &Month, unsigned &Year )
|
||||||
|
{
|
||||||
|
struct tm CurrentDate;
|
||||||
|
time_t UTC;
|
||||||
|
|
||||||
|
// Get current date and time
|
||||||
|
time( &UTC );
|
||||||
|
localtime_r( &UTC, &CurrentDate );
|
||||||
|
|
||||||
|
// Extract date
|
||||||
|
Day = CurrentDate.tm_mday;
|
||||||
|
Month = CurrentDate.tm_mon + 1;
|
||||||
|
Year = CurrentDate.tm_year + 1900;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Get the current date in a string
|
||||||
|
char const * GetDateStr( const char * DateSeparator )
|
||||||
|
{
|
||||||
|
unsigned char Day;
|
||||||
|
unsigned char Month;
|
||||||
|
unsigned int Year;
|
||||||
|
|
||||||
|
// Get Date
|
||||||
|
GetDate( Day, Month, Year );
|
||||||
|
|
||||||
|
// Build String
|
||||||
|
sprintf( ReturnStr, "%04d%s%02d%s%02d",
|
||||||
|
Year, ((DateSeparator)? DateSeparator : "/"), Month, ((DateSeparator)? DateSeparator : "/"), Day );
|
||||||
|
|
||||||
|
// Return value
|
||||||
|
return (ReturnStr);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
char const * GetTimeStr( const char * TimeSeparator )
|
||||||
|
{
|
||||||
|
unsigned char Hours;
|
||||||
|
unsigned char Minutes;
|
||||||
|
unsigned char Seconds;
|
||||||
|
|
||||||
|
// Get Date & Time
|
||||||
|
GetTime( Hours, Minutes, Seconds );
|
||||||
|
|
||||||
|
// Build String
|
||||||
|
sprintf( ReturnStr, "%02d%s%02d%s%02d",
|
||||||
|
Hours, ((TimeSeparator)? TimeSeparator : ":"), Minutes, ((TimeSeparator)? TimeSeparator : ":"), Seconds );
|
||||||
|
|
||||||
|
return (ReturnStr);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
char const * GetDateTimeStr( const char * DateSeparator, const char * TimeSeparator )
|
||||||
|
{
|
||||||
|
unsigned char Day;
|
||||||
|
unsigned char Month;
|
||||||
|
unsigned int Year;
|
||||||
|
unsigned char Hours;
|
||||||
|
unsigned char Minutes;
|
||||||
|
unsigned char Seconds;
|
||||||
|
|
||||||
|
// Get Date & Time
|
||||||
|
GetDate( Day, Month, Year );
|
||||||
|
GetTime( Hours, Minutes, Seconds );
|
||||||
|
|
||||||
|
// Build String
|
||||||
|
sprintf( ReturnStr, "%04d%s%02d%s%02d %02d%s%02d%s%02d",
|
||||||
|
Year, ((DateSeparator)? DateSeparator : "/"), Month, ((DateSeparator)? DateSeparator : "/"), Day,
|
||||||
|
Hours, ((TimeSeparator)? TimeSeparator : ":"), Minutes, ((TimeSeparator)? TimeSeparator : ":"), Seconds );
|
||||||
|
|
||||||
|
return (ReturnStr);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
32
DateTimeCore.h
Normal file
32
DateTimeCore.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* DateTimeCore.h
|
||||||
|
*
|
||||||
|
* Created on: 3 Mar 2017
|
||||||
|
* Author: wentzelc
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef REDACORE_DATETIMECORE_H_
|
||||||
|
#define REDACORE_DATETIMECORE_H_
|
||||||
|
|
||||||
|
// redA Libraries
|
||||||
|
/* none */
|
||||||
|
|
||||||
|
// Standard C/C++ Libraries
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Get and set System Date and Time
|
||||||
|
bool SetTime( unsigned char Hours, unsigned char Minutes, unsigned char Seconds );
|
||||||
|
bool GetTime( unsigned char &Hours, unsigned char &Minutes, unsigned char &Seconds );
|
||||||
|
|
||||||
|
bool SetDate( unsigned char Day, unsigned char Month, unsigned Year );
|
||||||
|
bool GetDate( unsigned char &Day, unsigned char &Month, unsigned &Year );
|
||||||
|
|
||||||
|
char const * GetDateStr( const char * DateSeparator = NULL );
|
||||||
|
char const * GetTimeStr( const char * TimeSeparator = NULL );
|
||||||
|
char const * GetDateTimeStr( const char * DateSeparator = NULL, const char * TimeSeparator = NULL );
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif /* REDACORE_DATETIMECORE_H_ */
|
||||||
122
DeviceCore.cpp
122
DeviceCore.cpp
@@ -446,7 +446,7 @@ bool CDeviceCore::UpdateSignedValue( TDeviceParam * Param, const int32_t Value,
|
|||||||
|
|
||||||
// Mark change & log event
|
// Mark change & log event
|
||||||
Changed = true;
|
Changed = true;
|
||||||
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %u", Name, Param->Name, ((Init)? "initialised" : "changed"), *((int16_t*)Param->Value) );
|
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %d", Name, Param->Name, ((Init)? "initialised" : "changed"), *((int16_t*)Param->Value) );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ bool CDeviceCore::UpdateSignedValue( TDeviceParam * Param, const int32_t Value,
|
|||||||
|
|
||||||
// Mark change & log event
|
// Mark change & log event
|
||||||
Changed = true;
|
Changed = true;
|
||||||
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %u", Name, Param->Name, ((Init)? "initialised" : "changed"), *((int32_t*)Param->Value) );
|
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %d", Name, Param->Name, ((Init)? "initialised" : "changed"), *((int32_t*)Param->Value) );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -518,6 +518,9 @@ bool CDeviceCore::UpdateStringValue( TDeviceParam * Param, const char * Value, c
|
|||||||
if (!Param || (Param->DataType != dtString))
|
if (!Param || (Param->DataType != dtString))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
switch (Param->DataType)
|
||||||
|
{
|
||||||
|
case dtString :
|
||||||
// Update register
|
// Update register
|
||||||
if (Init || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len))
|
if (Init || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len))
|
||||||
{
|
{
|
||||||
@@ -537,6 +540,12 @@ bool CDeviceCore::UpdateStringValue( TDeviceParam * Param, const char * Value, c
|
|||||||
Changed = true;
|
Changed = true;
|
||||||
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %s", Name, Param->Name, ((Init)? "initialised" : "changed"), (char*)Param->Value );
|
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %s", Name, Param->Name, ((Init)? "initialised" : "changed"), (char*)Param->Value );
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
// Invalid Data Type
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Generate Channel Event
|
// Generate Channel Event
|
||||||
if (Changed) {
|
if (Changed) {
|
||||||
Param->Changed = true;
|
Param->Changed = true;
|
||||||
@@ -680,6 +689,115 @@ bool CDeviceCore::SetStringValue( TDeviceParam * Param, const char * Value, cons
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool CDeviceCore::SetValue( TDeviceParam * Param, const char * Value, const int Len, bool Force )
|
||||||
|
{
|
||||||
|
u_int32_t UnsignedVal;
|
||||||
|
int32_t SignedVal;
|
||||||
|
float FloatVal;
|
||||||
|
|
||||||
|
char * TempStr;
|
||||||
|
bool UseTempStr = false;
|
||||||
|
|
||||||
|
// Validate
|
||||||
|
if (!Param || !Value || !Len)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check if string
|
||||||
|
if (Param->DataType == dtString)
|
||||||
|
{
|
||||||
|
// Simply set string
|
||||||
|
SetStringValue( Param, Value, Len, Force );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Ensure string is zero terminated
|
||||||
|
if (Value[Len] != 0) {
|
||||||
|
TempStr = (char *)malloc( Len+1 );
|
||||||
|
memcpy( TempStr, Value, Len );
|
||||||
|
TempStr[Len] = 0;
|
||||||
|
UseTempStr = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to correct type
|
||||||
|
switch (Param->DataType)
|
||||||
|
{
|
||||||
|
case dtUnsigned16 :
|
||||||
|
case dtUnsigned32 :
|
||||||
|
UnsignedVal = (u_int32_t)strtoul( ((UseTempStr)? TempStr : Value), NULL, 10 );
|
||||||
|
SetUnsignedValue( Param, UnsignedVal, Force );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dtSigned16 :
|
||||||
|
case dtSigned32 :
|
||||||
|
SignedVal = (u_int32_t)strtol( ((UseTempStr)? TempStr : Value), NULL, 10 );
|
||||||
|
SetUnsignedValue( Param, SignedVal, Force );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dtFloat32 :
|
||||||
|
FloatVal = (u_int32_t) strtof( ((UseTempStr)? TempStr : Value), NULL );
|
||||||
|
SetUnsignedValue( Param, FloatVal, Force );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear memory
|
||||||
|
if (UseTempStr) {
|
||||||
|
free( TempStr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool CDeviceCore::GetValue( TDeviceParam * Param, char * Value, int &Len )
|
||||||
|
{
|
||||||
|
// Validate
|
||||||
|
if (!Param || !Value)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check if return value longer than actual value
|
||||||
|
switch (Param->DataType)
|
||||||
|
{
|
||||||
|
case dtUnsigned16 :
|
||||||
|
sprintf( Value, "%u", (*((u_int16_t*)Param->Value)) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dtUnsigned32 :
|
||||||
|
sprintf( Value, "%u", (*((u_int32_t*)Param->Value)) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dtSigned16 :
|
||||||
|
sprintf( Value, "%d", (*((int16_t*)Param->Value)) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dtSigned32 :
|
||||||
|
sprintf( Value, "%d", (*((int32_t*)Param->Value)) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dtFloat32 :
|
||||||
|
sprintf( Value, "%f", (*((float*)Param->Value)) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dtString :
|
||||||
|
if (Len < Param->Len)
|
||||||
|
{
|
||||||
|
// Only copy requested no of chars
|
||||||
|
memcpy( Value, Param->Value, Len );
|
||||||
|
Value[ Len ] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy( Value, Param->Value, Param->Len );
|
||||||
|
Value[ Param->Len ] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool CDeviceCore::CompareParamString( const char * ParamValue, const int ParamLen, const char * Value, const int Len )
|
bool CDeviceCore::CompareParamString( const char * ParamValue, const int ParamLen, const char * Value, const int Len )
|
||||||
{
|
{
|
||||||
bool Match = true;
|
bool Match = true;
|
||||||
|
|||||||
12
DeviceCore.h
12
DeviceCore.h
@@ -95,13 +95,13 @@ protected:
|
|||||||
// Find Devices
|
// Find Devices
|
||||||
inline TDevice * GetDevice( const char * Name ) {
|
inline TDevice * GetDevice( const char * Name ) {
|
||||||
TDevice * Device = FirstDevice;
|
TDevice * Device = FirstDevice;
|
||||||
while (Device && strcmp( Device->Name, Name ))
|
while (Device && strcasecmp( Device->Name, Name ))
|
||||||
Device = Device->Next;
|
Device = Device->Next;
|
||||||
return Device;
|
return Device;
|
||||||
}
|
}
|
||||||
inline TDevice ** GetDevicePtr( const char * Name ) {
|
inline TDevice ** GetDevicePtr( const char * Name ) {
|
||||||
TDevice ** Device = &FirstDevice;
|
TDevice ** Device = &FirstDevice;
|
||||||
while (*Device && strcmp( (*Device)->Name, Name ))
|
while (*Device && strcasecmp( (*Device)->Name, Name ))
|
||||||
Device = &((*Device)->Next);
|
Device = &((*Device)->Next);
|
||||||
return Device;
|
return Device;
|
||||||
}
|
}
|
||||||
@@ -119,14 +119,14 @@ protected:
|
|||||||
inline TDeviceParam * GetDeviceParam( TDevice * Device, const char * Name ) {
|
inline TDeviceParam * GetDeviceParam( TDevice * Device, const char * Name ) {
|
||||||
if (!Device) return NULL;
|
if (!Device) return NULL;
|
||||||
TDeviceParam * Param = Device->FirstParam;
|
TDeviceParam * Param = Device->FirstParam;
|
||||||
while (Param && strcmp( Param->Name, Name ))
|
while (Param && strcasecmp( Param->Name, Name ))
|
||||||
Param = Param->Next;
|
Param = Param->Next;
|
||||||
return Param;
|
return Param;
|
||||||
}
|
}
|
||||||
inline TDeviceParam ** GetDeviceParamPtr( TDevice * Device, const char * Name ) {
|
inline TDeviceParam ** GetDeviceParamPtr( TDevice * Device, const char * Name ) {
|
||||||
if (!Device) return NULL;
|
if (!Device) return NULL;
|
||||||
TDeviceParam ** Param = &Device->FirstParam;
|
TDeviceParam ** Param = &Device->FirstParam;
|
||||||
while (*Param && strcmp( (*Param)->Name, Name ))
|
while (*Param && strcasecmp( (*Param)->Name, Name ))
|
||||||
Param = &((*Param)->Next);
|
Param = &((*Param)->Next);
|
||||||
return Param;
|
return Param;
|
||||||
}
|
}
|
||||||
@@ -196,6 +196,10 @@ public:
|
|||||||
bool SetSignedValue( TDeviceParam * Param, const int32_t Value, bool Force );
|
bool SetSignedValue( TDeviceParam * Param, const int32_t Value, bool Force );
|
||||||
bool SetFloatValue( TDeviceParam * Param, const float Value, bool Force );
|
bool SetFloatValue( TDeviceParam * Param, const float Value, bool Force );
|
||||||
bool SetStringValue( TDeviceParam * Param, const char * Value, const int Len, bool Force );
|
bool SetStringValue( TDeviceParam * Param, const char * Value, const int Len, bool Force );
|
||||||
|
|
||||||
|
// Text Interfaces
|
||||||
|
bool SetValue( TDeviceParam * Param, const char * Value, const int Len, bool Force );
|
||||||
|
bool GetValue( TDeviceParam * Param, char * Value, int &Len );
|
||||||
};
|
};
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
49
LogCore.cpp
49
LogCore.cpp
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
// redA Libraries
|
// redA Libraries
|
||||||
#include "LogCore.h"
|
#include "LogCore.h"
|
||||||
|
#include "DateTimeCore.h"
|
||||||
|
|
||||||
// Standard C/C++ Libraries
|
// Standard C/C++ Libraries
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -22,9 +23,9 @@ char LogStr[1000]; // Temporary var to create log messages,
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
CLogCore::CLogCore( FILE * pFileOutput )
|
CLogCore::CLogCore( FILE * pOutputFile )
|
||||||
{
|
{
|
||||||
FileOutput = pFileOutput;
|
OutputFile = pOutputFile;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -37,14 +38,19 @@ bool CLogCore::Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check debug level
|
// Check debug level
|
||||||
if (!FileOutput || (MsgLevel > DebugLevel)) {
|
if (!OutputFile || (MsgLevel > DebugLevel)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show normal output
|
// Show Date & Time
|
||||||
|
if (OutputFile->_fileno > 3) {
|
||||||
|
fprintf( OutputFile, "%s", GetDateTimeStr( "/", ":" ));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print formated message
|
||||||
va_start( ArgPtr, Format );
|
va_start( ArgPtr, Format );
|
||||||
vfprintf( FileOutput, Format, ArgPtr );
|
vfprintf( OutputFile, Format, ArgPtr );
|
||||||
fprintf( FileOutput, "\r\n" );
|
fprintf( OutputFile, "\r\n" );
|
||||||
va_end( ArgPtr );
|
va_end( ArgPtr );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -59,7 +65,7 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check debug level
|
// Check debug level
|
||||||
if (!FileOutput || (MsgLevel > DebugLevel)) {
|
if (!OutputFile || (MsgLevel > DebugLevel)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +73,15 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
if (Len == -1)
|
if (Len == -1)
|
||||||
Len = strlen( Buffer );
|
Len = strlen( Buffer );
|
||||||
|
|
||||||
|
// Show date & time
|
||||||
|
if (OutputFile->_fileno > 3) {
|
||||||
|
fprintf( OutputFile, "%s", GetDateTimeStr( "/", ":" ));
|
||||||
|
}
|
||||||
|
|
||||||
// Show Lead
|
// Show Lead
|
||||||
if (Format && *Format) {
|
if (Format && *Format) {
|
||||||
va_start( ArgPtr, Format );
|
va_start( ArgPtr, Format );
|
||||||
vfprintf( FileOutput, Format, ArgPtr );
|
vfprintf( OutputFile, Format, ArgPtr );
|
||||||
va_end( ArgPtr );
|
va_end( ArgPtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +89,11 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
if (Show & OUT_COUNT)
|
if (Show & OUT_COUNT)
|
||||||
{
|
{
|
||||||
// Print byte count
|
// Print byte count
|
||||||
fprintf( FileOutput, " [%d] ", Len );
|
fprintf( OutputFile, " [%d] ", Len );
|
||||||
|
|
||||||
// EOL if only count wanted
|
// EOL if only count wanted
|
||||||
if (Show & OUT_COUNT) {
|
if (Show & OUT_COUNT) {
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,25 +102,25 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
{
|
{
|
||||||
if (Show & OUT_ASIS) {
|
if (Show & OUT_ASIS) {
|
||||||
// Print entire buffer as is (line feeds included)
|
// Print entire buffer as is (line feeds included)
|
||||||
fprintf( FileOutput, "%s", Buffer );
|
fprintf( OutputFile, "%s", Buffer );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Ignore \r\n
|
// Ignore \r\n
|
||||||
for (int i=0; i<Len; i++) {
|
for (int i=0; i<Len; i++) {
|
||||||
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
|
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
|
||||||
if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n')))
|
if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n')))
|
||||||
fprintf( FileOutput, "%c", Buffer[i] );
|
fprintf( OutputFile, "%c", Buffer[i] );
|
||||||
else
|
else
|
||||||
fprintf( FileOutput, "." );
|
fprintf( OutputFile, "." );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf( FileOutput, "%c", Buffer[i] );
|
fprintf( OutputFile, "%c", Buffer[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add EOL if not present or ignored
|
// Add EOL if not present or ignored
|
||||||
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
|
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,9 +129,9 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
{
|
{
|
||||||
// Print Hex values of individual bytes
|
// Print Hex values of individual bytes
|
||||||
for (int i=0; i<Len; i++) {
|
for (int i=0; i<Len; i++) {
|
||||||
fprintf( FileOutput, "%02X ", (unsigned char)Buffer[i] );
|
fprintf( OutputFile, "%02X ", (unsigned char)Buffer[i] );
|
||||||
}
|
}
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show Binary output
|
// Show Binary output
|
||||||
@@ -128,10 +139,10 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
// Print each byte as 8-bit binary
|
// Print each byte as 8-bit binary
|
||||||
for (int i=0; i<Len; i++) {
|
for (int i=0; i<Len; i++) {
|
||||||
for (int j=0; j<8; j++) {
|
for (int j=0; j<8; j++) {
|
||||||
fprintf( FileOutput, "%d", (bool)((Buffer[i] << j) & 0x80) );
|
fprintf( OutputFile, "%d", (bool)((Buffer[i] << j) & 0x80) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ typedef enum { dlNone = 0, dlLow = 1, dlMedium = 2, dlHigh = 3 } EDebugLevel;
|
|||||||
class CLogCore
|
class CLogCore
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
FILE * FileOutput;
|
FILE * OutputFile;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CLogCore( FILE * pFileOutput );
|
CLogCore( FILE * pOutputFile );
|
||||||
|
|
||||||
bool Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Format, ... );
|
bool Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Format, ... );
|
||||||
bool Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show, const char * Buffer, int Len, const char * Format, ... );
|
bool Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show, const char * Buffer, int Len, const char * Format, ... );
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* Author: wentzelc
|
* Author: wentzelc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// redA Librarie
|
// redA Libraries
|
||||||
#include "TimingCore.h"
|
#include "TimingCore.h"
|
||||||
|
|
||||||
// Standard C/C++ Libraries
|
// Standard C/C++ Libraries
|
||||||
@@ -64,3 +64,4 @@ bool Timeout( timeval StartTime, long MilliSeconds )
|
|||||||
return ((TimePassed(StartTime) > MilliSeconds)? true : false);
|
return ((TimePassed(StartTime) > MilliSeconds)? true : false);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user