Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 7176958

Browse files
committed
typedefs in seperate file
1 parent e728fd5 commit 7176958

File tree

3 files changed

+67
-27
lines changed

3 files changed

+67
-27
lines changed

src/ModbusMessage.h

+2-25
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2727
#include <stdint.h> // for uint*_t
2828
#include <stddef.h> // for size_t
2929

30-
enum MBFunctionCode : uint8_t {
31-
READ_COIL = 0x01,
32-
READ_DISC_INPUT = 0x02,
33-
READ_HOLD_REGISTER = 0x03,
34-
READ_INPUT_REGISTER = 0x04,
35-
WRITE_COIL = 0x05,
36-
WRITE_HOLD_REGISTER = 0x06,
37-
WRITE_MULT_COILS = 0x0F,
38-
WRITE_MULT_REGISTERS = 0x10
39-
};
30+
#include "esp32ModbusTypeDefs.h"
4031

41-
enum MBError : uint8_t {
42-
SUCCES = 0x00,
43-
ILLEGAL_FUNCTION = 0x01,
44-
ILLEGAL_DATA_ADDRESS = 0x02,
45-
ILLEGAL_DATA_VALUE = 0x03,
46-
SERVER_DEVICE_FAILURE = 0x04,
47-
ACKNOWLEDGE = 0x05,
48-
SERVER_DEVICE_BUSY = 0x06,
49-
NEGATIVE_ACKNOWLEDGE = 0x07,
50-
MEMORY_PARITY_ERROR = 0x08,
51-
TIMEOUT = 0xE0,
52-
INVALID_SLAVE = 0xE1,
53-
INVALID_FUNCTION = 0xE2,
54-
CRC_ERROR = 0xE3
55-
};
32+
using namespace esp32Modbus; // NOLINT
5633

5734
class ModbusMessage {
5835
public:

src/esp32ModbusRTU.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ extern "C" {
4141
#include <HardwareSerial.h>
4242
#include <esp32-hal-gpio.h>
4343

44+
#include "esp32ModbusTypeDefs.h"
4445
#include "ModbusMessage.h"
4546

46-
typedef std::function<void(uint8_t, MBFunctionCode, uint8_t*, uint16_t)> MBOnData;
47-
typedef std::function<void(MBError)> MBOnError;
47+
using namespace esp32Modbus; // NOLINT
4848

4949
class esp32ModbusRTU {
5050
public:

src/esp32ModbusTypeDefs.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* esp32ModbusTypedefs
2+
3+
Copyright 2018 Bert Melis
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
25+
#pragma once
26+
27+
#include <stdint.h> // for uint*_t
28+
#include <functional> // for std::function
29+
30+
namespace esp32Modbus {
31+
32+
enum MBFunctionCode : uint8_t {
33+
READ_COIL = 0x01,
34+
READ_DISC_INPUT = 0x02,
35+
READ_HOLD_REGISTER = 0x03,
36+
READ_INPUT_REGISTER = 0x04,
37+
WRITE_COIL = 0x05,
38+
WRITE_HOLD_REGISTER = 0x06,
39+
WRITE_MULT_COILS = 0x0F,
40+
WRITE_MULT_REGISTERS = 0x10
41+
};
42+
43+
enum MBError : uint8_t {
44+
SUCCES = 0x00,
45+
ILLEGAL_FUNCTION = 0x01,
46+
ILLEGAL_DATA_ADDRESS = 0x02,
47+
ILLEGAL_DATA_VALUE = 0x03,
48+
SERVER_DEVICE_FAILURE = 0x04,
49+
ACKNOWLEDGE = 0x05,
50+
SERVER_DEVICE_BUSY = 0x06,
51+
NEGATIVE_ACKNOWLEDGE = 0x07,
52+
MEMORY_PARITY_ERROR = 0x08,
53+
TIMEOUT = 0xE0,
54+
INVALID_SLAVE = 0xE1,
55+
INVALID_FUNCTION = 0xE2,
56+
CRC_ERROR = 0xE3, // only for Modbus-RTU
57+
COMM_ERROR = 0xE4 // general communication error
58+
};
59+
60+
typedef std::function<void(uint8_t, MBFunctionCode, uint8_t*, uint16_t)> MBOnData;
61+
typedef std::function<void(MBError)> MBOnError;
62+
63+
} // namespace esp32Modbus

0 commit comments

Comments
 (0)