Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package downloader #51

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary for rfcat? Reading about the security implications and how they want to deprecate this feature, I think maybe it should be avoided. We can list installation of rfcat as a separate step.

Copy link
Collaborator Author

@Lytrix Lytrix Jan 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For RFcat this is necessary if you want to install it with setup.py because it not registered on PiPy.

I read the option has been put back in because there is currently no other solution in the works:
pypa/pip#4187

I would like to keep it in for now because it simplifies the install steps, but I will create PR tonight on RFCat with the needed changes to add rfcat to the PiPy registry. It's quite easy to add packages to pipy yourself.

The separate step was a bit confusing for me at the time to understand what RFCat is used for. I used the RFCat first as a CC compiler for the TI stick and then also for openomni as a python package. So when I found out it can be installed as a package, I liked this, because it helps in the logic of all the different steps and have a 1 install command (I started using Docker at work so I am really into 1 line installers now ;-))

```
** Note: You may need to add 'sudo' before the pip install line if you are using a system python install.

Expand Down
91 changes: 60 additions & 31 deletions openomni/bin/omni_listen_rfcat
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -27,34 +33,57 @@ 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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use python recommended naming for variables: underscores instead of camel case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

userName = getpass.getuser()
fileName = '%s-%s' % (dateRecording, userName)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also looking for a better way of naming the files. Now there only date and username, so finding your results back is a bit cumbersome. The free text input would be a bit to unorganised as a filename I think. Do you have any suggestions?




#actionDescription = raw_input("Write what you are doing: ")
with open('../../results/' + fileName + '.json', 'a') as outFile:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails for me. I usually work out of the top level directory, and run things like ./openomni/bin/omni_listen_rfcat. File output should be an option; one is not always wanting to store things to disk.

Copy link
Collaborator Author

@Lytrix Lytrix Jan 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I've added a path argument to tackle this, plus added it to the readme. I will add the option to skip writing to file.

"""Create 1 dict for each message loop."""
package ={}
messages = {"string": [],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've grouped the raw's all together and the strings, I first had it grouped for each step, but that was not really easy to read, see added example with the grouping I find is really helpful. @ps2 what do you think?

"raw": []}
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["string"].append(str(packet))
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, outFile, encoding="utf-8", indent=4)
# sys.stdin.read(1)
print("Stopped recording")


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
73 changes: 73 additions & 0 deletions results/2017-12-16T04:34:10.944215-eelkejager.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
install_requires=[
'crccheck',
'python-dateutil',
'enum34;python_version<"3.4"',
'enum34',
'pyusb',
'rfcat>=1.0'
],
Expand Down