Supplementing Generated C : Callbacks to Track Model Changes : Callback Example

Callback Example

The following example illustrates the Rational Statemate callback and set commands.

Initially the system time and date are sensed from the operating system and then passed to the Rational Statemate model by using the seti command.

The use of condition callbacks monitor the SOUND_FLAG conditions inside the Rational Statemate model and then call their respective function routine to pass a desired sound file to the sound device driver.

#ifndef m_generic
 
#include “types.h”
#include “all.h”
#include <time.h>
#include <stdio.h>
 
void ext_code_task_a(c_val,c_num)
int c_val;
int c_num;
 
{
if (SOUND_FLAG_A)
{
system(“cat sound_a.au > /dev/audio &”);
}
}
 
void ext_code_task_b(c_val,c_num)
int c_val;
int c_num;
 
 
{
if (SOUND_FLAG_B)
{
system(“cat sound_b.au > /dev/audio &”);
}
}
 
void ext_code_task_c(c_val,c_num)
int c_val;
int c_num;
 
 
{
if (SOUND_FLAG_C)
{
system(“cat sound_c.au > /dev/audio &”);
}
}
 
void ext_code_task_d(c_val,c_num)
int c_val;
int c_num;
 
 
{
if (SOUND_FLAG_D)
{
system(“cat sound_d.au > /dev/audio &”);
}
}
 
void ext_code_task_e(c_val,c_num)
int c_val;
int c_num;
 
 
{
if (SOUND_FLAG_E)
{
system(“cat sound_e.au > /dev/audio &”);
}
}
 
 
void user_init()
 
{
 
struct tm locTime, UTCtime;
time_t ltime;
 
time( &ltime ); /* get system time */
 
locTime = *localtime( &ltime ); /* convert to struct
tm in local time */
UTCtime = *gmtime( &ltime ); /* convert to struct
tm in UTC/GMT */
 
 
/* pass time and date back to statemate model */
 
seti(&BUR_TIME_MINS,locTime.tm_min);
seti(&BUR_TIME_HRS,locTime.tm_hour);
seti(&BUR_TIME_MTH,locTime.tm_mon);
seti(&BUR_TIME_YR,locTime.tm_year);
seti(&BUR_TIME_DATE,locTime.tm_mday);
 
/* monitor sound flag conditions in model */
set_cond_cbk(0,&SOUND_FLAG_A,ext_code_task_a,1);
set_cond_cbk(0,&SOUND_FLAG_B,ext_code_task_b,1);
set_cond_cbk(0,&SOUND_FLAG_C,ext_code_task_c,1);
set_cond_cbk(0,&SOUND_FLAG_D,ext_code_task_d,1);
set_cond_cbk(0,&SOUND_FLAG_E,ext_code_task_e,1);
 
}
void user_quit()
{
}
 
#endif
 
#ifdef m_g_enter_pin
 
static void g_enter_pin_user_init()
{
}
#endif