Skip to content

Oscar Software Framework Manual General Framework API Usage for Oscar

Beat Küng edited this page Jul 16, 2012 · 3 revisions

Go to Table of Contents.

General Framework API Usage for Oscar v2.0 and higher

Following code segment demonstrates framework creation and its usage. For the sake of simplicity, error checking is neglected.

 OscSimInitialize(); /* (2) */
 /************** Do stuff ********************/
 while(1)
 {
     /* main loop */
     Osc<Module1>Do(); /* (3) */
     ...
     Osc<Module2>Do();
     ...
     OscSimStep(); /* (4) */
 }
 /********************************************/
 
 OscDestroy(); /* (5) */
  1. Instantiate the framework with all the desired modules. In this example, the cam and bmp modules have been requested. This will automatically create and set up the framework and modules.
  2. Initialize the Simulation cycle. This is optional and required only if a simulation is required on the host side. If no simulated modules are loaded, this is unnecessary. On the target, this is a void operation.
  3. Enter the main loop of the application. Therein the actual application code resides, which makes use of the methods of loaded modules.
  4. Increment the simulation step. Again, this is optional and used only if a simulation on the host side is required.
  5. Unload the framework and all the modules.

General Framework API Usage for Oscar v1.3 and lower

Following code segment demonstrates framework creation and its usage. For the sake of simplicity, error checking is neglected.

Framework creation with automatic module instantiation:

 OscCreate(&hOsc); /* (1) */
 
 OscLoadDependencies(hOsc, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY)); /* (2) */
 
 OscSimInitialize(); /* (3) */
 /************** Do stuff ********************/
 while(1)
 {
     /* main loop */
     Osc<Module1>Do(); /* (4) */
     ...
     Osc<Module2>Do();
     ...
     OscSimStep(); /* (5) */
 }
 /********************************************/
 
 OscUnloadDependencies(hOsc, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY)); /* (6) */
 
 OscDestroy(hOsc); /* (7) */

As an alternative, the following code segment does the same but with manual module initialization

 OscCreate(&hOsc); /* (1) */
 
 Osc<Module1>Create(hOsc); /* (2) */
 Osc<Module2>Create(hOsc);
 
 OscSimInitialize(); /* (3) */
 /************** Do stuff ********************/
 while(1)
 {
     /* main loop */
     Osc<Module1>Do(); /* (4) */
     ...
     Osc<Module2>Do();
     ...
     OscSimStep(); /* (5) */
 }
 /********************************************/
 Osc<Module2>Destroy(hOsc); /* (6) */
 Osc<Module1>Destroy(hOsc);
 
 OscDestroy(hOsc); /* (7) */ 
  1. Instantiate the framework. This will return a void * as a handle to the framework to be used in subsequent calls to the framework.
  2. Load the modules needed by that application. Every module features a Create() method which must be called prior to use and a Destroy() method which must be called prior to destroying the framework.
  3. Initialize the Simulation cycle. This is optional and required only if a simulation is required on the host side. If no simulated modules are loaded, this is unnecessary. On the target, this is a void operation.
  4. Enter the main loop of the application. Therein the actual application code resides, which makes use of the methods of loaded modules.
  5. Increment the simulation step. Again, this is optional and used only if a simulation on the host side is required.
  6. Unload the modules prior to unloading the framework by calling their Destroy() method.
  7. Unload the framework.
Clone this wiki locally