Пример #1
0
 def __init__(self):
     self.reset_action_counters()
     self.fsm_instance = fsm.Fsm(
         definition=self.fsm_definition,
         action_handler=self,
         log=None,                   # TODO: Testing logging output
         log_id=None)
Пример #2
0
def run():
    password_path = "./pass.txt"
    pad = keypad.Keypad()
    pad.setup()
    #testpad = keypad_test.Keypad()
    ledboard = led.LEDboard()
    #testledboard = led_test.LEDboard()
    ledboard.setup()
    kpc = kpc_agent.KPCAgent(pad, ledboard, password_path)
    #kpc = KPCAgent.KPCAgent(testpad, testledboard, password_path)

    thefsm = fsm.Fsm(kpc)
    # Add fsm rules
    thefsm.addRule("S-init", "S-read", fsm.signal_is_symbol, kpc.reset_password_accumulator)
    thefsm.addRule("S-read", "S-read", fsm.signal_is_digit, kpc.append_next_password_digit)
    thefsm.addRule("S-read", "S-verify", "*", kpc.verify_password)
    thefsm.addRule("S-read", "S-init", fsm.signal_is_symbol, kpc.reset_agent)
    thefsm.addRule("S-verify", "S-active", "Y", kpc.fully_activate_agent)
    thefsm.addRule("S-verify", "S-init", fsm.signal_is_symbol, kpc.reset_agent)
    thefsm.addRule("S-active", "S-led", fsm.signal_less_than_six, kpc.set_lid)  # sett led
    thefsm.addRule("S-active", "S-password", "*", None)  # Begynn passordendring
    thefsm.addRule("S-active", "S-logout", "#", None)
    thefsm.addRule("S-led", "S-time", "*", None)  # Begynn Sett tid, kanskje None
    thefsm.addRule("S-time", "S-time", fsm.signal_is_digit, kpc.append_next_time_digit)  # Legg til på tid
    thefsm.addRule("S-time", "S-active", "*", kpc.light_one_led)
    thefsm.addRule("S-password", "S-password", fsm.signal_is_digit,
                   kpc.append_next_password_digit)  # Legg til på endret passord
    thefsm.addRule("S-password", "S-active", "*", kpc.validate_password)
    thefsm.addRule("S-logout", "S-done", "#", kpc.exit_action)
    thefsm.addRule("S-logout", "S-active", fsm.signal_is_symbol, None)
    thefsm.addRule("S-done", "S-read", fsm.signal_is_symbol, kpc.reset_agent())

    thefsm.set_start_state("S-init")
    # fsm.set_end_state("S-end")#Har ingen end state foreløpig
    thefsm.main_loop()
Пример #3
0
 def __init__(self, node, config):
     # TODO: process bandwidth field in config
     self._node = node
     self.name = config['name']
     # TODO: Make the default metric/bandwidth depend on the speed of the interface
     self._metric = self.get_config_attribute(config, 'metric',
                                              common.constants.default_bandwidth)
     self._advertised_name = self.generate_advertised_name()
     self._log_id = node.log_id + "-{}".format(self.name)
     self._ipv4_address = utils.interface_ipv4_address(self.name,
                                                       self._node.engine.tx_src_address)
     self._rx_lie_ipv4_mcast_address = self.get_config_attribute(
         config, 'rx_lie_mcast_address', constants.DEFAULT_LIE_IPV4_MCAST_ADDRESS)
     self._tx_lie_ipv4_mcast_address = self.get_config_attribute(
         config, 'tx_lie_mcast_address', constants.DEFAULT_LIE_IPV4_MCAST_ADDRESS)
     self._rx_lie_ipv6_mcast_address = self.get_config_attribute(
         config, 'rx_lie_v6_mcast_address', constants.DEFAULT_LIE_IPV6_MCAST_ADDRESS)
     self._tx_lie_ipv6_mcast_address = self.get_config_attribute(
         config, 'tx_lie_v6_mcast_address', constants.DEFAULT_LIE_IPV6_MCAST_ADDRESS)
     self._rx_lie_port = self.get_config_attribute(config, 'rx_lie_port',
                                                   constants.DEFAULT_LIE_PORT)
     self._tx_lie_port = self.get_config_attribute(config, 'tx_lie_port',
                                                   constants.DEFAULT_LIE_PORT)
     self._rx_tie_port = self.get_config_attribute(config, 'rx_tie_port',
                                                   constants.DEFAULT_TIE_PORT)
     self._rx_fail = False
     self._tx_fail = False
     self._log = node.log.getChild("if")
     self.info("Create interface")
     self._rx_log = self._log.getChild("rx")
     self._tx_log = self._log.getChild("tx")
     self._fsm_log = self._log.getChild("fsm")
     self.local_id = node.allocate_interface_id()
     self._mtu = self.get_mtu()
     self._pod = self.UNDEFINED_OR_ANY_POD
     self.neighbor = None
     self._time_ticks_since_lie_received = None
     self._lie_accept_or_reject = "No LIE Received"
     self._lie_accept_or_reject_rule = "-"
     self._lie_receive_handler = None
     self._flood_receive_handler = None
     self._flood_send_handler = None
     # The following queues (ties_tx, ties_rtx, ties_req, are ties_ack) are ordered dictionaries.
     # The value is the header of the TIE. The index is the TIE-ID want to have two headers with
     # same TIE-ID in the queue. The ordering is needed because we want to service the entries
     # in the queue in the same order in which they were added (FIFO).
     # TODO: For _ties_rtx, add time to retransmit to retransmit queue
     self._ties_tx = collections.OrderedDict()
     self._ties_rtx = collections.OrderedDict()
     self._ties_req = collections.OrderedDict()
     self._ties_ack = collections.OrderedDict()
     self.fsm = fsm.Fsm(
         definition=self.fsm_definition,
         action_handler=self,
         log=self._fsm_log,
         log_id=self._log_id)
     if self._node.running:
         self.run()
         self.fsm.start()
    def setUp(self) -> None:
        rospy.init_node("test_fsm", anonymous=True)
        self.mm = MavrosMock()

        rospy.Service("/mavros/set_mode",SetMode, self.mm.handle_set_mode)
        rospy.Service("/mavros/cmd/arming", CommandBool, self.mm.handle_arm)
        rospy.Service("/mavros/cmd/takeoff", CommandTOL, self.mm.handle_takeoff)
        rospy.Service("/mavros/cmd/land", CommandTOL, self.mm.handle_landing)
        rospy.Service("/mavros/setpoint_velocity/mav_frame", SetMavFrame, self.mm.handle_set_vel_FOR)

        rospy.Subscriber("/mavros/global_position/set_gp_origin", GeoPointStamped, self.mm.handle_set_gp_origin)

        self.fsm = fsmmod.Fsm()
