forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadingContext.cpp
More file actions
65 lines (58 loc) · 2.13 KB
/
ReadingContext.cpp
File metadata and controls
65 lines (58 loc) · 2.13 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <string.h>
#include <MicroOcpp/Model/Metering/ReadingContext.h>
#include <MicroOcpp/Debug.h>
namespace MicroOcpp {
const char *serializeReadingContext(ReadingContext context) {
switch (context) {
case (ReadingContext_InterruptionBegin):
return "Interruption.Begin";
case (ReadingContext_InterruptionEnd):
return "Interruption.End";
case (ReadingContext_Other):
return "Other";
case (ReadingContext_SampleClock):
return "Sample.Clock";
case (ReadingContext_SamplePeriodic):
return "Sample.Periodic";
case (ReadingContext_TransactionBegin):
return "Transaction.Begin";
case (ReadingContext_TransactionEnd):
return "Transaction.End";
case (ReadingContext_Trigger):
return "Trigger";
default:
MO_DBG_ERR("ReadingContext not specified");
/* fall through */
case (ReadingContext_UNDEFINED):
return "";
}
}
ReadingContext deserializeReadingContext(const char *context) {
if (!context) {
MO_DBG_ERR("Invalid argument");
return ReadingContext_UNDEFINED;
}
if (!strcmp(context, "Sample.Periodic")) {
return ReadingContext_SamplePeriodic;
} else if (!strcmp(context, "Sample.Clock")) {
return ReadingContext_SampleClock;
} else if (!strcmp(context, "Transaction.Begin")) {
return ReadingContext_TransactionBegin;
} else if (!strcmp(context, "Transaction.End")) {
return ReadingContext_TransactionEnd;
} else if (!strcmp(context, "Other")) {
return ReadingContext_Other;
} else if (!strcmp(context, "Interruption.Begin")) {
return ReadingContext_InterruptionBegin;
} else if (!strcmp(context, "Interruption.End")) {
return ReadingContext_InterruptionEnd;
} else if (!strcmp(context, "Trigger")) {
return ReadingContext_Trigger;
}
MO_DBG_ERR("ReadingContext not specified %.10s", context);
return ReadingContext_UNDEFINED;
}
} //namespace MicroOcpp