Source Code for Project Cool


The following source files, led by gray banners, contain all the class functions needed for Project Cool.  The sections highlighted by a yellow background Color are manually entered.  Code sections with white background color are generated by the SansGUI Source Code Framework.  The source files are compiled into a dynamic linked library to be invoked by SansGUI during simulation runs.

For more details about this example, please read A Tour of SansGUI Examples in the SansGUI Getting Started Guide.

Implementation in C/C++ (MSVC)

Functions in Class Base.CoffeeCup    [Go To Top]

/* Base_CoffeeCup.c
 * - DLL routines for class <Component>Base.CoffeeCup
 * DATE: Monday, May 22, 2000 TIME: 01:37:20 PM
 * The skeleton of this file is generated by SansGUI(tm)
 */

#include <stdio.h>
#include "SGdll.h"

#ifdef __cplusplus
extern "C"
{
#endif

SG_EXPORT SG_SIM_FUNC SG_xEval_Base_CoffeeCup;

#ifdef __cplusplus
}
#endif

/* Macros for attribute indices in class version [1.0.alpha.4] */
#define SG_NDX_FTEMP 0 /* fTemp - Temperature */
#define SG_NDX_FR 1 /* fR - Cooling Constant */

/* Macros added by hand for simCtrl class attribute access */
#define SG_NDX_FDT 9
#define SG_NDX_FROOMT 11

/* ============================================================
 * SG_xEval - Evaluation
 * ------------------------------------------------------------
 */
SG_RET_CODE SG_xEval_Base_CoffeeCup(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 */

    float* pfTemp = &self->zValues[SG_NDX_FTEMP].fData[0];
    const float cfR = self->zValues[SG_NDX_FR].fData[0];

    const float cfDt = simCtrl->zValues[SG_NDX_FDT].fData[0];
    const float cfRoomT = simCtrl->zValues[SG_NDX_FROOMT].fData[0];

    if (!SG_IsSchemaOK(self->nSGobjSchema))
        return SG_R_SCHM;

    /* TODO: put your simulator code here */

    *pfTemp += (-cfR * (*pfTemp - cfRoomT) * cfDt);

    return SG_R_OK;
}

Functions in Class Collection.Clock    [Go To Top]

/* Collection_Clock.c
 * - DLL routines for class <Reference>Collection.Clock
 * DATE: Monday, May 22, 2000 TIME: 01:37:20 PM
 * The skeleton of this file is generated by SansGUI(tm)
 */

#include <stdio.h>
#include "SGdll.h"

#ifdef __cplusplus
extern "C"
{
#endif

SG_EXPORT SG_SIM_FUNC SG_xEval_Collection_Clock;

#ifdef __cplusplus
}
#endif

/* Macros added by hand for simCtrl class attribute access */
#define SG_NDX_FDT 9
#define SG_NDX_FTIME 10

/* ============================================================
* SG_xEval - Evaluation
* ------------------------------------------------------------
*/
SG_RET_CODE SG_xEval_Collection_Clock(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 */

    const float cfDt = simCtrl->zValues[SG_NDX_FDT].fData[0];
    float* pfTime = &simCtrl->zValues[SG_NDX_FTIME].fData[0];

    if (!SG_IsSchemaOK(self->nSGobjSchema))
        return SG_R_SCHM;

    /* TODO: put your simulator code here */

    *pfTime += cfDt;

    return SG_R_OK;
}

 


SansGUI Modeling and Simulation Environment version 1.2

Copyright 2000-2003 ProtoDesign, Inc. All rights reserved.

http://protodesign-inc.com