From 70b3e0e31e6690ecdbb462fc11d76d9af2003d2f Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Thu, 15 Sep 2016 15:37:25 -0700 Subject: [PATCH 1/6] Working SPI support (#44) Add spi support. This is a work-in-progress that removes a bunch of resets, since they cause the device to be unresponsive, which leads to SPI issues. - import mmeowlink.exceptions so corrupt packets don't crash rf_dump_app - don't raise CommsException on lack of wakeup ack - attempt to make SerialRfSpy.CMD_RESET conditional on spi for backwards compatibility - Wait for hardware when RESET command issued --- mmeowlink/cli/rf_dump_app.py | 1 + mmeowlink/handlers/stick.py | 1 + mmeowlink/vendors/serial_interface.py | 11 ++++++++--- mmeowlink/vendors/serial_rf_spy.py | 14 +++++++++----- mmeowlink/vendors/subg_rfspy_link.py | 3 ++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/mmeowlink/cli/rf_dump_app.py b/mmeowlink/cli/rf_dump_app.py index 79e3096..51a8f14 100644 --- a/mmeowlink/cli/rf_dump_app.py +++ b/mmeowlink/cli/rf_dump_app.py @@ -2,6 +2,7 @@ from .. hex_handling import hexify from .. exceptions import CommsException +from mmeowlink.exceptions import CommsException,InvalidPacketReceived from mmeowlink.vendors.mmcommander_link import MMCommanderLink from mmeowlink.vendors.subg_rfspy_link import SubgRfspyLink diff --git a/mmeowlink/handlers/stick.py b/mmeowlink/handlers/stick.py index 26296ee..b3dc17d 100644 --- a/mmeowlink/handlers/stick.py +++ b/mmeowlink/handlers/stick.py @@ -211,6 +211,7 @@ def power_control (self, minutes=None): status = repeater(self.command, repetitions=500, ack_wait_seconds=20) + return True if status: return True else: diff --git a/mmeowlink/vendors/serial_interface.py b/mmeowlink/vendors/serial_interface.py index 809a20a..18122ac 100644 --- a/mmeowlink/vendors/serial_interface.py +++ b/mmeowlink/vendors/serial_interface.py @@ -22,9 +22,14 @@ def open( self ): if fuser.in_use(self.device): raise AlreadyInUseException("%s already in use" % self.device) - self.serial = serial.Serial( self.device, self.speed ) - self.clear_receive_buffer('New port open') - self.check_setup() + if self.device.find('spi') >= 0: + import spi_serial + self.serial = spi_serial.SpiSerial() + self.check_setup() + else: + self.serial = serial.Serial( self.device, self.speed ) + self.clear_receive_buffer('New port open') + self.check_setup() return True diff --git a/mmeowlink/vendors/serial_rf_spy.py b/mmeowlink/vendors/serial_rf_spy.py index ae7da48..719cc7d 100644 --- a/mmeowlink/vendors/serial_rf_spy.py +++ b/mmeowlink/vendors/serial_rf_spy.py @@ -57,6 +57,8 @@ def __init__(self, ser): def do_command(self, command, param="", timeout=0): self.send_command(command, param, timeout=timeout) + if command == self.CMD_RESET: + time.sleep(1) return self.get_response(timeout=timeout) def send_command(self, command, param="", timeout=1): @@ -66,11 +68,13 @@ def send_command(self, command, param="", timeout=1): self.ser.write_timeout = timeout - self.ser.write(chr(command)) - log.debug("command %d" % command) - if len(param) > 0: - log.debug("params: %s" % str(param).encode('hex')) - self.ser.write(param) + cmd_str = chr(command) + param + + self.ser.write(cmd_str) + log.debug("command: " + cmd_str) + #if len(param) > 0: + # log.debug("params: %s" % str(param).encode('hex')) + # self.ser.write(param) self.ser.write_timeout = self.default_write_timeout diff --git a/mmeowlink/vendors/subg_rfspy_link.py b/mmeowlink/vendors/subg_rfspy_link.py index 344e84c..720333b 100644 --- a/mmeowlink/vendors/subg_rfspy_link.py +++ b/mmeowlink/vendors/subg_rfspy_link.py @@ -67,7 +67,8 @@ def set_base_freq(self, freq_mhz): def check_setup(self): self.serial_rf_spy = SerialRfSpy(self.serial) - +# if self.device.find('spi') >= 0: +# self.serial_rf_spy.do_command(SerialRfSpy.CMD_RESET, param="", timeout=1) self.serial_rf_spy.sync() # Check it's a SerialRfSpy device by retrieving the firmware version From cd4a79f4f2a12b2e7203e433472c23d416fc9b45 Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 1 Oct 2016 14:28:53 -0700 Subject: [PATCH 2/6] keep listening after InvalidPacketReceived --- mmeowlink/detect_radio_comms.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mmeowlink/detect_radio_comms.py b/mmeowlink/detect_radio_comms.py index d010391..4b3ae12 100644 --- a/mmeowlink/detect_radio_comms.py +++ b/mmeowlink/detect_radio_comms.py @@ -1,6 +1,7 @@ import time from exceptions import CommsException +from mmeowlink.exceptions import CommsException,InvalidPacketReceived from hex_handling import hexify from vendors.mmcommander_link import MMCommanderLink @@ -30,6 +31,8 @@ def detect(self): hex_string = hexify(resp).upper() except CommsException as e: pass + except InvalidPacketReceived: + print "%s (N/A db) - Corrupt packet" % ts # EG: A7 12 31 23 22 5D .. .. # POS: 01234567890123456789 From 3e81ce17e571070baa80900a79ff29d6ac9c3800 Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 1 Oct 2016 14:40:55 -0700 Subject: [PATCH 3/6] 'ts' is not defined here --- mmeowlink/detect_radio_comms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmeowlink/detect_radio_comms.py b/mmeowlink/detect_radio_comms.py index 4b3ae12..0613b4b 100644 --- a/mmeowlink/detect_radio_comms.py +++ b/mmeowlink/detect_radio_comms.py @@ -32,7 +32,7 @@ def detect(self): except CommsException as e: pass except InvalidPacketReceived: - print "%s (N/A db) - Corrupt packet" % ts + print "Corrupt packet received; ignoring" # EG: A7 12 31 23 22 5D .. .. # POS: 01234567890123456789 From 23ba0f428b8474d91a29b5647b8bbfc1ec0d7d9f Mon Sep 17 00:00:00 2001 From: Jason Wittmer Date: Sun, 9 Oct 2016 17:17:07 -0500 Subject: [PATCH 4/6] Update subg_rfspy_link.py Update supported_versions to include 0.9 --- mmeowlink/vendors/subg_rfspy_link.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmeowlink/vendors/subg_rfspy_link.py b/mmeowlink/vendors/subg_rfspy_link.py index 720333b..cf9a497 100644 --- a/mmeowlink/vendors/subg_rfspy_link.py +++ b/mmeowlink/vendors/subg_rfspy_link.py @@ -38,7 +38,7 @@ class SubgRfspyLink(SerialInterface): # Which version of subg_rfspy do we support? UINT16_TIMEOUT_VERSIONS = ["0.6"] - SUPPORTED_VERSIONS = ["0.6", "0.7", "0.8"] + SUPPORTED_VERSIONS = ["0.6", "0.7", "0.8", "0.9"] RFSPY_ERRORS = { 0xaa: "Timeout", From 78a997982fe2ec2ab65813fcaaf41de6eb94758b Mon Sep 17 00:00:00 2001 From: Oskar Pearson Date: Mon, 21 Nov 2016 00:49:14 +0000 Subject: [PATCH 5/6] Added support for radio_locale parameter --- mmeowlink/vendors/mmeowlink.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mmeowlink/vendors/mmeowlink.py b/mmeowlink/vendors/mmeowlink.py index 4055df0..d5af623 100644 --- a/mmeowlink/vendors/mmeowlink.py +++ b/mmeowlink/vendors/mmeowlink.py @@ -91,7 +91,10 @@ def setup_medtronic (self): # setup_logging(self) setup_medtronic_link(self) serial = self.device.get('serial') - self.mmtune = MMTune(self.pump.link, serial) + radio_locale = self.device.get('radio_locale') + if not radio_locale: + radio_locale = 'US' + self.mmtune = MMTune(self.pump.link, serial, radio_locale) def main (self, args, app): return self.mmtune.run( ) From b6a61c618ba25dccfb8aed29f91e8391f49b0fc7 Mon Sep 17 00:00:00 2001 From: Oskar Pearson Date: Sat, 3 Dec 2016 00:35:29 +0200 Subject: [PATCH 6/6] Change detect_radio_comms.py corrupt packet message --- mmeowlink/detect_radio_comms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmeowlink/detect_radio_comms.py b/mmeowlink/detect_radio_comms.py index 0613b4b..4b3ae12 100644 --- a/mmeowlink/detect_radio_comms.py +++ b/mmeowlink/detect_radio_comms.py @@ -32,7 +32,7 @@ def detect(self): except CommsException as e: pass except InvalidPacketReceived: - print "Corrupt packet received; ignoring" + print "%s (N/A db) - Corrupt packet" % ts # EG: A7 12 31 23 22 5D .. .. # POS: 01234567890123456789