示例#1
0
 def decode( self, msg ):
   data = bytearray( msg[ 3: len(msg) - 3 ] )
   date = time.ctime( ls_long( data[ 2:6 ] ) )
   io.info( 'relevant message: %s' % lib.hexdump( data ) )
   io.info( 'glucose: %s' % lib.hexdump( data[ 6:10 ] ) )
   glucose = ls_long( data[ 6:10 ] )
   return ( date, glucose )
示例#2
0
 def stage2_wakeup(self):
     stage2a = [0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x07]
     stage2b = [0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08]
     stage2c = [0x11, 0x0D, 0x44, 0x4D, 0x53, 0x0D, 0x0D]
     stage2d = [0x11, 0x0D, 0x44, 0x4D, 0x53, 0x0D, 0x0D]
     stage2e = [0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x08]
     stage2f = [0x11, 0x0D, 0x44, 0x4D, 0x53, 0x0D]
     stages = [
         stage2a,
         stage2b,
         stage2c,
         stage2d,
         stage2e,
         stage2f,
     ]
     awake = False
     for stage in stages:
         msg = bytearray(stage)
         self.write(str(msg))
         response = self.readlines()
         if len(response) > 0:
             io.info("got a response!!!")
             io.info(lib.hexdump(bytearray(response)))
             awake = True
     return awake
示例#3
0
文件: proto.py 项目: jden/insulaudit
 def __call__(self, port ):
   stuff = port.write("")
   time.sleep(5)
   stuff = port.readlines( )
   io.info( "RECIEVED HANDSHAKE REPLY: %s bytes" % len(stuff) )
   io.info(lib.hexdump(bytearray( stuff )))
   if len(stuff) > 0:
     return True
   return False
示例#4
0
 def wakeup_smart( self ):
   io.info("begin wakeup")
   self.stage1_wakeup( )
   self.stage2_wakeup( )
   #stage2 = UltraSmartWakeUpStage2( )
   #self.write( str( stage2.code ) )
   #response_2 = stage2( self )
   #self.write( str( wake1.code ) )
   time.sleep( self.__pause__ )
示例#5
0
 def __call__(self, port):
     stuff = port.write("")
     #time.sleep(5)
     stuff = port.readlines()
     io.info("RECIEVED HANDSHAKE REPLY: %s bytes" % len(stuff))
     io.info(lib.hexdump(bytearray(stuff)))
     if len(stuff) > 0:
         return True
     return False
示例#6
0
 def wakeup_smart(self):
     io.info("begin wakeup")
     self.stage1_wakeup()
     self.stage2_wakeup()
     #stage2 = UltraSmartWakeUpStage2( )
     #self.write( str( stage2.code ) )
     #response_2 = stage2( self )
     #self.write( str( wake1.code ) )
     time.sleep(self.__pause__)
示例#7
0
 def __retry_write_with_ack__( self, msg, retries ):
   try:
     for i in xrange( RETRIES - 1 ):
       try:
         self.write( str( bytearray( msg ) ) )
         io.info( '__retry_write_with_ack__::%i' % i )
         self.__ack__ = self.__requireAck__( )
         return self.__ack__
       except MissingAck, e:
         io.info( 'retry:%s:missing ack:%r' % ( i, e ) )
     self.write( str( bytearray( msg ) ) )
     self.__ack__ = self.__requireAck__( )
示例#8
0
文件: proto.py 项目: jden/insulaudit
 def wakeup_smart( self ):
   io.info("begin wakeup")
   stage1 = UltraSmartWakeUpStage1( )
   self.write( str( stage1.code ) )
   response = stage1( self )
   io.info(response)
   #wake2 = UltraSmartWakeUp2( )
   stage2 = UltraSmartWakeUpStage2( )
   self.write( str( stage2.code ) )
   response_2 = stage2( self )
   #self.write( str( wake1.code ) )
   time.sleep( self.__pause__ )
示例#9
0
 def __call__(self, command):
     self.prevCommand = command
     x = str(command)
     self.serial.setTimeout(command.timeout)
     log.debug('setting timeout: %s' % command.timeout)
     io.info('carelink.command: %r\n%s' % (command, command.hexdump()))
     self.write(x)
     self.write(x)
     log.debug('sent command, waiting')
     time.sleep(command.sleep)
     reply = command(self)
     return reply
示例#10
0
 def __call__( self, command ):
   self.prevCommand = command
   x = str( command )
   self.serial.setTimeout( command.timeout )
   log.debug( 'setting timeout: %s' % command.timeout )
   io.info( 'carelink.command: %r\n%s' % ( command,
                                           command.hexdump( ) ) )
   self.write( x )
   self.write( x )
   log.debug( 'sent command, waiting' )
   time.sleep( command.sleep )
   reply = command( self )
   return reply
