struct-frame 0.0.24__tar.gz → 0.0.25__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of struct-frame might be problematic. Click here for more details.
- {struct_frame-0.0.24 → struct_frame-0.0.25}/PKG-INFO +1 -1
- {struct_frame-0.0.24 → struct_frame-0.0.25}/pyproject.toml +1 -1
- struct_frame-0.0.25/src/struct_frame/boilerplate/py/__init__.py +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/py/struct_frame_parser.py +38 -38
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/generate.py +1 -1
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/py_gen.py +2 -22
- {struct_frame-0.0.24 → struct_frame-0.0.25}/.clang-format +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/.gitignore +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/DEVGUIDE.md +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/LICENSE +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/README.md +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/TODO +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/index.ts +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/main.c +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/myl_vehicle.proto +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/package-lock.json +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/package.json +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/main.py +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/__init__.py +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/__main__.py +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/base.py +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame.h +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_cpp.h +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_gen.h +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_parser.h +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_types.h +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/ts/struct_frame.ts +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/ts/struct_frame_gen.ts +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/ts/struct_frame_parser.ts +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/ts/struct_frame_types.ts +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/c_gen.py +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/ts_gen.py +0 -0
- {struct_frame-0.0.24 → struct_frame-0.0.25}/tsconfig.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: struct-frame
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.25
|
|
4
4
|
Summary: A framework for serializing data with headers
|
|
5
5
|
Project-URL: Homepage, https://github.com/mylonics/struct-frame
|
|
6
6
|
Project-URL: Issues, https://github.com/mylonics/struct-frame/issues
|
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/py/struct_frame_parser.py
RENAMED
|
@@ -4,10 +4,10 @@ from enum import Enum
|
|
|
4
4
|
|
|
5
5
|
def fletcher_checksum_calculation(buffer, start=0, end=None):
|
|
6
6
|
if end == None:
|
|
7
|
-
end = buffer
|
|
7
|
+
end = len(buffer)
|
|
8
8
|
|
|
9
9
|
byte1 = 0
|
|
10
|
-
byte2 =
|
|
10
|
+
byte2 = 0
|
|
11
11
|
|
|
12
12
|
for x in range(start, end):
|
|
13
13
|
byte1 += buffer[x]
|
|
@@ -17,26 +17,26 @@ def fletcher_checksum_calculation(buffer, start=0, end=None):
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class BasicPacket:
|
|
20
|
-
start_byte =
|
|
20
|
+
start_byte = 0x90
|
|
21
21
|
header_length = 0
|
|
22
22
|
footer_length = 0
|
|
23
23
|
|
|
24
24
|
desired_packet_length = 0
|
|
25
25
|
packet = []
|
|
26
26
|
|
|
27
|
-
def __init__(self, start_byte, header_length, footer_length):
|
|
27
|
+
def __init__(self, start_byte=0x90, header_length=2, footer_length=2):
|
|
28
28
|
self.start_byte = start_byte
|
|
29
29
|
self.header_length = header_length
|
|
30
30
|
self.footer_length = footer_length
|
|
31
31
|
|
|
32
|
-
def add_header_byte(self, byte, clear):
|
|
32
|
+
def add_header_byte(self, byte, clear=False):
|
|
33
33
|
if clear:
|
|
34
34
|
self.packet.clear()
|
|
35
|
-
self.packet.
|
|
35
|
+
self.packet.append(byte)
|
|
36
36
|
return len(self.packet) == self.header_length
|
|
37
37
|
|
|
38
38
|
def add_packet_byte(self, byte):
|
|
39
|
-
self.packet.
|
|
39
|
+
self.packet.append(byte)
|
|
40
40
|
return len(self.packet) == self.desired_packet_length
|
|
41
41
|
|
|
42
42
|
def get_msg_id(self):
|
|
@@ -54,15 +54,20 @@ class BasicPacket:
|
|
|
54
54
|
def get_msg_buffer(self):
|
|
55
55
|
return self.packet[self.header_length:self.desired_packet_length - self.footer_length]
|
|
56
56
|
|
|
57
|
+
def encode_msg(self, msg):
|
|
58
|
+
return self.encode(msg.pack(), msg.msg_id)
|
|
59
|
+
|
|
57
60
|
def encode(self, data, msg_id):
|
|
58
61
|
output = []
|
|
59
|
-
output.
|
|
60
|
-
output.
|
|
61
|
-
|
|
62
|
+
output.append(self.start_byte)
|
|
63
|
+
output.append(msg_id)
|
|
64
|
+
if (len(data)):
|
|
65
|
+
for b in data:
|
|
66
|
+
output.append(b)
|
|
62
67
|
checksum = fletcher_checksum_calculation(data)
|
|
63
68
|
|
|
64
|
-
output.
|
|
65
|
-
output.
|
|
69
|
+
output.append(checksum[0])
|
|
70
|
+
output.append(checksum[1])
|
|
66
71
|
return output
|
|
67
72
|
|
|
68
73
|
|
|
@@ -75,44 +80,39 @@ class ParserState(Enum):
|
|
|
75
80
|
class FrameParser:
|
|
76
81
|
state = ParserState.LOOKING_FOR_START_BYTE
|
|
77
82
|
buffer = []
|
|
78
|
-
|
|
83
|
+
packetFormat = None
|
|
79
84
|
msg_definitions = None
|
|
80
85
|
msg_id_loc = None
|
|
81
86
|
msg_type = None
|
|
82
87
|
|
|
83
|
-
def __init__(self,
|
|
84
|
-
self.
|
|
88
|
+
def __init__(self, packetFormats, msg_definitions):
|
|
89
|
+
self.packetFormats = packetFormats
|
|
85
90
|
self.msg_definitions = msg_definitions
|
|
86
91
|
|
|
87
92
|
def parse_char(self, c):
|
|
88
|
-
if state == ParserState.LOOKING_FOR_START_BYTE:
|
|
89
|
-
self.
|
|
90
|
-
if self.
|
|
91
|
-
if self.
|
|
92
|
-
state = ParserState.GETTING_PACKET
|
|
93
|
+
if self.state == ParserState.LOOKING_FOR_START_BYTE:
|
|
94
|
+
self.packetFormat = self.packetFormats[c]
|
|
95
|
+
if self.packetFormat:
|
|
96
|
+
if self.packetFormat.add_header_byte(c, True):
|
|
97
|
+
self.state = ParserState.GETTING_PACKET
|
|
93
98
|
else:
|
|
94
|
-
state = ParserState.GETTING_HEADER
|
|
99
|
+
self.state = ParserState.GETTING_HEADER
|
|
95
100
|
|
|
96
|
-
elif state == ParserState.GETTING_HEADER:
|
|
97
|
-
if self.
|
|
98
|
-
msg_id = self.
|
|
101
|
+
elif self.state == ParserState.GETTING_HEADER:
|
|
102
|
+
if self.packetFormat.add_header_byte(c):
|
|
103
|
+
msg_id = self.packetFormat.get_msg_id()
|
|
99
104
|
self.msg_type = self.msg_definitions[msg_id]
|
|
100
105
|
if self.msg_type:
|
|
101
|
-
self.
|
|
102
|
-
|
|
106
|
+
self.packetFormat.get_full_packet_length(
|
|
107
|
+
self.msg_type.msg_size)
|
|
108
|
+
self.state = ParserState.GETTING_PACKET
|
|
103
109
|
else:
|
|
104
|
-
state = ParserState.LOOKING_FOR_START_BYTE
|
|
110
|
+
self.state = ParserState.LOOKING_FOR_START_BYTE
|
|
105
111
|
|
|
106
|
-
elif state == ParserState.GETTING_PACKET:
|
|
107
|
-
if self.
|
|
108
|
-
state = ParserState.LOOKING_FOR_START_BYTE
|
|
109
|
-
if self.
|
|
110
|
-
return self.msg_type.create_unpack(self.
|
|
112
|
+
elif self.state == ParserState.GETTING_PACKET:
|
|
113
|
+
if self.packetFormat.add_packet_byte(c):
|
|
114
|
+
self.state = ParserState.LOOKING_FOR_START_BYTE
|
|
115
|
+
if self.packetFormat.validate_packet():
|
|
116
|
+
return self.msg_type.create_unpack(bytes(self.packetFormat.get_msg_buffer()))
|
|
111
117
|
|
|
112
118
|
return False
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def TestFunction():
|
|
116
|
-
parsers = {BasicPacket.start_byte, BasicPacket()}
|
|
117
|
-
frameParser = FrameParser(parsers)
|
|
118
|
-
frameParser.parse_char
|
|
@@ -340,7 +340,7 @@ def generateTsFileStrings(path):
|
|
|
340
340
|
def generatePyFileStrings(path):
|
|
341
341
|
out = {}
|
|
342
342
|
for key, value in packages.items():
|
|
343
|
-
name = os.path.join(path, value.name + ".
|
|
343
|
+
name = os.path.join(path, value.name + "_sf.py")
|
|
344
344
|
data = ''.join(FilePyGen.generate(value))
|
|
345
345
|
out[name] = data
|
|
346
346
|
return out
|
|
@@ -88,32 +88,12 @@ class MessagePyGen():
|
|
|
88
88
|
structName = '%s%s' % (pascalCase(msg.package), msg.name)
|
|
89
89
|
result += 'class %s(Structured):\n' % structName
|
|
90
90
|
result += ' msg_size = %s\n' % msg.size
|
|
91
|
-
if msg.id:
|
|
91
|
+
if msg.id != None:
|
|
92
92
|
result += ' msg_id = %s\n' % msg.id
|
|
93
93
|
|
|
94
|
-
size = 1
|
|
95
|
-
if not msg.fields:
|
|
96
|
-
# Empty structs are not allowed in C standard.
|
|
97
|
-
# Therefore add a dummy field if an empty message occurs.
|
|
98
|
-
result += ' dummy_field: pad'
|
|
99
|
-
else:
|
|
100
|
-
size = msg.size
|
|
101
|
-
|
|
102
94
|
result += '\n'.join([FieldPyGen.generate(f)
|
|
103
95
|
for key, f in msg.fields.items()])
|
|
104
96
|
|
|
105
|
-
# defineName = '%s_%s' % (CamelToSnakeCase(
|
|
106
|
-
# msg.package).upper(), CamelToSnakeCase(msg.name).upper())
|
|
107
|
-
# result += '#define %s_MAX_SIZE %d\n' % (defineName, size)
|
|
108
|
-
#
|
|
109
|
-
# if msg.id:
|
|
110
|
-
# result += '#define %s_MSG_ID %d\n' % (defineName, msg.id)
|
|
111
|
-
#
|
|
112
|
-
# funcName = defineName.lower()
|
|
113
|
-
# if msg.id:
|
|
114
|
-
# result += 'MESSAGE_HELPER(%s, %s, %d, %d);\n\n' % (funcName, structName,
|
|
115
|
-
# size, msg.id)
|
|
116
|
-
#
|
|
117
97
|
return result + '\n'
|
|
118
98
|
|
|
119
99
|
@staticmethod
|
|
@@ -153,7 +133,7 @@ class FilePyGen():
|
|
|
153
133
|
|
|
154
134
|
yield '%s_definitions = {\n' % package.name
|
|
155
135
|
for key, msg in package.sortedMessages().items():
|
|
156
|
-
if msg.id:
|
|
136
|
+
if msg.id != None:
|
|
157
137
|
structName = '%s%s' % (pascalCase(msg.package), msg.name)
|
|
158
138
|
yield ' %s: %s,\n' % (msg.id, structName)
|
|
159
139
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_cpp.h
RENAMED
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_gen.h
RENAMED
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_parser.h
RENAMED
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/c/struct_frame_types.h
RENAMED
|
File without changes
|
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/ts/struct_frame_gen.ts
RENAMED
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/ts/struct_frame_parser.ts
RENAMED
|
File without changes
|
{struct_frame-0.0.24 → struct_frame-0.0.25}/src/struct_frame/boilerplate/ts/struct_frame_types.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|