From 7d9edb8ed08bfc003b503a7c38418fcbd406295e Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Wed, 13 Dec 2017 20:37:14 +0100 Subject: [PATCH 01/13] added depenancy option to resolve error downloading rfcat --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6cde490..bfb8aec 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ 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. From 3e027230c4f8292d765bbf3b88c6570d3f306705 Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 16 Dec 2017 04:42:54 +0100 Subject: [PATCH 02/13] Added automatic json messages creation with simple description field --- openomni/bin/omni_listen_rfcat | 89 ++++++++++++------- requirements.txt | 2 +- ...2017-12-16T04:34:10.944215-eelkejager.json | 73 +++++++++++++++ setup.py | 2 +- 4 files changed, 133 insertions(+), 33 deletions(-) create mode 100644 results/2017-12-16T04:34:10.944215-eelkejager.json diff --git a/openomni/bin/omni_listen_rfcat b/openomni/bin/omni_listen_rfcat index 220b356..a51e129 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -5,13 +5,19 @@ 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 sys +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): @@ -27,34 +33,55 @@ def main(options=None): d = RfCat(0, debug=False) openomni.rf.configure_rfcat(d) - json = args.json - - while not keystop(): - try: - pkt, ts = d.RFrecv(timeout=80000) - pkt = Packet.flip_bytes(pkt) - rcv_time = datetime.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")) - if args.raw: - print(packet.data.encode("hex")) - if json: - print(packet.as_json()) - else: - print(packet) - break - x += 1 - - except ChipconUsbTimeoutException: - time.sleep(0.5) - - sys.stdin.read(1) + + # Default variables for filename + dateRecording = datetime.today().isoformat() + userName = getpass.getuser() + fileName = '%s-%s' % (dateRecording, userName) + + + + #actionDescription = raw_input("Write what you are doing: ") + with open('../../results/' + fileName + '.json', 'a') as outFile: + """Create 1 dict for each message loop.""" + package ={} + messages = [] + print ('Start recording:') + print ('-------------------------') + print ('Press \'ctrl+c\' to quit and write the performed action') + while not keystop(): + try: + pkt, ts = d.RFrecv(timeout=80000) + pkt = Packet.flip_bytes(pkt) + 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")) + if args.raw: + print(packet.data.encode("hex")) + messages.append(packet.data.encode("hex")) + if args.json: + print(packet.as_json()) + messages.append(packet.as_json()) + else: + print(packet) + messages.append({"string": str(packet), "raw": packet.data.encode("hex")}) + package["messages"] = messages + break + x += 1 + except ChipconUsbTimeoutException: + # time.sleep(0.5) + action = raw_input('Performed action: ') + package["Action"] = action + break + json.dump(package, outFile, encoding="utf-8", indent=4) + # sys.stdin.read(1) + print("Stopped recording") + 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/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' ], From 603f342f9604af9b4183597e489c90178ced21b5 Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Mon, 18 Dec 2017 03:30:25 +0100 Subject: [PATCH 03/13] grouped raw and string data --- openomni/bin/omni_listen_rfcat | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openomni/bin/omni_listen_rfcat b/openomni/bin/omni_listen_rfcat index a51e129..e661395 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -45,7 +45,8 @@ def main(options=None): with open('../../results/' + fileName + '.json', 'a') as outFile: """Create 1 dict for each message loop.""" package ={} - messages = [] + messages = {"string": [], + "raw": []} print ('Start recording:') print ('-------------------------') print ('Press \'ctrl+c\' to quit and write the performed action') @@ -69,7 +70,8 @@ def main(options=None): messages.append(packet.as_json()) else: print(packet) - messages.append({"string": str(packet), "raw": packet.data.encode("hex")}) + messages["string"].append(str(packet)) + messages["raw"].append(packet.data.encode("hex")) package["messages"] = messages break x += 1 From 20b786ec455123c31a806aeb376efab19ec50219 Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Mon, 18 Dec 2017 03:56:21 +0100 Subject: [PATCH 04/13] added example --- .../2017-12-18T03:28:50.720359-eelkejager.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 results/2017-12-18T03:28:50.720359-eelkejager.json 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 From 5e2dd7443f5fdb7b7e1867bda456bf8fcf2b3023 Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 17:33:02 +0100 Subject: [PATCH 05/13] changed camelCase to lower_case_with_underscores --- openomni/bin/omni_listen_rfcat | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/openomni/bin/omni_listen_rfcat b/openomni/bin/omni_listen_rfcat index e661395..5ae8bb8 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -35,24 +35,21 @@ def main(options=None): openomni.rf.configure_rfcat(d) # Default variables for filename - dateRecording = datetime.today().isoformat() - userName = getpass.getuser() - fileName = '%s-%s' % (dateRecording, userName) + recording_datetime = datetime.today().isoformat() + username = getpass.getuser() + filename = '%s-%s' % (recording_datetime, username) - - - #actionDescription = raw_input("Write what you are doing: ") - with open('../../results/' + fileName + '.json', 'a') as outFile: + with open('../../results/' + filename + '.json', 'a') as out_file: """Create 1 dict for each message loop.""" - package ={} - messages = {"string": [], + package = {} + messages = {"string": [], "raw": []} - print ('Start recording:') - print ('-------------------------') - print ('Press \'ctrl+c\' to quit and write the performed action') + print('Start recording (stops automatically after 10 minutes):') + print('-------------------------') + print('Press \'ctrl+c\' to quit and write the performed action.') 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.now() x = 0 @@ -71,6 +68,7 @@ def main(options=None): else: print(packet) messages["string"].append(str(packet)) + print(packet.body) messages["raw"].append(packet.data.encode("hex")) package["messages"] = messages break @@ -80,7 +78,7 @@ def main(options=None): action = raw_input('Performed action: ') package["Action"] = action break - json.dump(package, outFile, encoding="utf-8", indent=4) + json.dump(package, out_file, encoding="utf-8", indent=4) # sys.stdin.read(1) print("Stopped recording") From 619df058b09492b9d140e3efc1940bad86a4874e Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 20:02:13 +0100 Subject: [PATCH 06/13] added --path argument --- README.md | 12 +++---- openomni/bin/omni_listen_rfcat | 64 ++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index bfb8aec..f25b8a5 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,13 @@ 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: - -omni_listen_rfcat - +## Usage +You can capture packets by plugging an RFCat into a USB port -- and execute this command: +``` +omni_listen_rfcat --path results/ +``` Then issue commands from your PDM and they'll appear at the command line. - +You must specify a path to save the results using --path for example your local documents folder on your mac: /Users/MyName/Documents/results/. ======= ##### ** 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 5ae8bb8..a9cb17c 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -5,8 +5,8 @@ from __future__ import unicode_literals from __future__ import division from __future__ import absolute_import -import time import argparse +import os import sys import getpass import json @@ -17,36 +17,62 @@ import openomni.rf from openomni.packet import Packet - - - def main(options=None): - - parser = argparse.ArgumentParser(description="Capture omnipod packets using rfcat.") - parser.add_argument("--json", action="store_true", + 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", + parser.add_argument("--raw", + action="store_true", help="print raw packet") args = parser.parse_args() - d = RfCat(0, debug=False) - openomni.rf.configure_rfcat(d) + # if no argument is used, show help and exit + if len(sys.argv) == 1: + parser.print_help() + sys.exit(1) + + path = args.path[0] + + # Create path if it does not exists + 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) + filename = "%s-%s" % (recording_datetime, username) + + with open(path + filename + ".json", "a") as out_file: + # setup the RFcat + d = RfCat(0, debug=False) + openomni.rf.configure_rfcat(d) - with open('../../results/' + filename + '.json', 'a') as out_file: - """Create 1 dict for each message loop.""" package = {} messages = {"string": [], - "raw": []} - print('Start recording (stops automatically after 10 minutes):') - print('-------------------------') - print('Press \'ctrl+c\' to quit and write the performed action.') + "raw": [] + } + + print(""" + -------------------------------------------------------- + Start recording... + Press \"ctrl+c\" to quit and write the performed action. + -------------------------------------------------------- + (listening stops automatically after 10 minutes) + """) + while not keystop(): try: pkt, ts = d.RFrecv(timeout=600000) # 10 minutes timeout @@ -75,7 +101,7 @@ def main(options=None): x += 1 except ChipconUsbTimeoutException: # time.sleep(0.5) - action = raw_input('Performed action: ') + action = raw_input("Performed action: ") package["Action"] = action break json.dump(package, out_file, encoding="utf-8", indent=4) From 07bd448231d602e2a7550d45449aec0b5164404e Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 20:10:45 +0100 Subject: [PATCH 07/13] Added what to write when closing session --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f25b8a5..db02e40 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,15 @@ 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. ## Usage -You can capture packets by plugging an RFCat into a USB port -- and execute this command: +You can capture packets by plugging an RFCat into a USB port and execute this command: ``` omni_listen_rfcat --path results/ ``` Then issue commands from your PDM and they'll appear at the command line. -You must specify a path to save the results using --path for example your local documents folder on your mac: /Users/MyName/Documents/results/. +After completing, close the session with ctrl+c and add a comment explaining what type of actions you have performed. + +You must specify a path to save the results using --path. +For example the documents folder on your mac: /Users/MyName/Documents/results/. ======= ##### ** Please note the details below are related to a project created to better understand how the omnipod communicates ** From 9dce164068608d63e52b25b6762eee3b883bd28f Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 21:55:22 +0100 Subject: [PATCH 08/13] made saving to file optional --- openomni/bin/omni_listen_rfcat | 148 +++++++++++++++++---------------- 1 file changed, 76 insertions(+), 72 deletions(-) diff --git a/openomni/bin/omni_listen_rfcat b/openomni/bin/omni_listen_rfcat index a9cb17c..e09540d 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -7,7 +7,6 @@ from __future__ import absolute_import import argparse import os -import sys import getpass import json from datetime import datetime @@ -17,6 +16,79 @@ import openomni.rf from openomni.packet import Packet +def openomni_listen_rfcat(args): + + # setup the RFcat + d = RfCat(0, debug=False) + openomni.rf.configure_rfcat(d) + + 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=600000) # 10 minutes timeout + pkt = Packet.flip_bytes(pkt) + 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")) + if args.raw: + print(packet.data.encode("hex")) + messages.append(packet.data.encode("hex")) + if args.json: + print(packet.as_json()) + messages.append(packet.as_json()) + else: + print(packet) + messages["string"].append(str(packet)) + print(packet.body) + messages["raw"].append(packet.data.encode("hex")) + recording["messages"] = messages + break + x += 1 + except ChipconUsbTimeoutException: + 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", @@ -35,78 +107,10 @@ def main(options=None): help="print raw packet") args = parser.parse_args() + recording = openomni_listen_rfcat(args) - # if no argument is used, show help and exit - if len(sys.argv) == 1: - parser.print_help() - sys.exit(1) - - path = args.path[0] - - # Create path if it does not exists - 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) - - with open(path + filename + ".json", "a") as out_file: - # setup the RFcat - d = RfCat(0, debug=False) - openomni.rf.configure_rfcat(d) - - package = {} - messages = {"string": [], - "raw": [] - } - - print(""" - -------------------------------------------------------- - Start recording... - Press \"ctrl+c\" to quit and write the performed action. - -------------------------------------------------------- - (listening stops automatically after 10 minutes) - """) - - while not keystop(): - try: - pkt, ts = d.RFrecv(timeout=600000) # 10 minutes timeout - pkt = Packet.flip_bytes(pkt) - 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")) - if args.raw: - print(packet.data.encode("hex")) - messages.append(packet.data.encode("hex")) - if args.json: - print(packet.as_json()) - messages.append(packet.as_json()) - else: - print(packet) - messages["string"].append(str(packet)) - print(packet.body) - messages["raw"].append(packet.data.encode("hex")) - package["messages"] = messages - break - x += 1 - except ChipconUsbTimeoutException: - # time.sleep(0.5) - action = raw_input("Performed action: ") - package["Action"] = action - break - json.dump(package, out_file, encoding="utf-8", indent=4) - # sys.stdin.read(1) - print("Stopped recording") + if args.path[0] is not None: + save_recording(recording, args) if __name__ == "__main__": From 3461049f94e32a52ea4f1c289c966eebb3b2046d Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 21:56:00 +0100 Subject: [PATCH 09/13] explained save to file options --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index db02e40..ca2352e 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,22 @@ pip install -e . --process-dependency-links ## Usage You can capture packets by plugging an RFCat into a USB port and execute this command: ``` -omni_listen_rfcat --path results/ +cd openomni/bin +omni_listen_rfcat ``` Then issue commands from your PDM and they'll appear at the command line. -After completing, close the session with ctrl+c and add a comment explaining what type of actions you have performed. -You must specify a path to save the results using --path. -For example the documents folder on your mac: /Users/MyName/Documents/results/. +To save the results directly to a file, use the --path option to specify the location to save them. + +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 recording, close the session 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 ** From c5b711dc9f81ff3a7c985781e99fd87f22ee9700 Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 22:02:07 +0100 Subject: [PATCH 10/13] added link to example file --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca2352e..6f753b6 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ omni_listen_rfcat ``` Then issue commands from your PDM and they'll appear at the command line. -To save the results directly to a file, use the --path option to specify the location to save them. - +### save to file +To save the results directly to a file, use the --path option to specify the location to save them. [Example json 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/ @@ -53,7 +53,7 @@ In the documents folder on your mac: ``` omni_listen_rfcat --path /Users/MyName/Documents/results/ ``` -After completing the recording, close the session with ctrl+c and add a description explaining what type of actions you have performed. +After completing the recording, 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 ** From 01c21a9fd6641e2ffeb1fc768e08cb574bd3e0cc Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 22:07:34 +0100 Subject: [PATCH 11/13] used the word captures instead of recording --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6f753b6..46c6a3d 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,10 @@ omni_listen_rfcat ``` Then issue commands from your PDM and they'll appear at the command line. -### save to file -To save the results directly to a file, use the --path option to specify the location to save them. [Example json file](results/2017-12-18T03:28:50.720359-eelkejager.json) +### 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/ @@ -53,7 +55,7 @@ In the documents folder on your mac: ``` omni_listen_rfcat --path /Users/MyName/Documents/results/ ``` -After completing the recording, stop the recording with ctrl+c and add a description explaining what type of actions you have performed. +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 ** From 4f86127534b6c2e3e3ce5189982aa4055daf3e30 Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 22:17:01 +0100 Subject: [PATCH 12/13] removed testing print statement --- openomni/bin/omni_listen_rfcat | 1 - 1 file changed, 1 deletion(-) diff --git a/openomni/bin/omni_listen_rfcat b/openomni/bin/omni_listen_rfcat index e09540d..ec7c85b 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -54,7 +54,6 @@ def openomni_listen_rfcat(args): else: print(packet) messages["string"].append(str(packet)) - print(packet.body) messages["raw"].append(packet.data.encode("hex")) recording["messages"] = messages break From 76ad00f77646ed31e39bfd1ff12a48ef81e61e53 Mon Sep 17 00:00:00 2001 From: "e.jager@amsterdam.nl" Date: Sat, 13 Jan 2018 22:32:44 +0100 Subject: [PATCH 13/13] removed message.append from --raw/json flag --- openomni/bin/omni_listen_rfcat | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/openomni/bin/omni_listen_rfcat b/openomni/bin/omni_listen_rfcat index ec7c85b..b51451e 100755 --- a/openomni/bin/omni_listen_rfcat +++ b/openomni/bin/omni_listen_rfcat @@ -47,15 +47,13 @@ def openomni_listen_rfcat(args): # print(data.encode("hex")) if args.raw: print(packet.data.encode("hex")) - messages.append(packet.data.encode("hex")) if args.json: print(packet.as_json()) - messages.append(packet.as_json()) else: print(packet) - messages["string"].append(str(packet)) - messages["raw"].append(packet.data.encode("hex")) - recording["messages"] = messages + messages["string"].append(str(packet)) + messages["raw"].append(packet.data.encode("hex")) + recording["messages"] = messages break x += 1 except ChipconUsbTimeoutException: