#! usr/bin/env python print "\n*** " + __file__ + " ***\n" import sys sys.path.append('./test') sys.path.append('../test') import startup # SCRIPT EXAMPLE # To be run with "stationtest.elf" station executable # (to be compiled under "/trunk/maximus/stationtest"). from interface import * from struct import pack, unpack def my_cb (msg): print "=>",my_cb.func_name if msg.is_param("result_2"): result2 = unpack('q',msg.bind_param("result_2")) print "result 2 =",result2[0] receive_fc1_rsp = True # Instantiate a Maximus object and initialize it. maximus = Maximus() maximus.init(sys.argv) # Create three stations. stationA = maximus.create_sta() stationB = maximus.create_sta() stationC = maximus.create_sta() # Launch a debugger attached to station B. stationB.debug() # Send an asynchronous function message to station A. # # Create a function message and set the name of the function to call of station A. fc1 = maximus.create_fcall("function_1") # Add a first parameter to the created message. param1 = pack('iiB',1,2,True) fc1.add_param("param_1", param1) # Add a second parameter to the created message. param2 = pack('iiiiiiiiii',0,1,2,3,4,5,6,7,8,9) fc1.add_param("param_2", param2) # Add a third parameter to the created message. param3 = "hello" fc1.add_param("param_3", param3) # Add a fourth parameter to the created message. param4 = pack('q',123) fc1.add_param("param_4", param4) # Register a callback function which will be called at message response reception. fc1.set_cb(my_cb) # Set destination station of message 1. fc1.set_sta(stationA) # Send the configured message in an asynchronous mode. receive_fc1_rsp = False fc1.send_async() # Send a synchronous function message to station B. # Create a function message and set the name of the function to call into station B. fc2 = maximus.create_fcall("function_2") # Add a first parameter to the created message. fc2.add_param_bool("param_5", True) # Send the configured message to station B in a synchronous mode. fc2.send(stationB) # Get the function result. result1 = fc2.bind_param_string("result_1") print "result1 =",result1 # Set a parameter value of station B. probe1 = maximus.create_probe() param6 = 789 probe1.add_param_ulong("param_6", param6) probe1.send(stationB) # Get a parameter value from station B. probe2 = maximus.create_probe().add_param("param_7") probe2.send(stationB) param7 = probe2.bind_param_ulong("param_7") print "param 7 =",param7 # Get the same parameter value from station C, re-using existing message. probe2.send(stationC) # Send asynchronous function message(s) to station B. if 456 == param7: fc3 = maximus.create_fcall("function_3") fc3.send_async(stationC) fc4 = maximus.create_fcall("function_4") fc4.send_async(stationC) # Send an asynchronous function message to station C. fc5 = maximus.create_fcall("function_5") fc5.send_async(stationC) # Wait for responses to all sent messages in asynchronous mode. maximus.wait() # Get list of all registered parameters of stations C. probe3 = maximus.create_probe() probe3.send(stationC) if probe3.is_param("param_8"): # Get parameter 8 value and set parameter 9 value of station C. probe4 = maximus.create_probe() probe4.add_param("param_8") probe4.add_param_bool("param_9", False) probe4.send(stationC) param8 = probe4.bind_param_bool("param_8") print "param 8 =",param8 # Wait during 1000000 ticks before creating another station. maximus.wait(1000000) # Create a fourth station. stationD = maximus.create_sta() # Wait during 1000000 ticks before terminating the program. maximus.wait(1000000) # Remove stations. stationA.remove() stationB.remove() stationC.remove() stationD.remove() print "\n*** END ***\n"