-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
type_conversions.go
74 lines (70 loc) · 2.5 KB
/
type_conversions.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
65
66
67
68
69
70
71
72
73
74
package modbus
import "fmt"
func determineConverter(inType, byteOrder, outType string, scale float64) (fieldConverterFunc, error) {
if scale != 0.0 {
return determineConverterScale(inType, byteOrder, outType, scale)
}
return determineConverterNoScale(inType, byteOrder, outType)
}
func determineConverterScale(inType, byteOrder, outType string, scale float64) (fieldConverterFunc, error) {
switch inType {
case "INT8L":
return determineConverterI8LScale(outType, byteOrder, scale)
case "INT8H":
return determineConverterI8HScale(outType, byteOrder, scale)
case "UINT8L":
return determineConverterU8LScale(outType, byteOrder, scale)
case "UINT8H":
return determineConverterU8HScale(outType, byteOrder, scale)
case "INT16":
return determineConverterI16Scale(outType, byteOrder, scale)
case "UINT16":
return determineConverterU16Scale(outType, byteOrder, scale)
case "INT32":
return determineConverterI32Scale(outType, byteOrder, scale)
case "UINT32":
return determineConverterU32Scale(outType, byteOrder, scale)
case "INT64":
return determineConverterI64Scale(outType, byteOrder, scale)
case "UINT64":
return determineConverterU64Scale(outType, byteOrder, scale)
case "FLOAT16":
return determineConverterF16Scale(outType, byteOrder, scale)
case "FLOAT32":
return determineConverterF32Scale(outType, byteOrder, scale)
case "FLOAT64":
return determineConverterF64Scale(outType, byteOrder, scale)
}
return nil, fmt.Errorf("invalid input data-type: %s", inType)
}
func determineConverterNoScale(inType, byteOrder, outType string) (fieldConverterFunc, error) {
switch inType {
case "INT8L":
return determineConverterI8L(outType, byteOrder)
case "INT8H":
return determineConverterI8H(outType, byteOrder)
case "UINT8L":
return determineConverterU8L(outType, byteOrder)
case "UINT8H":
return determineConverterU8H(outType, byteOrder)
case "INT16":
return determineConverterI16(outType, byteOrder)
case "UINT16":
return determineConverterU16(outType, byteOrder)
case "INT32":
return determineConverterI32(outType, byteOrder)
case "UINT32":
return determineConverterU32(outType, byteOrder)
case "INT64":
return determineConverterI64(outType, byteOrder)
case "UINT64":
return determineConverterU64(outType, byteOrder)
case "FLOAT16":
return determineConverterF16(outType, byteOrder)
case "FLOAT32":
return determineConverterF32(outType, byteOrder)
case "FLOAT64":
return determineConverterF64(outType, byteOrder)
}
return nil, fmt.Errorf("invalid input data-type: %s", inType)
}