Пример #5
0
 def __init__(self, node, config):
     # TODO: process bandwidth field in config
     self._node = node
     self._interface_name = config['name']
     # TODO: Make the default metric/bandwidth depend on the speed of the interface
     self._metric = self.get_config_attribute(
         config, 'metric', common.constants.default_bandwidth)
     self._advertised_name = self.generate_advertised_name()
     self._log_id = node.log_id + "-{}".format(self._interface_name)
     self._ipv4_address = utils.interface_ipv4_address(
         self._interface_name, self._node.engine.tx_src_address)
     self._rx_lie_ipv4_mcast_address = self.get_config_attribute(
         config, 'rx_lie_mcast_address',
         constants.DEFAULT_LIE_IPV4_MCAST_ADDRESS)
     self._tx_lie_ipv4_mcast_address = self.get_config_attribute(
         config, 'tx_lie_mcast_address',
         constants.DEFAULT_LIE_IPV4_MCAST_ADDRESS)
     self._rx_lie_ipv6_mcast_address = self.get_config_attribute(
         config, 'rx_lie_v6_mcast_address',
         constants.DEFAULT_LIE_IPV6_MCAST_ADDRESS)
     self._tx_lie_ipv6_mcast_address = self.get_config_attribute(
         config, 'tx_lie_v6_mcast_address',
         constants.DEFAULT_LIE_IPV6_MCAST_ADDRESS)
     self._rx_lie_port = self.get_config_attribute(
         config, 'rx_lie_port', constants.DEFAULT_LIE_PORT)
     self._tx_lie_port = self.get_config_attribute(
         config, 'tx_lie_port', constants.DEFAULT_LIE_PORT)
     self._rx_tie_port = self.get_config_attribute(
         config, 'rx_tie_port', constants.DEFAULT_TIE_PORT)
     self._rx_fail = False
     self._tx_fail = False
     self._log = node.log.getChild("if")
     self.info(self._log, "Create interface")
     self._rx_log = self._log.getChild("rx")
     self._tx_log = self._log.getChild("tx")
     self._fsm_log = self._log.getChild("fsm")
     self._local_id = node.allocate_interface_id()
     self._mtu = self.get_mtu()
     self._pod = self.UNDEFINED_OR_ANY_POD
     self._neighbor = None
     self._time_ticks_since_lie_received = None
     self._lie_accept_or_reject = "No LIE Received"
     self._lie_accept_or_reject_rule = "-"
     self._fsm = fsm.Fsm(definition=self.fsm_definition,
                         action_handler=self,
                         log=self._fsm_log,
                         log_id=self._log_id)
     if self._node.running:
         self.run()
         self._fsm.start()
Пример #6
0
def main():

    netw = network.Network(config.ELEV_ID)
    elev = fsm.Fsm()
    elevator_driver.elevator_hardware_init()
    elev.fsm_init()

    running_thread = Thread(target=elev.fsm_run,
                            args=(netw.online_elevators, ))
    network_receiver_thread = Thread(target=netw.msg_receive_handler,
                                     args=(elev, ))
    network_sender_thread = Thread(target=netw.msg_send_handler, args=(elev, ))

    running_thread.start()
    network_receiver_thread.start()
    network_sender_thread.start()
