Project

General

Profile

Bug #10208 » kguv8e.py

Prospective Converted KG-UV8E v3 - Dan Smith, 01/02/2023 07:47 PM

 
1
# Copyright 2019 Pavel Milanes CO7WT <pavelmc@gmail.com>
2
#
3
# Based on the work of Krystian Struzik <toner_82@tlen.pl>
4
# who figured out the crypt used and made possible the
5
# Wuoxun KG-UV8D Plus driver, in which this work is based.
6
#
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19

    
20
"""Wouxun KG-UV8E radio management module"""
21

    
22
import struct
23
import time
24
import os
25
import logging
26
from chirp import util, chirp_common, bitwise, memmap, errors, directory
27
from chirp.settings import RadioSetting, RadioSettingGroup, \
28
    RadioSettingValueBoolean, RadioSettingValueList, \
29
    RadioSettingValueInteger, RadioSettingValueString, \
30
    RadioSettings
31

    
32
LOG = logging.getLogger(__name__)
33

    
34
CMD_ID = 128
35
CMD_END = 129
36
CMD_RD = 130
37
CMD_WR = 131
38

    
39
MEM_VALID = 158
40

    
41
AB_LIST = ["A", "B"]
42
STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 25.0, 50.0, 100.0]
43
STEP_LIST = [str(x) for x in STEPS]
44
ROGER_LIST = ["Off", "Begin", "End", "Both"]
45
TIMEOUT_LIST = ["Off"] + [str(x) + "s" for x in range(15, 901, 15)]
46
VOX_LIST = ["Off"] + ["%s" % x for x in range(1, 10)]
47
BANDWIDTH_LIST = ["Narrow", "Wide"]
48
VOICE_LIST = ["Off", "On"]
49
LANGUAGE_LIST = ["Chinese", "English"]
50
SCANMODE_LIST = ["TO", "CO", "SE"]
51
PF1KEY_LIST = ["Call", "VFTX"]
52
PF3KEY_LIST = ["Disable", "Scan", "Lamp", "Tele Alarm", "SOS-CH", "Radio"]
53
WORKMODE_LIST = ["VFO", "Channel No.", "Ch. No.+Freq.", "Ch. No.+Name"]
54
BACKLIGHT_LIST = ["Always On"] + [str(x) + "s" for x in range(1, 21)] + \
55
    ["Always Off"]
56
OFFSET_LIST = ["+", "-"]
57
PONMSG_LIST = ["Bitmap", "Battery Volts"]
58
SPMUTE_LIST = ["QT", "QT+DTMF", "QT*DTMF"]
59
DTMFST_LIST = ["DT-ST", "ANI-ST", "DT-ANI", "Off"]
60
DTMF_TIMES = ["%s" % x for x in range(50, 501, 10)]
61
RPTSET_LIST = ["", "X-DIRRPT", "X-TWRPT"] # TODO < what is index 0?
62
ALERTS = [1750, 2100, 1000, 1450]
63
ALERTS_LIST = [str(x) for x in ALERTS]
64
PTTID_LIST = ["Begin", "End", "Both"]
65
LIST_10 = ["Off"] + ["%s" % x for x in range(1, 11)]
66
SCANGRP_LIST = ["All"] + ["%s" % x for x in range(1, 11)]
67
SCQT_LIST = ["Decoder", "Encoder", "All"]
68
SMUTESET_LIST = ["Off", "Tx", "Rx", "Tx/Rx"]
69
POWER_LIST = ["Lo", "Hi"]
70
HOLD_TIMES = ["Off"] + ["%s" % x for x in range(100, 5001, 100)]
71
RPTMODE_LIST = ["Radio", "Repeater"]
72

    
73
# memory slot 0 is not used, start at 1 (so need 1000 slots, not 999)
74
# structure elements whose name starts with x are currently unidentified
75

    
76
_MEM_FORMAT = """
77
    #seekto 0x0030;
78
    struct {
79
        u32    rx_start;
80
        u32    rx_stop;
81
        u32    tx_start;
82
        u32    tx_stop;
83
    } vhf1_limits;
84

    
85
    #seekto 0x0044;
86
    struct {
87
        u32    rx_start;
88
        u32    rx_stop;
89
        u32    tx_start;
90
        u32    tx_stop;
91
    } uhf_limits;
92

    
93
    #seekto 0x0054;
94
    struct {
95
        u32    rx_start;
96
        u32    rx_stop;
97
        u32    tx_start;
98
        u32    tx_stop;
99
    } vhf_limits;
100

    
101
    #seekto 0x0400;
102
    struct {
103
        u8     oem1[8];
104
        u8     unknown[2];
105
        u8     unknown2[10];
106
        u8     unknown3[10];
107
        u8     unknown4[8];
108
        u8     model[10];
109
        u8     version[6];
110
        u8     date[8];
111
        u8     unknown5[1];
112
        u8     oem2[8];
113
    } oem_info;
114

    
115
    #seekto 0x0480;
116
    struct {
117
        u16    lower;
118
        u16    upper;
119
    } scan_groups[10];
120

    
121
    #seekto 0x0500;
122
    struct {
123
        u8    call_code[6];
124
    } call_groups[20];
125

    
126
    #seekto 0x0580;
127
    struct {
128
        char    call_name[6];
129
    } call_group_name[20];
130

    
131
    #seekto 0x0800;
132
    struct {
133
        u8      ponmsg;
134
        char    dispstr[15];
135
        u8 x0810;
136
        u8 x0811;
137
        u8 x0812;
138
        u8 x0813;
139
        u8 x0814;
140
        u8      voice;
141
        u8      timeout;
142
        u8      toalarm;
143
        u8      channel_menu;
144
        u8      power_save;
145
        u8      autolock;
146
        u8      keylock;
147
        u8      beep;
148
        u8      stopwatch;
149
        u8      vox;
150
        u8      scan_rev;
151
        u8      backlight;
152
        u8      roger_beep;
153
        u8 x0822[6];
154
        u8 x0823[6];
155
        u16     pri_ch;
156
        u8      ani_sw;
157
        u8      ptt_delay;
158
        u8      ani_code[6];
159
        u8      dtmf_st;
160
        u8      bcl_a;
161
        u8      bcl_b;
162
        u8      ptt_id;
163
        u8      prich_sw;
164
        u8      rpt_set;
165
        u8      rpt_spk;
166
        u8      rpt_ptt;
167
        u8      alert;
168
        u8      pf1_func;
169
        u8      pf3_func;
170
        u8 x0843;
171
        u8      workmode_a;
172
        u8      workmode_b;
173
        u8      dtmf_tx_time;
174
        u8      dtmf_interval;
175
        u8      main_ab;
176
        u16     work_cha;
177
        u16     work_chb;
178
        u8 x084d;
179
        u8 x084e;
180
        u8 x084f;
181
        u8 x0850;
182
        u8 x0851;
183
        u8 x0852;
184
        u8 x0853;
185
        u8 x0854;
186
        u8      rpt_mode;
187
        u8      language;
188
        u8 x0857;
189
        u8 x0858;
190
        u8 x0859;
191
        u8 x085a;
192
        u8 x085b;
193
        u8 x085c;
194
        u8 x085d;
195
        u8 x085e;
196
        u8      single_display;
197
        u8      ring_time;
198
        u8      scg_a;
199
        u8      scg_b;
200
        u8 x0863;
201
        u8      rpt_tone;
202
        u8      rpt_hold;
203
        u8      scan_det;
204
        u8      sc_qt;
205
        u8 x0868;
206
        u8      smuteset;
207
        u8      callcode;
208
    } settings;
209

    
210
    #seekto 0x0880;
211
    struct {
212
        u32     rxfreq;
213
        u32     txoffset;
214
        u16     rxtone;
215
        u16     txtone;
216
        u8      scrambler:4,
217
                unknown1:2,
218
                power:1,
219
                unknown2:1;
220
        u8      unknown3:1,
221
                shift_dir:2
222
                unknown4:1,
223
                compander:1,
224
                mute_mode:2,
225
                iswide:1;
226
        u8      step;
227
        u8      squelch;
228
      } vfoa;
229

    
230
    #seekto 0x08c0;
231
    struct {
232
        u32     rxfreq;
233
        u32     txoffset;
234
        u16     rxtone;
235
        u16     txtone;
236
        u8      scrambler:4,
237
                unknown1:2,
238
                power:1,
239
                unknown2:1;
240
        u8      unknown3:1,
241
                shift_dir:2
242
                unknown4:1,
243
                compander:1,
244
                mute_mode:2,
245
                iswide:1;
246
        u8      step;
247
        u8      squelch;
248
    } vfob;
249

    
250
    #seekto 0x0900;
251
    struct {
252
        u32     rxfreq;
253
        u32     txfreq;
254
        u16     rxtone;
255
        u16     txtone;
256
        u8      scrambler:4,
257
                unknown1:2,
258
                power:1,
259
                unknown2:1;
260
        u8      unknown3:2,
261
                scan_add:1,
262
                unknown4:1,
263
                compander:1,
264
                mute_mode:2,
265
                iswide:1;
266
        u16     padding;
267
    } memory[1000];
268

    
269
    #seekto 0x4780;
270
    struct {
271
        u8    name[8];
272
                u8    unknown[4];
273
    } names[1000];
274

    
275
    #seekto 0x7670;
276
    u8          valid[1000];
277
    """
