[chirp_devel] Issues in bitwise.py
Daniele Forsi
Tue Feb 6 13:21:43 PST 2024
Hello,
the driver kyd_IP620.py has a channel memory structure of 16 bytes but
printing it shows a length of 15 bytes.
I get this output:
struct {
memory: struct {
rx_freq: 4:[(0)]
tx_freq: 4:[(0)]
rx_tone: 0x0000
tx_tone: 0x0000
unknown_1: 0x00 (....0000b)
busy_loc: 0x00 (......00b)
n_a: 0x00 (......00b)
unknown_2: 0x00 (.......0b)
scan_add: 0x00 (.......0b)
w_n: 0x00 (.......0b)
lout: 0x00 (.......0b)
n_a_: 0x00 (.......0b)
power: 0x00 (......00b)
unknown_3: 0x00
unknown_4: 0x00
} memory (15 bytes at 0x0000)
} (anonymous) (15 bytes at 0x0000)
using the following script
===
from chirp import bitwise
defn ="""
struct { // Channel memory structure
lbcd rx_freq[4]; // RX frequency
lbcd tx_freq[4]; // TX frequency
ul16 rx_tone; // RX tone
ul16 tx_tone; // TX tone
u8 unknown_1:4, // n-a
busy_loc:2, // NO-00, Crrier wave-01, SM-10
n_a:2; // n-a
u8 unknown_2:1, // n-a
scan_add:1, // Scan add
n_a:1, // n-a
w_n:1, // Narrow-0 Wide-1
lout:1, // LOCKOUT OFF-0 ON-1
n_a_:1, // n-a
power:2; // Power low-00 middle-01 high-10
u8 unknown_3; // n-a
u8 unknown_4; // n-a
} memory[1];
"""
data = bytearray(b"\x00" * 16)
tree = bitwise.parse(defn, data)
print(tree)
===
I do not own such a radio but the same issue could be present in other drivers.
I think that the reason is that n_a is used twice, so I reduced the
definition to this
defn ="""
struct {
u8 n_a:2;
u8 n_a:1;
} memory[1];
"""
but this throws a RecursionError exception at .../chirp/bitwise.py",
line 878, in do_bitfield
LOG.warn("WARNING: %i trailing bits unaccounted for in %s" %
I would submit a pull request but I don't know how to handle the
following issues in bitwise.py:
* line 878 doesn't correctly handle the name that it needs to print,
but I don't know how to fix it
* the __repr__ of class structDataElement and possibly 4 other lines
of code shouldn't use the integer division self.size() // 8 or the
size should be automatically padded to the next multiple of 8 with a
dummy member?
* should there be a warning for reused names of struct members or an exception?
thanks
--
73 de IU5HKX Daniele
More information about the chirp_devel
mailing list