Esempio n. 1
0
class TestFormationClock:
    def setup_method(self, method):

        # Create FormationClock instance

        if method.__name__ == "test_referenceClock":
            self.clock = FormationClock(time.time())
        else:
            self.clock = FormationClock()

    def test_standardClock(self):
        """Test non-referenced clock functionality."""
        startTime = time.time()
        clockTime = self.clock.getTime()
        endTime = time.time()
        assert (clockTime >= startTime and clockTime <= endTime
                )  # Check that returned time is correct

    def test_referenceClock(self):
        """Test referenced clock functionality."""
        assert (self.clock.getTime() <= time.time() - self.clock.referenceTime)

    def test_getOffset(self):
        """Test time offset functionality."""
        offset = self.clock.getOffset()
        assert (offset == None or (isinstance(offset, Real) and offset > 0))
Esempio n. 2
0
class TestFormationClock:
    def setup_method(self, method):

        # Create FormationClock instance

        if method.__name__ == "test_referenceClock":
            self.clock = FormationClock(time.time())
        else:
            self.clock = FormationClock()

    def test_nonreferenceClock(self):
        """Test non-referenced clock functionality."""
        startTime = time.time()
        clockTime = self.clock.getTime()
        endTime = time.time()
        assert (clockTime >= startTime and clockTime <= endTime
                )  # Check that returned time is correct

    def test_referenceClock(self):
        """Test referenced clock functionality."""
        assert (self.clock.getTime() <= time.time() - self.clock.referenceTime)

    def test_getOffset(self):
        """Test time offset functionality."""
        # Test zero offset returned when no time source
        self.clock.timeSource = None
        offset = self.clock.getOffset()
        assert (abs(offset) < 0.00001)
Esempio n. 3
0
class NodeParams():
    def __init__(self, configFile=[], config=[]):
        if configFile:
            self.config = NodeConfig(configFile)
        elif config:
            self.config = config

        self.setupParams()

    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)]

    def get_cmdCounter(self):
        #if self.commStartTime: # time-based counter
        #    return int((self.clock.getTime() - self.commStartTime)*1000)
        #else: # random counter
        return random.randint(1, 65536)

    def checkTimeOffset(self, offset=None):
        if (self.config.commType == "TDMA"):  # TDMA time offset failsafe
            if self.config.commConfig[
                    'fpga'] and self.fpgaFailsafePin:  # TDMA time controlled by FPGA
                if (GPIO.input(self.fpgaFailsafePin) == 0):  # failsafe not set
                    self.timeOffsetTimer = None  # reset timer
                else:  # failsafe condition set
                    if self.timeOffsetTimer:
                        if self.clock.getTime(
                        ) - self.timeOffsetTimer > self.config.commConfig[
                                'offsetTimeout']:  # No time offset reading for longer than allowed
                            self.tdmaFailsafe = True  # Set TDMA failsafe flag
                            return 3
                    else:  # start timer
                        self.timeOffsetTimer = self.clock.getTime()

            else:
                if offset == None:  # offset not provided so attempt to get offset from clock
                    offset = self.clock.getOffset()

                if offset != None:  # time offset available
                    self.timeOffsetTimer = None  # reset time offset timer
                    self.nodeStatus[self.config.nodeId - 1].timeOffset = offset
                    if abs(self.nodeStatus[self.config.nodeId - 1].timeOffset
                           ) > self.config.commConfig['operateSyncBound']:
                        return 1
                else:  # no offset available
                    self.nodeStatus[self.config.nodeId -
                                    1].timeOffset = 127  # Error value
                    # Check time offset timer
                    if self.timeOffsetTimer:
                        #print(self.clock.getTime() - self.timeOffsetTimer)
                        if self.clock.getTime(
                        ) - self.timeOffsetTimer > self.config.commConfig[
                                'offsetTimeout']:  # No time offset reading for longer than allowed
                            self.tdmaFailsafe = True  # Set TDMA failsafe flag
                            return 2
                    else:  # start timer
                        self.timeOffsetTimer = self.clock.getTime()