Skip to content

Commit 0cf6bb2

Browse files
committed
modbus add extended float/integer support for custom and third party devices
1 parent 4302175 commit 0cf6bb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3124
-388
lines changed

.gitlab-ci.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ after_script:
106106
--manifest-file .build-test-rules.yml
107107
--parallel-count ${CI_NODE_TOTAL:-1}
108108
--parallel-index ${CI_NODE_INDEX:-1}
109+
# delete all other build artifacts, except esp32
110+
- echo "delete build folders:" $(find . -type d -regex '^\./.*build_esp32[a-z]+[0-9]+[_a-z]*' -print -exec rm -rf {} +)
111+
109112
variables:
110113
TEST_TARGETS: "esp32"
111114

@@ -121,11 +124,11 @@ build_idf_v5.0:
121124
variables:
122125
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3"
123126

124-
build_idf_v4.4:
127+
build_idf_v5.2:
125128
extends: .build_pytest_template
126-
image: espressif/idf:release-v4.4
129+
image: espressif/idf:release-v5.2
127130
variables:
128-
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c3"
131+
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2"
129132

130133
.target_test_template:
131134
stage: target_test
@@ -162,20 +165,20 @@ build_idf_v4.4:
162165
expire_in: 1 week
163166
script:
164167
- cd ${TEST_DIR}/${TEST_PORT}
165-
- echo "Start test for [esp-idf_${IDF_BRANCH}_${IDF_TARGET}_${TEST_PORT}]"
168+
- echo "Start target test for [esp-idf_${IDF_BRANCH}_${IDF_TARGET}_${TEST_PORT}]"
166169
- python -m pytest --junit-xml=${TEST_DIR}/${TEST_PORT}/results_${IDF_TARGET}_${IDF_BRANCH}.xml --target=${IDF_TARGET}
167170
- ls -lh > ${TEST_DIR}/test_dir.txt
168171

169172
target_test:
170173
stage: target_test
171174
image: "$CI_DOCKER_REGISTRY/target-test-env-v5.2:2"
172175
extends: .test_template
173-
needs: [build_idf_master, build_idf_v4.4, build_idf_v5.0]
176+
needs: [build_idf_master, build_idf_v5.2, build_idf_v5.0]
174177
parallel:
175178
matrix:
176-
- IDF_BRANCH: ["master", "v4.4", "v5.0"]
179+
- IDF_BRANCH: ["master", "v5.2", "v5.0"]
177180
IDF_TARGET: ["esp32"]
178-
TEST_PORT: ["serial", "tcp"]
181+
TEST_PORT: ["serial", "tcp", "generic"]
179182
after_script: []
180183

181184
build_docs:

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ list(APPEND priv_include_dirs serial_slave/port serial_slave/modbus_controller
5353
tcp_slave/port tcp_slave/modbus_controller
5454
tcp_master/port tcp_master/modbus_controller)
5555

56+
if(CONFIG_FMB_EXT_TYPE_SUPPORT)
57+
list(APPEND srcs "common/mb_endianness_utils.c")
58+
endif()
59+
5660
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/freemodbus/" ${srcs})
5761
add_prefix(include_dirs "${CMAKE_CURRENT_LIST_DIR}/freemodbus/" ${include_dirs})
5862
add_prefix(priv_include_dirs "${CMAKE_CURRENT_LIST_DIR}/freemodbus/" ${priv_include_dirs})

Kconfig

+9
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,13 @@ menu "Modbus configuration"
221221
This option has dependency with the UART_ISR_IN_IRAM option which places UART interrupt
222222
handler into IRAM to prevent delays related to processing of UART events.
223223

224+
config FMB_EXT_TYPE_SUPPORT
225+
bool "Modbus uses extended types to support third party devices"
226+
default n
227+
help
228+
If this option is set the Modbus stack supports extended list of types
229+
in data dictionary and conversion API to work with the extended types
230+
otherwise the only legacy types are supported. The extended types include
231+
integer, float, double types with different endianness and size.
232+
224233
endmenu

docs/Doxyfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
# http://doxygen.nl/manual/config.html
1414

1515

16-
PROJECT_NAME = "IDF Programming Guide"
16+
PROJECT_NAME = "ESP-MODBUS Programming Guide"
1717

1818
## The 'INPUT' statement below is used as input by script 'gen-df-input.py'
1919
## to automatically generate API reference list files heder_file.inc
2020
## These files are placed in '_inc' directory
2121
## and used to include in API reference documentation
2222

23+
##
24+
2325
INPUT = \
2426
$(PROJECT_PATH)/freemodbus/common/include/esp_modbus_common.h \
2527
$(PROJECT_PATH)/freemodbus/common/include/esp_modbus_slave.h \
2628
$(PROJECT_PATH)/freemodbus/common/include/esp_modbus_master.h \
29+
$(PROJECT_PATH)/freemodbus/common/include/mb_endianness_utils.h
2730

2831
## Get warnings for functions that have no documentation for their parameters or return value
2932
##

