]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_scis.c
8ab2fdebe6a1eac7ada93e8d794a342c3fb1e076
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_scis.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * File : sfunction_scis.c
20  * Abstract:
21  *     C-MEX S-function block for RPP Serial Communication send.
22  *
23  * References:
24  *     header.c
25  *     trailer.c
26  *
27  * Compile with:
28  *     <matlabroot>/bin/mex sfunction_scis.c
29  */
30
31
32 #define S_FUNCTION_NAME sfunction_scis
33 #include "header.c"
34
35
36 static void mdlInitializeSizes(SimStruct *S)
37 {
38     /*
39      * Configure parameters: 1
40      *  - Use printf.
41      *  - Printf format [not runtime].
42      */
43     if(!rppSetNumParams(S, 2)) {
44         return;
45     }
46
47     /*
48      * Configure input ports: 1
49      *  - Data send.
50      */
51     if(!ssSetNumInputPorts(S, 1)) {
52         return;
53     }
54     rppAddInputPort(S, 0, SS_UINT8);
55
56     /*
57      * Configure output ports: 1
58      *  - Error flag.
59      */
60     if(!ssSetNumOutputPorts(S, 1)) {
61         return;
62     }
63     rppAddOutputPort(S, 0, SS_BOOLEAN);
64
65     /* Set standard options for this block */
66     rppSetStandardOptions(S);
67 }
68
69
70 #ifdef MATLAB_MEX_FILE
71 #define MDL_CHECK_PARAMETERS
72 static void mdlCheckParameters(SimStruct *S)
73 {
74     /* Check the parameter 1 */
75     if(!rppValidParamBoolean(S, 0)) {
76         return;
77     }
78
79     /* Note that parameter 2 is not checked */
80 }
81 #endif
82
83
84 #ifdef MATLAB_MEX_FILE
85 #define MDL_SET_WORK_WIDTHS
86 static void mdlSetWorkWidths(SimStruct *S)
87 {
88     /* Set number of run-time parameters */
89     if(!ssSetNumRunTimeParams(S, 1)) {
90         return;
91     }
92
93     /* Register the run-time parameter 1 */
94     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT32);
95 }
96 #endif
97
98
99 #ifdef MATLAB_MEX_FILE
100 #define MDL_RTW
101 static void mdlRTW(SimStruct* S)
102 {
103     /* Register parameter 2 as a parameter setting */
104     static char_T str[128];
105     mxGetString(ssGetSFcnParam(S, 1), (char*)&str, sizeof(str)); // Get string
106     if(!ssWriteRTWParamSettings(S, 1,
107             SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
108         // An error ocurred
109         return;
110     }
111 }
112 #endif
113
114
115
116 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
117 #define UNUSED_MDLOUTPUTS
118 #define UNUSED_MDLTERMINATE
119 #include "trailer.c"