278

    
279
    # Support for the Wouxun KG-UV8E radio
280
    # Serial coms are at 19200 baud
281
    # The data is passed in variable length records
282
    # Record structure:
283
    #  Offset   Usage
284
    #    0      start of record (\x7a)
285
    #    1      Command (\x80 Identify \x81 End/Reboot \x82 Read \x83 Write)
286
    #    2      direction (\xff PC-> Radio, \x00 Radio -> PC)
287
    #    3      length of payload (excluding header/checksum) (n)
288
    #    4      payload (n bytes)
289
    #    4+n+1  checksum - byte sum (% 256) of bytes 1 -> 4+n
290
    #
291
    # Memory Read Records:
292
    # the payload is 3 bytes, first 2 are offset (big endian),
293
    # 3rd is number of bytes to read
294
    # Memory Write Records:
295
    # the maximum payload size (from the Wouxun software) seems to be 66 bytes
296
    #  (2 bytes location + 64 bytes data).
297

    
298
@directory.register
299
class KGUV8ERadio(chirp_common.CloneModeRadio,
300
                  chirp_common.ExperimentalRadio):
301

    
302
    """Wouxun KG-UV8E"""
303
    VENDOR = "Wouxun"
304
    MODEL = "KG-UV8E"
305
    _model = b"KG-UV8D-A"
306
    _file_ident = b"kguv8e" # lowercase
307
    BAUD_RATE = 19200
308
    POWER_LEVELS = [chirp_common.PowerLevel("L", watts=1),
309
                    chirp_common.PowerLevel("H", watts=5)]
310
    _record_start = 0x7B
311
    NEEDS_COMPAT_SERIAL = False
312

    
313
    def _checksum(self, data):
314
        cs = 0
315
        for byte in data:
316
            cs += byte
317
        return cs % 256
318

    
319
    def _write_record(self, cmd, payload=b''):
320
        _packet = struct.pack('BBBB', self._record_start, cmd, 0xFF,
321
                              len(payload))
322
        checksum = bytes([self._checksum(_packet[1:] + payload)])
323
        _packet += self.encrypt(payload + checksum)
324
        LOG.debug("Sent:\n%s" % util.hexprint(_packet))
325
        self.pipe.write(_packet)
326

    
327
    def _read_record(self):
328
        # read 4 chars for the header
329
        _header = self.pipe.read(4)
330
        if len(_header) != 4:
331
            raise errors.RadioError('Radio did not respond')
332
        _length = struct.unpack('xxxB', _header)[0]
333
        _packet = self.pipe.read(_length)
334
        _rcs_xor = _packet[-1]
335
        _packet = self.decrypt(_packet)
336
        _cs = self._checksum(_header[1:])
337
        _cs += self._checksum(_packet)
338
        _cs %= 256
339
        _rcs = self.strxor(self.pipe.read(1)[0], _rcs_xor)[0]
340
        LOG.debug("_cs =%x", _cs)
341
        LOG.debug("_rcs=%x", _rcs)
342
        return (_rcs != _cs, _packet)
343

    
344
    def decrypt(self, data):
345
        result = b''
346
        for i in range(len(data)-1, 0, -1):
