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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: protobin
3
- Version: 0.0.37
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
- return self.crc16(binary).to_bytes(self.crc_size, byteorder=self.crc_byteorder)
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)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.37"
7
+ version = "0.0.38"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
@@ -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"},
@@ -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"},
@@ -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\x04\x1d\x08#\x00\x00\x01\x93x\xb7T\xc8\x00\xd2\x0f\xa2\xd0\xf8\xdbz\x81\x00s\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xb7\xa2\xe8\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xb7\xf1\x08\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xb8?(\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xb8\x8dH\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xbae\xf0\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xbc6\xc8\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xbe\x0fp\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xbf\xe40\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xc1\xb8\xf0\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xc3\x91\x98\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xc5bp\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xc7;\x18\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xc9\x13\xc0\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xca\xe4\x98\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xcc\xbd@\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xce\x92\x00\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd0f\xc0\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd2;\x80\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd4\x10@\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd5\xe8\xe8\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd7\xbd\xa8\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd9\x92h\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xdbg(\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xdd?\xd0\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xdf\x14\x90\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xe0\xe9P\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xe2\xbe\x10\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xe4\x92\xd0\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xe6kx\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xe8<P\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xea\x14\xf8\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xeb\xed\xa0\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xed\xbex\x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xef\x97 \x00\xd2\x0f\xa5\x06\xf8\xdb{\x06\x00s\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00#\x00\x00v\x92'
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