Mission control example with inlining

This commit is contained in:
Cédric Pasteur 2011-09-14 15:54:34 +02:00
parent 1c43a8b1ac
commit 346b223a94
9 changed files with 1477 additions and 0 deletions

56
examples/MC_inlined/build Executable file
View file

@ -0,0 +1,56 @@
#!/bin/bash
HEPTC=../../heptc
HEPTC_OPTIONS="-flatten"
GCC=gcc
GCC_OPTIONS="-g -O2 -std=c99 -I ../../../lib/c"
VERBOSE=1
interfaces=(mctypes.epi)
ext_libs=(mc_ext.epi mathext.epi)
sources=(mc.ept)
for f in ${interfaces[@]}; do
if [ $VERBOSE ] ; then
echo "**** Compiling interface: $f *******"
fi
$HEPTC $HEPTC_OPTIONS -target c $f
done
for f in ${ext_libs[@]}; do
if [ $VERBOSE ] ; then
echo "**** Compiling external lib: $f *******"
fi
$HEPTC $HEPTC_OPTIONS $f
done
for f in ${sources[@]}; do
if [ $VERBOSE ] ; then
echo "**** Compiling source file: $f *******"
fi
$HEPTC $HEPTC_OPTIONS -target c $f
done
#$HEPTC $HEPTC_OPTIONS -target c -s dv_fighterdebug mc.ept
source_dirs=(mctypes_c mc_c)
other_files=(main.c mathext.c mathext.h mc_ext.c mc_ext.h)
if [ -d _build ]; then
rm -r _build
fi
mkdir _build
cd _build
for f in ${source_dirs[@]}; do
cp ../$f/* .
done
for f in ${other_files[@]}; do
cp ../$f .
done
$GCC $GCC_OPTIONS *.c -o mission_control
cp mission_control ..
cd ..

View file

@ -0,0 +1,14 @@
#include <math.h>
#include "mathext.h"
#define WRAP_FUN_DEF(FNAME, CNAME, TY_IN, TY_OUT) \
void FNAME ## _step(TY_IN a, FNAME ## _out *out) { \
out->o = CNAME(a); \
}
WRAP_FUN_DEF(Mathext__atanr, atan, float, float)
WRAP_FUN_DEF(Mathext__acosr, acos, float, float)
WRAP_FUN_DEF(Mathext__cosr, cos, float, float)
WRAP_FUN_DEF(Mathext__asinr, asin, float, float)
WRAP_FUN_DEF(Mathext__sinr, sin, float, float)
WRAP_FUN_DEF(Mathext__sqrtr, sqrt, float, float)

View file

@ -0,0 +1,17 @@
(* atan() *)
val fun atanr(a : float) returns (o : float)
(* acos() *)
val fun acosr(a : float) returns (o : float)
(* cos() *)
val fun cosr(a : float) returns (o : float)
(* asin() *)
val fun asinr(a : float) returns (o : float)
(* sin() *)
val fun sinr(a : float) returns (o : float)
(* sqrt() *)
val fun sqrtr(a : float) returns (o : float)

View file

@ -0,0 +1,18 @@
#ifndef MATHEXT_H
#define MATHEXT_H
#define WRAP_FUN_DECL(FNAME, TY_IN, TY_OUT) \
typedef struct { \
TY_OUT o; \
} FNAME ## _out; \
\
void FNAME ## _step(TY_IN, FNAME ## _out *)
WRAP_FUN_DECL(Mathext__atanr, float, float);
WRAP_FUN_DECL(Mathext__acosr, float, float);
WRAP_FUN_DECL(Mathext__cosr, float, float);
WRAP_FUN_DECL(Mathext__asinr, float, float);
WRAP_FUN_DECL(Mathext__sinr, float, float);
WRAP_FUN_DECL(Mathext__sqrtr, float, float);
#endif

1039
examples/MC_inlined/mc.ept Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,127 @@
#include <math.h>
#include <stdlib.h>
#include "mc_ext.h"
/*$**************************************
NAME : MC_Tracks_Prio_SortTracks
INPUTS :
InputTrack1 : TMissionTrack
InputTrack2 : TMissionTrack
InputTrack3 : TMissionTrack
InputTrack4 : TMissionTrack
OUPUTS :
OutputTrack1 : TMissionTrack
OutputTrack2 : TMissionTrack
OutputTrack3 : TMissionTrack
OutputTrack4 : TMissionTrack
***************************************$*/
void mc_tracks_prio_sorttracks(
const Mctypes__tmissiontrack *InputTrack1, const Mctypes__tmissiontrack *InputTrack2,
const Mctypes__tmissiontrack *InputTrack3, const Mctypes__tmissiontrack *InputTrack4,
Mc_ext__mc_tracks_prio_sorttracks_out *out)
{
Mctypes__tmissiontrack _LO1_newA = *InputTrack1;
Mctypes__tmissiontrack _LO1_newB = *InputTrack1;
Mctypes__tmissiontrack _LO2_newA = *InputTrack1;
Mctypes__tmissiontrack _LO2_newB = *InputTrack1;
Mctypes__tmissiontrack _LO3_newA = *InputTrack1;
Mctypes__tmissiontrack _LO3_newB = *InputTrack1;
Mctypes__tmissiontrack _LO4_newA = *InputTrack1;
Mctypes__tmissiontrack _LO4_newB = *InputTrack1;
Mctypes__tmissiontrack _LO5_newA = *InputTrack1;
Mctypes__tmissiontrack _LO5_newB = *InputTrack1;
Mctypes__tmissiontrack _LO6_newA = *InputTrack1;
Mctypes__tmissiontrack _LO6_newB = *InputTrack1;
Mctypes__tmissiontrack _LI_A = *InputTrack1;
Mctypes__tmissiontrack _LI_B = *InputTrack2;
Mc_ext__SortBlockPriorities(&_LI_A, &_LI_B, &_LO4_newA, &_LO4_newB);
_LI_A = *InputTrack3;
_LI_B = *InputTrack4;
Mc_ext__SortBlockPriorities(&_LI_A, &_LI_B, &_LO6_newA, &_LO6_newB);
Mc_ext__SortBlockPriorities(&_LO4_newB, &_LO6_newA, &_LO2_newA, &_LO2_newB);
Mc_ext__SortBlockPriorities(&_LO4_newA, &_LO2_newA, &_LO1_newA, &_LO1_newB);
out->OutputTrack1 = _LO1_newA;
Mc_ext__SortBlockPriorities(&_LO2_newB, &_LO6_newB, &_LO5_newA, &_LO5_newB);
Mc_ext__SortBlockPriorities(&_LO1_newB, &_LO5_newA, &_LO3_newA, &_LO3_newB);
out->OutputTrack2 = _LO3_newA;
out->OutputTrack3 = _LO3_newB;
out->OutputTrack4 = _LO5_newB;
}
/* ROLE :,
Sort two mission tracks according to:,
1) their (rate of closing / distance) ratio,
2) target type,
3) detection or not by the Radar */
void Mc_ext__SortBlockPriorities(const Mctypes__tmissiontrack *InputTrackA, const Mctypes__tmissiontrack *InputTrackB, Mctypes__tmissiontrack *OutputTrackA, Mctypes__tmissiontrack *OutputTrackB)
{
bool bInvertTracks = false;
float vrDivDResultTrackA = 0.0;
float vrDivDResultTrackB = 0.0;
vrDivDResultTrackA = Mc_ext__CalculateVrDivD(InputTrackA->m_sr, InputTrackA->m_d);
vrDivDResultTrackB = Mc_ext__CalculateVrDivD(InputTrackB->m_sr, InputTrackB->m_d);
bInvertTracks = (InputTrackA->m_targettype == Mctypes__Ttargettype_unknown);
bInvertTracks = bInvertTracks || !(InputTrackA->m_detectedbyradar);
if ( ( fabs(vrDivDResultTrackA) < 0.0001 ) && ( fabs(vrDivDResultTrackB) < 0.0001 ) ) {
bInvertTracks = bInvertTracks ||
( (InputTrackA->m_detectedbyradar) &&
(InputTrackB->m_detectedbyradar) &&
( InputTrackA->m_d > InputTrackB->m_d ) );
} else {
bInvertTracks = bInvertTracks ||
( (InputTrackA->m_detectedbyradar) &&
(InputTrackB->m_detectedbyradar) &&
(vrDivDResultTrackA < vrDivDResultTrackB) );
}
if (bInvertTracks) {
*OutputTrackA = *InputTrackB;
*OutputTrackB = *InputTrackA;
} else {
*OutputTrackA = *InputTrackA;
*OutputTrackB = *InputTrackB;
}
}
/* ROLE :,
Calculate: result = rate of closing / distance */
float Mc_ext__CalculateVrDivD(const float _I0_Vr, const float _I1_D)
{
bool bDIsNotZero = (_I1_D > 0.1);
if (bDIsNotZero) {
return ( _I0_Vr / _I1_D ) ;
} else {
return ( 0.0 );
}
}
void Mc_ext__rand_step(Mc_ext__rand_out *out)
{
float a = (float)(rand());
float b = (float)RAND_MAX;
out->o = a/b;
}
void Mc_ext__int_of_float_step(float a, Mc_ext__int_of_float_out *out)
{
out->o = (int) a;
}
void Mc_ext__float_of_int_step(int a, Mc_ext__float_of_int_out *out)
{
out->o = (float) a;
}

