Enables support for custom function codes. Modbus specification allows
vendor specific function codes in the range 65-72 & 100-110 [1] and this
feature allows users to implement custom logic for those codes.
Additionally, since the Zephyr Modbus stack doesn't implement all defined
Modbus fcs this feature allows users to add support for codes outside the
basic register reading / writing functionality offered by Zephyr.
Custom function codes can be added on a per-interface basis and the handler
structures are allocated by the caller.
[1]: https://modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf
Signed-off-by: Henrik Lindblom <henrik.lindblom@vaisala.com>
Allow to periodically initializes/disables the modbus interface.
Switch from modbus line discipline to serial and switch back to modbus.
This can be required when the serial is shared by two sensors
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.
Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.
Partial fix for #50654
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
add user data for adu callback, which helps in passing
socket and relevant application parameters.
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
Although it is possible to simply use the interface number,
it has proven convenient to use the names for the interfaces
in the samples.
Migrate to DEVICE_DT_NAME().
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Added the stop_bits_client parameter to the modbus_serial_param struct.
Being able to configure the number of stop bits for the client
independently from the parity setting, allows to support connecting to
modbus server that do not follow the MODBUS over Serial Line Specification
and Implementation Guide.
Signed-off-by: Constantin Krischke <constantin.krischke@lemonbeat.com>
Signed-off-by: Jan Geldmacher <jan.geldmacher@lemonbeat.com>
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:
sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
On some platforms, if there are multiple MODBUS interfaces,
receiving of RTU frames may fail. Replacing while loop with
just "if" fixes this problem.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This patch is to fix an issue where the transceiver chip is
disabled before it has transmitted all data. This causes the
message to be corrupted because the last few bytes are missing.
The fix adds a check to make sure the transmission is completed
before disabling the transceiver.
Signed-off-by: Marius Scholtz <mariuss@ricelectronics.com>
In previous commits the crc16_ansi() function has been made compliant
with the CRC-16-ANSI aka CRC-16-MODBUS standard. Use that standard
function instead of a custom one.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Serial line interface does not use transaction and protocol
IDs. Continue to use memcpy() for the whole frame as it is safer
and more efficient but temporarily store transaction and protocol
IDs, and write it back if the transfer was successful.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use size_t type where it makes sense and
check if the buffer is large enough before it is used.
Fixes: #33786Fixes: #33795
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The size of ctx->rx_adu.data is not CONFIG_MODBUS_BUFFER_SIZE. Coverity
flagged the potential overwrite so just use sizeof().
Fixes#33789Fixes#33792Fixes#33818
Signed-off-by: David Leach <david.leach@nxp.com>
Let the core call the modbus_tx_adu() to make
the process more comprehensible.
Move tx-wait-for-rx handling outside of client code.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Prefix internal functions and structs with modbus_.
Use unit_id consistently instead of node_addr.
Fix mbm_ remainder and rename to mbc_.
Rename struct modbus_frame to modbus_adu since
ADU is closer to what the structure represents.
Let the compiler/linker do the job and
remove ifdef around mbc_validate_fc03fp_response().
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add function to get Modbus RTU interface index according
to interface name. This can be used to clearly identify
interfaces in the application.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add support to control DE/nRE RS-485 transceiver signals
over GPIO pins. Useful if the UART controller does not
support RS-485 mode.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add MODBUS RTU (over serial line) subsystem.
MODBUS RTU implementation supports booth server and
client roles. Some components of the implementation are based
on the uC/Modbus stack, which was published under Apache license,
(https://github.com/SiliconLabs/uC-Modbus
fdd1218a28e313c1212fed5ed42e5c65d3056a2c).
Resolves: #2854
Signed-off-by: Johann Fischer <j.fischer@phytec.de>