def update(): global commandnames, fnumber, teststart, timer if fnumber < len(commandnames): # form function name func = "test_"+ commandnames[fnumber].lower() timer = sim.simt # if function exists if func in globals().keys(): # run the test and get result result = globals()[func](teststart) teststart = False if result != None: stack.stack("ECHO "+commandnames[fnumber]+" DOES %sWORK" % ("" if result else "NOT ") ) # Prepare for next test function fnumber += 1 teststart = True # reset traffic to get rid of unnecessary crap traf.reset() else: # if function does not exist - keep looping fnumber += 1 #stack.stack("ECHO "+func+" DOES NOT EXIST") else: stack.stack("RESET") stack.stack("PAUSE") stack.stack("ECHO FINISHED PERFORMING STACKCHECK") stack.stack("PLUGIN REMOVE STACKCHECK")
def init_plugin(): global fnumber, commandnames, teststart # Run the time stack.stack("OP") stack.stack("FF") # Reset the traffic simulation traf.reset() commandnames = list(stack.cmddict.keys()) # Make a list of testing functions fnumber = 0 teststart = True # Configuration parameters config = { # The name of your plugin 'plugin_name': 'STACKCHECK', # The type of this plugin. For now, only simulation plugins are possible. 'plugin_type': 'sim', 'update': update, 'preupdate': preupdate } stackfunctions = { # The command name for your function 'MYFUN': [ # A short usage string. This will be printed if you type HELP <name> in the BlueSky console 'MYFUN ON/OFF', # A list of the argument types your function accepts. For a description of this, see ... '[onoff]', # The name of your function in this plugin myfun, # a longer help text of your function. 'Print something to the bluesky console based on the flag passed to MYFUN.'] } # init_plugin() should always return these two dicts. return config, stackfunctions
def test_mcre(start): ac_type = 'B747' alt = 100 # FL spd = 250 # CAS in knots ades = 'EHAM' # airport of destination is not checked yet if start: stack.stack("MCRE 11") elif traf.ntraf == 11: traf.reset() stack.stack("MCRE 5 %s FL%s %s %s" % (ac_type, alt, spd, ades)) else: close_enough_alt = np.logical_and(traf.alt <= (alt * 100 * ft + 10), traf.alt >= (alt * 100 * ft - 10)) close_enough_spd = np.logical_and(traf.cas <= (spd * kts + 10), traf.cas >= (spd * kts - 10)) return (traf.ntraf == 5 and len(traf.type)==5 and np.all(close_enough_alt) and np.all(close_enough_spd))