]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/commitdiff
Implemented string printf format for Simulink SCIS block.
authorCarlos Jenkins <carlos@jenkins.co.cr>
Thu, 13 Jun 2013 00:34:59 +0000 (02:34 +0200)
committerCarlos Jenkins <carlos@jenkins.co.cr>
Thu, 13 Jun 2013 00:34:59 +0000 (02:34 +0200)
rpp/blocks/README.txt
rpp/blocks/rpp_lib.slx
rpp/blocks/sfunction_scis.c
rpp/blocks/tlc_c/sfunction_scis.tlc
rpp/demos/hello_world.slx
rpp/rpp/rpp_srmain.tlc

index 2ffd49dd265206e8239a23959fe95650a9ed788e..5f00e7ce33bfdc3ad84e8018bb245415ea9ede2e 100644 (file)
@@ -264,6 +264,7 @@ The following are the currently specified Simulink blocks.
 
     Parameters  : 1
         bool    UsePrintf
+        string  PrintFormat [SETTING]
 
 
 [SCIC] Serial Comm. Interface Configure ========================================
index fe5617df6344c233097f4e13469f5577f5cf76a1..401287964e86286fb311ebe3184c0ed08c1c87b6 100644 (file)
Binary files a/rpp/blocks/rpp_lib.slx and b/rpp/blocks/rpp_lib.slx differ
index 0d93f5c039da99e1f74eda67f4f22565aa64f755..8ab2fdebe6a1eac7ada93e8d794a342c3fb1e076 100644 (file)
@@ -38,8 +38,9 @@ static void mdlInitializeSizes(SimStruct *S)
     /*
      * Configure parameters: 1
      *  - Use printf.
+     *  - Printf format [not runtime].
      */
-    if(!rppSetNumParams(S, 1)) {
+    if(!rppSetNumParams(S, 2)) {
         return;
     }
 
@@ -74,6 +75,8 @@ static void mdlCheckParameters(SimStruct *S)
     if(!rppValidParamBoolean(S, 0)) {
         return;
     }
+
+    /* Note that parameter 2 is not checked */
 }
 #endif
 
@@ -93,6 +96,23 @@ static void mdlSetWorkWidths(SimStruct *S)
 #endif
 
 
+#ifdef MATLAB_MEX_FILE
+#define MDL_RTW
+static void mdlRTW(SimStruct* S)
+{
+    /* Register parameter 2 as a parameter setting */
+    static char_T str[128];
+    mxGetString(ssGetSFcnParam(S, 1), (char*)&str, sizeof(str)); // Get string
+    if(!ssWriteRTWParamSettings(S, 1,
+            SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
+        // An error ocurred
+        return;
+    }
+}
+#endif
+
+
+
 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
 #define UNUSED_MDLOUTPUTS
 #define UNUSED_MDLTERMINATE
index 9440def17814c57f97d09bc5e858ce3003c4b92e..aa55e5d73e6a8ebfec54cb5d8d633af88b06dcd9 100644 (file)
         %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
 
         %if use_printf
-            rpp_sci_print("%d\r\n", %<data>);
+            %assign printf_format = SFcnParamSettings.PrintfFormat
+            rpp_sci_printf((const char*)"%<printf_format>", %<data>);
+            %<err_flag> = FALSE;
         %else
-            rpp_sci_putc(%<data>);
+            if(rpp_sci_write_nb(1, &%<data>) != SUCCESS) {
+                %<err_flag> = TRUE;
+            } else {
+                %<err_flag> = FALSE;
+            }
         %endif
 
     %endif
index 8d5438b7d3e7d1b5c547ba5b53bff0c8b60adcb4..e874434e5a24d1eb021a491005ed20b3d2da0e1d 100644 (file)
Binary files a/rpp/demos/hello_world.slx and b/rpp/demos/hello_world.slx differ
index 9c1afdaab86543543fe60a87a59c82122763b46d..afbfe8b825e5992397591620be50093393a38942 100644 (file)
             /* Lock semaphore */
             if(xSemaphoreTake(step_signal, portMAX_DELAY)) {
                 WORKING = TRUE;
-                #ifdef DEBUG
-                /* rpp_sci_printf("Model step %d\r\n", steps_working + 1); */
-                #endif
                 %<LibCallModelStep(0)>\
                 steps_working++;
                 WORKING = FALSE;
         rpp_init();
 
         #ifdef DEBUG
-          rpp_sci_printf((const char*)
-              "Running Simulink model '%s'.\r\n", "%<LibGetMdlPubHdrBaseName()>"
+        %assign model_info = SPRINTF("'%s' - %s (TLC %s)\\r\\n", LibGetMdlPubHdrBaseName(), TLC_TIME, TLC_VERSION)
+        rpp_sci_printf((const char*)
+                "%<model_info>"
             );
         #endif