diff --git a/README.md b/README.md index 6cde490..46c6a3d 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,31 @@ You can install openomni in editable mode like this: ``` git clone https://github.com/openaps/openomni.git cd openomni -pip install -e . +pip install -e . --process-dependency-links ``` ** Note: You may need to add 'sudo' before the pip install line if you are using a system python install. -** Note: You can capture packets by plugging an RFCat into a USB port -- then go to the command line, and navigate to this directory: -/openomni/bin/ and type: - +## Usage +You can capture packets by plugging an RFCat into a USB port and execute this command: +``` +cd openomni/bin omni_listen_rfcat - +``` Then issue commands from your PDM and they'll appear at the command line. +### saving the captures to a file +Use the --path option to specify the location to save te captures. ([Example file](results/2017-12-18T03:28:50.720359-eelkejager.json) ) + + +In a subfolder within the folder you are currently in: +``` +omni_listen_rfcat --path results/ +``` +In the documents folder on your mac: +``` +omni_listen_rfcat --path /Users/MyName/Documents/results/ +``` +After completing the capture, stop the recording with ctrl+c and add a description explaining what type of actions you have performed. ======= ##### ** Please note the details below are related to a project created to better understand how the omnipod communicates ** diff --git a/openomni/bin/omni_listen_rfcat b/openomni/bin/omni_listen_rfcat index 220b356..b51451e 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -5,56 +5,110 @@ from __future__ import unicode_literals from __future__ import division from __future__ import absolute_import -from rflib import RfCat, keystop, ChipconUsbTimeoutException -import time -import datetime import argparse +import os +import getpass +import json +from datetime import datetime + +from rflib import RfCat, keystop, ChipconUsbTimeoutException import openomni.rf from openomni.packet import Packet -import sys - - -def main(options=None): - - parser = argparse.ArgumentParser(description="Capture omnipod packets using rfcat.") - parser.add_argument("--json", action="store_true", - help="print as json (default: text line)") - parser.add_argument("--raw", action="store_true", - help="print raw packet") - args = parser.parse_args() +def openomni_listen_rfcat(args): + # setup the RFcat d = RfCat(0, debug=False) openomni.rf.configure_rfcat(d) - json = args.json + + recording = {} + messages = {"string": [], "raw": []} + + print(""" + -------------------------------------------------------- + Start recording... + Press \"ctrl+c\" to quit. + -------------------------------------------------------- + (listening stops automatically after 10 minutes) + """) while not keystop(): try: - pkt, ts = d.RFrecv(timeout=80000) + pkt, ts = d.RFrecv(timeout=600000) # 10 minutes timeout pkt = Packet.flip_bytes(pkt) - rcv_time = datetime.datetime.now() - + rcv_time = datetime.now() x = 0 while x < len(pkt): data = pkt[:len(pkt) - (x + 1)] packet = Packet(data) packet.received_at = rcv_time if packet.is_valid(): - #print(data.encode("hex")) + # print(data.encode("hex")) if args.raw: print(packet.data.encode("hex")) - if json: + if args.json: print(packet.as_json()) else: print(packet) + messages["string"].append(str(packet)) + messages["raw"].append(packet.data.encode("hex")) + recording["messages"] = messages break x += 1 - except ChipconUsbTimeoutException: - time.sleep(0.5) + print("Stopped recording") + break + return recording + + +def save_recording(recording, args): + # Create path if it does not exists + path = args.path[0] + try: + os.makedirs(path) + except OSError: + if not os.path.isdir(path): + raise + + # Default variables for filename + recording_datetime = datetime.today().isoformat() + username = getpass.getuser() + filename = "%s-%s" % (recording_datetime, username) + full_path_filename = path + filename + ".json" + + # Add Description field + recording["Action"] = raw_input("Describe performed action(s): ") + + with open(full_path_filename, "a") as out_file: + json.dump(recording, out_file, encoding="utf-8", indent=4) + # sys.stdin.read(1) + print("Saved messages to file: %s" % (full_path_filename)) + + +def main(options=None): + parser = argparse.ArgumentParser(description="Capture Omnipod packets using rfcat. For a quickstart use this command: omni_listen_rfcat --path results/") + parser.add_argument("--path", + type=str, + help=""" + Add the path you want to save the resulting json. + --path /Users/MyName/Documents/results/ + or --path results/ to save in the current folder. + """, + nargs=1) + parser.add_argument("--json", + action="store_true", + help="print as json (default: text line)") + parser.add_argument("--raw", + action="store_true", + help="print raw packet") + + args = parser.parse_args() + recording = openomni_listen_rfcat(args) + + if args.path[0] is not None: + save_recording(recording, args) - sys.stdin.read(1) if __name__ == "__main__": main() diff --git a/requirements.txt b/requirements.txt index e09b47c..2878bda 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ crccheck python-dateutil pyusb git+https://github.com/atlas0fd00m/rfcat -enum34>=1.1.6 ; python_version <= '2.7' +enum34>=1.1.6 ; python_version <= '2.7' \ No newline at end of file diff --git a/results/2017-12-16T04:34:10.944215-eelkejager.json b/results/2017-12-16T04:34:10.944215-eelkejager.json new file mode 100644 index 0000000..9aedd84 --- /dev/null +++ b/results/2017-12-16T04:34:10.944215-eelkejager.json @@ -0,0 +1,73 @@ +{ + "Action": "Started PDM, added 0,5units Bolus", + "messages": [ + { + "raw": "1f05e708fc1f05e7081c0a1d190539d800003dab9980981817fccba797114b3f4e10412f259aef07557915a42119b53042", + "string": "2017-12-16T04:34:17.980680 ID1:1f05e708 PTYPE:POD SEQ:28 ID2:1f05e708 B9:1c BLEN:10 BODY:1d190539d800003dab998098 CRC:18" + }, + { + "raw": "1f05e7085d000000004f1129b3d1ddc62586521a4109947e63e5a264c441e03583e1e005f0a881d457c6088268773b5ffd", + "string": "2017-12-16T04:34:17.981187 ID1:1f05e708 PTYPE:ACK SEQ:29 ID2:00000000 CRC:4f" + }, + { + "raw": "1f05e708be1f05e70820030e010002f9be07340bd9ee0d9dbd9ea54bcfa08d67ccefadb8a33094c610e8d9a11422169f5f", + "string": "2017-12-16T04:34:45.077493 ID1:1f05e708 PTYPE:PDM SEQ:30 ID2:1f05e708 B9:20 BLEN:3 BODY:0e010002f9 CRC:be" + }, + { + "raw": "1f05e708be1f05e70820030e010002f9be11223410d882d21466b801ba2b2a550eff80bbb9905d74aba65e1c7d83c6a0c3", + "string": "2017-12-16T04:34:45.358736 ID1:1f05e708 PTYPE:PDM SEQ:30 ID2:1f05e708 B9:20 BLEN:3 BODY:0e010002f9 CRC:be" + }, + { + "raw": "1f05e7084000000000891952a349cd444f62342c0531b26bbe8e50dc4a22a40ca46aa252db81c18edd40563009929636ca", + "string": "2017-12-16T04:34:45.484386 ID1:1f05e708 PTYPE:ACK SEQ:00 ID2:00000000 CRC:89" + }, + { + "raw": "1f05e708a11f05e708281f1a0e4a024c6b0200b50100a0000a000a170d3c006400030d403d1d02162bab281696242898c9", + "string": "2017-12-16T04:34:45.815361 ID1:1f05e708 PTYPE:PDM SEQ:01 ID2:1f05e708 B9:28 BLEN:31 BODY:1a0e4a024c6b0200b50100a0000a000a170d3c006400030d40 CRC:3d" + }, + { + "raw": "1f05e708a11f05e708281f1a0e4a024c6b0200b50100a0000a000a170d3c006400030d403d170be42ece19a610954d28b3", + "string": "2017-12-16T04:34:46.145580 ID1:1f05e708 PTYPE:PDM SEQ:01 ID2:1f05e708 B9:28 BLEN:31 BODY:1a0e4a024c6b0200b50100a0000a000a170d3c006400030d40 CRC:3d" + }, + { + "raw": "1f05e708421f05e708281ce28406568470453dd7c0c1d889509054d9b928fe7023381e8d630d502e93bc7184cafc8bce46", + "string": "2017-12-16T04:34:46.181086 ID1:1f05e708 PTYPE:ACK SEQ:02 ID2:1f05e708 CRC:28" + }, + { + "raw": "1f05e7088300000000000002ec92", + "string": "2017-12-16T04:34:46.354696 ID1:1f05e708 PTYPE:CON SEQ:03 CON:00000000000002ec CRC:92" + }, + { + "raw": "1f05e708e41f05e7082c0a1d590539d00a003daf99037f030fe490638aab6175cc7f797e017eee2398762fa96d3547086e", + "string": "2017-12-16T04:34:46.429407 ID1:1f05e708 PTYPE:POD SEQ:04 ID2:1f05e708 B9:2c BLEN:10 BODY:1d590539d00a003daf99037f CRC:03" + }, + { + "raw": "1f05e708e41f05e7082c0a1d590539d00a003daf99037f03001d658db02056973acd7d19e89e768a892208726588287132", + "string": "2017-12-16T04:34:46.598305 ID1:1f05e708 PTYPE:POD SEQ:04 ID2:1f05e708 B9:2c BLEN:10 BODY:1d590539d00a003daf99037f CRC:03" + }, + { + "raw": "1f05e708e41f05e7082c0a1d590539d00a003daf99037f03106079fcae929c525aff2e7aa8c81c4b5918c9989b5ddc0eab", + "string": "2017-12-16T04:34:46.715804 ID1:1f05e708 PTYPE:POD SEQ:04 ID2:1f05e708 B9:2c BLEN:10 BODY:1d590539d00a003daf99037f CRC:03" + }, + { + "raw": "1f05e708e41f05e7082c0a1d590539d00a003daf99037f0304fdea1481c2259dd19e272c6a14c80a45a69931206d812530", + "string": "2017-12-16T04:34:46.841103 ID1:1f05e708 PTYPE:POD SEQ:04 ID2:1f05e708 B9:2c BLEN:10 BODY:1d590539d00a003daf99037f CRC:03" + }, + { + "raw": "1f05e7084500000000641bfddeb44aa95396467635c67140a330095bb3597bed869417e5cbb06516920cc50986a675e85c", + "string": "2017-12-16T04:34:46.841793 ID1:1f05e708 PTYPE:ACK SEQ:05 ID2:00000000 CRC:64" + }, + { + "raw": "1f05e708a61f05e70830030e010081d1110804b4b344f9463d15bb24a4c108b2896b2cfc2c09c2e53da67b1c2ebd36b596", + "string": "2017-12-16T04:35:09.298730 ID1:1f05e708 PTYPE:PDM SEQ:06 ID2:1f05e708 B9:30 BLEN:3 BODY:0e010081d1 CRC:11" + }, + { + "raw": "1f05e708e71f05e708340a1d19053ed000003daf8f803b5a1c1c6e2c71ae7000561ae154423962fc42a7803ac246cb5af5", + "string": "2017-12-16T04:35:09.419289 ID1:1f05e708 PTYPE:POD SEQ:07 ID2:1f05e708 B9:34 BLEN:10 BODY:1d19053ed000003daf8f803b CRC:5a" + }, + { + "raw": "1f05e70848000000009015b2cda1d376d2cb9023096d4243a292d59b7f4a922975b91b67bec4524fa0b62cc3652ae60038", + "string": "2017-12-16T04:35:09.423660 ID1:1f05e708 PTYPE:ACK SEQ:08 ID2:00000000 CRC:90" + } + ] +} \ No newline at end of file diff --git a/results/2017-12-18T03:28:50.720359-eelkejager.json b/results/2017-12-18T03:28:50.720359-eelkejager.json new file mode 100644 index 0000000..34edfcb --- /dev/null +++ b/results/2017-12-18T03:28:50.720359-eelkejager.json @@ -0,0 +1,15 @@ +{ + "Action": "Status command", + "messages": { + "raw": [ + "1f05e709a01f05e70920030e010083a8ce18e11471f10e9a2c66494e3707d34d3ed92a90a42284ceaf1c58d6e09be67593", + "1f05e709a31f05e70928030e010080a6d6138a469a35df8faa64bfeacd83368ee6d6dc26443c7059e542dd6392d0c9c6b0", + "1f05e70945000000004d04091feccb086025e3217c23528b8f4e8eb5501dc42607ef9cc266b02c13e9ea27580a154b4589" + ], + "string": [ + "2017-12-18T03:28:50.723003 ID1:1f05e709 PTYPE:PDM SEQ:00 ID2:1f05e709 B9:20 BLEN:3 BODY:0e010083a8 CRC:ce", + "2017-12-18T03:28:55.109494 ID1:1f05e709 PTYPE:PDM SEQ:03 ID2:1f05e709 B9:28 BLEN:3 BODY:0e010080a6 CRC:d6", + "2017-12-18T03:28:55.232136 ID1:1f05e709 PTYPE:ACK SEQ:05 ID2:00000000 CRC:4d" + ] + } +} \ No newline at end of file diff --git a/setup.py b/setup.py index b8af61c..470ba68 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ install_requires=[ 'crccheck', 'python-dateutil', - 'enum34;python_version<"3.4"', + 'enum34', 'pyusb', 'rfcat>=1.0' ],