示例#1
0
文件: mcap_csp.py 项目: nawrasg/hdpy
	def read(self, piconet):
		"""
		Reads Bluetooth clock.

		If piconet is True, reads piconet clock. If False, reads
		native clock (which is the same as piconet clock if
		local BT is piconet master).

		Returns a tuple with BT clock and accuracy, or None if
		not successful.

		Accuracy may be zero (means theoretical infinit precision).
		Unit is Bluetooth "ticks" (312.5 us each), wraps 32 bits
		"""
		addr = None
		if piconet:
			addr = self.addr
		# FIXME handle temporary failure
		return mcap_sock.hci_read_clock(self.raw_socket, addr)
示例#2
0
文件: mcap_csp.py 项目: nawrasg/hdpy
	def _determine_latency(self):
		"""
		Determine how much time it takes to read HCI clock
		"""
		# Exercise modules first
		mcap_sock.hci_read_clock(self.raw_socket, None)
		t = time.time()
		mcap_sock.hci_read_clock(self.raw_socket, None)
		t = time.time()
		mcap_sock.hci_read_clock(self.raw_socket, None)
		t = time.time()

		# take a bunch of measures
		latencies = []
		latencies2 = []
		for x in range(0, 20):
			t1 = time.time()
			# FIXME handle temporary failure
			mcap_sock.hci_read_clock(self.raw_socket, None)
			t2 = time.time()
			latency = t2 - t1
			latencies.append(latency)
			latencies2.append(latency * latency)

		s = sum(latencies)
		n = len(latencies)
		avg = s / n
		stdev = math.sqrt((n * sum(latencies2) - s * s)) / n

		filtered = []
		for latency in latencies:
			# leap of faith here: we assume that latencies too
			# high are result of preemption between calls
			if latency < avg + 6 * stdev:
				filtered.append(latency)

		# Return average without freak samples
		avg = sum(filtered) / len(filtered)
		return int(avg * 1000000)
示例#3
0
文件: mcap_csp.py 项目: nawrasg/hdpy
	def read_native(self):
		# FIXME handle temporary failure
		return mcap_sock.hci_read_clock(self.raw_socket, None)