]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/commitdiff
Implemented a boolean parameter check routine and SCIS S-Function.
authorCarlos Jenkins <carlos@jenkins.co.cr>
Tue, 4 Jun 2013 22:56:14 +0000 (00:56 +0200)
committerCarlos Jenkins <carlos@jenkins.co.cr>
Tue, 4 Jun 2013 22:56:14 +0000 (00:56 +0200)
rpp/blocks/README.txt
rpp/blocks/header.c
rpp/blocks/sfunction_din.c
rpp/blocks/sfunction_scis.c [new file with mode: 0644]

index 3d6d5944b10cffe4e2af337e7a229d7501d403bb..d81cd74218a4dbf0dda57cb7928d0202c739d7f9 100644 (file)
@@ -254,7 +254,7 @@ The following are the currently specified Simulink blocks.
         None
 
 
-[SDIS] Serial Comm. Interface Send =============================================
+[SCIS] Serial Comm. Interface Send =============================================
     Inputs      : 1
         uint8   Data
 
index 3fb0abc370371bb8f3a6d6b7bc5a8bf039f73021..887bc1954534d58c12c92768c65e1bdab48b75d5 100644 (file)
@@ -266,7 +266,7 @@ static void rppSetStandardOptions(SimStruct* S)
 
 /* Function: rppValidParamRange ================================================
  * Abstract:
- *     Validate that given numeric parameters is between given range.
+ *     Validate that given parameter is scalar, numeric and between given range.
  */
 static bool rppValidParamRange(SimStruct* S, int_T parIdx, int_T mn, int_T mx)
 {
@@ -299,6 +299,22 @@ static bool rppValidParamRange(SimStruct* S, int_T parIdx, int_T mn, int_T mx)
 }
 
 
+/* Function: rppValidParamBoolean ==============================================
+ * Abstract:
+ *     Validate that given parameter is boolean (logical).
+ */
+static bool rppValidParamBoolean(SimStruct* S, int_T parIdx)
+{
+    const mxArray* raw = ssGetSFcnParam(S, parIdx);
+    if(!mxIsLogicalScalar(raw)) {
+        ssSetErrorStatus(S, "Parameter to S-function must be a scalar.");
+        return false;
+    }
+
+    return true;
+}
+
+
 /*
  *==============================================================================
  *=           BEGIN EXAMPLE CODE AND FUNCTIONS DOCUMENTATION                   =
index 051e585024d8d4d4a128b9faf67cfdc04e00648d..9fe1fdb58d4482500104eea2b159895925296521 100644 (file)
@@ -76,7 +76,10 @@ static void mdlCheckParameters(SimStruct *S)
         return;
     }
 
-    /* FIXME: Check parameter 2 */
+    /* Check the parameter 2 */
+    if(!rppValidParamBoolean(S, 1)) {
+        return;
+    }
 }
 #endif
 
diff --git a/rpp/blocks/sfunction_scis.c b/rpp/blocks/sfunction_scis.c
new file mode 100644 (file)
index 0000000..c2461e9
--- /dev/null
@@ -0,0 +1,101 @@
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : sfunction_scis.c
+ * Abstract:
+ *     C-MEX S-function block for RPP Serial Communication send.
+ *
+ * References:
+ *     header.c
+ *     trailer.c
+ *
+ * Compile with:
+ *     <matlabroot>/bin/mex sfunction_scis.c
+ */
+
+
+#define S_FUNCTION_NAME sfunction_scis
+#include "header.c"
+
+
+static void mdlInitializeSizes(SimStruct *S)
+{
+    /*
+     * Configure parameters: 1
+     *  - Use printf.
+     */
+    if(!rppSetNumParams(S, 1)) {
+        return;
+    }
+
+    /*
+     * Configure input ports: 1
+     *  - Data.
+     */
+    if(!ssSetNumInputPorts(S, 1)) {
+        return;
+    }
+    rppAddInputPort(S, 0, SS_UINT8);
+
+    /*
+     * Configure output ports: 1
+     *  - Error flag.
+     */
+    if(!ssSetNumOutputPorts(S, 1)) {
+        return;
+    }
+    rppAddOutputPort(S, 0, SS_BOOLEAN);
+
+    /* Set standard options for this block */
+    rppSetStandardOptions(S);
+}
+
+
+#ifdef MATLAB_MEX_FILE
+#define MDL_CHECK_PARAMETERS
+static void mdlCheckParameters(SimStruct *S)
+{
+    /* Check the parameter 1 */
+    if(!rppValidParamBoolean(S, 0)) {
+        return;
+    }
+}
+#endif
+
+
+#ifdef MATLAB_MEX_FILE
+#define MDL_SET_WORK_WIDTHS
+static void mdlSetWorkWidths(SimStruct *S)
+{
+    /* Set number of run-time parameters */
+    if(!ssSetNumRunTimeParams(S, 1)) {
+        return;
+    }
+
+    /* Register the run-time parameter 1 */
+    ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
+
+    /* Note that parameter 2 is for TLC, not runtime, so not declared */
+}
+#endif
+
+
+#define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
+#define UNUSED_MDLOUTPUTS
+#define UNUSED_MDLTERMINATE
+#include "trailer.c"