Dear All,
Could anyone help me how to fix it? This code not all my sent because too long.
Thank for any help in advance.
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "tmwtypes.h"
#endif
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "rtmodel.h"
#endif
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "rt_sim.c"
#endif
#ifdef USE_RTMODEL
# include "simstruc_types.h"
#else
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "simstruc.h"
#endif
#ifndef RT_MALLOC /* statically declare data */
#endif
/*==========*
* Struct's *
*==========*/
typedef struct TimingData_Tag {
real_T period[NUMST]; /* Task periods in seconds */
real_T offset[NUMST]; /* Task offsets in seconds */
real_T clockTick[NUMST]; /* Flint task time tick counter */
int_T taskTick[NUMST]; /* Counter for determining task hits */
int_T nTaskTicks[NUMST]; /* Number base rate ticks for a task hit */
int_T firstDiscIdx; /* First discrete task index */
} TimingData;
/*=========================*
* Data local to this file *
*=========================*/
static TimingData td;
/*==================*
* Visible routines *
*==================*/
/* Function: rt_SimInitTimingEngine
* Returns:
* NULL - success
* non-NULL - error string
*/
const char *rt_SimInitTimingEngine(int_T rtmNumSampTimes,
real_T rtmStepSize,
real_T *rtmSampleTimePtr,
real_T *rtmOffsetTimePtr,
int_T *rtmSampleHitPtr,
int_T *rtmSampleTimeTaskIDPtr,
real_T rtmTStart,
SimTimeStep *rtmSimTimeStepPtr,
void **rtmTimingDataPtr)
{
int_T i;
int *tsMap = rtmSampleTimeTaskIDPtr;
real_T *period = rtmSampleTimePtr;
real_T *offset = rtmOffsetTimePtr;
int_T *sampleHit = rtmSampleHitPtr;
real_T stepSize = rtmStepSize;
if (rtmTStart != 0.0) {
return("Start time must be zero for real-time systems");
}
*rtmSimTimeStepPtr = MAJOR_TIME_STEP;
*rtmTimingDataPtr = (void*)&td;
for (i = 0; i < NUMST; i++) {
tsMap = i;
td.period = period;
td.offset = offset;
td.nTaskTicks = (int_T)floor(period/stepSize + 0.5);
if (td.period == CONTINUOUS_SAMPLE_TIME ||
td.offset == 0.0) {
td.taskTick = 0;
td.clockTick = 0.0;
sampleHit = 1;
} else {
td.taskTick = (int_T)floor((td.period-td.offset) /
stepSize+0.5);
td.clockTick = -1.0;
sampleHit = 0;
}
}
/* Correct first sample time if continuous task */
td.period[0] = stepSize;
td.nTaskTicks[0] = 1;
/* Set first discrete task index */
#if NUMST == 1
td.firstDiscIdx = (int_T)(period[0] == CONTINUOUS_SAMPLE_TIME);
#else
td.firstDiscIdx = ((int_T)(period[0] == CONTINUOUS_SAMPLE_TIME) +
(int_T)(period[1] == CONTINUOUS_SAMPLE_TIME));
#endif
return(NULL); /* success */
} /* end rt_SimInitTimingEngine */
#if !defined(MULTITASKING)
/* SINGLE TASKING */
/* Function: rt_SimGetNextSampleHit ============================================
* Abstract:
* For a single tasking real-time system, return time of next sample hit.
*/
time_T rt_SimGetNextSampleHit(void)
{
time_T timeOfNextHit;
td.clockTick[0] += 1;
timeOfNextHit = td.clockTick[0] * td.period[0];
# if NUMST > 1
{
int i;
for (i = 1; i < NUMST; i++) {
if (++td.taskTick == td.nTaskTicks) {
td.taskTick = 0;
td.clockTick++;
}
}
}
# endif
return(timeOfNextHit);
} /* end rt_SimGetNextSampleHit */
/* Function: rt_SimUpdateDiscreteTaskSampleHits */
void rt_SimUpdateDiscreteTaskSampleHits(int_T rtmNumSampTimes,
void *rtmTimingData,
int_T *rtmSampleHitPtr,
real_T *rtmTPtr)
{
int_T *sampleHit = rtmSampleHitPtr;
int i;
UNUSED_PARAMETER(rtmTimingData);
UNUSED_PARAMETER(rtmNumSampTimes);
for (i = td.firstDiscIdx; i < NUMST; i++) {
int_T hit = (td.taskTick == 0);
if (hit) {
rttiSetTaskTime(rtmTPtr, i,
td.clockTick*td.period + td.offset);
}
sampleHit = hit;
}
} /* rt_SimUpdateDiscreteTaskSampleHits */
#else /* defined(MULTITASKING) */
/* Function: rt_SimUpdateDiscreteEvents */
time_T rt_SimUpdateDiscreteEvents(int_T rtmNumSampTimes,
void *rtmTimingData,
int_T *rtmSampleHitPtr,
int_T *rtmPerTaskSampleHits)
{
int i, j;
int_T *sampleHit = rtmSampleHitPtr;
UNUSED_PARAMETER(rtmTimingData);
/*
* Run this loop in reverse so that we do lower priority events first.
*/
i = NUMST;
while (--i >= 0) {
if (td.taskTick == 0) {
/*
* Got a sample hit, reset the counter, and update the clock
* tick counter.
*/
sampleHit = 1;
td.clockTick++;
/*
* Record the state of all "slower" events
*/
for (j = i + 1; j < NUMST; j++) {
rttiSetSampleHitInTask(rtmPerTaskSampleHits, rtmNumSampTimes,
j, i, sampleHit[j]);
}
} else {
/*
* no sample hit, increment the counter
*/
sampleHit = 0;
}
if (++td.taskTick == td.nTaskTicks) { /* update for next time */
td.taskTick = 0;
}
}
return(td.clockTick[0]*td.period[0]);
} /* rt_SimUpdateDiscreteEvents */
/* Function: rt_SimUpdateDiscreteTaskTime */
void rt_SimUpdateDiscreteTaskTime(real_T *rtmTPtr,
void *rtmTimingData,
int tid)
{
UNUSED_PARAMETER(rtmTimingData);
rttiSetTaskTime(rtmTPtr, tid,
td.clockTick[tid]*td.period[tid] + td.offset[tid]);
}
#endif /* MULTITASKING */
#else
....
.....
......
c:\matlab6p5\work\denas\rt_sim.c(94) : error C2065: 'NUMST' : undeclared identifier
c:\matlab6p5\work\denas\rt_sim.c(94) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(95) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(95) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(96) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(96) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(97) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(97) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(98) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(98) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(99) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(241) : warning C4013: 'rttiSetTaskTime' undefined; assuming extern returning int
c:\matlab6p5\work\denas\rt_sim.c(376) : fatal error C1019: unexpected #else
Error executing cl.exe.
RV2AJFRONT_NEW.obj - 12 error(s), 1 warning(s)[/SIZE][/SIZE]
Could anyone help me how to fix it? This code not all my sent because too long.
Thank for any help in advance.
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "tmwtypes.h"
#endif
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "rtmodel.h"
#endif
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "rt_sim.c"
#endif
#ifdef USE_RTMODEL
# include "simstruc_types.h"
#else
#ifndef UNIQUE_IDENTIFIER
#define UNIQUE_IDENTIFIER
#if (MSC_VER > 1000)
#pragma once
#endif
#include "simstruc.h"
#endif
#ifndef RT_MALLOC /* statically declare data */
#endif
/*==========*
* Struct's *
*==========*/
typedef struct TimingData_Tag {
real_T period[NUMST]; /* Task periods in seconds */
real_T offset[NUMST]; /* Task offsets in seconds */
real_T clockTick[NUMST]; /* Flint task time tick counter */
int_T taskTick[NUMST]; /* Counter for determining task hits */
int_T nTaskTicks[NUMST]; /* Number base rate ticks for a task hit */
int_T firstDiscIdx; /* First discrete task index */
} TimingData;
/*=========================*
* Data local to this file *
*=========================*/
static TimingData td;
/*==================*
* Visible routines *
*==================*/
/* Function: rt_SimInitTimingEngine
* Returns:
* NULL - success
* non-NULL - error string
*/
const char *rt_SimInitTimingEngine(int_T rtmNumSampTimes,
real_T rtmStepSize,
real_T *rtmSampleTimePtr,
real_T *rtmOffsetTimePtr,
int_T *rtmSampleHitPtr,
int_T *rtmSampleTimeTaskIDPtr,
real_T rtmTStart,
SimTimeStep *rtmSimTimeStepPtr,
void **rtmTimingDataPtr)
{
int_T i;
int *tsMap = rtmSampleTimeTaskIDPtr;
real_T *period = rtmSampleTimePtr;
real_T *offset = rtmOffsetTimePtr;
int_T *sampleHit = rtmSampleHitPtr;
real_T stepSize = rtmStepSize;
if (rtmTStart != 0.0) {
return("Start time must be zero for real-time systems");
}
*rtmSimTimeStepPtr = MAJOR_TIME_STEP;
*rtmTimingDataPtr = (void*)&td;
for (i = 0; i < NUMST; i++) {
tsMap = i;
td.period = period;
td.offset = offset;
td.nTaskTicks = (int_T)floor(period/stepSize + 0.5);
if (td.period == CONTINUOUS_SAMPLE_TIME ||
td.offset == 0.0) {
td.taskTick = 0;
td.clockTick = 0.0;
sampleHit = 1;
} else {
td.taskTick = (int_T)floor((td.period-td.offset) /
stepSize+0.5);
td.clockTick = -1.0;
sampleHit = 0;
}
}
/* Correct first sample time if continuous task */
td.period[0] = stepSize;
td.nTaskTicks[0] = 1;
/* Set first discrete task index */
#if NUMST == 1
td.firstDiscIdx = (int_T)(period[0] == CONTINUOUS_SAMPLE_TIME);
#else
td.firstDiscIdx = ((int_T)(period[0] == CONTINUOUS_SAMPLE_TIME) +
(int_T)(period[1] == CONTINUOUS_SAMPLE_TIME));
#endif
return(NULL); /* success */
} /* end rt_SimInitTimingEngine */
#if !defined(MULTITASKING)
/* SINGLE TASKING */
/* Function: rt_SimGetNextSampleHit ============================================
* Abstract:
* For a single tasking real-time system, return time of next sample hit.
*/
time_T rt_SimGetNextSampleHit(void)
{
time_T timeOfNextHit;
td.clockTick[0] += 1;
timeOfNextHit = td.clockTick[0] * td.period[0];
# if NUMST > 1
{
int i;
for (i = 1; i < NUMST; i++) {
if (++td.taskTick == td.nTaskTicks) {
td.taskTick = 0;
td.clockTick++;
}
}
}
# endif
return(timeOfNextHit);
} /* end rt_SimGetNextSampleHit */
/* Function: rt_SimUpdateDiscreteTaskSampleHits */
void rt_SimUpdateDiscreteTaskSampleHits(int_T rtmNumSampTimes,
void *rtmTimingData,
int_T *rtmSampleHitPtr,
real_T *rtmTPtr)
{
int_T *sampleHit = rtmSampleHitPtr;
int i;
UNUSED_PARAMETER(rtmTimingData);
UNUSED_PARAMETER(rtmNumSampTimes);
for (i = td.firstDiscIdx; i < NUMST; i++) {
int_T hit = (td.taskTick == 0);
if (hit) {
rttiSetTaskTime(rtmTPtr, i,
td.clockTick*td.period + td.offset);
}
sampleHit = hit;
}
} /* rt_SimUpdateDiscreteTaskSampleHits */
#else /* defined(MULTITASKING) */
/* Function: rt_SimUpdateDiscreteEvents */
time_T rt_SimUpdateDiscreteEvents(int_T rtmNumSampTimes,
void *rtmTimingData,
int_T *rtmSampleHitPtr,
int_T *rtmPerTaskSampleHits)
{
int i, j;
int_T *sampleHit = rtmSampleHitPtr;
UNUSED_PARAMETER(rtmTimingData);
/*
* Run this loop in reverse so that we do lower priority events first.
*/
i = NUMST;
while (--i >= 0) {
if (td.taskTick == 0) {
/*
* Got a sample hit, reset the counter, and update the clock
* tick counter.
*/
sampleHit = 1;
td.clockTick++;
/*
* Record the state of all "slower" events
*/
for (j = i + 1; j < NUMST; j++) {
rttiSetSampleHitInTask(rtmPerTaskSampleHits, rtmNumSampTimes,
j, i, sampleHit[j]);
}
} else {
/*
* no sample hit, increment the counter
*/
sampleHit = 0;
}
if (++td.taskTick == td.nTaskTicks) { /* update for next time */
td.taskTick = 0;
}
}
return(td.clockTick[0]*td.period[0]);
} /* rt_SimUpdateDiscreteEvents */
/* Function: rt_SimUpdateDiscreteTaskTime */
void rt_SimUpdateDiscreteTaskTime(real_T *rtmTPtr,
void *rtmTimingData,
int tid)
{
UNUSED_PARAMETER(rtmTimingData);
rttiSetTaskTime(rtmTPtr, tid,
td.clockTick[tid]*td.period[tid] + td.offset[tid]);
}
#endif /* MULTITASKING */
#else
....
.....
......
c:\matlab6p5\work\denas\rt_sim.c(94) : error C2065: 'NUMST' : undeclared identifier
c:\matlab6p5\work\denas\rt_sim.c(94) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(95) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(95) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(96) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(96) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(97) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(97) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(98) : error C2057: expected constant expression
c:\matlab6p5\work\denas\rt_sim.c(98) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(99) : error C2229: struct 'TimingData_Tag' has an illegal zero-sized array
c:\matlab6p5\work\denas\rt_sim.c(241) : warning C4013: 'rttiSetTaskTime' undefined; assuming extern returning int
c:\matlab6p5\work\denas\rt_sim.c(376) : fatal error C1019: unexpected #else
Error executing cl.exe.
RV2AJFRONT_NEW.obj - 12 error(s), 1 warning(s)[/SIZE][/SIZE]