347
            result += self.strxor(data[i], data[i - 1])
348
        result += self.strxor(data[0], 0x57)
349
        return result[::-1]
350

    
351
    def encrypt(self, data):
352
        result = self.strxor(0x57, data[0])
353
        for i in range(1, len(data), 1):
354
            result += self.strxor(result[i - 1], data[i])
355
        return result
356

    
357
    def strxor(self, xora, xorb):
358
        return bytes([xora ^ xorb])
359

    
360
    # Identify the radio
361
    #
362
    # A Gotcha: the first identify packet returns a bad checksum, subsequent
363
    # attempts return the correct checksum... (well it does on my radio!)
364
    #
365
    # The ID record returned by the radio also includes the current frequency range
366
    # as 4 bytes big-endian in 10Hz increments
367
    #
368
    # Offset
369
    #  0:10     Model, zero padded (Use first 7 chars for 'KG-UV8D')
370
    #  11:14    UHF rx lower limit (in units of 10Hz)
371
    #  15:18    UHF rx upper limit
372
    #  19:22    UHF tx lower limit
373
    #  23:26    UHF tx upper limit
374
    #  27:30    VHF rx lower limit
375
    #  31:34    VHF rx upper limit
376
    #  35:38    VHF tx lower limit
377
    #  39:42    VHF tx upper limit
378

    
379
    @classmethod
380
    def match_model(cls, filedata, filename):
381
        id = cls._file_ident 
382
        return cls._file_ident in b'kg' + filedata[0x426:0x430].replace(b'(', b'').replace(b')', b'').lower()
383

    
384
    def _identify(self):
385
        """Do the identification dance"""
386
        for _i in range(0, 10):
387
            self._write_record(CMD_ID)
388
            _chksum_err, _resp = self._read_record()
389
            LOG.debug("Got:\n%s" % util.hexprint(_resp))
390
            if _chksum_err:
391
                LOG.error("Checksum error: retrying ident...")
392
                time.sleep(0.100)
393
                continue
394
            LOG.debug("Model %s" % util.hexprint(_resp[0:9]))
395
            if _resp[0:9] == self._model:
396
                return
397
            if len(_resp) == 0:
398
                raise Exception("Radio not responding")
399
            else:
400
                raise Exception("Unable to identify radio")
401

    
402
    def _finish(self):
403
        self._write_record(CMD_END)
404

    
405
    def process_mmap(self):
406
        self._memobj = bitwise.parse(_MEM_FORMAT, self._mmap)
407

    
408
    def sync_in(self):
409
        try:
410
            self._mmap = self._download()
411
        except errors.RadioError:
412
            raise
413
        except Exception as e:
414
            raise errors.RadioError("Failed to communicate with radio: %s" % e)
415
        self.process_mmap()
416

    
417
    def sync_out(self):
418
        self._upload()
419

    
420
    # TODO: Load all memory.
421
    # It would be smarter to only load the active areas and none of
422
    # the padding/unused areas. Padding still need to be investigated.
423
    def _download(self):
424
        """Talk to a wouxun KG-UV8E and do a download"""
425
        try:
426
            self._identify()
427
            return self._do_download(0, 32768, 64)
428
        except errors.RadioError:
429
            raise
430
        except Exception as e:
431
            LOG.exception('Unknown error during download process')
432
            raise errors.RadioError("Failed to communicate with radio: %s" % e)
433

    
434
    def _do_download(self, start, end, blocksize):
435
        # allocate & fill memory
436
        image = b""
437
        for i in range(start, end, blocksize):
438
            req = struct.pack('>HB', i, blocksize)
439
            self._write_record(CMD_RD, req)
440
            cs_error, resp = self._read_record()
441
            if cs_error:
442
                LOG.debug(util.hexprint(resp))
443
                raise Exception("Checksum error on read")
444
            LOG.debug("Got:\n%s" % util.hexprint(resp))
445
            image += resp[2:]
446
            if self.status_fn:
447
                status = chirp_common.Status()
448
                status.cur = i
449
                status.max = end
450
                status.msg = "Cloning from radio"
451
                self.status_fn(status)
452
        self._finish()
453
        return memmap.MemoryMapBytes(image)
454

    
455
    def _upload(self):
456
        """Talk to a wouxun KG-UV8E and do a upload"""
457
        try:
458
            self._identify()
459
            self._do_upload(0, 32768, 64)
460
        except errors.RadioError:
461
            raise
462
        except Exception as e:
463
            raise errors.RadioError("Failed to communicate with radio: %s" % e)
464
        return
465

    
466
    def _do_upload(self, start, end, blocksize):
467
        ptr = start
468
        for i in range(start, end, blocksize):
469
            req = struct.pack('>H', i)
470
            chunk = self.get_mmap()[ptr:ptr + blocksize]
471
            self._write_record(CMD_WR, req + chunk)
472
            # ~ LOG.debug(util.hexprint(req + chunk))
473
            cserr, ack = self._read_record()
474
            # ~ LOG.debug(util.hexprint(ack))
475
            j = struct.unpack('>H', ack)[0]
476
            if cserr or j != ptr:
477
                raise Exception("Radio did not ack block %i" % ptr)
478
            ptr += blocksize
479
            if self.status_fn:
480
                status = chirp_common.Status()
481
                status.cur = i
482
                status.max = end
483
                status.msg = "Cloning to radio"
484
                self.status_fn(status)
485
        self._finish()
486

    
487
    def get_features(self):
488
        rf = chirp_common.RadioFeatures()
489
        rf.has_settings = True
490
        rf.has_ctone = True
491
        rf.has_rx_dtcs = True
492
        rf.has_cross = True
493
        rf.has_tuning_step = False
494
        rf.has_bank = False
495
        rf.can_odd_split = True
496
        rf.valid_skips = ["", "S"]
497
        rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"]
498
        rf.valid_cross_modes = [
499
            "Tone->Tone",
500
            "Tone->DTCS",
501
            "DTCS->Tone",
502
            "DTCS->",
503
            "->Tone",
504
            "->DTCS",
505
            "DTCS->DTCS",
506
        ]
507
        rf.valid_modes = ["FM", "NFM"]
508
        rf.valid_power_levels = self.POWER_LEVELS
509
        rf.valid_name_length = 8
510
        rf.valid_duplexes = ["", "-", "+", "split", "off"]
