You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/04/23 15:19:58 UTC

[plc4x] branch feature/c-api updated: - Added a "simulated" driver - Added a plc4c_system_add_driver to the "system" domain - Extended the hello_world.c to instantiate the "simulated" driver and register that at the "system".

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/c-api
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/c-api by this push:
     new 3243cc7  - Added a "simulated" driver - Added a plc4c_system_add_driver to the "system" domain - Extended the hello_world.c to instantiate the "simulated" driver and register that at the "system".
3243cc7 is described below

commit 3243cc7c89401daceea48803a732bc4aea89985f
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Apr 23 17:19:51 2020 +0200

    - Added a "simulated" driver
    - Added a plc4c_system_add_driver to the "system" domain
    - Extended the hello_world.c to instantiate the "simulated" driver and register that at the "system".
---
 sandbox/plc4c/api/include/plc4c/system.h               |  2 ++
 sandbox/plc4c/drivers/CMakeLists.txt                   |  1 +
 sandbox/plc4c/drivers/modbus/CMakeLists.txt            |  6 ++++--
 .../modbus/include/plc4c/driver/modbus.h}              | 18 ++++++++++--------
 .../drivers/modbus/src/{Test.c => driver_modbus.c}     |  9 +++++++++
 sandbox/plc4c/drivers/s7/CMakeLists.txt                |  6 ++++--
 .../s7/include/plc4c/driver/s7.h}                      | 18 ++++++++++--------
 sandbox/plc4c/drivers/s7/src/{Test.c => driver_s7.c}   |  9 +++++++++
 .../hello-world => drivers/simulated}/CMakeLists.txt   |  8 ++++----
 .../simulated/include/plc4c/driver/simulated.h}        | 18 ++++++++++--------
 .../src/Test.c => simulated/src/driver_simulated.c}    |  9 +++++++++
 sandbox/plc4c/examples/hello-world/CMakeLists.txt      |  4 ++--
 sandbox/plc4c/examples/hello-world/src/hello_world.c   | 10 +++++++++-
 sandbox/plc4c/spi/CMakeLists.txt                       |  2 +-
 .../plc4c/spi/include/plc4c/{ => spi}/types_private.h  |  2 ++
 sandbox/plc4c/spi/src/connection.c                     |  4 ++--
 sandbox/plc4c/spi/src/system.c                         |  8 ++++++--
 sandbox/plc4c/spi/src/types.c                          |  4 ++--
 18 files changed, 96 insertions(+), 42 deletions(-)