View file

@ -0,0 +1,14 @@
(* compute each detected track priority, and sort tracks
according to their priority *)
val fun mc_tracks_prio_sorttracks(inputtrack1 : Mctypes.tmissiontrack;
inputtrack2 : Mctypes.tmissiontrack;
inputtrack3 : Mctypes.tmissiontrack;
inputtrack4 : Mctypes.tmissiontrack)
returns (outputtrack1 : Mctypes.tmissiontrack;
outputtrack2 : Mctypes.tmissiontrack;
outputtrack3 : Mctypes.tmissiontrack;
outputtrack4 : Mctypes.tmissiontrack)
val fun int_of_float(a:float) returns (o:int)
val fun float_of_int(a:int) returns (o:float)
val fun rand() returns (o : float)

View file

@ -0,0 +1,48 @@
#ifndef MC_EXT_H
#define MC_EXT_H
#include "mctypes.h"
typedef struct Mc_ext__mc_tracks_prio_sorttracks_out {
Mctypes__tmissiontrack OutputTrack1;
Mctypes__tmissiontrack OutputTrack2;
Mctypes__tmissiontrack OutputTrack3;
Mctypes__tmissiontrack OutputTrack4;
} Mc_ext__mc_tracks_prio_sorttracks_out;
/* =============== */
/* CYCLIC FUNCTION */
/* =============== */
void Mc_ext__mc_tracks_prio_sorttracks(
const Mctypes__tmissiontrack *InputTrack1, const Mctypes__tmissiontrack *InputTrack2,
const Mctypes__tmissiontrack *InputTrack3, const Mctypes__tmissiontrack *InputTrack4,
Mc_ext__mc_tracks_prio_sorttracks_out *out);
void Mc_ext__SortBlockPriorities(const Mctypes__tmissiontrack *InputTrackA, const Mctypes__tmissiontrack *InputTrackB, Mctypes__tmissiontrack *OutputTrackA, Mctypes__tmissiontrack *OutputTrackB);
float Mc_ext__CalculateVrDivD(const float _I0_Vr, const float _I1_D);
/* rand() */
typedef struct {
float o;
} Mc_ext__rand_out;
void Mc_ext__rand_step(Mc_ext__rand_out *out);
/* int_of_float */
typedef struct {
int o;
} Mc_ext__int_of_float_out;
void Mc_ext__int_of_float_step(float a, Mc_ext__int_of_float_out *out);
/* float_of_int */
typedef struct {
float o;
} Mc_ext__float_of_int_out;
void Mc_ext__float_of_int_step(int a, Mc_ext__float_of_int_out *out);
#endif