511
        rf.valid_bands = [(134000000, 175000000),  # supports 2m
512
                          (220000000, 260000000),  # supports 1.25m
513
                          (350000000, 520000000)]  # supports 70cm
514
        rf.valid_characters = chirp_common.CHARSET_ASCII
515
        rf.memory_bounds = (1, 999)  # 999 memories
516
        rf.valid_tuning_steps = STEPS
517
        return rf
518

    
519
    @classmethod
520
    def get_prompts(cls):
521
        rp = chirp_common.RadioPrompts()
522
        rp.experimental = \
523
            ('This driver is experimental.\n'
524
             '\n'
525
             'Please keep a copy of your memories with the original software '
526
             'if you treasure them, this driver is new and may contain'
527
             ' bugs.\n'
528
             '\n'
529
             )
530
        return rp
531

    
532
    def get_raw_memory(self, number):
533
        return repr(self._memobj.memory[number])
534

    
535
    def _get_tone(self, _mem, mem):
536
        def _get_dcs(val):
537
            code = int("%03o" % (val & 0x07FF))
538
            pol = (val & 0x8000) and "R" or "N"
539
            return code, pol
540

    
541
        tpol = False
542
        if _mem.txtone != 0xFFFF and (_mem.txtone & 0x2800) == 0x2800:
543
            tcode, tpol = _get_dcs(_mem.txtone)
544
            mem.dtcs = tcode
545
            txmode = "DTCS"
546
        elif _mem.txtone != 0xFFFF and _mem.txtone != 0x0:
547
            mem.rtone = (_mem.txtone & 0x7fff) / 10.0
548
            txmode = "Tone"
549
        else:
550
            txmode = ""
551

    
552
        rpol = False
553
        if _mem.rxtone != 0xFFFF and (_mem.rxtone & 0x2800) == 0x2800:
554
            rcode, rpol = _get_dcs(_mem.rxtone)
555
            mem.rx_dtcs = rcode
556
            rxmode = "DTCS"
557
        elif _mem.rxtone != 0xFFFF and _mem.rxtone != 0x0:
558
            mem.ctone = (_mem.rxtone & 0x7fff) / 10.0
559
            rxmode = "Tone"
560
        else:
561
            rxmode = ""
562

    
563
        if txmode == "Tone" and not rxmode:
564
            mem.tmode = "Tone"
565
        elif txmode == rxmode and txmode == "Tone" and mem.rtone == mem.ctone:
566
            mem.tmode = "TSQL"
567
        elif txmode == rxmode and txmode == "DTCS" and mem.dtcs == mem.rx_dtcs:
568
            mem.tmode = "DTCS"
569
        elif rxmode or txmode:
570
            mem.tmode = "Cross"
571
            mem.cross_mode = "%s->%s" % (txmode, rxmode)
572

    
573
        # always set it even if no dtcs is used
574
        mem.dtcs_polarity = "%s%s" % (tpol or "N", rpol or "N")
575

    
576
        LOG.debug("Got TX %s (%i) RX %s (%i)" %
577
                  (txmode, _mem.txtone, rxmode, _mem.rxtone))
578

    
579
    def get_memory(self, number):
580
        _mem = self._memobj.memory[number]
581
        _nam = self._memobj.names[number]
582

    
583
        mem = chirp_common.Memory()
584
        mem.number = number
585
        _valid = self._memobj.valid[mem.number]
586
        LOG.debug("%d %s", number, _valid == MEM_VALID)
587
        if _valid != MEM_VALID:
588
            mem.empty = True
589
            return mem
590
        else:
591
            mem.empty = False
592

    
593
        mem.freq = int(_mem.rxfreq) * 10
594

    
595
        if _mem.txfreq == 0xFFFFFFFF:
596
            # TX freq not set
597
            mem.duplex = "off"
598
            mem.offset = 0
599
        elif int(_mem.rxfreq) == int(_mem.txfreq):
600
            mem.duplex = ""
601
            mem.offset = 0
602
        elif abs(int(_mem.rxfreq) * 10 - int(_mem.txfreq) * 10) > 70000000:
603
            mem.duplex = "split"
604
            mem.offset = int(_mem.txfreq) * 10
605
        else:
606
            mem.duplex = int(_mem.rxfreq) > int(_mem.txfreq) and "-" or "+"
607
            mem.offset = abs(int(_mem.rxfreq) - int(_mem.txfreq)) * 10
608

    
609
        for char in _nam.name:
610
            if char != 0:
611
                mem.name += chr(char)
612
        mem.name = mem.name.rstrip()
613

    
614
        self._get_tone(_mem, mem)
615

    
616
        mem.skip = "" if bool(_mem.scan_add) else "S"
617

    
618
        mem.power = self.POWER_LEVELS[_mem.power]
619
        mem.mode = _mem.iswide and "FM" or "NFM"
620
        return mem
621

    
622
    def _set_tone(self, mem, _mem):
623
        def _set_dcs(code, pol):
624
            val = int("%i" % code, 8) + 0x2800
625
            if pol == "R":
626
                val += 0x8000
627
            return val
628

    
629
        rx_mode = tx_mode = None
630
        rxtone = txtone = 0x0000
631

    
632
        if mem.tmode == "Tone":
633
            tx_mode = "Tone"
634
            rx_mode = None
635
            txtone = int(mem.rtone * 10) + 0x8000
636
        elif mem.tmode == "TSQL":
637
            rx_mode = tx_mode = "Tone"
638
            rxtone = txtone = int(mem.ctone * 10) + 0x8000
639
        elif mem.tmode == "DTCS":
640
            tx_mode = rx_mode = "DTCS"
641
            txtone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0])
642
            rxtone = _set_dcs(mem.dtcs, mem.dtcs_polarity[1])
643
        elif mem.tmode == "Cross":
644
            tx_mode, rx_mode = mem.cross_mode.split("->")
645
            if tx_mode == "DTCS":
646
                txtone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0])
647
            elif tx_mode == "Tone":
648
                txtone = int(mem.rtone * 10) + 0x8000
649
            if rx_mode == "DTCS":
650
                rxtone = _set_dcs(mem.rx_dtcs, mem.dtcs_polarity[1])
651
            elif rx_mode == "Tone":
652
                rxtone = int(mem.ctone * 10) + 0x8000