示例#11
0
 def execute( self, command ):
   """
   XXX: Handles retries, link control, and message validation?
   """
   link = 0
   # TODO: validate against CRC/ACK
   r = self.__send__require_ack__( command )
   # meter sends DATA
   response = bytearray( self.read( 40 ) )
   io.info( 'get response:%s' % response );
   # PC sends ACK
   self.__acknowledge__( )
   return command.decode( response )
示例#12
0
 def stage1_wakeup(self):
   io.info("wakeup: stage 1")
   command = UltraSmartWakeUpStage1( )
   msg = bytearray( command.code )
   for x in xrange( RETRIES ):
     self.write( str( msg ) )
     #self.write( str( msg ) )
     time.sleep( self.__pause__ )
     response = command( self )
     if response:
       break
   io.info( 'get response:%s' % ( response ) )
   if not response:
     raise OneTouch2Exception("NOT A GOOD START")
示例#13
0
 def stage1_wakeup(self):
     io.info("wakeup: stage 1")
     command = UltraSmartWakeUpStage1()
     msg = bytearray(command.code)
     for x in xrange(RETRIES):
         self.write(str(msg))
         #self.write( str( msg ) )
         time.sleep(self.__pause__)
         response = command(self)
         if response:
             break
     io.info('get response:%s' % (response))
     if not response:
         raise OneTouch2Exception("NOT A GOOD START")
示例#14
0
 def __requireAck__( self ):
   """Try to read an ack, raising MissingAck if we don't read it. Returns
   bytearray ack."""
   ack = None
   for i in xrange( RETRIES ):
     ack = bytearray( self.read( 6 ) )
     if ack == '':
       io.debug( "empty ack:%s:%s:sleeping:%s" % ( i, ack, self.__pause__ ) )
       time.sleep( self.__pause__ )
     else:
       break
   io.info( 'ACK: %s' % lib.hexdump( ack ) )
   if ack == '':
     raise MissingAck(i)
   return ack
示例#15
0
 def execute(self, command):
     """
 """
     msg = self.wrap(command.code)
     # empty meter's buffer before writing anything
     self.readlines()
     for x in xrange(RETRIES):
         self.write(str(msg))
         self.write(str(msg))
         time.sleep(self.__pause__)
         io.info('dm read:%s' % x)
         response = command(self)
         if not command.isEmpty(response):
             break
     io.info('get response:%r' % (repr(response)))
     return command.decode(response)
示例#16
0
 def execute( self, command ):
   """
   """
   msg = self.wrap( command.code )
   # empty meter's buffer before writing anything
   self.readlines( )
   for x in xrange( RETRIES ):
     self.write( str( msg ) )
     self.write( str( msg ) )
     time.sleep( self.__pause__ )
     io.info( 'dm read:%s' % x );
     response = command( self )
     if not command.isEmpty( response ):
       break
   io.info( 'get response:%r' % ( repr( response ) ) )
   return command.decode( response )
示例#17
0
 def stage2_wakeup(self):
   stage2a = [ 0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x07 ]
   stage2b = [ 0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08 ]
   stage2c = [ 0x11, 0x0D, 0x44, 0x4D, 0x53, 0x0D, 0x0D ]
   stage2d = [ 0x11, 0x0D, 0x44, 0x4D, 0x53, 0x0D, 0x0D ]
   stage2e = [ 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x08 ]
   stage2f = [ 0x11, 0x0D, 0x44, 0x4D, 0x53, 0x0D ]
   stages = [ stage2a, stage2b, stage2c, stage2d, stage2e, stage2f, ]
   awake = False
   for stage in stages:
     msg = bytearray(stage)
     self.write( str( msg ) )
     response = self.readlines( )
     if len(response) > 0:
       io.info("got a response!!!")
       io.info(lib.hexdump(bytearray(response)))
       awake = True
   return awake
示例#18
0
 def close( self ):
   io.info( 'closing serial port' )
   return self.serial.close( )
示例#19
0
 def read(self, c):
     r = self.serial.read(c)
     io.info('usb.read.len: %s' % (len(r)))
     io.info('usb.read.raw: \n%s' % (lib.hexdump(bytearray(r))))
     return r
示例#20
0
 def readlines(self):
     r = self.serial.readlines()
     io.info('usb.read.len: %s\n%s' %
             (len(r), lib.hexdump(bytearray(''.join(r)))))
     return r
示例#21
0
 def __acknowledge__( self ):
   msg = [ STX, 6, 0x04 | 0x08, ETX ]
   crc = lib.CRC16CCITT.compute( msg )
   msg.extend( [ lib.LowByte( crc ), lib.HighByte( crc ) ] )
   io.info( 'sending ACK' )
   self.write( str( bytearray( msg ) ) )