diff --git a/sandbox/plc4c/api/include/plc4c/system.h b/sandbox/plc4c/api/include/plc4c/system.h
index bb2a34f..b656fa0 100644
--- a/sandbox/plc4c/api/include/plc4c/system.h
+++ b/sandbox/plc4c/api/include/plc4c/system.h
@@ -164,6 +164,8 @@ void plc4c_system_set_on_disconnection_error(plc4c_system *system,
 void plc4c_system_set_on_loop_error(plc4c_system *system,
                                     plc4c_system_callback_loop_error callback);
 
+return_code plc4c_system_add_driver(plc4c_driver *driver);
+
 /**
  * Function to initialize the PLC4C system (Initialize the driver manager and the list of enabled drivers)
  * @param system
diff --git a/sandbox/plc4c/drivers/CMakeLists.txt b/sandbox/plc4c/drivers/CMakeLists.txt
index cf842f4..a37d896 100644
--- a/sandbox/plc4c/drivers/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/CMakeLists.txt
@@ -19,3 +19,4 @@
 
 add_subdirectory(modbus)
 add_subdirectory(s7)
+add_subdirectory(simulated)
diff --git a/sandbox/plc4c/drivers/modbus/CMakeLists.txt b/sandbox/plc4c/drivers/modbus/CMakeLists.txt
index 4d2164e..600d2d9 100644
--- a/sandbox/plc4c/drivers/modbus/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/modbus/CMakeLists.txt
@@ -17,12 +17,14 @@
   under the License.
 ]]
 
+include_directories("include" "../../api/include" "../../spi/include")
+
 # Add the sources
 file(GLOB sources "src/*.c")
 
 # Add the generated sources
 file(GLOB generatedSources "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/modbus/src/main/c/*.c")
 
-add_library(plc4c-drivers-modbus ${sources} ${generatedSources})
+add_library(plc4c-driver-modbus ${sources} ${generatedSources})
 
-target_link_libraries (plc4c-drivers-modbus ${CMAKE_DL_LIBS})
\ No newline at end of file
+target_link_libraries (plc4c-driver-modbus ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/spi/src/connection.c b/sandbox/plc4c/drivers/modbus/include/plc4c/driver/modbus.h
similarity index 72%
copy from sandbox/plc4c/spi/src/connection.c
copy to sandbox/plc4c/drivers/modbus/include/plc4c/driver/modbus.h
index 5ceceb3..2235dd5 100644
--- a/sandbox/plc4c/spi/src/connection.c
+++ b/sandbox/plc4c/drivers/modbus/include/plc4c/driver/modbus.h
@@ -16,15 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#ifndef PLC4C_DRIVER_S7_H_
+#define PLC4C_DRIVER_S7_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-#include "../../api/include/plc4c/connection.h"
-#include "../include/plc4c/types_private.h"
+#include <plc4c/types.h>
 
-return_code plc4c_connection_disconnect(plc4c_connection *connection) {
-    return OK;
-}
+plc4c_driver *plc4c_driver_modbus_create();
 
-char* plc4c_connection_get_connection_string(plc4c_connection *connection) {
-    return connection->connection_string;
+#ifdef __cplusplus
 }
-
+#endif
+#endif //PLC4C_DRIVER_S7_H_
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/modbus/src/Test.c b/sandbox/plc4c/drivers/modbus/src/driver_modbus.c
similarity index 77%
rename from sandbox/plc4c/drivers/modbus/src/Test.c
rename to sandbox/plc4c/drivers/modbus/src/driver_modbus.c
index a031845..1240f42 100644
--- a/sandbox/plc4c/drivers/modbus/src/Test.c
+++ b/sandbox/plc4c/drivers/modbus/src/driver_modbus.c
@@ -17,3 +17,12 @@
   under the License.
 */
 
+#include <stdlib.h>
+#include <plc4c/spi/types_private.h>
+#include "plc4c/driver/modbus.h"
+
+plc4c_driver *plc4c_driver_modbus_create() {
+    plc4c_driver* driver = (plc4c_driver*) malloc(sizeof(plc4c_driver));
+    return driver;
+}
+
diff --git a/sandbox/plc4c/drivers/s7/CMakeLists.txt b/sandbox/plc4c/drivers/s7/CMakeLists.txt
index 56c0025..dd84010 100644
--- a/sandbox/plc4c/drivers/s7/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/s7/CMakeLists.txt
@@ -17,12 +17,14 @@
   under the License.
 ]]
 
+include_directories("include" "../../api/include" "../../spi/include")
+
 # Add the sources
 file(GLOB sources "src/*.c")
 
 # Add the generated sources
 file(GLOB generatedSources "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/s7/src/main/c/*.c")
 
-add_library(plc4c-drivers-s7 ${sources} ${generatedSources})
+add_library(plc4c-driver-s7 ${sources} ${generatedSources})
 
-target_link_libraries (plc4c-drivers-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
+target_link_libraries (plc4c-driver-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/spi/src/connection.c b/sandbox/plc4c/drivers/s7/include/plc4c/driver/s7.h
similarity index 72%
copy from sandbox/plc4c/spi/src/connection.c
copy to sandbox/plc4c/drivers/s7/include/plc4c/driver/s7.h
index 5ceceb3..82cbff2 100644
--- a/sandbox/plc4c/spi/src/connection.c
+++ b/sandbox/plc4c/drivers/s7/include/plc4c/driver/s7.h
@@ -16,15 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#ifndef PLC4C_DRIVER_S7_H_
+#define PLC4C_DRIVER_S7_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-#include "../../api/include/plc4c/connection.h"
-#include "../include/plc4c/types_private.h"
+#include <plc4c/types.h>
 
-return_code plc4c_connection_disconnect(plc4c_connection *connection) {
-    return OK;
-}
+plc4c_driver *plc4c_driver_s7_create();
 
-char* plc4c_connection_get_connection_string(plc4c_connection *connection) {
-    return connection->connection_string;
+#ifdef __cplusplus
 }
-
+#endif
+#endif //PLC4C_DRIVER_S7_H_
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/src/Test.c b/sandbox/plc4c/drivers/s7/src/driver_s7.c
similarity index 78%
copy from sandbox/plc4c/drivers/s7/src/Test.c
copy to sandbox/plc4c/drivers/s7/src/driver_s7.c
index a031845..5bcc2b0 100644
--- a/sandbox/plc4c/drivers/s7/src/Test.c
+++ b/sandbox/plc4c/drivers/s7/src/driver_s7.c
@@ -17,3 +17,12 @@
   under the License.
 */
 
+#include <stdlib.h>
+#include <plc4c/spi/types_private.h>
+#include "plc4c/driver/s7.h"
+
+plc4c_driver *plc4c_driver_s7_create() {
+    plc4c_driver* driver = (plc4c_driver*) malloc(sizeof(plc4c_driver));
+    return driver;
+}
+
diff --git a/sandbox/plc4c/examples/hello-world/CMakeLists.txt b/sandbox/plc4c/drivers/simulated/CMakeLists.txt
similarity index 80%
copy from sandbox/plc4c/examples/hello-world/CMakeLists.txt
copy to sandbox/plc4c/drivers/simulated/CMakeLists.txt
index 30e9a30..2cd4ac9 100644
--- a/sandbox/plc4c/examples/hello-world/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/simulated/CMakeLists.txt
@@ -17,11 +17,11 @@
   under the License.
 ]]
 
