Skip to content

Commit ac1cc1a

Browse files
committed
Remove "types.h" and "pattern.h". Move all its content to the right header. Hide some of the enums to cpp files.
1 parent 885db14 commit ac1cc1a

5 files changed

Lines changed: 93 additions & 122 deletions

File tree

src/dlms_parser/apdu_handler.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66

77
namespace dlms_parser {
88

9+
enum DlmsCipherConstants : uint8_t {
10+
DLMS_SYSTITLE_LENGTH = 8,
11+
DLMS_FRAME_COUNTER_LENGTH = 4,
12+
DLMS_IV_LENGTH = 12,
13+
DLMS_GCM_TAG_LENGTH = 12,
14+
DLMS_LENGTH_SINGLE_BYTE_MAX = 127,
15+
DLMS_LENGTH_CORRECTION = 5
16+
};
17+
18+
enum DlmsApduTag : uint8_t {
19+
DLMS_APDU_DATA_NOTIFICATION = 0x0F,
20+
DLMS_APDU_GENERAL_BLOCK_TRANSFER = 0xE0,
21+
DLMS_APDU_GENERAL_GLO_CIPHERING = 0xDB,
22+
DLMS_APDU_GENERAL_DED_CIPHERING = 0xDF
23+
}; // There will be more, keep as list (not single line)
24+
925
static bool is_known_tag(const uint8_t b) {
1026
switch (b) {
1127
case DLMS_APDU_GENERAL_BLOCK_TRANSFER:

src/dlms_parser/axdr_parser.h

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include "pattern.h"
4-
#include "types.h"
53
#include "utils.h"
64
#include <cstdint>
75
#include <functional>
@@ -11,6 +9,56 @@
119

1210
namespace dlms_parser {
1311

12+
enum class AxdrTokenType : uint8_t {
13+
EXPECT_TO_BE_FIRST,
14+
EXPECT_TO_BE_LAST,
15+
EXPECT_TYPE_EXACT,
16+
EXPECT_TYPE_U_I_8,
17+
EXPECT_CLASS_ID_UNTAGGED,
18+
EXPECT_OBIS6_TAGGED,
19+
EXPECT_OBIS6_TAGGED_WRONG,
20+
EXPECT_OBIS6_UNTAGGED,
21+
EXPECT_ATTR8_UNTAGGED,
22+
EXPECT_VALUE_GENERIC,
23+
EXPECT_VALUE_DATE_TIME,
24+
EXPECT_VALUE_OCTET_STRING,
25+
EXPECT_STRUCTURE_N,
26+
EXPECT_SCALER_TAGGED,
27+
EXPECT_UNIT_ENUM_TAGGED,
28+
GOING_DOWN,
29+
GOING_UP,
30+
END_OF_PATTERN = 0xFF
31+
};
32+
33+
struct AxdrPatternStep {
34+
AxdrTokenType type{};
35+
uint8_t param_u8_a{ 0 };
36+
};
37+
38+
struct AxdrDescriptorPattern {
39+
const char* name{ nullptr };
40+
int priority{ 0 };
41+
AxdrPatternStep steps[32]{};
42+
uint16_t default_class_id{ 0 };
43+
bool has_default_obis{ false };
44+
std::array<uint8_t, 6> default_obis{};
45+
};
46+
47+
struct AxdrCaptures {
48+
uint32_t elem_idx{ 0 };
49+
uint16_t class_id{ 0 };
50+
std::span<const uint8_t> obis{};
51+
DlmsDataType value_type{ DLMS_DATA_TYPE_NONE };
52+
std::span<const uint8_t> value{};
53+
54+
bool has_scaler_unit{ false };
55+
int8_t scaler{ 0 };
56+
uint8_t unit_enum{ 0 };
57+
};
58+
59+
// Callback: OBIS code, numeric value, string value, is_numeric flag
60+
using DlmsDataCallback = std::function<void(const char* obis_code, float float_val, const char* str_val, bool is_numeric)>;
61+
1462
struct ParseResult {
1563
size_t count{ 0 }; // number of matched COSEM objects
1664
size_t bytes_consumed{ 0 }; // how many bytes of the input buffer were processed

src/dlms_parser/pattern.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/dlms_parser/types.h

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/dlms_parser/utils.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "types.h"
43
#include <cstddef>
54
#include <cstdint>
65
#include <span>
@@ -30,6 +29,33 @@ class NonCopyableAndNonMovable : NonCopyable {
3029
NonCopyableAndNonMovable& operator=(NonCopyableAndNonMovable&&) = delete;
3130
};
3231

32+
enum DlmsDataType : uint8_t {
33+
DLMS_DATA_TYPE_NONE = 0,
34+
DLMS_DATA_TYPE_ARRAY = 1,
35+
DLMS_DATA_TYPE_STRUCTURE = 2,
36+
DLMS_DATA_TYPE_BOOLEAN = 3,
37+
DLMS_DATA_TYPE_BIT_STRING = 4,
38+
DLMS_DATA_TYPE_INT32 = 5,
39+
DLMS_DATA_TYPE_UINT32 = 6,
40+
DLMS_DATA_TYPE_OCTET_STRING = 9,
41+
DLMS_DATA_TYPE_STRING = 10,
42+
DLMS_DATA_TYPE_STRING_UTF8 = 12,
43+
DLMS_DATA_TYPE_BINARY_CODED_DECIMAL = 13,
44+
DLMS_DATA_TYPE_INT8 = 15,
45+
DLMS_DATA_TYPE_INT16 = 16,
46+
DLMS_DATA_TYPE_UINT8 = 17,
47+
DLMS_DATA_TYPE_UINT16 = 18,
48+
DLMS_DATA_TYPE_COMPACT_ARRAY = 19,
49+
DLMS_DATA_TYPE_INT64 = 20,
50+
DLMS_DATA_TYPE_UINT64 = 21,
51+
DLMS_DATA_TYPE_ENUM = 22,
52+
DLMS_DATA_TYPE_FLOAT32 = 23,
53+
DLMS_DATA_TYPE_FLOAT64 = 24,
54+
DLMS_DATA_TYPE_DATETIME = 25,
55+
DLMS_DATA_TYPE_DATE = 26,
56+
DLMS_DATA_TYPE_TIME = 27
57+
};
58+
3359
inline uint16_t be16(const uint8_t* p) { return static_cast<uint16_t>(static_cast<unsigned>(p[0]) << 8 | p[1]); }
3460
inline uint32_t be32(const uint8_t* p) {
3561
return static_cast<uint32_t>(p[0]) << 24 | static_cast<uint32_t>(p[1]) << 16 |

0 commit comments

Comments
 (0)