rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
datalogging.h
Go to the documentation of this file.
1/**
2 * @file datalogging.h
3 * @brief Buffered console output stream header
4 *
5 * @date Feb 25, 2013
6 * @author Andrey Belomutskiy, (c) 2012-2020
7 */
8
9#pragma once
10
11#include <cstdarg>
12#include <cstdint>
13#include <cstddef>
14
15// todo: migrate to external buffer so that different instances have different
16// size of buffers?
17class Logging {
18public:
19 Logging() = delete;
20 Logging(const char *name, char *buffer, int bufferSize);
21
22 void reset();
23
24 void append(const char *text);
25 void appendFast(const char *text);
26 void appendPrintf(const char *fmt, ...)
27 #if EFI_PROD_CODE
28 __attribute__ ((format (printf, 2, 3)))
29 #endif
30 ;
31 void appendFloat(float value, int precision);
32
33 void terminate() {
34 linePointer[0] = '\0';
35 }
36
37 /**
38 * This macro breaks the normal zero=termination constraint, please take care of this outside of this function
39 */
40 void appendChar(char c) {
41 *linePointer = c;
43 }
44
45 size_t loggingSize() const {
46 return (uintptr_t)linePointer - (uintptr_t)buffer;
47 }
48
49 size_t remainingSize() const {
50 return bufferSize - loggingSize();
51 }
52
53//private:
54 bool validateBuffer(uint32_t extraLen);
55
56 const char* const name = nullptr;
57
58 /**
59 * Zero-terminated buffer of pending debug message
60 *
61 * Unless a larger external buffer is specified, this is just a pointer to DEFAULT_BUFFER
62 */
63 char* const buffer = nullptr;
64 const int bufferSize = 0;
65
66 /**
67 * This pointer is always pointing at the position within the buffer into which next
68 * write operation would append additional data
69 */
70 char *linePointer = nullptr;
71};
72
74public:
75 explicit LoggingWithStorage(const char *name);
76 char DEFAULT_BUFFER[100];
77};
78
79void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize);
typedef __attribute__
Ignition Mode.
void appendFast(const char *text)
void appendChar(char c)
Definition datalogging.h:40
const char *const name
Definition datalogging.h:56
void void appendFloat(float value, int precision)
size_t remainingSize() const
Definition datalogging.h:49
void terminate()
Definition datalogging.h:33
size_t loggingSize() const
Definition datalogging.h:45
void reset()
char * linePointer
Definition datalogging.h:70
char *const buffer
Definition datalogging.h:63
Logging()=delete
void appendPrintf(const char *fmt,...) __attribute__((format(printf
const int bufferSize
Definition datalogging.h:64
char DEFAULT_BUFFER[100]
Definition datalogging.h:76
void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize)
static BigBufferHandle buffer
printf("\n")