summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.com>2023-08-03 10:19:38 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-08-03 10:59:53 +0200
commit94ff09b946be3c170103b841633e6ec48b4c0297 (patch)
tree74735d183a328fefd085b1db089217df2cf4fb24
parentIf present, load the actual keys from freestyle-keys package. (diff)
downloadfreestyle-hid-94ff09b946be3c170103b841633e6ec48b4c0297.tar
freestyle-hid-94ff09b946be3c170103b841633e6ec48b4c0297.tar.gz
freestyle-hid-94ff09b946be3c170103b841633e6ec48b4c0297.tar.bz2
freestyle-hid-94ff09b946be3c170103b841633e6ec48b4c0297.tar.lz
freestyle-hid-94ff09b946be3c170103b841633e6ec48b4c0297.tar.xz
freestyle-hid-94ff09b946be3c170103b841633e6ec48b4c0297.tar.zst
freestyle-hid-94ff09b946be3c170103b841633e6ec48b4c0297.zip
-rw-r--r--freestyle_hid/_session.py11
-rwxr-xr-xfreestyle_hid/tools/hid_console.py16
2 files changed, 21 insertions, 6 deletions
diff --git a/freestyle_hid/_session.py b/freestyle_hid/_session.py
index 0debaed..a2c9195 100644
--- a/freestyle_hid/_session.py
+++ b/freestyle_hid/_session.py
@@ -119,17 +119,18 @@ class Session:
text_message_type: int,
text_reply_message_type: int,
encoding: str = "ascii",
+ encrypted: bool = False,
) -> None:
+ if encrypted and not _HAS_LIBRE2_KEYS:
+ raise MissingFreeStyleKeys()
+
self._handle = HidWrapper.open(device_path, ABBOTT_VENDOR_ID, product_id)
self._text_message_type = text_message_type
self._text_reply_message_type = text_reply_message_type
self._encoding = encoding
- self._encrypted_protocol = product_id in [0x3950]
+ self._encrypted_protocol = encrypted
def encryption_handshake(self):
- if not _HAS_LIBRE2_KEYS:
- raise MissingFreeStyleKeys()
-
self.send_command(0x05, b"")
response = self.read_response()
assert response[0] == 0x06
@@ -179,9 +180,9 @@ class Session:
# print("HANDSHAKE SUCCESSFUL!")
def connect(self):
+ """Open connection to the device, starting the knocking sequence."""
if self._encrypted_protocol:
self.encryption_handshake()
- """Open connection to the device, starting the knocking sequence."""
self.send_command(_INIT_COMMAND, b"")
response = self.read_response()
if not _is_init_reply(response):
diff --git a/freestyle_hid/tools/hid_console.py b/freestyle_hid/tools/hid_console.py
index 2c395bd..6eec4e2 100755
--- a/freestyle_hid/tools/hid_console.py
+++ b/freestyle_hid/tools/hid_console.py
@@ -46,6 +46,14 @@ click_log.basic_config(logger)
help="Encoding to use to decode commands returned by the meter",
default="ascii",
)
+@click.option(
+ "--encrypted-protocol / --no-encrypted-protocol",
+ default=False,
+ help=(
+ "Whether to use the encrypted protocol to communicate to the device."
+ " This is necessary to talk to Libre2 glucometers."
+ ),
+)
@click.argument(
"device-path",
type=click.Path(exists=True, dir_okay=False, writable=True, allow_dash=False),
@@ -59,6 +67,7 @@ def main(
product_id: Optional[int],
device_path: Optional[pathlib.Path],
encoding: str,
+ encrypted_protocol: bool,
):
if not product_id and not device_path:
raise click.UsageError(
@@ -66,7 +75,12 @@ def main(
)
session = freestyle_hid.Session(
- product_id, device_path, text_command_type, text_reply_type, encoding=encoding
+ product_id,
+ device_path,
+ text_command_type,
+ text_reply_type,
+ encoding=encoding,
+ encrypted=encrypted_protocol,
)
session.connect()