[chirp_devel] [PATCH 1 of 2] [bitwise] Allow packing in bcd msb for FT-60 fractional step. #1273
Tom Hayward
Wed Nov 27 09:17:29 PST 2013
# HG changeset patch
# User Tom Hayward <tom at 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")
More information about the chirp_devel
mailing list