def receiveData(f):
	while len(sensorReceiver) > 0:
		if com.lenght() > 0:
			dato = com.receive()
			print dato.getSender()
			f.write(dato.getSender().center(15)+'-'.center(10)+'-'.center(10)+str(dato.getData()).center(10)+dato.getUnit().center(10)+time.strftime("%H:%M:%S").center(10)+'\n')
	exit(0)
示例#2
0
def readCommand(sensorList, conditionList):
	
	# Se leen comandos mientras existan sensores activos
	while len(sensorDict) > 0:
		
		# Pregunta si hay mensajes por recibir
		if com.lenght() > 0: 
			# Recibe el mensaje  en cola
			comando = com.receive()
			
			sensorNumber = sensorDict[comando.getReceiver()]
			#sensorNumber = sensorDict[parsedCommand[0]]
			
			# Adquiere el lock sobre la condicion para garantizar la 
			# exclusion mutua sobre las variables compartidas
			conditionList[sensorNumber].acquire()
			
			# interpreta los comandos  y actua de acuerdo a lo recibido
			if (comando.getCommand() == "SENSE") | (comando.getCommand() == "SETFR"):	
				sensorList[sensorNumber].setSenseFlag(True)
				sensorList[sensorNumber].setFrequency(comando.getValue())
				#sensorList[sensorNumber].setFrequency(int(parsedCommand[2]))				
			else:
				# Si se recibe un STOP sobre un determinado sensor, 
				# se lo elimina del diccionario
				sensorList[sensorNumber].setSenseFlag(False)
				del sensorDict[comando.getReceiver()];
			
			# Despierta los hilos dormidos bajo la condicion y libera el bloqueo
			conditionList[sensorNumber].notify()
			conditionList[sensorNumber].release()
	exit (0)