| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 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? | |||
| 17 | class Logging { | |||
| 18 | public: | |||
| 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 | 26972 | void terminate() { | ||
| 34 | 26972 | linePointer[0] = '\0'; | ||
| 35 | 26972 | } | ||
| 36 | ||||
| 37 | /** | |||
| 38 | * This macro breaks the normal zero=termination constraint, please take care of this outside of this function | |||
| 39 | */ | |||
| 40 | 80916 | void appendChar(char c) { | ||
| 41 | 80916 | *linePointer = c; | ||
| 42 | 80916 | linePointer++; | ||
| 43 | 80916 | } | ||
| 44 | ||||
| 45 | 27556 | size_t loggingSize() const { | ||
| 46 | 27556 | return (uintptr_t)linePointer - (uintptr_t)buffer; | ||
| 47 | } | |||
| 48 | ||||
| 49 | 27556 | size_t remainingSize() const { | ||
| 50 | 27556 | 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 | ||||
| 73 | class LoggingWithStorage : public Logging { | |||
| 74 | public: | |||
| 75 | explicit LoggingWithStorage(const char *name); | |||
| 76 | char DEFAULT_BUFFER[100]; | |||
| 77 | }; | |||
| 78 | ||||
| 79 | void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize); | |||
| 80 |