blob: 97b67d745d8c4c0ffb13ce33ec4b72352168c448 (
plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import os
import struct
import unittest
from chirp.drivers import kguv8e
from chirp.drivers import kguv8d
from chirp.drivers import kguv8dplus
from chirp.drivers import kg935g
from chirp import directory
class FakeUV8D:
def __init__(self, rclass):
self.writebuf = b''
self.readbuf = b''
self.rclass = rclass
self._model = rclass._model
def write(self, data):
assert isinstance(data, bytes)
cmd = data[1]
response = b''
if cmd == kguv8d.CMD_ID:
response = self._model + b'\x00' * 10
elif cmd == kguv8d.CMD_RD:
response = b'\x00' * 64
elif cmd == kguv8d.CMD_WR:
response = data[4:6]
if hasattr(self.rclass, 'decrypt'):
response = self.rclass(None).decrypt(response)
elif cmd == kguv8d.CMD_END:
return
else:
raise Exception('Unhandled command')
packet = struct.pack('xxxB', len(response)) + response
cs = sum(x for x in packet) % 256
packet += struct.pack('B', cs)
if hasattr(self.rclass, 'encrypt'):
payload = self.rclass(None).encrypt(packet[4:])
packet = packet[:4] + payload
self.readbuf += packet
def read(self, n):
buf = self.readbuf[:n]
self.readbuf = self.readbuf[n:]
return buf
class TestKGUV8D(unittest.TestCase):
RCLASS = kguv8d.KGUV8DRadio
def test_identify(self):
f = FakeUV8D(self.RCLASS)
r = self.RCLASS(f)
r._identify()
def test_download(self):
f = FakeUV8D(self.RCLASS)
r = self.RCLASS(f)
r.sync_in()
def test_upload(self):
f = FakeUV8D(self.RCLASS)
img = os.path.join(os.path.dirname(__file__),
'..', 'images',
'%s.img' % directory.radio_class_id(self.RCLASS))
r = self.RCLASS(img)
r.set_pipe(f)
r.sync_out()
class TestKGUV8DPlus(TestKGUV8D):
RCLASS = kguv8dplus.KGUV8DPlusRadio
class TestKGUV8ER(TestKGUV8D):
RCLASS = kguv8e.KGUV8ERadio
class TestKG935(TestKGUV8D):
RCLASS = kg935g.KG935GRadio
|