EasyLink
EasyLink is a C++ software development kit for developing blocks for SIMULINK (S-functions)
/Users/guillaume.laurent/Documents/Prog/easylinkEigen/easylink/sfunTimesTwoWithEigen.cpp
1 /*
2  * C++ S-function for multiplying an input by 2 using EasyLink and Eigen
3  *
4  * y = 2*u
5  *
6  * Input and output ports are dynamically sized.
7  *
8  * To compile this C++ S-function, enter the following command in MATLAB:
9  *
10  * >>make sfunTimesTwoWithEigen.cpp
11  *
12  * Then open the file "testTimesTwoWithEigen.mdl/slx" and start the simulation.
13  */
14 
15 //------------------------------------------------------------------------------
16 
17 #define S_FUNCTION_NAME sfunTimesTwoWithEigen
18 
19 #include "EasyLink.h"
20 
21 #include <Eigen/Dense>
22 
23 #define EIGEN_INPUT_MATRIX(type, name, port) Eigen::Map<Eigen::Matrix<type, Eigen::Dynamic, Eigen::Dynamic> > name((type*)getInputData(port), getInputNRows(port), getInputNCols(port))
24 #define EIGEN_INPUT_ARRAY(type, name, port) Eigen::Map<Eigen::Array<type, Eigen::Dynamic, Eigen::Dynamic> > name((type*)getInputData(port), getInputNRows(port), getInputNCols(port))
25 #define EIGEN_OUTPUT_MATRIX(type, name, port) Eigen::Map<Eigen::Matrix<type, Eigen::Dynamic, Eigen::Dynamic> > name((type*)getOutputData(port), getOutputNRows(port), getOutputNCols(port))
26 #define EIGEN_OUTPUT_ARRAY(type, name, port) Eigen::Map<Eigen::Array<type, Eigen::Dynamic, Eigen::Dynamic> > name((type*)getOutputData(port), getOutputNRows(port), getOutputNCols(port))
27 
28 
29 //------------------------------------------------------------------------------
30 
31 class Block : public BaseBlock {
32 public:
33 
34  static void initializeInputPortSizes() {
36  setInputPort(0, -1, -1, SS_DOUBLE);
37  }
38 
39  static void initializeOutputPortSizes() {
41  setOutputPort(0, -1, -1, SS_DOUBLE);
42  }
43 
44  static void checkInputPortFinalSizes(int port, int nRows, int nCols) {
45  if (port == 0) {
46  setOutputPortFinalSizes(0, nRows, nCols);
47  }
48  }
49 
50  void outputs() {
51  EIGEN_INPUT_ARRAY(double, in, 0);
52  EIGEN_OUTPUT_ARRAY(double, out, 0);
53  out = in * 2.0;
54  }
55 
56 };
57 
58 //------------------------------------------------------------------------------
59 
60 #include "sfunDefinitions.h"
61 
62 //------------------------------------------------------------------------------
static void setInputPortsCount(int portsCount)
Definition: BaseBlock.h:104
static void setOutputPortsCount(int portsCount)
Definition: BaseBlock.h:152
void outputs()
Definition: BaseBlock.h:340
static void setInputPort(int port, int nRows, int nCols, DTypeId type=SS_DOUBLE, bool directFeedThrough=true)
Definition: BaseBlock.h:116
static void initializeInputPortSizes()
Definition: BaseBlock.h:145
static void checkInputPortFinalSizes(int port, int nRows, int nCols)
Definition: BaseBlock.h:273
static void initializeOutputPortSizes()
Definition: BaseBlock.h:189
static void setOutputPortFinalSizes(int port, int nRows, int nCols)
Definition: BaseBlock.h:279
static void setOutputPort(int port, int nRows, int nCols, DTypeId type=SS_DOUBLE)
Definition: BaseBlock.h:164

Copyright (c) 2014 FEMTO-ST / ENSMM / UFC / UTBM, Besançon, France. Generated by Doxygen.