|
| 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