]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blobdiff - rpp/blocks/sfunction_sdrw.c
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_sdrw.c
index e5f4273d6c806a543f4d634ba3c9937d9d569176..f9fc2f60cfa5c6187a081f5beef10ea211f37ab4 100644 (file)
@@ -1,20 +1,28 @@
-/* Copyright (C) 2013 Czech Technical University in Prague
+/* Copyright (C) 2013, 2014 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.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  *
  * File : sfunction_sdrw.c
  * Abstract:
  *     <matlabroot>/bin/mex sfunction_sdrw.c
  */
 
+/*
+%YAML 1.2
+---
+Name: SD-RAM Log Data
+Category: Logging
+Header: rpp/sdc.h
+Mnemonic: SDRW
+
+Inputs:
+  - { name: "Data", type: "double" }
+
+Outputs:
+  - { name: "ErrFlag", type: "bool" }
+
+Parameters:
+  - { name: "Block ID",              type: "uint8", range: "[0-255]" }
+  - { name: "Printf format for logging", type: "string", range: "(include specifiers)" }
+
+# Description and Help is in Markdown mark-up
+Description: &desc |
+
+  This block allows to log a double value to the SD-RAM. User needs to provide a valid PrintFormat 
+  string to format and register the double value on the log. The PrintFormat string should include 
+  two specifiers:  
+    1. For the block ID. Any valid integer specifier.  
+    2. For the value to log. Any valid double specifier.  
+
+  Note that the value of PrintFormat is inserted raw between quotes on code generation and thus there 
+  is no validation on it. Error to provide a valid PrintFormat could generate compilation errors or 
+  even run-time errors (normally this generates a warning on compile time). Note that the function 
+  for logging used is `rpp_sdr_printf()`, which is a blocking call, and can potentially overrun the 
+  step. The ErrFlag will set if `rpp_sdr_printf()` returns an error (for example out of memory), 
+  but will clear back if the next step the call to this function is successful.
+
+Help: *desc
+
+Status: Beta
+
+RPP API functions used:
+    - rpp_sdr_printf()
+
+Relevant demos:
+    - log_analog_input
+...
+*/
 
 #define S_FUNCTION_NAME sfunction_sdrw
 #include "header.c"
@@ -40,7 +93,7 @@ static void mdlInitializeSizes(SimStruct *S)
      *  - Block ID.
      *  - Printf format [setting].
      */
-    if(!rppSetNumParams(S, 2)) {
+    if (!rppSetNumParams(S, 2)) {
         return;
     }
 
@@ -48,7 +101,7 @@ static void mdlInitializeSizes(SimStruct *S)
      * Configure input ports: 1
      *  - Data.
      */
-    if(!ssSetNumInputPorts(S, 1)) {
+    if (!ssSetNumInputPorts(S, 1)) {
         return;
     }
     rppAddInputPort(S, 0, SS_DOUBLE);
@@ -57,7 +110,7 @@ static void mdlInitializeSizes(SimStruct *S)
      * Configure output ports: 1
      *  - Error flag.
      */
-    if(!ssSetNumOutputPorts(S, 1)) {
+    if (!ssSetNumOutputPorts(S, 1)) {
         return;
     }
     rppAddOutputPort(S, 0, SS_BOOLEAN);
@@ -72,7 +125,7 @@ static void mdlInitializeSizes(SimStruct *S)
 static void mdlCheckParameters(SimStruct *S)
 {
     /* Check the parameter 1 */
-    if(!rppValidParamRange(S, 0, 0, 255)) {
+    if (!rppValidParamRange(S, 0, 0, 255)) {
         return;
     }
 }
@@ -84,7 +137,7 @@ static void mdlCheckParameters(SimStruct *S)
 static void mdlSetWorkWidths(SimStruct *S)
 {
     /* Set number of run-time parameters */
-    if(!ssSetNumRunTimeParams(S, 1)) {
+    if (!ssSetNumRunTimeParams(S, 1)) {
         return;
     }
 
@@ -101,7 +154,7 @@ 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,
+    if (!ssWriteRTWParamSettings(S, 1,
             SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
         /* An error ocurred */
         return;