protobin 0.0.37__tar.gz → 0.0.38__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.
- {protobin-0.0.37 → protobin-0.0.38}/PKG-INFO +1 -1
- {protobin-0.0.37 → protobin-0.0.38}/protobin/protocol.py +8 -5
- {protobin-0.0.37 → protobin-0.0.38}/pyproject.toml +1 -1
- {protobin-0.0.37 → protobin-0.0.38}/tests/codec8.json +4 -0
- {protobin-0.0.37 → protobin-0.0.38}/tests/teltonika.json +1 -0
- {protobin-0.0.37 → protobin-0.0.38}/tests/tests.py +8 -1
- {protobin-0.0.37 → protobin-0.0.38}/.gitignore +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/LICENSE.txt +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/README.md +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/protobin/__init__.py +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/protobin/errors.py +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/protobin/fields.py +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/protobin/interfaces.py +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/protobin/singleton.py +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/tests/demo.json +0 -0
- {protobin-0.0.37 → protobin-0.0.38}/tests/demo.yaml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: protobin
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.38
|
|
4
4
|
Summary: Python library for encode and decode data in protobin format
|
|
5
5
|
Project-URL: Homepage, https://github.com/drmelectronic/protobin-python
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/drmelectronic/protobin-python/issues
|
|
@@ -18,6 +18,7 @@ class Format:
|
|
|
18
18
|
self.header = format.get('header')
|
|
19
19
|
self.codec = format.get('codec')
|
|
20
20
|
self.crc = format.get('crc', True)
|
|
21
|
+
self.crc_size = format.get('crc_size')
|
|
21
22
|
if server is None:
|
|
22
23
|
input_mode = 'fields'
|
|
23
24
|
output_mode = 'fields'
|
|
@@ -115,9 +116,9 @@ class Protocol:
|
|
|
115
116
|
format = self.formats[format_key]
|
|
116
117
|
binary = format.encode(data)
|
|
117
118
|
if self.fake_prefix and format.header:
|
|
118
|
-
binary = binary + self.get_crc(binary)
|
|
119
|
+
binary = binary + self.get_crc(binary, format.crc_size)
|
|
119
120
|
elif format.crc and self.crc16:
|
|
120
|
-
binary = len(binary).to_bytes(self.length, 'big', signed=False) + binary + self.get_crc(binary)
|
|
121
|
+
binary = len(binary).to_bytes(self.length, 'big', signed=False) + binary + self.get_crc(binary, format.crc_size)
|
|
121
122
|
|
|
122
123
|
return binary
|
|
123
124
|
|
|
@@ -171,7 +172,7 @@ class Protocol:
|
|
|
171
172
|
if not crc:
|
|
172
173
|
raise CRCError(f'There is no CRC')
|
|
173
174
|
elif crc_value != self.crc16(clean_binary):
|
|
174
|
-
raise CRCError(f'CRC no coincide {crc} != {self.get_crc(clean_binary)}')
|
|
175
|
+
raise CRCError(f'CRC no coincide {crc} != {self.get_crc(clean_binary, None)}')
|
|
175
176
|
return clean_binary
|
|
176
177
|
|
|
177
178
|
def config_crc(self, js):
|
|
@@ -180,5 +181,7 @@ class Protocol:
|
|
|
180
181
|
if 'size' in js:
|
|
181
182
|
self.crc_size = js['size']
|
|
182
183
|
|
|
183
|
-
def get_crc(self, binary):
|
|
184
|
-
|
|
184
|
+
def get_crc(self, binary, crc_size):
|
|
185
|
+
if crc_size is None:
|
|
186
|
+
crc_size = self.crc_size
|
|
187
|
+
return self.crc16(binary).to_bytes(crc_size, byteorder=self.crc_byteorder)
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"login_status": {
|
|
13
|
+
"crc": false,
|
|
14
|
+
"crc_size": 2,
|
|
15
|
+
"header": "P",
|
|
13
16
|
"fields": {
|
|
14
17
|
"bus_number": {"type": "string"},
|
|
15
18
|
"company": {"type": "string"},
|
|
@@ -53,6 +56,7 @@
|
|
|
53
56
|
},
|
|
54
57
|
"status3": {
|
|
55
58
|
"header": "s",
|
|
59
|
+
"crc_size": 2,
|
|
56
60
|
"fields": {
|
|
57
61
|
"status": {"type": "char"},
|
|
58
62
|
"direction": {"type": "char"},
|
|
@@ -697,7 +697,7 @@ report:
|
|
|
697
697
|
}}}, server=True)
|
|
698
698
|
|
|
699
699
|
def test_teltonika_binary(self):
|
|
700
|
-
binary = b'\x00\x00\x00\x00\x00\x00\
|
|
700
|
+
binary = b'\x00\x00\x00\x00\x00\x00\x00!\x08\x01\x00\x00\x01\x94\xd26B\xd8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xa4\x12'
|
|
701
701
|
client = Protocol(file='teltonika.json', server=None)
|
|
702
702
|
header, recv = client.decode(binary)
|
|
703
703
|
print(recv)
|
|
@@ -720,3 +720,10 @@ report:
|
|
|
720
720
|
binary2 = client.encode(recv, 'login')
|
|
721
721
|
self.assertEqual(binary, binary2)
|
|
722
722
|
print(binary2)
|
|
723
|
+
|
|
724
|
+
def test_teltonika_login(self):
|
|
725
|
+
client = Protocol(file='codec8.json', server=None)
|
|
726
|
+
data = {'bus_number': '110', 'company': 'roma', 'route': 'IO37'}
|
|
727
|
+
binary = client.encode(data, 'login_status')
|
|
728
|
+
print(binary)
|
|
729
|
+
self.assertEqual(b'P=\x03110\x04roma\x04IO37\x19\x8f', binary)
|
|
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
|