]> rtime.felk.cvut.cz Git - socketcan-simulink.git/blob - blocks/sfunction_printf.c
Run model script uses local target-ssh-key only if it is present.
[socketcan-simulink.git] / blocks / sfunction_printf.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  *    contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * File : sfunction_printf.c
35  * Abstract:
36  *     C-MEX S-function block for RPP Serial Communication Printf.
37  *
38  * References:
39  *     header.c
40  *     trailer.c
41  *
42  * Compile with:
43  *     <matlabroot>/bin/mex sfunction_printf.c
44  */
45
46
47 #define S_FUNCTION_NAME sfunction_printf
48 #include "header.c"
49
50
51 static void mdlInitializeSizes(SimStruct *S)
52 {
53     /*
54      * Configure parameters: 2
55      *  - Printf format [setting].
56      */
57     if (!rppSetNumParams(S, 1)) {
58         return;
59     }
60
61     /*
62      * Configure input ports: 1
63      *  - Data send.
64      */
65     if (!ssSetNumInputPorts(S, 1)) {
66         return;
67     }
68     rppAddInputVectorPort(S, 0, DYNAMICALLY_TYPED, DYNAMICALLY_SIZED);
69
70     /*
71      * Configure output ports: 1
72      *  - Error flag.
73      */
74     if (!ssSetNumOutputPorts(S, 1)) {
75         return;
76     }
77     rppAddOutputPort(S, 0, SS_BOOLEAN);
78
79     /* Set standard options for this block */
80     rppSetStandardOptions(S);
81 }
82
83
84 #ifdef MATLAB_MEX_FILE
85 #define MDL_CHECK_PARAMETERS
86 static void mdlCheckParameters(SimStruct *S)
87 {
88     /* Check the parameter 1 */
89     /*if (!rppValidParamBoolean(S, 0)) {
90         return;
91     }
92
93     /* Note that parameter 2 is not checked */
94 }
95 #endif
96
97
98 #ifdef MATLAB_MEX_FILE
99 #define MDL_SET_WORK_WIDTHS
100 static void mdlSetWorkWidths(SimStruct *S)
101 {
102     /* Set number of run-time parameters */
103     /*if (!ssSetNumRunTimeParams(S, 1)) {
104         return;
105     }
106
107     /* Register the run-time parameter 1 */
108     /*ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_BOOLEAN);*/
109 }
110 #endif
111
112
113 #ifdef MATLAB_MEX_FILE
114 #define MDL_RTW
115 static void mdlRTW(SimStruct* S)
116 {
117     /* Register parameter as a parameter setting */
118     static char_T str[128];
119     mxGetString(ssGetSFcnParam(S, 0), (char*)&str, sizeof(str)); /* Get string */
120     if (!ssWriteRTWParamSettings(S, 1,
121             SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
122         /* An error ocurred */
123         return;
124     }
125 }
126 #endif
127
128
129
130 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
131 #define UNUSED_MDLOUTPUTS
132 #define UNUSED_MDLTERMINATE
133 #include "trailer.c"