Skip to content

Commit 811c7e4

Browse files
committed
Update documentation
1 parent 7523c7a commit 811c7e4

File tree

7 files changed

+773
-342
lines changed

7 files changed

+773
-342
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ if (CPACK_GENERATOR STREQUAL "DEB")
184184
set(CPACK_DEBIAN_DOC_PACKAGE_NAME "libmodbuspp-doc")
185185
set(CPACK_COMPONENT_DOC_DESCRIPTION "${CPACK_DEBIAN_LIB_PACKAGE_NAME} - ${PROJECT_DESCRIPTION} (documentation)\n${PROJECT_DESCRIPTION_TEXT}\n This package provides the API documentation.")
186186
set(CPACK_DEBIAN_DOC_FILE_NAME "lib${PROJECT_NAME}-doc_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")
187-
set(CPACK_DEBIAN_DOC_PACKAGE_DEPENDS "${CPACK_DEBIAN_DEV_PACKAGE_NAME} (= ${CPACK_PACKAGE_VERSION})")
187+
#set(CPACK_DEBIAN_DOC_PACKAGE_DEPENDS "${CPACK_DEBIAN_DEV_PACKAGE_NAME} (= ${CPACK_PACKAGE_VERSION})")
188188
set(CPACK_DEBIAN_DOC_PACKAGE_SECTION "libdevel")
189189

190190
endif (CPACK_GENERATOR STREQUAL "DEB")