docs/_static/diag_frame.diag

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Modbus float_abcd frame structure diagram
2+
3+
blockdiag mb_float_frame {
4+
# global properties
5+
span_width = 2;
6+
span_height = 5;
7+
node_height = 25;
8+
default_fontsize = 16;
9+
default_group_color = lightgrey;
10+
class spacer [shape=none, width=10];
11+
# tuning node properties and connections
12+
0,1,2 [class=spacer];
13+
0; note
14+
1; header
15+
2; response -- uid -- cmd -- len -- fl_abcd -- crc
16+
group float_abcd_packet {
17+
label = "PDU";
18+
color = gray;
19+
shape = line;
20+
style = dashed;
21+
group{uid,resp_uid};group{cmd,resp_cmd};group{len,resp_len};group{crc,resp_crc};
22+
group float_abcd{
23+
color = blue;
24+
shape = line;
25+
style = dashed;
26+
fl_abcd;dt_abcd;
27+
}
28+
}
29+
note[label="1: Unit Identificator, 2: Function code, 3: Data length, 4: Float data array, 5: Checksum",colwidth=6,color=lightyellow,shape=roundedbox]
30+
header[label="FLOAT_ABCD = 0x4640e400 = 12345.0",colwidth=6,color=lightgreen]
31+
response[label="RX:",color=yellow];
32+
uid[label="UID",numbered=1];cmd[label="FC",numbered=2];
33+
len[label="LENGTH",numbered=3];crc[label="CRC",numbered=5];
34+
resp_uid[label="0x01"];resp_cmd[label="0x03"];resp_len[label="0x08"];resp_crc[label="0x9065"];
35+
fl_abcd[label="FLOAT_ABCD",color=lightgreen,numbered=4];
36+
dt_abcd[label="0xE4004640",shape=note];
37+
}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Modbus frame packaging examples
2+
3+
blockdiag mb_master_frames {
4+
# global properties
5+
span_width = 5;
6+
span_height = 5;
7+
node_height = 25;
8+
default_group_color = lightgrey;
9+
default_fontsize = 15;
10+
# tuning node properties and connections
11+
group 16bit_packets {
12+
label = "16bit frame";
13+
color = red;
14+
shape = line;
15+
style = dashed;
16+
16bit_notes;
17+
}
18+
group 32bit_packets {
19+
label = "32bit frame";
20+
color = green;
21+
shape = line;
22+
style = dashed;
23+
group{32bit_notes};
24+
}
25+
group 64bit_packets {
26+
label = "64bit frame";
27+
color = blue;
28+
shape = line;
29+
style = dashed;
30+
64bit_notes;
31+
}
32+
16bit_notes[label="UINT16, INT16 VALUE = 0x3039 = (uint16_t)12345", width=600, color=orange, shape = roundedbox];
33+
req_u16_hd1[label= "TX:| UID | FC | REG_START | REG_LEN | CRC |", color=lightyellow, width=380, colwidth=2, shape = roundedbox ,group=16bit_packets];
34+
req_u16_frm1[label="TX:| 01 | 03 | 00 04 | 00 02 | 85 CA |", color=lightgrey, width=380, colwidth=2,group=16bit_packets];
35+
rsp_u16_hd1[label= "RX:| UID | FC | LEN | UINT16_AB1 | UINT16_AB2 | CRC |", color=lightyellow, width=380, colwidth=2, shape = roundedbox ,group=16bit_packets];
36+
rsp_u16_frm1[label="RX:| 01 | 03 | 04 | 30 39 | 30 39 | F1 2C |", color=lightgrey, width=380, colwidth=2,group=16bit_packets];
37+
rsp_u16_hd2[label= "RX:| UID | FC | LEN | UINT16_BA1 | UINT16_BA2 | CRC |\n ", color=lightyellow, width=380, colwidth=2, shape = roundedbox, group=16bit_packets];
38+
rsp_u16_frm2[label="RX:| 01 | 03 | 04 | 39 30 | 39 30 | E4 E4 |\n", color=lightgrey, width=380, colwidth=2,group=16bit_packets];
39+
32bit_notes[label="(UINT32, INT32) FLOAT32 VALUE = 0x4640e400 = 12345.0", width=600, color=lightgreen, shape = roundedbox];
40+
req_fl_hd1[label= "TX:| UID | FC | REG_START | REG_LEN | CRC |", color=lightyellow, width=380, colwidth=2, shape = roundedbox ,group=32bit_packets];
41+
req_fl_frm1[label="TX:| 01 | 03 | 00 XX | 00 04 | C5 CB |", color=lightgrey, width=380, colwidth=2,group=32bit_packets];
42+
rsp_fl_hd1[label= "RX:| UID | FC | LEN | FLOAT_ABCD1 | FLOAT_ABCD2 | CRC |", color=lightyellow, width=380, colwidth=2, shape = roundedbox ,group=32bit_packets];
43+
rsp_fl_frm1[label="RX:| 01 | 03 | 08 | E4 00 46 40 | E4 00 46 40 | 90 65 |", color=lightgrey, width=380, colwidth=2,group=32bit_packets];
44+
rsp_fl_hd2[label= "RX:| UID | FC | LEN | FLOAT_CDAB1 | FLOAT_CDAB2 | CRC |\n ", color=lightyellow, width=380, colwidth=2, shape = roundedbox, group=32bit_packets];
45+
rsp_fl_frm2[label="RX:| 01 | 03 | 08 | 46 40 E4 00 | 46 40 E4 00 | 18 71 |\n", color=lightgrey, width=380, colwidth=2,group=32bit_packets];
46+
rsp_fl_hd3[label= "RX:| UID | FC | LEN | FLOAT_BADC1 | FLOAT_BADC2 | CRC |\n ", color=lightyellow, width=380, colwidth=2, shape = roundedbox, group=32bit_packets];
47+
rsp_fl_frm3[label="RX:| 01 | 03 | 08 | 00 E4 40 46 | 00 E4 40 46 | 46 D3 |\n", color=lightgrey, width=380, colwidth=2,group=32bit_packets];
48+
rsp_fl_hd4[label= "RX:| UID | FC | LEN | FLOAT_DCAB1 | FLOAT_DCAB2 | CRC |\n ", color=lightyellow, width=380, colwidth=2, shape = roundedbox, group=32bit_packets];
49+
rsp_fl_frm4[label="RX:| 01 | 03 | 08 | 40 46 00 E4 | 40 46 00 E4 | 32 6B |\n", color=lightgrey, width=380, colwidth=2,group=32bit_packets];
50+
64bit_notes[label="(UINT64, INT64) FLOAT64 VALUE = 0x40c81c8000000000 = 12345.0", width=600, color=lightblue, shape = roundedbox];
51+
req_dbl_hd1[label= "TX:| UID | FC | REG_START | REG_LEN | CRC |", color=lightyellow, width=380, colwidth=2, shape = roundedbox ,group=64bit_packets];
52+
req_dbl_frm1[label="TX:| 01 | 03 | 00 28 | 00 08 | C4 04 |", color=lightgrey, width=380, colwidth=2,group=64bit_packets];
53+
rsp_dbl_hd1[label= "RX:| UID | FC | LEN | DOUBLE_ABCDEFGH1 | DOUBLE_ABCDEFGH2 | CRC |", color=lightyellow, width=380, colwidth=2, shape = roundedbox ,group=64bit_packets];
54+
rsp_dbl_frm1[label="RX:| 01 | 03 | 10 | 00 00 00 00 1C 80 40 C8 | 00 00 00 00 1C 80 40 C8 | 9F 4B |", color=lightgrey, width=380, colwidth=2,group=64bit_packets];
55+
rsp_dbl_hd2[label= "RX:| UID | FC | LEN | DOUBLE_HGFEDCBA1 | DOUBLE_HGFEDCBA2 | CRC |\n ", color=lightyellow, width=380, colwidth=2, shape = roundedbox, group=64bit_packets];
56+
rsp_dbl_frm2[label="RX:| 01 | 03 | 10 | C8 40 80 1C 00 00 00 00 | C8 40 80 1C 00 00 00 00 | DF D3 |\n", color=lightgrey, width=380, colwidth=2,group=64bit_packets];
57+
rsp_dbl_hd3[label= "RX:| UID | FC | LEN | DOUBLE_GHEFCDAB1 | DOUBLE_GHEFCDAB2 | CRC |\n ", color=lightyellow, width=380, colwidth=2, shape = roundedbox, group=64bit_packets];
58+
rsp_dbl_frm3[label="RX:| 01 | 03 | 10 | 40 C8 1C 80 00 00 00 00 | 40 C8 1C 80 00 00 00 00 | B1 9C |\n", color=lightgrey, width=380, colwidth=2,group=64bit_packets];
59+
rsp_dbl_hd4[label= "RX:| UID | FC | LEN | DOUBLE_BADCFEHG1 | DOUBLE_BADCFEHG2 | CRC |\n ", color=lightyellow, width=380, colwidth=2, shape = roundedbox, group=64bit_packets];
60+
rsp_dbl_frm4[label="RX:| 01 | 03 | 10 | 00 00 00 00 80 1C C8 40 | 00 00 00 00 80 1C C8 40 | 86 94 |\n", color=lightgrey, width=380, colwidth=2,group=64bit_packets];
61+
}

docs/en/applications_and_references.rst

+5
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ API Reference
7070
.. include-build-file:: inc/esp_modbus_master.inc
7171
.. include-build-file:: inc/esp_modbus_slave.inc
7272

73+
.. _modbus_api_endianness_conversion:
7374

75+
Modbus Endianness Conversion API Reference
76+
------------------------------------------
77+
78+
.. include-build-file:: inc/mb_endianness_utils.inc

docs/en/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ The Modbus is a data communications protocol originally published by Modicon (no
1111
Modbus Port Initialization <port_initialization>
1212
Modbus Master API <master_api_overview>
1313
Modbus Slave API <slave_api_overview>
14-
Applications and References <applications_and_references>
14+
Applications and References <applications_and_references>

0 commit comments

Comments
 (0)