-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
configuration.go
64 lines (55 loc) · 1.58 KB
/
configuration.go
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
package modbus
import "fmt"
const (
maxQuantityDiscreteInput = uint16(2000)
maxQuantityCoils = uint16(2000)
maxQuantityInputRegisters = uint16(125)
maxQuantityHoldingRegisters = uint16(125)
)
type Configuration interface {
Check() error
Process() (map[byte]requestSet, error)
SampleConfigPart() string
}
func removeDuplicates(elements []uint16) []uint16 {
encountered := map[uint16]bool{}
result := []uint16{}
for _, addr := range elements {
if !encountered[addr] {
encountered[addr] = true
result = append(result, addr)
}
}
return result
}
func normalizeInputDatatype(dataType string) (string, error) {
switch dataType {
case "INT8L", "INT8H", "UINT8L", "UINT8H",
"INT16", "UINT16", "INT32", "UINT32", "INT64", "UINT64",
"FLOAT16", "FLOAT32", "FLOAT64":
return dataType, nil
}
return "unknown", fmt.Errorf("unknown input type %q", dataType)
}
func normalizeOutputDatatype(dataType string) (string, error) {
switch dataType {
case "", "native":
return "native", nil
case "INT64", "UINT64", "FLOAT64":
return dataType, nil
}
return "unknown", fmt.Errorf("unknown output type %q", dataType)
}
func normalizeByteOrder(byteOrder string) (string, error) {
switch byteOrder {
case "ABCD", "MSW-BE", "MSW": // Big endian (Motorola)
return "ABCD", nil
case "BADC", "MSW-LE": // Big endian with bytes swapped
return "BADC", nil
case "CDAB", "LSW-BE": // Little endian with bytes swapped
return "CDAB", nil
case "DCBA", "LSW-LE", "LSW": // Little endian (Intel)
return "DCBA", nil
}
return "unknown", fmt.Errorf("unknown byte-order %q", byteOrder)
}