forked from hidaba/PylontechMonitoring
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpy_parser_task.cpp
More file actions
107 lines (86 loc) · 3.01 KB
/
Copy pathpy_parser_task.cpp
File metadata and controls
107 lines (86 loc) · 3.01 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
#include "py_uart.h"
#include "py_log.h"
#include "config.h"
#include "py_parser.h"
extern PyUart py_uart;
extern QueueHandle_t frameQueue;
/*
* Parser Task
* -----------
* Reads frames from the UART frame queue and dispatches them
* to the corresponding parser (PWR / BAT / STAT).
*
* All parsers use RAM‑optimized global tables:
* - PWR → pwrTable
* - BAT → batTable
* - STAT → statTable
*
* The raw frame content is always taken from py_uart.getLastRawFrame().
*/
void parserTask(void* param)
{
UartFrame f;
while (true)
{
// Wait for next UART frame
if (xQueueReceive(frameQueue, &f, portMAX_DELAY) != pdPASS)
continue;
// Always fetch raw frame directly from UART
String raw = py_uart.getLastRawFrame();
Log(LOG_DEBUG,
"parserTask: FRAME received type=" + String(f.type) +
" len=" + String(raw.length()));
if (!py_uart.isFrameValid()) {
Log(LOG_WARN, "parserTask: frame invalid → skip");
vTaskDelay(5);
continue;
}
// ---------------------------------------------------------
// PWR FRAME
// ---------------------------------------------------------
if (f.type == FRAME_PWR)
{
Log(LOG_DEBUG, "parserTask: PWR frame");
ParseResult r = parsePwrFrame(raw);
if (r == PARSE_OK)
{
// Signal that new PWR data is available
parserHasData = true;
// Prepare module publishing
pwrFrameReady = true;
pwrCurrentModule = 0;
pwrTotalModules = pwrTable.rows;
}
Log(LOG_DEBUG, "parserTask: parsePwrFrame -> " + String(r));
}
// ---------------------------------------------------------
// BAT FRAME
// ---------------------------------------------------------
else if (f.type == FRAME_BAT)
{
Log(LOG_DEBUG, "parserTask: BAT frame");
ParseResult r = parseBatFrame(f.module, raw);
if (r == PARSE_OK)
{
batParserHasData = true;
batParserModuleIndex = f.module;
}
Log(LOG_DEBUG, "parserTask: parseBatFrame -> " + String(r));
}
// ---------------------------------------------------------
// STAT FRAME
// ---------------------------------------------------------
else if (f.type == FRAME_STAT)
{
Log(LOG_DEBUG, "parserTask: STAT frame");
ParseResult r = parseStatFrame(f.module, raw);
if (r == PARSE_OK)
{
statParserHasData = true;
statParserModuleIndex = f.module;
}
Log(LOG_DEBUG, "parserTask: parseStatFrame -> " + String(r));
}
vTaskDelay(5);
}
}