653

    
654
        _mem.rxtone = rxtone
655
        _mem.txtone = txtone
656

    
657
        LOG.debug("Set TX %s (%i) RX %s (%i)" %
658
                  (tx_mode, _mem.txtone, rx_mode, _mem.rxtone))
659

    
660
    def set_memory(self, mem):
661
        number = mem.number
662

    
663
        _mem = self._memobj.memory[number]
664
        _nam = self._memobj.names[number]
665

    
666
        if mem.empty:
667
            _mem.set_raw("\x00" * (_mem.size() // 8))
668
            self._memobj.valid[number] = 0
669
            self._memobj.names[number].set_raw("\x00" * (_nam.size() // 8))
670
            return
671

    
672
        _mem.rxfreq = int(mem.freq / 10)
673
        if mem.duplex == "off":
674
            _mem.txfreq = 0xFFFFFFFF
675
        elif mem.duplex == "split":
676
            _mem.txfreq = int(mem.offset / 10)
677
        elif mem.duplex == "off":
678
            for i in range(0, 4):
679
                _mem.txfreq[i].set_raw("\xFF")
680
        elif mem.duplex == "+":
681
            _mem.txfreq = int(mem.freq / 10) + int(mem.offset / 10)
682
        elif mem.duplex == "-":
683
            _mem.txfreq = int(mem.freq / 10) - int(mem.offset / 10)
684
        else:
685
            _mem.txfreq = int(mem.freq / 10)
686
        _mem.scan_add = int(mem.skip != "S")
687
        _mem.iswide = int(mem.mode == "FM")
688
        # set the tone
689
        self._set_tone(mem, _mem)
690
        # set the scrambler and compander to off by default
691
        _mem.scrambler = 0
692
        _mem.compander = 0
693
        # set the power
694
        if mem.power:
695
            _mem.power = self.POWER_LEVELS.index(mem.power)
696
        else:
697
            _mem.power = True
698
        # set to mute mode to QT (not QT+DTMF or QT*DTMF) by default
699
        _mem.mute_mode = 0
700

    
701
        for i in range(0, len(_nam.name)):
702
            if i < len(mem.name) and mem.name[i]:
703
                _nam.name[i] = ord(mem.name[i])
704
            else:
705
                _nam.name[i] = 0x0
706
        self._memobj.valid[mem.number] = MEM_VALID
707

    
708
    def _get_settings(self):
709
        _settings = self._memobj.settings
710
        _vfoa = self._memobj.vfoa
711
        _vfob = self._memobj.vfob
712
        cfg_grp = RadioSettingGroup("cfg_grp", "Configuration")
713
        vfoa_grp = RadioSettingGroup("vfoa_grp", "VFO A Settings")
714
        vfob_grp = RadioSettingGroup("vfob_grp", "VFO B Settings")
715
        key_grp = RadioSettingGroup("key_grp", "Key Settings")
716
        lmt_grp = RadioSettingGroup("lmt_grp", "Frequency Limits")
717
        uhf_lmt_grp = RadioSettingGroup("uhf_lmt_grp", "UHF")
718
        vhf_lmt_grp = RadioSettingGroup("vhf_lmt_grp", "VHF")
719
        vhf1_lmt_grp = RadioSettingGroup("vhf1_lmt_grp", "VHF1")
720
        oem_grp = RadioSettingGroup("oem_grp", "OEM Info")
721

    
722
        lmt_grp.append(vhf_lmt_grp);
723
        lmt_grp.append(vhf1_lmt_grp);
724
        lmt_grp.append(uhf_lmt_grp);
725
        group = RadioSettings(cfg_grp, vfoa_grp, vfob_grp,
726
                              key_grp, lmt_grp, oem_grp)
727

    
728
        #
729
        # Configuration Settings
730
        #
731
        rs = RadioSetting("channel_menu", "Menu available in channel mode",
732
                          RadioSettingValueBoolean(_settings.channel_menu))
733
        cfg_grp.append(rs)
734
        rs = RadioSetting("ponmsg", "Poweron message",
735
                          RadioSettingValueList(
736
                              PONMSG_LIST, PONMSG_LIST[_settings.ponmsg]))
737
        cfg_grp.append(rs)
738
        rs = RadioSetting("voice", "Voice Guide",
739
                          RadioSettingValueBoolean(_settings.voice))
740
        cfg_grp.append(rs)
741
        rs = RadioSetting("language", "Language",
742
                          RadioSettingValueList(LANGUAGE_LIST,
743
                                                LANGUAGE_LIST[_settings.
744
                                                              language]))
745
        cfg_grp.append(rs)
746
        rs = RadioSetting("timeout", "Timeout Timer",
747
                          RadioSettingValueList(
748
                              TIMEOUT_LIST, TIMEOUT_LIST[_settings.timeout]))
749
        cfg_grp.append(rs)
750
        rs = RadioSetting("toalarm", "Timeout Alarm",
751
                          RadioSettingValueInteger(0, 10, _settings.toalarm))
752
        cfg_grp.append(rs)
753
        rs = RadioSetting("roger_beep", "Roger Beep",
754
                          RadioSettingValueList(ROGER_LIST,
755
                                                ROGER_LIST[_settings.roger_beep]))
756
        cfg_grp.append(rs)
757
        rs = RadioSetting("power_save", "Power save",
758
                          RadioSettingValueBoolean(_settings.power_save))
759
        cfg_grp.append(rs)
760
        rs = RadioSetting("autolock", "Autolock",
761
                          RadioSettingValueBoolean(_settings.autolock))
762
        cfg_grp.append(rs)
763
        rs = RadioSetting("keylock", "Keypad Lock",
764
                          RadioSettingValueBoolean(_settings.keylock))
765
        cfg_grp.append(rs)
766
        rs = RadioSetting("beep", "Keypad Beep",
767
                          RadioSettingValueBoolean(_settings.beep))
768
        cfg_grp.append(rs)
769
        rs = RadioSetting("stopwatch", "Stopwatch",
770
                          RadioSettingValueBoolean(_settings.stopwatch))
771
        cfg_grp.append(rs)
772
        rs = RadioSetting("backlight", "Backlight",
773
                          RadioSettingValueList(BACKLIGHT_LIST,
774
                                                BACKLIGHT_LIST[_settings.
775
                                                               backlight]))
776
        cfg_grp.append(rs)
777
        rs = RadioSetting("dtmf_st", "DTMF Sidetone",
778
                          RadioSettingValueList(DTMFST_LIST,
779
                                                DTMFST_LIST[_settings.
780
                                                            dtmf_st]))
781
        cfg_grp.append(rs)
782
        rs = RadioSetting("ani_sw", "ANI-ID Switch",
783
                          RadioSettingValueBoolean(_settings.ani_sw))
784
        cfg_grp.append(rs)
785
        rs = RadioSetting("ptt_id", "PTT-ID Delay",
786
                          RadioSettingValueList(PTTID_LIST,
787
                                                PTTID_LIST[_settings.ptt_id]))
788
        cfg_grp.append(rs)
789
        rs = RadioSetting("ring_time", "Ring Time",
790
                          RadioSettingValueList(LIST_10,
791
                                                LIST_10[_settings.ring_time]))
792
        cfg_grp.append(rs)
793
        rs = RadioSetting("scan_rev", "Scan Mode",
794
                          RadioSettingValueList(SCANMODE_LIST,
795
                                                SCANMODE_LIST[_settings.
796
                                                              scan_rev]))
797
        cfg_grp.append(rs)
798
        rs = RadioSetting("vox", "VOX",
799
                          RadioSettingValueList(LIST_10,
800
                                                LIST_10[_settings.vox]))
801
        cfg_grp.append(rs)
802
        rs = RadioSetting("prich_sw", "Priority Channel Switch",
803
                          RadioSettingValueBoolean(_settings.prich_sw))
804
        cfg_grp.append(rs)
805
        rs = RadioSetting("pri_ch", "Priority Channel",
806
                          RadioSettingValueInteger(1, 999, _settings.pri_ch))
807
        cfg_grp.append(rs)
808
        rs = RadioSetting("rpt_mode", "Radio Mode",
809
                          RadioSettingValueList(RPTMODE_LIST,
810
                                                RPTMODE_LIST[_settings.
811
                                                             rpt_mode]))
812
        cfg_grp.append(rs)
813
        rs = RadioSetting("rpt_set", "Repeater Setting",
814
                          RadioSettingValueList(RPTSET_LIST,
815
                                                RPTSET_LIST[_settings.
816
                                                            rpt_set]))
817
        cfg_grp.append(rs)
818
        rs = RadioSetting("rpt_spk", "Repeater Mode Speaker",
819
                          RadioSettingValueBoolean(_settings.rpt_spk))
820
        cfg_grp.append(rs)
821
        rs = RadioSetting("rpt_ptt", "Repeater PTT",
822
                          RadioSettingValueBoolean(_settings.rpt_ptt))
823
        cfg_grp.append(rs)
824
        rs = RadioSetting("dtmf_tx_time", "DTMF Tx Duration",
825
                          RadioSettingValueList(DTMF_TIMES,
826
                                                DTMF_TIMES[_settings.
827
                                                           dtmf_tx_time]))
828
        cfg_grp.append(rs)
829
        rs = RadioSetting("dtmf_interval", "DTMF Interval",
830
                          RadioSettingValueList(DTMF_TIMES,
831
                                                DTMF_TIMES[_settings.
832
                                                           dtmf_interval]))
833
        cfg_grp.append(rs)
834
        rs = RadioSetting("alert", "Alert Tone",
835
                          RadioSettingValueList(ALERTS_LIST,
836
                                                ALERTS_LIST[_settings.alert]))
837
        cfg_grp.append(rs)
838
        rs = RadioSetting("rpt_tone", "Repeater Tone",
839
                          RadioSettingValueBoolean(_settings.rpt_tone))
840
        cfg_grp.append(rs)
841
        rs = RadioSetting("rpt_hold", "Repeater Hold Time",
842
                          RadioSettingValueList(HOLD_TIMES,
843
                                                HOLD_TIMES[_settings.
844
                                                           rpt_hold]))
845
        cfg_grp.append(rs)
846
        rs = RadioSetting("scan_det", "Scan DET",
847
                          RadioSettingValueBoolean(_settings.scan_det))
848
        cfg_grp.append(rs)
849
        rs = RadioSetting("sc_qt", "SC-QT",
850
                          RadioSettingValueList(SCQT_LIST,
851
                                                SCQT_LIST[_settings.sc_qt]))
852
        cfg_grp.append(rs)
853
        rs = RadioSetting("smuteset", "SubFreq Mute",
854
                          RadioSettingValueList(SMUTESET_LIST,
855
                                                SMUTESET_LIST[_settings.
856
                                                              smuteset]))
857
        cfg_grp.append(rs)
858

    
859
                #
860
        # VFO A Settings
861
        #
862
        rs = RadioSetting("workmode_a", "VFO A Workmode",
863
                          RadioSettingValueList(WORKMODE_LIST, WORKMODE_LIST[_settings.workmode_a]))
864
        vfoa_grp.append(rs)
865
        rs = RadioSetting("work_cha", "VFO A Channel",
866
                          RadioSettingValueInteger(1, 999, _settings.work_cha))
867
        vfoa_grp.append(rs)
868
        rs = RadioSetting("vfoa.rxfreq", "VFO A Rx Frequency",
869
                          RadioSettingValueInteger(
870
                              134000000, 520000000, _vfoa.rxfreq * 10, 5000))
871
        vfoa_grp.append(rs)
872
        rs = RadioSetting("vfoa.txoffset", "VFO A Tx Offset",
873
                          RadioSettingValueInteger(
874
                              0, 520000000, _vfoa.txoffset * 10, 5000))
875
        vfoa_grp.append(rs)
876
        #   u16   rxtone;
877
        #   u16   txtone;
878
        rs = RadioSetting("vfoa.power", "VFO A Power",
879
                          RadioSettingValueList(
880
                              POWER_LIST, POWER_LIST[_vfoa.power]))
881
        vfoa_grp.append(rs)
882
        #         shift_dir:2
883
        rs = RadioSetting("vfoa.iswide", "VFO A NBFM",
884
                          RadioSettingValueList(
885
                              BANDWIDTH_LIST, BANDWIDTH_LIST[_vfoa.iswide]))
886
        vfoa_grp.append(rs)
887
        rs = RadioSetting("vfoa.mute_mode", "VFO A Mute",
888
                          RadioSettingValueList(
889
                              SPMUTE_LIST, SPMUTE_LIST[_vfoa.mute_mode]))
890
        vfoa_grp.append(rs)
891
        rs = RadioSetting("vfoa.step", "VFO A Step (kHz)",
892
                          RadioSettingValueList(
893
                              STEP_LIST, STEP_LIST[_vfoa.step]))
894
        vfoa_grp.append(rs)
895
        rs = RadioSetting("vfoa.squelch", "VFO A Squelch",
896
                          RadioSettingValueList(
897
                              LIST_10, LIST_10[_vfoa.squelch]))
898
        vfoa_grp.append(rs)
899
        rs = RadioSetting("bcl_a", "Busy Channel Lock-out A",
900
                          RadioSettingValueBoolean(_settings.bcl_a))
901
        vfoa_grp.append(rs)
902

    
903
                #
904
        # VFO B Settings
905
        #
906
        rs = RadioSetting("workmode_b", "VFO B Workmode",
907
                          RadioSettingValueList(WORKMODE_LIST, WORKMODE_LIST[_settings.workmode_b]))
908
        vfob_grp.append(rs)
909
        rs = RadioSetting("work_chb", "VFO B Channel",
910
                          RadioSettingValueInteger(1, 999, _settings.work_chb))
911
        vfob_grp.append(rs)
912
        rs = RadioSetting("vfob.rxfreq", "VFO B Rx Frequency",
913
                          RadioSettingValueInteger(
914
                              134000000, 520000000, _vfob.rxfreq * 10, 5000))
915
        vfob_grp.append(rs)
916
        rs = RadioSetting("vfob.txoffset", "VFO B Tx Offset",
917
                          RadioSettingValueInteger(
918
                              0, 520000000, _vfob.txoffset * 10, 5000))
919
        vfob_grp.append(rs)
920
        #   u16   rxtone;
921
        #   u16   txtone;
922
        rs = RadioSetting("vfob.power", "VFO B Power",
923
                          RadioSettingValueList(
924
                              POWER_LIST, POWER_LIST[_vfob.power]))
925
        vfob_grp.append(rs)
926
        #         shift_dir:2
927
        rs = RadioSetting("vfob.iswide", "VFO B NBFM",
928
                          RadioSettingValueList(
929
                              BANDWIDTH_LIST, BANDWIDTH_LIST[_vfob.iswide]))
930
        vfob_grp.append(rs)
931
        rs = RadioSetting("vfob.mute_mode", "VFO B Mute",
932
                          RadioSettingValueList(
933
                              SPMUTE_LIST, SPMUTE_LIST[_vfob.mute_mode]))
934
        vfob_grp.append(rs)
935
        rs = RadioSetting("vfob.step", "VFO B Step (kHz)",
936
                          RadioSettingValueList(
937
                              STEP_LIST, STEP_LIST[_vfob.step]))
938
        vfob_grp.append(rs)
939
        rs = RadioSetting("vfob.squelch", "VFO B Squelch",
940
                          RadioSettingValueList(
941
                              LIST_10, LIST_10[_vfob.squelch]))
942
        vfob_grp.append(rs)
943
        rs = RadioSetting("bcl_b", "Busy Channel Lock-out B",
944
                          RadioSettingValueBoolean(_settings.bcl_b))
945
        vfob_grp.append(rs)
946

    
947
                #
948
        # Key Settings
949
        #
950
        _msg = str(_settings.dispstr).split("\0")[0]
951
        val = RadioSettingValueString(0, 15, _msg)
952
        val.set_mutable(True)
953
        rs = RadioSetting("dispstr", "Display Message", val)
954
        key_grp.append(rs)
955

    
956
        dtmfchars = "0123456789"
957
        _codeobj = _settings.ani_code
958
        _code = "".join([dtmfchars[x] for x in _codeobj if int(x) < 0x0A])
959
        val = RadioSettingValueString(3, 6, _code, False)
960
        val.set_charset(dtmfchars)
961
        rs = RadioSetting("ani_code", "ANI Code", val)
962
        def apply_ani_id(setting, obj):
963
            value = []
964
            for j in range(0, 6):
965
                try:
966
                    value.append(dtmfchars.index(str(setting.value)[j]))
967
                except IndexError:
968
                    value.append(0xFF)
969
            obj.ani_code = value
970
        rs.set_apply_callback(apply_ani_id, _settings)
971
        key_grp.append(rs)
972

    
973
        rs = RadioSetting("pf1_func", "PF1 Key function",
974
                          RadioSettingValueList(
975
                              PF1KEY_LIST,
976
                              PF1KEY_LIST[_settings.pf1_func]))
977
        key_grp.append(rs)
978
        rs = RadioSetting("pf3_func", "PF3 Key function",
979
                          RadioSettingValueList(
980
                              PF3KEY_LIST,
981
                              PF3KEY_LIST[_settings.pf3_func]))
982
        key_grp.append(rs)
983

    
984
        #
985
        # Limits settings
986
        #
987
        rs = RadioSetting("vhf_limits.rx_start", "VHF RX Lower Limit",
988
                          RadioSettingValueInteger(
989
                              134000000, 174997500,
990
                              self._memobj.vhf_limits.rx_start * 10, 5000))
991
        vhf_lmt_grp.append(rs)
992
        rs = RadioSetting("vhf_limits.rx_stop", "VHF RX Upper Limit",
993
                          RadioSettingValueInteger(
994
                              134000000, 174997500,
995
                              self._memobj.vhf_limits.rx_stop * 10, 5000))
996
        vhf_lmt_grp.append(rs)
997
        rs = RadioSetting("vhf_limits.tx_start", "VHF TX Lower Limit",
998
                          RadioSettingValueInteger(
999
                              134000000, 174997500,
1000
                              self._memobj.vhf_limits.tx_start * 10, 5000))
1001
        vhf_lmt_grp.append(rs)
1002
        rs = RadioSetting("vhf_limits.tx_stop", "VHF TX Upper Limit",
1003
                          RadioSettingValueInteger(
1004
                              134000000, 174997500,
1005
                              self._memobj.vhf_limits.tx_stop * 10, 5000))
1006
        vhf_lmt_grp.append(rs)
1007

    
1008
        rs = RadioSetting("vhf1_limits.rx_start", "VHF1 RX Lower Limit",
1009
                          RadioSettingValueInteger(
1010
                              220000000, 265000000,
1011
                              self._memobj.vhf1_limits.rx_start * 10, 5000))
1012
        vhf1_lmt_grp.append(rs)
1013
        rs = RadioSetting("vhf1_limits.rx_stop", "VHF1 RX Upper Limit",
1014
                          RadioSettingValueInteger(
1015
                              220000000, 265000000,
1016
                              self._memobj.vhf1_limits.rx_stop * 10, 5000))
1017
        vhf1_lmt_grp.append(rs)
1018
        rs = RadioSetting("vhf1_limits.tx_start", "VHF1 TX Lower Limit",
1019
                          RadioSettingValueInteger(
1020
                              220000000, 265000000,
1021
                              self._memobj.vhf1_limits.tx_start * 10, 5000))
1022
        vhf1_lmt_grp.append(rs)
1023
        rs = RadioSetting("vhf1_limits.tx_stop", "VHF1 TX Upper Limit",
1024
                          RadioSettingValueInteger(
1025
                              220000000, 265000000,
1026
                              self._memobj.vhf1_limits.tx_stop * 10, 5000))
1027
        vhf1_lmt_grp.append(rs)
1028

    
1029
        rs = RadioSetting("uhf_limits.rx_start", "UHF RX Lower Limit",
1030
                          RadioSettingValueInteger(
1031
                              350000000, 520000000,
1032
                              self._memobj.uhf_limits.rx_start * 10, 5000))
1033
        uhf_lmt_grp.append(rs)
1034
        rs = RadioSetting("uhf_limits.rx_stop", "UHF RX Upper Limit",
1035
                          RadioSettingValueInteger(
1036
                              350000000, 520000000,
1037
                              self._memobj.uhf_limits.rx_stop * 10, 5000))
1038
        uhf_lmt_grp.append(rs)
1039
        rs = RadioSetting("uhf_limits.tx_start", "UHF TX Lower Limit",
1040
                          RadioSettingValueInteger(
1041
                              400000000, 520000000,
1042
                              self._memobj.uhf_limits.tx_start * 10, 5000))
1043
        uhf_lmt_grp.append(rs)
1044
        rs = RadioSetting("uhf_limits.tx_stop", "UHF TX Upper Limit",
1045
                          RadioSettingValueInteger(
1046
                              400000000, 520000000,
1047
                              self._memobj.uhf_limits.tx_stop * 10, 5000))
1048
        uhf_lmt_grp.append(rs)
1049

    
1050
        #
1051
        # OEM info
1052
        #
1053
        def _decode(lst):
1054
            _str = ''.join([chr(c) for c in lst
1055
                            if chr(c) in chirp_common.CHARSET_ASCII])
1056
            return _str
1057

    
1058
        def do_nothing(setting, obj):
1059
            return
1060

    
1061
        _str = _decode(self._memobj.oem_info.model)
1062
        val = RadioSettingValueString(0, 15, _str)
1063
        val.set_mutable(False)
1064
        rs = RadioSetting("oem_info.model", "Model", val)
1065
        rs.set_apply_callback(do_nothing, _settings)
1066
        oem_grp.append(rs)
1067
        _str = _decode(self._memobj.oem_info.oem1)
1068
        val = RadioSettingValueString(0, 15, _str)
1069
        val.set_mutable(False)
1070
        rs = RadioSetting("oem_info.oem1", "OEM String 1", val)
1071
        rs.set_apply_callback(do_nothing, _settings)
1072
        oem_grp.append(rs)
1073
        _str = _decode(self._memobj.oem_info.oem2)
1074
        val = RadioSettingValueString(0, 15, _str)
1075
        val.set_mutable(False)
1076
        rs = RadioSetting("oem_info.oem2", "OEM String 2", val)
1077
        rs.set_apply_callback(do_nothing, _settings)
1078
        oem_grp.append(rs)
1079
        _str = _decode(self._memobj.oem_info.version)
1080
        val = RadioSettingValueString(0, 15, _str)
1081
        val.set_mutable(False)
1082
        rs = RadioSetting("oem_info.version", "Software Version", val)
1083
        rs.set_apply_callback(do_nothing, _settings)
1084
        oem_grp.append(rs)
1085
        _str = _decode(self._memobj.oem_info.date)
1086
        val = RadioSettingValueString(0, 15, _str)
1087
        val.set_mutable(False)
1088
        rs = RadioSetting("oem_info.date", "OEM Date", val)
1089
        rs.set_apply_callback(do_nothing, _settings)
1090
        oem_grp.append(rs)
1091

    
1092
        return group
1093

    
1094
    def get_settings(self):
1095
        try:
1096
            return self._get_settings()
1097
        except:
1098
            import traceback
1099
            LOG.error("Failed to parse settings: %s", traceback.format_exc())
1100
            return None
1101

    
1102
    def set_settings(self, settings):
1103
        for element in settings:
1104
            if not isinstance(element, RadioSetting):
1105
                self.set_settings(element)
1106
                continue
1107
            else:
1108
                try:
1109
                    if "." in element.get_name():
1110
                        bits = element.get_name().split(".")
1111
                        obj = self._memobj
1112
                        for bit in bits[:-1]:
1113
                            obj = getattr(obj, bit)
1114
                        setting = bits[-1]
1115
                    else:
1116
                        obj = self._memobj.settings
1117
                        setting = element.get_name()
1118

    
1119
                    if element.has_apply_callback():
1120
                        LOG.debug("Using apply callback")
1121
                        element.run_apply_callback()
1122
                    else:
1123
                        LOG.debug("Setting %s = %s" % (setting, element.value))
1124
                        if self._is_freq(element):
1125
                            setattr(obj, setting, int(element.value)/10)
1126
                        else:
1127
                            setattr(obj, setting, element.value)
1128
                except Exception as e:
1129
                    LOG.debug(element.get_name())
1130
                    raise
1131

    
1132
    def _is_freq(self, element):
1133
        return "rxfreq" in element.get_name() or "txoffset" in element.get_name() or "rx_start" in element.get_name() or "rx_stop" in element.get_name() or "tx_start" in element.get_name() or "tx_stop" in element.get_name()
(8-8/9)