def test_ping(sniffer, nodeid): print "ping" bugOne.ping(nodeid, sniffer) message = sniffer.waitForMessage() if message and bugOne.getPacketType(message) == bugOne.PACKET_PONG: return True return False
#!/usr/bin/python #-*- coding: utf-8 -*- import rfm12 import bugOne import sys device = "/dev/ttyUSB0" if len(sys.argv) == 2: device = sys.argv[1] sniffer = rfm12.SnifferSerial(device) bugOne.ping(0x1, sniffer) while True: message = sniffer.waitForMessage() if message: messageType = bugOne.getPacketType(message) srcNodeId = bugOne.getPacketSrc(message) destNodeId = bugOne.getPacketDest(message) counter = bugOne.getPacketCounter(message) print "Message [%s] from %s to %s" % (counter, hex(srcNodeId), hex(destNodeId)) if messageType == bugOne.PACKET_HELLO: print "Hello" elif messageType == bugOne.PACKET_PING: print "Ping" elif messageType == bugOne.PACKET_PONG: print "Pong" elif messageType == bugOne.PACKET_VALUES: values = bugOne.readValues(bugOne.getPacketData(message))
#!/usr/bin/python #-*- coding: utf-8 -*- import sys import rfm12 import bugOne if len(sys.argv) != 2: print >>sys.stderr, "usage:", sys.argv[0], "<device id (int)>" exit(1) sniffer = rfm12.SnifferSerial() destDeviceId = int(sys.argv[1]) print "Ping", hex(destDeviceId) bugOne.ping(destDeviceId, sniffer) message = sniffer.waitForMessage() if message and bugOne.getPacketType(message) == bugOne.PACKET_PONG: print "Pong" else: print "Error"