-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.h
More file actions
365 lines (303 loc) · 10.9 KB
/
logging.h
File metadata and controls
365 lines (303 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/**
* \addtogroup logging
* @{
*
* \author Lukas Kempf
* \brief Logging entries and message and queue2file handling
*
*
*
*
*/
//*****************************************************************************
//
// logging.h - Prototypes for handling log files
//
//*****************************************************************************
#ifndef LOGGING_H_
#define LOGGING_H_
#include <string.h>
#include <time.h>
#include "sysdefs.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "fatfs/ff.h"
//*****************************************************************************
//
/// Defines path to the log file
//
//*****************************************************************************
#define LOG_FILE_PATH "log/sys.log"
/* for getLogfilename(x,y) */
#define contLog 0
#define dayLog 1
#define monthLog 2
#define allTimeSummary 3
#if CFG_LCD == 1
/* special characters for LCD */
#define charANTENNA 0x95
#define charDEGREES 0x80
#define numberOfReportScreens 12
#endif
//*****************************************************************************
//
/// global pointer to the log file
//
//*****************************************************************************
FIL* log_file;
/** Opens the log file (path defined as LOG_FILE_PATH) and
* sets file pointer to the end of file
*/
FRESULT initLog();
/**
* Appends the message to the log file and adds the current time
*
*/
FRESULT appendToLog(char *msg);
/** Task functions */
void loggingDoSomething(void);
signed portBASE_TYPE loggingStart (void);
signed portBASE_TYPE loggingStop (void);
/**
* single Log entry item structure
*
* { Date/Time; Wind Direction [0-359°N]; Wind velocity [m/s]; }
*
*/
volatile typedef struct
{
/* sizeof (_SLOG_ENTRY_ITEM = (19+1)+2+2+2+2+2+2 = 32 */
//char datetime[20]; /* YYYY-MM-DD_HH-mm(24h)-ss'\0' */
time_t datetime;
unsigned short winddirection; /* Value 0-Aref(3300) [0-359°N] */
unsigned short windspeed; /* summed-up over a whole day */
} /* __attribute__ ((packed)) */ _SLOG_ENTRY_ITEM;
_SLOG_ENTRY_ITEM slog_entry_item;
#define _SLOG_ENTRY_ITEM_SIZE 32
/**
* continuous(24h-DayLong) Log entry item structure
*
* { Date/Time; ADC1 [°C]; ADC2 [°C]; ADC3 [°C]; ADC4 [°C]; Volumenstrom [l/s]; }
*
*/
#ifdef logCDaySummary
volatile typedef struct
{
time_t last_update; /* YYYY-MM-DD_HH(24h)-mm-ss+'\0' */
unsigned short sum_flowtime; /* pumptime[s] */
float sum_flowvolume; /* Value 0-int l */
unsigned short sum_energy; /* Value in Ws */
unsigned short sum_profit; /* Value in Rappen */
} /* __attribute__ ((packed)) */ _CDAYLOG_ENTRY_ITEM;
_CDAYLOG_ENTRY_ITEM cdaylog_entry_item;
#define _CDAYLOG_ENTRY_ITEM_SIZE 29
#endif
/**
* continuous Log entry item structure
*
* { Date/Time; ADC1 [°C]; ADC2 [°C]; ADC3 [°C]; ADC4 [°C]; Volumenstrom [l/s]; }
*
*/
#ifdef logAllTimeSummary
volatile typedef struct
{
char last_update[20]; /* YYYY-MM-DD;HH(24h)-mm-ss+'\0' */
//unsigned short sum_count_days; /* how long the structure is logging */
unsigned long sum_flowtime; /* pumptime[s] */
unsigned long sum_flowvolume; /* Value 0-int l */
unsigned long sum_energy; /* Value in Ws */
unsigned long sum_profit; /* Value in Rappen */
unsigned short arithm_day_flowtime; /* pumptime[s]/day */
unsigned short arithm_day_flowvolume; /* Value 0-int l */
unsigned short arithm_day_energy; /* Value in Ws */
unsigned short arithm_day_profit; /* Value in Rappen */
} /* __attribute__ ((packed)) */ _CLOG_ENTRY_ITEM;
//_CLOG_ENTRY_ITEM cmonthlog_entry_item, cyearlog_entry_item, ctotallog_entry_item;
_CLOG_ENTRY_ITEM clog_entry_item;
#define _CLOG_ENTRY_ITEM_SIZE 52
#endif
//void fillSlogEntryItem(char *datetime, unsigned short adc1, unsigned short adc2, unsigned short adc3, unsigned short adc4/*, unsigned short flowrate*/);
//void fillSlogEntryItem(time_t datetime, unsigned short adc1, unsigned short adc2, unsigned short adc3, unsigned short adc4/*, unsigned short flowrate*/); --> the struct tm ts is already global, no need to give it as a parameter
//void fillSlogEntryItem(unsigned short winddirection, unsigned short windvelocity);
void fillSlogEntryItem(unsigned short winddirection, unsigned short winddirection_max, unsigned short windspeed);
void getLogFilename(char log, char *filename);
static float WhPriceRappen; // price of a Wh in CHRp.
void setWhPrice(float WsRappen);
static float getWhPriceRappen(void);
void getDateTime(char *datetime);
void trackLog(void);
signed portBASE_TYPE trackLogTaskStart (void);
signed portBASE_TYPE trackLogTaskStop (void);
/* SD Card Variables */
FATFS Fatfs[_DRIVES]; /* File system object for each logical drive */
FIL FileContLog, FileDayLog, /*FileMonthLog,*/ FileAllTimeLog; /* File objects */
/** Filenames of the Log files:
* [0] : FileContLog: "YYYY-contLog.txt" (16+1 chars) ->> "YYYY" (to save space -> just the year will be saved)
* [1] : FileDayLog: "YYYY-dayLog.txt" (15+1 chars) ->> "YYYY" (to save space -> just the year will be saved)
* [2] : FileMonthLog: "YYYY-monthLog.txt" (17+1 chars) ->> "YYYY-MM" (to save space -> just the year and month will be saved) ->> (8)
* [3] : FileAllTimeLog: "alltime.txt" (11+1 chars)
*/
static char logFilename[18];
static volatile float __windFrequency=0;
void setWindFrequency(short value);
int getWindSpeed(void);
int getWindFrequency(void);
void clrWindFrequency(void);
void incr_SumFlowvolume(void);
static volatile unsigned short daysLogging; /** counts the days the system is logging. Is going to be increment for the following day at 23.55h */
unsigned short incr_daysLogging(void);
void init_daysLogging(void);
void updateCDayLogEntryItem(void);
void updateCLogEntryItem(void);
#if CFG_LCD == 1
/**********************************************************************************************************************
******************* LCD Routines *************************************************************************************
**********************************************************************************************************************/
//void b_itoab(char **buf, DWORD i, unsigned int base);
void b_itoab(char **buf, DWORD i);
char nrOfDigits(int i, int base);
void feedLCD(void);
static unsigned char actReportScreen = 0;
/** [12]: number of screens
* [4]: number of rows
* [20]: Text-Template without variable values to be written on screen
*/
static const char reportScreen[12][4][20] = {
// {"aktuelle Werte 1/2 ", // screen 0
// "aktiv seit : h",
// "Panel %3d C",
// "Rücklauf %3d C"},
//
// {"aktuelle Werte 2/2 ", // 1
// "Boiler oben %3d C",
// "Boiler unten %3d C",
// "Durchfluss %2dl/s"},
{"aktuelle Werte 1/2 ", // screen 0
"aktiv seit : h",
"Panel 0 C",
"Rücklauf 0 C"},
{"aktuelle Werte 2/2 ", // 1
"Boiler oben 0 C",
"Boiler unten 0 C",
"Durchfluss 0l/s"},
{"Tageswerte 1/2 ", // 2
"Laufzeit %3d ' ",
"umges. Vol. %3d l ",
"Energie %3d Wh"},
{"Tageswerte 2/2 ", // 3
"Leistung %3d W ",
"Profit %3d Fr",
" "},
{"Monatswerte 1/3 ", // 4
"Messtage d ",
"Laufzeit h m ",
"Energie Wh"},
{"Monatswerte 2/3 ", // 5
"Volumen l ",
"Profit Fr",
"Mw tPumpe/T m "},
{"Monatswerte 3/3 ", // 6
"Mw Volumen/T l ",
"Mw Energie/T Wh",
"Mw Profit/T Fr"},
{"kont. Log 1/3 ", // 7
"Messtage d ",
"Laufzeit h m ",
"Energie Wh"},
{"kont. Log 2/3 ", // 8
"Volumen l ",
"Profit Fr",
"Mw tPumpe/T m "},
{"kont. Log 3/3 ", // 9
"Mw Volumen/T l ",
"Mw Energie/T Wh",
"Mw Profit/T Fr"},
{"if no one else can ", // Werbung / Startup 1/2 (knacksen aus Lautsprecher)
"help, and if you can",
"find them, may be ",
"you can hire... "},
{" the ", // Werbung / Startup 2/2 (opening title)
" ",
" A-TEAM ",
" "}
/*(Ten years ago / In 1972), a crack commando unit was sent to prison by a military court
for a crime they didn't commit. These men promptly escaped from a maximum security stockade
to the Los Angeles underground. Today, still wanted by the government, they survive as soldiers
of fortune. If you have a problem, if no one else can help, and if you can find them, maybe you can hire...
The A-Team.*/
};
//static const char AUSWERTUNGSBILDSCHIRME[40][20];
/** [12]: number of screens
* [4]: number of rows
* [2]: [0]: at which column the first/least valuable letter of the number is located
* [1]: number format of float
*/
static const float reportScreenConfig[12][4][2] = {
{ 0 ,0, // screen 0
14, 5.2,
16, 3,
16, 3},
{ 0, 0, // 1
16, 3,
16, 3,
16, 3,},
{ 0, 0, // 2
16, 3,
16, 3,
14, 5.1},
{ 0, 0, // 3
14, 5.1,
16, 3,
0, 0},
{ 0, 0, // 4
16, 3,
15, 4,
14, 5.1},
{ 0, 0, // 5
15, 4,
16, 3,
16, 3},
{ 0, 0, // 6
16, 3,
16, 3,
16, 3,},
{ 0, 0, // 7
16, 3,
16, 3,
14, 5.1,},
{ 0, 0, // 8
15, 4,
16, 3,
16, 3},
{ 0, 0, // 9
16, 3,
16, 3,
16, 3,},
{ 0, 0, // Werbung / Startup 1/2 (knacksen aus Lautsprecher)
0, 0,
0, 0,
0, 0,},
{ 0, 0, // Werbung / Startup 2/2 (opening title)
0, 0,
0, 0,
0, 0,},
};
//if(slog_entry_item.val_adc1 == 0)
// buf[(int)(reportScreenConfig[0][2][0])] = '0';
//else {
// b_itoab(*numberAsChar, slog_entry_item.val_adc1);
// for(count=0; count < nrOfDigits(slog_entry_item.val_adc1, 10); count++) {
// buf[(int)(reportScreenConfig[0][2][0] - count)] = numberAsChar[count];
// }
//}
#define FILL_BUF_WITH_VALUES(value, position) { if(value != 0) { b_itoab(*numberAsChar, value); for(count=0; count < nrOfDigits(value, 10); count++) { buf[(int)(position - count)] = numberAsChar[count]; } } strcpy(numberAsChar, " "); }
void luk_strcpy(char *to, char *from, char howMany);
#endif // #if CFG_LCD == 1
#endif
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************