ThresholdDetectorRuntimeBox::ThresholdDetectorRuntimeBox(const ThresholdDetectorBox *box) :
    m_quiet(box->quiet())
{
    setOwner(box);

    InputPorts in = box->inputPorts();
    m_threshold.init(this, in[0], toPortNotifier(&ThresholdDetectorRuntimeBox::setThreshold));
    m_in.init(this, in[1], toPortNotifier(&ThresholdDetectorRuntimeBox::processData));
    setInputPorts(RuntimeInputPorts() << &m_threshold << &m_in);

    OutputPorts out = box->outputPorts();
    m_out.init(this, out[0]);
    setOutputPorts(RuntimeOutputPorts() << &m_out);

    Q_ASSERT(in[0]->format().dataSize() == 1);
    Q_ASSERT(in[1]->format().dataSize() == 1);
    Q_ASSERT(out[0]->format().dataSize() == 1);

    switch (box->param()) {
    case ThresholdLess:   m_thresholdFunc = &ThresholdDetectorRuntimeBox::thresholdLess;   break;
    case ThresholdLessOrEqual:   m_thresholdFunc = &ThresholdDetectorRuntimeBox::thresholdLessOrEqual;   break;
    case ThresholdGreater:   m_thresholdFunc = &ThresholdDetectorRuntimeBox::thresholdGreater;   break;
    case ThresholdGreaterOrEqual:   m_thresholdFunc = &ThresholdDetectorRuntimeBox::thresholdGreaterOrEqual;   break;
    case ThresholdEqual:   m_thresholdFunc = &ThresholdDetectorRuntimeBox::thresholdEqual;   break;
    case ThresholdNotEqual:   m_thresholdFunc = &ThresholdDetectorRuntimeBox::thresholdNotEqual;   break;
    default:
        throwBoxException("Invalid threshold parameter");
    }
    if (in[0]->link())
        m_thresholdDataValid = false;
    else {
        m_thresholdDataValid = true;
        m_thresholdData = box->thresholdValue();
    }
}
Example #2
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
        int idx;

        int_T canExDT; // Extended extended frame
        int_T canStDT; // Standard frame

        /* See sfuntmpl_doc.c for more details on the macros below */

        ssSetNumSFcnParams(S, P_NPARMS);  /* Number of expected parameters */
        
        if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
                /* Return if number of expected != number of actual parameters */
                return;
        }
                
        // No parameters will be tunable
        for(idx=0; idx<P_NPARMS; idx++){
                ssSetSFcnParamNotTunable(S,idx);
        }

        // Setup all the CAN datatypes
        CAN_Common_MdlInitSizes(S);
        canExDT = ssGetDataTypeId(S,SL_CAN_EXTENDED_FRAME_DTYPE_NAME );
        canStDT = ssGetDataTypeId(S,SL_CAN_STANDARD_FRAME_DTYPE_NAME );

        // One vectorized output port may contain several CAN
        // messages, one frame per signal element
        ssSetNumOutputPorts(S,1);
        ssSetOutputPortWidth(S,0,1);
        if( P_TYPE == CAN_MESSAGE_STANDARD){
                ssSetOutputPortDataType(S,0,canStDT);
        }else if ( P_TYPE == CAN_MESSAGE_EXTENDED ){
                ssSetOutputPortDataType(S,0,canExDT);
        }

        // Multiple input ports. Each input port represents
        // a CAN data frame. These will be vectorized
        // uint8 inputs. The width corressponds to the
        // number of data bytes in the frame
        setInputPorts(S);

        ssSetNumContStates(S, 0);
        ssSetNumDiscStates(S, 0);


        ssSetNumSampleTimes(S, 1);
        ssSetNumRWork(S, 0);
        ssSetNumIWork(S, 0);
        ssSetNumPWork(S, 0);
        ssSetNumModes(S, 0);
        ssSetNumNonsampledZCs(S, 0);
         
        /* use generated code in Accelerator Mode */
        ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR);
}
Example #3
0
ValveRuntimeBox::ValveRuntimeBox(const ValveBox *box)
{
    setOwner(box);

    InputPorts in = box->inputPorts();
    m_valve.init(this, in[0], toPortNotifier(&ValveRuntimeBox::setValve));
    m_in.init(this, in[1], toPortNotifier(&ValveRuntimeBox::setInput));
    setInputPorts(RuntimeInputPorts() << &m_valve << &m_in);

    m_hasValve = false;
    m_hasData = false;
    m_data.resize(in[1]->format().dataSize());

    OutputPorts out = box->outputPorts();
    m_out.init(this, out[0], PortData(m_data.size(), m_data.data()));
    setOutputPorts(RuntimeOutputPorts() << &m_out);
}