示例#22
0
    sys.exit(1)
  print ""
  print "read firmware number"
  firmware = mini.execute( onetouch2.ReadFirmware( ) )
  print "firmware: %s" % firmware 
  print ""
  print "RFID"
  print mini.execute( onetouch2.ReadRFID( ) )
  print "GLUCOSE"
  data = mini.read_glucose( )
  print data
  print "len glucose: %s" % len( data )
  head, body = data 
  output = open( 'sugars-debug.txt', 'w' )
  output.write( glucose.format_records( body ) )
  output.write( '\n' )
  output.close( )

  return mini



if __name__ == '__main__':
  PORT = len(sys.argv) > 1 and sys.argv[1] or PORT
  port = init()
  io.info( port )
  port.close( )

#####
# EOF
示例#23
0
    print "max records: %s" % max_records
    print ""
    print "all records"
    records = []
    for x in xrange(max_records):
        print 'record: %s' % x
        r = mini.execute(lsultramini.ReadGlucoseRecord(idx=x))
        ts, sugar = dateutil.parser.parse(r[0]), r[1]
        msg = ','.join([ts.isoformat(), str(sugar)])
        print msg
        args.output.write(msg + "\n")
        records.append(r)

    print "total records found:%s" % len(records)

    return mini


if __name__ == '__main__':
    parser = argparse.ArgumentParser(add_help=True)
    parser.add_argument('--output',
                        type=argparse.FileType('w'),
                        default="sugars.txt")
    parser.add_argument('port', type=str, default=PORT)
    args = parser.parse_args()
    # PORT = len(sys.argv) > 1 and sys.argv[1] or PORT
    PORT = args.port
    io.info("using PORT %s" % PORT)
    port = init(args)
    io.info(port)
示例#24
0
 def disconnect( self ):
   msg = list( self.wrap( 0x08, [ ] ) )
   io.info( 'disconnect' )
   self.__retry_write_with_ack__( msg, RETRIES )
示例#25
0
  print "FIRMWARE IS: %s" % firmware 
  print ""
  print "read serial number"
  serial = mini.execute( lsultramini.ReadSerialNumber( ) )
  print "serial number: %s" % serial 
  print ""
  print "number of available records:"
  max_records = mini.execute( lsultramini.ReadAvailableRecords( ) )
  print "max records: %s" % max_records 
  print ""
  print "all records"
  records = [ ]
  for x in xrange( max_records ):
    print 'record: %s' % x
    r = mini.execute( lsultramini.ReadGlucoseRecord( x ) )
    print r
    records.append( x )

  print "total records found:%s" % len(records)

  return mini



if __name__ == '__main__':
  PORT = len(sys.argv) > 1 and sys.argv[1] or PORT
  io.info("using PORT %s" % PORT)
  port = init()
  io.info( port )

示例#26
0
    print "could not connect"
    sys.exit(1)
  print ""
  print "read firmware number"
  firmware = mini.execute( onetouch.ReadFirmware( ) )
  print "firmware: %s" % firmware 
  print ""
  print "RFID"
  print mini.execute( onetouch.ReadRFID( ) )
  print "GLUCOSE"
  data = mini.read_glucose( )
  print data
  print "len glucose: %s" % len( data )
  head, body = data 
  output = open( 'sugars-debug.txt', 'w' )
  output.write( glucose.format_records( body ) )
  output.write( '\n' )
  output.close( )

  return mini



if __name__ == '__main__':
  port = init()
  io.info( port )
  port.close( )

#####
# EOF
示例#27
0
 def readlines( self ):
   r = self.serial.readlines( )
   io.info( 'usb.read.len: %s\n%s' % ( len( r ),
                                       lib.hexdump( bytearray( ''.join( r ) ) ) ) )
   return r
示例#28
0
 def read( self, c ):
   r = self.serial.read( c )
   io.info( 'usb.read.len: %s'   % ( len( r ) ) )
   io.info( 'usb.read.raw: \n%s' % ( lib.hexdump( bytearray( r ) ) ) )
   return r
示例#29
0
 def write(self, string):
     r = self.serial.write(string)
     io.info('usb.write.len: %s\n%s' %
             (len(string), lib.hexdump(bytearray(string))))
     return r
示例#30
0
 def write( self, string ):
   r = self.serial.write( string )
   io.info( 'usb.write.len: %s\n%s' % ( len( string ),
                                        lib.hexdump( bytearray( string ) ) ) )
   return r
示例#31
0
 def close(self):
     io.info('closing serial port')
     return self.serial.close()