-#include_directories("../../includes")
+include_directories("include" "../../api/include" "../../spi/include")
 
+# Add the sources
 file(GLOB sources "src/*.c")
 
-add_executable(plc4c-examples-hello-world ${sources} src/hello_world.c)
+add_library(plc4c-driver-simulated ${sources})
 
-target_link_libraries (plc4c-examples-hello-world
-        plc4c-spi)
\ No newline at end of file
+target_link_libraries (plc4c-driver-simulated ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/spi/src/connection.c b/sandbox/plc4c/drivers/simulated/include/plc4c/driver/simulated.h
similarity index 72%
copy from sandbox/plc4c/spi/src/connection.c
copy to sandbox/plc4c/drivers/simulated/include/plc4c/driver/simulated.h
index 5ceceb3..7077551 100644
--- a/sandbox/plc4c/spi/src/connection.c
+++ b/sandbox/plc4c/drivers/simulated/include/plc4c/driver/simulated.h
@@ -16,15 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#ifndef PLC4C_DRIVER_S7_H_
+#define PLC4C_DRIVER_S7_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-#include "../../api/include/plc4c/connection.h"
-#include "../include/plc4c/types_private.h"
+#include <plc4c/types.h>
 
-return_code plc4c_connection_disconnect(plc4c_connection *connection) {
-    return OK;
-}
+plc4c_driver *plc4c_driver_simulated_create();
 
-char* plc4c_connection_get_connection_string(plc4c_connection *connection) {
-    return connection->connection_string;
+#ifdef __cplusplus
 }
-
+#endif
+#endif //PLC4C_DRIVER_S7_H_
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/src/Test.c b/sandbox/plc4c/drivers/simulated/src/driver_simulated.c
similarity index 76%
rename from sandbox/plc4c/drivers/s7/src/Test.c
rename to sandbox/plc4c/drivers/simulated/src/driver_simulated.c
index a031845..7614980 100644
--- a/sandbox/plc4c/drivers/s7/src/Test.c
+++ b/sandbox/plc4c/drivers/simulated/src/driver_simulated.c
@@ -17,3 +17,12 @@
   under the License.
 */
 
+#include <stdlib.h>
+#include <plc4c/spi/types_private.h>
+#include "plc4c/driver/simulated.h"
+
+plc4c_driver *plc4c_driver_simulated_create() {
+    plc4c_driver* driver = (plc4c_driver*) malloc(sizeof(plc4c_driver));
+    return driver;
+}
+
diff --git a/sandbox/plc4c/examples/hello-world/CMakeLists.txt b/sandbox/plc4c/examples/hello-world/CMakeLists.txt
index 30e9a30..7f094ad 100644
--- a/sandbox/plc4c/examples/hello-world/CMakeLists.txt
+++ b/sandbox/plc4c/examples/hello-world/CMakeLists.txt
@@ -17,11 +17,11 @@
   under the License.
 ]]
 
-#include_directories("../../includes")
+include_directories("../../api/include" "../../drivers/simulated/include")
 
 file(GLOB sources "src/*.c")
 
 add_executable(plc4c-examples-hello-world ${sources} src/hello_world.c)
 
 target_link_libraries (plc4c-examples-hello-world
-        plc4c-spi)
\ No newline at end of file
+        plc4c-spi plc4c-driver-simulated)
\ No newline at end of file
diff --git a/sandbox/plc4c/examples/hello-world/src/hello_world.c b/sandbox/plc4c/examples/hello-world/src/hello_world.c
index 1768792..010a271 100644
--- a/sandbox/plc4c/examples/hello-world/src/hello_world.c
+++ b/sandbox/plc4c/examples/hello-world/src/hello_world.c
@@ -17,7 +17,8 @@
  * under the License.
  */
 #include <stdio.h>
