Skip to content

Commit

Permalink
Fix bitwise grammar for bitfield
Browse files Browse the repository at this point in the history
Long ago, an error in the bitwise grammar allowed bitfields to be
defined without the comma delimiter between fields. This fixes that
error to make the grammar correct and also fixes the *many* errors
in bitwise definitions in a lot of drivers.
  • Loading branch information
kk7ds committed Oct 30, 2023
1 parent bd659cf commit bf80d7d
Show file tree
Hide file tree
Showing 39 changed files with 201 additions and 198 deletions.
11 changes: 9 additions & 2 deletions chirp/bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ def items(self):


class Processor:
strict = False

_types = {
"u8": u8DataElement,
Expand Down Expand Up @@ -962,6 +963,11 @@ def parse_directive(self, directive):
name = directive[0][0]
value = directive[0][1][0][1]
if name == "seekto":
if self._offset == int(value, 0):
if self.strict:
raise SyntaxError('Unnecessary #seekto %s' % value)
else:
LOG.warning('Unnecessary #seekto %s' % value)
self._offset = int(value, 0)
elif name == "seek":
self._offset += int(value, 0)
Expand Down Expand Up @@ -992,18 +998,19 @@ def parse(spec, data, offset=0):

if __name__ == "__main__":
defn = """
// comment
struct mytype { u8 foo; };
struct mytype bar;
struct {
u8 foo;
u8 foo; // inline
u8 highbit:1,
sixzeros:6,
lowbit:1;
char string[3];
bbcd fourdigits[2];
} mystruct;
"""
data = "\xab\x7F\x81abc\x12\x34"
data = b"\xab\x7F\x81abc\x12\x34"
tree = parse(defn, data)

print(repr(tree))
Expand Down
4 changes: 2 additions & 2 deletions chirp/bitwise_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def count():


def bitdef():
return symbol, ":", count, -1
return symbol, ":", count


def _bitdeflist():
return bitdef, -1, (",", bitdef)


def bitfield():
return -2, _bitdeflist
return _bitdeflist


def array():
Expand Down
4 changes: 2 additions & 2 deletions chirp/drivers/anytone_iii.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_memory_mappings(self, memory):
pttid:2, // [Off, Begin, End, Begin&End]
unknown6:2,
bclo:2; // [Off, Repeater, Busy]
u8 unknown7:6
u8 unknown7:6,
band:2; // [2m, 1-1/4m, 350+ MHz, 70cm]
u8 unknown8:5,
sql_mode:3; // [Carrier, CTCSS/DCS Tones, Opt Sig Only,
Expand Down Expand Up @@ -238,7 +238,7 @@ def get_memory_mappings(self, memory):
clk_shift:1, // CLK Shift: 0=off 1=on
ext_spk_on:1, // Enable the external speaker
alt_key_mode:1, // Use Alt Keypad Mode: 0=off 1=on
beep_on:1 // Enable beep
beep_on:1, // Enable beep
no_tone_elim_tail:1, // Elim squelch tail when no CTCSS/DCS signaling
sql_key_mode:1; // SQL Key Function: [Momentary, Toggle]
u8 unknown16:5,
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/baofeng_wp970i.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class WP970I(baofeng_common.BaofengCommonHT):
sftd:2,
scode:4;
u8 unknown4;
u8 unused3:1
u8 unused3:1,
step:3,
unused4:4;
u8 unused5:1,
Expand Down
4 changes: 2 additions & 2 deletions chirp/drivers/bj9900.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ class BJ9900Radio(chirp_common.CloneModeRadio,
u16 is_txdigtone:1,
txdtcs_pol:1,
txtone:14;
u8 txdtmf:4
u8 txdtmf:4,
pttid:4;
u8 power:1,
wide:1,
compandor:1
compandor:1,
unknown3:5;
u8 namelen;
u8 name[7];
Expand Down
6 changes: 3 additions & 3 deletions chirp/drivers/ft1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
u8 lcd_dimmer; // 14 DIMMER
u8 dtmf_delay; // 18 DT DLY
u8 unknown0[3];
u8 unknown1:4
u8 unknown1:4,
lcd_contrast:4;
u8 lamp; // 28 LAMP
u8 lock; // 30 LOCK
Expand All @@ -76,7 +76,7 @@
u8 busy_led:1,
unknown9:2,
bclo:1, // 03 BCLO
beep_edge:1 // 06 BEP.EDG
beep_edge:1, // 06 BEP.EDG
unknown9_1:3;
u8 unknown10:5,
password:1,
Expand Down Expand Up @@ -248,7 +248,7 @@
u8 unknown7:1,
aprs_units_wind_mph:1,
aprs_units_rain_inch:1,
aprs_units_temperature_f:1
aprs_units_temperature_f:1,
aprs_units_altitude_ft:1,
unknown8:1,
aprs_units_distance_m:1,
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/ft2900.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _upload(radio):
unk:2,
dtmf_mode:1;
u8 unk:1,
ts_mut:1
ts_mut:1,
wires_auto:1,
busy_lockout:1,
edge_beep:1,
Expand Down
10 changes: 5 additions & 5 deletions chirp/drivers/ft450d.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio):
u8 tunerok:1, // @ Byte 4 ?? Poss tuned ok
cnturon:1,
unk4b:1,
dnr_on:1
dnr_on:1,
notch:1,
unk4c:1,
tmode:2; // Tone/Cross/etc as Off/Enc/Enc+Dec
Expand Down Expand Up @@ -146,7 +146,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio):
set0ea:1,
amfmdial:1, // 0= Enabled. 1 = Disabled
cwpitch:3; // 0-based index
u8 sql_rfg:1
u8 sql_rfg:1,
set0F:2,
cwweigt:5; // Index 1:2.5=0 -> 1:4.5=20
u8 cw_dly; // @x10 ms = val * 10
Expand All @@ -157,8 +157,8 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio):
emergen:1,
vox_dly:5; // ms = val * 100
u8 set15a:1,
stby_beep:1
set15b:1
stby_beep:1,
set15b:1,
mem_grp:1,
apo:4;
u8 tot; // Byte x16, 1:1
Expand Down Expand Up @@ -190,7 +190,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio):
cat_tot:2; // Index 0-3
u8 set2CA:2,
rtyrpol:1,
rtytpol:1
rtytpol:1,
rty_sft:2,
rty_ton:1,
set2CC:1;
Expand Down
4 changes: 2 additions & 2 deletions chirp/drivers/ft60.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _encode_name(mem):
x3B_6:2;
u8 x3C_0:2,
rev_hm:1,
mt_cl:1
mt_cl:1,
resume:2,
txsave:1,
pag_abk:1;
Expand Down Expand Up @@ -235,7 +235,7 @@ def _encode_name(mem):
u8 unknown4:1,
dtcs:7;
u8 unknown5;
u16 unknown5_1:1
u16 unknown5_1:1,
offset:15;
u8 unknown6[3];
};
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/ft7100.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _upload(radio):
u8 dtcs_index;
u8 is_mode_am:1,
unknown71:2,
is_packet96:1
is_packet96:1,
unknown72:2,
power_index:2;
u8 unknown81:2,
Expand Down
66 changes: 31 additions & 35 deletions chirp/drivers/ft7800.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,34 @@
ACK = b'\x06'

