forked from dingo35/SmartEVSE-3.5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolar_debug_json.c
More file actions
51 lines (46 loc) · 1.39 KB
/
solar_debug_json.c
File metadata and controls
51 lines (46 loc) · 1.39 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
/*
* solar_debug_json.c - Format evse_solar_debug_t as JSON
*
* Pure C module — no platform dependencies, testable natively.
*/
#include "solar_debug_json.h"
#include <stdio.h>
int solar_debug_to_json(const evse_solar_debug_t *snap, char *buf, size_t bufsz)
{
if (!snap || !buf || bufsz == 0)
return -1;
int n = snprintf(buf, bufsz,
"{"
"\"IsetBalanced\":%d,"
"\"IsetBalanced_ema\":%d,"
"\"Idifference\":%d,"
"\"IsumImport\":%d,"
"\"Isum\":%d,"
"\"MainsMeterImeasured\":%d,"
"\"Balanced0\":%u,"
"\"SolarStopTimer\":%u,"
"\"PhaseSwitchTimer\":%u,"
"\"PhaseSwitchHoldDown\":%u,"
"\"NoCurrent\":%u,"
"\"SettlingTimer\":%u,"
"\"Nr_Of_Phases_Charging\":%u,"
"\"ErrorFlags\":%u"
"}",
(int)snap->IsetBalanced,
(int)snap->IsetBalanced_ema,
(int)snap->Idifference,
(int)snap->IsumImport,
(int)snap->Isum,
(int)snap->MainsMeterImeasured,
(unsigned)snap->Balanced0,
(unsigned)snap->SolarStopTimer,
(unsigned)snap->PhaseSwitchTimer,
(unsigned)snap->PhaseSwitchHoldDown,
(unsigned)snap->NoCurrent,
(unsigned)snap->SettlingTimer,
(unsigned)snap->Nr_Of_Phases_Charging,
(unsigned)snap->ErrorFlags);
if (n < 0 || (size_t)n >= bufsz)
return -1;
return n;
}