コード例 #1
0
ファイル: nodeParams.py プロジェクト: sqf-ice/meshNetwork
    def setupParams(self):
        self.cmdCounterMax = 255  # DEPRECATED - TODO - DELETE
        self.cmdCounterThreshold = 10  # DEPRECATED - TODO - DELETE
        self.commStartTime = []
        #self.cmdRelayBuffer = []
        self.cmdHistory = deque(
            maxlen=50)  # FIFO list of last commands received

        # Node status
        self.nodeStatus = [
            NodeState(node + 1) for node in range(self.config.maxNumNodes)
        ]

        # Formation clock
        self.clock = FormationClock()

        # TDMA Failsafe status
        self.tdmaStatus = TDMAStatus.nominal
        self.frameStartTime = []  # DEPRECATED - REMOVE
        self.tdmaFailsafe = False
        self.timeOffsetTimer = None
        if (self.config.commConfig['fpga'] == True):
            # Setup FPGA failsafe status pin
            self.fpgaFailsafePin = self.config.commConfig['fpgaFailsafePin']
            GPIO.setup(self.fpgaFailsafePin, "in")
        else:
            self.fpgaFailsafePin = []
        # Comm link status
        self.linkStatus = [[
            LinkStatus.NoLink for i in range(self.config.maxNumNodes)
        ] for j in range(self.config.maxNumNodes)]
コード例 #2
0
    def __init__(self, ppsPin, timerUpdate):
        threading.Thread.__init__(self)

        # Setup PPS GPIO pin
        self.ppsPin = ppsPin
        GPIO.setup(ppsPin, "in")
        self.stopThread = False
        self.timerUpdate = timerUpdate
コード例 #3
0
 def __init__(self, serial, config, sleepPin=[]):
     Radio.__init__(self, serial, config)
     self.sleepPin = sleepPin
     # Setup sleep pin
     if self.sleepPin:
         GPIO.setup(self.sleepPin, "out")
         self.setOff()  # default to off mode
     pass
コード例 #4
0
    def __init__(self, initBound, useLEDs=False):
        self.initSyncBound = initBound
        self.gpsdActive = True
        self.useLEDs = useLEDs

        # Set up logging to syslog
        formatter = logging.Formatter(
            '%(module)s: [%(levelname)s] %(message)s')
        self.sysLogger = logging.getLogger(__name__)
        self.sysLogger.setLevel(logging.DEBUG)
        syslogHandler = logging.handlers.SysLogHandler(address='/dev/log')
        syslogHandler.setFormatter(formatter)
        self.sysLogger.addHandler(syslogHandler)

        # Set up LEDs
        if (self.useLEDs):
            GPIO.setup("P8_15", "out")
            GPIO.output("P8_15", "low")
            GPIO.setup("P8_16", "out")
            GPIO.output("P8_16", "low")
            GPIO.setup("P8_17", "out")
            GPIO.output("P8_17", "low")
            GPIO.setup("P8_18", "out")
            GPIO.output("P8_18", "low")

        # Time sync variables
        self.timeSyncTime = 0.0
コード例 #5
0
    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/")