Пример #1
0
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if stomp:
        stomp.connect(clientid="serial port listener",
                      username="******",
                      password="******")

    while (1):
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!",
                     manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)
        packet = xbee_receiver.find_packet(port)
        if packet:
            xb = xbee_receiver(packet)
        else:
            log.warn("NO PACKET FOUND")
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                lastgoodtime = time.time()
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn(
                    "Received a packet, but not a normal rx, was instead: %#x",
                    xb.app_id)
                qq = kpacket.wire_packet(xb.rfdata)
                qqhp = kpacket.human_packet(node=xb.address_16,
                                            sensors=qq.sensors)
                log.info("was actually: %s", qqhp)
                lastgoodtime = time.time()
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp),
                      destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Пример #2
0
def runMainLoop():
    data_queue = Queue.Queue()
    teensy = Usbreader(data_queue)
    teensy.daemon = True
    teensy.start()

    serial = FakeSerial(data_queue)

    if stomp:
        stomp.connect(clientid="teensy usb listener", username="******", password="******")

    while 1:
        packet = xbee_receiver.find_packet(serial)
        if packet:
            xb = xbee_receiver(packet)
        else:
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn("Received a packet, but not a normal rx, was instead: %#x", xb.app_id)
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp), destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Пример #3
0
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if stomp:
        stomp.connect(clientid="serial port local listener", username="******", password="******")

    while(1):
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!", manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)

        wireRx = kpacket.wire_receiver()
        raw = wireRx.find_raw_packet(port)
        if not raw:
            log.warn("NO PACKET FOUND")
            continue

        try:
            kp = kpacket.wire_packet(raw)
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=0x0001, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp), destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Пример #4
0
def runMainLoop():
    lastgoodtime = 0
    port = serial.Serial(config['serialPort'], 19200, timeout=10)
    
    while(1):
        xbtx = xbee()
        fakeReadings = []
        fakeReadings.append(kpacket.Sensor(type=36, raw=0x55))
        fakeReadings.append(kpacket.Sensor(type=0xee, raw=0xff))
        fakeReadings.append(kpacket.Sensor(type=0xaa, raw=0x12345678))
        data = kpacket.human_packet(node=0x6209, sensors=fakeReadings)
        #data = "cafebabe"
        #data = struct.pack("> 5s", "abcde")
        if options.manual:
            log.debug("Press enter to send the packet")
            sys.stdin.readline()
            log.info("injecting a fake packet into the ether...%s", data)
            wiredata = xbtx.tx16(destination=0x6001, data=data.wire_format())
            #wiredata = xbtx.tx16(destination=0x6001, data=data)
            port.write(wiredata)
        else:
            log.info("injecting a fake packet into the ether...%s", data)
            wiredata = xbtx.tx16(destination=0x6001, data=data.wire_format())
            port.write(wiredata)
            time.sleep(1)
Пример #5
0
def runMainLoop():
    lastgoodtime = 0
    port = serial.Serial(config['serialPort'], 19200, timeout=10)

    while (1):
        xbtx = xbee()
        fakeReadings = []
        fakeReadings.append(kpacket.Sensor(type=36, raw=0x55))
        fakeReadings.append(kpacket.Sensor(type=0xee, raw=0xff))
        fakeReadings.append(kpacket.Sensor(type=0xaa, raw=0x12345678))
        data = kpacket.human_packet(node=0x6209, sensors=fakeReadings)
        #data = "cafebabe"
        #data = struct.pack("> 5s", "abcde")
        if options.manual:
            log.debug("Press enter to send the packet")
            sys.stdin.readline()
            log.info("injecting a fake packet into the ether...%s", data)
            wiredata = xbtx.tx16(destination=0x6001, data=data.wire_format())
            #wiredata = xbtx.tx16(destination=0x6001, data=data)
            port.write(wiredata)
        else:
            log.info("injecting a fake packet into the ether...%s", data)
            wiredata = xbtx.tx16(destination=0x6001, data=data.wire_format())
            port.write(wiredata)
            time.sleep(1)
Пример #6
0
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if mqttc:
        mqttc.connect("localhost")

    while mqttc.loop() == 0:
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!", manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)
        packet = xbee_receiver.find_packet(port)
        if packet:
            xb = xbee_receiver(packet)
        else:
            log.warn("NO PACKET FOUND")
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                lastgoodtime = time.time()
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn("Received a packet, but not a normal rx, was instead: %#x", xb.app_id)
                qq = kpacket.wire_packet(xb.rfdata)
                qqhp = kpacket.human_packet(node=xb.address_16, sensors=qq.sensors)
                log.info("was actually: %s", qqhp)
                lastgoodtime = time.time()
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if mqttc:
            mqttc.publish("karlnet/readings/%d" % hp.node, jsonpickle.encode(hp))
            #stomp.put(jsonpickle.encode(hp), destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Пример #7
0
def runMain():
    clientid = "karlnet_fake_producer@%s/%d" % (socket.gethostname(), os.getpid())
    stomp.connect(clientid=clientid)
    
    while True:
        fakeNodeId = 0xbabe
        s1 = kpacket.Sensor(type=36, raw=1234, value=random.randint(0,100))
        s2 = kpacket.Sensor(type=69, raw=4321, value=random.randint(40,80))
        kp = kpacket.human_packet(fakeNodeId, [s1, s2])
        log.info("Producing the dummy data: %s", kp)
        stomp.put(jsonpickle.encode(kp), destination="/topic/karlnet.%d" % fakeNodeId)
        time.sleep(5)
Пример #8
0
def runMainLoop():
    data_queue = Queue.Queue()
    teensy = Usbreader(data_queue)
    teensy.daemon = True
    teensy.start()

    serial = FakeSerial(data_queue)

    if stomp:
        stomp.connect(clientid="teensy usb listener",
                      username="******",
                      password="******")

    while 1:
        packet = xbee_receiver.find_packet(serial)
        if packet:
            xb = xbee_receiver(packet)
        else:
            continue

        try:
            if xb.app_id == xbee.SERIES1_RXPACKET_16:
                kp = kpacket.wire_packet(xb.rfdata)
            else:
                log.warn(
                    "Received a packet, but not a normal rx, was instead: %#x",
                    xb.app_id)
                continue
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        hp = kpacket.human_packet(node=xb.address_16, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp),
                      destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)
Пример #9
0
def runMainLoop():
    lastgoodtime = 0
    port = None
    manualTimeout = 40

    if stomp:
        stomp.connect(clientid="serial port local listener",
                      username="******",
                      password="******")

    while (1):
        if time.time() - lastgoodtime > manualTimeout:
            log.warn("XXX Reopening the serial port, no data for %d seconds!",
                     manualTimeout)
            if port:
                port.close()
            port = serial.Serial(options.port, 19200, timeout=10)

        wireRx = kpacket.wire_receiver()
        raw = wireRx.find_raw_packet(port)
        if not raw:
            log.warn("NO PACKET FOUND")
            continue

        try:
            kp = kpacket.wire_packet(raw)
        except kpacket.BadPacketException as e:
            log.warn("Couldn't decode: %s" % e.msg)
            continue
        lastgoodtime = time.time()
        hp = kpacket.human_packet(node=0x0001, sensors=kp.sensors)
        hp.time_received = time.time()
        if stomp:
            stomp.put(jsonpickle.encode(hp),
                      destination="/topic/karlnet.%d" % hp.node)
        log.info(hp)