Script demo 1.txtΒΆ

#         1         2         3         4         5         6         7
#234567890123456789012345678901234567890123456789012345678901234567890123456789
################################################################################
#                           Basic Script Demo
#
# This is a basic script example that demonstrates some the features
# of the scripting language and how to use scripting in a WSF component.
#
# In this scenario we have:
#
# a) an air platform.
#
# The air platform will fly a route and print its configuration using a script.
#
################################################################################

script_interface
   debug
end_script_interface

.. include:: dis_network.txt

################################################################################
// Define the platform type for the notional 737.

platform_type 737 WSF_PLATFORM

   mover WSF_AIR_MOVER
   end_mover

   // This is an example single shot processor that runs only once.
   // It dumps out a bunch of information about the platform.  In its
   // current configuration it doesn't contain any sensors, comm devices, etc.
   processor show-config-proc WSF_SCRIPT_PROCESSOR
      update_interval 1.0 sec

      // An example of how to create instance variables.  These can be used
      // in any scripts defined within the current processor.
      Script Variables
         int mMyInt = 999;
         double mMyDouble = 123.456;
         WsfPlatform mMyPlatform = PLATFORM;

         // Create an Array<T>.  Maps are also available (see the User's guide).
         Array<double> mMyArray = Array<double> ();
      end_script_variables

      // This is an example of how to create a script that is available
      // on the current processor.
      script void PrintPlatformName(WsfPlatform aPlatform)
         // Print name using script argument.
         print("The platform's name is ", aPlatform.Name());

         // Print name using the script variable (declared in Script Variables).
         print("The platform's name is ", mMyPlatform.Name());
      end_script

      // on_initialize is a 'common' script provided by several WSF components
      // (see User's guide for a complete list).  Notice the syntax is different
      // from how regular scripts are declared.
      on_initialize
         print("on_initialize");

         // Add some data to the Array.
         mMyArray.PushBack(1.2);
         mMyArray.PushBack(2.3);
         mMyArray.PushBack(3.4);
      end_on_initialize

      // on_update is a 'common' script provided by several WSF components
      // (see User's guide for a complete list).  Notice the syntax is different
      // from how regular scripts are declared..
      on_update
         print("on_update");

         // Calls to external script must be externed.
         extern void PrintPlatformName(WsfPlatform);
         PrintPlatformName(PLATFORM);

         print("");
         print("Print my member variables");
         print("--- mMyPlatform name = ", mMyPlatform.Name());
         print("--- mMyInt = ", mMyInt);
         print("--- mMyDouble = ", mMyDouble);
         print("--- mMyArray = ");

         // For each loop.  The key loop variable is optional.
         print("Array elements using a foreach with key and data");
         foreach (int key : double data in mMyArray)
         {
            print("---            key, data ", key, ", ", data);
         }
         print("");

         // For each loop without the key.
         print("Array elements using a foreach with data");
         foreach (double data in mMyArray)
         {
            print("---            data ", data);
         }
         print("");

         // You can use an iterator.
         print("Array elements using an iterator");
         ArrayIterator arrayIter = mMyArray.GetIterator();
         while (arrayIter.HasNext())
         {
            double data = (double)arrayIter.Next();
            print("---            key, data ", arrayIter.Key(), ", ", data);
         }
         print("");

         print("Information for ", PLATFORM.Name(), ".", PLATFORM.Type());

         print("  Command Chains");
         for (int i = 0; i < PLATFORM.CommandChainCount(); i = i + 1)
         {
            WsfCommandChain chain = PLATFORM.CommandChainEntry(i);
            print("    ", chain.Name());
            if (chain.Commander().IsValid())
            {
               print("      Commander: ", chain.Commander().Name());
            }
            print("      Peers");
            foreach (WsfPlatform peer in chain.Peers())
            {
               print("          ", peer.Name());
            }
            print("      Subordinates");
            foreach (WsfPlatform subordinate in chain.Subordinates())
            {
               print("          ", subordinate.Name());
            }
         }
         print("  comm Systems");
         for (int i = 0; i < PLATFORM.CommCount(); i = i + 1)
         {
            WsfComm comm = PLATFORM.CommEntry(i);
            print("    ", comm.Name(), "; Type=", comm.Type(),
                  " On=", comm.IsTurnedOn());
         }
         print("  sensor Systems");
         for (int i = 0; i < PLATFORM.SensorCount(); i = i + 1)
         {
            WsfSensor sensor = PLATFORM.SensorEntry(i);
            print("    ", sensor.Name(), "; Type=", sensor.Type(),
                  " On=", sensor.IsTurnedOn());
         }
         print("  Processors");
         for (int i = 0; i < PLATFORM.ProcessorCount(); i = i + 1)
         {
            WsfProcessor processor = PLATFORM.ProcessorEntry(i);
            print("    ", processor.Name(), "; Type=", processor.Type(),
                  " On=", processor.IsTurnedOn(),
                  " UpdateInterval=", processor.UpdateInterval());
         }

         // Disable future calls.
         PROCESSOR.TurnOff();
      end_on_update
   end_processor

end_platform_type

#         1         2         3         4         5         6         7
#234567890123456789012345678901234567890123456789012345678901234567890123456789
################################################################################

platform 737-1 737
   side blue

   command_chain ATC SELF

   route
#     Take off
      position 38:44:52.3n 90:21:36.4w altitude 6 ft agl speed 0 kts
      position 38:45:07.6n 90:22:09.4w altitude 6 ft agl speed 120 kts # climb_rate 1000 fpm

      position 38:49:00n 90:29:00w altitude 15000 ft speed 400 kts
      position 39:29:00n 91:30:00w altitude 35000 ft
      position 38:45:00n 90:06:08w
      position 38:38:24n 90:07:46w altitude 10000 ft speed 250 kts

#     Landing
      position 38:44:52.3n 90:21:36.4w altitude 6 ft agl speed 120 kts
      position 38:45:07.6n 90:22:09.4w altitude 6 ft agl speed 0 kts
   end_route
end_platform

end_time 1200 sec