[chirp_devel] [PATCH 0 of 2 ] Signed settings needed in ft8x7
To fix #863 I added signet support to bitwise grammar. Everything seems ok but the bitwise browser which does not correctly shows negative values.
73 de IZ3GME Marco
# HG changeset patch # User Marco Filippi iz3gme.marco@gmail.com # Date 1368103529 -7200 # Node ID f161e27eb3dd26f857e92b5c85d579fcde78ac31 # Parent 113d314ca49639e98f09dbf800422bcfadc2924b bitwise: add signed integer support needed for #863
diff --git a/chirp/bitwise.py b/chirp/bitwise.py --- a/chirp/bitwise.py +++ b/chirp/bitwise.py @@ -25,6 +25,13 @@ # ul24 foo; /* Unsigned 24-bit value (LE) */ # u32 foo; /* Unsigned 32-bit value */ # ul32 foo; /* Unsigned 32-bit value (LE) */ +# i8 foo; /* Signed 8-bit value */ +# i16 foo; /* Signed 16-bit value */ +# il16 foo; /* Signed 16-bit value (LE) */ +# i24 foo; /* Signed 24-bit value */ +# il24 foo; /* Signed 24-bit value (LE) */ +# i32 foo; /* Signed 32-bit value */ +# il32 foo; /* Signed 32-bit value (LE) */ # char foo; /* Character (single-byte */ # lbcd foo; /* BCD-encoded byte (LE) */ # bbcd foo; /* BCD-encoded byte (BE) */ @@ -401,7 +408,7 @@
class ul16DataElement(u16DataElement): _endianess = "<" - + class u24DataElement(intDataElement): _size = 3 _endianess = ">" @@ -438,6 +445,65 @@ class ul32DataElement(u32DataElement): _endianess = "<"
+class i8DataElement(u8DataElement): + _size = 1 + + def _get_value(self, data): + return struct.unpack("b", data)[0] + + def set_value(self, value): + self._data[self._offset] = struct.pack("b", int(value) ) + +class i16DataElement(intDataElement): + _size = 2 + _endianess = ">" + + def _get_value(self, data): + return struct.unpack(self._endianess + "h", data)[0] + + def set_value(self, value): + self._data[self._offset] = struct.pack(self._endianess + "h", + int(value) ) + +class il16DataElement(i16DataElement): + _endianess = "<" + +class i24DataElement(intDataElement): + _size = 3 + _endianess = ">" + + def _get_value(self, data): + pre = self._endianess == ">" and "\x00" or "" + post = self._endianess == "<" and "\x00" or "" + return struct.unpack(self._endianess + "i", pre+data+post)[0] + + def set_value(self, value): + if self._endianess == "<": + start = 0 + end = 3 + else: + start = 1 + end = 4 + self._data[self._offset] = struct.pack(self._endianess + "i", + int(value) )[start:end] + +class il24DataElement(i24DataElement): + _endianess = "<" + +class i32DataElement(intDataElement): + _size = 4 + _endianess = ">" + + def _get_value(self, data): + return struct.unpack(self._endianess + "i", data)[0] + + def set_value(self, value): + self._data[self._offset] = struct.pack(self._endianess + "i", + int(value) ) + +class il32DataElement(i32DataElement): + _endianess = "<" + class charDataElement(DataElement): _size = 1
@@ -629,6 +695,12 @@ "ul24" : ul24DataElement, "u32" : u32DataElement, "ul32" : ul32DataElement, + "i8" : i8DataElement, + "i16" : i16DataElement, + "il16" : il16DataElement, + "i24" : i24DataElement, + "il24" : il24DataElement, + "i32" : i32DataElement, "char" : charDataElement, "lbcd" : lbcdDataElement, "bbcd" : bbcdDataElement, diff --git a/chirp/bitwise_grammar.py b/chirp/bitwise_grammar.py --- a/chirp/bitwise_grammar.py +++ b/chirp/bitwise_grammar.py @@ -16,7 +16,8 @@ import re from chirp.pyPEG import keyword, parse as pypeg_parse
-TYPES = ["bit", "u8", "u16", "ul16", "u24", "ul24", "u32", "ul32", "char", +TYPES = ["bit", "u8", "u16", "ul16", "u24", "ul24", "u32", "ul32", + "i8", "i16", "il16", "i24", "il24", "i32", "il32", "char", "lbcd", "bbcd"] DIRECTIVES = ["seekto", "seek", "printoffset"]
bitwise: add signed integer support
Cool!
+# i8 foo; /* Signed 8-bit value */ +# i16 foo; /* Signed 16-bit value */ +# il16 foo; /* Signed 16-bit value (LE) */ +# i24 foo; /* Signed 24-bit value */ +# il24 foo; /* Signed 24-bit value (LE) */ +# i32 foo; /* Signed 32-bit value */ +# il32 foo; /* Signed 32-bit value (LE) */
What is the choice of using 'i' here? For 'integer'? I think 's' for 'signed' would make more sense to me. What do you think?
You added whitespace here :)
Thanks!
Hi Dan
+# i8 foo; /* Signed 8-bit value */ +# i16 foo; /* Signed 16-bit value */ +# il16 foo; /* Signed 16-bit value (LE) */ +# i24 foo; /* Signed 24-bit value */ +# il24 foo; /* Signed 24-bit value (LE) */ +# i32 foo; /* Signed 32-bit value */ +# il32 foo; /* Signed 32-bit value (LE) */
What is the choice of using 'i' here? For 'integer'? I think 's' for 'signed' would make more sense to me. What do you think?
Well ... 'i' is for integer as in printf where 'u' is for unsigned int (same as % operator in python pre PEP-237)
I prefere 'i' but if your choise is 's' I don't mind.
You added whitespace here :)
You are allowed to delete it ;)
73 de IZ3GME Marco
# HG changeset patch # User Marco Filippi iz3gme.marco@gmail.com # Date 1368103650 -7200 # Node ID 7b06ae4691d0e131596655fbd6a2e67029207227 # Parent f161e27eb3dd26f857e92b5c85d579fcde78ac31 [ft8x7] make use of signed integer where needed in settings fix #863
diff --git a/chirp/ft817.py b/chirp/ft817.py --- a/chirp/ft817.py +++ b/chirp/ft817.py @@ -159,12 +159,12 @@ pkt_mic:7; u8 unknown14:1, pkt9600_mic:7; - ul16 dig_shift; - ul16 dig_disp; - u8 r_lsb_car; - u8 r_usb_car; - u8 t_lsb_car; - u8 t_usb_car; + il16 dig_shift; + il16 dig_disp; + i8 r_lsb_car; + i8 r_usb_car; + i8 t_lsb_car; + i8 t_usb_car; u8 unknown15:2, menu_item:6; u8 unknown16:4, diff --git a/chirp/ft857.py b/chirp/ft857.py --- a/chirp/ft857.py +++ b/chirp/ft857.py @@ -157,12 +157,12 @@ pkt1200:7; u8 unknown15:1, pkt9600:7; - ul16 dig_shift; - ul16 dig_disp; - u8 r_lsb_car; - u8 r_usb_car; - u8 t_lsb_car; - u8 t_usb_car; + il16 dig_shift; + il16 dig_disp; + i8 r_lsb_car; + i8 r_usb_car; + i8 t_lsb_car; + i8 t_usb_car; u8 unknown16:1, menu_item:7; u8 unknown17[5];
participants (3)
-
Dan Smith
-
IZ3GME Marco
-
Marco Filippi IZ3GME