Exemple #1
0
	def _inLod(self, perf, charis=None):
		""" get lodrecs of charis to be found for peripheral
		"""
		if not perf.name:
			return []
		isin = tls.query_lod(self.lodCharist,
		lambda rw: rw[chPERF] in perf.name and (not rw[chPUID]) and rw[chCUID])
		if not isin:
			isin = tls.query_lod(self.lodCharist, 
			lambda rw: (rw[chPUID] and rw[chPUID] in perf.uuid))
		if not isin:
			isin = tls.query_lod(self.lodCharist,
			lambda rw: rw[chPERF] in perf.name and (not rw[chPUID]) and (not rw[chCUID]))
		if charis:
			isin = tls.query_lod(isin,
			lambda rw: ((rw[chCUID] in charis.uuid) and (rw[chID] in self.ToBeFnd)))
		return isin
Exemple #2
0
	def read_characteristic(self, chId, waitReceived=False, timeout=10):
		""" did_update_value callback will receive result
		"""
		rec = tls.query_lod(self.charFound, lambda rw:rw[chID]==chId)
		self.updating = chId
		if rec:
			char = rec[0]['charis']
			rec[0]['periph'].read_characteristic_value(char)
			tick = time.clock()
			while waitReceived and self.updating>0 and time.clock()-tick <timeout:
				time.sleep(0.1)
			return rec[0]['charis'].value
		else:
			logger.warning('no recs reading')
Exemple #3
0
	def setup_notification(self, chId):
		""" setup notification for characteristic that support it
		  returns True when successfull or allready notifying
		"""
		isin = tls.query_lod(self.charFound, lambda rw:rw[chID]==chId)
		c = isin[0]['charis']
		if c.notifying:
			return True
		p = isin[0]['periph']
		logger.info('setup notification for perf:%s (c:%d) with prop:%s notifying:%d' % (p.name,chId, MaskedPropMsg(cbPropMsg, c.properties), c.notifying))
		if c.properties & cb.CH_PROP_INDICATE:
			p.set_notify_value(c, True)
		elif c.properties & cb.CH_PROP_NOTIFY:
			p.set_notify_value(c, True)
		else:
			return False
		return True
Exemple #4
0
	def did_update_value(self, c, error):
		''' called after notify or read event 
			as cb does not support descriptors, notifiers are not used for analog chans but just read with waiting for result and chId is found in self.updating
		'''
		lodr = tls.query_lod(self.charFound, 
			lambda rw:rw['charis'].uuid==c.uuid and (rw[chID]==self.updating or self.updating==0))  # may find wrong anachan on notifying !!!
		if lodr:
			respCallback = lodr[0][chCallback]
		else:
			logger.warning('%s not found ' % c.uuid)
			respCallback=None
			lodr=[{chID:-1}]
		if respCallback is None:
			sval = ''.join('{:02x}'.format(x) for x in c.value)
			logger.info('Updated value: %s from %s' % (sval, c.uuid))
		else:
			respCallback(c)  # allready having chId from partial, lodr[0][chID])
		self.updating = 0
Exemple #5
0
	def setup_response(self, chId, respCallback=None):
		""" setup callback for value of characteristic
		"""
		isin = tls.query_lod(self.charFound, lambda rw:rw[chID]==chId)
		isin[0][chCallback] = partial(respCallback ,chId=chId)   # to be used in self.did_update_value
Exemple #6
0
	def write_characteristic(self, chId, chData):
		''' write data to ble characteristic '''
		rec = tls.query_lod(self.charFound, lambda rw: rw[chID]==chId)
		c = rec[0]['charis']
		logger.debug('writing val to c:%s val:%s' % (c.uuid,''.join('{:02x}'.format(x) for x in chData)))
		rec[0]['periph'].write_characteristic_value(c, chData, c.properties & cb.CH_PROP_WRITE_WITHOUT_RESPONSE ==0)