You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Online database block uses a MySQL server to generate the desired output data, this is achieved by a custom CMEX S-Function written in C using the **MySQL Connector C API version 6.1.11**.
10
+
The MySQL database block connects to a MySQL server in order to request the desired output data, this is achieved by a custom CMEX S-Function written in C using the **MySQL Connector C API version 6.1.11**.
15
11
16
12
The block can interpret a predefined format of SQL entry:
17
13
@@ -26,33 +22,61 @@ The precision required for the simulation is, currently, achieved by linear inte
26
22
27
23
The connection and the query take a long time compared to the other operations. To solve this problem the block saves the results in a unique file and only uses the database when this file does not exist, otherwise reads the data from the file, which takes significantly less time.
The Offline database block uses a file to output the measured data. The Simulink program has no easy built-in support for custom text file handling, so this is achieved by the same .dll file used in the Online database block.
31
+
The WebAPI (JSON) block connects to a TCP/IP server in order to request the desired output data in the form of a JSON response. The block implements a TCP/IP client and uses [DaveGamble's cJSON library](https://github.com/DaveGamble/cJSON) to parse the response.
34
32
35
-
The block can interpret a predefined format of file entry:
33
+
An example of a request:
34
+
```
35
+
http://127.0.0.1/api/api.php?startDate=2019-05-
36
+
17&startTime=06:00:00&endDate=2019-05-
37
+
17&endTime=20:30:00&sensors=TW,I
38
+
```
39
+
An example of a response (if the query was successful):
36
40
```
37
-
Date;Time;N1;N2;N3;N4...
38
-
YYYY-MM-DD;hh:mm:ss;v1;v2;v3;v4...
41
+
{
42
+
"data":[
43
+
{
44
+
"date":"2018-04-17",
45
+
"time":"06:00:00",
46
+
"TW":20.98,
47
+
"I":53.33
48
+
},
49
+
{
50
+
"date":"2018-04-17",
51
+
"time":"06:40:00",
52
+
"TW":21.95,
53
+
"I":103.33
54
+
}
55
+
]
56
+
}
57
+
```
58
+
An example of a response (if the query was unsuccessful):
59
+
```
60
+
{
61
+
"error": "startTime is needed"
62
+
}
39
63
```
40
-
This format can be easily exported from an Excel table using CSV export.
41
64
42
65
The precision required for the simulation is, currently, achieved by linear interpolation, which can be turned off.
43
66
67
+
The connection and the query take a long time compared to the other operations. To solve this problem the block saves the results in a unique file and only uses the database when this file does not exist, otherwise reads the data from the file, which takes significantly less time.
68
+
44
69
## Requirements
45
-
- MATLAB R2018b + Simulink (trial can do the trick)
70
+
- MATLAB (>= R2018b) + Simulink (trial can do the trick)
46
71
- Visual Studio 2017 Community Edition (free)
47
72
48
73
## Compilation
49
74
Setup ```mex``` with the ```mex -setup``` command in MATLAB.
50
-
- sfun : Run ```compile.m```.
51
-
- extlib : Run ```compile_and_test.m```.
75
+
Run ```sfun/sql/compile.m``` or ```sfun/webjson/compile.m```.
52
76
53
77
## Usage
54
-
- sfun : Copy```sfun_simdatabase.mexwXX``` to the **Working Directory** and see ```sim_test.slx```.
55
-
- extlib : Copy ```simdatabase.dll``` and ```resolve_pointer.m``` to the **Working Directory** and follow the example ```.SLX``` files.
78
+
Use the database example```example/sql/sim_test.sql``` to setup the database.
79
+
In order to use the JSON block, an example implementation of the API can be found in ```example/webjson```, it is called **api**. It uses the previously installed database scheme.
0 commit comments