def unpack_byte_array(self, byte_array): datos = unpack('BIBBBBBf', byte_array) self.rand_id = datos[0] self.date = datos[1] self.sensor_id = SensorId( [Equipo(datos[2]), datos[3], datos[4], datos[5]]) self.type = Tipo(datos[6]) self.data = datos[7]
def main(): pin_movimiento = 23 #PIR 23 pin_big_sound = 17 sensor_id_movimiento = SensorId([Equipo.whitenoise,0,0,1]) sensor_id_big_sound = SensorId([Equipo.whitenoise,0,0,2]) sensor_movimiento = Sensor(sensor_id_movimiento, Tipo.movimiento, pin_movimiento) sensor_big_sound = Sensor(sensor_id_big_sound, Tipo.big_sound, pin_big_sound) sensor_movimiento.start_sensor() sensor_big_sound.start_sensor() try: while True: time.sleep(100) except KeyboardInterrupt: print ("\nSensores Recepcion Finalizado...")
def __init__(self, rand_id=0, date=0, sensor_id=SensorId(), type=Tipo.keep_alive, data=0): self.rand_id = rand_id self.date = date self.sensor_id = sensor_id self.type = type self.data = data
def __init__(self, sensor_id = SensorId(), tipo = Tipo.keep_alive, pin = 0): self.sensor_id = sensor_id self.tipo = tipo self.pin = pin self.mq = sysv_ipc.MessageQueue(2525, sysv_ipc.IPC_CREAT, int("0600", 8), 2048) self.ka = Thread(target=self.keep_alive, args=()) # Configuracion GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(self.pin, GPIO.IN)
def main(): mq = sysv_ipc.MessageQueue(2525, sysv_ipc.IPC_CREAT, int("0600", 8), 2048) try: while True: c = sys.stdin.read(1) if c != '\n': if c == '' or int(c) > 9: c = '0' pre_paquete = CARRETA(0, Utilidades.get_unix_time(), SensorId([Equipo.whitenoise,0,0,1]), Tipo(int(c)), 1) print(pre_paquete) mq.send(pre_paquete.pack_byte_array()) except KeyboardInterrupt: print("\nPrueba finalizada...")
def sendToQueue(cls): carreta = CARRETA(2, 0, SensorId([Equipo((int)(sys.argv[1])), 0, 0, 1]), Tipo((int)(sys.argv[2])), 0) while True: cls.mq.send(carreta.pack_byte_array()) time.sleep(0.5)
def unpack_byte_array(self, byte_array): data = unpack('BBBBB', byte_array) self.rand_id = data[0] self.sensor_id = SensorId([Equipo(data[1]), data[2], data[3], data[4]])
def __init__(self, rand_id = 0, sensor_id = SensorId()): self.rand_id = rand_id self.sensor_id = sensor_id