protobin 0.0.36__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.36 → protobin-0.0.38}/PKG-INFO +1 -1
- {protobin-0.0.36 → protobin-0.0.38}/protobin/protocol.py +14 -11
- {protobin-0.0.36 → protobin-0.0.38}/pyproject.toml +1 -1
- {protobin-0.0.36 → protobin-0.0.38}/tests/codec8.json +5 -1
- {protobin-0.0.36 → protobin-0.0.38}/tests/teltonika.json +2 -1
- {protobin-0.0.36 → protobin-0.0.38}/tests/tests.py +20 -13
- {protobin-0.0.36 → protobin-0.0.38}/.gitignore +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/LICENSE.txt +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/README.md +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/protobin/__init__.py +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/protobin/errors.py +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/protobin/fields.py +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/protobin/interfaces.py +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/protobin/singleton.py +0 -0
- {protobin-0.0.36 → protobin-0.0.38}/tests/demo.json +0 -0
- {protobin-0.0.36 → 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 =
|
|
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
|
|
|
@@ -132,12 +133,12 @@ class Protocol:
|
|
|
132
133
|
else:
|
|
133
134
|
if n > 4:
|
|
134
135
|
# comandos de pantalla con = o que tengan un igual más adelante por casualidad
|
|
135
|
-
if self.fake_prefix and binary[:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
else:
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
# if self.fake_prefix and int.from_bytes(binary[:self.fake_prefix - 1]) and binary[self.fake_prefix - 1]:
|
|
137
|
+
# # comandos
|
|
138
|
+
# binary = binary[4:]
|
|
139
|
+
# else:
|
|
140
|
+
# # codec8
|
|
141
|
+
binary = self.check_crc(binary)
|
|
141
142
|
n = binary.find(b'=')
|
|
142
143
|
if n > 4 or n == -1:
|
|
143
144
|
# si el igual está adelante no es parte del comando
|
|
@@ -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)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"length": 8,
|
|
3
|
-
"fake_prefix":
|
|
3
|
+
"fake_prefix": true,
|
|
4
4
|
"crc": {"poly": "0x18005", "init": "0x0000", "reverse": true, "byte_order": "big", "size": 4},
|
|
5
5
|
"formats": {
|
|
6
6
|
"login": {
|
|
@@ -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"},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"length": 8,
|
|
3
3
|
"crc": {"poly": "0x18005", "init": "0x0000", "reverse": true, "byte_order": "big", "size": 4},
|
|
4
|
-
"fake_prefix":
|
|
4
|
+
"fake_prefix": true,
|
|
5
5
|
"formats": {
|
|
6
6
|
"login": {
|
|
7
7
|
"crc": false,
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"login_status": {
|
|
13
13
|
"crc": false,
|
|
14
|
+
"crc_size": 2,
|
|
14
15
|
"header": "P",
|
|
15
16
|
"fields": {
|
|
16
17
|
"bus_number": {"type": "string"},
|
|
@@ -561,16 +561,6 @@ report:
|
|
|
561
561
|
}}
|
|
562
562
|
})
|
|
563
563
|
|
|
564
|
-
def test_teltonika_login_hex(self):
|
|
565
|
-
hexdata = '000F333536333037303432343431303133'
|
|
566
|
-
binary = bytes.fromhex(hexdata)
|
|
567
|
-
client = Protocol(file='codec8.json', server=None)
|
|
568
|
-
recv = client.decode(binary, 'login')
|
|
569
|
-
self.assertEqual(recv, {'serial': '356307042441013'})
|
|
570
|
-
binary2 = client.encode(recv, 'login')
|
|
571
|
-
self.assertEqual(binary, binary2)
|
|
572
|
-
print(binary2)
|
|
573
|
-
|
|
574
564
|
def test_position_binary(self):
|
|
575
565
|
data = {'positions':
|
|
576
566
|
[{'time': datetime.datetime(2024, 10, 18, 15, 57, 38),
|
|
@@ -645,7 +635,7 @@ report:
|
|
|
645
635
|
data = {'status': 'E', 'direction': 'A', 'next_next_control': '', 'next_next_time': ' ', 'next_control': '', 'next_time': ' ', 'previous_control': '', 'delay': 0, 'front_control': '', 'back_control': '', 'back_back_control': '', 'datero_bus_-1': 0, 'datero_dif_-1': 0, 'datero_bus_0': 0, 'datero_dif_0': 0, 'datero_bus_1': 0, 'datero_dif_1': 0, 'datero_bus_2': 0, 'datero_dif_2': 0, 'datero_bus_3': 256, 'datero_dif_3': 0, 'datero_bus_4': 0, 'datero_dif_4': 0, 'datero_bus_5': 0, 'datero_dif_5': 0}
|
|
646
636
|
client = Protocol(file='codec8.json')
|
|
647
637
|
binary = client.encode(data, 'status3')
|
|
648
|
-
self.assertEqual(b'
|
|
638
|
+
self.assertEqual(b's=EA\x00 \x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb6\xd6', binary)
|
|
649
639
|
header, recv = client.decode(binary)
|
|
650
640
|
self.assertEqual(data, recv)
|
|
651
641
|
|
|
@@ -707,16 +697,33 @@ report:
|
|
|
707
697
|
}}}, server=True)
|
|
708
698
|
|
|
709
699
|
def test_teltonika_binary(self):
|
|
710
|
-
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'
|
|
711
701
|
client = Protocol(file='teltonika.json', server=None)
|
|
712
702
|
header, recv = client.decode(binary)
|
|
713
703
|
print(recv)
|
|
714
704
|
|
|
715
705
|
def test_status_teltonika(self):
|
|
716
|
-
pesquero = b'
|
|
706
|
+
pesquero = b'S=RA\x07IQUITOS14:05\x06LOBATO\x04\x07IGLESIA\x00f\x08\x00n\x05\x00\x96\x03\x01m\x08\x00\xb5\r\x01w\t\x00\x00o\xb4'
|
|
717
707
|
client = Protocol(file='teltonika.json', server=None)
|
|
718
708
|
header, recv = client.decode(pesquero)
|
|
719
709
|
print(recv)
|
|
720
710
|
binary = client.encode(recv, header)
|
|
721
711
|
print(binary)
|
|
722
712
|
self.assertEqual(pesquero, binary)
|
|
713
|
+
|
|
714
|
+
def test_teltonika_login_hex(self):
|
|
715
|
+
hexdata = '000F333536333037303432343431303133'
|
|
716
|
+
binary = bytes.fromhex(hexdata)
|
|
717
|
+
client = Protocol(file='codec8.json', server=None)
|
|
718
|
+
recv = client.decode(binary, 'login')
|
|
719
|
+
self.assertEqual(recv, {'serial': '356307042441013'})
|
|
720
|
+
binary2 = client.encode(recv, 'login')
|
|
721
|
+
self.assertEqual(binary, binary2)
|
|
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
|