Пример #7
0
 def __init__(self):
     self.reset_action_counters()
     self.fsm_instance = fsm.Fsm(definition=self.fsm_definition,
                                 action_handler=self,
                                 log=None,
                                 log_id=None)
Пример #8
0
 def __init__(self, parent_engine, config, force_passive):
     # TODO: process state_thrift_services_port field in config
     # TODO: process config_thrift_services_port field in config
     # TODO: process v4prefixes field in config
     # TODO: process v6prefixes field in config
     self._engine = parent_engine
     self._config = config
     self._node_nr = Node._next_node_nr
     Node._next_node_nr += 1
     self._name = self.get_config_attribute('name', self.generate_name())
     self._passive = force_passive or self.get_config_attribute(
         'passive', False)
     self._running = self.is_running()
     self._system_id = self.get_config_attribute('systemid',
                                                 self.generate_system_id())
     self._log_id = self._name
     self._log = logging.getLogger('node')
     # TODO: Make sure formating of log message is deferred everywhere, not just direct calls
     self._log.info("[%s] Create node", self._log_id)
     self._configured_level_symbol = self.get_config_attribute(
         'level', 'undefined')
     parse_result = self.parse_level_symbol(self._configured_level_symbol)
     assert parse_result is not None, "Configuration validation should have caught this"
     (configured_level, leaf_only, leaf_2_leaf,
      superspine_flag) = parse_result
     self._configured_level = configured_level
     self._leaf_only = leaf_only
     self._leaf_2_leaf = leaf_2_leaf
     self._superspine_flag = superspine_flag
     self._interfaces = sortedcontainers.SortedDict()
     self._rx_lie_ipv4_mcast_address = self.get_config_attribute(
         'rx_lie_mcast_address', constants.DEFAULT_LIE_IPV4_MCAST_ADDRESS)
     self._tx_lie_ipv4_mcast_address = self.get_config_attribute(
         'tx_lie_mcast_address', constants.DEFAULT_LIE_IPV4_MCAST_ADDRESS)
     self._rx_lie_ipv6_mcast_address = self.get_config_attribute(
         'rx_lie_v6_mcast_address',
         constants.DEFAULT_LIE_IPV6_MCAST_ADDRESS)
     self._tx_lie_ipv6_mcast_address = self.get_config_attribute(
         'tx_lie_v6_mcast_address',
         constants.DEFAULT_LIE_IPV6_MCAST_ADDRESS)
     self._rx_lie_port = self.get_config_attribute(
         'rx_lie_port', constants.DEFAULT_LIE_PORT)
     self._tx_lie_port = self.get_config_attribute(
         'tx_lie_port', constants.DEFAULT_LIE_PORT)
     # TODO: make lie-send-interval configurable
     self._lie_send_interval_secs = constants.DEFAULT_LIE_SEND_INTERVAL_SECS
     self._rx_tie_port = self.get_config_attribute(
         'rx_tie_port', constants.DEFAULT_TIE_PORT)
     self._derived_level = None
     self._rx_offers = {}
     self._tx_offers = {}
     self._highest_available_level = None
     self._highest_adjacency_three_way = None
     self._fsm_log = self._log.getChild("fsm")
     self._holdtime = 1
     self._next_interface_id = 1
     if 'interfaces' in config:
         for interface_config in self._config['interfaces']:
             self.create_interface(interface_config)
     self._fsm = fsm.Fsm(definition=self.fsm_definition,
                         action_handler=self,
                         log=self._fsm_log,
                         log_id=self._log_id)
     self._hold_down_timer = timer.Timer(
         interval=self.DEFAULT_HOLD_DOWN_TIME,
         expire_function=lambda: self._fsm.push_event(self.Event.
                                                      HOLD_DOWN_EXPIRED),
         periodic=False,
         start=False)
     self._fsm.start()
Пример #9
0
'''
generate test cases based on walking through a finite state machine

'''
import fsm
from random import choice

demo = fsm.Fsm('rubertoDemo.xml')  #generates a FSM from xml file

#putting text_file in global scope for now. TODO refactor
text_file = open("demo.py", "w")
'''
Setup the test, by creating the code headers and initialization for the tests

'''


def test_setup():
    text_file.write("#demo.py, automatically generated webdriver code\n")
    text_file.write("from selenium import webdriver\n")
    text_file.write("driver = webdriver.Firefox()\n")
    text_file.write("driver.get(\"http://blog.ruberto.com\")\n"
                    )  #should read this from the fsm xml file

    return


def test_teardown():
    text_file.write("driver.quit()\n")
    text_file.write("print \"So long, and thanks for all the fish\"")
    text_file.close()