Functions
in Class Base.Add [Go To Top]
|
/*
Base_Add.c
* - DLL routines for class <Component>Base.Add
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xEval_Base_Add;
#ifdef
__cplusplus
}
#endif
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_Add(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */ |
INT i;
FLOAT fSum = 0.0f;
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */ |
/* sum up all the values from input links */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
fSum +=
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
}
/* Deposit the resulting value to all the output links */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = fSum;
}
|
return SG_R_OK;
} |
Function
in Class Base.Subtract [Go To
Top] |
/*
Base_Subtract.c
* - DLL routines for class <Component>Base.Subtract
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include <string.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xEval_Base_Subtract;
#ifdef
__cplusplus
}
#endif
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_Subtract(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */ |
INT i;
FLOAT fResult = 0.0f;
BOOL bFoundPort0 = FALSE;
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */ |
/* go through input ports */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[1]
== 0)
{ /* port 0 for the subtraction operator */
bFoundPort0 = TRUE;
fResult += lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
}
else
{ /* other input ports, just subtract */
fResult -= lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
}
}
}
/* Deposit the resulting value to all the output links */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = fResult;
}
if (!bFoundPort0)
{
strcpy(cMessage, "Warning:
Port 0 is not connected, 0.0 is used.");
return SG_R_PAUS;
}
|
return SG_R_OK;
} |
Function
in Class Base.Multiply [Go To
Top] |
/*
Base_Multiply.c
* - DLL routines for class <Component>Base.Multiply
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xEval_Base_Multiply;
#ifdef
__cplusplus
}
#endif
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_Multiply(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
FLOAT fProduct = 1.0f;
BOOL bReassigned = FALSE;
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */ |
/* multiply all the values from input links */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
{
fProduct *= lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
bReassigned = TRUE;
}
}
/* Deposit the resulting value to all the output links */
if (bReassigned)
{
for (i = 0; i < *piLnkObjs;
i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = fProduct;
}
}
|
return SG_R_OK;
}
|
Function
in Class Base.Divide [Go To Top] |
/*
Base_Divide.c
* - DLL routines for class <Component>Base.Divide
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include <string.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xEval_Base_Divide;
#ifdef
__cplusplus
}
#endif
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_Divide(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
FLOAT fResult = 1.0;
BOOL bFoundPort0 = FALSE;
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */ |
/* go through input ports */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
{
FLOAT
fInput = lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[1]
== 0)
{ /* port 0 for the division operator */
bFoundPort0 = TRUE;
fResult *= fInput;
}
else if
(fInput != 0.0f)
{ /* other input ports, just divide */
fResult /= fInput;
}
else
{
strcpy(cMessage, "Error: divided by 0.0");
return SG_R_STOP;
}
}
}
/* dividend connected at port 0 is required */
if (!bFoundPort0)
{
strcpy(cMessage, "Error:
need a dividend connected at Port 0");
return SG_R_STOP;
}
/* Deposit the resulting value to all the output links */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = fResult;
}
|
return SG_R_OK;
}
|
Function
in Class Base.Negate [Go To Top] |
/*
Base_Negate.c
* - DLL routines for class <Component>Base.Negate
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xEval_Base_Negate;
#ifdef
__cplusplus
}
#endif
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_Negate(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
FLOAT fValue;
BOOL bReassigned = FALSE;
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */
|
/* take input value, should have at most one link */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
{
fValue
= lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
fValue
= -fValue; /* negate operation */
bReassigned = TRUE;
break; /* Connectivity rule limits to one input link */
}
}
/* Deposit the resulting value to all the output links, if any */
if (bReassigned)
{
for (i = 0; i < *piLnkObjs;
i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = fValue;
}
}
|
return SG_R_OK;
}
|
Function
in Class Base.SquareRoot [Go To
Top] |
/*
Base_SquareRoot.c
* - DLL routines for class <Component>Base.SquareRoot
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include <math.h>
#include <string.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xEval_Base_SquareRoot;
#ifdef
__cplusplus
}
#endif
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_SquareRoot(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
FLOAT fValue;
BOOL bReassigned = FALSE;
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */
|
/* take input value, should have at most one link */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
{
fValue
= lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
if (fValue
< 0.0f)
{
strcpy(cMessage,
"Input for square root function cannot be less than 0.");
return SG_R_STOP; /* range error, stop */
}
fValue
= (FLOAT)sqrt((DOUBLE)fValue); /* square root operation */
bReassigned = TRUE;
break; /* Connectivity rule limits to one input link */
}
}
/* Deposit the resulting value to all the output links, if any */
if (bReassigned)
{
for (i = 0; i < *piLnkObjs;
i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = fValue;
}
}
|
return SG_R_OK;
}
|
Function
in Class Base.SineGen [Go To
Top] |
/*
Base_SineGen.c
* - DLL routines for class <Component>Base.SineGen
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include <math.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xEval_Base_SineGen;
#ifdef
__cplusplus
}
#endif
/*
Macros for attribute indices in class version [1.0.0.0] */
#define SG_NDX_FANGLE 0 /*
fAngle - Current Angle */
#define SG_NDX_FDELTA 1 /*
fDelta - Angle Increment */
#define SG_NDX_FDAMP
2 /* fDamp - Damping
Factor */
#define SG_NDX_IPERIOD 3 /*
iPeriod - Period Register */
|
#define PI2 (6.283185f)
|
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_SineGen(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
INT *piPeriod = &self->zValues[SG_NDX_IPERIOD].iData[0];
const FLOAT cfDelta = self->zValues[SG_NDX_FDELTA].fData[0];
const FLOAT cfDamp = self->zValues[SG_NDX_FDAMP].fData[0];
FLOAT *pfAngle = &self->zValues[SG_NDX_FANGLE].fData[0];
FLOAT fCurrAngle;
FLOAT fCurrFac;
FLOAT fNextFac;
FLOAT fValue;
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */
|
*pfAngle += cfDelta;
*piPeriod = (INT)(*pfAngle / PI2);
fCurrAngle = *pfAngle - (*piPeriod * PI2);
fValue = (FLOAT)sin((DOUBLE)fCurrAngle);
// calculate damping, if necessary
if (cfDamp > 0.0f)
{
fCurrFac = (FLOAT)pow((DOUBLE)(1.0f
- cfDamp), (DOUBLE)*piPeriod);
fNextFac = fCurrFac * (1.0f -
cfDamp); /* next period */
fValue *= ((fCurrFac - fNextFac)
* (PI2 - fCurrAngle) / PI2 + fNextFac);
}
// place the value in all output links
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = fValue;
}
|
return SG_R_OK;
}
|
Functions in Class
Base.Constant [Go To Top]
|
/*
Base_Constant.c
* - DLL routines for class <Component>Base.Constant
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xBgnRun_Base_Constant;
#ifdef
__cplusplus
}
#endif
/*
Macros for attribute indices in class version [1.1.0.0] */
#define SG_NDX_FVALUE 0 /* fValue - Value */
/*
============================================================
* SG_xBgnRun - Begin Run
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xBgnRun_Base_Constant(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
FLOAT *pfValue = &self->zValues[SG_NDX_FVALUE].fData[0];
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */
|
/* Deposit the constant value to all the output links, if any */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = *pfValue;
}
|
return SG_R_OK;
}
|
Functions
in Class Base.Variable [Go To
Top] |
/*
Base_Variable.c
* - DLL routines for class <Component>Base.Variable
* DATE: Sunday, April 21, 2002 TIME: 11:47:43 AM
* The skeleton of this file is generated by SansGUI(tm)
*/
#include
<stdio.h>
#include "SGdll.h"
|
#include
"../Calc_1_1/Calc.h"
|
#ifdef
__cplusplus
extern "C"
{
#endif
SG_EXPORT
SG_SIM_FUNC SG_xInit_Base_Variable;
SG_EXPORT SG_SIM_FUNC SG_xEval_Base_Variable;
#ifdef
__cplusplus
}
#endif
/*
Macros for attribute indices in class version [1.0.0.0] */
#define SG_NDX_FVALUE 0 /* fValue - Variable Value */
/*
============================================================
* SG_xInit - Initialization
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xInit_Base_Variable(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
FLOAT *pfValue = &self->zValues[SG_NDX_FVALUE].fData[0];
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */
|
/* Deposit the current value to all input link, if exists */
/* This is to avoid the initial value from being wiped
off */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
{
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = *pfValue;
break; /* there should only be one input link */
}
}
|
return
SG_R_OK;
}
/*
============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Base_Variable(SG_OBJ *const self,
SG_OBJ *const
simCtrl, SG_OBJ *const chgChild,
SG_OBJ *const
refObjs[], const INT *const piRefObjs,
SG_OBJ *const
adjObjs[], const INT *const piAdjObjs,
SG_OBJ *const
lnkObjs[], const INT *const piLnkObjs,
TCHAR *const
cMessage, const INT iMsgLen,
TCHAR *const
cCommand, const INT iCmdLen,
SG_FILE *const
pOutFile )
{
/* TODO: declare your local variables here */
|
INT i;
FLOAT *pfValue = &self->zValues[SG_NDX_FVALUE].fData[0];
|
if (!SG_IsSchemaOK(self->nSGobjSchema))
return SG_R_SCHM;
/* TODO: put your simulator code here */
|
/* take input value, should have at most one link */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_IN)
{
*pfValue
= lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0];
break; /* Connectivity rule limits to one input link */
}
}
/* Deposit the resulting value to all the output links, if any */
for (i = 0; i < *piLnkObjs; i++)
{
if (lnkObjs[i]->zValues[SG_NDX_LNK_IINFO].iData[0]
== SG_LINK_OUT)
lnkObjs[i]->zValues[SG_NDX_LNK_FVALUE].fData[0] = *pfValue;
}
|
return
SG_R_OK;
}
|
Contents of Calc.h File
[Go To Top] |
/*
Calc.h - manually created header file for common definitions
*/
/*
logical type and values */
typedef INT BOOL;
#define FALSE 0
#define TRUE (!FALSE)
/*
manually added indices for link value access */
#define SG_NDX_LNK_IINFO 0 /* link information */
#define SG_NDX_LNK_FVALUE 1 /* link value */
|