MEM_FORMAT = """
struct mem_struct {
u8 used:1,
unknown1:1,
mode:2,
unknown2:1,
duplex:3;
bbcd freq[3];
u8 clockshift:1,
tune_step:3,
unknown5:1, // TODO: tmode has extended settings, at least 4 bits
tmode:3;
bbcd split[3];
u8 power:2,
tone:6;
u8 unknown6:1,
dtcs:7;
u8 unknown7[2];
u8 offset;
u8 unknown9[3];
};
#seekto 0x002A;
u8 banks_unk2;
u8 current_channel;
u8 unk3;
u8 unk4;
u8 current_menu;
#seekto 0x0035;
u8 banks_unk1;
#seekto 0x00C8;
struct {
u8 memory[16];
} dtmf[16];
#seekto 0x003A;
struct {
u8 apo;
Expand Down Expand Up @@ -86,30 +99,14 @@
u8 unk6;
} settings;
struct mem_struct {
u8 used:1,
unknown1:1,
mode:2,
unknown2:1,
duplex:3;
bbcd freq[3];
u8 clockshift:1,
tune_step:3,
unknown5:1, // TODO: tmode has extended settings, at least 4 bits
tmode:3;
bbcd split[3];
u8 power:2,
tone:6;
u8 unknown6:1,
dtcs:7;
u8 unknown7[2];
u8 offset;
u8 unknown9[3];
};
#seekto 0x0048;
struct mem_struct vfos[5];
#seekto 0x00C8;
struct {
u8 memory[16];
} dtmf[16];
#seekto 0x01C8;
struct mem_struct homes[5];
Expand Down Expand Up @@ -793,6 +790,11 @@ def set_settings(self, uisettings):
u8 name[6];
} memory[500];
#seekto 0x%X;
struct {
u32 bitmap[16];
} bank_channels[10];
#seekto 0x51C8;
struct {
u8 skip0:2,
Expand All @@ -801,12 +803,6 @@ def set_settings(self, uisettings):
skip3:2;
} flags[250];
#seekto 0x%X;
struct {
u32 bitmap[16];
} bank_channels[10];
#seekto 0x7B48;
u8 checksum;
"""
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/ft857.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class FT857Radio(ft817.FT817Radio):
ars_430:1,
cw_weight:5;
u8 cw_delay;
u8 cw_delay_hi:1
u8 cw_delay_hi:1,
cw_sidetone:7;
u8 unknown10:2,
cw_speed:6;
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/ft90.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio):
step:3;
u8 artsmode:2,
unknown2:1,
isUhf2:1
isUhf2:1,
power:2,
shift:2;
u8 skip:1,
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/gmrsuv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def get_features(self):
sftd:2,
scode:4;
u8 unknown4;
u8 unused3:1
u8 unused3:1,
step:3,
unused4:4;
u8 txpower:1,
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/gmrsv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def get_features(self):
sftd:2,
unused5:4;
u8 unknown4;
u8 unused3:1
u8 unused3:1,
step:3,
unused4:4;
u8 txpower:1,
Expand Down
14 changes: 7 additions & 7 deletions chirp/drivers/ic2730.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

