rusefi-1/firmware/util/datalogging.h

104 lines
2.7 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file datalogging.h
* @brief Buffered console output stream header
*
* @date Feb 25, 2013
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*/
#ifndef DATALOGGING_H_
#define DATALOGGING_H_
#include <stdarg.h>
2018-09-16 19:00:14 -07:00
#include <stdint.h>
2015-07-10 06:01:56 -07:00
#define DELIMETER ","
// todo: migrate to external buffer so that different instances have different
// size of buffers?
class Logging {
public:
Logging();
Logging(const char *name, char *buffer, int bufferSize);
2018-08-31 18:38:14 -07:00
void initLoggingExt(const char *name, char *buffer, int bufferSize);
2018-08-31 19:30:03 -07:00
void vappendPrintf(const char *fmt, va_list arg);
2018-08-31 18:38:14 -07:00
void append(const char *text);
void appendFast(const char *text);
void appendPrintf(const char *fmt, ...);
2019-10-07 22:26:35 -07:00
const char *name = nullptr;
2015-07-10 06:01:56 -07:00
char SMALL_BUFFER[40];
/**
* Zero-terminated buffer of pending debug message
*
* Unless a larger external buffer is specified, this is just a pointer to DEFAULT_BUFFER
*/
2019-10-07 22:26:35 -07:00
char *buffer = nullptr;
2015-07-10 06:01:56 -07:00
/**
* This pointer is always pointing at the position within the buffer into which next
* write operation would append additional data
*/
2019-10-07 22:26:35 -07:00
char *linePointer = nullptr;
int bufferSize = 0;
volatile bool isInitialized = false;
2015-07-10 06:01:56 -07:00
};
class LoggingWithStorage : public Logging {
public:
explicit LoggingWithStorage(const char *name);
2015-07-10 06:01:56 -07:00
char DEFAULT_BUFFER[200];
};
void initIntermediateLoggingBuffer(void);
int isInitialized(Logging *logging);
void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize);
void debugInt(Logging *logging, const char *caption, int value);
void debugFloat(Logging *logging, const char *text, float value, int precision);
void appendFloat(Logging *logging, float value, int precision);
void resetLogging(Logging *logging);
void appendMsgPrefix(Logging *logging);
void appendMsgPostfix(Logging *logging);
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
2017-06-07 18:26:32 -07:00
#define lockOutputBuffer lockAnyContext
#define unlockOutputBuffer unlockAnyContext
2015-07-10 06:01:56 -07:00
uint32_t remainingSize(Logging *logging);
#define loggingSize(logging) ((int) (logging)->linePointer - (int) ((logging)->buffer))
void printMsg(Logging *logging, const char *fmt, ...);
void appendPrintf(Logging *logging, const char *fmt, ...);
void append(Logging *logging, const char *text);
void appendFast(Logging *logging, const char *text);
/**
* This macro breaks the normal zero=termination constraint, please take care of this outside of this macro
*/
#define appendChar(logging, symbol) {(logging)->linePointer[0] = (symbol);(logging)->linePointer++;}
/**
* this method copies the line into the intermediate buffer for later output by
* the main thread
*/
void scheduleLogging(Logging *logging);
#ifdef __cplusplus
}
#endif /* __cplusplus */
void printWithLength(char *line);
#endif /* DATALOGGING_H_ */