protobin 0.0.4__tar.gz → 0.0.6__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.4 → protobin-0.0.6}/PKG-INFO +1 -1
- {protobin-0.0.4 → protobin-0.0.6}/protobin/fields.py +5 -5
- {protobin-0.0.4 → protobin-0.0.6}/protobin/protocol.py +13 -4
- {protobin-0.0.4 → protobin-0.0.6}/pyproject.toml +1 -1
- {protobin-0.0.4 → protobin-0.0.6}/tests/demo.json +34 -7
- protobin-0.0.6/tests/demo.yaml +622 -0
- {protobin-0.0.4 → protobin-0.0.6}/tests/tests.py +85 -12
- {protobin-0.0.4 → protobin-0.0.6}/.gitignore +0 -0
- {protobin-0.0.4 → protobin-0.0.6}/LICENSE.txt +0 -0
- {protobin-0.0.4 → protobin-0.0.6}/README.md +0 -0
- {protobin-0.0.4 → protobin-0.0.6}/protobin/__init__.py +0 -0
- {protobin-0.0.4 → protobin-0.0.6}/protobin/errors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: protobin
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
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
|
|
@@ -177,7 +177,7 @@ class FieldBool(FieldBase):
|
|
|
177
177
|
bytes = 1
|
|
178
178
|
|
|
179
179
|
def to_binary(self, val):
|
|
180
|
-
return val.to_bytes(1, 'big', signed=False)
|
|
180
|
+
return bool(val).to_bytes(1, 'big', signed=False)
|
|
181
181
|
|
|
182
182
|
def from_binary(self, binary):
|
|
183
183
|
return bool(int.from_bytes(binary, 'big', signed=False))
|
|
@@ -281,18 +281,18 @@ class FieldFloat(FieldBase):
|
|
|
281
281
|
|
|
282
282
|
def __init__(self, js):
|
|
283
283
|
super().__init__(js)
|
|
284
|
-
self.
|
|
284
|
+
self.decimals = js['decimals']
|
|
285
285
|
|
|
286
286
|
def from_binary(self, binary):
|
|
287
287
|
val = int.from_bytes(binary[:self.bytes], 'big', signed=True)
|
|
288
|
-
return val / (10 ** self.
|
|
288
|
+
return val / (10 ** self.decimals)
|
|
289
289
|
|
|
290
290
|
def to_binary(self, val):
|
|
291
|
-
return int(round(val * (10 ** self.
|
|
291
|
+
return int(round(val * (10 ** self.decimals))).to_bytes(self.bytes, 'big', signed=True)
|
|
292
292
|
|
|
293
293
|
def to_dict(self):
|
|
294
294
|
d = super().to_dict()
|
|
295
|
-
d['
|
|
295
|
+
d['decimals'] = self.decimals
|
|
296
296
|
return d
|
|
297
297
|
|
|
298
298
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
|
|
3
|
+
import yaml
|
|
4
|
+
|
|
3
5
|
from protobin.fields import FieldBase, FIELD_MAP
|
|
4
6
|
|
|
5
7
|
|
|
@@ -38,10 +40,17 @@ class Protocol:
|
|
|
38
40
|
def __init__(self, file=None, js=None):
|
|
39
41
|
if file:
|
|
40
42
|
with open(file, 'r') as f:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if 'json' in file:
|
|
44
|
+
js = json.loads(f.read())
|
|
45
|
+
self.formats = {}
|
|
46
|
+
for k in js.keys():
|
|
47
|
+
self.formats[k] = Format(js[k])
|
|
48
|
+
elif 'yaml' in file:
|
|
49
|
+
js = yaml.full_load(f.read())
|
|
50
|
+
self.formats = {}
|
|
51
|
+
for k in js.keys():
|
|
52
|
+
self.formats[k] = Format(js[k])
|
|
53
|
+
|
|
45
54
|
|
|
46
55
|
def temp_format(self, k):
|
|
47
56
|
return self.formats[k].to_dict()
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ask_schedule1": {
|
|
3
|
+
"id": [{"bytes": 4, "type": "unsigned"}],
|
|
4
|
+
"inicio": [{"bytes": 6, "type": "datetime"}]},
|
|
5
|
+
|
|
2
6
|
"fare": [
|
|
3
7
|
{"key": "id", "bytes": 2, "type": "unsigned"},
|
|
4
8
|
{"key": "color", "bytes": 7, "type": "string"},
|
|
@@ -7,7 +11,7 @@
|
|
|
7
11
|
{"keys": ["activo", "reintegro"], "bytes": 1, "type": "flags"},
|
|
8
12
|
{"keys": ["lunes", "martes", "miercoles", "jueves", "viernes", "sabado", "domingo", "feriado"], "bytes": 1, "type": "flags"},
|
|
9
13
|
{"key": "ruta", "bytes": 2, "type": "unsigned"},
|
|
10
|
-
{"key": "tarifa", "bytes": 2, "type": "float", "
|
|
14
|
+
{"key": "tarifa", "bytes": 2, "type": "float", "decimals": 2},
|
|
11
15
|
{"key": "timestamp", "bytes": 6, "type": "datetime"}
|
|
12
16
|
],
|
|
13
17
|
"command": [
|
|
@@ -45,8 +49,8 @@
|
|
|
45
49
|
"geocerca": [
|
|
46
50
|
{"key": "id", "bytes": 2, "type": "unsigned"},
|
|
47
51
|
{"key": "orden", "bytes": 1, "type": "unsigned"},
|
|
48
|
-
{"key": "longitud", "bytes": 4, "type": "float", "
|
|
49
|
-
{"key": "latitud", "bytes": 4, "type": "float", "
|
|
52
|
+
{"key": "longitud", "bytes": 4, "type": "float", "decimals": 6},
|
|
53
|
+
{"key": "latitud", "bytes": 4, "type": "float", "decimals": 6},
|
|
50
54
|
{"key": "radio", "bytes": 2, "type": "unsigned"},
|
|
51
55
|
{"key": "ruta", "bytes": 1, "type": "unsigned"},
|
|
52
56
|
{"keys": ["lado", "control", "datear", "activo"], "bytes": 1, "type": "flags"},
|
|
@@ -146,8 +150,8 @@
|
|
|
146
150
|
"busstop": [
|
|
147
151
|
{"key": "id", "bytes": 2, "type": "unsigned"},
|
|
148
152
|
{"key": "orden", "bytes": 1, "type": "unsigned"},
|
|
149
|
-
{"key": "longitud", "bytes": 4, "type": "float", "
|
|
150
|
-
{"key": "latitud", "bytes": 4, "type": "float", "
|
|
153
|
+
{"key": "longitud", "bytes": 4, "type": "float", "decimals": 6},
|
|
154
|
+
{"key": "latitud", "bytes": 4, "type": "float", "decimals": 6},
|
|
151
155
|
{"key": "radio", "bytes": 2, "type": "unsigned"},
|
|
152
156
|
{"key": "ruta", "bytes": 1, "type": "unsigned"},
|
|
153
157
|
{"keys": ["liquidar", "lado", "terminal", "activo"], "bytes": 1, "type": "flags"},
|
|
@@ -167,8 +171,8 @@
|
|
|
167
171
|
"report": [
|
|
168
172
|
{"key": "positions", "bytes": 19, "type": "array", "array": [
|
|
169
173
|
{"key": "time", "bytes": 6, "type": "datetime"},
|
|
170
|
-
{"key": "lng", "bytes": 4, "type": "float", "
|
|
171
|
-
{"key": "lat", "bytes": 4, "type": "float", "
|
|
174
|
+
{"key": "lng", "bytes": 4, "type": "float", "decimals": 6},
|
|
175
|
+
{"key": "lat", "bytes": 4, "type": "float", "decimals": 6},
|
|
172
176
|
{"key": "speed", "bytes": 1, "type": "unsigned"},
|
|
173
177
|
{"key": "mark", "bytes": 2, "type": "unsigned"},
|
|
174
178
|
{"key": "busstop", "bytes": 2, "type": "unsigned"}
|
|
@@ -183,6 +187,29 @@
|
|
|
183
187
|
{"key": "value", "bytes": 1, "type": "unsigned"}
|
|
184
188
|
]}
|
|
185
189
|
],
|
|
190
|
+
"report": {
|
|
191
|
+
"positions": {"bytes": 19,"type": "array",
|
|
192
|
+
"array": {
|
|
193
|
+
"time": {"bytes": 6,"type": "datetime"},
|
|
194
|
+
"lng": {"bytes": 4,"decimals": 6,"type": "float"},
|
|
195
|
+
"lat": {"bytes": 4,"decimals": 6,"type": "float"},
|
|
196
|
+
"speed": {"bytes": 1,"type": "unsigned"},
|
|
197
|
+
"mark": {"bytes": 2,"type": "unsigned"},
|
|
198
|
+
"busstop": {"bytes": 2,"type": "unsigned"}
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
"trip": {"bytes": 4,"type": "unsigned"},
|
|
202
|
+
"route": {"bytes": 1,"type": "unsigned"},
|
|
203
|
+
"direction": {"bytes": 1,"type": "bool"},
|
|
204
|
+
"state": {"bytes": 1,"type": "char"},
|
|
205
|
+
"sales": {"bytes": 3,"type": "unsigned"},
|
|
206
|
+
"events": {"bytes": 3,"type": "array",
|
|
207
|
+
"array": {
|
|
208
|
+
"id": {"bytes": 2,"type": "unsigned"},
|
|
209
|
+
"value": {"bytes": 1,"type": "unsigned"}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
186
213
|
"position_response": [
|
|
187
214
|
{"key": "reportes", "bytes": 1, "type": "unsigned"},
|
|
188
215
|
{"key": "ids", "bytes": 0, "type": "array", "array": [
|
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
report:
|
|
2
|
+
positions:
|
|
3
|
+
bytes: 19
|
|
4
|
+
type: array
|
|
5
|
+
array:
|
|
6
|
+
time:
|
|
7
|
+
bytes: 6
|
|
8
|
+
type: datetime
|
|
9
|
+
lng:
|
|
10
|
+
bytes: 4
|
|
11
|
+
decimals: 6
|
|
12
|
+
type: float
|
|
13
|
+
lat:
|
|
14
|
+
bytes: 4
|
|
15
|
+
decimals: 6
|
|
16
|
+
type: float
|
|
17
|
+
speed:
|
|
18
|
+
bytes: 1
|
|
19
|
+
type: unsigned
|
|
20
|
+
mark:
|
|
21
|
+
bytes: 2
|
|
22
|
+
type: unsigned
|
|
23
|
+
busstop:
|
|
24
|
+
bytes: 2
|
|
25
|
+
type: unsigned
|
|
26
|
+
trip:
|
|
27
|
+
bytes: 4
|
|
28
|
+
type: unsigned
|
|
29
|
+
route:
|
|
30
|
+
bytes: 1
|
|
31
|
+
type: unsigned
|
|
32
|
+
direction:
|
|
33
|
+
bytes: 1
|
|
34
|
+
type: bool
|
|
35
|
+
state:
|
|
36
|
+
bytes: 1
|
|
37
|
+
type: char
|
|
38
|
+
sales:
|
|
39
|
+
bytes: 3
|
|
40
|
+
type: unsigned
|
|
41
|
+
events:
|
|
42
|
+
bytes: 3
|
|
43
|
+
type: array
|
|
44
|
+
array:
|
|
45
|
+
id:
|
|
46
|
+
bytes: 2
|
|
47
|
+
type: unsigned
|
|
48
|
+
value:
|
|
49
|
+
bytes: 1
|
|
50
|
+
type: unsigned
|
|
51
|
+
|
|
52
|
+
ask_schedule:
|
|
53
|
+
id:
|
|
54
|
+
bytes: 4
|
|
55
|
+
type: unsigned
|
|
56
|
+
inicio:
|
|
57
|
+
bytes: 6
|
|
58
|
+
type: datetime
|
|
59
|
+
controles:
|
|
60
|
+
type: array
|
|
61
|
+
array:
|
|
62
|
+
geocerca:
|
|
63
|
+
bytes: 2
|
|
64
|
+
type: unsigned
|
|
65
|
+
tiempo:
|
|
66
|
+
bytes: 1
|
|
67
|
+
type: signed
|
|
68
|
+
volada:
|
|
69
|
+
bytes: 1
|
|
70
|
+
type: signed
|
|
71
|
+
|
|
72
|
+
ask_trip:
|
|
73
|
+
- bytes: 4
|
|
74
|
+
key: salida
|
|
75
|
+
type: unsigned
|
|
76
|
+
backward_datero:
|
|
77
|
+
- bytes: 2
|
|
78
|
+
key: geocerca
|
|
79
|
+
type: unsigned
|
|
80
|
+
- bytes: 1
|
|
81
|
+
key: i
|
|
82
|
+
type: unsigned
|
|
83
|
+
- bytes: 1
|
|
84
|
+
key: delta
|
|
85
|
+
type: unsigned
|
|
86
|
+
- bytes: 2
|
|
87
|
+
key: padron
|
|
88
|
+
type: unsigned
|
|
89
|
+
- bytes: 0
|
|
90
|
+
key: id
|
|
91
|
+
type: string
|
|
92
|
+
busstop:
|
|
93
|
+
- bytes: 2
|
|
94
|
+
key: id
|
|
95
|
+
type: unsigned
|
|
96
|
+
- bytes: 1
|
|
97
|
+
key: orden
|
|
98
|
+
type: unsigned
|
|
99
|
+
- bytes: 4
|
|
100
|
+
decimals: 6
|
|
101
|
+
key: longitud
|
|
102
|
+
type: float
|
|
103
|
+
- bytes: 4
|
|
104
|
+
decimals: 6
|
|
105
|
+
key: latitud
|
|
106
|
+
type: float
|
|
107
|
+
- bytes: 2
|
|
108
|
+
key: radio
|
|
109
|
+
type: unsigned
|
|
110
|
+
- bytes: 1
|
|
111
|
+
key: ruta
|
|
112
|
+
type: unsigned
|
|
113
|
+
- bytes: 1
|
|
114
|
+
keys:
|
|
115
|
+
- liquidar
|
|
116
|
+
- lado
|
|
117
|
+
- terminal
|
|
118
|
+
- activo
|
|
119
|
+
type: flags
|
|
120
|
+
- bytes: 14
|
|
121
|
+
key: nombre
|
|
122
|
+
type: string
|
|
123
|
+
- bytes: 1
|
|
124
|
+
key: velocidad
|
|
125
|
+
type: unsigned
|
|
126
|
+
- array:
|
|
127
|
+
- bytes: 2
|
|
128
|
+
key: boleto
|
|
129
|
+
type: unsigned
|
|
130
|
+
- bytes: 2
|
|
131
|
+
key: fin
|
|
132
|
+
type: unsigned
|
|
133
|
+
bytes: 0
|
|
134
|
+
key: tarifas
|
|
135
|
+
type: array
|
|
136
|
+
- bytes: 6
|
|
137
|
+
key: timestamp
|
|
138
|
+
type: datetime
|
|
139
|
+
command:
|
|
140
|
+
- bytes: 1
|
|
141
|
+
key: comando
|
|
142
|
+
type: char
|
|
143
|
+
- bytes: 0
|
|
144
|
+
key: id
|
|
145
|
+
type: string
|
|
146
|
+
- bytes: 0
|
|
147
|
+
key: value
|
|
148
|
+
type: string
|
|
149
|
+
error:
|
|
150
|
+
- bytes: 0
|
|
151
|
+
key: error
|
|
152
|
+
type: string
|
|
153
|
+
fare:
|
|
154
|
+
- bytes: 2
|
|
155
|
+
key: id
|
|
156
|
+
type: unsigned
|
|
157
|
+
- bytes: 7
|
|
158
|
+
key: color
|
|
159
|
+
type: string
|
|
160
|
+
- bytes: 1
|
|
161
|
+
key: orden
|
|
162
|
+
type: unsigned
|
|
163
|
+
- bytes: 13
|
|
164
|
+
key: nombre
|
|
165
|
+
type: string
|
|
166
|
+
- bytes: 1
|
|
167
|
+
keys:
|
|
168
|
+
- activo
|
|
169
|
+
- reintegro
|
|
170
|
+
type: flags
|
|
171
|
+
- bytes: 1
|
|
172
|
+
keys:
|
|
173
|
+
- lunes
|
|
174
|
+
- martes
|
|
175
|
+
- miercoles
|
|
176
|
+
- jueves
|
|
177
|
+
- viernes
|
|
178
|
+
- sabado
|
|
179
|
+
- domingo
|
|
180
|
+
- feriado
|
|
181
|
+
type: flags
|
|
182
|
+
- bytes: 2
|
|
183
|
+
key: ruta
|
|
184
|
+
type: unsigned
|
|
185
|
+
- bytes: 2
|
|
186
|
+
decimals: 2
|
|
187
|
+
key: tarifa
|
|
188
|
+
type: float
|
|
189
|
+
- bytes: 6
|
|
190
|
+
key: timestamp
|
|
191
|
+
type: datetime
|
|
192
|
+
finalize_sales:
|
|
193
|
+
- bytes: 4
|
|
194
|
+
key: sesion
|
|
195
|
+
type: unsigned
|
|
196
|
+
- bytes: 2
|
|
197
|
+
key: unidad
|
|
198
|
+
type: unsigned
|
|
199
|
+
- bytes: 6
|
|
200
|
+
key: fin
|
|
201
|
+
type: datetime
|
|
202
|
+
- bytes: 4
|
|
203
|
+
key: produccion
|
|
204
|
+
type: unsigned
|
|
205
|
+
- bytes: 4
|
|
206
|
+
key: primero
|
|
207
|
+
type: unsigned
|
|
208
|
+
- bytes: 4
|
|
209
|
+
key: ultimo
|
|
210
|
+
type: unsigned
|
|
211
|
+
finalize_sales_response:
|
|
212
|
+
- bytes: 1
|
|
213
|
+
key: error
|
|
214
|
+
type: bool
|
|
215
|
+
- bytes: 0
|
|
216
|
+
key: title
|
|
217
|
+
type: string
|
|
218
|
+
- bytes: 0
|
|
219
|
+
key: mensaje
|
|
220
|
+
type: string
|
|
221
|
+
- bytes: 4
|
|
222
|
+
key: id
|
|
223
|
+
type: unsigned
|
|
224
|
+
forward_datero:
|
|
225
|
+
- bytes: 2
|
|
226
|
+
key: geocerca
|
|
227
|
+
type: unsigned
|
|
228
|
+
- bytes: 4
|
|
229
|
+
key: salida
|
|
230
|
+
type: unsigned
|
|
231
|
+
- bytes: 6
|
|
232
|
+
key: hora
|
|
233
|
+
type: datetime
|
|
234
|
+
- array:
|
|
235
|
+
- bytes: 2
|
|
236
|
+
key: padron
|
|
237
|
+
type: unsigned
|
|
238
|
+
- bytes: 1
|
|
239
|
+
key: delta
|
|
240
|
+
type: unsigned
|
|
241
|
+
bytes: 0
|
|
242
|
+
key: dateros
|
|
243
|
+
type: array
|
|
244
|
+
geocerca:
|
|
245
|
+
- bytes: 2
|
|
246
|
+
key: id
|
|
247
|
+
type: unsigned
|
|
248
|
+
- bytes: 1
|
|
249
|
+
key: orden
|
|
250
|
+
type: unsigned
|
|
251
|
+
- bytes: 4
|
|
252
|
+
decimals: 6
|
|
253
|
+
key: longitud
|
|
254
|
+
type: float
|
|
255
|
+
- bytes: 4
|
|
256
|
+
decimals: 6
|
|
257
|
+
key: latitud
|
|
258
|
+
type: float
|
|
259
|
+
- bytes: 2
|
|
260
|
+
key: radio
|
|
261
|
+
type: unsigned
|
|
262
|
+
- bytes: 1
|
|
263
|
+
key: ruta
|
|
264
|
+
type: unsigned
|
|
265
|
+
- bytes: 1
|
|
266
|
+
keys:
|
|
267
|
+
- lado
|
|
268
|
+
- control
|
|
269
|
+
- datear
|
|
270
|
+
- activo
|
|
271
|
+
type: flags
|
|
272
|
+
- bytes: 15
|
|
273
|
+
key: nombre
|
|
274
|
+
type: string
|
|
275
|
+
- bytes: 6
|
|
276
|
+
key: timestamp
|
|
277
|
+
type: datetime
|
|
278
|
+
login:
|
|
279
|
+
- bytes: 0
|
|
280
|
+
key: serial
|
|
281
|
+
type: string
|
|
282
|
+
login_device:
|
|
283
|
+
- bytes: 2
|
|
284
|
+
key: id
|
|
285
|
+
type: unsigned
|
|
286
|
+
- bytes: 2
|
|
287
|
+
key: padron
|
|
288
|
+
type: unsigned
|
|
289
|
+
- bytes: 1
|
|
290
|
+
key: ruta
|
|
291
|
+
type: unsigned
|
|
292
|
+
- bytes: 1
|
|
293
|
+
key: lado
|
|
294
|
+
type: bool
|
|
295
|
+
- bytes: 2
|
|
296
|
+
key: geocerca
|
|
297
|
+
type: unsigned
|
|
298
|
+
- bytes: 1
|
|
299
|
+
key: estado
|
|
300
|
+
type: char
|
|
301
|
+
- bytes: 4
|
|
302
|
+
key: salida
|
|
303
|
+
type: unsigned
|
|
304
|
+
- bytes: 4
|
|
305
|
+
key: conductor
|
|
306
|
+
type: unsigned
|
|
307
|
+
- bytes: 1
|
|
308
|
+
key: orden
|
|
309
|
+
type: unsigned
|
|
310
|
+
- bytes: 1
|
|
311
|
+
key: logueado
|
|
312
|
+
type: bool
|
|
313
|
+
- bytes: 6
|
|
314
|
+
key: data
|
|
315
|
+
type: datetime
|
|
316
|
+
- bytes: 2
|
|
317
|
+
key: programada
|
|
318
|
+
type: time
|
|
319
|
+
message:
|
|
320
|
+
- bytes: 4
|
|
321
|
+
key: id
|
|
322
|
+
type: unsigned
|
|
323
|
+
- bytes: 0
|
|
324
|
+
key: texto
|
|
325
|
+
type: string
|
|
326
|
+
message_response:
|
|
327
|
+
- bytes: 4
|
|
328
|
+
key: id
|
|
329
|
+
type: unsigned
|
|
330
|
+
- bytes: 1
|
|
331
|
+
key: read
|
|
332
|
+
type: bool
|
|
333
|
+
new_ip:
|
|
334
|
+
- bytes: 0
|
|
335
|
+
key: ip
|
|
336
|
+
type: string
|
|
337
|
+
operation:
|
|
338
|
+
- bytes: 0
|
|
339
|
+
key: id
|
|
340
|
+
type: string
|
|
341
|
+
- bytes: 0
|
|
342
|
+
key: section
|
|
343
|
+
type: string
|
|
344
|
+
- bytes: 0
|
|
345
|
+
key: key
|
|
346
|
+
type: string
|
|
347
|
+
- bytes: 0
|
|
348
|
+
key: value
|
|
349
|
+
type: string
|
|
350
|
+
operation_response:
|
|
351
|
+
- bytes: 0
|
|
352
|
+
key: id
|
|
353
|
+
type: string
|
|
354
|
+
parameter:
|
|
355
|
+
- bytes: 0
|
|
356
|
+
key: id
|
|
357
|
+
type: string
|
|
358
|
+
- bytes: 0
|
|
359
|
+
key: nombre
|
|
360
|
+
type: string
|
|
361
|
+
- bytes: 0
|
|
362
|
+
key: valor
|
|
363
|
+
type: string
|
|
364
|
+
position_response:
|
|
365
|
+
- bytes: 1
|
|
366
|
+
key: reportes
|
|
367
|
+
type: unsigned
|
|
368
|
+
- array:
|
|
369
|
+
- bytes: 2
|
|
370
|
+
key: id
|
|
371
|
+
type: unsigned
|
|
372
|
+
bytes: 0
|
|
373
|
+
key: ids
|
|
374
|
+
type: array
|
|
375
|
+
remaining_data:
|
|
376
|
+
- bytes: 4
|
|
377
|
+
key: faltantes
|
|
378
|
+
type: unsigned
|
|
379
|
+
- bytes: 1
|
|
380
|
+
key: tabla
|
|
381
|
+
type: char
|
|
382
|
+
route:
|
|
383
|
+
- bytes: 2
|
|
384
|
+
key: id
|
|
385
|
+
type: unsigned
|
|
386
|
+
- bytes: 0
|
|
387
|
+
key: codigo
|
|
388
|
+
type: string
|
|
389
|
+
- bytes: 6
|
|
390
|
+
key: timestamp
|
|
391
|
+
type: datetime
|
|
392
|
+
route_settings:
|
|
393
|
+
- bytes: 2
|
|
394
|
+
key: id
|
|
395
|
+
type: unsigned
|
|
396
|
+
- bytes: 0
|
|
397
|
+
key: nombre
|
|
398
|
+
type: string
|
|
399
|
+
- bytes: 1
|
|
400
|
+
key: ruta
|
|
401
|
+
type: unsigned
|
|
402
|
+
- bytes: 0
|
|
403
|
+
key: tipo
|
|
404
|
+
type: string
|
|
405
|
+
- bytes: 0
|
|
406
|
+
key: data
|
|
407
|
+
type: string
|
|
408
|
+
- bytes: 6
|
|
409
|
+
key: timestamp
|
|
410
|
+
type: datetime
|
|
411
|
+
schedule:
|
|
412
|
+
- bytes: 4
|
|
413
|
+
key: salida
|
|
414
|
+
type: unsigned
|
|
415
|
+
- array:
|
|
416
|
+
- bytes: 2
|
|
417
|
+
key: geocerca
|
|
418
|
+
type: unsigned
|
|
419
|
+
bytes: 0
|
|
420
|
+
key: controles
|
|
421
|
+
type: array
|
|
422
|
+
settings:
|
|
423
|
+
- bytes: 2
|
|
424
|
+
key: id
|
|
425
|
+
type: unsigned
|
|
426
|
+
- bytes: 0
|
|
427
|
+
key: nombre
|
|
428
|
+
type: string
|
|
429
|
+
- bytes: 0
|
|
430
|
+
key: tipo
|
|
431
|
+
type: string
|
|
432
|
+
- bytes: 0
|
|
433
|
+
key: data
|
|
434
|
+
type: string
|
|
435
|
+
- bytes: 6
|
|
436
|
+
key: timestamp
|
|
437
|
+
type: datetime
|
|
438
|
+
start_sales:
|
|
439
|
+
- bytes: 0
|
|
440
|
+
key: clave
|
|
441
|
+
type: string
|
|
442
|
+
- bytes: 0
|
|
443
|
+
key: dni
|
|
444
|
+
type: string
|
|
445
|
+
- bytes: 1
|
|
446
|
+
key: lado
|
|
447
|
+
type: bool
|
|
448
|
+
- bytes: 1
|
|
449
|
+
key: ruta
|
|
450
|
+
type: unsigned
|
|
451
|
+
- bytes: 2
|
|
452
|
+
key: unidad
|
|
453
|
+
type: unsigned
|
|
454
|
+
start_sales_response:
|
|
455
|
+
- bytes: 1
|
|
456
|
+
key: error
|
|
457
|
+
type: bool
|
|
458
|
+
- bytes: 0
|
|
459
|
+
key: title
|
|
460
|
+
type: string
|
|
461
|
+
- bytes: 0
|
|
462
|
+
key: mensaje
|
|
463
|
+
type: string
|
|
464
|
+
- array:
|
|
465
|
+
- bytes: 4
|
|
466
|
+
key: id
|
|
467
|
+
type: unsigned
|
|
468
|
+
- bytes: 2
|
|
469
|
+
key: conductor_id
|
|
470
|
+
type: unsigned
|
|
471
|
+
- bytes: 0
|
|
472
|
+
key: conductor_codigo
|
|
473
|
+
type: string
|
|
474
|
+
- bytes: 1
|
|
475
|
+
keys:
|
|
476
|
+
- activo
|
|
477
|
+
- castigado
|
|
478
|
+
- conductor
|
|
479
|
+
- vencido
|
|
480
|
+
type: flags
|
|
481
|
+
- bytes: 1
|
|
482
|
+
key: ruta
|
|
483
|
+
type: unsigned
|
|
484
|
+
- bytes: 1
|
|
485
|
+
key: lado
|
|
486
|
+
type: bool
|
|
487
|
+
- bytes: 6
|
|
488
|
+
key: inicio
|
|
489
|
+
type: datetime
|
|
490
|
+
bytes: 0
|
|
491
|
+
key: sesiones
|
|
492
|
+
type: array
|
|
493
|
+
tickets:
|
|
494
|
+
- array:
|
|
495
|
+
- bytes: 2
|
|
496
|
+
key: boleto
|
|
497
|
+
type: unsigned
|
|
498
|
+
- bytes: 2
|
|
499
|
+
key: conductor
|
|
500
|
+
type: unsigned
|
|
501
|
+
- bytes: 4
|
|
502
|
+
key: correlativo
|
|
503
|
+
type: unsigned
|
|
504
|
+
- bytes: 3
|
|
505
|
+
key: dia
|
|
506
|
+
type: date
|
|
507
|
+
- bytes: 2
|
|
508
|
+
key: fin
|
|
509
|
+
type: unsigned
|
|
510
|
+
- bytes: 6
|
|
511
|
+
key: hora
|
|
512
|
+
type: datetime
|
|
513
|
+
- bytes: 4
|
|
514
|
+
key: inicio
|
|
515
|
+
type: unsigned
|
|
516
|
+
- bytes: 2
|
|
517
|
+
key: inspector
|
|
518
|
+
type: unsigned
|
|
519
|
+
- bytes: 1
|
|
520
|
+
key: medio_pago
|
|
521
|
+
type: unsigned
|
|
522
|
+
- bytes: 4
|
|
523
|
+
key: numero
|
|
524
|
+
type: unsigned
|
|
525
|
+
- bytes: 2
|
|
526
|
+
key: precio
|
|
527
|
+
type: unsigned
|
|
528
|
+
- bytes: 1
|
|
529
|
+
key: ruta
|
|
530
|
+
type: unsigned
|
|
531
|
+
- bytes: 4
|
|
532
|
+
key: sesion
|
|
533
|
+
type: unsigned
|
|
534
|
+
- bytes: 2
|
|
535
|
+
key: unidad
|
|
536
|
+
type: unsigned
|
|
537
|
+
- bytes: 0
|
|
538
|
+
key: tarjeta
|
|
539
|
+
type: string
|
|
540
|
+
bytes: 0
|
|
541
|
+
key: tickets
|
|
542
|
+
type: array
|
|
543
|
+
tickets_response:
|
|
544
|
+
- array:
|
|
545
|
+
- bytes: 4
|
|
546
|
+
key: correlativo
|
|
547
|
+
type: unsigned
|
|
548
|
+
- bytes: 0
|
|
549
|
+
key: id
|
|
550
|
+
type: string
|
|
551
|
+
bytes: 0
|
|
552
|
+
key: tickets
|
|
553
|
+
type: array
|
|
554
|
+
timestamp:
|
|
555
|
+
- bytes: 6
|
|
556
|
+
key: timestamp
|
|
557
|
+
type: timestamp
|
|
558
|
+
timestamp_us:
|
|
559
|
+
- bytes: 8
|
|
560
|
+
key: timestamp
|
|
561
|
+
type: timestamp
|
|
562
|
+
trip:
|
|
563
|
+
- bytes: 4
|
|
564
|
+
key: id
|
|
565
|
+
type: unsigned
|
|
566
|
+
- bytes: 1
|
|
567
|
+
key: ruta
|
|
568
|
+
type: unsigned
|
|
569
|
+
- bytes: 1
|
|
570
|
+
key: lado
|
|
571
|
+
type: bool
|
|
572
|
+
- bytes: 6
|
|
573
|
+
key: inicio
|
|
574
|
+
type: datetime
|
|
575
|
+
- bytes: 1
|
|
576
|
+
key: estado
|
|
577
|
+
type: char
|
|
578
|
+
- bytes: 1
|
|
579
|
+
key: frecuencia
|
|
580
|
+
type: unsigned
|
|
581
|
+
- bytes: 4
|
|
582
|
+
key: conductor
|
|
583
|
+
type: unsigned
|
|
584
|
+
- bytes: 2
|
|
585
|
+
key: geocerca
|
|
586
|
+
type: unsigned
|
|
587
|
+
- array:
|
|
588
|
+
- bytes: 2
|
|
589
|
+
key: geocerca
|
|
590
|
+
type: unsigned
|
|
591
|
+
- bytes: 1
|
|
592
|
+
key: tiempo
|
|
593
|
+
type: signed
|
|
594
|
+
- bytes: 1
|
|
595
|
+
key: volada
|
|
596
|
+
type: signed
|
|
597
|
+
bytes: 0
|
|
598
|
+
key: controles
|
|
599
|
+
type: array
|
|
600
|
+
- bytes: 0
|
|
601
|
+
key: marcados
|
|
602
|
+
type: bits
|
|
603
|
+
user_route:
|
|
604
|
+
- bytes: 2
|
|
605
|
+
key: id
|
|
606
|
+
type: unsigned
|
|
607
|
+
- bytes: 9
|
|
608
|
+
key: celular
|
|
609
|
+
type: string
|
|
610
|
+
- bytes: 14
|
|
611
|
+
key: nombre
|
|
612
|
+
type: string
|
|
613
|
+
- array:
|
|
614
|
+
- bytes: 1
|
|
615
|
+
key: ruta
|
|
616
|
+
type: unsigned
|
|
617
|
+
bytes: 1
|
|
618
|
+
key: rutas
|
|
619
|
+
type: array
|
|
620
|
+
- bytes: 6
|
|
621
|
+
key: timestamp
|
|
622
|
+
type: datetime
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import unittest
|
|
2
2
|
|
|
3
3
|
import datetime
|
|
4
|
-
|
|
4
|
+
import json
|
|
5
|
+
import yaml
|
|
5
6
|
from protobin import Protocol
|
|
6
7
|
|
|
7
8
|
DATA = {
|
|
@@ -99,7 +100,7 @@ class FormatTest(unittest.TestCase):
|
|
|
99
100
|
'date': [{'key': 'test', 'bytes': 3, 'type': 'date'}],
|
|
100
101
|
'datetime': [{'key': 'test', 'bytes': 6, 'type': 'datetime'}],
|
|
101
102
|
'flags': [{'keys': ['f1', 'f2', 'f3', 'f4'], 'bytes': 1, 'type': 'flags'}],
|
|
102
|
-
'float': [{'key': 'test', 'bytes': 4, '
|
|
103
|
+
'float': [{'key': 'test', 'bytes': 4, 'decimals': 6, 'type': 'float'}],
|
|
103
104
|
'signed': [{'key': 'test', 'bytes': 2, 'type': 'signed'}],
|
|
104
105
|
'string': [{'key': 'test', 'bytes': 0, 'type': 'string'}],
|
|
105
106
|
'time': [{'key': 'test', 'bytes': 1, 'type': 'time'}],
|
|
@@ -122,7 +123,7 @@ class BasicTest(unittest.TestCase):
|
|
|
122
123
|
'date': [{'key': 'test', 'bytes': 1, 'type': 'date'}],
|
|
123
124
|
'datetime': [{'key': 'test', 'bytes': 1, 'type': 'datetime'}],
|
|
124
125
|
'flags': [{'keys': ['f1', 'f2', 'f3', 'f4'], 'type': 'flags'}],
|
|
125
|
-
'float': [{'key': 'test', 'bytes': 4, '
|
|
126
|
+
'float': [{'key': 'test', 'bytes': 4, 'decimals': 6, 'type': 'float'}],
|
|
126
127
|
'signed': [{'key': 'test', 'bytes': 2, 'type': 'signed'}],
|
|
127
128
|
'string': [{'key': 'test', 'bytes': 0, 'type': 'string'}],
|
|
128
129
|
'time': [{'key': 'test', 'bytes': 2, 'type': 'time'}],
|
|
@@ -139,23 +140,30 @@ class BasicTest(unittest.TestCase):
|
|
|
139
140
|
binary = self.protocol.encode(data, 'array')
|
|
140
141
|
recv = self.protocol.decode(binary, 'array')
|
|
141
142
|
self.assertEqual(data, recv)
|
|
143
|
+
data = {'test': [
|
|
144
|
+
{'test': 'texto2 de prueba'},
|
|
145
|
+
{'test': 'segunda prueba4'},
|
|
146
|
+
{'test': 'otra más3'},
|
|
147
|
+
{'test': 'y una última'}]
|
|
148
|
+
}
|
|
149
|
+
binary = self.protocol.encode(data, 'array')
|
|
150
|
+
recv = self.protocol.decode(binary, 'array')
|
|
151
|
+
self.assertEqual(data, recv)
|
|
142
152
|
|
|
143
153
|
def test_bits(self):
|
|
144
154
|
data = {'test': [True, False, True, False, False] * 3}
|
|
145
|
-
print('data', data)
|
|
146
155
|
binary = self.protocol.encode(data, 'bits')
|
|
147
|
-
print('binary', binary)
|
|
148
156
|
recv = self.protocol.decode(binary, 'bits')
|
|
149
|
-
|
|
157
|
+
self.assertEqual(data, recv)
|
|
158
|
+
data = {'test': [True, False, True, False, False] * 5}
|
|
159
|
+
binary = self.protocol.encode(data, 'bits')
|
|
160
|
+
recv = self.protocol.decode(binary, 'bits')
|
|
150
161
|
self.assertEqual(data, recv)
|
|
151
162
|
|
|
152
163
|
def test_bits_fixed(self):
|
|
153
164
|
data = {'test': [True, False, True, False, False, True, True]}
|
|
154
|
-
print('data', data)
|
|
155
165
|
binary = self.protocol.encode(data, 'bits_fixed')
|
|
156
|
-
print('binary', binary)
|
|
157
166
|
recv = self.protocol.decode(binary, 'bits_fixed')
|
|
158
|
-
print('recv', recv)
|
|
159
167
|
self.assertEqual(data, recv)
|
|
160
168
|
|
|
161
169
|
def test_bool(self):
|
|
@@ -231,12 +239,18 @@ class BasicTest(unittest.TestCase):
|
|
|
231
239
|
|
|
232
240
|
class AdvancedTest(unittest.TestCase):
|
|
233
241
|
|
|
234
|
-
def
|
|
242
|
+
def test_file_json(self):
|
|
235
243
|
protocol = Protocol(file='demo.json')
|
|
236
244
|
binary = protocol.encode(DATA, 'report')
|
|
237
245
|
recv = protocol.decode(binary, 'report')
|
|
238
246
|
self.assertEqual(DATA, recv)
|
|
239
247
|
|
|
248
|
+
def test_file_yaml(self):
|
|
249
|
+
protocol = Protocol(file='demo.yaml')
|
|
250
|
+
binary = protocol.encode(DATA, 'report')
|
|
251
|
+
recv = protocol.decode(binary, 'report')
|
|
252
|
+
self.assertEqual(DATA, recv)
|
|
253
|
+
|
|
240
254
|
def test_json(self):
|
|
241
255
|
protocol = Protocol(js={'medida': [
|
|
242
256
|
{'key': 'id', 'bytes': 1, 'type': 'unsigned'},
|
|
@@ -245,9 +259,68 @@ class AdvancedTest(unittest.TestCase):
|
|
|
245
259
|
]})
|
|
246
260
|
data = {'id': 2, 'nombre': 'Voltaje', 'valor': -20}
|
|
247
261
|
binary = protocol.encode(data, 'medida')
|
|
248
|
-
print('binary', binary)
|
|
249
262
|
recv = protocol.decode(binary, 'medida')
|
|
250
|
-
|
|
263
|
+
self.assertEqual(data, recv)
|
|
264
|
+
data = {'id': 4, 'nombre': 'Corriente', 'valor': 240}
|
|
265
|
+
binary = protocol.encode(data, 'medida')
|
|
266
|
+
recv = protocol.decode(binary, 'medida')
|
|
251
267
|
self.assertEqual(data, recv)
|
|
252
268
|
|
|
269
|
+
def test_new_yaml(self):
|
|
270
|
+
ym = yaml.full_load("""report:
|
|
271
|
+
positions:
|
|
272
|
+
bytes: 19
|
|
273
|
+
type: array
|
|
274
|
+
array:
|
|
275
|
+
time:
|
|
276
|
+
bytes: 6
|
|
277
|
+
type: datetime
|
|
278
|
+
lng:
|
|
279
|
+
bytes: 4
|
|
280
|
+
decimals: 6
|
|
281
|
+
type: float
|
|
282
|
+
lat:
|
|
283
|
+
bytes: 4
|
|
284
|
+
decimals: 6
|
|
285
|
+
type: float
|
|
286
|
+
speed:
|
|
287
|
+
bytes: 1
|
|
288
|
+
type: unsigned
|
|
289
|
+
mark:
|
|
290
|
+
bytes: 2
|
|
291
|
+
type: unsigned
|
|
292
|
+
busstop:
|
|
293
|
+
bytes: 2
|
|
294
|
+
type: unsigned
|
|
295
|
+
trip:
|
|
296
|
+
bytes: 4
|
|
297
|
+
type: unsigned
|
|
298
|
+
route:
|
|
299
|
+
bytes: 1
|
|
300
|
+
type: unsigned
|
|
301
|
+
direction:
|
|
302
|
+
bytes: 1
|
|
303
|
+
type: bool
|
|
304
|
+
state:
|
|
305
|
+
bytes: 1
|
|
306
|
+
type: char
|
|
307
|
+
sales:
|
|
308
|
+
bytes: 3
|
|
309
|
+
type: unsigned
|
|
310
|
+
events:
|
|
311
|
+
bytes: 3
|
|
312
|
+
type: array
|
|
313
|
+
array:
|
|
314
|
+
id:
|
|
315
|
+
bytes: 2
|
|
316
|
+
type: unsigned
|
|
317
|
+
value:
|
|
318
|
+
bytes: 1
|
|
319
|
+
type: unsigned
|
|
320
|
+
""")
|
|
321
|
+
js = json.dumps(ym, indent=2)
|
|
322
|
+
print(js)
|
|
323
|
+
|
|
324
|
+
def test_convert_json_to_yaml(self):
|
|
325
|
+
protocol = Protocol(file='demo.json')
|
|
253
326
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|