Skip to content

Commit ed16605

Browse files
committed
initial commit
0 parents  commit ed16605

File tree

89 files changed

+4648
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4648
-0
lines changed

Logging.cpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#include "Logging.h"
2+
3+
Logging::Logging(int level, long baud) {
4+
_level = constrain(level,LOG_LEVEL_NOOUTPUT,LOG_LEVEL_VERBOSE);
5+
_baud = baud;
6+
}
7+
8+
9+
void Logging::Init(){
10+
Serial.begin(_baud);
11+
}
12+
13+
void Logging::Error(char* msg, ...){
14+
if (LOG_LEVEL_ERRORS <= _level) {
15+
print ("ERROR: ",0);
16+
va_list args;
17+
va_start(args, msg);
18+
print(msg,args);
19+
}
20+
}
21+
22+
#if LOGLEVEL >= LOG_LEVEL_INFOS
23+
void Logging::Info(char* msg, ...){
24+
if (LOG_LEVEL_INFOS <= _level) {
25+
va_list args;
26+
va_start(args, msg);
27+
print(msg,args);
28+
}
29+
}
30+
31+
#if LOGLEVEL >= LOG_LEVEL_DEBUG
32+
void Logging::Debug(char* msg, ...){
33+
if (LOG_LEVEL_DEBUG <= _level) {
34+
va_list args;
35+
va_start(args, msg);
36+
print(msg,args);
37+
}
38+
}
39+
40+
#if LOGLEVEL >= LOG_LEVEL_VERBOSE
41+
void Logging::Verbose(char* msg, ...){
42+
if (LOG_LEVEL_VERBOSE <= _level) {
43+
va_list args;
44+
va_start(args, msg);
45+
print(msg,args);
46+
}
47+
}
48+
#endif // LOG_LEVEL_VERBOSE
49+
#endif // LOG_LEVEL_DEBUG
50+
#endif // LOG_LEVEL_INFOS
51+
52+
53+
void Logging::print(const char *format, va_list args) {
54+
//
55+
// loop through format string
56+
for (; *format != 0; ++format) {
57+
if (*format == '%') {
58+
++format;
59+
if (*format == '\0') break;
60+
if (*format == '%') {
61+
Serial.print(*format);
62+
continue;
63+
}
64+
if( *format == 's' ) {
65+
register char *s = (char *)va_arg( args, int );
66+
Serial.print(s);
67+
continue;
68+
}
69+
if( *format == 'd' || *format == 'i') {
70+
Serial.print(va_arg( args, int ),DEC);
71+
continue;
72+
}
73+
if( *format == 'x' ) {
74+
Serial.print(va_arg( args, int ),HEX);
75+
continue;
76+
}
77+
if( *format == 'X' ) {
78+
Serial.print("0x");
79+
Serial.print(va_arg( args, int ),HEX);
80+
continue;
81+
}
82+
if( *format == 'b' ) {
83+
Serial.print(va_arg( args, int ),BIN);
84+
continue;
85+
}
86+
if( *format == 'B' ) {
87+
Serial.print("0b");
88+
Serial.print(va_arg( args, int ),BIN);
89+
continue;
90+
}
91+
if( *format == 'l' ) {
92+
Serial.print(va_arg( args, long ),DEC);
93+
continue;
94+
}
95+
96+
if( *format == 'c' ) {
97+
Serial.print(va_arg( args, int ));
98+
continue;
99+
}
100+
if( *format == 't' ) {
101+
if (va_arg( args, int ) == 1) {
102+
Serial.print("T");
103+
}
104+
else {
105+
Serial.print("F");
106+
}
107+
continue;
108+
}
109+
if( *format == 'T' ) {
110+
if (va_arg( args, int ) == 1) {
111+
Serial.print("true");
112+
}
113+
else {
114+
Serial.print("false");
115+
}
116+
continue;
117+
}
118+
119+
}
120+
Serial.print(*format);
121+
}
122+
}
123+
124+
125+
126+
127+
128+
129+
130+
131+

