forked from bewest/mmblelink
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from oskarpearson/dev
Merge from Dev
- Loading branch information
Showing
16 changed files
with
291 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env python | ||
# PYTHON_ARGCOMPLETE_OK | ||
|
||
from mmeowlink.cli.bolus_app import BolusApp | ||
|
||
if __name__ == '__main__': | ||
BolusApp().run(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env python | ||
# PYTHON_ARGCOMPLETE_OK | ||
|
||
from mmeowlink.cli.rf_dump_app import RfDumpApp | ||
|
||
if __name__ == '__main__': | ||
RfDumpApp().run(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
#!/usr/bin/env python | ||
# PYTHON_ARGCOMPLETE_OK | ||
|
||
from mmeowlink.cli import messages | ||
from mmeowlink.cli.send_msg_app import SendMsgApp | ||
|
||
if __name__ == '__main__': | ||
app = messages.SendMsgApp( ) | ||
app.run(None) | ||
SendMsgApp().run(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,7 @@ | ||
#!/usr/bin/env python | ||
# PYTHON_ARGCOMPLETE_OK | ||
|
||
import sys | ||
import json | ||
from mmeowlink.mmtune import MMTune | ||
from mmeowlink.vendors.subg_rfspy_link import SubgRfspyLink | ||
from mmeowlink.cli.mmtune_app import MMTuneApp | ||
|
||
if __name__ == '__main__': | ||
locale = 'US' | ||
|
||
if len(sys.argv) < 3: | ||
print "Usage: mmtune.py /dev/ttyMFD1 pumpserial [radio_locale]" | ||
print "Radio locale defaults to 'US'. Set to 'WW' for other countries" | ||
sys.exit(-1) | ||
|
||
link = SubgRfspyLink(sys.argv[1]) | ||
serial = sys.argv[2] | ||
|
||
if len(sys.argv) >= 4: | ||
locale = sys.argv[3] | ||
|
||
if locale not in ['US', 'WW']: | ||
print "Radio locale not supported - must be either 'WW' or 'US'" | ||
sys.exit(1) | ||
|
||
tuner = MMTune(link, serial, locale) | ||
output = tuner.run() | ||
print json.dumps(output, sort_keys=True,indent=4, separators=(',', ': ')) | ||
MMTuneApp().run(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env python | ||
# PYTHON_ARGCOMPLETE_OK | ||
|
||
from decocare import commands | ||
from decocare import lib | ||
from base_mmeowlink_app import BaseMMeowlinkApp | ||
|
||
from mmeowlink.link_builder import LinkBuilder | ||
from mmeowlink.handlers.stick import Pump | ||
|
||
|
||
class BolusApp (BaseMMeowlinkApp): | ||
""" %(prog)s - Send bolus command to a pump. | ||
XXX: Be careful please! | ||
Units might be wrong. Keep disconnected from pump until you trust it by | ||
observing the right amount first. | ||
""" | ||
def customize_parser (self, parser): | ||
parser.add_argument('units', | ||
type=float, | ||
help="Amount of insulin to bolus." | ||
) | ||
|
||
group = parser.add_mutually_exclusive_group(required=True) | ||
group.add_argument('--515', | ||
dest='strokes_per_unit', | ||
action='store_const', | ||
const=10 | ||
) | ||
group.add_argument('--554', | ||
dest='strokes_per_unit', | ||
action='store_const', | ||
const=40 | ||
) | ||
group.add_argument('--strokes', | ||
dest='strokes_per_unit', | ||
type=int | ||
) | ||
|
||
parser.add_argument('--radio_type', dest='radio_type', default='subg_rfspy', choices=['mmcommander', 'subg_rfspy']) | ||
parser.add_argument('--mmcommander', dest='radio_type', action='store_const', const='mmcommander') | ||
parser.add_argument('--subg_rfspy', dest='radio_type', action='store_const', const='subg_rfspy') | ||
# parser = super(BolusApp, self).customize_parser(parser) | ||
|
||
return parser | ||
|
||
def prelude(self, args): | ||
port = args.port | ||
builder = LinkBuilder() | ||
if port == 'scan': | ||
port = builder.scan() | ||
self.link = link = LinkBuilder().build(args.radio_type, port) | ||
link.open() | ||
self.pump = Pump(self.link, args.serial) | ||
self.model = None | ||
if args.no_rf_prelude: | ||
return | ||
if not args.autoinit: | ||
if args.init: | ||
self.pump.power_control(minutes=args.session_life) | ||
else: | ||
self.autoinit(args) | ||
self.sniff_model() | ||
|
||
def postlude(self, args): | ||
# self.link.close( ) | ||
return | ||
|
||
def main (self, args): | ||
print args | ||
self.bolus(args); | ||
|
||
def bolus (self, args): | ||
query = commands.Bolus | ||
kwds = dict(params=fmt_params(args)) | ||
|
||
resp = self.exec_request(self.pump, query, args=kwds, | ||
dryrun=args.dryrun, render_hexdump=False) | ||
return resp | ||
|
||
def fmt_params (args): | ||
strokes = int(float(args.units) * args.strokes_per_unit) | ||
if (args.strokes_per_unit > 10): | ||
return [lib.HighByte(strokes), lib.LowByte(strokes)] | ||
return [strokes] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
from mmeowlink.mmtune import MMTune | ||
from base_mmeowlink_app import BaseMMeowlinkApp | ||
|
||
class MMTuneApp(BaseMMeowlinkApp): | ||
""" | ||
Tune radio automatically | ||
""" | ||
def customize_parser(self, parser): | ||
parser = super(self.__class__, self).configure_radio_params(parser) | ||
|
||
parser.add_argument('--radio_locale', choices=['US', 'WW'], default='US', help="US=916mhz, WW=868mhz. Only supported on subg_rfspy radios") | ||
|
||
return parser | ||
|
||
def prelude(self, args): | ||
# When running mmtune, we don't want the code to try and send | ||
# prelude packets or auto-init the pump, since they duplicate what | ||
# we are about to do | ||
args.no_rf_prelude = True | ||
|
||
super(MMTuneApp, self).prelude(args) | ||
|
||
def main(self, args): | ||
tuner = MMTune(self.link, args.serial, args.radio_locale) | ||
output = tuner.run() | ||
print json.dumps(output, sort_keys=True,indent=4, separators=(',', ': ')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from datetime import datetime | ||
|
||
from .. hex_handling import hexify | ||
from .. exceptions import CommsException | ||
|
||
from mmeowlink.vendors.mmcommander_link import MMCommanderLink | ||
from mmeowlink.vendors.subg_rfspy_link import SubgRfspyLink | ||
|
||
from base_mmeowlink_app import BaseMMeowlinkApp | ||
|
||
class RfDumpApp(BaseMMeowlinkApp): | ||
""" | ||
Dump Radio Transmissions | ||
""" | ||
|
||
# Override the parser since we don't want the standard commands | ||
def customize_parser(self, parser): | ||
parser = super(self.__class__, self).configure_radio_params(parser) | ||
|
||
return parser | ||
|
||
def prelude(self, args): | ||
# When running mmtune, we don't want the code to try and send | ||
# prelude packets or auto-init the pump, since they duplicate what | ||
# we are about to do | ||
args.no_rf_prelude = True | ||
|
||
super(RfDumpApp, self).prelude(args) | ||
|
||
def main(self, args): | ||
while True: | ||
try: | ||
if type(self.link) == SubgRfspyLink: | ||
resp = self.link.get_packet(timeout=1) | ||
ts = datetime.now() | ||
print "%s (%d db) - %s" % (ts, resp['rssi'], hexify(resp['data']).upper()) | ||
elif type(self.link) == MMCommanderLink: | ||
resp = self.link.read(timeout=1) | ||
ts = datetime.now() | ||
print "%s (N/A db) - %s" % (ts, hexify(resp).upper()) | ||
except CommsException as e: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from base_mmeowlink_app import BaseMMeowlinkApp | ||
|
||
class SendMsgApp(BaseMMeowlinkApp): | ||
""" | ||
mmeowlink adapter to decocare's SendMsgApp. All actual implementation details | ||
are handled in MMeowlinkApp and messages in decocare.helpers | ||
""" | ||
def customize_parser(self, parser): | ||
parser = super(self.__class__, self).configure_radio_params(parser) | ||
parser = super(self.__class__, self).customize_parser(parser) | ||
|
||
return parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def hexify(data): | ||
return ' '.join( [ '%02x' % x for x in list( data ) ] ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.