Modbus/TCP server. More...
#include "core/net.h"
#include "modbus/modbus_common.h"
#include "core/crypto.h"
#include "tls.h"
#include "tls_ticket.h"
Go to the source code of this file.
Data Structures | |
struct | ModbusServerSettings |
Modbus/TCP server settings. More... | |
struct | _ModbusClientConnection |
Modbus/TCP client connection. More... | |
struct | _ModbusServerContext |
Modbus/TCP server context. More... | |
Macros | |
#define | MODBUS_SERVER_SUPPORT ENABLED |
#define | MODBUS_SERVER_TLS_SUPPORT DISABLED |
#define | MODBUS_SERVER_DIAG_SUPPORT DISABLED |
#define | MODBUS_SERVER_STACK_SIZE 650 |
#define | MODBUS_SERVER_PRIORITY OS_TASK_PRIORITY_NORMAL |
#define | MODBUS_SERVER_MAX_CONNECTIONS 2 |
#define | MODBUS_SERVER_TIMEOUT 60000 |
#define | MODBUS_SERVER_TICK_INTERVAL 1000 |
#define | MODBUS_SERVER_TLS_TX_BUFFER_SIZE 2048 |
#define | MODBUS_SERVER_TLS_RX_BUFFER_SIZE 2048 |
#define | MODBUS_SERVER_MAX_ROLE_LEN 32 |
#define | MODBUS_SERVER_PRIVATE_CONTEXT |
#define | ModbusServerContext struct _ModbusServerContext |
#define | ModbusClientConnection struct _ModbusClientConnection |
Typedefs | |
typedef error_t(* | ModbusServerOpenCallback) (ModbusClientConnection *connection, IpAddr clientIpAddr, uint16_t clientPort) |
TCP connection open callback function. More... | |
typedef void(* | ModbusServerCloseCallback) (ModbusClientConnection *connection) |
TCP connection close callback function. More... | |
typedef error_t(* | ModbusServerTlsInitCallback) (ModbusClientConnection *connection, TlsContext *tlsContext) |
TLS initialization callback function. More... | |
typedef void(* | ModbusServerLockCallback) (void) |
Lock Modbus table callback function. More... | |
typedef void(* | ModbusServerUnlockCallback) (void) |
Unlock Modbus table callback function. More... | |
typedef error_t(* | ModbusServerReadCoilCallback) (const char_t *role, uint16_t address, bool_t *state) |
Get coil state callback function. More... | |
typedef error_t(* | ModbusServerWriteCoilCallback) (const char_t *role, uint16_t address, bool_t state, bool_t commit) |
Set coil state callback function. More... | |
typedef error_t(* | ModbusServerReadRegCallback) (const char_t *role, uint16_t address, uint16_t *value) |
Get register value callback function. More... | |
typedef error_t(* | ModbusServerWriteRegCallback) (const char_t *role, uint16_t address, uint16_t value, bool_t commit) |
Set register value callback function. More... | |
typedef error_t(* | ModbusServerProcessPduCallback) (const uint8_t *request, size_t requestLen, uint8_t *response, size_t *responseLen) |
PDU processing callback function. More... | |
typedef void(* | ModbusServerTickCallback) (ModbusServerContext *context) |
Tick callback function. More... | |
Enumerations | |
enum | ModbusConnectionState { MODBUS_CONNECTION_STATE_CLOSED = 0, MODBUS_CONNECTION_STATE_CONNECT_TLS = 1, MODBUS_CONNECTION_STATE_RECEIVE = 2, MODBUS_CONNECTION_STATE_SEND = 3, MODBUS_CONNECTION_STATE_SHUTDOWN_TLS = 4, MODBUS_CONNECTION_STATE_SHUTDOWN_TX = 5, MODBUS_CONNECTION_STATE_SHUTDOWN_RX = 6 } |
Modbus/TCP connection state. More... | |
Functions | |
void | modbusServerGetDefaultSettings (ModbusServerSettings *settings) |
Initialize settings with default values. More... | |
error_t | modbusServerInit (ModbusServerContext *context, const ModbusServerSettings *settings) |
Initialize Modbus/TCP server context. More... | |
error_t | modbusServerStart (ModbusServerContext *context) |
Start Modbus/TCP server. More... | |
error_t | modbusServerStop (ModbusServerContext *context) |
Stop Modbus/TCP server. More... | |
void | modbusServerTask (ModbusServerContext *context) |
Modbus/TCP server task. More... | |
void | modbusServerDeinit (ModbusServerContext *context) |
Release Modbus/TCP server context. More... | |
Detailed Description
Modbus/TCP server.
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneTCP Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- Version
- 2.4.4
Definition in file modbus_server.h.
Macro Definition Documentation
◆ MODBUS_SERVER_DIAG_SUPPORT
#define MODBUS_SERVER_DIAG_SUPPORT DISABLED |
Definition at line 54 of file modbus_server.h.
◆ MODBUS_SERVER_MAX_CONNECTIONS
#define MODBUS_SERVER_MAX_CONNECTIONS 2 |
Definition at line 73 of file modbus_server.h.
◆ MODBUS_SERVER_MAX_ROLE_LEN
#define MODBUS_SERVER_MAX_ROLE_LEN 32 |
Definition at line 108 of file modbus_server.h.
◆ MODBUS_SERVER_PRIORITY
#define MODBUS_SERVER_PRIORITY OS_TASK_PRIORITY_NORMAL |
Definition at line 68 of file modbus_server.h.
◆ MODBUS_SERVER_PRIVATE_CONTEXT
#define MODBUS_SERVER_PRIVATE_CONTEXT |
Definition at line 115 of file modbus_server.h.
◆ MODBUS_SERVER_STACK_SIZE
#define MODBUS_SERVER_STACK_SIZE 650 |
Definition at line 61 of file modbus_server.h.
◆ MODBUS_SERVER_SUPPORT
#define MODBUS_SERVER_SUPPORT ENABLED |
Definition at line 40 of file modbus_server.h.
◆ MODBUS_SERVER_TICK_INTERVAL
#define MODBUS_SERVER_TICK_INTERVAL 1000 |
Definition at line 87 of file modbus_server.h.
◆ MODBUS_SERVER_TIMEOUT
#define MODBUS_SERVER_TIMEOUT 60000 |
Definition at line 80 of file modbus_server.h.
◆ MODBUS_SERVER_TLS_RX_BUFFER_SIZE
#define MODBUS_SERVER_TLS_RX_BUFFER_SIZE 2048 |
Definition at line 101 of file modbus_server.h.
◆ MODBUS_SERVER_TLS_SUPPORT
#define MODBUS_SERVER_TLS_SUPPORT DISABLED |
Definition at line 47 of file modbus_server.h.
◆ MODBUS_SERVER_TLS_TX_BUFFER_SIZE
#define MODBUS_SERVER_TLS_TX_BUFFER_SIZE 2048 |
Definition at line 94 of file modbus_server.h.
◆ ModbusClientConnection
#define ModbusClientConnection struct _ModbusClientConnection |
Definition at line 131 of file modbus_server.h.
◆ ModbusServerContext
#define ModbusServerContext struct _ModbusServerContext |
Definition at line 127 of file modbus_server.h.
Typedef Documentation
◆ ModbusServerCloseCallback
typedef void(* ModbusServerCloseCallback) (ModbusClientConnection *connection) |
TCP connection close callback function.
Definition at line 167 of file modbus_server.h.
◆ ModbusServerLockCallback
typedef void(* ModbusServerLockCallback) (void) |
Lock Modbus table callback function.
Definition at line 187 of file modbus_server.h.
◆ ModbusServerOpenCallback
typedef error_t(* ModbusServerOpenCallback) (ModbusClientConnection *connection, IpAddr clientIpAddr, uint16_t clientPort) |
TCP connection open callback function.
Definition at line 159 of file modbus_server.h.
◆ ModbusServerProcessPduCallback
typedef error_t(* ModbusServerProcessPduCallback) (const uint8_t *request, size_t requestLen, uint8_t *response, size_t *responseLen) |
PDU processing callback function.
Definition at line 233 of file modbus_server.h.
◆ ModbusServerReadCoilCallback
typedef error_t(* ModbusServerReadCoilCallback) (const char_t *role, uint16_t address, bool_t *state) |
Get coil state callback function.
Definition at line 201 of file modbus_server.h.
◆ ModbusServerReadRegCallback
typedef error_t(* ModbusServerReadRegCallback) (const char_t *role, uint16_t address, uint16_t *value) |
Get register value callback function.
Definition at line 217 of file modbus_server.h.
◆ ModbusServerTickCallback
typedef void(* ModbusServerTickCallback) (ModbusServerContext *context) |
Tick callback function.
Definition at line 241 of file modbus_server.h.
◆ ModbusServerTlsInitCallback
typedef error_t(* ModbusServerTlsInitCallback) (ModbusClientConnection *connection, TlsContext *tlsContext) |
TLS initialization callback function.
Definition at line 177 of file modbus_server.h.
◆ ModbusServerUnlockCallback
typedef void(* ModbusServerUnlockCallback) (void) |
Unlock Modbus table callback function.
Definition at line 194 of file modbus_server.h.
◆ ModbusServerWriteCoilCallback
typedef error_t(* ModbusServerWriteCoilCallback) (const char_t *role, uint16_t address, bool_t state, bool_t commit) |
Set coil state callback function.
Definition at line 209 of file modbus_server.h.
◆ ModbusServerWriteRegCallback
typedef error_t(* ModbusServerWriteRegCallback) (const char_t *role, uint16_t address, uint16_t value, bool_t commit) |
Set register value callback function.
Definition at line 225 of file modbus_server.h.
Enumeration Type Documentation
◆ ModbusConnectionState
Modbus/TCP connection state.
Definition at line 143 of file modbus_server.h.
Function Documentation
◆ modbusServerDeinit()
void modbusServerDeinit | ( | ModbusServerContext * | context | ) |
Release Modbus/TCP server context.
- Parameters
-
[in] context Pointer to the Modbus/TCP server context
Definition at line 420 of file modbus_server.c.
◆ modbusServerGetDefaultSettings()
void modbusServerGetDefaultSettings | ( | ModbusServerSettings * | settings | ) |
Initialize settings with default values.
- Parameters
-
[out] settings Structure that contains Modbus/TCP server settings
Definition at line 49 of file modbus_server.c.
◆ modbusServerInit()
error_t modbusServerInit | ( | ModbusServerContext * | context, |
const ModbusServerSettings * | settings | ||
) |
Initialize Modbus/TCP server context.
- Parameters
-
[in] context Pointer to the Modbus/TCP server context [in] settings Modbus/TCP server specific settings
- Returns
- Error code
Definition at line 108 of file modbus_server.c.
◆ modbusServerStart()
error_t modbusServerStart | ( | ModbusServerContext * | context | ) |
Start Modbus/TCP server.
- Parameters
-
[in] context Pointer to the Modbus/TCP server context
- Returns
- Error code
Definition at line 167 of file modbus_server.c.
◆ modbusServerStop()
error_t modbusServerStop | ( | ModbusServerContext * | context | ) |
Stop Modbus/TCP server.
- Parameters
-
[in] context Pointer to the Modbus/TCP server context
- Returns
- Error code
Definition at line 261 of file modbus_server.c.
◆ modbusServerTask()
void modbusServerTask | ( | ModbusServerContext * | context | ) |
Modbus/TCP server task.
- Parameters
-
[in] context Pointer to the Modbus/TCP server context
Definition at line 314 of file modbus_server.c.