README.md

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,6 @@ _A C++ wrapper for the [libmodbus](https://libmodbus.org/) library_
88
data according to the MODBUS protocol. This library is written in C and supports
99
RTU (serial) and TCP (Ethernet) communications.
1010

11-
MODBUS is considered an application layer messaging protocol, providing
12-
Master/Slave communication between devices connected together through buses or
13-
networks.
14-
On the OSI model, MODBUS is positioned at level 7. MODBUS is intended to be a
15-
request/reply protocol and delivers services specified by function codes.
16-
The function codes of MODBUS are elements of MODBUS’ request/reply PDUs
17-
(Protocol Data Unit).
18-
19-
In order to build the MODBUS application data unit, the client must initiate a
20-
MODBUS transaction. It is the function which informs the server as to which type
21-
of action to perform. The format of a request initiated by a Master is
22-
established by the MODBUS application protocol. The function code field is then
23-
coded into one byte. Only codes within the range of 1 through 255 are
24-
considered valid, with 128-255 being reserved for exception responses.
25-
When the Master sends a message to the Slave, it is the function code field
26-
which informs the server of what type of action to perform.
27-
28-
To define multiple actions, some functions will have sub-function codes added to
29-
them. For instance, the Master is able to read the ON/OFF states of a group of
30-
discreet outputs or inputs.
31-
It could also read/write the data contents of a group of MODBUS registers.
32-
When the Master receives the Slave response, the function code field is used by
33-
the Slave to indicate either an error-free response or an exception response.
34-
The Slave echoes to the request of the initial function code in the case of a
35-
normal response.
36-
3711
The libmodbuspp library provides a C++ overlay to
3812
[libmodbus](https://libmodbus.org/), a wrapper, having no other dependency than
3913
libmodbus and libstdc++
@@ -64,7 +38,7 @@ so you should do the following :
6438
wget -O- http://www.piduino.org/piduino-key.asc | sudo apt-key add -
6539
sudo add-apt-repository 'deb http://apt.piduino.org stretch piduino'
6640
sudo apt update
67-
sudo apt install libmodbuspp-dev
41+
sudo apt install libmodbuspp-dev libmodbuspp-doc
6842
6943
This repository provides Piduino packages for `i386`, `amd64`, `armhf` and
7044
`arm64` architectures.
@@ -78,7 +52,7 @@ For Raspbian you have to do a little different :
7852
wget -O- http://www.piduino.org/piduino-key.asc | sudo apt-key add -
7953
echo 'deb http://raspbian.piduino.org stretch piduino' | sudo tee /etc/apt/sources.list.d/piduino.list
8054
sudo apt update
81-
sudo apt install libmodbuspp-dev
55+
sudo apt install libmodbuspp-dev libmodbuspp-doc
8256
8357
The Raspbian repository provides Piduino packages for `armhf` architecture for Stretch only.
8458
@@ -145,4 +119,46 @@ With [Codelite](https://codelite.org/) it's easier and funny, right ?
145119
![Debugging with Codelite](https://raw.githubusercontent.com/epsilonrt/piduino/master/doc/images/codelite-2.png)
146120

147121
You will find several examples in the folder
148-
[/usr/share/doc/modbuspp/examples](https://github.com/epsilonrt/libmodbuspp/tree/master/examples/master) (or `/usr/local/share/...`)
122+
[/usr/share/doc/modbuspp/examples](https://github.com/epsilonrt/libmodbuspp/tree/master/examples/master)
123+
124+
## Documentation
125+
126+
The libmodbus-doc package provides documentation.
127+
128+
The classes provided by the library are documented by man pages:
129+
130+
* The **Modbus_Master** page for the `Modbus::Master` class
131+
* The **Modbus_Data** page for the `Modbus::Data` class
132+
* The **Modbus_RtuLayer** page for the `Modbus::RtuLayer` class
133+
* The **Modbus_TcpLayer** page for the `Modbus::TcpLayer` class
134+
* The **Modbus_Timeout** page for the `Modbus::Timeout` class
135+
136+
The complete API is documented in the folder `/usr/share/doc/libmodbus/api-manual`
137+
138+
## About Modbus
139+
140+
MODBUS is considered an application layer messaging protocol, providing
141+
Master/Slave communication between devices connected together through buses or
142+
networks.
143+
On the OSI model, MODBUS is positioned at level 7. MODBUS is intended to be a
144+
request/reply protocol and delivers services specified by function codes.
145+
The function codes of MODBUS are elements of MODBUS’ request/reply PDUs
146+
(Protocol Data Unit).
147+
148+
In order to build the MODBUS application data unit, the client must initiate a
149+
MODBUS transaction. It is the function which informs the server as to which type
150+
of action to perform. The format of a request initiated by a Master is
151+
established by the MODBUS application protocol. The function code field is then
152+
coded into one byte. Only codes within the range of 1 through 255 are
153+
considered valid, with 128-255 being reserved for exception responses.
154+
When the Master sends a message to the Slave, it is the function code field
155+
which informs the server of what type of action to perform.
156+
157+
To define multiple actions, some functions will have sub-function codes added to
158+
them. For instance, the Master is able to read the ON/OFF states of a group of
159+
discreet outputs or inputs.
160+
It could also read/write the data contents of a group of MODBUS registers.
161+
When the Master receives the Slave response, the function code field is used by
162+
the Slave to indicate either an error-free response or an exception response.
163+
The Slave echoes to the request of the initial function code in the case of a
164+
normal response.

include/global.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
inline Class* q_func() { return reinterpret_cast<Class *>(q_ptr); } \
4747
inline const Class* q_func() const { return reinterpret_cast<const Class *>(q_ptr); } \
4848
friend class Class;
49-
namespace libmodbuspp {
50-
}
5149

5250
#endif /* __DOXYGEN__ not defined */
5351
/* ========================================================================== */

include/modbuspp-data.h

Lines changed: 88 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,100 +19,151 @@
1919
#define MODBUSPP_DATA_H
2020

2121
#include <cstdio> // printf
22-
#include <cstring> // mencpy ...
22+
#include <cstring> // memcpy ...
2323
#include <array>
2424
#include <type_traits>
2525
#include "modbuspp-swap.h"
2626

27-
#ifndef __DOXYGEN__
28-
#endif /* __DOXYGEN__ not defined */
29-
30-
/**
31-
*
32-
*/
3327
namespace Modbus {
3428

35-
enum Endian { // network number ABCD
36-
EndianBigBig = 0x00, // bytes in big endian order, word in big endian order : ABCD
37-
EndianBig = EndianBigBig, // big endian order : ABCD
38-
EndianBigLittle = 0x01, // bytes in big endian order, word in little endian order : CDAB
39-
EndianLittleBig = 0x02, // bytes in little endian order, word in big endian order : BADC
40-
EndianLittleLittle = 0x03, // bytes in little endian order, word in little endian order : DCBA
41-
EndianLittle = EndianLittleLittle // little endian order : DCBA
29+
/**
30+
* @enum Endian
31+
* @brief Sequential order in which bytes are arranged
32+
*/
33+
enum Endian {
34+
EndianBigBig = 0x00, ///< Bytes in big endian order, word in big endian order : ABCD
35+
EndianBig = EndianBigBig, ///< Big endian order : ABCD
36+
EndianBigLittle = 0x01, ///< Bytes in big endian order, word in little endian order : CDAB
37+
EndianLittleBig = 0x02, ///< Bytes in little endian order, word in big endian order : BADC
38+
EndianLittleLittle = 0x03, ///< Bytes in little endian order, word in little endian order : DCBA
39+
EndianLittle = EndianLittleLittle ///< Little endian order : DCBA
4240
};
4341

44-
4542
class Device;
4643
class Master;
4744

4845
/**
4946
* @class Data
5047
* @author Pascal JEAN, aka epsilonrt
5148
* @copyright GNU Lesser General Public License
52-
* @brief
49+
* @brief Arithmetic data in multiple 16-bit Modbus registers
50+
*
51+
* Data is a template class for storing, transmitting, and receiving
52+
* arithmetic data in multiple 16-bit Modbus registers.
53+
*
54+
* @param T is a type of arithmetic data (int, float ...) of a size greater
55+
* than or equal to 2.
56+
* @param e is the order of bytes and words in the data model used by the
57+
* user's Modbus network. By default it is the big endian order for bytes
58+
* and words that is used.
5359
*/
54-
template <typename T, Endian e = EndianBigBig>
60+
template <typename T, Endian e = EndianBig>
5561
class Data {
5662
public:
5763
static_assert ( (sizeof (T) >= 2 && (sizeof (T) % 2) == 0), "Bad Data typename !");
58-
static_assert (std::is_arithmetic<T>::value, "Arithmetic type required.");
64+
static_assert (std::is_arithmetic<T>::value, "Arithmetic type required !");
5965

66+
/**
67+
* @brief Default constructor
68+
*
69+
* The default value of T is 0.
70+
*/
6071
Data() : m_endian (e) {
6172
m_value = 0;
6273
updateRegisters();
6374
}
6475

76+
/**
77+
* @brief Constructor from a value of T
78+
*/
6579
Data (const T& t) : m_value (t), m_endian (e) {
6680
updateRegisters();
6781
}
6882

83+
/**
84+
* @brief Overload of the reference operator on the T value
85+
*/
6986
operator T&() {
7087
return m_value;
7188
}
7289

90+
/**
91+
* @brief Overload of the reference operator on the T value
92+
*/
7393
operator T&() const {
7494
return m_value;
7595
}
7696

97+
/**
98+
* @brief Access to the T value
99+
*/
77100
T& value() {
78101
return m_value;
79102
}
80103

104+
/**
105+
* @brief Access to the T value
106+
*/
81107
const T& value() const {
82108
return m_value;
83109
}
84110

111+
/**
112+
* @brief Overload of the pointer operator on the T value
113+
*/
85114
T* operator&() {
86115
return & m_value;
87116
}
88117

118+
/**
119+
* @brief Overload of the pointer operator on the T value
120+
*/
89121
const T* operator&() const {
90122
return & m_value;
91123
}
92124

125+
/**
126+
* @brief Overload of the assignment operator from a T value
127+
*/
93128
T& operator= (const T& t) {
94129
m_value = t;
95130
updateRegisters();
96131
return m_value;
97132
}
98133

134+
/**
135+
* @brief Return the bytes and words endianness
136+
*/
99137
Endian endianness() const {
100138
return m_endian;
101139
}
102140

141+
/**
142+
* @brief Number of bytes of type T
143+
*/
103144
std::size_t size() const {
104145
return sizeof (m_value);
105146
}
106147

148+
/**
149+
* @brief Array of Modbus registers corresponding to the T value
150+
*/
107151
std::array < uint16_t, sizeof (T) / 2 > & registers() {
108152
return m_registers;
109153
}
110154

155+
/**
156+
* @brief Array of Modbus registers corresponding to the T value
157+
*/
111158
const std::array < uint16_t, sizeof (T) / 2 > & registers() const {
112159
return m_registers;
113160
}
114161

115-
162+
/**
163+
* @brief Swap bytes and words of a T value \b v
164+
*
165+
* The order used is \b endianness().
166+
*/
116167
void swap (T & v) {
117168

118169
switch (m_endian) { // net value: ABCDEFGH
@@ -130,7 +181,11 @@ namespace Modbus {
130181
}
131182
}
132183

133-
// debug purpose
184+
/**
185+
* @brief Prints the hexadecimal values of a byte array
186+
*
187+
* For debugging purpose.
188+
*/
134189
static void print (const uint8_t * p, const size_t s) {
135190
std::printf ("0x");
136191
for (std::size_t i = 0; i < s; i++) {
@@ -139,10 +194,20 @@ namespace Modbus {
139194
std::printf ("\n");
140195
}
141196

197+
/**
198+
* @brief Prints the hexadecimal values of T value
199+
*
200+
* For debugging purpose.
201+
*/
142202
static void print (const T & v) {
143203
print ( (const uint8_t *) &v, sizeof (v));
144204
}
145205

206+
/**
207+
* @brief Prints the hexadecimal values of the current T value
208+
*
209+
* For debugging purpose.
210+
*/
146211
void print () {
147212
updateRegisters();
148213
print ( (const uint8_t *) m_registers.data(), size());
@@ -151,8 +216,9 @@ namespace Modbus {
151216
friend class Device;
152217
friend class Master;
153218

154-
protected:
219+
protected:
155220

221+
#ifndef __DOXYGEN__
156222
// update MODBUS registers from data value
157223
// to call before writing in the MODBUS registers
158224
void updateRegisters() {
@@ -178,15 +244,13 @@ namespace Modbus {
178244
swap (v);
179245
m_value = ntoh (v);
180246
}
247+
#endif /* __DOXYGEN__ not defined */
181248

182249
private:
183250
T m_value;
184251
Endian m_endian;
185252
std::array < uint16_t, sizeof (T) / 2 > m_registers;
186253
};
187254
}
188-
/**
189-
* @}
190-
*/
191255
/* ========================================================================== */
192256
#endif /* MODBUSPP_DATA_H defined */

0 commit comments

Comments
 (0)