Made the Scade example compile in C
This commit is contained in:
parent
4cd506f3db
commit
f3e9d738a0
7 changed files with 116 additions and 83 deletions
|
@ -1,6 +1,10 @@
|
|||
#!/bin/bash
|
||||
HEPTC=../../compiler/heptc.byte
|
||||
HEPTC_OPTIONS=
|
||||
|
||||
GCC=gcc
|
||||
GCC_OPTIONS="-std=c99 -I ../../../lib/c"
|
||||
|
||||
VERBOSE=1
|
||||
|
||||
interfaces=(typeBase.epi typeTracks.epi typeArray.epi cstArrayInit.epi cstBaseInit.epi cstPhysics.epi cstTracksInit.epi mc_TypeInputs.epi mc_TypeLists.epi mc_TypeSensors.epi)
|
||||
|
@ -11,19 +15,38 @@ for f in ${interfaces[@]}; do
|
|||
if [ $VERBOSE ] ; then
|
||||
echo "**** Compiling interface: $f *******"
|
||||
fi
|
||||
$HEPTC $f
|
||||
$HEPTC $HEPTC_OPTIONS -target c $f
|
||||
done
|
||||
|
||||
for f in ${ext_libs[@]}; do
|
||||
if [ $VERBOSE ] ; then
|
||||
echo "**** Compiling external lib: $f *******"
|
||||
fi
|
||||
$HEPTC $f
|
||||
$HEPTC $HEPTC_OPTIONS $f
|
||||
done
|
||||
|
||||
for f in ${sources[@]}; do
|
||||
if [ $VERBOSE ] ; then
|
||||
echo "**** Compiling source file: $f *******"
|
||||
fi
|
||||
$HEPTC -target c $f
|
||||
$HEPTC $HEPTC_OPTIONS -target c $f
|
||||
done
|
||||
|
||||
source_dirs=(debug_c dv_c digital_c math_c mc_c trackslib_c verif_c typeBase_c typeTracks_c typeArray_c cstArrayInit_c cstBaseInit_c cstPhysics_c cstTracksInit_c mc_TypeInputs_c mc_TypeLists_c mc_TypeSensors_c)
|
||||
other_files=(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
|
||||
|
||||
cd ..
|
|
@ -6,9 +6,9 @@
|
|||
out->o = CNAME(a); \
|
||||
}
|
||||
|
||||
WRAP_FUN_DEF(atanr, atan, float, float)
|
||||
WRAP_FUN_DEF(acosr, acos, float, float)
|
||||
WRAP_FUN_DEF(cosr, cos, float, float)
|
||||
WRAP_FUN_DEF(asinr, asin, float, float)
|
||||
WRAP_FUN_DEF(sinr, sin, float, float)
|
||||
WRAP_FUN_DEF(sqrtr, sqrt, float, float)
|
||||
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)
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
\
|
||||
void FNAME ## _step(TY_IN, FNAME ## _out *)
|
||||
|
||||
WRAP_FUN_DECL(atanr, float, float);
|
||||
WRAP_FUN_DECL(acosr, float, float);
|
||||
WRAP_FUN_DECL(cosr, float, float);
|
||||
WRAP_FUN_DECL(asinr, float, float);
|
||||
WRAP_FUN_DECL(sinr, float, float);
|
||||
WRAP_FUN_DECL(sqrtr, float, float);
|
||||
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
|
||||
|
|
|
@ -17,41 +17,41 @@ OutputTrack4 : TMissionTrack
|
|||
***************************************$*/
|
||||
|
||||
void mc_tracks_prio_sorttracks(
|
||||
const TMissionTrack *InputTrack1, const TMissionTrack *InputTrack2,
|
||||
const TMissionTrack *InputTrack3, const TMissionTrack *InputTrack4,
|
||||
mc_tracks_prio_sorttracks_out *out)
|
||||
const TypeTracks__tmissiontrack *InputTrack1, const TypeTracks__tmissiontrack *InputTrack2,
|
||||
const TypeTracks__tmissiontrack *InputTrack3, const TypeTracks__tmissiontrack *InputTrack4,
|
||||
Mc_ext__mc_tracks_prio_sorttracks_out *out)
|
||||
{
|
||||
TMissionTrack _LO1_newA = *InputTrack1;
|
||||
TMissionTrack _LO1_newB = *InputTrack1;
|
||||
TMissionTrack _LO2_newA = *InputTrack1;
|
||||
TMissionTrack _LO2_newB = *InputTrack1;
|
||||
TMissionTrack _LO3_newA = *InputTrack1;
|
||||
TMissionTrack _LO3_newB = *InputTrack1;
|
||||
TMissionTrack _LO4_newA = *InputTrack1;
|
||||
TMissionTrack _LO4_newB = *InputTrack1;
|
||||
TMissionTrack _LO5_newA = *InputTrack1;
|
||||
TMissionTrack _LO5_newB = *InputTrack1;
|
||||
TMissionTrack _LO6_newA = *InputTrack1;
|
||||
TMissionTrack _LO6_newB = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO1_newA = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO1_newB = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO2_newA = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO2_newB = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO3_newA = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO3_newB = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO4_newA = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO4_newB = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO5_newA = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO5_newB = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO6_newA = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LO6_newB = *InputTrack1;
|
||||
|
||||
TMissionTrack _LI_A = *InputTrack1;
|
||||
TMissionTrack _LI_B = *InputTrack2;
|
||||
TypeTracks__tmissiontrack _LI_A = *InputTrack1;
|
||||
TypeTracks__tmissiontrack _LI_B = *InputTrack2;
|
||||
|
||||
SortBlockPriorities(&_LI_A, &_LI_B, &_LO4_newA, &_LO4_newB);
|
||||
Mc_ext__SortBlockPriorities(&_LI_A, &_LI_B, &_LO4_newA, &_LO4_newB);
|
||||
|
||||
_LI_A = *InputTrack3;
|
||||
_LI_B = *InputTrack4;
|
||||
SortBlockPriorities(&_LI_A, &_LI_B, &_LO6_newA, &_LO6_newB);
|
||||
Mc_ext__SortBlockPriorities(&_LI_A, &_LI_B, &_LO6_newA, &_LO6_newB);
|
||||
|
||||
SortBlockPriorities(&_LO4_newB, &_LO6_newA, &_LO2_newA, &_LO2_newB);
|
||||
Mc_ext__SortBlockPriorities(&_LO4_newB, &_LO6_newA, &_LO2_newA, &_LO2_newB);
|
||||
|
||||
SortBlockPriorities(&_LO4_newA, &_LO2_newA, &_LO1_newA, &_LO1_newB);
|
||||
Mc_ext__SortBlockPriorities(&_LO4_newA, &_LO2_newA, &_LO1_newA, &_LO1_newB);
|
||||
|
||||
out->OutputTrack1 = _LO1_newA;
|
||||
|
||||
SortBlockPriorities(&_LO2_newB, &_LO6_newB, &_LO5_newA, &_LO5_newB);
|
||||
Mc_ext__SortBlockPriorities(&_LO2_newB, &_LO6_newB, &_LO5_newA, &_LO5_newB);
|
||||
|
||||
SortBlockPriorities(&_LO1_newB, &_LO5_newA, &_LO3_newA, &_LO3_newB);
|
||||
Mc_ext__SortBlockPriorities(&_LO1_newB, &_LO5_newA, &_LO3_newA, &_LO3_newB);
|
||||
|
||||
out->OutputTrack2 = _LO3_newA;
|
||||
out->OutputTrack3 = _LO3_newB;
|
||||
|
@ -63,27 +63,27 @@ Sort two mission tracks according to:,
|
|||
1) their (rate of closing / distance) ratio,
|
||||
2) target type,
|
||||
3) detection or not by the Radar */
|
||||
void SortBlockPriorities(const TMissionTrack *InputTrackA, const TMissionTrack *InputTrackB, TMissionTrack *OutputTrackA, TMissionTrack *OutputTrackB)
|
||||
void Mc_ext__SortBlockPriorities(const TypeTracks__tmissiontrack *InputTrackA, const TypeTracks__tmissiontrack *InputTrackB, TypeTracks__tmissiontrack *OutputTrackA, TypeTracks__tmissiontrack *OutputTrackB)
|
||||
{
|
||||
bool bInvertTracks = false;
|
||||
real vrDivDResultTrackA = 0.0;
|
||||
real vrDivDResultTrackB = 0.0;
|
||||
float vrDivDResultTrackA = 0.0;
|
||||
float vrDivDResultTrackB = 0.0;
|
||||
|
||||
vrDivDResultTrackA = CalculateVrDivD(InputTrackA->Vr, InputTrackA->D);
|
||||
vrDivDResultTrackB = CalculateVrDivD(InputTrackB->Vr, InputTrackB->D);
|
||||
vrDivDResultTrackA = Mc_ext__CalculateVrDivD(InputTrackA->m_sr, InputTrackA->m_d);
|
||||
vrDivDResultTrackB = Mc_ext__CalculateVrDivD(InputTrackB->m_sr, InputTrackB->m_d);
|
||||
|
||||
bInvertTracks = (InputTrackA->targetType == TTargetType_FRIEND);
|
||||
bInvertTracks = bInvertTracks || !(InputTrackA->detectedByRadar);
|
||||
bInvertTracks = (InputTrackA->m_targettype == TypeBase__Ttargettype_unknown);
|
||||
bInvertTracks = bInvertTracks || !(InputTrackA->m_detectedbyradar);
|
||||
if ( ( fabs(vrDivDResultTrackA) < 0.0001 ) && ( fabs(vrDivDResultTrackB) < 0.0001 ) ) {
|
||||
bInvertTracks = bInvertTracks ||
|
||||
( (InputTrackA->detectedByRadar) &&
|
||||
(InputTrackB->detectedByRadar) &&
|
||||
( InputTrackA->D > InputTrackB->D ) );
|
||||
( (InputTrackA->m_detectedbyradar) &&
|
||||
(InputTrackB->m_detectedbyradar) &&
|
||||
( InputTrackA->m_d > InputTrackB->m_d ) );
|
||||
|
||||
} else {
|
||||
bInvertTracks = bInvertTracks ||
|
||||
( (InputTrackA->detectedByRadar) &&
|
||||
(InputTrackB->detectedByRadar) &&
|
||||
( (InputTrackA->m_detectedbyradar) &&
|
||||
(InputTrackB->m_detectedbyradar) &&
|
||||
(vrDivDResultTrackA < vrDivDResultTrackB) );
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ void SortBlockPriorities(const TMissionTrack *InputTrackA, const TMissionTrack *
|
|||
|
||||
/* ROLE :,
|
||||
Calculate: result = rate of closing / distance */
|
||||
real CalculateVrDivD(const float _I0_Vr, const float _I1_D)
|
||||
float Mc_ext__CalculateVrDivD(const float _I0_Vr, const float _I1_D)
|
||||
{
|
||||
bool bDIsNotZero = (_I1_D > 0.1);
|
||||
|
||||
|
@ -109,19 +109,19 @@ real CalculateVrDivD(const float _I0_Vr, const float _I1_D)
|
|||
}
|
||||
}
|
||||
|
||||
void rand_step(rand_out *out)
|
||||
void Mc_ext__rand_step(Mc_ext__rand_out *out)
|
||||
{
|
||||
float a = (float)(rand());
|
||||
kcg_real b = (float)RAND_MAX;
|
||||
float b = (float)RAND_MAX;
|
||||
out->o = a/b;
|
||||
}
|
||||
|
||||
void int_of_float_step(float a, int_of_float_out *out)
|
||||
void Mc_ext__int_of_float_step(float a, Mc_ext__int_of_float_out *out)
|
||||
{
|
||||
return (int) a;
|
||||
out->o = (int) a;
|
||||
}
|
||||
|
||||
void float_of_int_step(int a, int_of_float_out *out)
|
||||
void Mc_ext__float_of_int_step(int a, Mc_ext__float_of_int_out *out)
|
||||
{
|
||||
return (float) a;
|
||||
out->o = (float) a;
|
||||
}
|
||||
|
|
|
@ -11,4 +11,4 @@ val fun mc_tracks_prio_sorttracks(inputtrack1 : TypeTracks.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 (output1 : float)
|
||||
val fun rand() returns (o : float)
|
|
@ -1,48 +1,48 @@
|
|||
#ifndef MC_EXT_H
|
||||
#define MC_EXT_H
|
||||
|
||||
#include "typeArray_types.h"
|
||||
#include "typeArray.h"
|
||||
|
||||
typedef struct mc_tracks_prio_sorttracks_out {
|
||||
TMissionTrack OutputTrack1;
|
||||
TMissionTrack OutputTrack2;
|
||||
TMissionTrack OutputTrack3;
|
||||
TMissionTrack OutputTrack4;
|
||||
} mc_tracks_prio_sorttracks_out;
|
||||
typedef struct Mc_ext__mc_tracks_prio_sorttracks_out {
|
||||
TypeTracks__tmissiontrack OutputTrack1;
|
||||
TypeTracks__tmissiontrack OutputTrack2;
|
||||
TypeTracks__tmissiontrack OutputTrack3;
|
||||
TypeTracks__tmissiontrack OutputTrack4;
|
||||
} Mc_ext__mc_tracks_prio_sorttracks_out;
|
||||
|
||||
/* =============== */
|
||||
/* CYCLIC FUNCTION */
|
||||
/* =============== */
|
||||
void mc_tracks_prio_sorttracks(
|
||||
const TMissionTrack *InputTrack1, const TMissionTrack *InputTrack2,
|
||||
const TMissionTrack *InputTrack3, const TMissionTrack *InputTrack4,
|
||||
mc_tracks_prio_sorttracks_out *out);
|
||||
void Mc_ext__mc_tracks_prio_sorttracks(
|
||||
const TypeTracks__tmissiontrack *InputTrack1, const TypeTracks__tmissiontrack *InputTrack2,
|
||||
const TypeTracks__tmissiontrack *InputTrack3, const TypeTracks__tmissiontrack *InputTrack4,
|
||||
Mc_ext__mc_tracks_prio_sorttracks_out *out);
|
||||
|
||||
void SortBlockPriorities(const TMissionTrack *InputTrackA, const TMissionTrack *InputTrackB, TMissionTrack *OutputTrackA, TMissionTrack *OutputTrackB);
|
||||
void Mc_ext__SortBlockPriorities(const TypeTracks__tmissiontrack *InputTrackA, const TypeTracks__tmissiontrack *InputTrackB, TypeTracks__tmissiontrack *OutputTrackA, TypeTracks__tmissiontrack *OutputTrackB);
|
||||
|
||||
real CalculateVrDivD(const float _I0_Vr, const float _I1_D);
|
||||
float Mc_ext__CalculateVrDivD(const float _I0_Vr, const float _I1_D);
|
||||
|
||||
|
||||
/* rand() */
|
||||
typedef struct {
|
||||
float o;
|
||||
} rand_out;
|
||||
} Mc_ext__rand_out;
|
||||
|
||||
void rand_step(rand_out *out);
|
||||
void Mc_ext__rand_step(Mc_ext__rand_out *out);
|
||||
|
||||
/* int_of_float */
|
||||
typedef struct {
|
||||
int o;
|
||||
} int_of_float_out;
|
||||
} Mc_ext__int_of_float_out;
|
||||
|
||||
void int_of_float_step(float a, int_of_float_out *out);
|
||||
void Mc_ext__int_of_float_step(float a, Mc_ext__int_of_float_out *out);
|
||||
|
||||
/* float_of_int */
|
||||
typedef struct {
|
||||
float o;
|
||||
} float_of_int_out;
|
||||
} Mc_ext__float_of_int_out;
|
||||
|
||||
void float_of_int_step(int a, float_of_int_out *out);
|
||||
void Mc_ext__float_of_int_step(int a, Mc_ext__float_of_int_out *out);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -247,12 +247,12 @@ tel
|
|||
|
||||
(* calculate the derivative of a value x(n) according to its
|
||||
ante-previous value x(n-2) *)
|
||||
node myderivative(inv, period : float) returns (out : float)
|
||||
node myderivative(inv, period : float) returns (o : float)
|
||||
var l2 : float;
|
||||
let
|
||||
(* l2 = fby (inv; 2; 0.0); *)
|
||||
l2 = 0.0 fby (0.0 fby inv);
|
||||
out =
|
||||
o =
|
||||
if Math.abs(l2) <. 0.1 or Math.abs(inv) <. 0.1
|
||||
then 0.0
|
||||
else 0.0 -> (inv -. l2) /. (2.0 *. period);
|
||||
|
@ -310,6 +310,16 @@ let
|
|||
newa = if l25 then b else a;
|
||||
tel
|
||||
|
||||
fun position_equal(p1, p2 : TypeBase.tposition) returns (res:bool)
|
||||
let
|
||||
res = (p1.x = p2.x) & (p1.y = p2.y)
|
||||
tel
|
||||
|
||||
fun speed_equal(s1, s2 : TypeBase.tspeed) returns (res:bool)
|
||||
let
|
||||
res = (s1.sx = s2.sx) & (s1.sy = s2.sy)
|
||||
tel
|
||||
|
||||
(* convert an iff track (position + identifier) into a mission
|
||||
track (position + speed + distance + rate of closing +
|
||||
detected by radar/iff + tracknumber + target type) *)
|
||||
|
@ -318,7 +328,7 @@ node convertifftracktomissiontrack(ifftrack : TypeTracks.tifftrack)
|
|||
let
|
||||
missiontrack =
|
||||
{ m_pos = ifftrack.i_pos;
|
||||
m_speed = if CstBaseInit.kInitPosition = ifftrack.i_pos
|
||||
m_speed = if position_equal(CstBaseInit.kInitPosition, ifftrack.i_pos)
|
||||
then CstBaseInit.kInitSpeed
|
||||
else calculatetrackspeedfrompos(ifftrack.i_pos);
|
||||
m_id = ifftrack.i_id;
|
||||
|
@ -327,7 +337,7 @@ let
|
|||
m_sabs = 0.0;
|
||||
m_sr = 0.0;
|
||||
m_detectedbyradar = false;
|
||||
m_detectedbyiff = not (ifftrack.i_pos = CstBaseInit.kInitPosition &
|
||||
m_detectedbyiff = not (position_equal(ifftrack.i_pos, CstBaseInit.kInitPosition) &
|
||||
ifftrack.i_id = 0);
|
||||
m_tracknumber = 0;
|
||||
m_targettype = calculatetracktargettypefromid(ifftrack.i_id);
|
||||
|
@ -350,8 +360,8 @@ let
|
|||
m_d = rdrtrack.r_d;
|
||||
m_sabs = rdrtrack.r_sabs;
|
||||
m_sr = rdrtrack.r_sr;
|
||||
m_detectedbyradar = not (rdrtrack.r_pos = CstBaseInit.kInitPosition &
|
||||
rdrtrack.r_s = CstBaseInit.kInitSpeed &
|
||||
m_detectedbyradar = not (position_equal(rdrtrack.r_pos, CstBaseInit.kInitPosition) &
|
||||
speed_equal(rdrtrack.r_s, CstBaseInit.kInitSpeed) &
|
||||
rdrtrack.r_d = 0.0 &
|
||||
rdrtrack.r_sabs = 0.0 &
|
||||
rdrtrack.r_sr = 0.0);
|
||||
|
|
Loading…
Reference in a new issue