#include "SwitchingTable.h"
#include "DTC.h"

SFIO_BlockExecutionResult SwitchingTable(const void *pInBuff, void *pOutBuff, void *pVariables, SFIO_BlockCommand eCmd)
{
    /* input signals */
    typedef struct
    {
        short             sum_s_x;
    } InStruct;

    /* output signals */
    typedef struct
    {
        long		t1;
        short       u_a_b_c[3];
    } OutStruct;

    /* Uncomment the following structure and place your block-related 
       persistent variables there. Don't forget to change SIZEOF_StateStruct 
       below from 0 to sizeof(StateStruct). */ 
    /*typedef struct
    {
        short    x;
    }StateStruct;
    */

    /* structure lengths and sizes */
    enum StructSizes
    {
        LENGTHOF_InStruct  = 2,        /* real communicated length of input data items */
        LENGTHOF_OutStruct = 10,        /* real communicated length of output data items */
        SIZEOF_StateStruct = 0         /* size to be allocated, use sizeof(StateStruct) */
    };

    /* local variables */
    SFIO_BlockExecutionResult eResult;
    SFIO_BlockRegistration    *pReg;
    InStruct    *pIn = (InStruct*) pInBuff;
    OutStruct   *pOut = (OutStruct*) pOutBuff;
    //StateStruct *pState = (StateStruct *)pVariables;

    /* default result code */
    eResult = SFIO_EXEC_OK;

    switch(eCmd)
    {
        /* provide block registration data */
        case SFIO_CMD_REGISTER:
            pReg = (SFIO_BlockRegistration*) pOutBuff;
            pReg->wInputsCount = LENGTHOF_InStruct;          /* input data length in bytes */
            pReg->wOutputsCount = LENGTHOF_OutStruct;        /* output data length in bytes */
            pReg->wVariablesCount = SIZEOF_StateStruct;      /* state variables data size */
            //strcpy(pReg->pDescriptor,"SwitchingTable");        /* block descriptor, customize if neccessary */
            break;

        /* state variables initialization */
        case SFIO_CMD_INIT:
            //pState->x = 0;
            break;

        /* compute function */
        case SFIO_CMD_EXECUTE:
            /* this macro gives an opportunity to break into this application
               when the "break" button is pressed in the Matlab/Simulink window */
            SFIO_Breakpoint();

            /**** place your computational code here ****/
			
			SFIO_TimerStart();
			c_switchingtable(pIn->sum_s_x,&pOut->u_a_b_c[0],&pOut->u_a_b_c[1],&pOut->u_a_b_c[2]); //call the C function 'vyber_sektoru_napetia' with adresses of input parameters and save return values like a pointers
			SFIO_TimerStop(&pOut->t1);
			/**** end of your code ****/

            break;

        /* unknown command requested */
        default:
            eResult = SFIO_EXEC_UNKNOWN_COMMAND;
    }

    return(eResult);
}