Ejemplo n.º 1
0
def main(retries=10, retry_delay=1.0):
	adb = lambda cmd, ADB=ADB: sh("%s %s"%(ADB, cmd))
	adb("forward tcp:%i tcp:%i"%(LOCATION_PORT, LOCATION_PORT))
	#adb("install -r -g %s"%SERVER_APK)
	adb("shell am startservice -a independent.trusas.LocationDumpManager")
	
	for retry in range(retries):
		try:
			con = socket.create_connection(
				("127.0.0.1", LOCATION_PORT),
				timeout=retry_delay)
			con.setblocking(1) # Just in case
			reader = SocketLineReader(con)
			# Seems to be the only way to see if the
			# socket is still (or in this case has ever really been)
			# connected.
			if not reader.has_eof():
				break
			
		except socket.error:
			pass
		
		time.sleep(retry_delay)
	else:
		raise IOError("Unable to connect to trusas location dump.")
	
	packer = default_packer()
	for line in reader:
		event = json.loads(line)
		packer.send(event)
Ejemplo n.º 2
0
def main(nexus_address, pin=None):
	if pin:
		# TODO: Check the status
		Popen("echo %s |bt-agent"%(pin,),
			stdout=open(os.devnull), stderr=open(os.devnull),
			shell=True)
	record(nexus_address, default_packer())
Ejemplo n.º 3
0
def main(retries=10, retry_delay=0.5):
	adb = lambda cmd, ADB=ADB: sh("%s %s"%(ADB, cmd))
	adb("forward tcp:%i tcp:%i"%(LOCATION_PORT, LOCATION_PORT))
	adb("install %s"%SERVER_APK)
	adb("shell am startservice -a independent.trusas.LocationDumpManager")
	
	for retry in range(retries):
		try:
			con = socket.create_connection(
				("127.0.0.1", LOCATION_PORT),
				timeout=retry_delay)
			con.setblocking(1) # Just in case
			reader = SocketLineReader(con)
			# Seems to be the only way to see if the
			# socket is still (or in this case has ever really been)
			# connected.
			if not reader.has_eof():
				break
			
		except socket.error:
			pass
		
		time.sleep(retry_delay)
	else:
		raise IOError("Unable to connect to trusas location dump.")
	
	packer = default_packer()
	for line in reader:
		event = json.loads(line)
		packer.send(event)
Ejemplo n.º 4
0
def main():
	unpacker = default_unpacker()
	packer = default_packer()

	for header, event in unpacker:
		mapped = map_from_android(event)
		if mapped is None: continue
		packer.send(mapped, header=header)
Ejemplo n.º 5
0
def main():
    unpacker = default_unpacker()
    packer = default_packer()

    for header, event in unpacker:
        mapped = map_from_android(event)
        if mapped is None: continue
        packer.send(mapped, header=header)
Ejemplo n.º 6
0
def run_ui(*args, **kwargs):
	global appscopehack
	app = QApplication([])
	appscopehack = app
	window = QWidget()
	layout = QGridLayout(window)
	window.setLayout(layout)

	
	beeper = QPushButton("Preview beep")
	beeper.clicked.connect(lambda *args: bg_run(play_stimulus_once)(NOTIFICATION_STIMULUS))
	noiser = QPushButton("Preview noise")
	noiser.clicked.connect(lambda *args: bg_run(play_stimulus_once)(STIMULUS))
	
	cancel = QPushButton("Cancel experiment")

	layout.addWidget(beeper, 0, 0)
	layout.addWidget(noiser, 0, 1)
	
	class ThreadSyncHack(QObject):
		on_done = pyqtSignal()
	
	hack = ThreadSyncHack()
	control = QPushButton("Start experiment")

	def on_done(*args):
		output.send({'event': "experiment-end"})
		control.setText("DONE! Restart experiment")
		layout.addWidget(control, 1, 0, 1, 2)
		beeper.setDisabled(False)
		noiser.setDisabled(False)
		control.setDisabled(False)

	hack.on_done.connect(on_done)

	output = default_packer()
	def start(*args):
		duration = 15*60.0
		#duration = 10.0
		frequency = 1.0/10.0
		
		beeper.setDisabled(True)
		noiser.setDisabled(True)
		control.setDisabled(True)
		control.setText("Experiment running")
		output.send({'event': "experiment-start"})
		bg_run(run_noise_sequence)(output, duration, int(duration*frequency),
			on_done=lambda: hack.on_done.emit())

		#layout.addWidget(cancel, 1, 0, 1, 2)
		
	
	control.clicked.connect(start)
	layout.addWidget(control, 1, 0, 1, 2)

	window.show()
	app.exec_()
Ejemplo n.º 7
0
def main(retries=10, retry_delay=0.5):
	adb = lambda cmd, ADB=ADB: sh("%s %s"%(ADB, cmd))
	adb("forward tcp:%i tcp:%i"%(SENSOR_PORT, SENSOR_PORT))
	adb("install -r -g %s"%SERVER_APK)
	adb("shell am startservice -a independent.trusas.SensorDumpManager")
	
	for retry in range(retries):
		try:
			con = socket.create_connection(
				("127.0.0.1", SENSOR_PORT),
				timeout=retry_delay)
			con.setblocking(1) # Just in case
			reader = SocketLineReader(con)
			# Seems to be the only way to see if the
			# socket is still (or in this case has ever really been)
			# connected.
			if not reader.has_eof():
				break
			
		except socket.error:
			pass
		
		time.sleep(retry_delay)
	else:
		raise IOError("Unable to connect to trusas sensor dump.")
	
	packer = default_packer()
	for line in reader:
		event = json.loads(line)
		# FIXME: A desperate premature optimization that
		#	probably at least halves the filesizes, but
		#	breaks our principles. When we get a stream
		#	compression, this mostly static stuff will be
		#	a non-issue
		event["sensor_type"] = event["sensor"]["mType"]
		del event["sensor"]
		
		packer.send(event)
Ejemplo n.º 8
0
def main(retries=10, retry_delay=1.0):
	adb = lambda cmd, ADB=ADB: sh("%s %s"%(ADB, cmd))
	adb("forward tcp:%i tcp:%i"%(SENSOR_PORT, SENSOR_PORT))
	#adb("install -r -g %s"%SERVER_APK)
	adb("shell am startservice -a independent.trusas.SensorDumpManager")
	
	for retry in range(retries):
		try:
			con = socket.create_connection(
				("127.0.0.1", SENSOR_PORT),
				timeout=retry_delay)
			con.setblocking(1) # Just in case
			reader = SocketLineReader(con)
			# Seems to be the only way to see if the
			# socket is still (or in this case has ever really been)
			# connected.
			if not reader.has_eof():
				break
			
		except socket.error:
			pass
		
		time.sleep(retry_delay)
	else:
		raise IOError("Unable to connect to trusas sensor dump.")
	
	packer = default_packer()
	for line in reader:
		event = json.loads(line)
		# FIXME: A desperate premature optimization that
		#	probably at least halves the filesizes, but
		#	breaks our principles. When we get a stream
		#	compression, this mostly static stuff will be
		#	a non-issue
		event["sensor_type"] = event["sensor"]["mType"]
		del event["sensor"]
		
		packer.send(event)