-#include "../../../api/include/plc4c.h"
+#include <plc4c.h>
+#include <plc4c/driver/simulated.h>
 
 void onGlobalConnectionSuccess(plc4c_connection *connection) {
     printf("Connected to %s", plc4c_connection_get_connection_string(connection));
@@ -46,6 +47,13 @@ int main() {
         return -1;
     }
 
+    // Manually register the "simulated" driver with the system.
+    plc4c_driver *simulatedDriver = plc4c_driver_simulated_create();
+    result = plc4c_system_add_driver(simulatedDriver);
+    if (result != OK) {
+        return -1;
+    }
+
     // Initialize the plc4c_system (loading of drivers, setting up other stuff, ...)
     result = plc4c_system_init(system);
     if (result != OK) {
diff --git a/sandbox/plc4c/spi/CMakeLists.txt b/sandbox/plc4c/spi/CMakeLists.txt
index d620594..d006973 100644
--- a/sandbox/plc4c/spi/CMakeLists.txt
+++ b/sandbox/plc4c/spi/CMakeLists.txt
@@ -17,7 +17,7 @@
   under the License.
 ]]
 
-include_directories("include")
+include_directories("include" "../api/include")
 
 file(GLOB sources "src/*.c")
 
diff --git a/sandbox/plc4c/spi/include/plc4c/types_private.h b/sandbox/plc4c/spi/include/plc4c/spi/types_private.h
similarity index 97%
rename from sandbox/plc4c/spi/include/plc4c/types_private.h
rename to sandbox/plc4c/spi/include/plc4c/spi/types_private.h
index cc2104f..afe3c83 100644
--- a/sandbox/plc4c/spi/include/plc4c/types_private.h
+++ b/sandbox/plc4c/spi/include/plc4c/spi/types_private.h
@@ -19,6 +19,8 @@
 #ifndef PLC4C_SPI_TYPES_PRIVATE_H_
 #define PLC4C_SPI_TYPES_PRIVATE_H_
 
+#include <plc4c/types.h>
+
 struct plc4c_system_t {
   /* drivers */
 
diff --git a/sandbox/plc4c/spi/src/connection.c b/sandbox/plc4c/spi/src/connection.c
index 5ceceb3..90390f8 100644
--- a/sandbox/plc4c/spi/src/connection.c
+++ b/sandbox/plc4c/spi/src/connection.c
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#include "../../api/include/plc4c/connection.h"
-#include "../include/plc4c/types_private.h"
+#include <plc4c/connection.h>
+#include "plc4c/spi/types_private.h"
 
 return_code plc4c_connection_disconnect(plc4c_connection *connection) {
     return OK;
diff --git a/sandbox/plc4c/spi/src/system.c b/sandbox/plc4c/spi/src/system.c
index 1bad2d1..8edbddd 100644
--- a/sandbox/plc4c/spi/src/system.c
+++ b/sandbox/plc4c/spi/src/system.c
@@ -18,8 +18,8 @@
  */
 
 #include <stdlib.h>
-#include "../../api/include/plc4c/system.h"
-#include "../include/plc4c/types_private.h"
+#include <plc4c/system.h>
+#include "plc4c/spi/types_private.h"
 
 return_code plc4c_system_create(plc4c_system **system) {
     return OK;
@@ -64,6 +64,10 @@ void plc4c_system_set_on_loop_error(plc4c_system *system,
 
 }
 
+return_code plc4c_system_add_driver(plc4c_driver *driver) {
+    return OK;
+}
+
 return_code plc4c_system_init(plc4c_system *system) {
     return OK;
 }
diff --git a/sandbox/plc4c/spi/src/types.c b/sandbox/plc4c/spi/src/types.c
index a3c7432..301aa36 100644
--- a/sandbox/plc4c/spi/src/types.c
+++ b/sandbox/plc4c/spi/src/types.c
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#include "../../api/include/plc4c/types.h"
-#include "../include/plc4c/types_private.h"
+#include <plc4c/types.h>
+#include "plc4c/spi/types_private.h"
 
 char *plc4c_return_code_to_message(return_code err) {
     return "hurz";