MEM_FORMAT = """
struct {
u24 freq_flags:6
u24 freq_flags:6,
freq:18;
u16 offset;
u8 tune_step:4,
Expand Down Expand Up @@ -90,11 +90,11 @@
#seekto 0x4e80;
struct {
u24 loflags:6
u24 loflags:6,
lofreq:18;
u24 hiflags:6
u24 hiflags:6,
hifreq:18;
u8 flag:4
u8 flag:4,
mode:4;
u8 tstp;
char name[6];
Expand Down Expand Up @@ -122,7 +122,7 @@
u8 civtcvr;
u8 sqlatt;
u8 sqldly;
u8 unk5014a:4
u8 unk5014a:4,
fanspeed:4;
u8 unk5015;
u8 bthvox;
Expand Down Expand Up @@ -193,8 +193,8 @@
u8 unk505b;
u8 unk505c;
u8 unk505d;
u8 unk505e:6
rpthangup:1
u8 unk505e:6,
rpthangup:1,
unk505e2:1;
u8 unk505f;
} settings;
Expand Down
2 changes: 1 addition & 1 deletion chirp/drivers/icq7.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
u8 fractional:1,
unknown:7;
bbcd offset[2];
u16 ctone:6
u16 ctone:6,
rtone:6,
tune_step:4;
} memory[200];
Expand Down
Loading

0 comments on commit bf80d7d

Please sign in to comment.