From 5614d3b156ddd652eebe6ca1f5e2de5e9d8a7f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sun, 7 Jul 2019 22:29:13 +0100 Subject: Get and set the patient name on supported meters. This includes the command line extensions to include the get/set patient name, as well as the driver support for all FreeStyle devices with the shared HID protocol, although not all will support this properly. --- glucometerutils/drivers/fslibre.py | 3 ++- glucometerutils/glucometer.py | 22 ++++++++++++++++++++++ glucometerutils/support/freestyle.py | 9 +++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py index 87a6556..2823a2b 100644 --- a/glucometerutils/drivers/fslibre.py +++ b/glucometerutils/drivers/fslibre.py @@ -6,7 +6,8 @@ Supported features: - get readings (sensor, flash and blood glucose), including comments; - get and set date and time; - - get serial number and software version. + - get serial number and software version; + - get and set patient name. Expected device path: /dev/hidraw9 or similar HID device. Optional when using HIDAPI. diff --git a/glucometerutils/glucometer.py b/glucometerutils/glucometer.py index 8cf2555..8f222bc 100755 --- a/glucometerutils/glucometer.py +++ b/glucometerutils/glucometer.py @@ -58,6 +58,12 @@ def main(): '--set', action='store', nargs='?', const='now', default=None, help='Set the date rather than just reading it from the device.') + parser_patient = subparsers.add_parser( + 'patient', help='Reads or sets the patient information.') + parser_patient.add_argument( + '--set_name', action='store', required=False, + help='Set the patient name, if the meter supports it.') + args = parser.parse_args() logging.basicConfig(level=args.vlog) @@ -124,6 +130,22 @@ def main(): print(device.set_datetime(new_date)) else: print(device.get_datetime()) + elif args.action == 'patient': + if args.set_name != None: + try: + device.set_patient_name(args.set_name) + except NotImplementedError: + print( + 'The glucometer does not support setting patient name.') + try: + patient_name = device.get_patient_name() + if patient_name is None: + patient_name = '[N/A]' + print('Patient Name: {patient_name}'.format( + patient_name=patient_name)) + except NotImplementedError: + print( + 'The glucometer does not support retrieving patient name.') elif args.action == 'zero': confirm = input('Delete the device data log? (y/N) ') if confirm.lower() in ['y', 'ye', 'yes']: diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index 4684194..13674df 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -193,6 +193,15 @@ class FreeStyleHidDevice(hiddevice.HidDevice): return None return patient_name + def set_patient_name(self, name): + # type: (Text) -> None + try: + name = name.encode('ascii') + except UnicodeDecodeError: + raise ValueError('Only ASCII-safe names are tested working') + + result = self._send_text_command(b'$ptname,' + name) + def get_datetime(self): # type: () -> datetime.datetime """Gets the date and time as reported by the device. -- cgit v1.2.3