/src/insulaudit/devices/onetouch/console.py

https://github.com/bewest/insulaudit
Python | 75 lines | 50 code | 12 blank | 13 comment | 0 complexity | f1041b035a3c642e4c5bc801c577202e MD5 | raw file
  1. from insulaudit import core
  2. from insulaudit.data import glucose
  3. from insulaudit.console import device
  4. import proto
  5. class OnetouchApp(device.LinkCommand):
  6. """Onetouch compatible lifescan devices.
  7. """
  8. name = 'onetouch'
  9. def link_factory(self):
  10. return proto.Link
  11. #return proto.Linonetouch2.OneTouchUltra2( PORT, 5 )
  12. def setup(self, parser):
  13. import argparse, sys
  14. super(type(self), self).setup(parser)
  15. parser.add_argument('--output', type=argparse.FileType('w'),
  16. default=sys.stdout)
  17. def getFlows(self):
  18. return [ HelloFlow, sugars ]
  19. def title(self):
  20. return "onetouch - talk with Lifescan OneTouch compatible devices."
  21. def help(self):
  22. return "talk with Lifescan OneTouch compatible devices"
  23. def subcommand_manufacturer(self, flow):
  24. return OTCommand(flow, self)
  25. class OTCommand(device.FlowCommand):
  26. def setup_link(self, port):
  27. self.log.info('setting up %s' % port)
  28. return self.handler.selected.link_factory()(port, 5)
  29. class HelloFlow(core.Flow):
  30. """Hello world for Lifescan onetouch compatible devices.
  31. Can we reliably exchange bytes?
  32. """
  33. name = 'hello'
  34. def flow(self, session):
  35. link = session.link
  36. serial = link.execute( proto.ReadSerial( ) )
  37. print "serial number: %s" % serial
  38. session.log.info("serial number: %s" % serial)
  39. firmware = link.execute( proto.ReadFirmware( ) )
  40. print "firmware: %s" % firmware
  41. session.log.info("firmware: %s" % firmware)
  42. session.log.info('done')
  43. class sugars(core.Flow):
  44. """Dump the sugars to stdout
  45. Can we reliably exchange bytes?
  46. """
  47. #name = 'sugars'
  48. def get_out_file(self):
  49. return self.session.handler.handler.params.output
  50. return sys.stdout
  51. def flow(self, session):
  52. link = session.link
  53. serial = link.execute( proto.ReadSerial( ) )
  54. data = link.read_glucose( )
  55. #print data
  56. print "len glucose: %s" % len( data )
  57. head, body = data
  58. records = glucose.format_records( body )
  59. print head
  60. print records
  61. self.get_out_file( ).write(records)
  62. #####
  63. # EOF