Graphics.TrickApiServer - lordmundi/wikidoctest GitHub Wiki

Drive DOUG overlays using Enigma API file definitions (using TCL)

Parsing The Enigma API File

The following code parses an Enigma API file and obtains the list of variables defined within it:

set filename "${DOUG_HOME}/sim_data/graphics.api"

 parse_enigma_api_file ${filename}

 set get_variable_list [set enigma_apifile(${filename},variable_list)] 

You can reference information within the parsed API data by referring to the global array "enigma_apifile". The enigma_apifile array holds the node name, parameter, recorded units, read/write, and scale factor values. Each member of the array can be accessed as:

set node_name    [set enigma_apifile(${variable_name},node_name)]
 set node_param   [set enigma_apifile(${variable_name},node_param)]
 set units        [set enigma_apifile(${variable_name},recorded_units)]
 set read_write   [set enigma_apifile(${variable_name},read_write)]
 set scale_factor [set enigma_apifile(${variable_name},scale_factor)]

Getting Data From Doug

Once you have parsed the API file and define the variable list you can begin pulling corresponding values from DOUG. To do this we call the parse_enigma_data routine. This routine will construct a data list that is equivalent to the parsed Trick Interface Libraries data list. By using the same format for the data list you can use data from either source to update your overlays.

parse_enigma_data ${get_variable_list}

Initiating and Scheduling Updates

To kick off your updates make an initial call to your update routine:

update_overlays_api

Each time the update routine executes it will schedule the next update call at the defined cycle time.

after [expr int(${cycletime} * 1000)] update_overlays_api

Dependencies

You must source the Enigma Interface Library at the top of your routine:

# Enigma interface routines…
 if { [catch { source "${DOUG_HOME}/gui/interface_libraries/enigma_interface_library.tcl" } results] != 0 } {
     puts "ERROR sourcing ${DOUG_HOME}/gui/interface_libraries/enigma_interface_library.tcl: ${results}"
     exit −1
 }

Putting It All Together

#!/usr/bin/wish

 set cycletime 0.20

 set DOUG_HOME $env(DOUG_HOME)

 # Enigma interface routines…
 if { [catch { source "${DOUG_HOME}/gui/interface_libraries/enigma_interface_library.tcl" } results] != 0 } {
     puts "ERROR sourcing ${DOUG_HOME}/gui/interface_libraries/enigma_interface_library.tcl: ${results}"
     exit −1
 }

 set filename "${DOUG_HOME}/sim_data/graphics.api"

 parse_enigma_api_file ${filename}
 set get_variable_list [set enigma_apifile(${filename},variable_list)]

 set comm_prefix "_COMM_"

 # Playback Data Processing Routine
 proc update_overlays_api { } {
    global get_variable_list cycletime

    update_overlays [parse_enigma_data ${get_variable_list}]

    # Reschedule this call…
    after [expr int(${cycletime} * 1000)] update_overlays_api
 }

 proc update_overlays { data_list } {
    global get_variable_list comm_prefix

    # Create variables that map to associated variable list indexes.
    # This allows us to reference values by name instead of hard-coded indexes.
    set list_size [ llength ${get_variable_list} ]
    for { set idx 0 } { ${idx} < ${list_size} } { incr idx } {
        regsub -all {\[} [lindex ${get_variable_list} ${idx}] _ variable_name
        regsub -all {\]} ${variable_name} _ variable_name
        set ${comm_prefix}${variable_name} ${idx}
    }

    # Collect the data from simulation&hellip;

    # Display simulation time (sys.exec.out.time)
    puts "Simulation Time: [lindex $data_list [set ${comm_prefix}sys.exec.out.time]]"

    # Call goes here to functions that utilize sim data&hellip;

 }

 update_overlays_api