View file

@ -0,0 +1,144 @@
type tid = int
type tpriority_v = int
type tmetres = float
type tmetresseconde = float
type tposition = { x : tmetres; y : tmetres }
type tspeed = { sx : tmetresseconde; sy : tmetresseconde }
type ttargettype = Ttargettype_unknown | Ttargettype_friend | Ttargettype_foe
type trdrtrack = {
r_pos : tposition;
r_s : tspeed;
r_d : tmetres;
r_sabs : tmetresseconde;
r_sr : tmetresseconde
}
type tifftrack = { i_pos : tposition; i_id : tid }
type ttrack = { t_pos : tposition; t_id : tid }
type tmissiontrack = {
m_pos : tposition;
m_speed : tspeed;
m_id : tid;
m_priority : tpriority_v;
m_d : tmetres;
m_sabs : tmetresseconde;
m_sr : tmetresseconde;
m_detectedbyradar : bool;
m_detectedbyiff : bool;
m_tracknumber : int;
m_targettype : ttargettype;
m_isvisible : bool;
m_angle : float
}
const ksizetracksarray : int = 10
const ksizeifftracksarray : int = 3
const ksizerdrtracksarray : int = 5
const ksizemissiontracksarray : int =
ksizeifftracksarray + ksizerdrtracksarray
type trdrtracksarray = trdrtrack^ksizerdrtracksarray
type tifftracksarray = tifftrack^ksizeifftracksarray
type tdetectedifftracksarray = int^ksizeifftracksarray
type tdetectedrdrtracksarray = int^ksizerdrtracksarray
type ttracksarray = ttrack^ksizetracksarray
type tmissiontracksarray = tmissiontrack^ksizemissiontracksarray
const kinitifftrackarray : tifftracksarray =
{ i_pos = { x = 0.0; y = 0.0 }; i_id = 0 } ^ ksizeifftracksarray
const kinitmissiontrackarray : tmissiontracksarray =
{ m_pos = { x = 0.0;
y = 0.0 };
m_speed = { sx = 0.0;
sy = 0.0 };
m_id = 0;
m_priority = 0;
m_d = 0.0;
m_sabs = 0.0;
m_sr = 0.0;
m_detectedbyradar = false;
m_detectedbyiff = false;
m_tracknumber = 0;
m_targettype = Ttargettype_unknown;
m_isvisible = false;
m_angle = 0.0 } ^ ksizemissiontracksarray
const kinitrdrtrackarray : trdrtracksarray =
{ r_pos = { x = 0.0;
y = 0.0 };
r_s = { sx = 0.0;
sy = 0.0 };
r_d = 0.0;
r_sabs = 0.0;
r_sr = 0.0 } ^ ksizerdrtracksarray
const kinittrackarray : ttracksarray =
{ t_pos = { x = 0.0; y = 0.0 }; t_id = 0 } ^ ksizetracksarray
const kInitPosition : tposition = { x = 0.0; y = 0.0 }
const kInitSpeed : tspeed = { sx = 0.0; sy = 0.0 }
const nm : float = 1852.0
const t : float = 0.01
const pi : float = 3.141592
const kinittrack : ttrack = { t_pos = { x = 0.0;
y = 0.0 };
t_id = 0 }
const kinitrdrtrack : trdrtrack = { r_pos = { x = 0.0;
y = 0.0 };
r_s = { sx = 0.0;
sy = 0.0 };
r_d = 0.0;
r_sabs = 0.0;
r_sr = 0.0 }
const kinitmissiontrack : tmissiontrack = { m_pos = { x = 0.0;
y = 0.0 };
m_speed = { sx = 0.0;
sy = 0.0 };
m_id = 0;
m_priority = 0;
m_d = 0.0;
m_sabs = 0.0;
m_sr = 0.0;
m_detectedbyradar = false;
m_detectedbyiff = false;
m_tracknumber = 0;
m_targettype = Ttargettype_unknown;
m_isvisible = false;
m_angle = 0.0 }
const kinitifftrack : tifftrack = { i_pos = { x = 0.0;
y = 0.0 };
i_id = 0 }
type tinputspanel = {
p_slope : float;
p_speed : float;
p_id : int;
p_x0 : float;
p_y0 : float;
p_reset : bool
}
type tinputspanelarray = tinputspanel^4
type tpriority = { missionTrackIndex : int; trackNumber : int }
(* TrackNumbers of the tracks with highest priority,
sorted from the highest priority *)
type tpriorityList = int^4
type trdrmode = TRdrMode_WIDE | TRdrMode_NARROW
type tsensorstate = TState_OFF | TState_ON | TState_FAIL