Logging.h

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#ifndef LOGGING_H
2+
#define LOGGING_H
3+
#include <inttypes.h>
4+
#include <stdarg.h>
5+
#if defined(ARDUINO) && ARDUINO >= 100
6+
#include "Arduino.h"
7+
#else
8+
#include "WProgram.h"
9+
#endif
10+
//#include "pins_arduino.h"
11+
extern "C" {
12+
#include <avr/io.h>
13+
}
14+
15+
16+
#define LOG_LEVEL_NOOUTPUT 0
17+
#define LOG_LEVEL_ERRORS 1
18+
#define LOG_LEVEL_INFOS 2
19+
#define LOG_LEVEL_DEBUG 3
20+
#define LOG_LEVEL_VERBOSE 4
21+
22+
// default loglevel if nothing is set from user
23+
#define LOGLEVEL LOG_LEVEL_DEBUG
24+
25+
26+
#define CR "\r\n"
27+
#define LOGGING_VERSION 1
28+
29+
/*!
30+
* Logging is a helper class to output informations over
31+
* RS232. If you know log4j or log4net, this logging class
32+
* is more or less similar ;-) <br>
33+
* Different loglevels can be used to extend or reduce output
34+
* All methods are able to handle any number of output parameters.
35+
* All methods print out a formated string (like printf).<br>
36+
* To reduce output and program size, reduce loglevel.
37+
* <br>
38+
* Output format string can contain below wildcards. Every wildcard
39+
* must be start with percent sign (\%)
40+
*
41+
* <b>Depending on loglevel, source code is excluded from compile !</b><br>
42+
* <br>
43+
* <b>Wildcards</b><br>
44+
* <ul>
45+
* <li><b>\%s</b> replace with an string (char*)</li>
46+
* <li><b>\%c</b> replace with an character</li>
47+
* <li><b>\%d</b> replace with an integer value</li>
48+
* <li><b>\%l</b> replace with an long value</li>
49+
* <li><b>\%x</b> replace and convert integer value into hex</li>
50+
* <li><b>\%X</b> like %x but combine with <b>0x</b>123AB</li>
51+
* <li><b>\%b</b> replace and convert integer value into binary</li>
52+
* <li><b>\%B</b> like %x but combine with <b>0b</b>10100011</li>
53+
* <li><b>\%t</b> replace and convert boolean value into <b>"t"</b> or <b>"f"</b></li>
54+
* <li><b>\%T</b> like %t but convert into <b>"true"</b> or <b>"false"</b></li>
55+
* </ul><br>
56+
* <b>Loglevels</b><br>
57+
* <table border="0">
58+
* <tr><td>0</td><td>LOG_LEVEL_NOOUTPUT</td><td>no output </td></tr>
59+
* <tr><td>1</td><td>LOG_LEVEL_ERRORS</td><td>only errors </td></tr>
60+
* <tr><td>2</td><td>LOG_LEVEL_INFOS</td><td>errors and info </td></tr>
61+
* <tr><td>3</td><td>LOG_LEVEL_DEBUG</td><td>errors, info and debug </td></tr>
62+
* <tr><td>4</td><td>LOG_LEVEL_VERBOSE</td><td>all </td></tr>
63+
* </table>
64+
*/
65+
class Logging {
66+
private:
67+
int _level;
68+
long _baud;
69+
public:
70+
/*!
71+
* Constructor
72+
* initialize loglevel and set baud rate
73+
* \param level possible loglevel between 0 - 4
74+
* \param baud baudrate for RS232
75+
* \return
76+
*
77+
*/
78+
Logging(int level, long baud) ;
79+
80+
/**
81+
* Initializing, must be called as first.
82+
* \param void
83+
* \return void
84+
*
85+
*/
86+
void Init();
87+
88+
/**
89+
* Output an error message. Output message contains
90+
* ERROR: followed by original msg
91+
* Error messages are printed out, at every loglevel
92+
* except 0 ;-)
93+
* \param msg format string to output
94+
* \param ... any number of variables
95+
* \return void
96+
*/
97+
void Error(char* msg, ...);
98+
99+
/**
100+
* Output an info message. Output message contains
101+
* Info messages are printed out at l
102+
* loglevels >= LOG_LEVEL_INFOS
103+
*
104+
* \param msg format string to output
105+
* \param ... any number of variables
106+
* \return void
107+
*/
108+
#if LOGLEVEL >= LOG_LEVEL_INFOS
109+
void Info(char* msg, ...);
110+
111+
/**
112+
* Output an debug message. Output message contains
113+
* Debug messages are printed out at l
114+
* loglevels >= LOG_LEVEL_DEBUG
115+
*
116+
* \param msg format string to output
117+
* \param ... any number of variables
118+
* \return void
119+
*/
120+
#if LOGLEVEL >= LOG_LEVEL_DEBUG
121+
void Debug(char* msg, ...);
122+
123+
/**
124+
* Output an verbose message. Output message contains
125+
* Debug messages are printed out at l
126+
* loglevels >= LOG_LEVEL_VERBOSE
127+
*
128+
* \param msg format string to output
129+
* \param ... any number of variables
130+
* \return void
131+
*/
132+
#if LOGLEVEL >= LOG_LEVEL_VERBOSE
133+
void Verbose(char* msg, ...);
134+
#endif // LOG_LEVEL_VERBOSE
135+
#endif // LOG_LEVEL_DEBUG
136+
#endif // LOG_LEVEL_INFOS
137+
138+
private:
139+
void print(const char *format, va_list args);
140+
};
141+
#endif
142+
143+
144+
145+

Logging_WikiPage.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
%define=box block bgcolor=#dddddd border="2px dotted white"%
2+
%define=wbox block bgcolor=#eeeeee color=#000000 border="1px dotted black" padding="2px"%
3+
4+
5+
%wbox%[@Logging library for Arudino
6+
by LunaX - 2010/2011
7+
@]%%
8+
9+
!CURRENT VERSION
10+
11+
0.8)14-FEB-2012 beta version.
12+
13+
!HISTORY
14+
15+
0.8) 14-FEB-2012 Initial Release\\
16+
17+
18+
!DESCRIPTION
19+
Easy to use logging library, like log4j or log4net. After getting a logger object, you will have
20+
methods like Error, Info, Warn, Debug, Verbose to log informations over RS232.
21+
Depending on the current loglevel lower logleves are not printed out.
22+
It is possible to work with variable argument lists during output.
23+
24+
!HOW TO IMPORT/INSTALL
25+
Download here: [[Attach:Enerlib.zip|Enerlib 1.0.0]]
26+
27+
Put the Logging folder in "libraries\".
28+
29+
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Logging".
30+
Once the library is imported, a "#include <Logging.h>" line will appear at the top of your Sketch.
31+
32+
!Methods
33+
!!void Error(
34+
35+
!Loglevels
36+
37+
!Example
38+
For more examples look into sub folder examples
39+
40+
41+
@]%%

doc/doxygen_objdb_4636.tmp

Whitespace-only changes.

0 commit comments

Comments
 (0)