-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathModbusTypeDefs.cpp
More file actions
66 lines (59 loc) · 3.89 KB
/
Copy pathModbusTypeDefs.cpp
File metadata and controls
66 lines (59 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// =================================================================================================
// eModbus: Copyright 2020 by Michael Harwerth, Bert Melis and the contributors to eModbus
// MIT license - see license.md for details
// =================================================================================================
#include "ModbusTypeDefs.h"
#ifndef MINIMAL
using Modbus::FCType;
using Modbus::FCT;
// Initialize function code type table
FCType FCT::table[] = {
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FCILLEGAL, FC01_TYPE, FC01_TYPE, FC01_TYPE, FC01_TYPE, FC01_TYPE, FC01_TYPE, FC07_TYPE, // 0x0.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FCGENERIC, FCILLEGAL, FCILLEGAL, FC07_TYPE, FC07_TYPE, FCILLEGAL, FCILLEGAL, FC0F_TYPE, // 0x0.
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FC10_TYPE, FC07_TYPE, FCILLEGAL, FCILLEGAL, FCGENERIC, FCGENERIC, FC16_TYPE, FCGENERIC, // 0x1.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FC18_TYPE, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x1.
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x2.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCGENERIC, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x2.
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x3.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x3.
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FCILLEGAL, FCUSER, FCUSER, FCUSER, FCUSER, FCUSER, FCUSER, FCUSER, // 0x4.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FCUSER, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x4.
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x5.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x5.
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCUSER, FCUSER, FCUSER, FCUSER, // 0x6.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FCUSER, FCUSER, FCUSER, FCUSER, FCUSER, FCUSER, FCUSER, FCILLEGAL, // 0x6.
// 0x.0 0x.1 0x.2 0x.3 0x.4 0x.5 0x.6 0x.7
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x7.
// 0x.8 0x.9 0x.A 0x.B 0x.C 0x.D 0x.E 0x.F
FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, FCILLEGAL, // 0x7.
};
// FCT::getType: get the function code type for a given function code
FCType FCT::getType(uint8_t functionCode) {
return table[functionCode & 0x7F];
}
// redefineType: change the type of a function code.
// This is possible only for the codes undefined yet and will return
// the effective type
FCType FCT::redefineType(uint8_t functionCode, const FCType type) {
uint8_t fc = functionCode & 0x7F;
// Allow modifications for yet undefined codes only
if (table[fc] == FCILLEGAL) {
table[fc] = type;
}
return table[fc];
}
#endif