]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_scip.c
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_scip.c
1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * File : sfunction_scip.c
28  * Abstract:
29  *     C-MEX S-function block for RPP Serial Communication Printf.
30  *
31  * References:
32  *     header.c
33  *     trailer.c
34  *
35  * Compile with:
36  *     <matlabroot>/bin/mex sfunction_scip.c
37  */
38
39 /*
40 %YAML 1.2
41 ---
42 Name: Serial Printf
43 Category: Communication
44 Header: rpp/sci.h
45 Mnemonic: SCIP
46
47 Inputs:
48   - { name: "Send", type: "dynamically" }
49
50 Outputs:
51   - { name: "ErrFlag", type: "bool" }
52
53 Parameters:
54   - { name: "Print format", type: "string", range: "(must include specifier for arguments)" }
55
56 # Description and Help is in Markdown mark-up
57 Description: &desc |
58
59   This block prints a formatted string to the SCI. The *Print format*
60   parameter is used as the format specifier for C `printf()` function.
61   Note that this value is inserted raw between the quotes during code
62   generation and thus there is no validation on it. User should always
63   put a valid specifier for the input type of the block.
64
65   Due to Simulink limitations, it is not posible join diferent types
66   into one vector. So one block can be used only for one type of
67   inputs.
68
69 Help: *desc
70
71 Status: Stable
72
73 RPP API functions used:
74     - rpp_sci_printf()
75
76 Relevant demos:
77     - irc_input
78 ...
79 */
80
81 #define S_FUNCTION_NAME sfunction_scip
82 #include "header.c"
83
84
85 static void mdlInitializeSizes(SimStruct *S)
86 {
87     /*
88      * Configure parameters: 2
89      *  - Printf format [setting].
90      */
91     if (!rppSetNumParams(S, 1)) {
92         return;
93     }
94
95     /*
96      * Configure input ports: 1
97      *  - Data send.
98      */
99     if (!ssSetNumInputPorts(S, 1)) {
100         return;
101     }
102     rppAddInputVectorPort(S, 0, DYNAMICALLY_TYPED, DYNAMICALLY_SIZED);
103
104     /*
105      * Configure output ports: 1
106      *  - Error flag.
107      */
108     if (!ssSetNumOutputPorts(S, 1)) {
109         return;
110     }
111     rppAddOutputPort(S, 0, SS_BOOLEAN);
112
113     /* Set standard options for this block */
114     rppSetStandardOptions(S);
115 }
116
117
118 #ifdef MATLAB_MEX_FILE
119 #define MDL_CHECK_PARAMETERS
120 static void mdlCheckParameters(SimStruct *S)
121 {
122     /* Check the parameter 1 */
123     /*if (!rppValidParamBoolean(S, 0)) {
124         return;
125     }
126
127     /* Note that parameter 2 is not checked */
128 }
129 #endif
130
131
132 #ifdef MATLAB_MEX_FILE
133 #define MDL_SET_WORK_WIDTHS
134 static void mdlSetWorkWidths(SimStruct *S)
135 {
136     /* Set number of run-time parameters */
137     /*if (!ssSetNumRunTimeParams(S, 1)) {
138         return;
139     }
140
141     /* Register the run-time parameter 1 */
142     /*ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_BOOLEAN);*/
143 }
144 #endif
145
146
147 #ifdef MATLAB_MEX_FILE
148 #define MDL_RTW
149 static void mdlRTW(SimStruct* S)
150 {
151     /* Register parameter as a parameter setting */
152     static char_T str[128];
153     mxGetString(ssGetSFcnParam(S, 0), (char*)&str, sizeof(str)); /* Get string */
154     if (!ssWriteRTWParamSettings(S, 1,
155             SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
156         /* An error ocurred */
157         return;
158     }
159 }
160 #endif
161
162
163
164 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
165 #define UNUSED_MDLOUTPUTS
166 #define UNUSED_MDLTERMINATE
167 #include "trailer.c"