├── .clang-format
├── .github
├── ISSUE_TEMPLATE.md
└── workflows
│ ├── check.yml
│ ├── ci.yml
│ └── issue-translator.yaml
├── .gitignore
├── .gitkeep
├── .gitmodules
├── CMakeLists.txt
├── Install-dependencies.md
├── LICENSE
├── README-CN.md
├── README.md
├── cmake
├── aarch64-linux-gnu.cmake
├── arm-linux-gnueabi.cmake
├── arm-linux-gnueabihf.cmake
├── cross.cmake
├── neuron-config.cmake
├── neuron-version.cmake
└── x86_64-linux-gnu.cmake
├── codecov.yaml
├── create_cov_report.sh
├── default_plugins.json
├── deploy
└── charts
│ └── neuron
│ ├── Chart.yaml
│ ├── README.md
│ ├── templates
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── pvc.yaml
│ ├── svc.yaml
│ ├── tests
│ │ └── test-connection.yaml
│ └── tls-secrets.yaml
│ └── values.yaml
├── dev.conf
├── docs
└── pictures
│ ├── neuron-arch-overview.png
│ ├── neuron-bus-topo.png
│ ├── neuron-dataflow.png
│ ├── neuron-final.png
│ └── neuron-layers.png
├── include
└── neuron
│ ├── adapter.h
│ ├── adapter_info.h
│ ├── connection
│ ├── mqtt_client.h
│ ├── neu_connection.h
│ ├── neu_connection_eth.h
│ └── neu_smart_link.h
│ ├── datalayers
│ └── flight_sql_client.h
│ ├── define.h
│ ├── errcodes.h
│ ├── event
│ └── event.h
│ ├── json
│ ├── json.h
│ ├── neu_json_driver.h
│ ├── neu_json_error.h
│ ├── neu_json_fn.h
│ ├── neu_json_mqtt.h
│ ├── neu_json_param.h
│ ├── neu_json_rw.h
│ └── neu_json_scan.h
│ ├── metrics.h
│ ├── msg.h
│ ├── neuron.h
│ ├── otel
│ └── otel_manager.h
│ ├── persist
│ ├── json
│ │ └── persist_json_plugin.h
│ └── persist.h
│ ├── plugin.h
│ ├── tag.h
│ ├── tag_sort.h
│ ├── type.h
│ └── utils
│ ├── asprintf.h
│ ├── async_queue.h
│ ├── base64.h
│ ├── cid.h
│ ├── http.h
│ ├── http_handler.h
│ ├── log.h
│ ├── neu_jwt.h
│ ├── protocol_buf.h
│ ├── rolling_counter.h
│ ├── set.h
│ ├── time.h
│ ├── utarray.h
│ ├── utextend.h
│ ├── uthash.h
│ ├── utlist.h
│ └── zlog.h
├── install_dependencies.sh
├── jwt_encode.py
├── neuron.conf
├── neuron.json
├── neuron.key
├── neuron.pem
├── package-sdk.sh
├── persistence
├── 0000_2.2.0_initial.sql
├── 0001_2.3.0_users.sql
├── 0002_2.3.0_node_cache.sql
├── 0010_2.4.0_subscription_params.sql
├── 0020_2.4.0_static_tag.sql
├── 0030_2.4.0_ekuiper_node.sql
├── 0032_2.4.4_plugin_name.sql
├── 0033_2.4.5_mqtt_upload_topic.sql
├── 0040_2.5.0_template.sql
├── 0041_2.5.0_modbus_tmode.sql
├── 0042_2.5.3_fx_rename.sql
├── 0050_2.6.0_virtual_license.sql
├── 0060_2.7.3_tag_name_length.sql
├── 0070_2.7.5_tag_time_type.sql
├── 0080_2.9.0_tag_bias.sql
├── 0110_2.11.0_tag.sql
├── 0111_2.11.0_sub.sql
└── 0112_2.12.0_array.sql
├── plugins
├── datalayers
│ ├── CMakeLists.txt
│ ├── datalayers.json
│ ├── datalayers_config.c
│ ├── datalayers_config.h
│ ├── datalayers_handle.c
│ ├── datalayers_handle.h
│ ├── datalayers_plugin.c
│ ├── datalayers_plugin.h
│ ├── datalayers_plugin_intf.c
│ └── datalayers_plugin_intf.h
├── ekuiper
│ ├── CMakeLists.txt
│ ├── ekuiper.json
│ ├── json_rw.c
│ ├── json_rw.h
│ ├── plugin_ekuiper.c
│ ├── plugin_ekuiper.h
│ ├── read_write.c
│ └── read_write.h
├── file
│ ├── CMakeLists.txt
│ ├── file.json
│ └── file_plugin.c
├── modbus
│ ├── CMakeLists.txt
│ ├── modbus-rtu.json
│ ├── modbus-tcp.json
│ ├── modbus.c
│ ├── modbus.h
│ ├── modbus_point.c
│ ├── modbus_point.h
│ ├── modbus_req.c
│ ├── modbus_req.h
│ ├── modbus_rtu.c
│ ├── modbus_stack.c
│ ├── modbus_stack.h
│ └── modbus_tcp.c
├── monitor
│ ├── CMakeLists.txt
│ ├── monitor.c
│ ├── monitor.h
│ ├── monitor.json
│ ├── monitor_config.c
│ ├── monitor_config.h
│ ├── mqtt_handle.c
│ └── mqtt_handle.h
├── mqtt
│ ├── CMakeLists.txt
│ ├── aws-iot.json
│ ├── aws_iot_plugin.c
│ ├── azure-iot.json
│ ├── azure_iot_plugin.c
│ ├── mqtt.json
│ ├── mqtt_config.c
│ ├── mqtt_config.h
│ ├── mqtt_handle.c
│ ├── mqtt_handle.h
│ ├── mqtt_plugin.c
│ ├── mqtt_plugin.h
│ ├── mqtt_plugin_intf.c
│ ├── mqtt_plugin_intf.h
│ ├── ptformat.pb-c.c
│ ├── ptformat.pb-c.h
│ ├── ptformat.proto
│ ├── schema.c
│ └── schema.h
└── restful
│ ├── adapter_handle.c
│ ├── adapter_handle.h
│ ├── cid_handle.c
│ ├── cid_handle.h
│ ├── datalayers_handle.c
│ ├── datalayers_handle.h
│ ├── datatag_handle.c
│ ├── datatag_handle.h
│ ├── global_config_handle.c
│ ├── global_config_handle.h
│ ├── group_config_handle.c
│ ├── group_config_handle.h
│ ├── handle.c
│ ├── handle.h
│ ├── log_handle.c
│ ├── log_handle.h
│ ├── metric_handle.c
│ ├── metric_handle.h
│ ├── normal_handle.c
│ ├── normal_handle.h
│ ├── otel_handle.c
│ ├── otel_handle.h
│ ├── plugin_handle.c
│ ├── plugin_handle.h
│ ├── rest.c
│ ├── rest.h
│ ├── rw_handle.c
│ ├── rw_handle.h
│ ├── scan_handle.c
│ ├── scan_handle.h
│ ├── system_handle.c
│ ├── system_handle.h
│ ├── user.c
│ ├── user.h
│ ├── version_handle.c
│ └── version_handle.h
├── sdk-install.sh
├── sdk-zlog.conf
├── simulator
├── CMakeLists.txt
├── modbus_s.c
├── modbus_s.h
├── modbus_simulator.c
├── modbus_tty_simulator.c
└── otel_server.py
├── src
├── adapter
│ ├── adapter.c
│ ├── adapter_internal.h
│ ├── app
│ │ ├── app.c
│ │ └── app_internal.h
│ ├── driver
│ │ ├── cache.c
│ │ ├── cache.h
│ │ ├── driver.c
│ │ └── driver_internal.h
│ ├── msg_q.c
│ ├── msg_q.h
│ ├── storage.c
│ └── storage.h
├── argparse.c
├── argparse.h
├── base
│ ├── group.c
│ ├── group.h
│ ├── metrics.c
│ ├── msg.c
│ ├── msg_internal.h
│ ├── neu_plugin_common.c
│ ├── tag.c
│ └── tag_sort.c
├── connection
│ ├── connection.c
│ ├── connection_eth.c
│ ├── mqtt_client.c
│ └── smart_link.c
├── core
│ ├── manager.c
│ ├── manager.h
│ ├── manager_internal.c
│ ├── manager_internal.h
│ ├── node_manager.c
│ ├── node_manager.h
│ ├── plugin_manager.c
│ ├── plugin_manager.h
│ ├── storage.c
│ ├── storage.h
│ ├── subscribe.c
│ └── subscribe.h
├── daemon.c
├── daemon.h
├── event
│ ├── event_linux.c
│ └── event_unix.c
├── main.c
├── otel
│ ├── common.pb-c.c
│ ├── common.pb-c.h
│ ├── otel_manager.c
│ ├── resource.pb-c.c
│ ├── resource.pb-c.h
│ ├── trace.pb-c.c
│ └── trace.pb-c.h
├── parser
│ ├── neu_json_cid.c
│ ├── neu_json_cid.h
│ ├── neu_json_datalayers.c
│ ├── neu_json_datalayers.h
│ ├── neu_json_driver.c
│ ├── neu_json_error.c
│ ├── neu_json_fn.c
│ ├── neu_json_global_config.c
│ ├── neu_json_global_config.h
│ ├── neu_json_group_config.c
│ ├── neu_json_group_config.h
│ ├── neu_json_log.c
│ ├── neu_json_log.h
│ ├── neu_json_login.c
│ ├── neu_json_login.h
│ ├── neu_json_mqtt.c
│ ├── neu_json_node.c
│ ├── neu_json_node.h
│ ├── neu_json_otel.c
│ ├── neu_json_otel.h
│ ├── neu_json_plugin.c
│ ├── neu_json_plugin.h
│ ├── neu_json_rw.c
│ ├── neu_json_scan.c
│ ├── neu_json_system.c
│ ├── neu_json_system.h
│ ├── neu_json_tag.c
│ └── neu_json_tag.h
├── persist
│ ├── datalayers
│ │ ├── client_example.c
│ │ ├── flight_sql_client.cpp
│ │ └── flight_sql_client.h
│ ├── json
│ │ └── persist_json_plugin.c
│ ├── persist.c
│ ├── persist_impl.h
│ ├── sqlite.c
│ └── sqlite.h
└── utils
│ ├── asprintf.c
│ ├── async_queue.c
│ ├── base64.c
│ ├── cid.c
│ ├── http.c
│ ├── http_handler.c
│ ├── json.c
│ ├── log.c
│ └── neu_jwt.c
├── tests
├── ft
│ ├── app
│ │ ├── __init__.py
│ │ ├── test_app.py
│ │ ├── test_azure.py
│ │ ├── test_ekuiper.py
│ │ └── test_mqtt.py
│ ├── conftest.py
│ ├── driver
│ │ ├── __init__.py
│ │ ├── test_driver.py
│ │ └── test_modbus.py
│ ├── group
│ │ ├── __init__.py
│ │ └── test_group.py
│ ├── http_api
│ │ ├── __init__.py
│ │ ├── test_http_api.py
│ │ └── test_read_paginate.py
│ ├── log
│ │ ├── __init__.py
│ │ └── test_log.py
│ ├── login
│ │ ├── __init__.py
│ │ ├── neuron.json
│ │ ├── sub_filter_error.json
│ │ ├── test_launch.py
│ │ └── test_login.py
│ ├── metrics
│ │ └── test_metrics.py
│ ├── neuron
│ │ ├── __init__.py
│ │ ├── api.py
│ │ ├── common.py
│ │ ├── config.py
│ │ ├── data
│ │ │ ├── __init__.py
│ │ │ ├── ca.pem
│ │ │ ├── client.key
│ │ │ ├── client.pem
│ │ │ ├── server.key
│ │ │ └── server.pem
│ │ ├── error.py
│ │ ├── mqtt
│ │ │ ├── __init__.py
│ │ │ ├── broker.py
│ │ │ └── client.py
│ │ └── process.py
│ ├── node
│ │ ├── __init__.py
│ │ └── test_node.py
│ ├── persist
│ │ ├── __init__.py
│ │ └── test_persist.py
│ ├── plugin
│ │ ├── __init__.py
│ │ ├── plugin_data1.txt
│ │ ├── plugin_data2.txt
│ │ ├── test_library_data.json
│ │ └── test_plugin.py
│ ├── pytest.ini
│ ├── setup.py
│ └── tag
│ │ ├── __init__.py
│ │ ├── modbus-tcp.json
│ │ └── test_tag.py
├── plugins
│ ├── c1
│ │ ├── CMakeLists.txt
│ │ ├── c1.c
│ │ ├── c1.h
│ │ ├── c1.json
│ │ ├── c1_2.c
│ │ ├── c1_2_v_err.c
│ │ └── c1_v_err.c
│ ├── s1
│ │ ├── CMakeLists.txt
│ │ ├── s1.c
│ │ ├── s1.h
│ │ ├── s1.json
│ │ └── s1_2.c
│ └── sc1
│ │ ├── CMakeLists.txt
│ │ ├── sc1.c
│ │ ├── sc1.h
│ │ ├── sc1.json
│ │ └── sc1_2.c
└── ut
│ ├── CMakeLists.txt
│ ├── README.md
│ ├── async_queue_test.cc
│ ├── base64_test.cc
│ ├── cid_test.cc
│ ├── common_test.cc
│ ├── http_test.cc
│ ├── json_test.cc
│ ├── jwt_test.cc
│ ├── modbus_test.cc
│ ├── mqtt_client_test.cc
│ ├── mqtt_schema_test.cc
│ ├── rolling_counter_test.cc
│ ├── serverBMS_3_test.cid
│ └── tag_sort_test.cc
├── version
├── version.h.in
└── zlog.conf
/.clang-format:
--------------------------------------------------------------------------------
1 | BasedOnStyle: WebKit
2 | UseTab: Never
3 | IndentWidth: 4
4 | ColumnLimit: 80
5 | AlignConsecutiveAssignments: true
6 | AlignConsecutiveDeclarations: true
7 | AlignTrailingComments: true
8 | AlignEscapedNewlinesLeft: true
9 | AlignAfterOpenBracket: true
10 | PointerAlignment: Right
11 | # AlwaysBreakAfterReturnType: Inline
12 | SpaceAfterCStyleCast: true
13 | AllowShortFunctionsOnASingleLine: Inline
14 | BreakBeforeBinaryOperators: None
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | # Issue Template
2 |
3 | Please fill in the issue as required.
4 |
5 | * System:
6 | * Architecture:
7 | * Version:
8 | * Problem Description:
9 | * Log Information:
10 |
--------------------------------------------------------------------------------
/.github/workflows/issue-translator.yaml:
--------------------------------------------------------------------------------
1 | name: Translate Issue from Chinese to English
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | issue_number:
7 | description: 'The issue number to translate'
8 | required: true
9 | type: string
10 | issues:
11 | types: [opened]
12 |
13 | jobs:
14 | translate:
15 | runs-on: ubuntu-latest
16 | permissions:
17 | issues: write # Grant permission to edit issues
18 | steps:
19 | - uses: emqx/translate-issue-action@ee63ec619dfc5808ee2093dba93dfd7ac3beb437 # v1.0.2
20 | with:
21 | issue_number: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.issue_number || github.event.issue.number }}
22 | gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.un~
3 | *.swp
4 | tags
5 | build
6 | _build
7 | compile_commands.json
8 | .vscode
9 | *.log
10 | *.tar.gz
11 | ft/reports
12 | include/csptr/
13 | include/neuron/version.h
14 | __pycache__
15 | tmp
16 | *.deb
17 | *.rpm
18 | neuron-sdk
19 | .vscode
20 | log.html
21 | output.xml
22 | report.html
23 | *.cache
--------------------------------------------------------------------------------
/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/.gitkeep
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/.gitmodules
--------------------------------------------------------------------------------
/cmake/aarch64-linux-gnu.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_SYSTEM_NAME Linux)
2 | set(COMPILER_PREFIX aarch64-linux-gnu)
3 | set(CMAKE_SYSTEM_PROCESSOR aarch64)
4 | set(LIBRARY_DIR /home/neuron/main/libs)
5 |
6 | set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
7 | set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
8 | set(CMAKE_AR ${COMPILER_PREFIX}-ar)
9 | set(CMAKE_LINKER ${COMPILER_PREFIX}-ld)
10 | set(CMAKE_NM ${COMPILER_PREFIX}-nm)
11 | set(CMAKE_OBJDUMP ${COMPILER_PREFIX}-objdump)
12 | set(CMAKE_RANLIB ${COMPILER_PREFIX}-ranlib)
13 | set(CMAKE_STAGING_PREFIX ${LIBRARY_DIR}/${COMPILER_PREFIX})
14 | set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
15 |
16 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/include)
17 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/openssl/include)
18 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_STAGING_PREFIX})
19 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
20 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
21 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
22 | link_directories(${CMAKE_STAGING_PREFIX})
23 |
24 | file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
--------------------------------------------------------------------------------
/cmake/arm-linux-gnueabi.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_SYSTEM_NAME Linux)
2 | set(COMPILER_PREFIX arm-linux-gnueabi)
3 | set(CMAKE_SYSTEM_PROCESSOR armv5tejl)
4 | set(LIBRARY_DIR /home/neuron/main/libs)
5 |
6 | set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
7 | set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
8 | set(CMAKE_AR ${COMPILER_PREFIX}-ar)
9 | set(CMAKE_LINKER ${COMPILER_PREFIX}-ld)
10 | set(CMAKE_NM ${COMPILER_PREFIX}-nm)
11 | set(CMAKE_OBJDUMP ${COMPILER_PREFIX}-objdump)
12 | set(CMAKE_RANLIB ${COMPILER_PREFIX}-ranlib)
13 | set(CMAKE_STAGING_PREFIX ${LIBRARY_DIR}/${COMPILER_PREFIX})
14 | set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
15 |
16 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/include)
17 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/openssl/include)
18 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_STAGING_PREFIX})
19 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
20 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
21 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
22 | link_directories(${CMAKE_STAGING_PREFIX})
23 |
24 | file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
25 |
--------------------------------------------------------------------------------
/cmake/arm-linux-gnueabihf.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_SYSTEM_NAME Linux)
2 | set(COMPILER_PREFIX arm-linux-gnueabihf)
3 | set(CMAKE_SYSTEM_PROCESSOR armv7l)
4 | set(LIBRARY_DIR /home/neuron/main/libs)
5 |
6 | set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
7 | set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
8 | set(CMAKE_AR ${COMPILER_PREFIX}-ar)
9 | set(CMAKE_LINKER ${COMPILER_PREFIX}-ld)
10 | set(CMAKE_NM ${COMPILER_PREFIX}-nm)
11 | set(CMAKE_OBJDUMP ${COMPILER_PREFIX}-objdump)
12 | set(CMAKE_RANLIB ${COMPILER_PREFIX}-ranlib)
13 | set(CMAKE_STAGING_PREFIX ${LIBRARY_DIR}/${COMPILER_PREFIX})
14 | set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
15 |
16 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/include)
17 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/openssl/include)
18 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_STAGING_PREFIX})
19 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
20 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
21 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
22 | link_directories(${CMAKE_STAGING_PREFIX})
23 |
24 | file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
--------------------------------------------------------------------------------
/cmake/cross.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_SYSTEM_NAME Linux)
2 |
3 | set(CMAKE_C_COMPILER ${TOOL_DIR}/${COMPILER_PREFIX}-gcc)
4 | set(CMAKE_CXX_COMPILER ${TOOL_DIR}/${COMPILER_PREFIX}-g++)
5 | set(CMAKE_AR ${TOOL_DIR}/${COMPILER_PREFIX}-ar)
6 | set(CMAKE_LINKER ${TOOL_DIR}/${COMPILER_PREFIX}-ld)
7 | set(CMAKE_NM ${TOOL_DIR}/${COMPILER_PREFIX}-nm)
8 | set(CMAKE_OBJDUMP ${TOOL_DIR}/${COMPILER_PREFIX}-objdump)
9 | set(CMAKE_RANLIB ${TOOL_DIR}/${COMPILER_PREFIX}-ranlib)
10 | set(CMAKE_STAGING_PREFIX ${LIBRARY_DIR}/${COMPILER_PREFIX})
11 | set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
12 |
13 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/include)
14 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/openssl/include)
15 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_STAGING_PREFIX})
16 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
17 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
18 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
19 | link_directories(${CMAKE_STAGING_PREFIX})
20 |
21 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "mips32")
22 | link_libraries(atomic)
23 | endif()
24 |
25 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
26 | link_libraries(atomic)
27 | endif()
28 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
29 | link_libraries(atomic)
30 | endif()
31 |
--------------------------------------------------------------------------------
/cmake/neuron-config.cmake:
--------------------------------------------------------------------------------
1 | find_path(Neuron_INCLUDE_DIR neuron.h ${CMAKE_PREFIX_PATH}/include/neuron)
2 | find_library(Neuron_LIBRARY NAMES neuron-base PATHS ${CMAKE_PREFIX_PATH}/lib)
3 | if (Neuron_INCLUDE_DIR AND Neuron_LIBRARY)
4 | set(Neuron_FOUND TRUE)
5 | endif()
--------------------------------------------------------------------------------
/cmake/neuron-version.cmake:
--------------------------------------------------------------------------------
1 | set(HEADER_FILE ${CMAKE_CURRENT_LIST_DIR}/../include/neuron/version.h)
2 | set(HEADER_TMPL ${CMAKE_CURRENT_LIST_DIR}/../version.h.in)
3 | set(VERSION_FILE ${CMAKE_CURRENT_LIST_DIR}/../version)
4 |
5 | # versions
6 | file(STRINGS ${VERSION_FILE} NEURON_VERSION)
7 | string(REPLACE "." ";" VERSION_LIST ${NEURON_VERSION})
8 | list(GET VERSION_LIST 0 NEURON_VERSION_MAJOR)
9 | list(GET VERSION_LIST 1 NEURON_VERSION_MINOR)
10 | list(GET VERSION_LIST 2 NEURON_VERSION_MICRO)
11 |
12 | # git revisions
13 | execute_process(COMMAND git log --pretty=format:'%h' -n 1
14 | OUTPUT_VARIABLE GIT_REV
15 | ERROR_QUIET)
16 |
17 | if ("${GIT_REV}" STREQUAL "")
18 | set(GIT_REV "N/A")
19 | set(GIT_DIFF "")
20 | set(GIT_TAG "N/A")
21 | set(GIT_BRANCH "N/A")
22 | else()
23 | execute_process(COMMAND bash -c "git diff --quiet --exit-code || echo +dirty"
24 | OUTPUT_VARIABLE GIT_DIFF)
25 | execute_process(COMMAND git describe --exact-match --tags
26 | OUTPUT_VARIABLE GIT_TAG
27 | ERROR_QUIET)
28 | execute_process(COMMAND git rev-parse --abbrev-ref HEAD
29 | OUTPUT_VARIABLE GIT_BRANCH)
30 |
31 | string(STRIP "${GIT_REV}" GIT_REV)
32 | string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
33 | string(STRIP "${GIT_DIFF}" GIT_DIFF)
34 | string(STRIP "${GIT_TAG}" GIT_TAG)
35 | string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
36 | endif()
37 |
38 | # build date
39 | string(TIMESTAMP NEURON_BUILD_DATE "%Y-%m-%d")
40 |
41 | # generate the header file
42 | configure_file(${HEADER_TMPL} ${HEADER_FILE} @ONLY)
43 |
--------------------------------------------------------------------------------
/cmake/x86_64-linux-gnu.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_SYSTEM_NAME Linux)
2 | set(COMPILER_PREFIX x86_64-linux-gnu)
3 | set(CMAKE_SYSTEM_PROCESSOR x86_64)
4 | set(LIBRARY_DIR /home/neuron/main/libs)
5 |
6 | set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
7 | set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
8 | set(CMAKE_AR ${COMPILER_PREFIX}-ar)
9 | set(CMAKE_LINKER ${COMPILER_PREFIX}-ld)
10 | set(CMAKE_NM ${COMPILER_PREFIX}-nm)
11 | set(CMAKE_OBJDUMP ${COMPILER_PREFIX}-objdump)
12 | set(CMAKE_RANLIB ${COMPILER_PREFIX}-ranlib)
13 | set(CMAKE_STAGING_PREFIX ${LIBRARY_DIR}/${COMPILER_PREFIX})
14 | set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
15 |
16 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
17 |
18 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-lto")
19 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lto")
20 |
21 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/include)
22 | include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/openssl/include)
23 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_STAGING_PREFIX})
24 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27 | link_directories(${CMAKE_STAGING_PREFIX})
28 |
29 | file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
30 |
--------------------------------------------------------------------------------
/codecov.yaml:
--------------------------------------------------------------------------------
1 | ignore:
2 | - "src/otel/*.pb-c.c"
3 | coverage:
4 | status:
5 | project:
6 | default:
7 | target: auto # the required coverage value
8 | threshold: 0.1% # the leniency in hitting the target
--------------------------------------------------------------------------------
/default_plugins.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "libplugin-mqtt.so",
4 | "libplugin-aws-iot.so",
5 | "libplugin-azure-iot.so",
6 | "libplugin-ekuiper.so",
7 | "libplugin-modbus-tcp.so",
8 | "libplugin-modbus-rtu.so",
9 | "libplugin-file.so"
10 | ]
11 | }
--------------------------------------------------------------------------------
/deploy/charts/neuron/Chart.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v2
2 | name: neuron
3 | description: A Helm chart for Kubernetes
4 |
5 | # A chart can be either an 'application' or a 'library' chart.
6 | #
7 | # Application charts are a collection of templates that can be packaged into versioned archives
8 | # to be deployed.
9 | #
10 | # Library charts provide useful utilities or functions for the chart developer. They're included as
11 | # a dependency of application charts to inject those utilities and functions into the rendering
12 | # pipeline. Library charts do not define any templates and therefore cannot be deployed.
13 | type: application
14 |
15 | # This is the chart version. This version number should be incremented each time you make changes
16 | # to the chart and its templates, including the app version.
17 | # Versions are expected to follow Semantic Versioning (https://semver.org/)
18 | version: 1.0.6
19 |
20 | # This is the version number of the application being deployed. This version number should be
21 | # incremented each time you make changes to the application. Versions are not expected to
22 | # follow Semantic Versioning. They should reflect the version the application is using.
23 | # It is recommended to use it with quotes.
24 | appVersion: 2.2.8
25 |
--------------------------------------------------------------------------------
/deploy/charts/neuron/templates/_helpers.tpl:
--------------------------------------------------------------------------------
1 | {{/*
2 | Expand the name of the chart.
3 | */}}
4 | {{- define "neuron.name" -}}
5 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6 | {{- end }}
7 |
8 | {{/*
9 | Create a default fully qualified app name.
10 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11 | If release name contains chart name it will be used as a full name.
12 | */}}
13 | {{- define "neuron.fullname" -}}
14 | {{- if .Values.fullnameOverride }}
15 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16 | {{- else }}
17 | {{- $name := default .Chart.Name .Values.nameOverride }}
18 | {{- if contains $name .Release.Name }}
19 | {{- .Release.Name | trunc 63 | trimSuffix "-" }}
20 | {{- else }}
21 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22 | {{- end }}
23 | {{- end }}
24 | {{- end }}
25 |
26 | {{/*
27 | Create chart name and version as used by the chart label.
28 | */}}
29 | {{- define "neuron.chart" -}}
30 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31 | {{- end }}
32 |
33 | {{/*
34 | Common labels
35 | */}}
36 | {{- define "neuron.labels" -}}
37 | helm.sh/chart: {{ include "neuron.chart" . }}
38 | {{ include "neuron.selectorLabels" . }}
39 | {{- if .Chart.AppVersion }}
40 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41 | {{- end }}
42 | app.kubernetes.io/managed-by: {{ .Release.Service }}
43 | {{- end }}
44 |
45 | {{/*
46 | Selector labels
47 | */}}
48 | {{- define "neuron.selectorLabels" -}}
49 | app.kubernetes.io/name: {{ include "neuron.name" . }}
50 | app.kubernetes.io/instance: {{ .Release.Name }}
51 | {{- end }}
52 |
53 |
54 | {{/*
55 | Get the TLS secret.
56 | */}}
57 | {{- define "neuron.tlsSecretName" -}}
58 | {{- printf "%s-certs" (include "neuron.fullname" .) -}}
59 | {{- end -}}
--------------------------------------------------------------------------------
/deploy/charts/neuron/templates/pvc.yaml:
--------------------------------------------------------------------------------
1 | {{- if $.Values.persistence.enabled }}
2 | {{- $top := . -}}
3 | {{- range $mount := .Values.ekuiperMounts }}
4 | ---
5 | apiVersion: v1
6 | kind: PersistentVolumeClaim
7 | metadata:
8 | name: {{ printf "%s-%s" $.Release.Name (tpl $mount.name $) }}
9 | namespace: {{ $.Release.Namespace }}
10 | annotations:
11 | kubesphere.io/creator: admin
12 | finalizers:
13 | - kubernetes.io/pvc-protection
14 | spec:
15 | accessModes:
16 | - {{ $.Values.persistence.accessMode }}
17 | resources:
18 | requests:
19 | storage: {{ $mount.capacity }}
20 | storageClassName: {{ $.Values.persistence.storageClass }}
21 | {{- end }}
22 | {{- range $mount := .Values.neuronMounts }}
23 | ---
24 | apiVersion: v1
25 | kind: PersistentVolumeClaim
26 | metadata:
27 | name: {{ printf "%s-%s" $.Release.Name (tpl $mount.name $) }}
28 | namespace: {{ $.Release.Namespace }}
29 | annotations:
30 | kubesphere.io/creator: admin
31 | finalizers:
32 | - kubernetes.io/pvc-protection
33 | spec:
34 | accessModes:
35 | - {{ $.Values.persistence.accessMode }}
36 | resources:
37 | requests:
38 | storage: {{ $mount.capacity }}
39 | storageClassName: {{ $.Values.persistence.storageClass }}
40 | {{- end }}
41 | {{- end }}
--------------------------------------------------------------------------------
/deploy/charts/neuron/templates/svc.yaml:
--------------------------------------------------------------------------------
1 | {{- if .Values.service.enabled }}
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: {{ include "neuron.fullname" . }}
6 | namespace: {{ .Release.Namespace }}
7 | labels:
8 | {{- include "neuron.labels" . | nindent 4 }}
9 | {{- if eq .Values.service.type "LoadBalancer" }}
10 | {{- with .Values.service.annotations }}
11 | annotations:
12 | {{- toYaml . | nindent 4 }}
13 | {{- end }}
14 | {{- end }}
15 | spec:
16 | type: {{ .Values.service.type }}
17 | {{- if eq .Values.service.type "LoadBalancer" }}
18 | {{- if .Values.service.loadBalancerIP }}
19 | loadBalancerIP: {{ .Values.service.loadBalancerIP }}
20 | {{- end }}
21 | {{- if .Values.service.loadBalancerSourceRanges }}
22 | loadBalancerSourceRanges: {{- toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }}
23 | {{- end }}
24 | {{- end }}
25 | ports:
26 | - name: {{ .Values.service.ports.web.name }}
27 | port: {{ .Values.service.ports.web.port | default 7000 }}
28 | protocol: TCP
29 | targetPort: web
30 | {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.web)) }}
31 | nodePort: {{ .Values.service.nodePorts.web }}
32 | {{- else if eq .Values.service.type "ClusterIP" }}
33 | nodePort: null
34 | {{- end }}
35 | - name: {{ .Values.service.ports.api.name }}
36 | port: {{ .Values.service.ports.api.port | default 7001 }}
37 | protocol: TCP
38 | targetPort: api
39 | {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.api)) }}
40 | nodePort: {{ .Values.service.nodePorts.api }}
41 | {{- else if eq .Values.service.type "ClusterIP" }}
42 | nodePort: null
43 | {{- end }}
44 | selector:
45 | {{- include "neuron.selectorLabels" . | nindent 4 }}
46 | {{- end }}
--------------------------------------------------------------------------------
/deploy/charts/neuron/templates/tests/test-connection.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Pod
3 | metadata:
4 | name: "{{ include "neuron.fullname" . }}-test-connection"
5 | labels:
6 | {{- include "neuron.labels" . | nindent 4 }}
7 | annotations:
8 | "helm.sh/hook": test
9 | spec:
10 | containers:
11 | - name: wget
12 | image: busybox
13 | command: ['wget']
14 | args: ['{{ include "neuron.fullname" . }}:{{ .Values.service.port }}']
15 | restartPolicy: Never
16 |
--------------------------------------------------------------------------------
/deploy/charts/neuron/templates/tls-secrets.yaml:
--------------------------------------------------------------------------------
1 | {{- if .Values.tls.enabled }}
2 | apiVersion: v1
3 | kind: Secret
4 | metadata:
5 | name: {{ include "neuron.fullname" . }}-certs
6 | namespace: {{ .Release.Namespace }}
7 | labels:
8 | {{- include "neuron.labels" . | nindent 4 }}
9 | type: Opaque
10 | data:
11 | {{- if and .Values.tls.publicKey .Values.tls.privateKey }}
12 | neuron.pem: {{ required "A valid .Values.tls.publicKey entry required!" .Values.tls.publicKey | b64enc | quote }}
13 | neuron.key: {{ required "A valid .Values.tls.privateKey entry required!" .Values.tls.privateKey | b64enc | quote }}
14 | {{- end }}
15 | {{- end }}
--------------------------------------------------------------------------------
/dev.conf:
--------------------------------------------------------------------------------
1 | [global]
2 |
3 | file perms = 666
4 |
5 | [formats]
6 |
7 | stdout_format = "%d:%ms [%V] [%c] %f:%L %m%n"
8 | file_format = "%d:%ms [%V] %f:%L %m%n"
9 | syslog = "
%d(%Y-%m-%dT%T%z) %H neuron[%p]: level=%v msg="[%c] %m" file="%f:%L"%n"
10 |
11 | [rules]
12 |
13 | *.* "./logs/%c.log", 25MB * 1 ~ "./logs/%c.#2r.log"; file_format
14 | *.* >stdout; stdout_format
15 | *.* $remote_syslog,"%V"; syslog
16 |
--------------------------------------------------------------------------------
/docs/pictures/neuron-arch-overview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/docs/pictures/neuron-arch-overview.png
--------------------------------------------------------------------------------
/docs/pictures/neuron-bus-topo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/docs/pictures/neuron-bus-topo.png
--------------------------------------------------------------------------------
/docs/pictures/neuron-dataflow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/docs/pictures/neuron-dataflow.png
--------------------------------------------------------------------------------
/docs/pictures/neuron-final.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/docs/pictures/neuron-final.png
--------------------------------------------------------------------------------
/docs/pictures/neuron-layers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/docs/pictures/neuron-layers.png
--------------------------------------------------------------------------------
/include/neuron/adapter_info.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef ADAPTER_INFO_H
21 | #define ADAPTER_INFO_H
22 |
23 | #include
24 |
25 | #include "adapter.h"
26 | #include "plugin.h"
27 |
28 | typedef struct neu_adapter_info {
29 | const char * name;
30 | void * handle;
31 | neu_plugin_module_t *module;
32 | } neu_adapter_info_t;
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/include/neuron/connection/neu_connection_eth.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_CONNECTION_ETH_H
21 | #define NEURON_CONNECTION_ETH_H
22 |
23 | #include
24 |
25 | #include "define.h"
26 |
27 | // profinet
28 |
29 | typedef struct neu_conn_eth neu_conn_eth_t;
30 |
31 | neu_conn_eth_t *neu_conn_eth_init(const char *interface, void *ctx);
32 | int neu_conn_eth_uninit(neu_conn_eth_t *conn);
33 | int neu_conn_eth_check_interface(const char *interface);
34 | void neu_conn_eth_get_mac(neu_conn_eth_t *conn, uint8_t *mac);
35 | int neu_conn_eth_size();
36 |
37 | typedef void (*neu_conn_eth_msg_callback)(neu_conn_eth_t *conn, void *ctx,
38 | uint16_t protocol, uint16_t n_byte,
39 | uint8_t *bytes, uint8_t src_mac[6]);
40 |
41 | typedef struct neu_conn_eth_sub neu_conn_eth_sub_t;
42 |
43 | neu_conn_eth_sub_t *neu_conn_eth_register(neu_conn_eth_t *conn, uint8_t mac[6],
44 | neu_conn_eth_msg_callback callback);
45 | int neu_conn_eth_unregister(neu_conn_eth_t *conn, neu_conn_eth_sub_t *sub);
46 |
47 | int neu_conn_eth_send(neu_conn_eth_t *conn, uint16_t protocol, uint16_t n_byte,
48 | uint8_t *bytes);
49 |
50 | #endif
--------------------------------------------------------------------------------
/include/neuron/connection/neu_smart_link.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_CONNECTION_SMART_LINK_H
21 | #define NEURON_CONNECTION_SMART_LINK_H
22 |
23 | int neu_conn_smart_link_auto_set(const char *dev_path);
24 |
25 | #endif
--------------------------------------------------------------------------------
/include/neuron/datalayers/flight_sql_client.h:
--------------------------------------------------------------------------------
1 | #ifndef FLIGHT_SQL_CLIENT_H
2 | #define FLIGHT_SQL_CLIENT_H
3 |
4 | #include
5 |
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | typedef enum { INT_TYPE, FLOAT_TYPE, BOOL_TYPE, STRING_TYPE } ValueType;
11 |
12 | typedef union {
13 | int int_value;
14 | float float_value;
15 | bool bool_value;
16 | const char *string_value;
17 | } ValueUnion;
18 |
19 | typedef struct {
20 | const char *node_name;
21 | const char *group_name;
22 | const char *tag;
23 | ValueUnion value;
24 | ValueType value_type;
25 | } datatag;
26 |
27 | typedef struct {
28 | ValueType value_type;
29 | ValueUnion value;
30 | char time[64];
31 | char node_name[128];
32 | char group_name[128];
33 | char tag[128];
34 | } datarow;
35 |
36 | typedef struct {
37 | size_t row_count;
38 | datarow *rows;
39 | } query_result;
40 |
41 | typedef struct Client neu_datalayers_client;
42 |
43 | neu_datalayers_client *client_create(const char *host, int port,
44 | const char *username,
45 | const char *password);
46 |
47 | int client_execute(neu_datalayers_client *client, const char *sql);
48 |
49 | void client_destroy(neu_datalayers_client *client);
50 |
51 | int client_insert(neu_datalayers_client *client, ValueType type, datatag *tags,
52 | size_t tag_count);
53 |
54 | query_result *client_query(neu_datalayers_client *client, ValueType type,
55 | const char *node_name, const char *group_name,
56 | const char *tag);
57 |
58 | void client_query_free(query_result *result);
59 |
60 | query_result *client_query_nodes_groups(neu_datalayers_client *client,
61 | ValueType type);
62 |
63 | query_result *client_query_all_data(neu_datalayers_client *client,
64 | ValueType type);
65 |
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 |
70 | #endif
--------------------------------------------------------------------------------
/include/neuron/json/neu_json_error.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_JSON_ERROR_H_
26 | #define _NEU_JSON_API_NEU_JSON_ERROR_H_
27 |
28 | #include "json/json.h"
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | typedef struct {
35 | int64_t error;
36 | } neu_json_error_resp_t;
37 |
38 | int neu_json_encode_error_resp(void *json_object, void *param);
39 |
40 | #ifdef __cplusplus
41 | }
42 | #endif
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/include/neuron/json/neu_json_fn.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_JSON_FN_H
21 | #define _NEU_JSON_FN_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include
28 |
29 | #include "json/neu_json_error.h"
30 | #include "json/neu_json_rw.h"
31 |
32 | typedef int (*neu_json_encode_fn)(void *object, void *param);
33 |
34 | int neu_json_encode_by_fn(void *param, neu_json_encode_fn fn, char **result);
35 |
36 | int neu_json_encode_with_mqtt(void *param, neu_json_encode_fn fn,
37 | void *mqtt_param, neu_json_encode_fn mqtt_fn,
38 | char **result);
39 | int neu_json_encode_with_mqtt_ecp(void *param, neu_json_encode_fn fn,
40 | void *mqtt_param, neu_json_encode_fn mqtt_fn,
41 | char **result);
42 |
43 | #define NEU_JSON_RESPONSE_ERROR(err, func) \
44 | { \
45 | neu_json_error_resp_t error_code = { 0 }; \
46 | char * result_error = NULL; \
47 | error_code.error = (err); \
48 | neu_json_encode_by_fn(&error_code, neu_json_encode_error_resp, \
49 | &result_error); \
50 | { func }; \
51 | free(result_error); \
52 | }
53 |
54 | #ifdef __cplusplus
55 | }
56 | #endif
57 |
58 | #endif
--------------------------------------------------------------------------------
/include/neuron/json/neu_json_mqtt.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_MQTT_H_
26 | #define _NEU_JSON_API_NEU_MQTT_H_
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | #include
33 |
34 | typedef struct {
35 | char *uuid;
36 | char *traceparent;
37 | char *tracestate;
38 | char *payload;
39 | } neu_json_mqtt_t;
40 |
41 | typedef struct {
42 | char *node;
43 | int link;
44 | int running;
45 | } neu_json_node_state_t;
46 |
47 | typedef struct {
48 | char * version;
49 | uint64_t timpstamp;
50 | } neu_json_states_head_t;
51 |
52 | typedef struct {
53 | int n_state;
54 | neu_json_node_state_t *states;
55 | } neu_json_states_t;
56 |
57 | int neu_json_decode_mqtt_req(char *buf, neu_json_mqtt_t **result);
58 | void neu_json_decode_mqtt_req_free(neu_json_mqtt_t *req);
59 |
60 | int neu_json_encode_mqtt_resp(void *json_object, void *param);
61 |
62 | int neu_json_encode_state_header_resp(void *json_object, void *param);
63 | int neu_json_encode_states_resp(void *json_object, void *param);
64 |
65 | #ifdef __cplusplus
66 | }
67 | #endif
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/include/neuron/json/neu_json_param.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_JSON_PARAM_H
21 | #define _NEU_JSON_PARAM_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include "json/json.h"
28 |
29 | int neu_parse_param(const char *buf, char **err_param, int n,
30 | neu_json_elem_t *ele, ...);
31 |
32 | #ifdef __cplusplus
33 | }
34 | #endif
35 |
36 | #endif
--------------------------------------------------------------------------------
/include/neuron/json/neu_json_scan.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_JSON_SCAN_H_
26 | #define _NEU_JSON_API_NEU_JSON_SCAN_H_
27 |
28 | #include "json/json.h"
29 |
30 | #include "tag.h"
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | typedef struct {
37 | char *node;
38 | char *id;
39 | char *ctx;
40 | } neu_json_scan_tags_req_t;
41 |
42 | int neu_json_decode_scan_tags_req(char *buf, neu_json_scan_tags_req_t **result);
43 |
44 | void neu_json_decode_scan_tags_req_free(neu_json_scan_tags_req_t *req);
45 |
46 | int neu_json_encode_scan_tags_resp(void *json_object, void *param);
47 |
48 | #ifdef __cplusplus
49 | }
50 | #endif
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/include/neuron/neuron.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEURON_H_
21 | #define _NEURON_H_
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | #include "errcodes.h"
32 |
33 | #include "utils/async_queue.h"
34 | #include "utils/protocol_buf.h"
35 |
36 | #include "utils/base64.h"
37 | #include "utils/log.h"
38 | #include "utils/zlog.h"
39 |
40 | #include "utils/neu_jwt.h"
41 | #include "utils/time.h"
42 | #include "utils/utarray.h"
43 | #include "utils/utextend.h"
44 | #include "utils/uthash.h"
45 | #include "utils/utlist.h"
46 |
47 | #include "connection/neu_connection.h"
48 | #include "connection/neu_connection_eth.h"
49 | #include "event/event.h"
50 |
51 | #include "json/json.h"
52 | #include "json/neu_json_error.h"
53 | #include "json/neu_json_fn.h"
54 | #include "json/neu_json_mqtt.h"
55 | #include "json/neu_json_param.h"
56 | #include "json/neu_json_rw.h"
57 |
58 | #include "define.h"
59 |
60 | #include "adapter.h"
61 | #include "plugin.h"
62 | #include "tag.h"
63 | #include "tag_sort.h"
64 |
65 | #ifdef __cplusplus
66 | }
67 | #endif
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/include/neuron/persist/json/persist_json_plugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_PERSIST_JSON_PLUGIN_H_
26 | #define _NEU_JSON_API_PERSIST_JSON_PLUGIN_H_
27 |
28 | #include "json/json.h"
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | typedef char *neu_json_plugin_req_plugin_t;
35 |
36 | typedef struct {
37 | int n_plugin;
38 | neu_json_plugin_req_plugin_t *plugins;
39 | } neu_json_plugin_req_t;
40 |
41 | int neu_json_decode_plugin_req(char *buf, neu_json_plugin_req_t **result);
42 | void neu_json_decode_plugin_req_free(neu_json_plugin_req_t *req);
43 |
44 | typedef char *neu_json_plugin_resp_plugin_t;
45 |
46 | typedef struct {
47 | int n_plugin;
48 | neu_json_plugin_resp_plugin_t *plugins;
49 | } neu_json_plugin_resp_t;
50 |
51 | int neu_json_encode_plugin_resp(void *json_object, void *param);
52 |
53 | #ifdef __cplusplus
54 | }
55 | #endif
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/include/neuron/tag_sort.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | config_ **/
19 |
20 | #ifndef _NEU_TAG_SORT_H_
21 | #define _NEU_TAG_SORT_H_
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include
28 | #include
29 |
30 | #include "utils/utarray.h"
31 | #include "utils/utlist.h"
32 |
33 | typedef struct neu_tag_sort_elem {
34 | void * tag;
35 | struct neu_tag_sort_elem *next, *prev;
36 | } neu_tag_sort_elem_t;
37 |
38 | typedef int (*neu_tag_sort_cmp)(neu_tag_sort_elem_t *tag1,
39 | neu_tag_sort_elem_t *tag2);
40 |
41 | typedef struct {
42 | struct {
43 | uint16_t size;
44 | void * context;
45 | } info;
46 |
47 | UT_array *tags;
48 | } neu_tag_sort_t;
49 |
50 | typedef struct {
51 | uint16_t n_sort;
52 | neu_tag_sort_t *sorts;
53 | } neu_tag_sort_result_t;
54 |
55 | typedef bool (*neu_tag_sort_fn)(neu_tag_sort_t *sort, void *tag,
56 | void *tag_to_be_sorted);
57 |
58 | /**
59 | * @brief Use sort and cmp to sort and classify tags.
60 | *
61 | * @param[in] tags The tags that needs to be processed.
62 | * @param[in] sort Function for tag sort.
63 | * @param[in] cmp Function for tags comparison.
64 | * @return processed tags.
65 | */
66 | neu_tag_sort_result_t *neu_tag_sort(UT_array *tags, neu_tag_sort_fn sort,
67 | neu_tag_sort_cmp cmp);
68 |
69 | /**
70 | * @brief free the result.
71 | *
72 | * @param[in] result the tags result that needs to be relesed.
73 | */
74 | void neu_tag_sort_free(neu_tag_sort_result_t *result);
75 |
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 |
80 | #endif
--------------------------------------------------------------------------------
/include/neuron/utils/asprintf.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef __NEU_ASPRINTF_H__
20 | #define __NEU_ASPRINTF_H__
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | #include
27 |
28 | int neu_asprintf(char **strp, const char *fmt, ...);
29 | int neu_vasprintf(char **strp, const char *fmt, va_list ap);
30 |
31 | #ifdef __cplusplus
32 | }
33 | #endif
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/include/neuron/utils/base64.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef __NEU_BASE64_H__
21 | #define __NEU_BASE64_H__
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | /**
28 | * @brief base64 encoding.
29 | *
30 | * @param[in] input Data to be encoded.
31 | * @param[in] length Length of data to be encoded.
32 | * @return Encoded data.
33 | */
34 |
35 | char *neu_encode64(const unsigned char *input, int length);
36 |
37 | /**
38 | * @brief base64 decoding.
39 | *
40 | * @param[out] length Pointer to the length of the decoded data.
41 | * @param[in] input Data to be decoded.
42 | * @return The decoded data.
43 | */
44 | unsigned char *neu_decode64(int *length, const char *input);
45 |
46 | #ifdef __cplusplus
47 | }
48 | #endif
49 |
50 | #endif // __NEU_BASE64_H__
51 |
--------------------------------------------------------------------------------
/include/neuron/utils/neu_jwt.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef __NEU_JWT_H__
20 | #define __NEU_JWT_H__
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | #include
27 |
28 | int neu_jwt_init(const char *dir_path);
29 | int neu_jwt_new(char **token, const char *user);
30 | int neu_jwt_validate(char *b_token);
31 | void neu_jwt_destroy();
32 | void neu_jwt_decode_user_after_valid(char *bearer, char *user);
33 |
34 | #ifdef __cplusplus
35 | }
36 | #endif
37 |
38 | #endif
--------------------------------------------------------------------------------
/include/neuron/utils/set.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef NEURON_UTILS_SET_H
20 | #define NEURON_UTILS_SET_H
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | #include
27 | #include
28 |
29 | #include "uthash.h"
30 |
31 | typedef struct {
32 | const char * str;
33 | UT_hash_handle hh;
34 | } neu_strset_node_t;
35 |
36 | /** Set of strings.
37 | */
38 | typedef neu_strset_node_t *neu_strset_t;
39 |
40 | /** Destructs the string set.
41 | */
42 | static inline void neu_strset_free(neu_strset_t *set)
43 | {
44 | neu_strset_node_t *e = NULL, *tmp = NULL;
45 | HASH_ITER(hh, *set, e, tmp)
46 | {
47 | HASH_DEL(*set, e);
48 | free(e);
49 | }
50 | }
51 |
52 | /** Return the cardinal of the set.
53 | */
54 | static inline unsigned neu_strset_count(neu_strset_t *set)
55 | {
56 | return HASH_COUNT(*set);
57 | }
58 |
59 | /** Return true if the given string is a member of the set, false otherwise.
60 | */
61 | static inline bool neu_strset_test(neu_strset_t *set, const char *str)
62 | {
63 | neu_strset_node_t *e = NULL;
64 | HASH_FIND_STR(*set, str, e);
65 | return NULL != e;
66 | }
67 |
68 | /** Add the given string to the set.
69 | * NOTE: The given string is referenced, not copied.
70 | * Return 1 if success, 0 if the string is already a member, -1 on error.
71 | */
72 | static inline int neu_strset_add(neu_strset_t *set, const char *str)
73 | {
74 | neu_strset_node_t *e = NULL;
75 | HASH_FIND_STR(*set, str, e);
76 | if (e) {
77 | return 0;
78 | }
79 | e = calloc(1, sizeof(*e));
80 | if (NULL == e) {
81 | return -1;
82 | }
83 | e->str = str;
84 | HASH_ADD_KEYPTR(hh, *set, e->str, strlen(e->str), e);
85 | return 1;
86 | }
87 |
88 | #ifdef __cplusplus
89 | }
90 | #endif
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/include/neuron/utils/time.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef __NEU_TIME_H__
20 | #define __NEU_TIME_H__
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | static inline int64_t neu_time_ms()
32 | {
33 | struct timeval tv = { 0 };
34 | gettimeofday(&tv, NULL);
35 | return (int64_t) tv.tv_sec * 1000 + (int64_t) tv.tv_usec / 1000;
36 | }
37 |
38 | static inline int64_t neu_time_ns()
39 | {
40 | struct timespec ts = { 0 };
41 | clock_gettime(CLOCK_REALTIME, &ts);
42 | return (int64_t) ts.tv_sec * 1000000000 + (int64_t) ts.tv_nsec;
43 | }
44 |
45 | static inline void neu_msleep(unsigned msec)
46 | {
47 | struct timespec tv = {
48 | .tv_sec = msec / 1000,
49 | .tv_nsec = (msec % 1000) * 1000000,
50 | };
51 | nanosleep(&tv, NULL);
52 | }
53 |
54 | #ifdef __cplusplus
55 | }
56 | #endif
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/jwt_encode.py:
--------------------------------------------------------------------------------
1 | import jwt # pip install pyjwt
2 | import time
3 |
4 | with open("neuron.key", "r") as f:
5 | private_key = f.read()
6 |
7 | current_time = int(time.time())
8 | two_years = 60 * 60 * 24 * 365 * 2
9 | header = {"alg": "RS256", "typ": "JWT"}
10 | payload = {
11 | "aud": "neuron",
12 | "bodyEncode": 0,
13 | "exp": current_time + two_years,
14 | "iat": current_time,
15 | "iss": "neuron",
16 | }
17 | token = jwt.encode(payload, private_key, algorithm="RS256", headers=header).decode(
18 | "utf-8"
19 | )
20 | print(f"Bearer {token}")
21 |
--------------------------------------------------------------------------------
/neuron.conf:
--------------------------------------------------------------------------------
1 | # neuron driver default configuration
2 | /usr/local/lib/neuron
--------------------------------------------------------------------------------
/neuron.json:
--------------------------------------------------------------------------------
1 | {
2 | "ip": "0.0.0.0",
3 | "port": 7000,
4 | "disable_auth": 0,
5 | "syslog_host": "",
6 | "syslog_port": 541,
7 | "sub_filter_error": 0
8 | }
9 |
--------------------------------------------------------------------------------
/neuron.key:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEpAIBAAKCAQEAzrO7FUz4GGKl4nP5lwKMh5uageJAAHnLZpVxTR1wXA9E870s
3 | U03gHnPWsh2bXCCx85ymYaiu/5VlptgnU0rQB1I3xGRG8eHmHPrhHNWDRKpY6oY8
4 | AnTPqXvfa/Z4u+njJzDSqi4qM8Gwfqlgpjlg8DUF+sheLx8hL+x9XFzovTxafrmy
5 | JRRAVQTkhB7esKKqRF8BMjdOdYZxJEv9jxa0BwXcjprPDlj5TV6k3wJqbq4UtnEE
6 | VbjEQKqFVkfY4FuJ5NSPHpGEix94PGQGRsiWkGX0vx5udHJ0SlXM6qpMLny18FhW
7 | bwKNX3urc3mImn/j3zcJ5x1d+FlXAXs1NBSeTQIDAQABAoIBAQDJOT8PZXbAhohn
8 | A/AeimS0P08S0mbsD6VroGBEajxP4q2FeswD7PQZsTt4+kmcTlfuiLmQqN50AcSL
9 | wDHIbDRIbEnN7rECGKAj5jfwEgtQdWVKKpOQ8JaYr/a466BtjyuLo4PyGC8NY6mm
10 | JM3qBEHSlkvT7+uAhBWSye7gU7JfRPoCeFRpaMMC3Ad0DaIt/Pdt9CddNwj56+9j
11 | gl//blNnBImjvA7/kh9gL69SYVrQoG9vm/UgFbdIwd+w2hhhpx6kuHjRJ21xIV/y
12 | Yh9k4QhPr7zIkhQ8yn11ZhyZkMC8XAMy7NKCmAFIPNJ8jwvgBkunPEk2aYBeDUaq
13 | a30VwlIhAoGBAOnm8DW5DROcfSj4Q8zsvgmvhGM0zzF5zmA+4E+tEbf4t6sDUjSs
14 | ADo2EaiJZz75vLsD7UZHKzFEV/wnuT7SiNCbrJafx8Tp2UgijTkW8gEhAWREJDn5
15 | FS375RKFdEcpmVHWgsuz4z/0L3BGxmyYWQxx5pD2NL49ZpTIHAHm/XETAoGBAOI6
16 | 8Y08TmM2bnXbL/MggYMJlqOyv27ueVYz9of3FYFAMIe7ebSgrlSCOwsoDZYmegBM
17 | OrowR3AAnoP4fjGNbIPjNYbiv1qLOdtnvPxYotEz+ZaUBSn9V/gUEVFlgrKxgTKr
18 | sqi/QMyyJplBTUkUuqYRDuv6TZ3OWKiDUoXTdv8fAoGBAIbbyf+PlESMY3Vtvtm2
19 | XdODyRbR6ewiyKShW/9UT/T8iBknrwwDZ5YoeoHrxwV+RBynpPRyMCsVto0B8kKQ
20 | bKWqPBYURb/4/Hgkw7v4yMtx1jWTPDfYryd2JptJKsOk7mtK/Nqp+wpypa9cfyc5
21 | p44PVdqauco96Jk7zzohjlrVAoGAfjQDrJaH5DDpTjYIeckYdtFSh9+fi3LdnYk/
22 | bnoYNRJqAE5Fhs5ccih0Z7TgX3L3fFMKL/Pe5kxyIYzuWRZcAvctVSIJPamNjShB
23 | 9UQ9EBe+lJHej54VBP+s6YuHbcg4GtxNvnVy4L5Bah1T0AEQXrQFbv8jbXU/YEJi
24 | NuXQ7GECgYA0UNvuZxVSDn8fBxARcX3ub5aok5owdLL3SOCPMpNrmOBQj8iJGT+5
25 | nv7fH1TWVh9yUdRwhd81s5H/PO3/myLmgq0TcPvewtEEwY+++QpsYZwHTDXgxbbw
26 | ++lmJali4fzmd/72JqocGABYhZFt0jbcQ1QEcqUYcD380+cNVZPO+w==
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/neuron.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzrO7FUz4GGKl4nP5lwKM
3 | h5uageJAAHnLZpVxTR1wXA9E870sU03gHnPWsh2bXCCx85ymYaiu/5VlptgnU0rQ
4 | B1I3xGRG8eHmHPrhHNWDRKpY6oY8AnTPqXvfa/Z4u+njJzDSqi4qM8Gwfqlgpjlg
5 | 8DUF+sheLx8hL+x9XFzovTxafrmyJRRAVQTkhB7esKKqRF8BMjdOdYZxJEv9jxa0
6 | BwXcjprPDlj5TV6k3wJqbq4UtnEEVbjEQKqFVkfY4FuJ5NSPHpGEix94PGQGRsiW
7 | kGX0vx5udHJ0SlXM6qpMLny18FhWbwKNX3urc3mImn/j3zcJ5x1d+FlXAXs1NBSe
8 | TQIDAQAB
9 | -----END PUBLIC KEY-----
10 |
--------------------------------------------------------------------------------
/package-sdk.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | arch=x86_64-linux-gnu
4 | package_name=neuron-sdk
5 |
6 | function usage() {
7 | echo "Usage: $0 "
8 | echo "-n package name [default: ${package_name}]"
9 | echo "-p target platform compiler prefix (opts: x86_64-linux-gnu, arm-linux-gnueabihf, aarch64-linux-gnu, ...)[default: x86_64-linux-gnu]"
10 | }
11 |
12 | while getopts "p:n:h-:" OPT; do
13 | case ${OPT} in
14 | p)
15 | arch=$OPTARG
16 | ;;
17 | n)
18 | package_name=$OPTARG
19 | ;;
20 | h)
21 | usage
22 | exit 0
23 | ;;
24 | \?)
25 | usage
26 | exit 1
27 | ;;
28 | esac
29 | done
30 |
31 | rm -rf ${package_name}/*
32 |
33 | mkdir -p $package_name/include/neuron/
34 | mkdir -p $package_name/lib
35 | mkdir -p $package_name/config
36 | mkdir -p $package_name/plugins/schema
37 |
38 | cp sdk-install.sh ${package_name}/
39 | cp neuron.conf ${package_name}/
40 | cp cmake/neuron-config.cmake ${package_name}/
41 | cp -r include/* ${package_name}/include/
42 |
43 | cp -r build/dist ${package_name}/
44 |
45 | cp build/neuron ${package_name}
46 | cp build/libneuron-base.so ${package_name}/lib
47 | cp /usr/local/lib/libzlog.so.1.2 ${package_name}/lib
48 |
49 | cp persistence/*.sql ${package_name}/config/
50 |
51 | cp sdk-zlog.conf ${package_name}/config/
52 | cp zlog.conf ${package_name}/config/
53 | cp dev.conf ${package_name}/config/
54 | cp default_plugins.json ${package_name}/config/
55 | cp neuron.json ${package_name}/config/
56 |
57 | cp build/plugins/schema/ekuiper.json \
58 | build/plugins/schema/monitor.json \
59 | build/plugins/schema/mqtt.json \
60 | build/plugins/schema/modbus-tcp.json \
61 | build/plugins/schema/file.json \
62 | ${package_name}/plugins/schema/
63 |
64 | cp build/plugins/libplugin-ekuiper.so \
65 | build/plugins/libplugin-monitor.so \
66 | build/plugins/libplugin-mqtt.so \
67 | build/plugins/libplugin-modbus-tcp.so \
68 | build/plugins/libplugin-file.so \
69 | ${package_name}/plugins/
70 |
71 | tar czf ${package_name}-${arch}.tar.gz ${package_name}/
72 | ls ${package_name}
73 | rm -rf ${package_name}
74 |
75 | echo "${package_name}-${arch}.tar.gz"
76 |
--------------------------------------------------------------------------------
/persistence/0002_2.3.0_node_cache.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | --- fix primary key ---
21 | BEGIN;
22 |
23 | DROP TABLE IF EXISTS old_node_cache;
24 | ALTER TABLE node_cache RENAME TO old_node_cache;
25 |
26 | CREATE TABLE IF NOT EXISTS node_cache (
27 | node_name TEXT PRIMARY KEY,
28 | CACHE TEXT NOT NULL,
29 | FOREIGN KEY (node_name) REFERENCES nodes (name) ON UPDATE CASCADE ON DELETE CASCADE
30 | );
31 |
32 | INSERT OR REPLACE INTO node_cache SELECT * FROM old_node_cache;
33 |
34 | DROP TABLE old_node_cache;
35 |
36 | COMMIT;
37 |
--------------------------------------------------------------------------------
/persistence/0010_2.4.0_subscription_params.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | DROP TABLE
22 | IF EXISTS old_subscriptions;
23 |
24 | ALTER TABLE
25 | subscriptions RENAME TO old_subscriptions;
26 |
27 | -- add column params for subscription parameters
28 | CREATE TABLE
29 | IF NOT EXISTS subscriptions (
30 | app_name TEXT NOT NULL,
31 | driver_name TEXT NOT NULL,
32 | group_name TEXT NOT NULL,
33 | params TEXT DEFAULT NULL,
34 | CHECK (app_name != driver_name),
35 | UNIQUE (app_name, driver_name, group_name),
36 | FOREIGN KEY (app_name) REFERENCES nodes (name) ON UPDATE CASCADE ON DELETE CASCADE,
37 | FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
38 | );
39 |
40 | INSERT INTO
41 | subscriptions
42 | SELECT
43 | app_name,
44 | driver_name,
45 | group_name,
46 | NULL
47 | FROM
48 | old_subscriptions;
49 |
50 | DROP TABLE
51 | old_subscriptions;
52 |
53 | COMMIT;
54 |
--------------------------------------------------------------------------------
/persistence/0020_2.4.0_static_tag.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | DROP TABLE
22 | IF EXISTS old_tags;
23 |
24 | ALTER TABLE
25 | tags RENAME TO old_tags;
26 |
27 | -- alter attribute column constraint for static tags
28 | -- add value column
29 | CREATE TABLE
30 | IF NOT EXISTS tags (
31 | driver_name TEXT NOT NULL,
32 | group_name TEXT NOT NULL,
33 | name TEXT NULL check(length(name) <= 64),
34 | address TEXT NULL check(length(address) <= 128),
35 | attribute INTEGER NOT NULL check(attribute BETWEEN 0 AND 15),
36 | PRECISION INTEGER NOT NULL check(PRECISION BETWEEN 0 AND 17),
37 | decimal REAL NOT NULL,
38 | TYPE INTEGER NOT NULL check(TYPE BETWEEN 0 AND 19),
39 | description TEXT NULL check(length(description) <= 128),
40 | value TEXT DEFAULT NULL,
41 | UNIQUE (driver_name, group_name, name),
42 | FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
43 | );
44 |
45 | INSERT INTO
46 | tags
47 | SELECT
48 | driver_name,
49 | group_name,
50 | name,
51 | address,
52 | attribute,
53 | PRECISION,
54 | decimal,
55 | TYPE,
56 | description,
57 | NULL
58 | FROM
59 | old_tags;
60 |
61 | DROP TABLE
62 | old_tags;
63 |
64 | COMMIT;
65 |
--------------------------------------------------------------------------------
/persistence/0030_2.4.0_ekuiper_node.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | -- from neuron version 2.4.0, eKuiper plugin is no more singleton
22 | -- remove default data-stream-processing node if not in use
23 | DELETE FROM
24 | nodes
25 | WHERE
26 | name = 'data-stream-processing'
27 | AND name NOT in (
28 | SELECT
29 | node_name
30 | FROM
31 | settings
32 | )
33 | AND name NOT in (
34 | SELECT
35 | app_name
36 | FROM
37 | subscriptions
38 | );
39 |
40 | -- fix data-stream-processing node plugin name
41 | UPDATE
42 | nodes
43 | SET
44 | plugin_name = 'eKuiper'
45 | where
46 | name = 'data-stream-processing';
47 |
48 | COMMIT;
49 |
--------------------------------------------------------------------------------
/persistence/0033_2.4.5_mqtt_upload_topic.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | -- for backward compatibility with version 2.3,
22 | -- migrate MQTT plugin upload-topic to subscription parameters.
23 | WITH
24 | topics AS (
25 | SELECT
26 | name AS app,
27 | json_extract(json(setting), '$.params.upload-topic') AS topic
28 | FROM
29 | nodes
30 | JOIN settings
31 | WHERE
32 | name = node_name
33 | AND plugin_name = 'MQTT'
34 | )
35 | UPDATE
36 | subscriptions
37 | SET
38 | params = (
39 | SELECT
40 | json_object('params', json_object('topic', topic)) AS params
41 | FROM
42 | topics
43 | WHERE
44 | topics.app = subscriptions.app_name
45 | AND topics.topic NOT NULL
46 | )
47 | WHERE
48 | EXISTS (
49 | SELECT
50 | topic
51 | FROM
52 | topics
53 | WHERE
54 | topics.app = subscriptions.app_name
55 | AND topics.topic NOT NULL
56 | AND subscriptions.params IS NULL
57 | );
58 |
59 | COMMIT;
60 |
--------------------------------------------------------------------------------
/persistence/0040_2.5.0_template.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | CREATE TABLE
22 | IF NOT EXISTS templates (
23 | name TEXT PRIMARY KEY check(length(name) <= 128),
24 | plugin_name TEXT NOT NULL check(length(plugin_name) <= 32)
25 | );
26 |
27 | CREATE TABLE
28 | IF NOT EXISTS template_groups (
29 | tmpl_name TEXT NOT NULL,
30 | name TEXT NULL check(length(name) <= 128),
31 | interval INTEGER NOT NULL check(interval >= 100),
32 | UNIQUE (tmpl_name, name),
33 | FOREIGN KEY (tmpl_name) REFERENCES templates (name) ON UPDATE CASCADE ON DELETE CASCADE
34 | );
35 |
36 | CREATE TABLE
37 | IF NOT EXISTS template_tags (
38 | tmpl_name TEXT NOT NULL,
39 | group_name TEXT NOT NULL,
40 | name TEXT NULL check(length(name) <= 64),
41 | address TEXT NULL check(length(address) <= 128),
42 | attribute INTEGER NOT NULL check(attribute BETWEEN 0 AND 15),
43 | PRECISION INTEGER NOT NULL check(PRECISION BETWEEN 0 AND 17),
44 | decimal REAL NOT NULL,
45 | TYPE INTEGER NOT NULL check(TYPE BETWEEN 0 AND 19),
46 | description TEXT NULL check(length(description) <= 128),
47 | value TEXT DEFAULT NULL,
48 | UNIQUE (tmpl_name, group_name, name),
49 | FOREIGN KEY (tmpl_name, group_name) REFERENCES template_groups (tmpl_name, name) ON UPDATE CASCADE ON DELETE CASCADE
50 | );
51 |
52 | COMMIT;
53 |
--------------------------------------------------------------------------------
/persistence/0042_2.5.3_fx_rename.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | BEGIN TRANSACTION;
21 |
22 | UPDATE nodes
23 | SET plugin_name = 'Mitsubishi FX'
24 | WHERE plugin_name = 'Mitsabishi FX';
25 |
26 | COMMIT;
--------------------------------------------------------------------------------
/persistence/0050_2.6.0_virtual_license.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN;
20 |
21 | CREATE TABLE
22 | IF NOT EXISTS virtual_license (license TEXT NOT NULL);
23 |
24 | COMMIT;
25 |
--------------------------------------------------------------------------------
/persistence/0060_2.7.3_tag_name_length.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | ALTER TABLE tags RENAME TO temp_tags;
22 | CREATE TABLE IF NOT EXISTS
23 | tags (
24 | driver_name TEXT NOT NULL,
25 | group_name TEXT NOT NULL,
26 | name TEXT NULL check(length(name) <= 128),
27 | address TEXT NULL check(length(address) <= 128),
28 | attribute INTEGER NOT NULL check(attribute BETWEEN 0 AND 15),
29 | precision INTEGER NOT NULL check(precision BETWEEN 0 AND 17),
30 | decimal REAL NOT NULL,
31 | type INTEGER NOT NULL check(type BETWEEN 0 AND 19),
32 | description TEXT NULL check(length(description) <= 512),
33 | value TEXT,
34 | UNIQUE (driver_name, group_name, name),
35 | FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
36 | );
37 | INSERT INTO tags SELECT * FROM temp_tags;
38 |
39 | DROP TABLE temp_tags;
40 | COMMIT;
--------------------------------------------------------------------------------
/persistence/0070_2.7.5_tag_time_type.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | ALTER TABLE tags RENAME TO temp_tags;
22 |
23 | CREATE TABLE
24 | IF NOT EXISTS tags (
25 | driver_name TEXT NOT NULL,
26 | group_name TEXT NOT NULL,
27 | name TEXT NULL check (length (name) <= 128),
28 | address TEXT NULL check (length (address) <= 128),
29 | attribute INTEGER NOT NULL check (attribute BETWEEN 0 AND 15),
30 | precision INTEGER NOT NULL check (precision BETWEEN 0 AND 17),
31 | decimal REAL NOT NULL,
32 | type INTEGER NOT NULL check (type BETWEEN 0 AND 21),
33 | description TEXT NULL check (length (description) <= 512),
34 | value TEXT,
35 | UNIQUE (driver_name, group_name, name),
36 | FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
37 | );
38 |
39 | INSERT INTO tags SELECT * FROM temp_tags;
40 |
41 | DROP TABLE temp_tags;
42 |
43 | COMMIT;
44 |
--------------------------------------------------------------------------------
/persistence/0080_2.9.0_tag_bias.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | ALTER TABLE tags RENAME TO temp_tags;
22 |
23 | -- add bias column
24 | CREATE TABLE
25 | IF NOT EXISTS tags (
26 | driver_name TEXT NOT NULL,
27 | group_name TEXT NOT NULL,
28 | name TEXT NULL check (length (name) <= 128),
29 | address TEXT NULL check (length (address) <= 128),
30 | attribute INTEGER NOT NULL check (attribute BETWEEN 0 AND 15),
31 | precision INTEGER NOT NULL check (precision BETWEEN 0 AND 17),
32 | decimal REAL NOT NULL,
33 | bias REAL NOT NULL check (bias BETWEEN -1000 AND 1000),
34 | type INTEGER NOT NULL check (type BETWEEN 0 AND 21),
35 | description TEXT NULL check (length (description) <= 512),
36 | value TEXT,
37 | UNIQUE (driver_name, group_name, name),
38 | FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
39 | );
40 |
41 | INSERT INTO
42 | tags
43 | SELECT
44 | driver_name,
45 | group_name,
46 | name,
47 | address,
48 | attribute,
49 | PRECISION,
50 | decimal,
51 | 0,
52 | TYPE,
53 | description,
54 | NULL
55 | FROM
56 | temp_tags;
57 |
58 | DROP TABLE temp_tags;
59 |
60 | COMMIT;
61 |
--------------------------------------------------------------------------------
/persistence/0110_2.11.0_tag.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | alter TABLE groups add column context TEXT NULL check(length(context) <= 512);
22 | alter TABLE tags add column format TEXT NULL;
23 |
24 | COMMIT;
--------------------------------------------------------------------------------
/persistence/0111_2.11.0_sub.sql:
--------------------------------------------------------------------------------
1 | BEGIN TRANSACTION;
2 |
3 | DROP TABLE IF EXISTS temp_subscriptions;
4 | ALTER TABLE subscriptions RENAME TO temp_subscriptions;
5 |
6 | CREATE TABLE
7 | IF NOT EXISTS subscriptions (
8 | app_name TEXT NOT NULL,
9 | driver_name TEXT NOT NULL,
10 | group_name TEXT NOT NULL,
11 | params TEXT DEFAULT NULL,
12 | static_tags TEXT DEFAULT NULL,
13 | CHECK (app_name != driver_name),
14 | UNIQUE (app_name, driver_name, group_name),
15 | FOREIGN KEY (app_name) REFERENCES nodes (name) ON UPDATE CASCADE ON DELETE CASCADE,
16 | FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
17 | );
18 | INSERT INTO subscriptions SELECT app_name, driver_name, group_name, params, NULL FROM temp_subscriptions;
19 |
20 | DROP TABLE temp_subscriptions;
21 |
22 | COMMIT;
--------------------------------------------------------------------------------
/persistence/0112_2.12.0_array.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | BEGIN TRANSACTION;
20 |
21 | ALTER TABLE tags RENAME TO temp_tags;
22 |
23 | -- update type integer
24 | CREATE TABLE
25 | IF NOT EXISTS tags (
26 | driver_name TEXT NOT NULL,
27 | group_name TEXT NOT NULL,
28 | name TEXT NULL check (length (name) <= 128),
29 | address TEXT NULL check (length (address) <= 128),
30 | attribute INTEGER NOT NULL check (attribute BETWEEN 0 AND 15),
31 | precision INTEGER NOT NULL check (precision BETWEEN 0 AND 17),
32 | decimal REAL NOT NULL,
33 | bias REAL NOT NULL check (bias BETWEEN -1000 AND 1000),
34 | type INTEGER NOT NULL check (type BETWEEN 0 AND 34 OR type = 40),
35 | description TEXT NULL check (length (description) <= 512),
36 | value TEXT,
37 | format TEXT,
38 | UNIQUE (driver_name, group_name, name),
39 | FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
40 | );
41 |
42 | INSERT INTO
43 | tags
44 | SELECT
45 | driver_name,
46 | group_name,
47 | name,
48 | address,
49 | attribute,
50 | PRECISION,
51 | decimal,
52 | bias,
53 | TYPE,
54 | description,
55 | NULL,
56 | format
57 | FROM
58 | temp_tags;
59 |
60 | DROP TABLE temp_tags;
61 |
62 | COMMIT;
--------------------------------------------------------------------------------
/plugins/datalayers/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.12)
2 |
3 | project(plugin-datalayers)
4 |
5 | set(CMAKE_CXX_STANDARD 17)
6 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
7 | set(CMAKE_CXX_EXTENSIONS OFF)
8 |
9 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/plugins")
10 |
11 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/datalayers/datalayers.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
12 |
13 | add_library(${PROJECT_NAME} SHARED
14 | datalayers_config.c
15 | datalayers_handle.c
16 | datalayers_plugin.c
17 | datalayers_plugin_intf.c
18 | ${CMAKE_SOURCE_DIR}/src/persist/datalayers/flight_sql_client.cpp
19 | )
20 |
21 | target_include_directories(${PROJECT_NAME} PRIVATE
22 | ${CMAKE_SOURCE_DIR}/include/neuron
23 | ${CMAKE_SOURCE_DIR}/plugins/datalayers
24 | ${CMAKE_SOURCE_DIR}/src/persist/datalayers
25 | )
26 |
27 | set(ARROW_USE_STATIC_LIBS ON)
28 | set(ARROW_STATIC_LIB TRUE)
29 |
30 | find_package(Arrow REQUIRED)
31 | find_package(ArrowFlight REQUIRED)
32 | find_package(ArrowFlightSql REQUIRED)
33 | find_package(gRPC REQUIRED)
34 |
35 | target_link_libraries(${PROJECT_NAME}
36 | -Wl,--whole-archive
37 | gRPC::grpc++
38 | -Wl,--no-whole-archive
39 | Arrow::arrow_static
40 | ArrowFlight::arrow_flight_static
41 | ArrowFlightSql::arrow_flight_sql_static
42 | stdc++
43 | gflags
44 | ${CMAKE_THREAD_LIBS_INIT}
45 | )
46 |
47 | target_link_libraries(${PROJECT_NAME} neuron-base)
48 | target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
--------------------------------------------------------------------------------
/plugins/datalayers/datalayers.json:
--------------------------------------------------------------------------------
1 | {
2 | "host": {
3 | "name": "Broker Host",
4 | "name_zh": "服务器地址",
5 | "description": "Datalayers broker host",
6 | "description_zh": "Datalayers 服务器地址",
7 | "attribute": "required",
8 | "type": "string",
9 | "default": "127.0.0.1",
10 | "valid": {
11 | "length": 255
12 | }
13 | },
14 | "port": {
15 | "name": "Broker Port",
16 | "name_zh": "服务器端口",
17 | "description": "Datalayers broker port",
18 | "description_zh": "Datalayers 服务器端口",
19 | "attribute": "required",
20 | "type": "int",
21 | "default": 8360,
22 | "valid": {
23 | "min": 1,
24 | "max": 65535
25 | }
26 | },
27 | "username": {
28 | "name": "Username",
29 | "name_zh": "用户名",
30 | "description": "Datalayers user name",
31 | "description_zh": "Datalayers 用户名",
32 | "attribute": "required",
33 | "type": "string",
34 | "default": "admin",
35 | "valid": {
36 | "length": 255
37 | }
38 | },
39 | "password": {
40 | "name": "Password",
41 | "name_zh": "密码",
42 | "description": "Datalayers user password",
43 | "description_zh": "Datalayers 用户密码",
44 | "attribute": "required",
45 | "type": "string",
46 | "valid": {
47 | "length": 255
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/plugins/datalayers/datalayers_config.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_PLUGIN_DATALAYERS_CONFIG_H
21 | #define NEURON_PLUGIN_DATALAYERS_CONFIG_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include
28 |
29 | #include "plugin.h"
30 |
31 | typedef struct {
32 | char * host;
33 | uint16_t port;
34 | char * username;
35 | char * password;
36 | } datalayers_config_t;
37 |
38 | int datalayers_config_parse(neu_plugin_t *plugin, const char *setting,
39 | datalayers_config_t *config);
40 | void datalayers_config_fini(datalayers_config_t *config);
41 |
42 | #ifdef __cplusplus
43 | }
44 | #endif
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/plugins/datalayers/datalayers_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_PLUGIN_MQTT_HANDLE_H
21 | #define NEURON_PLUGIN_MQTT_HANDLE_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include "datalayers_plugin.h"
28 |
29 | void db_write_task_consumer(neu_plugin_t *plugin);
30 | void task_queue_init(task_queue_t *queue);
31 | void tasks_free(task_queue_t *queue);
32 |
33 | int handle_trans_data(neu_plugin_t * plugin,
34 | neu_reqresp_trans_data_t *trans_data);
35 |
36 | int handle_subscribe_group(neu_plugin_t *plugin, neu_req_subscribe_t *sub_info);
37 | int handle_unsubscribe_group(neu_plugin_t * plugin,
38 | neu_req_unsubscribe_t *unsub_info);
39 |
40 | int handle_update_group(neu_plugin_t *plugin, neu_req_update_group_t *req);
41 | int handle_del_group(neu_plugin_t *plugin, neu_req_del_group_t *cmd);
42 |
43 | int handle_update_driver(neu_plugin_t *plugin, neu_req_update_node_t *req);
44 | int handle_del_driver(neu_plugin_t *plugin, neu_reqresp_node_deleted_t *req);
45 | #ifdef __cplusplus
46 | }
47 | #endif
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/plugins/datalayers/datalayers_plugin.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #include "datalayers_plugin_intf.h"
21 |
22 | #define DESCRIPTION "Northbound DataStorage plugin."
23 | #define DESCRIPTION_ZH "北向应用 DataStorage 插件"
24 |
25 | const neu_plugin_module_t neu_plugin_module = {
26 | .version = NEURON_PLUGIN_VER_1_0,
27 | .schema = "datalayers",
28 | .module_name = "Datalayers",
29 | .module_descr = DESCRIPTION,
30 | .module_descr_zh = DESCRIPTION_ZH,
31 | .intf_funs = &datalayers_plugin_intf_funs,
32 | .kind = NEU_PLUGIN_KIND_SYSTEM,
33 | .type = NEU_NA_TYPE_APP,
34 | .display = true,
35 | .single = true,
36 | .single_name = "DataStorage",
37 | };
38 |
--------------------------------------------------------------------------------
/plugins/ekuiper/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # LF Edge eKuiper plugin
2 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/plugins")
3 |
4 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/ekuiper/ekuiper.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
5 | set(src
6 | json_rw.c
7 | read_write.c
8 | plugin_ekuiper.c)
9 |
10 | add_library(plugin-ekuiper SHARED ${src})
11 |
12 | target_include_directories(plugin-ekuiper PRIVATE
13 | ${CMAKE_SOURCE_DIR}/include/neuron)
14 |
15 | target_link_libraries(plugin-ekuiper neuron-base nng)
16 | target_link_libraries(plugin-ekuiper ${CMAKE_THREAD_LIBS_INIT})
17 |
--------------------------------------------------------------------------------
/plugins/ekuiper/ekuiper.json:
--------------------------------------------------------------------------------
1 | {
2 | "host": {
3 | "name": "Local IP Address",
4 | "name_zh": "本地IP地址",
5 | "description": "IP address to listen for connections from eKuiper",
6 | "description_zh": "绑定本地IP地址,等待eKuiper连接",
7 | "attribute": "required",
8 | "type": "string",
9 | "default": "0.0.0.0",
10 | "valid": {
11 | "length": 255
12 | }
13 | },
14 | "port": {
15 | "name": "Local Port",
16 | "name_zh": "本地端口",
17 | "description": "TCP port number to listen for connections from eKuiper",
18 | "description_zh": "绑定本地端口,等待eKuiper连接",
19 | "attribute": "required",
20 | "type": "int",
21 | "default": 7081,
22 | "valid": {
23 | "min": 1024,
24 | "max": 65535
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/plugins/ekuiper/json_rw.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_PLUGIN_EKUIPER_JSON_RW_H
21 | #define NEURON_PLUGIN_EKUIPER_JSON_RW_H
22 |
23 | #include
24 |
25 | #include "neuron.h"
26 | #include "json/neu_json_rw.h"
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | // NOTE: these utilities may better be reused by mqtt and restful plugin
33 | // should move to neuron public sources
34 |
35 | typedef struct {
36 | char * node_name;
37 | char * group_name;
38 | uint64_t timestamp;
39 | } json_read_resp_header_t;
40 |
41 | int wrap_tag_data(neu_json_read_resp_tag_t * json_tag,
42 | neu_resp_tag_value_meta_t *tag_value);
43 |
44 | typedef struct {
45 | neu_plugin_t * plugin;
46 | neu_reqresp_trans_data_t *trans_data;
47 | } json_read_resp_t;
48 |
49 | // { "node_name": "node0", "group_name": "grp0", "timestamp": 1649776722631 }
50 | int json_encode_read_resp_header(void *json_object, void *param);
51 |
52 | // { "values": { "tag0": 0 }, "errors": { "tag1": 3000 } }
53 | int json_encode_read_resp_tags(void *json_object, void *param);
54 |
55 | // {
56 | // "node_name": "node0",
57 | // "group_name": "grp0",
58 | // "timestamp": 1649776722631,
59 | // "values": { "tag0": 0 },
60 | // "errors": { "tag1": 3000 }
61 | // }
62 | int json_encode_read_resp(void *json_object, void *param);
63 |
64 | typedef struct {
65 | char * node_name;
66 | char * group_name;
67 | char * tag_name;
68 | enum neu_json_type t;
69 | union neu_json_value value;
70 | } json_write_req_t;
71 |
72 | int json_decode_write_req(char *buf, size_t len, neu_json_write_t **result);
73 |
74 | #ifdef __cplusplus
75 | }
76 | #endif
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/plugins/ekuiper/plugin_ekuiper.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_PLUGIN_EKUIPER_H
21 | #define NEURON_PLUGIN_EKUIPER_H
22 |
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | #include "neuron.h"
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | struct neu_plugin {
36 | neu_plugin_common_t common;
37 | nng_socket sock;
38 | nng_mtx * mtx;
39 | bool started;
40 | bool receiving;
41 | nng_aio * recv_aio;
42 | char * host;
43 | uint16_t port;
44 | char * url;
45 | };
46 |
47 | #ifdef __cplusplus
48 | }
49 | #endif
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/plugins/ekuiper/read_write.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_PLUGIN_EKUIPER_READ_WRITE_H
21 | #define NEURON_PLUGIN_EKUIPER_READ_WRITE_H
22 |
23 | #include "neuron.h"
24 |
25 | #include "json_rw.h"
26 | #include "plugin_ekuiper.h"
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | void send_data(neu_plugin_t *plugin, neu_reqresp_trans_data_t *trans_data);
33 |
34 | void recv_data_callback(void *arg);
35 |
36 | #ifdef __cplusplus
37 | }
38 | #endif
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/plugins/file/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/plugins")
2 |
3 | set(CMAKE_BUILD_RPATH ./)
4 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/file/file.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
5 |
6 | set(PLUGIN_NAME plugin-file)
7 | set(PLUGIN_SOURCES file_plugin.c)
8 | add_library(${PLUGIN_NAME} SHARED)
9 | target_include_directories(${PLUGIN_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
10 | target_sources(${PLUGIN_NAME} PRIVATE ${PLUGIN_SOURCES})
11 | target_link_libraries(${PLUGIN_NAME} neuron-base)
--------------------------------------------------------------------------------
/plugins/file/file.json:
--------------------------------------------------------------------------------
1 | {
2 | "tag_regex": [
3 | {
4 | "type": 13,
5 | "regex": ""
6 | }
7 | ],
8 | "group_interval": 1000
9 | }
--------------------------------------------------------------------------------
/plugins/modbus/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/plugins")
2 |
3 | set(MODBUS_SRC modbus.c modbus_point.c modbus_req.c modbus_stack.c)
4 |
5 | set(CMAKE_BUILD_RPATH ./)
6 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/modbus/modbus-tcp.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
7 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/modbus/modbus-rtu.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
8 | # modbus rtu plugin
9 | set(MODBUS_RTU_PLUGIN plugin-modbus-rtu)
10 | set(MODBUS_RTU_PLUGIN_SOURCES modbus_rtu.c
11 | ${MODBUS_SRC})
12 | add_library(${MODBUS_RTU_PLUGIN} SHARED)
13 | target_include_directories(${MODBUS_RTU_PLUGIN} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
14 | target_sources(${MODBUS_RTU_PLUGIN} PRIVATE ${MODBUS_RTU_PLUGIN_SOURCES})
15 | target_link_libraries(${MODBUS_RTU_PLUGIN} neuron-base)
16 |
17 | # modbus tcp plugin
18 | set(MODBUS_TCP_PLUS_PLUGIN plugin-modbus-tcp)
19 | set(MODBUS_TCP_PLUS_PLUGIN_SOURCES modbus_tcp.c
20 | ${MODBUS_SRC})
21 | add_library(${MODBUS_TCP_PLUS_PLUGIN} SHARED)
22 | target_include_directories(${MODBUS_TCP_PLUS_PLUGIN} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
23 | target_sources(${MODBUS_TCP_PLUS_PLUGIN} PRIVATE ${MODBUS_TCP_PLUS_PLUGIN_SOURCES})
24 | target_link_libraries(${MODBUS_TCP_PLUS_PLUGIN} neuron-base)
25 |
26 |
--------------------------------------------------------------------------------
/plugins/monitor/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # neuron monitor plugin
2 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/plugins")
3 |
4 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/monitor/monitor.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
5 |
6 | set(src
7 | monitor.c
8 | monitor_config.c
9 | mqtt_handle.c
10 | )
11 |
12 | add_library(plugin-monitor SHARED ${src})
13 |
14 | target_include_directories(plugin-monitor PRIVATE
15 | ${CMAKE_SOURCE_DIR}/include/neuron
16 | ${CMAKE_SOURCE_DIR}/src
17 | )
18 |
19 | target_link_libraries(plugin-monitor neuron-base nng)
20 | target_link_libraries(plugin-monitor ${CMAKE_THREAD_LIBS_INIT})
21 |
--------------------------------------------------------------------------------
/plugins/monitor/monitor.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEU_PLUGIN_MONITOR_H
21 | #define NEU_PLUGIN_MONITOR_H
22 |
23 | #include
24 |
25 | #include
26 | #include
27 |
28 | #include "adapter.h"
29 | #include "connection/mqtt_client.h"
30 | #include "event/event.h"
31 | #include "monitor_config.h"
32 | #include "plugin.h"
33 |
34 | struct neu_plugin {
35 | neu_plugin_common_t common;
36 | bool started;
37 | neu_events_t * events;
38 | neu_event_timer_t * heartbeat_timer;
39 | monitor_config_t * config;
40 | neu_mqtt_client_t * mqtt_client;
41 | };
42 |
43 | neu_plugin_t *neu_monitor_get_plugin();
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/plugins/monitor/mqtt_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_PLUGIN_MONITOR_MQTT_HANDLE_H
21 | #define NEURON_PLUGIN_MONITOR_MQTT_HANDLE_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include "neuron.h"
28 |
29 | int handle_nodes_state(neu_plugin_t *plugin, neu_reqresp_nodes_state_t *states);
30 |
31 | int handle_events(neu_plugin_t *plugin, neu_reqresp_type_e event, void *data);
32 |
33 | #ifdef __cplusplus
34 | }
35 | #endif
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/plugins/mqtt/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.12)
2 |
3 | project(plugin-mqtt)
4 |
5 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/plugins")
6 |
7 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/mqtt/mqtt.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
8 |
9 | add_library(${PROJECT_NAME} SHARED
10 | mqtt_config.c
11 | mqtt_handle.c
12 | mqtt_plugin.c
13 | mqtt_plugin_intf.c
14 | schema.c
15 | ptformat.pb-c.c
16 | )
17 |
18 | target_include_directories(${PROJECT_NAME} PRIVATE
19 | ${CMAKE_SOURCE_DIR}/include/neuron
20 | ${CMAKE_SOURCE_DIR}/plugins/mqtt
21 | )
22 |
23 | target_link_libraries(${PROJECT_NAME} neuron-base)
24 | target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
25 |
26 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/mqtt/aws-iot.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
27 |
28 | set(AWS_PLUGIN "plugin-aws-iot")
29 |
30 | add_library(${AWS_PLUGIN} SHARED
31 | mqtt_config.c
32 | mqtt_handle.c
33 | mqtt_plugin_intf.c
34 | aws_iot_plugin.c
35 | schema.c
36 | ptformat.pb-c.c
37 | )
38 |
39 | target_include_directories(${AWS_PLUGIN} PRIVATE
40 | ${CMAKE_SOURCE_DIR}/include/neuron
41 | ${CMAKE_SOURCE_DIR}/plugins/mqtt
42 | )
43 |
44 | target_link_libraries(${AWS_PLUGIN} neuron-base)
45 | target_link_libraries(${AWS_PLUGIN} ${CMAKE_THREAD_LIBS_INIT})
46 |
47 | file(COPY ${CMAKE_SOURCE_DIR}/plugins/mqtt/azure-iot.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
48 |
49 | set(AZURE_PLUGIN "plugin-azure-iot")
50 |
51 | add_library(${AZURE_PLUGIN} SHARED
52 | mqtt_config.c
53 | mqtt_handle.c
54 | mqtt_plugin_intf.c
55 | azure_iot_plugin.c
56 | schema.c
57 | ptformat.pb-c.c
58 | )
59 |
60 | target_include_directories(${AZURE_PLUGIN} PRIVATE
61 | ${CMAKE_SOURCE_DIR}/include/neuron
62 | ${CMAKE_SOURCE_DIR}/plugins/mqtt
63 | )
64 |
65 | target_link_libraries(${AZURE_PLUGIN} neuron-base)
66 | target_link_libraries(${AZURE_PLUGIN} ${CMAKE_THREAD_LIBS_INIT})
67 |
--------------------------------------------------------------------------------
/plugins/mqtt/aws_iot_plugin.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #include "utils/asprintf.h"
21 | #include "utils/time.h"
22 |
23 | #include "mqtt_config.h"
24 | #include "mqtt_handle.h"
25 | #include "mqtt_plugin.h"
26 | #include "mqtt_plugin_intf.h"
27 |
28 | #define DESCRIPTION "Northbound MQTT plugin bases on NanoSDK."
29 | #define DESCRIPTION_ZH "基于 NanoSDK 的北向应用 MQTT 插件"
30 |
31 | const neu_plugin_module_t neu_plugin_module = {
32 | .version = NEURON_PLUGIN_VER_1_0,
33 | .schema = "aws-iot",
34 | .module_name = "AWS IoT",
35 | .module_descr = DESCRIPTION,
36 | .module_descr_zh = DESCRIPTION_ZH,
37 | .intf_funs = &mqtt_plugin_intf_funs,
38 | .kind = NEU_PLUGIN_KIND_SYSTEM,
39 | .type = NEU_NA_TYPE_APP,
40 | .display = true,
41 | .single = false,
42 | };
43 |
--------------------------------------------------------------------------------
/plugins/mqtt/mqtt_plugin.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #include "utils/asprintf.h"
21 | #include "utils/time.h"
22 |
23 | #include "mqtt_config.h"
24 | #include "mqtt_handle.h"
25 | #include "mqtt_plugin.h"
26 | #include "mqtt_plugin_intf.h"
27 |
28 | #define DESCRIPTION "Northbound MQTT plugin bases on NanoSDK."
29 | #define DESCRIPTION_ZH "基于 NanoSDK 的北向应用 MQTT 插件"
30 |
31 | const neu_plugin_module_t neu_plugin_module = {
32 | .version = NEURON_PLUGIN_VER_1_0,
33 | .schema = "mqtt",
34 | .module_name = "MQTT",
35 | .module_descr = DESCRIPTION,
36 | .module_descr_zh = DESCRIPTION_ZH,
37 | .intf_funs = &mqtt_plugin_intf_funs,
38 | .kind = NEU_PLUGIN_KIND_SYSTEM,
39 | .type = NEU_NA_TYPE_APP,
40 | .display = true,
41 | .single = false,
42 | };
43 |
--------------------------------------------------------------------------------
/plugins/mqtt/mqtt_plugin_intf.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_PLUGIN_MQTT_INTF_H
21 | #define NEURON_PLUGIN_MQTT_INTF_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include "neuron.h"
28 |
29 | extern const neu_plugin_intf_funs_t mqtt_plugin_intf_funs;
30 |
31 | neu_plugin_t *mqtt_plugin_open(void);
32 | int mqtt_plugin_close(neu_plugin_t *plugin);
33 | int mqtt_plugin_init(neu_plugin_t *plugin, bool load);
34 | int mqtt_plugin_uninit(neu_plugin_t *plugin);
35 | int mqtt_plugin_config(neu_plugin_t *plugin, const char *setting);
36 | int mqtt_plugin_start(neu_plugin_t *plugin);
37 | int mqtt_plugin_stop(neu_plugin_t *plugin);
38 | int mqtt_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
39 | void *data);
40 |
41 | #ifdef __cplusplus
42 | }
43 | #endif
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/plugins/restful/adapter_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_PLUGIN_REST_ADAPTER_HANDLE_H_
20 | #define _NEU_PLUGIN_REST_ADAPTER_HANDLE_H_
21 |
22 | #include
23 |
24 | #include "adapter.h"
25 |
26 | void handle_add_adapter(nng_aio *aio);
27 | void handle_update_adapter(nng_aio *aio);
28 | void handle_del_adapter(nng_aio *aio);
29 | void handle_get_adapter(nng_aio *aio);
30 | void handle_get_adapter_resp(nng_aio *aio, neu_resp_get_node_t *nodes);
31 |
32 | void handle_set_node_setting(nng_aio *aio);
33 | void handle_get_node_setting(nng_aio *aio);
34 | void handle_get_node_setting_resp(nng_aio * aio,
35 | neu_resp_get_node_setting_t *setting);
36 |
37 | void handle_node_ctl(nng_aio *aio);
38 | void handle_get_node_state(nng_aio *aio);
39 | void handle_get_node_state_resp(nng_aio *aio, neu_resp_get_node_state_t *state);
40 | void handle_get_nodes_state_resp(nng_aio * aio,
41 | neu_resp_get_nodes_state_t *states);
42 |
43 | void handle_put_drivers(nng_aio *aio);
44 |
45 | #endif
--------------------------------------------------------------------------------
/plugins/restful/cid_handle.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "define.h"
5 | #include "errcodes.h"
6 | #include "handle.h"
7 | #include "utils/cid.h"
8 | #include "utils/http.h"
9 | #include "utils/log.h"
10 | #include "json/neu_json_error.h"
11 | #include "json/neu_json_fn.h"
12 |
13 | #include "parser/neu_json_cid.h"
14 |
15 | void handle_cid(nng_aio *aio)
16 | {
17 | neu_plugin_t *plugin = neu_rest_get_plugin();
18 | (void) plugin;
19 |
20 | NEU_PROCESS_HTTP_REQUEST(
21 | aio, neu_json_upload_cid_t, neu_json_decode_upload_cid_req, {
22 | cid_t cid = { 0 };
23 | int parse_re = neu_cid_parse(req->path, &cid);
24 | if (parse_re == 0) {
25 | neu_reqresp_head_t header = { 0 };
26 | neu_req_add_gtag_t cmd = { 0 };
27 | header.ctx = aio;
28 | header.type = NEU_REQ_ADD_GTAG;
29 | header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
30 |
31 | nlog_notice("cid parse success: %s", req->path);
32 | neu_cid_to_msg(req->driver, &cid, &cmd);
33 | int ret = neu_plugin_op(plugin, header, &cmd);
34 | if (ret != 0) {
35 | NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
36 | neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
37 | });
38 | }
39 | neu_cid_free(&cid);
40 | } else {
41 | NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_CID, {
42 | neu_http_response(aio, NEU_ERR_INVALID_CID, result_error);
43 | });
44 | }
45 | })
46 | }
--------------------------------------------------------------------------------
/plugins/restful/cid_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_PLUGIN_REST_CID_HANDLE_H_
20 | #define _NEU_PLUGIN_REST_CID_HANDLE_H_
21 |
22 | #include
23 |
24 | void handle_cid(nng_aio *aio);
25 |
26 | #endif
--------------------------------------------------------------------------------
/plugins/restful/datalayers_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_PLUGIN_REST_DATALAYERS_HANDLE_H_
21 | #define _NEU_PLUGIN_REST_DATALAYERS_HANDLE_H_
22 |
23 | #include
24 |
25 | #include "adapter.h"
26 |
27 | void handle_datalayers_get_groups(nng_aio *aio);
28 | void handle_datalayers_get_groups_resp(nng_aio * aio,
29 | neu_resp_get_subscribe_group_t *groups);
30 |
31 | void handle_datalayers_get_tags(nng_aio *aio);
32 | void handle_datalayers_get_tags_resp(nng_aio * aio,
33 | neu_resp_get_sub_driver_tags_t *tags);
34 |
35 | void handle_datalayers_get_tag(nng_aio *aio);
36 | void handle_datalayers_get_tag_resp(nng_aio * aio,
37 | neu_resp_get_sub_driver_tags_t *tags);
38 |
39 | #endif
--------------------------------------------------------------------------------
/plugins/restful/datatag_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_PLUGIN_REST_DATATAG_HANDLE_H_
21 | #define _NEU_PLUGIN_REST_DATATAG_HANDLE_H_
22 |
23 | #include
24 |
25 | #include "adapter.h"
26 |
27 | void handle_add_tags(nng_aio *aio);
28 | void handle_add_tags_resp(nng_aio *aio, neu_resp_add_tag_t *resp);
29 | void handle_add_gtags(nng_aio *aio);
30 | void handle_add_gtags_resp(nng_aio *aio, neu_resp_add_tag_t *resp);
31 | void handle_del_tags(nng_aio *aio);
32 | void handle_update_tags(nng_aio *aio);
33 | void handle_update_tags_resp(nng_aio *aio, neu_resp_update_tag_t *resp);
34 | void handle_get_tags(nng_aio *aio);
35 | void handle_get_tags_resp(nng_aio *aio, neu_resp_get_tag_t *tags);
36 |
37 | #endif
--------------------------------------------------------------------------------
/plugins/restful/global_config_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_PLUGIN_REST_GLOBAL_CONFIG_HANDLE_H_
20 | #define _NEU_PLUGIN_REST_GLOBAL_CONFIG_HANDLE_H_
21 |
22 | #include
23 |
24 | #include "adapter.h"
25 |
26 | void handle_get_global_config(nng_aio *aio);
27 | void handle_put_global_config(nng_aio *aio);
28 |
29 | void handle_get_drivers(nng_aio *aio);
30 |
31 | void handle_global_config_resp(nng_aio *aio, neu_reqresp_type_e type,
32 | void *data);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/plugins/restful/group_config_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_PLUGIN_REST_GROUP_CONFIG_HANDLE_H_
20 | #define _NEU_PLUGIN_REST_GROUP_CONFIG_HANDLE_H_
21 |
22 | #include
23 |
24 | #include "adapter.h"
25 |
26 | void handle_add_group_config(nng_aio *aio);
27 | void handle_update_group(nng_aio *aio);
28 | void handle_del_group_config(nng_aio *aio);
29 | void handle_get_group_config(nng_aio *aio);
30 | void handle_get_group_resp(nng_aio *aio, neu_resp_get_group_t *groups);
31 | void handle_get_driver_group_resp(nng_aio * aio,
32 | neu_resp_get_driver_group_t *groups);
33 |
34 | void handle_grp_subscribe(nng_aio *aio);
35 | void handle_grp_update_subscribe(nng_aio *aio);
36 | void handle_grp_unsubscribe(nng_aio *aio);
37 | void handle_grp_subscribes(nng_aio *aio);
38 | void handle_grp_get_subscribe(nng_aio *aio);
39 | void handle_grp_get_subscribe_resp(nng_aio * aio,
40 | neu_resp_get_subscribe_group_t *groups);
41 |
42 | #endif
--------------------------------------------------------------------------------
/plugins/restful/handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_PLUGIN_REST_HANDLE_H_
21 | #define _NEU_PLUGIN_REST_HANDLE_H_
22 |
23 | #include
24 |
25 | #include "plugin.h"
26 | #include "utils/http_handler.h"
27 |
28 | typedef struct neu_rest_handle_ctx neu_rest_handle_ctx_t;
29 |
30 | neu_rest_handle_ctx_t *neu_rest_init_ctx(void *plugin);
31 | void neu_rest_free_ctx(neu_rest_handle_ctx_t *ctx);
32 | void * neu_rest_get_plugin();
33 |
34 | void neu_rest_handler(const struct neu_http_handler **handlers, uint32_t *size);
35 | void neu_rest_api_cors_handler(const struct neu_http_handler **handlers,
36 | uint32_t * size);
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/plugins/restful/log_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_LOG_HANDLE_H_
21 | #define _NEU_LOG_HANDLE_H_
22 |
23 | #include
24 |
25 | // void handle_get_log(nng_aio *aio);
26 | void handle_log_level(nng_aio *aio);
27 | void handle_log_list(nng_aio *aio);
28 | void handle_log_file(nng_aio *aio);
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/plugins/restful/metric_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEU_PLUGIN_REST_METRIC_H
21 | #define NEU_PLUGIN_REST_METRIC_H
22 |
23 | #include
24 |
25 | #include "json/neu_json_fn.h"
26 |
27 | void handle_get_metric(nng_aio *aio);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/plugins/restful/normal_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_NORMAL_HANDLE_H_
21 | #define _NEU_NORMAL_HANDLE_H_
22 |
23 | #include
24 |
25 | #include "msg.h"
26 |
27 | void handle_ping(nng_aio *aio);
28 | void handle_login(nng_aio *aio);
29 | void handle_password(nng_aio *aio);
30 | void handle_get_plugin_schema(nng_aio *aio);
31 | void handle_get_plugin_schema_resp(nng_aio *aio, neu_resp_check_schema_t *resp);
32 | void handle_status(nng_aio *aio);
33 |
34 | void handle_get_user(nng_aio *aio);
35 | void handle_add_user(nng_aio *aio);
36 | void handle_update_user(nng_aio *aio);
37 | void handle_delete_user(nng_aio *aio);
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/plugins/restful/otel_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_OTEL_HANDLE_H_
21 | #define _NEU_OTEL_HANDLE_H_
22 |
23 | #include
24 |
25 | void handle_otel(nng_aio *aio);
26 |
27 | void handle_otel_get(nng_aio *aio);
28 |
29 | #endif
--------------------------------------------------------------------------------
/plugins/restful/plugin_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_PLUGIN_REST_PLUGIN_HANDLE_H_
20 | #define _NEU_PLUGIN_REST_PLUGIN_HANDLE_H_
21 |
22 | #include
23 |
24 | void handle_add_plugin(nng_aio *aio);
25 | void handle_del_plugin(nng_aio *aio);
26 | void handle_update_plugin(nng_aio *aio);
27 | void handle_get_plugin(nng_aio *aio);
28 | void handle_get_plugin_resp(nng_aio *aio, neu_resp_get_plugin_t *plugins);
29 |
30 | #endif
--------------------------------------------------------------------------------
/plugins/restful/rest.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_PLUGIN_REST_H_
21 | #define _NEU_PLUGIN_REST_H_
22 |
23 | #include "plugin.h"
24 |
25 | extern const neu_plugin_module_t default_dashboard_plugin_module;
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/plugins/restful/rw_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_RW_HANDLE_H_
21 | #define _NEU_RW_HANDLE_H_
22 |
23 | #include
24 |
25 | #include "adapter.h"
26 |
27 | void handle_rw_init();
28 | void handle_rw_uninit();
29 | void handle_read(nng_aio *aio);
30 | void handle_read_paginate(nng_aio *aio);
31 | void handle_test_read_tag(nng_aio *aio);
32 | void handle_write(nng_aio *aio);
33 | void handle_write_tags(nng_aio *aio);
34 | void handle_write_gtags(nng_aio *aio);
35 | void handle_read_resp(nng_aio *aio, neu_resp_read_group_t *resp);
36 | void handle_read_paginate_resp(nng_aio * aio,
37 | neu_resp_read_group_paginate_t *resp);
38 | void handle_test_read_tag_resp(nng_aio *aio, neu_resp_test_read_tag_t *resp);
39 | void handle_write_tags_resp(nng_aio *aio, neu_resp_write_tags_t *resp);
40 |
41 | #endif
--------------------------------------------------------------------------------
/plugins/restful/scan_handle.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "plugin.h"
4 | #include "utils/log.h"
5 | #include "json/neu_json_fn.h"
6 | #include "json/neu_json_scan.h"
7 |
8 | #include "handle.h"
9 | #include "utils/http.h"
10 |
11 | #include "scan_handle.h"
12 |
13 | void handle_scan_tags(nng_aio *aio)
14 | {
15 | neu_plugin_t *plugin = neu_rest_get_plugin();
16 |
17 | NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
18 | aio, neu_json_scan_tags_req_t, neu_json_decode_scan_tags_req, {
19 | neu_reqresp_head_t header = { 0 };
20 | neu_req_scan_tags_t cmd = { 0 };
21 | int err_type;
22 |
23 | nng_http_req *nng_req = nng_aio_get_input(aio, 0);
24 | nlog_notice("<%p> req %s %s", aio, nng_http_req_get_method(nng_req),
25 | nng_http_req_get_uri(nng_req));
26 | header.ctx = aio;
27 | header.type = NEU_REQ_SCAN_TAGS;
28 | header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
29 |
30 | if (NULL != req->node && NEU_NODE_NAME_LEN <= strlen(req->node)) {
31 | err_type = NEU_ERR_NODE_NAME_TOO_LONG;
32 | goto error;
33 | }
34 |
35 | if (NULL != req->id && NEU_TAG_ADDRESS_LEN <= strlen(req->id)) {
36 | err_type = NEU_ERR_NODE_NAME_TOO_LONG;
37 | goto error;
38 | }
39 |
40 | if (NULL != req->ctx && NEU_VALUE_SIZE <= strlen(req->ctx)) {
41 | err_type = NEU_ERR_NODE_NAME_TOO_LONG;
42 | goto error;
43 | }
44 |
45 | if (NULL != req->node) {
46 | strcpy(cmd.driver, req->node);
47 | }
48 |
49 | if (NULL != req->id) {
50 | strcpy(cmd.id, req->id);
51 | }
52 |
53 | if (NULL != req->ctx) {
54 | strcpy(cmd.ctx, req->ctx);
55 | }
56 |
57 | if (0 != neu_plugin_op(plugin, header, &cmd)) {
58 | NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
59 | neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
60 | });
61 | }
62 | goto success;
63 |
64 | error:
65 | NEU_JSON_RESPONSE_ERROR(
66 | err_type, { neu_http_response(aio, err_type, result_error); });
67 |
68 | success:;
69 | })
70 | }
71 |
72 | void handle_scan_tags_resp(nng_aio *aio, neu_resp_scan_tags_t *resp)
73 | {
74 | char *result = NULL;
75 | neu_json_encode_by_fn(resp, neu_json_encode_scan_tags_resp, &result);
76 | neu_http_ok(aio, result);
77 | free(result);
78 | }
79 |
--------------------------------------------------------------------------------
/plugins/restful/scan_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_SCAN_HANDLE_H_
21 | #define _NEU_ACAN_HANDLE_H_
22 |
23 | #include
24 |
25 | void handle_scan_tags(nng_aio *aio);
26 | void handle_scan_tags_resp(nng_aio *aio, neu_resp_scan_tags_t *resp);
27 | void handle_scan_tag(nng_aio *aio);
28 |
29 | #endif
--------------------------------------------------------------------------------
/plugins/restful/system_handle.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include "json/neu_json_fn.h"
15 |
16 | #include "handle.h"
17 | #include "utils/http.h"
18 | #include "utils/neu_jwt.h"
19 |
20 | #include "parser/neu_json_system.h"
21 | #include "system_handle.h"
22 |
23 | void handle_system_ctl(nng_aio *aio)
24 | {
25 | NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
26 | aio, neu_json_system_ctl_req_t, neu_json_decode_system_ctl_req, {
27 | if (req->action == 1) {
28 | neu_http_ok(aio, "{\"error\": 0 }");
29 | exit(-2);
30 | }
31 | })
32 | }
--------------------------------------------------------------------------------
/plugins/restful/system_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_SYSTEM_HANDLE_H_
21 | #define _NEU_SYSTEM_HANDLE_H_
22 |
23 | #include
24 |
25 | void handle_system_ctl(nng_aio *aio);
26 |
27 | #endif
--------------------------------------------------------------------------------
/plugins/restful/user.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_REST_USER_H
21 | #define NEURON_REST_USER_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | #include
28 |
29 | #include "persist/persist.h"
30 |
31 | typedef struct {
32 | char *name;
33 | char *hash;
34 | } neu_user_t;
35 |
36 | neu_user_t *neu_user_new(const char *name, const char *password);
37 | void neu_user_free(neu_user_t *user);
38 | bool neu_user_check_password(neu_user_t *user, const char *password);
39 | int neu_user_update_password(neu_user_t *user, const char *new_password);
40 |
41 | neu_user_t *neu_load_user(const char *name);
42 | int neu_save_user(neu_user_t *user);
43 |
44 | UT_array *neu_user_list();
45 | int neu_user_add(const char *name, const char *password);
46 | int neu_user_delete(const char *name);
47 |
48 | #ifdef __cplusplus
49 | }
50 | #endif
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/plugins/restful/version_handle.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #include "utils/asprintf.h"
21 | #include "utils/log.h"
22 | #include "version.h"
23 | #include "json/neu_json_error.h"
24 | #include "json/neu_json_fn.h"
25 |
26 | #include "handle.h"
27 | #include "utils/http.h"
28 |
29 | void handle_get_version(nng_aio *aio)
30 | {
31 | char *result = NULL;
32 |
33 | NEU_VALIDATE_JWT(aio);
34 |
35 | int ret = neu_asprintf(
36 | &result,
37 | "{\"version\":\"%s\", \"revision\":\"%s\", \"build_date\":\"%s\"}",
38 | NEURON_VERSION, NEURON_GIT_REV NEURON_GIT_DIFF, NEURON_BUILD_DATE);
39 |
40 | if (ret < 0) {
41 | NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, {
42 | neu_http_response(aio, error_code.error, result_error);
43 | });
44 | return;
45 | }
46 |
47 | neu_http_response(aio, 0, result);
48 | free(result);
49 | }
50 |
--------------------------------------------------------------------------------
/plugins/restful/version_handle.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_VERSION_HANDLE_H_
21 | #define _NEU_VERSION_HANDLE_H_
22 |
23 | #include
24 |
25 | void handle_get_version(nng_aio *aio);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/sdk-install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | neuron_bin="/usr/local/bin/neuron"
6 | neuron_include="/usr/local/include/neuron"
7 | neuron_lib="/usr/local/lib/neuron"
8 |
9 | cp neuron.conf /etc/ld.so.conf.d/
10 |
11 | mkdir -p /usr/local/lib/cmake/neuron/
12 | cp neuron-config.cmake /usr/local/lib/cmake/neuron/
13 |
14 | mkdir -p ${neuron_include}
15 | cp -r include/neuron/* ${neuron_include}/
16 |
17 | mkdir -p ${neuron_lib}
18 | cp lib/* ${neuron_lib}/
19 |
20 | mkdir -p ${neuron_bin}
21 | mkdir -p ${neuron_bin}/config
22 | mkdir -p ${neuron_bin}/persistence
23 | mkdir -p ${neuron_bin}/plugins
24 |
25 | cp ./neuron ${neuron_bin}/
26 | cp config/sdk-zlog.conf ${neuron_bin}/config/zlog.conf
27 | cp config/dev.conf ${neuron_bin}/config/
28 | cp config/default_plugins.json ${neuron_bin}/config/
29 | cp config/*.sql ${neuron_bin}/config/
30 |
31 | cp -r plugins/* ${neuron_bin}/plugins/
32 |
33 | cp -r dist ${neuron_bin}/
34 |
35 | ldconfig
36 |
37 | echo "Install neuron header to ${neuron_include}, include_directories ${neuron_include} in CMakeLists.txt."
38 | echo "Install neuron library to ${neuron_lib}, link_directories ${neuron_lib} in CMakeLists.txt."
39 | echo "Install neuron to ${neuron_bin}, the custom plugin is placed in the ${neuron_bin}/plugins directory and the ${neuron_bin}/persistence/plugins.json is modified."
40 |
--------------------------------------------------------------------------------
/sdk-zlog.conf:
--------------------------------------------------------------------------------
1 | [global]
2 |
3 | reload conf period = 60
4 | file perms = 666
5 |
6 | [formats]
7 |
8 | simple = "%d [%V] %f:%L %m%n"
9 |
10 | [rules]
11 |
12 | *.INFO "/var/log/neuron/%c.log", 100MB * 10 ~ "/var/log/neuron/%c-%d(%Y%m%d).#2s.log"; simple
13 |
--------------------------------------------------------------------------------
/simulator/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.12)
2 |
3 | project(simulator)
4 |
5 | if(NOT CMAKE_STAGING_PREFIX)
6 | if(APPLE)
7 | include_directories(/usr/local/include /usr/local/opt/openssl/include)
8 | link_directories(/usr/local/lib /usr/local/opt/openssl/lib)
9 | else()
10 | link_directories(/usr/local/lib)
11 | endif()
12 | else()
13 | set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
14 | include_directories(${CMAKE_STAGING_PREFIX}/openssl/include)
15 | link_directories(${CMAKE_STAGING_PREFIX}/openssl/lib)
16 | endif()
17 | find_package(Threads)
18 |
19 |
20 | add_executable(modbus_simulator modbus_simulator.c modbus_s.c)
21 | target_include_directories(modbus_simulator PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron ${CMAKE_SOURCE_DIR})
22 | target_link_libraries(modbus_simulator neuron-base ${CMAKE_THREAD_LIBS_INIT} dl)
23 |
24 | add_executable(modbus_tty_simulator modbus_tty_simulator.c modbus_s.c)
25 | target_include_directories(modbus_tty_simulator PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron ${CMAKE_SOURCE_DIR})
26 | target_link_libraries(modbus_tty_simulator neuron-base ${CMAKE_THREAD_LIBS_INIT} dl)
--------------------------------------------------------------------------------
/simulator/modbus_s.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef SIMULATOR_MODBUS_S_H
20 | #define SIMULATOR_MODBUS_S_H
21 |
22 | #include
23 | #include
24 | #include
25 |
26 | void modbus_s_init();
27 |
28 | void modbus_s_simulate_error(bool b);
29 |
30 | ssize_t modbus_s_rtu_req(uint8_t *req, uint16_t req_len, uint8_t *res,
31 | int res_mlen, int *res_len);
32 | ssize_t modbus_s_tcp_req(uint8_t *req, uint16_t req_len, uint8_t *res,
33 | int res_mlen, int *res_len);
34 |
35 | #endif
--------------------------------------------------------------------------------
/simulator/otel_server.py:
--------------------------------------------------------------------------------
1 | from http.server import BaseHTTPRequestHandler, HTTPServer
2 | import json
3 | import sys
4 |
5 |
6 | class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
7 | def do_POST(self):
8 | if self.path == '/v1/traces':
9 | print(f'Received request')
10 | self.send_response(200)
11 | self.send_header('Content-type', 'application/json')
12 | self.end_headers()
13 | response = json.dumps({"status": "success"})
14 | self.wfile.write(response.encode('utf-8'))
15 | else:
16 | self.send_response(404)
17 | self.end_headers()
18 | self.wfile.write(b'Not Found')
19 |
20 |
21 | def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler, port=4318):
22 | server_address = ('', port)
23 | httpd = server_class(server_address, handler_class)
24 | print(f'Starting httpd server on port {port}...')
25 | httpd.serve_forever()
26 |
27 |
28 | if __name__ == '__main__':
29 | if len(sys.argv) > 1:
30 | try:
31 | port = int(sys.argv[1])
32 | except ValueError:
33 | print("Invalid port number. Using default port 8080.")
34 | port = 4318
35 | else:
36 | port = 4318
37 | run(port=port)
38 |
--------------------------------------------------------------------------------
/src/adapter/app/app.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
--------------------------------------------------------------------------------
/src/adapter/app/app_internal.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
--------------------------------------------------------------------------------
/src/adapter/msg_q.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef ADAPTER_MSG_Q_H
21 | #define ADAPTER_MSG_Q_H
22 |
23 | #include
24 |
25 | #include "base/msg_internal.h"
26 | #include "msg.h"
27 |
28 | typedef struct adapter_msg_q adapter_msg_q_t;
29 |
30 | adapter_msg_q_t *adapter_msg_q_new(const char *name, uint32_t size);
31 | void adapter_msg_q_free(adapter_msg_q_t *q);
32 |
33 | int adapter_msg_q_push(adapter_msg_q_t *q, neu_msg_t *msg);
34 | uint32_t adapter_msg_q_pop(adapter_msg_q_t *q, neu_msg_t **p_data);
35 |
36 | #endif
--------------------------------------------------------------------------------
/src/adapter/storage.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef ADAPTER_STORAGE_H
21 | #define ADAPTER_STORAGE_H
22 |
23 | #include "persist/persist.h"
24 |
25 | #include "adapter_internal.h"
26 |
27 | void adapter_storage_state(const char *node, neu_node_running_state_e state);
28 | void adapter_storage_setting(const char *node, const char *setting);
29 | void adapter_storage_add_group(const char *node, const char *group,
30 | uint32_t interval, void *context);
31 | void adapter_storage_update_group(const char *node, const char *group,
32 | const char *new_name, uint32_t interval);
33 | void adapter_storage_del_group(const char *node, const char *group);
34 | void adapter_storage_add_tag(const char *node, const char *group,
35 | const neu_datatag_t *tag);
36 | void adapter_storage_add_tags(const char *node, const char *group,
37 | const neu_datatag_t *tags, size_t n);
38 | void adapter_storage_update_tag(const char *node, const char *group,
39 | const neu_datatag_t *tag);
40 | void adapter_storage_update_tag_value(const char *node, const char *group,
41 | const neu_datatag_t *tag);
42 | void adapter_storage_del_tag(const char *node, const char *group,
43 | const char *name);
44 |
45 | int adapter_load_setting(const char *node, char **setting);
46 | int adapter_load_group_and_tag(neu_adapter_driver_t *driver);
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/src/base/msg.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #include "msg.h"
21 | #include "utils/log.h"
22 |
23 | #include "msg_internal.h"
24 |
25 | void neu_msg_gen(neu_reqresp_head_t *header, void *data)
26 | {
27 | size_t data_size = neu_reqresp_size(header->type);
28 | assert(header->len >= sizeof(neu_reqresp_head_t) + data_size);
29 | memcpy((uint8_t *) &header[1], data, data_size);
30 | }
--------------------------------------------------------------------------------
/src/core/manager.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_MANAGER_H_
21 | #define _NEU_MANAGER_H_
22 |
23 | #include "utils/utextend.h"
24 |
25 | #include "persist/persist.h"
26 |
27 | #include "manager_internal.h"
28 |
29 | neu_manager_t *neu_manager_create();
30 | void neu_manager_destroy(neu_manager_t *manager);
31 |
32 | uint16_t neu_manager_get_port();
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/src/core/storage.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef _NEU_MANAGER_STORAGE_H_
21 | #define _NEU_MANAGER_STORAGE_H_
22 |
23 | #include "persist/persist.h"
24 |
25 | #include "manager_internal.h"
26 |
27 | void manager_strorage_plugin(neu_manager_t *manager);
28 | void manager_storage_del_node(neu_manager_t *manager, const char *node);
29 | void manager_storage_add_node(neu_manager_t *manager, const char *node);
30 | void manager_storage_update_node(neu_manager_t *manager, const char *node,
31 | const char *new_name);
32 | void manager_storage_subscribe(neu_manager_t *manager, const char *app,
33 | const char *driver, const char *group,
34 | const char *params, const char *static_tags);
35 | void manager_storage_update_subscribe(neu_manager_t *manager, const char *app,
36 | const char *driver, const char *group,
37 | const char *params,
38 | const char *static_tags);
39 | void manager_storage_unsubscribe(neu_manager_t *manager, const char *app,
40 | const char *driver, const char *group);
41 |
42 | void manager_storage_inst_node(neu_manager_t *manager, const char *tmpl_name,
43 | const char *node);
44 |
45 | int manager_load_plugin(neu_manager_t *manager);
46 | int manager_load_node(neu_manager_t *manager);
47 | int manager_load_subscribe(neu_manager_t *manager);
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/src/daemon.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #ifndef NEURON_DAEMON_H
21 | #define NEURON_DAEMON_H
22 |
23 | #define NEURON_DAEMON_LOCK_FNAME "/tmp/neuron.pid"
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | /** Turn the calling process into a daemon.
30 | */
31 | void daemonize();
32 |
33 | /** Check if neuron is already running.
34 | */
35 | int neuron_already_running();
36 |
37 | int neuron_stop();
38 |
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/src/parser/neu_json_cid.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_JSON_CID_H_
26 | #define _NEU_JSON_API_NEU_JSON_CID_H_
27 |
28 | #include "define.h"
29 | #include "json/json.h"
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | typedef struct {
36 | char *driver;
37 | char *path;
38 | } neu_json_upload_cid_t;
39 |
40 | int neu_json_decode_upload_cid_req(char *buf, neu_json_upload_cid_t **result);
41 | void neu_json_decode_upload_cid_req_fini(neu_json_upload_cid_t *req);
42 | void neu_json_decode_upload_cid_req_free(neu_json_upload_cid_t *req);
43 |
44 | #ifdef __cplusplus
45 | }
46 | #endif
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/src/parser/neu_json_datalayers.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_JSON_DATALAYERS_H_
26 | #define _NEU_JSON_API_NEU_JSON_DATALAYERS_H_
27 |
28 | #include "json/json.h"
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | typedef struct {
35 | char *group;
36 | char *driver;
37 | char *params;
38 | char *static_tags;
39 | } neu_json_get_subscribe_resp_group_t;
40 |
41 | typedef struct {
42 | int n_group;
43 | neu_json_get_subscribe_resp_group_t *groups;
44 | } neu_json_get_subscribe_resp_t;
45 |
46 | int neu_json_encode_datalayers_get_groups_resp(void *json_object, void *param);
47 |
48 | int neu_json_encode_datalayers_get_tags_resp(void *json_object, void *param);
49 |
50 | int neu_json_encode_datalayers_get_tag_resp(void *json_object, void *param);
51 |
52 | #ifdef __cplusplus
53 | }
54 | #endif
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/src/parser/neu_json_error.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #include
26 | #include
27 |
28 | #include "json/json.h"
29 |
30 | #include "json/neu_json_error.h"
31 |
32 | int neu_json_encode_error_resp(void *json_object, void *param)
33 | {
34 | int ret = 0;
35 | neu_json_error_resp_t *resp = (neu_json_error_resp_t *) param;
36 |
37 | neu_json_elem_t resp_elems[] = { {
38 | .name = "error",
39 | .t = NEU_JSON_INT,
40 | .v.val_int = resp->error,
41 | } };
42 | ret = neu_json_encode_field(json_object, resp_elems,
43 | NEU_JSON_ELEM_SIZE(resp_elems));
44 |
45 | return ret;
46 | }
47 |
--------------------------------------------------------------------------------
/src/parser/neu_json_log.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_JSON_LOG_H_
26 | #define _NEU_JSON_API_NEU_JSON_LOG_H_
27 |
28 | #include "json/json.h"
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | typedef char *neu_json_get_log_resp_row_t;
35 |
36 | typedef struct {
37 | char *node_name;
38 | char *log_level;
39 | bool core;
40 | } neu_json_update_log_level_req_t;
41 |
42 | typedef struct {
43 | int64_t page_count;
44 | int n_row;
45 | neu_json_get_log_resp_row_t *rows;
46 | int64_t error;
47 | } neu_json_get_log_resp_t;
48 |
49 | typedef struct {
50 | char file[128];
51 | int size;
52 | } neu_resp_log_file_t;
53 |
54 | void neu_json_decode_update_log_level_req_free(
55 | neu_json_update_log_level_req_t *req);
56 | int neu_json_decode_update_log_level_req(
57 | char *buf, neu_json_update_log_level_req_t **result);
58 | int neu_json_encode_log_list_resp(void *json_object, void *param);
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/src/parser/neu_json_otel.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_JSON_OTEL_H_
26 | #define _NEU_JSON_API_NEU_JSON_OTEL_H_
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | typedef struct {
33 | char * action;
34 | char * collector_url;
35 | char * service_name;
36 | bool control_flag;
37 | bool data_flag;
38 | double data_sample_rate;
39 |
40 | } neu_json_otel_conf_req_t;
41 |
42 | void neu_json_decode_otel_conf_req_free(neu_json_otel_conf_req_t *req);
43 | int neu_json_decode_otel_conf_req(char *buf, neu_json_otel_conf_req_t **result);
44 | int neu_json_encode_otel_conf_req(void *json_object, void *param);
45 | #ifdef __cplusplus
46 | }
47 | #endif
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/src/parser/neu_json_system.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #include
26 | #include
27 |
28 | #include "json/json.h"
29 |
30 | #include "neu_json_system.h"
31 |
32 | void neu_json_decode_system_ctl_req_free(neu_json_system_ctl_req_t *req)
33 | {
34 | if (req != NULL) {
35 | free(req);
36 | }
37 | }
38 |
39 | int neu_json_decode_system_ctl_req(char * buf,
40 | neu_json_system_ctl_req_t **result)
41 | {
42 | int ret = 0;
43 | void *json_obj = neu_json_decode_new(buf);
44 |
45 | neu_json_system_ctl_req_t *req =
46 | calloc(1, sizeof(neu_json_system_ctl_req_t));
47 | if (req == NULL) {
48 | return -1;
49 | }
50 |
51 | neu_json_elem_t req_elems[] = {
52 | {
53 | .name = "action",
54 | .t = NEU_JSON_INT,
55 | },
56 | };
57 |
58 | ret = neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(req_elems),
59 | req_elems);
60 | if (ret != 0) {
61 | free(req);
62 | if (json_obj != NULL) {
63 | neu_json_decode_free(json_obj);
64 | }
65 | return -1;
66 | }
67 |
68 | req->action = req_elems[0].v.val_int;
69 | *result = req;
70 |
71 | if (json_obj != NULL) {
72 | neu_json_decode_free(json_obj);
73 | }
74 | return ret;
75 | }
--------------------------------------------------------------------------------
/src/parser/neu_json_system.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `json-autotype`.
23 | */
24 |
25 | #ifndef _NEU_JSON_API_NEU_JSON_SYSTEM_H_
26 | #define _NEU_JSON_API_NEU_JSON_SYSTEM_H_
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | typedef struct {
33 | int action;
34 | } neu_json_system_ctl_req_t;
35 |
36 | void neu_json_decode_system_ctl_req_free(neu_json_system_ctl_req_t *req);
37 | int neu_json_decode_system_ctl_req(char * buf,
38 | neu_json_system_ctl_req_t **result);
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/src/persist/datalayers/flight_sql_client.h:
--------------------------------------------------------------------------------
1 | #ifndef FLIGHT_SQL_CLIENT_H
2 | #define FLIGHT_SQL_CLIENT_H
3 |
4 | #include
5 |
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | typedef enum { INT_TYPE, FLOAT_TYPE, BOOL_TYPE, STRING_TYPE } ValueType;
11 |
12 | typedef union {
13 | int int_value;
14 | float float_value;
15 | bool bool_value;
16 | const char *string_value;
17 | } ValueUnion;
18 |
19 | typedef struct {
20 | const char *node_name;
21 | const char *group_name;
22 | const char *tag;
23 | ValueUnion value;
24 | ValueType value_type;
25 | } datatag;
26 |
27 | typedef struct {
28 | ValueType value_type;
29 | ValueUnion value;
30 | char time[64];
31 | char node_name[128];
32 | char group_name[128];
33 | char tag[128];
34 | } datarow;
35 |
36 | typedef struct {
37 | size_t row_count;
38 | datarow *rows;
39 | } query_result;
40 |
41 | typedef struct Client neu_datalayers_client;
42 |
43 | neu_datalayers_client *client_create(const char *host, int port,
44 | const char *username,
45 | const char *password);
46 |
47 | int client_execute(neu_datalayers_client *client, const char *sql);
48 |
49 | void client_destroy(neu_datalayers_client *client);
50 |
51 | int client_insert(neu_datalayers_client *client, ValueType type, datatag *tags,
52 | size_t tag_count);
53 |
54 | query_result *client_query(neu_datalayers_client *client, ValueType type,
55 | const char *node_name, const char *group_name,
56 | const char *tag);
57 |
58 | void client_query_free(query_result *result);
59 |
60 | query_result *client_query_nodes_groups(neu_datalayers_client *client,
61 | ValueType type);
62 |
63 | query_result *client_query_all_data(neu_datalayers_client *client,
64 | ValueType type);
65 |
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 |
70 | #endif
--------------------------------------------------------------------------------
/src/utils/asprintf.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #if defined(__GNUC__) && !defined(_GNU_SOURCE)
21 | #define _GNU_SOURCE
22 | #endif
23 |
24 | #if (defined(__unix__) || defined(unix)) && !defined(USG)
25 | #include
26 | #endif
27 |
28 | #include
29 | #include
30 |
31 | #include "utils/asprintf.h"
32 |
33 | int neu_asprintf(char **strp, const char *fmt, ...)
34 | {
35 | va_list ap;
36 | va_start(ap, fmt);
37 | int rv = neu_vasprintf(strp, fmt, ap);
38 | va_end(ap);
39 | return rv;
40 | }
41 |
42 | int neu_vasprintf(char **strp, const char *fmt, va_list ap)
43 | {
44 | #if defined(_GNU_SOURCE) || defined(BSD) || defined(__APPLE__)
45 | return vasprintf(strp, fmt, ap);
46 | #else
47 | int n = 1 + vsnprintf(NULL, 0, fmt, ap);
48 | char *s = malloc(n);
49 | if (NULL == s) {
50 | return -1;
51 | }
52 |
53 | n = vsnprintf(s, n, fmt, ap);
54 | *strp = s;
55 | return n;
56 | #endif
57 | }
58 |
--------------------------------------------------------------------------------
/src/utils/log.c:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | #include
21 | #include
22 |
23 | #include "define.h"
24 | #include "utils/log.h"
25 | #include "utils/utarray.h"
26 | #include "utils/utextend.h"
27 |
28 | static UT_array *collect_logs(const char *dir, const char *node)
29 | {
30 | DIR * dirp = NULL;
31 | struct dirent *dent = NULL;
32 | UT_array * files = NULL;
33 | char flag[NEU_NODE_NAME_LEN + 2] = { 0 };
34 |
35 | if ((dirp = opendir(dir)) == NULL) {
36 | nlog_error("fail open dir: %s", dir);
37 | return NULL;
38 | }
39 |
40 | utarray_new(files, &ut_str_icd);
41 | snprintf(flag, sizeof(flag), "%s.", node);
42 |
43 | while (NULL != (dent = readdir(dirp))) {
44 | if (strstr(dent->d_name, flag) != NULL) {
45 | char *file = dent->d_name;
46 | utarray_push_back(files, &file);
47 | }
48 | }
49 |
50 | closedir(dirp);
51 | return files;
52 | }
53 |
54 | void remove_logs(const char *node)
55 | {
56 | UT_array *files = collect_logs("./logs", node);
57 | if (files != NULL) {
58 | if (0 == utarray_len(files)) {
59 | nlog_warn("directory logs contains no log files of %s", node);
60 | }
61 |
62 | utarray_foreach(files, char **, file)
63 | {
64 | char path[NEU_NODE_NAME_LEN + 10] = { 0 };
65 | snprintf(path, sizeof(path), "./logs/%s", *file);
66 | if (remove(path) != 0) {
67 | nlog_warn("rm %s file fail", path);
68 | }
69 | }
70 | utarray_free(files);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/tests/ft/app/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/conftest.py:
--------------------------------------------------------------------------------
1 | import pytest
2 |
3 |
4 | def pytest_addoption(parser):
5 | parser.addoption(
6 | "--env", default="github", choices=["github", "test"], help="enviroment parameter"
7 | )
8 |
9 |
10 | @pytest.fixture(autouse=True, scope="session")
11 | def get_envx(request):
12 | return request.config.getoption("--env")
13 |
--------------------------------------------------------------------------------
/tests/ft/driver/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/group/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/http_api/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/log/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/login/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/login/neuron.json:
--------------------------------------------------------------------------------
1 | {
2 | "ip": "0.0.0.0",
3 | "port": 7000,
4 | "disable_auth": 1,
5 | "syslog_host": "",
6 | "syslog_port": 541,
7 | "sub_filter_error": 0
8 | }
9 |
--------------------------------------------------------------------------------
/tests/ft/login/sub_filter_error.json:
--------------------------------------------------------------------------------
1 | {
2 | "ip": "0.0.0.0",
3 | "port": 7000,
4 | "disable_auth": 0,
5 | "syslog_host": "",
6 | "syslog_port": 541,
7 | "sub_filter_error": 1
8 | }
9 |
--------------------------------------------------------------------------------
/tests/ft/login/test_login.py:
--------------------------------------------------------------------------------
1 | import os
2 | import sys
3 |
4 | import neuron.api as api
5 | from neuron.common import *
6 | from neuron.error import *
7 |
8 |
9 | class TestLogin:
10 |
11 | @description(given="name and password", when="login", then="login success with token")
12 | def test_login_success(self):
13 | response = api.login()
14 | assert 200 == response.status_code
15 |
16 | @description(given="invalid user", when="login", then="login failed")
17 | def test_login_invalid_user(self):
18 | response = api.login('invalid_user')
19 | assert 401 == response.status_code
20 | assert NEU_ERR_INVALID_USER_OR_PASSWORD == response.json()['error']
21 |
22 | @description(given="invalid password", when="login", then="login failed")
23 | def test_login_invalid_password(self):
24 | response = api.login(password='invalid_password')
25 | assert 401 == response.status_code
26 | assert NEU_ERR_INVALID_USER_OR_PASSWORD == response.json()['error']
27 |
28 | @description(given="user, old and new password", when="change password", then="change success")
29 | def test_change_password(self):
30 | response = api.change_password(new_password='invalid_password')
31 | assert 200 == response.status_code
32 | assert 0 == response.json()['error']
33 |
34 | response = api.login(password='invalid_password')
35 | assert 200 == response.status_code
36 |
--------------------------------------------------------------------------------
/tests/ft/neuron/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/emqx/neuron/b9516ba4d0f75b18a0ade9a5a12f69182d2cd2a0/tests/ft/neuron/__init__.py
--------------------------------------------------------------------------------
/tests/ft/neuron/common.py:
--------------------------------------------------------------------------------
1 | import time
2 | from functools import wraps
3 | import random
4 |
5 | import pytest
6 |
7 | import neuron.process as process
8 |
9 |
10 | class description(object):
11 | def __init__(self, given, when, then):
12 | self.given = given
13 | self.when = when
14 | self.then = then
15 |
16 | def __call__(self, func):
17 | @wraps(func)
18 | def wrapper(*args, **kwargs):
19 | ctx = kwargs.copy()
20 | given, when, then = eval('f"%s", f"%s", f"%s"' % (
21 | self.given, self.when, self.then), ctx)
22 | info = "Given " + given + ", when " + \
23 | when + ", then " + then + "."
24 | print('\033[1;33;40m')
25 | print("\n" + info)
26 | print('\033[0m', end=' Result: ')
27 | return func(*args, **kwargs)
28 | return wrapper
29 |
30 |
31 | def random_port():
32 | return random.randint(30000, 65530)
33 |
34 |
35 | def compare_float(v1, v2, delta=0.001):
36 | return abs(v1 - v2) < delta
37 |
38 |
39 | @pytest.fixture(autouse=True, scope='class')
40 | def class_setup_and_teardown():
41 | process.remove_persistence()
42 | p = process.NeuronProcess()
43 | p.start()
44 | yield p
45 | p.stop()
46 |
47 |
48 | @pytest.fixture(autouse=True, scope='function')
49 | def case_time():
50 | start = time.time()
51 | yield
52 | print(' Time cost: {:.3f}s'.format(time.time() - start))
53 |
--------------------------------------------------------------------------------
/tests/ft/neuron/data/__init__.py:
--------------------------------------------------------------------------------
1 | from base64 import b64encode
2 | import pathlib
3 |
4 |
5 | def base64(file):
6 | with open(file, "rb") as f:
7 | return b64encode(f.read()).decode("utf-8")
8 |
9 |
10 | data_dir = pathlib.Path(__file__).resolve().parent
11 | ca = str(data_dir / "ca.pem")
12 | ca_base64 = base64(ca)
13 | server_cert = str(data_dir / "server.pem")
14 | server_cert_base64 = base64(server_cert)
15 | server_key = str(data_dir / "server.key")
16 | server_key_base64 = base64(server_key)
17 | client_cert = str(data_dir / "client.pem")
18 | client_cert_base64 = base64(client_cert)
19 | client_key = str(data_dir / "client.key")
20 | client_key_base64 = base64(client_key)
21 |
--------------------------------------------------------------------------------
/tests/ft/neuron/data/ca.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIID2TCCAsGgAwIBAgIUNeeQubx1N4A+ySwcOVjbBu9nrPcwDQYJKoZIhvcNAQEL
3 | BQAwfDELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5nZG9uZzERMA8GA1UEBwwI
4 | U2hlbnpoZW4xDTALBgNVBAoMBGVtcXgxDTALBgNVBAsMBGVtcXgxEDAOBgNVBAMM
5 | B2NhaS5ib3QxFjAUBgkqhkiG9w0BCQEWB2NhaUBib3QwHhcNMjMwODI4MDcyMzQy
6 | WhcNMzMwODI1MDcyMzQyWjB8MQswCQYDVQQGEwJDTjESMBAGA1UECAwJR3Vhbmdk
7 | b25nMREwDwYDVQQHDAhTaGVuemhlbjENMAsGA1UECgwEZW1xeDENMAsGA1UECwwE
8 | ZW1xeDEQMA4GA1UEAwwHY2FpLmJvdDEWMBQGCSqGSIb3DQEJARYHY2FpQGJvdDCC
9 | ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANU8sgwP/kLDKNgAYwSk6Qd/
10 | ophEiqyHWZvvCCzmR3bNRQ+PuKtasXjrRO5l/6xfz51P6prbiRvn031JjgMUc5Jb
11 | kDvrJki/zhF8IS47z+9NTIemOW6/ajWoAGsnmDVqoFExBFxPQBvnMyiFi/dCTFyK
12 | /T+haW2tR3gIOEv0UPrdTbtvWpLAQY2Y3tfyHvEeaimgw8VFQXoKe7vbU/muvFZh
13 | 8Kq3+AEjUzG8UThyrObbROaE9PIuVYtcziqK+Du4IzT43+N+rnSnGWkCLRu6kOsq
14 | Tq6EcPYQs5LLJYJ+yOgpT68Z6UOO4xh8qIxGpO1aGkKjZRENOwd//sgbynOIc1sC
15 | AwEAAaNTMFEwHQYDVR0OBBYEFIy2R3kCh/vBALuaekERs7o1zsW0MB8GA1UdIwQY
16 | MBaAFIy2R3kCh/vBALuaekERs7o1zsW0MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZI
17 | hvcNAQELBQADggEBAGy51hXtNeIwF0aDks9BNV2iegNKBjQYTXg4r4+Bs018sD4W
18 | KvloYee7P3nr+s7WWHxokn9fJwABmwXrhJSuPGOPkZzW9zfwO9qPWnYkcIOvxohX
19 | lYM41Rngsp63fe/NKCWbNcwFuOuIxgC+lI6kRrPZY5PIqVLVv0nDuzma9F9OwoVz
20 | wXnTszVUTAkY8bLIhBx3rvXffz07mOM216H05Wh8GdWb1StjHEpNXL4dNk0s15Wn
21 | oQudGt/SQ98xTEYho8zQ5VhCFtzOcuYHhrQHHKNj3FeDFVSs4W35C204vF8pUZ3b
22 | 9e/Ss1sUaAgiPwfYadIF8+kf80noLm4Tyo1yoXA=
23 | -----END CERTIFICATE-----
24 |
--------------------------------------------------------------------------------
/tests/ft/neuron/data/client.key:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEowIBAAKCAQEAxkiDi8eR5e8tYzxQnw+Ps7g/FTURvyp6wigPM1gDn35BnWT4
3 | XN8C/yvp9pk2wQ/zuJRMLbCTc34q8ih/OHweymHxaPbYrw9/ghMkucqK/wsWTE72
4 | Ib+dlWQwN4hKzfKCq5BKkDveFVV9itW23707LXSR/h2uq5D6wocPUGEqEhR6tHeJ
5 | FwzzHGPlvMEX+19V5Aj3SYTZkr9DIlCB8vAIDfhR8gwsYRTp7aYcknuBPfbEfc+K
6 | nOsqPoX9YBz+p8lyf1S0WXOjiDnRSaGsAYLPBftQ4oAJStg2t0FBAzVvWuIT9NQe
7 | aDarAvA8SAp9U2tzPTJKlGXKKanTnm+Bwf0hjQIDAQABAoIBAC8xJw3nq9Pb/yN1
8 | QYL6Ayu1GF6FyPmEtL7tJeEEe6hENn2tgGcqNN5ip0an5J5Cm7E8qnzdX9rHFpWY
9 | Cd95uyJT+U8QITZZK/HbeIw3pqlZDC+RQ4d4wZrCw68T4yntJCiNKRH3Db5qIH0g
10 | rGvH8AO7kNu4WNBAq04NMxngZlDy348ud5oHzZCwCyOTD129JWVCbOAngaCmWHa+
11 | X+tYAT8bOR/pmoLbvu7B81Pa+GnuzfzRmz7FTxb2sILI174T/snDSxtX9aFszNN1
12 | 57Eqc09obpx+vcZL3akL/oVdjXNgVU9HtYtJS0vKr0onji6GUEOuJcLSsIBjvt5X
13 | ray2kkkCgYEA59rRQZxKT6oAwsFVWvyQ4IoBl83pzpVCjOq/NrSnoqQEFLN+7NK1
14 | OTeiiAP1P2nXmsCoyh99U40CAl9gVzQMbFR9tI6b0+ylgGZNDOhbUqf1qtJVZYHA
15 | /AGLaxdyZzIYxy3TdSPnGUcMIeutZdQDqA2SAyX26/lmJD7HXa3jUdsCgYEA2u6w
16 | ksVyQeI6PWmLZg/3JHcEFpo5jp1gdtjz9EMsx+cS/gFawcOk42JUS3351B0SMtZm
17 | drGcfCAjc5wKkkPZ9hZSs4ey7s0jOw4nofghVvt0IunFswgvjZwtpyf+dsvUjCsR
18 | hQMTB+r+rFn0HOEuogYg/nIzVcBT+nE963t2OrcCgYEAgQW96RsGJ2rdXYOk8isW
19 | nD1wQX/vGmzpSe3gVpsVpmZLdxGkEjn3a03QfoxlT9Kgjpej1kbLwVD4y0U0IZLv
20 | TuF9ypqJkNdiCh/jxMkQ+OBKz7KYnxIjyJk7cm7r1Q2FyGFyCP/fvKtSzxWNutrO
21 | 5hgXJvVbgVmaQ5VD8Jexpn0CgYBf86rZuMWZ0H+7+K0Kv0aO6caV7WP6eEkV7YIF
22 | 9QcEWeb+AjP3pjp3Gdpd98ltyIv4UfU4YiF2WVOQULxlXG2DqEb4vimS9b9SG6MN
23 | HsXl7HD6+EAYdib5RpDPqPyirjTqddnI1Q8bMkgJ26bcnWilxE/jlMOg+pkTs1vy
24 | //pSQwKBgH3mHa3ndm7EMp8Hn17sm+zdfC4BImpLCPbAC8n/HHdXA+bOZHCbe34t
25 | jQn/ef6pAWvqKR14Gx+uz9lA7vK3hPgcnjzQkEi7YwBv4F4r06uUw5MvWEP5mC+/
26 | EocORPKTDsvp5i1BXrDLLhjLsU85FbJqhJX73if1QZpxjrEB1bjn
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/tests/ft/neuron/data/client.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDVjCCAj4CFHF2xpoZ9cyNabuNRQN20G2W7exOMA0GCSqGSIb3DQEBCwUAMHwx
3 | CzAJBgNVBAYTAkNOMRIwEAYDVQQIDAlHdWFuZ2RvbmcxETAPBgNVBAcMCFNoZW56
4 | aGVuMQ0wCwYDVQQKDARlbXF4MQ0wCwYDVQQLDARlbXF4MRAwDgYDVQQDDAdjYWku
5 | Ym90MRYwFAYJKoZIhvcNAQkBFgdjYWlAYm90MB4XDTIzMDkwNzAyNTA1M1oXDTMz
6 | MDkwNDAyNTA1M1owUzELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFpoZWppYW5nMREw
7 | DwYDVQQHDAhIYW5nemhvdTENMAsGA1UECgwERU1RWDEPMA0GA1UEAwwGY2xpZW50
8 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxkiDi8eR5e8tYzxQnw+P
9 | s7g/FTURvyp6wigPM1gDn35BnWT4XN8C/yvp9pk2wQ/zuJRMLbCTc34q8ih/OHwe
10 | ymHxaPbYrw9/ghMkucqK/wsWTE72Ib+dlWQwN4hKzfKCq5BKkDveFVV9itW23707
11 | LXSR/h2uq5D6wocPUGEqEhR6tHeJFwzzHGPlvMEX+19V5Aj3SYTZkr9DIlCB8vAI
12 | DfhR8gwsYRTp7aYcknuBPfbEfc+KnOsqPoX9YBz+p8lyf1S0WXOjiDnRSaGsAYLP
13 | BftQ4oAJStg2t0FBAzVvWuIT9NQeaDarAvA8SAp9U2tzPTJKlGXKKanTnm+Bwf0h
14 | jQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQDTnLAjiJmXNVvVYOeDoTBlDnTrOE7/
15 | Am+U437M18Fji4loFit80H1mtxr+GQZOR/9COnlad5wtiWkypolILvEF6fL4Ftj9
16 | 1hLbeRsVB8nEbp1Ao160SS/tTAphXScxwj6DRXJ9Jr0ChGRyyiJcGZzOuUUtk4Kt
17 | b87YfVFqjmbr4Ob+gNWhP713OSSClcVwyHXsYKk1mpJm9BtwRPPs4mLBRyJNMQDf
18 | p8iMUxoBW067rp+5zU7GUsJakFRqyo9m5nBy0DN0EoMYPi4Nai4OxfbeRNf9ZDrx
19 | md/p3oStOGhmXOw3TkFhqIdyaH0BR1KeCAcmc5jpT2YvGy830+6WivWH
20 | -----END CERTIFICATE-----
21 |
--------------------------------------------------------------------------------
/tests/ft/neuron/data/server.key:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEowIBAAKCAQEA7of4vDxhZV2TCRnwtQ0y4wb8R7svMXXAfuuG7oDvg6a6Qh5J
3 | qjTNtleSaRLG/at61fuhDRDdnaHHV5LPcR2QlJWWirFbK52OeIeSPl58V58q+yml
4 | VUhA7ag7uYFSl1xYualVTUxeQZnEsZt4WtJQY1OfKeZ+P8uiTNlueN94VZ2DMTlN
5 | C+vn8AzgrKMh/S426Y9uX0juh/b+UA4TehcXDRp1Ueum31lFFZkB108f7ZlpAMkx
6 | dq3YZv37X0TfN5rWzNcHyqKI+gLad0hni4G/QzLQ5XcmLVN/YHDVFBY/9uGNiBJM
7 | 8TE/rnypna4vTN+SX/IZ6hmSZgdyrFxoAq7DVwIDAQABAoIBACJseRchV6T7Vibw
8 | GW7nkrp03Z+0geEPb1Jhxz1QWkCTpTm5iUQJDs8L4FNNpG4jezy6bcmm73S6Tjxz
9 | MYDPlXf8BpfJdLDcshzu48ogdK1oiRlqLzQZk1U4/DWPVk4Fw8A3kdnv9YJeIKbJ
10 | GxtwUq2i+ctgOkQWrTuN/YVwKrugEmWpFrDOOAYtW8qe/NdJRsljzMqUOyRHy1oe
11 | S0l6BpoxLW7E3S+QN71YqDCS0ewPNCIHwKqA+MEld6VqevYhO0ohmlehcvNV09VD
12 | fxKDpTJ0h6eMHZvQne2Tl0C3oSasxnZTQMHffGP0bjM3X/3SPkQbWedcsWreF644
13 | KznRHcECgYEA9z1kpheYYRQduQyP5VS4nRmDDpw0ZvxkebMlYH9G71qGf61m/iI7
14 | AJ+rcNAsjgOEPIrkEF47NnrEDfmBlkS4ApDPkgD/Ochi+bZbj5EufKNI07cjQSZk
15 | 6yjdtdYxLYkY94MpzF7nkeQRX2Fpc8Fhh70ojWPHcRcNXn1I3XLO6icCgYEA9vuV
16 | 9JXkUB5tc04mMsxY2on7pEkWpfRnmYLTcMeszaquK6t+U6DgW18Ev5qff3wo+0X9
17 | TvCrRt22XC+gFmzYSeKTVGhdWjdJnFpOHQ14IiQ5ngLdQW+RJolGqYvFFRK7ZpFk
18 | 0aJAMsJUtj4RAHq0Ve1JQDsBEgAd5pg1cbcBC1ECgYAUI0IBbUaSEatiGS3XRhFL
19 | anqMRBjYkpI0f2z58SP79umhmKQc6vjXUioKpEocvxiUPdPZqXM1OsahRMNTVAGQ
20 | 4+6kO8SOFk5JfJr0lKSurjYOWIpckh4CMW/tkaaryNDpyBstdEV0Upk/pZWLQiMJ
21 | hVS6P3hNM8149sdqkiFcXQKBgE4Aoxl+BX9wPKz/73x3oVBT58+47Zg4GkgXU2P5
22 | DBBgaWWNYfZThsgUuFEzKlB/DApfzmKSC+Xzu9ZdjDfI5H5hOpqb42/MqkjhFG6E
23 | hH5z5maLDQnPjI4ZKOH/LJ09L0ZzgN3cWl4tlceAzqnSFwZUTKAmgm4G72qWg7qI
24 | S6IhAoGBANEC140obgAtkUokYBrwFmJDTRFtVgQBjQL9oPmdZD7TvcowuMgCK0kG
25 | 2c3Qclc/sP4gkDIWuLCaxLRIZw46ECdxBWx7IUm9YYLjLRG1FHyzwxAmfrnJg0yi
26 | ALdfk6iS3ue56a/hhzmnArP5I9JroXH45a3ess8uF1EWQfuYx3E0
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/tests/ft/neuron/data/server.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDhzCCAm+gAwIBAgIUcXbGmhn1zI1pu41FA3bQbZbt7E0wDQYJKoZIhvcNAQEL
3 | BQAwfDELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5nZG9uZzERMA8GA1UEBwwI
4 | U2hlbnpoZW4xDTALBgNVBAoMBGVtcXgxDTALBgNVBAsMBGVtcXgxEDAOBgNVBAMM
5 | B2NhaS5ib3QxFjAUBgkqhkiG9w0BCQEWB2NhaUBib3QwHhcNMjMwODI4MDcyODQw
6 | WhcNMzMwODI1MDcyODQwWjBfMQswCQYDVQQGEwJDTjERMA8GA1UECAwIWmhlamlh
7 | bmcxETAPBgNVBAcMCEhhbmd6aG91MQ0wCwYDVQQKDARFTVFYMRswGQYDVQQDDBJT
8 | ZXJ2ZXIgY2VydGlmaWNhdGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
9 | AQDuh/i8PGFlXZMJGfC1DTLjBvxHuy8xdcB+64bugO+DprpCHkmqNM22V5JpEsb9
10 | q3rV+6ENEN2docdXks9xHZCUlZaKsVsrnY54h5I+XnxXnyr7KaVVSEDtqDu5gVKX
11 | XFi5qVVNTF5BmcSxm3ha0lBjU58p5n4/y6JM2W5433hVnYMxOU0L6+fwDOCsoyH9
12 | Ljbpj25fSO6H9v5QDhN6FxcNGnVR66bfWUUVmQHXTx/tmWkAyTF2rdhm/ftfRN83
13 | mtbM1wfKooj6Atp3SGeLgb9DMtDldyYtU39gcNUUFj/24Y2IEkzxMT+ufKmdri9M
14 | 35Jf8hnqGZJmB3KsXGgCrsNXAgMBAAGjHjAcMBoGA1UdEQQTMBGHBH8AAAGCCWxv
15 | Y2FsaG9zdDANBgkqhkiG9w0BAQsFAAOCAQEAnzyPz/3CAbLe6vn1GTIAh2wJ33AK
16 | 7xg2M2Ri5FQg24pcxl7s3J5u/ScVe1QXcoT0GIY1qLGUp2ha496MnrxlQlMfZcll
17 | bjjvoZSyZW8kgBdVWQ8Wfndsu7CFIYDLz5Olxa+vGApHpE5R7SwdcpD4mzaa8nRm
18 | pz2kXyAEeUgnvkavNdPEmbZgfmI528VYpyKQ+N5nHl8oj2xKjOF8Ar9+2Wvcovle
19 | t9Im64+1NJzBnQI+W3P17a5Nb2bL7xrfrTj8dt5ntMRQn2/A2EsuPjvzSMnK1KBN
20 | UQPPrKY+K3z7ut1T4S+HYTb5voG32yevQRXgaiUgfdN3dH+KbUVFUYrwQw==
21 | -----END CERTIFICATE-----
22 |
--------------------------------------------------------------------------------
/tests/ft/node/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/persist/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/plugin/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/ft/plugin/test_library_data.json:
--------------------------------------------------------------------------------
1 | {
2 | "node_config": {
3 | "node": "c1-a",
4 | "params": {
5 | "transport_mode": 0,
6 | "connection_mode": 0,
7 | "max_retries": 0,
8 | "retry_interval": 0,
9 | "interval": 20,
10 | "host": "127.0.0.1",
11 | "port": 502,
12 | "timeout": 3000
13 | }
14 | },
15 | "library_c1": "libplugin-c1.so",
16 | "library_s1": "libplugin-s1.so",
17 | "library_sc1": "libplugin-sc1.so"
18 | }
--------------------------------------------------------------------------------
/tests/ft/pytest.ini:
--------------------------------------------------------------------------------
1 | [pytest]
2 | python_files = test_*.py
3 | python_functions = test_*
4 |
5 | addopts = --strict-markers
6 |
7 | markers =
8 | test : 'test'
9 |
--------------------------------------------------------------------------------
/tests/ft/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 |
3 | packages = find_packages(include=["neuron*"])
4 | print("Found packages:", packages)
5 |
6 | setup(
7 | name="neuronft",
8 | version="0.0.2",
9 | description="Neuron function test utilities",
10 | author="Neuron Team",
11 | author_email="neuron@emqx.io",
12 | packages=packages,
13 | package_data={"neuron.data": ["*.key", "*.pem"]},
14 | )
15 |
--------------------------------------------------------------------------------
/tests/ft/tag/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | sys.path.append("tests/ft")
4 |
--------------------------------------------------------------------------------
/tests/plugins/c1/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/tests/plugins")
2 |
3 | set(CMAKE_BUILD_RPATH ./)
4 | file(COPY ${CMAKE_SOURCE_DIR}/tests/plugins/c1/c1.json DESTINATION ${CMAKE_BINARY_DIR}/tests/plugins/schema/)
5 |
6 |
7 | # v1
8 | set(PLUGIN_NAME plugin-c1)
9 | set(PLUGIN_SOURCES c1.c )
10 | add_library(${PLUGIN_NAME} SHARED)
11 | target_include_directories(${PLUGIN_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
12 | target_sources(${PLUGIN_NAME} PRIVATE ${PLUGIN_SOURCES})
13 | target_link_libraries(${PLUGIN_NAME} neuron-base)
14 |
15 | # v2
16 | set(PLUGIN_NAME_2 plugin-c1_2)
17 | set(PLUGIN_SOURCES_2 c1_2.c )
18 | add_library(${PLUGIN_NAME_2} SHARED)
19 | target_include_directories(${PLUGIN_NAME_2} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
20 | target_sources(${PLUGIN_NAME_2} PRIVATE ${PLUGIN_SOURCES_2})
21 | target_link_libraries(${PLUGIN_NAME_2} neuron-base)
22 |
23 | # v1_v_err
24 | set(PLUGIN_NAME plugin-c1verr)
25 | set(PLUGIN_SOURCES c1_v_err.c )
26 | add_library(${PLUGIN_NAME} SHARED)
27 | target_include_directories(${PLUGIN_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
28 | target_sources(${PLUGIN_NAME} PRIVATE ${PLUGIN_SOURCES})
29 | target_link_libraries(${PLUGIN_NAME} neuron-base)
30 |
31 | # v2_v_err
32 | set(PLUGIN_NAME_2 plugin-c1_2verr)
33 | set(PLUGIN_SOURCES_2 c1_2_v_err.c )
34 | add_library(${PLUGIN_NAME_2} SHARED)
35 | target_include_directories(${PLUGIN_NAME_2} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
36 | target_sources(${PLUGIN_NAME_2} PRIVATE ${PLUGIN_SOURCES_2})
37 | target_link_libraries(${PLUGIN_NAME_2} neuron-base)
38 |
--------------------------------------------------------------------------------
/tests/plugins/c1/c1.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_M_PLUGIN_MODBUS_REQ_H_
20 | #define _NEU_M_PLUGIN_MODBUS_REQ_H_
21 |
22 | #include
23 |
24 | struct neu_plugin {
25 | neu_plugin_common_t common;
26 | };
27 |
28 | #endif
--------------------------------------------------------------------------------
/tests/plugins/c1/c1.json:
--------------------------------------------------------------------------------
1 | {
2 | "tag_regex": [
3 | {
4 | "type": 1,
5 | "regex": ""
6 | },
7 | {
8 | "type": 2,
9 | "regex": ""
10 | },
11 | {
12 | "type": 3,
13 | "regex": ""
14 | },
15 | {
16 | "type": 4,
17 | "regex": ""
18 | },
19 | {
20 | "type": 5,
21 | "regex": ""
22 | },
23 | {
24 | "type": 6,
25 | "regex": ""
26 | },
27 | {
28 | "type": 7,
29 | "regex": ""
30 | },
31 | {
32 | "type": 8,
33 | "regex": ""
34 | },
35 | {
36 | "type": 9,
37 | "regex": ""
38 | },
39 | {
40 | "type": 10,
41 | "regex": ""
42 | },
43 | {
44 | "type": 12,
45 | "regex": ""
46 | },
47 | {
48 | "type": 13,
49 | "regex": ""
50 | }
51 | ],
52 | "group_interval": 1000
53 | }
--------------------------------------------------------------------------------
/tests/plugins/s1/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/tests/plugins")
2 |
3 | set(CMAKE_BUILD_RPATH ./)
4 | file(COPY ${CMAKE_SOURCE_DIR}/tests/plugins/s1/s1.json DESTINATION ${CMAKE_BINARY_DIR}/tests/plugins/schema/)
5 |
6 |
7 | # v1
8 | set(PLUGIN_NAME plugin-s1)
9 | set(PLUGIN_SOURCES s1.c )
10 | add_library(${PLUGIN_NAME} SHARED)
11 | target_include_directories(${PLUGIN_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
12 | target_sources(${PLUGIN_NAME} PRIVATE ${PLUGIN_SOURCES})
13 | target_link_libraries(${PLUGIN_NAME} neuron-base)
14 |
15 | # v2
16 | set(PLUGIN_NAME_2 plugin-s1_2)
17 | set(PLUGIN_SOURCES_2 s1_2.c )
18 | add_library(${PLUGIN_NAME_2} SHARED)
19 | target_include_directories(${PLUGIN_NAME_2} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
20 | target_sources(${PLUGIN_NAME_2} PRIVATE ${PLUGIN_SOURCES_2})
21 | target_link_libraries(${PLUGIN_NAME_2} neuron-base)
22 |
--------------------------------------------------------------------------------
/tests/plugins/s1/s1.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_M_PLUGIN_MODBUS_REQ_H_
20 | #define _NEU_M_PLUGIN_MODBUS_REQ_H_
21 |
22 | #include
23 |
24 | struct neu_plugin {
25 | neu_plugin_common_t common;
26 | };
27 |
28 | #endif
--------------------------------------------------------------------------------
/tests/plugins/s1/s1.json:
--------------------------------------------------------------------------------
1 | {
2 | "tag_regex": [
3 | {
4 | "type": 1,
5 | "regex": ""
6 | },
7 | {
8 | "type": 2,
9 | "regex": ""
10 | },
11 | {
12 | "type": 3,
13 | "regex": ""
14 | },
15 | {
16 | "type": 4,
17 | "regex": ""
18 | },
19 | {
20 | "type": 5,
21 | "regex": ""
22 | },
23 | {
24 | "type": 6,
25 | "regex": ""
26 | },
27 | {
28 | "type": 7,
29 | "regex": ""
30 | },
31 | {
32 | "type": 8,
33 | "regex": ""
34 | },
35 | {
36 | "type": 9,
37 | "regex": ""
38 | },
39 | {
40 | "type": 10,
41 | "regex": ""
42 | },
43 | {
44 | "type": 12,
45 | "regex": ""
46 | },
47 | {
48 | "type": 13,
49 | "regex": ""
50 | }
51 | ],
52 | "group_interval": 1000
53 | }
--------------------------------------------------------------------------------
/tests/plugins/sc1/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/tests/plugins")
2 |
3 | set(CMAKE_BUILD_RPATH ./)
4 | file(COPY ${CMAKE_SOURCE_DIR}/tests/plugins/sc1/sc1.json DESTINATION ${CMAKE_BINARY_DIR}/tests/plugins/schema/)
5 |
6 |
7 | # v1
8 | set(PLUGIN_NAME plugin-sc1)
9 | set(PLUGIN_SOURCES sc1.c )
10 | add_library(${PLUGIN_NAME} SHARED)
11 | target_include_directories(${PLUGIN_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
12 | target_sources(${PLUGIN_NAME} PRIVATE ${PLUGIN_SOURCES})
13 | target_link_libraries(${PLUGIN_NAME} neuron-base)
14 |
15 | # v2
16 | set(PLUGIN_NAME_2 plugin-sc1_2)
17 | set(PLUGIN_SOURCES_2 sc1_2.c )
18 | add_library(${PLUGIN_NAME_2} SHARED)
19 | target_include_directories(${PLUGIN_NAME_2} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
20 | target_sources(${PLUGIN_NAME_2} PRIVATE ${PLUGIN_SOURCES_2})
21 | target_link_libraries(${PLUGIN_NAME_2} neuron-base)
22 |
--------------------------------------------------------------------------------
/tests/plugins/sc1/sc1.h:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 | #ifndef _NEU_M_PLUGIN_MODBUS_REQ_H_
20 | #define _NEU_M_PLUGIN_MODBUS_REQ_H_
21 |
22 | #include
23 |
24 | struct neu_plugin {
25 | neu_plugin_common_t common;
26 | };
27 |
28 | #endif
--------------------------------------------------------------------------------
/tests/plugins/sc1/sc1.json:
--------------------------------------------------------------------------------
1 | {
2 | "tag_regex": [
3 | {
4 | "type": 1,
5 | "regex": ""
6 | },
7 | {
8 | "type": 2,
9 | "regex": ""
10 | },
11 | {
12 | "type": 3,
13 | "regex": ""
14 | },
15 | {
16 | "type": 4,
17 | "regex": ""
18 | },
19 | {
20 | "type": 5,
21 | "regex": ""
22 | },
23 | {
24 | "type": 6,
25 | "regex": ""
26 | },
27 | {
28 | "type": 7,
29 | "regex": ""
30 | },
31 | {
32 | "type": 8,
33 | "regex": ""
34 | },
35 | {
36 | "type": 9,
37 | "regex": ""
38 | },
39 | {
40 | "type": 10,
41 | "regex": ""
42 | },
43 | {
44 | "type": 12,
45 | "regex": ""
46 | },
47 | {
48 | "type": 13,
49 | "regex": ""
50 | }
51 | ],
52 | "group_interval": 1000
53 | }
--------------------------------------------------------------------------------
/tests/ut/README.md:
--------------------------------------------------------------------------------
1 | # Test
2 | Unit testing uses googletest testing framework, testing point processing, JSON reading, architecture, HTTP acquisition, and other small-scale tests.
3 | To run all unit tests.
4 |
5 | ```shell
6 | $ cd build
7 | $ ctest --output-on-failure
8 | ```
9 |
10 | To introduce coverage statistics using LCOV:
11 |
12 | Add parameter -DUSE_GCOV=1 during compilation
13 |
14 | Generate image files .gcno and data files .gcda under build/tests/CMakeFiles/.dir
15 |
16 | Execute the following command in the build folder to generate an intermediate file for HTML:
17 |
18 | ```shell
19 | $ lcov --capture --directory . --output-file testneuron.info --test-name testneuron
20 | ```
21 |
22 | Execute the following command in the build folder to generate an HTML file in the result folder under the build folder:
23 |
24 | ```shell
25 | $ genhtml -o result testneuron.info
26 | ```
27 |
28 | Open build/result index.html to view coverage statistics report.
--------------------------------------------------------------------------------
/tests/ut/base64_test.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "utils/base64.h"
4 | #include "utils/log.h"
5 |
6 | zlog_category_t *neuron = NULL;
7 | TEST(Base64Test, neu_encode64_test)
8 | {
9 | const char *input = "hello world!";
10 | size_t len = strlen(input);
11 | char * b64 = neu_encode64((unsigned char *) input, len);
12 | EXPECT_STREQ(b64, "aGVsbG8gd29ybGQh");
13 | free(b64);
14 | }
15 |
16 | TEST(Base64Test, neu_decode64_test)
17 | {
18 | int len = 0;
19 | const char * input = "aGVsbG8gd29ybGQh";
20 | const char * output = "hello world!";
21 | char temp[100] = { '\0' };
22 | unsigned char *data = neu_decode64(&len, input);
23 | memcpy(temp, data, len);
24 | free(data);
25 | EXPECT_STREQ(temp, output);
26 | EXPECT_EQ(len, strlen(output));
27 | }
28 |
29 | int main(int argc, char **argv)
30 | {
31 | zlog_init("./config/dev.conf");
32 | neuron = zlog_get_category("neuron");
33 | ::testing::InitGoogleTest(&argc, argv);
34 | return RUN_ALL_TESTS();
35 | }
--------------------------------------------------------------------------------
/tests/ut/common_test.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "neuron.h"
4 | #include "type.h"
5 |
6 | zlog_category_t *neuron = NULL;
7 | TEST(type_set_get, type_set)
8 | {
9 | uint16_t u16 = 0;
10 | neu_set_u16((uint8_t *) &u16, 0x1234);
11 | EXPECT_EQ(0x1234, u16);
12 |
13 | int16_t i16 = 0;
14 | neu_set_i16((uint8_t *) &i16, 0x1234);
15 | EXPECT_EQ(0x1234, i16);
16 |
17 | uint32_t u32 = 0;
18 | neu_set_u32((uint8_t *) &u32, 0x12345678);
19 | EXPECT_EQ(0x12345678, u32);
20 |
21 | int32_t i32 = 0;
22 | neu_set_i32((uint8_t *) &i32, 0x12345678);
23 | EXPECT_EQ(0x12345678, i32);
24 |
25 | float f32 = 0;
26 | neu_set_f32((uint8_t *) &f32, 3.1415926);
27 | EXPECT_FLOAT_EQ(3.1415926, f32);
28 |
29 | double f64 = 0;
30 | neu_set_f64((uint8_t *) &f64, 3.1415926);
31 | EXPECT_DOUBLE_EQ(3.1415926, f64);
32 |
33 | int64_t i64 = 0;
34 | neu_set_i64((uint8_t *) &i64, 0x1234567890ABCDEF);
35 | EXPECT_EQ(0x1234567890ABCDEF, i64);
36 |
37 | uint64_t u64 = 0;
38 | neu_set_u64((uint8_t *) &u64, 0x1234567890ABCDEF);
39 | EXPECT_EQ(0x1234567890ABCDEF, u64);
40 | }
41 |
42 | TEST(type_set_get, type_get)
43 | {
44 | uint16_t u16 = 0x1234;
45 | EXPECT_EQ(0x1234, neu_get_u16((uint8_t *) &u16));
46 |
47 | int16_t i16_ = 0x1234;
48 | EXPECT_EQ(0x1234, neu_get_i16((uint8_t *) &i16_));
49 |
50 | uint32_t u32 = 0x12345678;
51 | EXPECT_EQ(0x12345678, neu_get_u32((uint8_t *) &u32));
52 |
53 | int32_t i32 = 0x12345678;
54 | EXPECT_EQ(0x12345678, neu_get_i32((uint8_t *) &i32));
55 |
56 | float f32 = 3.1415926;
57 | EXPECT_FLOAT_EQ(3.1415926, neu_get_f32((uint8_t *) &f32));
58 |
59 | double f64 = 3.1415926;
60 | EXPECT_DOUBLE_EQ(3.1415926, neu_get_f64((uint8_t *) &f64));
61 |
62 | int64_t i64 = 0x1234567890ABCDEF;
63 | EXPECT_EQ(0x1234567890ABCDEF, neu_get_i64((uint8_t *) &i64));
64 |
65 | uint64_t u64 = 0x1234567890ABCDEF;
66 | EXPECT_EQ(0x1234567890ABCDEF, neu_get_u64((uint8_t *) &u64));
67 | }
68 |
69 | TEST(type_h_n, type_h_n)
70 | {
71 | uint16_t u16 = 0x1234;
72 | neu_htons_p(&u16);
73 | EXPECT_EQ(0x3412, u16);
74 |
75 | uint32_t u32 = 0x12345678;
76 | neu_htonl_p(&u32);
77 | EXPECT_EQ(0x78563412, u32);
78 |
79 | uint64_t u64 = 0x1234567890ABCDEF;
80 | neu_htonll_p(&u64);
81 | EXPECT_EQ(0xEFCDAB9078563412, u64);
82 | }
83 |
84 | int main(int argc, char **argv)
85 | {
86 | zlog_init("./config/dev.conf");
87 | neuron = zlog_get_category("neuron");
88 | ::testing::InitGoogleTest(&argc, argv);
89 | return RUN_ALL_TESTS();
90 | }
91 |
--------------------------------------------------------------------------------
/tests/ut/jwt_test.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 |
5 | #include "jwt.h"
6 | #include "utils/neu_jwt.h"
7 |
8 | #include "utils/log.h"
9 |
10 | zlog_category_t *neuron = NULL;
11 | TEST(JwtTest, SetJwt)
12 | {
13 | char *token = NULL;
14 |
15 | EXPECT_EQ(0, neu_jwt_init((char *) "./config"));
16 |
17 | EXPECT_EQ(0, neu_jwt_new(&token, "admin"));
18 | EXPECT_GE(strlen(token), 400);
19 |
20 | jwt_free_str(token);
21 | }
22 |
23 | TEST(JwtTest, JwtValidate)
24 | {
25 | char *token = NULL;
26 | char b_token[1024] = { 0 };
27 |
28 | EXPECT_EQ(0, neu_jwt_init((char *) "./config"));
29 | EXPECT_EQ(0, neu_jwt_new(&token, "admin"));
30 |
31 | snprintf(b_token, sizeof(b_token), "Bearer %s", token);
32 |
33 | EXPECT_EQ(0, neu_jwt_validate(b_token));
34 |
35 | jwt_free_str(token);
36 | }
37 | int main(int argc, char **argv)
38 | {
39 | zlog_init("./config/dev.conf");
40 | neuron = zlog_get_category("neuron");
41 | ::testing::InitGoogleTest(&argc, argv);
42 | return RUN_ALL_TESTS();
43 | }
44 |
--------------------------------------------------------------------------------
/tests/ut/rolling_counter_test.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "utils/log.h"
4 | #include "utils/rolling_counter.h"
5 |
6 | zlog_category_t *neuron = NULL;
7 | TEST(RollingCounterTest, neu_rolling_counter_inc)
8 | {
9 | uint64_t ts = 0;
10 | neu_rolling_counter_t *counter = neu_rolling_counter_new(4000);
11 | EXPECT_NE(nullptr, counter);
12 |
13 | for (int i = 1; i <= 4; ++i) {
14 | ts += 1000;
15 | EXPECT_EQ(i, neu_rolling_counter_inc(counter, ts, 1));
16 | }
17 |
18 | // wrap around
19 | for (int i = 1; i <= 4; ++i) {
20 | ts += 1000;
21 | EXPECT_EQ(4, neu_rolling_counter_inc(counter, ts, 1));
22 | }
23 |
24 | // increment without time stamp update
25 | EXPECT_EQ(4, neu_rolling_counter_value(counter));
26 | for (int i = 1; i <= 10; ++i) {
27 | EXPECT_EQ(4 + i, neu_rolling_counter_inc(counter, ts, 1));
28 | }
29 |
30 | EXPECT_EQ(4 + 10, neu_rolling_counter_value(counter));
31 |
32 | // stale value will be clean
33 | ts += 4000;
34 | EXPECT_EQ(0, neu_rolling_counter_inc(counter, ts, 0));
35 |
36 | neu_rolling_counter_free(counter);
37 | }
38 |
39 | int main(int argc, char **argv)
40 | {
41 | zlog_init("./config/dev.conf");
42 | neuron = zlog_get_category("neuron");
43 | ::testing::InitGoogleTest(&argc, argv);
44 | return RUN_ALL_TESTS();
45 | }
46 |
--------------------------------------------------------------------------------
/version:
--------------------------------------------------------------------------------
1 | 2.12.0-alpha
--------------------------------------------------------------------------------
/version.h.in:
--------------------------------------------------------------------------------
1 | /**
2 | * NEURON IIoT System for Industry 4.0
3 | * Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 3 of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program; if not, write to the Free Software Foundation,
17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | **/
19 |
20 | /*
21 | * DO NOT EDIT THIS FILE MANUALLY!
22 | * It was automatically generated by `neuron-version.cmake`
23 | */
24 |
25 | #ifndef NEURON_VERSION_H
26 | #define NEURON_VERSION_H
27 |
28 | #define NEURON_VERSION "@NEURON_VERSION@"
29 |
30 | #define NEURON_VERSION_MAJOR @NEURON_VERSION_MAJOR@
31 | #define NEURON_VERSION_MINOR @NEURON_VERSION_MINOR@
32 | #define NEURON_VERSION_MICRO @NEURON_VERSION_MICRO@
33 |
34 | #define NEURON_GIT_REV "@GIT_REV@"
35 | #define NEURON_GIT_TAG "@GIT_TAG@"
36 | #define NEURON_GIT_DIFF "@GIT_DIFF@"
37 | #define NEURON_GIT_BRANCH "@GIT_BRANCH@"
38 |
39 | #define NEURON_BUILD_DATE "@NEURON_BUILD_DATE@"
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/zlog.conf:
--------------------------------------------------------------------------------
1 | [global]
2 |
3 | file perms = 666
4 |
5 | [formats]
6 |
7 | simple = "%d:%ms [%V] %f:%L %m%n"
8 | syslog = "%d(%Y-%m-%dT%T%z) %H neuron[%p]: level=%v msg="[%c] %m" file="%f:%L"%n"
9 |
10 | [rules]
11 |
12 | *.* "./logs/%c.log", 25MB * 1 ~ "./logs/%c.#2r.log"; simple
13 | *.* $remote_syslog,"%V"; syslog
14 |
--------------------------------------------------------------------------------