[chirp_devel] [PATCH 0 of 2] FT-60 frequency encoding #1273
The FT-60 uses the most significant bit (& 0x80) of its bcd frequency array to flag that the stored frequency should have 0.5 KHz added to it. Our bcd encoder did not support this (understandably--it's a complete violation of bcd format). I've added support here in a rather hacky way, by performing a different operation on the first element of the bcd array.
The other way we can handle this is to declare that the bcd encoder should remain true to bcd and flags like this should be handled in the radio driver. Please comment.
Tom KD7LXL
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1385572398 28800 # Node ID 93f5de5142ed81f73d43d6a6bcecf964a24dfcc5 # Parent 1a9283f1028738f2f1f0968fbd5ee1a99a67802d [bitwise] Allow packing in bcd msb for FT-60 fractional step. #1273
diff -r 1a9283f10287 -r 93f5de5142ed chirp/bitwise.py --- a/chirp/bitwise.py Wed Nov 27 08:41:33 2013 -0800 +++ b/chirp/bitwise.py Wed Nov 27 09:13:18 2013 -0800 @@ -215,10 +215,12 @@ raise ValueError("Cannot coerce this to int")
def __set_value_bbcd(self, value): - for i in reversed(self.__items): + for i in reversed(self.__items[1:]): twodigits = value % 100 value /= 100 i.set_value(twodigits) + # msb packing is only supported in first byte + self.__items[0].set_value(value)
def __set_value_lbcd(self, value): for i in self.__items: @@ -543,7 +545,8 @@ type(data))
def set_value(self, value): - self._data[self._offset] = int("%02i" % value, 16) + a, b = value / 10, value % 10 + self._data[self._offset] = (a << 4) + b
def _get_value(self, data): a = (ord(data) & 0xF0) >> 4 diff -r 1a9283f10287 -r 93f5de5142ed tests/unit/test_bitwise.py --- a/tests/unit/test_bitwise.py Wed Nov 27 08:41:33 2013 -0800 +++ b/tests/unit/test_bitwise.py Wed Nov 27 09:13:18 2013 -0800 @@ -168,6 +168,11 @@ expected = "\x42" + (len(_data) == 2 and "\x00" or "") raw = data.get_packed() self.assertEqual(raw, expected) + + # attempt set with bitwise + setattr(obj, name, value) + raw = data.get_packed() + self.assertEqual(_data, raw)
def test_bbcd(self): self._test_def("bbcd foo;", "foo", "\x12", 12) @@ -177,10 +182,18 @@
def test_bbcd_array(self): self._test_def("bbcd foo[2];", "foo", "\x12\x34", 1234) + self._test_def("bbcd foo[2];", "foo", "\x02\x34", 234)
def test_lbcd_array(self): self._test_def("lbcd foo[2];", "foo", "\x12\x34", 3412)
+ def test_bbcd_packed_msb(self): + self._test_def("bbcd foo;", "foo", "\xC4", 124) + + def test_bbcd_array_packed_msb(self): + self._test_def("bbcd foo[2];", "foo", "\xC4\x77", 12477) + + class TestBitwiseCharTypes(BaseTest): def test_char(self): data = memmap.MemoryMap("c")
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1385572552 28800 # Node ID 08504fccb356540010fe5cffc7fee4a76015794f # Parent 93f5de5142ed81f73d43d6a6bcecf964a24dfcc5 [ft60] Fix off-by-order-of-magnitude in frequency encoding. #1273
diff -r 93f5de5142ed -r 08504fccb356 chirp/ft60.py --- a/chirp/ft60.py Wed Nov 27 09:13:18 2013 -0800 +++ b/chirp/ft60.py Wed Nov 27 09:15:52 2013 -0800 @@ -97,7 +97,7 @@
def _encode_freq(freq): freqraw = freq / 10000 - if ((freq / 1000) % 10) == 5: + if ((freq / 100) % 10) == 5: freqraw += 800000 if chirp_common.is_fractional_step(freq): freqraw += 400000
participants (1)
-
Tom Hayward