-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
53 lines (44 loc) · 1.32 KB
/
test.py
File metadata and controls
53 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@file :test.py
@author :Chavis.Chen (chavis.chen@quectel.com)
@brief :test for qpytlv-iostream
@version :0.1
@date :2022-06-15 17:01:42
@copyright :Copyright (c) 2022
"""
from usr.qpytlv_iostream import QpyTLVIOAbs, QpyTLVIoStream
from usr.qpytlv import QpyTLV
from usr.serial import Serial
from machine import UART
class QpyTLVIO(QpyTLVIOAbs):
def __init__(self):
self._serial = Serial(UART.UART1)
def read(self, timeout = 0):
return self._serial.read(1024, timeout)
def write(self, data):
return self._serial.write(data)
def tlv_parse_cb(errno, unparsed_data_len, parsed_data, original_data):
print("errno:", errno)
print("unparsed_data_len:", unparsed_data_len)
print("parsed_data:", parsed_data)
print("original_data:", original_data)
tags = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'ffff', 'a5a5', 'e1e1']
qpytlv = QpyTLV(tags)
qpytlv_io = QpyTLVIO()
qpytlv_iostream = QpyTLVIoStream(qpytlv, qpytlv_io, tlv_parse_cb)
d = {
"aaaa": b'\xaa\xaa',
"bbbb": {
"cccc": b'\xcc\xcc',
"dddd": b'\xdd\xdd'
},
"eeee": {
"ffff": b'\xff\xff',
"a5a5": {
"e1e1": b'\xe1\xe1'
}
}
}
qpytlv_iostream.write(d)