def readNodeId(self): '''Determines node ID of this node by reading the GPIO input values wired to the DIP switches on the node formation cape.''' if not isBeaglebone(): # not a Beaglebone (assumed to be gcs) self.nodeId = self.maxNumNodes return import mesh.generic.gpio as GPIO # Enable switches GPIO.setup("P8_7", "in") GPIO.setup("P8_8", "in") GPIO.setup("P8_10", "in") if(GPIO.input("P8_7") == 0 and GPIO.input("P8_8") == 0 and GPIO.input("P8_10") == 0): if (self.gcsPresent): # ground node self.nodeId = self.maxNumNodes else: # Node disabled print("Invalid Node ID switch settings. Exiting node control script") sys.exit() elif(GPIO.input("P8_7") == 0 and GPIO.input("P8_8") == 1 and GPIO.input("P8_10") == 0): self.nodeId = 1 elif(GPIO.input("P8_7") == 1 and GPIO.input("P8_8") == 0 and GPIO.input("P8_10") == 0): self.nodeId = 2 elif(GPIO.input("P8_7") == 1 and GPIO.input("P8_8") == 1 and GPIO.input("P8_10") == 0): self.nodeId = 3 elif(GPIO.input("P8_7") == 0 and GPIO.input("P8_8") == 0 and GPIO.input("P8_10") == 1): self.nodeId = 4 elif(GPIO.input("P8_7") == 0 and GPIO.input("P8_8") == 1 and GPIO.input("P8_10") == 1): self.nodeId = 5 elif(GPIO.input("P8_7") == 1 and GPIO.input("P8_8") == 0 and GPIO.input("P8_10") == 1): self.nodeId = 6 elif(GPIO.input("P8_7") == 1 and GPIO.input("P8_8") == 1 and GPIO.input("P8_10") == 1): self.nodeId = 7 else: # Node disabled print("Node is disabled. Exiting node control script") sys.exit() print("Node id: " + str(self.nodeId)) # Set ip address and hostname based on node id if self.nodeId > 0: os.system('sudo hostname node' + str(self.nodeId)) os.system('sudo ifconfig eth0 192.168.0.' + str(self.nodeId) + '0') os.system('sudo route add default gw 192.168.0.1') with open("hostname", "a") as f: f.write("node" + str(self.nodeId)) with open("hosts", "a") as f: f.write("127.0.0.1 localhost.localdomain localhost \n") f.write("127.0.0.1 node" + str(self.nodeId)) os.system("sudo mv hostname /etc/") os.system("sudo mv hosts /etc/")
def __init__(self, referenceTime=[], ppsPin=None): if referenceTime: # Initialize time from some reference time self.referenced = True self.referenceTime = referenceTime else: self.referenced = False if ppsPin and isBeaglebone(): # monitor PPS signal self.tdmaTimerStart = time.time() self.timerLock = Lock() self.monitorThread = SyncPulseMonitorThread( ppsPin, self.resetTDMATimer) self.monitorThread.setDaemon( True ) # set as daemon so it will terminate when main program ends self.monitorThread.start()
class TestTDMATime: pytestmark = pytest.mark.skipif( isBeaglebone() == False, reason="requires configured formation node") def setup_method(self, method): pass def test_getTimeOffset(self): """Test getTimeOffset method.""" # Test pps offset offset = getTimeOffset('pps') assert (offset == None or (isinstance(offset, Real) and offset > 0)) # Test standard offset retValue = getTimeOffset('standard') assert (isinstance(retValue, tuple)) assert (isinstance(retValue[0], bool)) assert (retValue[1] == None or (isinstance(retValue[1], Real) and retValue[1] > 0))
class TestXbeeRadio: pytestmark = pytest.mark.skipif(isBeaglebone() == False, reason="requires GPIO") def setup_method(self, method): from mesh.generic.xbeeRadio import XbeeRadio self.nodeParams = NodeParams(configFile=configFilePath) self.xbeeRadio = XbeeRadio( [], { 'uartNumBytesToRead': self.nodeParams.config.uartNumBytesToRead, 'rxBufferSize': 2000 }, "P8_12") def test_modeChanges(self): """Test mode changes of XbeeRadio.""" import Adafruit_BBIO.GPIO as GPIO assert (self.xbeeRadio.mode == RadioMode.off) # Set mode to receive self.changeMode(RadioMode.receive) assert (GPIO.input("P8_12") == 0) # Set mode to off self.changeMode(RadioMode.off) assert (GPIO.input("P8_12") == 1) # Set mode to transmit self.changeMode(RadioMode.transmit) assert (GPIO.input("P8_12") == 0) # Set mode to sleep self.changeMode(RadioMode.sleep) assert (GPIO.input("P8_12") == 1) def changeMode(self, mode): self.xbeeRadio.setMode(mode) assert (self.xbeeRadio.mode == mode)
def test_readNodeId(self): if isBeaglebone(): # only run test if running on node assert (socket.gethostname() == 'node' + str(self.nodeConfig.nodeId)) # confirm hostname assert (netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr'] == '192.168.0.' + str(self.nodeConfig.nodeId) + '0')