Beispiel #1
0
 def _getAnaMap(self, anaChan=None):
     if not self.anamap:
         hand = 9999
         descr = None
         #time.sleep(0.1)
         if self.dev:
             descr = self.dev.getDescriptors(
             )  # also having the characteristics
         if not descr:
             logger.warning("no descriptors for dev %s" % self.dev)
         for des in descr:
             if des.uuid == btle.UUID(
                     CHARS[chANA1ST]):  # it is an analog channel charist
                 hand = des.handle
             #logger.debug('des:%s , %s' % (hand,des.uuid));
             if des.handle > hand and (des.uuid == btle.UUID(
                     CHARS[dscPRESFORM])):  # look for presentation format
                 #time.sleep(0.1)
                 datPresForm = des.read()
                 logger.debug(
                     'DescrPresForm hand:%d dat:%s uuid %s' %
                     (des.handle, tls.bytes_to_hex(datPresForm), des.uuid))
                 chan = datPresForm[5]
                 self.anamap[chan] = hand
                 logger.debug('(A%d) ana hand:%s with presfrm:%s ' %
                              (chan, hand, des))
                 hand = 9999
     if self.anamap and anaChan in self.anamap:
         return self.anamap[anaChan]
     return None
Beispiel #2
0
 def _readDigitals(self):
     ''' get aios GATT representation of digital bit values and settings '''
     if self.dev and self.dev.getState() == 'conn':
         service = self.dev.getServiceByUUID(btle.UUID(AIOS_SVR))
         chT = service.getCharacteristics(btle.UUID(CHARS[chDIGI]))
         if chT:
             bts = self.read(chT[0])
             logger.debug('reading digitals:%s' % tls.bytes_to_hex(bts))
             return bts
     return None
Beispiel #3
0
 def _sendDigBits(self):
     ''' send state of digital bits to aios device '''
     nbits = len(self.digmods)
     if nbits <= 0:
         return
     bitsbuf = bytearray((nbits >> 2) + (1 if (nbits & 3) else 0))
     for bt in range(nbits):
         bit2 = self.digmods[bt]
         if bit2 == mdOUT and self.bitvals[bt]:
             bit2 |= 1
         bitsbuf[bt >> 2] |= bit2 << ((bt & 3) * 2)
     if self.dev:
         service = self.dev.getServiceByUUID(btle.UUID(AIOS_SVR))
         chT = service.getCharacteristics(btle.UUID(CHARS[chDIGI]))
         self.write(chT[0], bytes(bitsbuf))
         logger.debug('aios sending %d digdat:%s' %
                      (nbits, tls.bytes_to_hex(bitsbuf, '.')))
Beispiel #4
0
 def setAnaVoltRange(self, chan, volt, SCL=SCALES[chANA1ST]):
     charist = self._getAnaCharacteristic(chan)
     maxV = None
     if charist:
         descr = charist.getDescriptors(btle.UUID(CHARS[dscVALRNG]))
         if descr:
             minmax = descr[0].read()
             minV = tls.bytes_to_int(minmax[:2], '<', False) / SCL
             maxV = tls.bytes_to_int(minmax[2:], '<', False) / SCL
             logger.info('dscVALRNG : %s min=%f max=%f' %
                         (minmax, minV, maxV))
             if volt and descr:
                 minmax = (int(minV * SCL)) + (int(volt * SCL) << 16)
                 minmax = (int(chan)) + (int(volt * SCL) << 16
                                         )  # hack to know channel at server
                 minmax = minmax.to_bytes(4, 'little')
                 logger.info(
                     "update volt range chan:%d to %fV :minmax=%s on %s" %
                     (chan, volt, tls.bytes_to_hex(minmax), descr[0].uuid))
                 self.write(descr[0], minmax)
     return maxV