-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataidentifier.go
103 lines (96 loc) · 3.03 KB
/
dataidentifier.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package xsens
import (
"fmt"
)
// DataIdentifier is an Xsens data identifier.
//
// Each data identifier is constructed in this way:
//
// +-------------------------------------------------------------------------------+
// | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// +------------------------+--------------+-------------------+-------------------+
// | Group | Reserved | Type | Format |
// +------------------------+--------------+-------------------+-------------------+
//
// Group defines the category of the data, such as timestamps, orientations, angular velocities, etc.
//
// Type combined with Group defines the actual type of the data.
type DataIdentifier struct {
DataType DataType
CoordinateSystem CoordinateSystem
Precision Precision
}
const (
dataIdentifierTypeMask uint16 = 0xf8f0
dataIdentifierCoordinateSystemMask uint16 = 0x000c
dataIdentifierPrecisionMask uint16 = 0x0003
)
// Uint16 returns the data identifier represented as a uint16.
func (d DataIdentifier) Uint16() uint16 {
return uint16(d.DataType) | uint16(d.CoordinateSystem) | uint16(d.Precision)
}
// SetUint16 sets the data identifier from a uint16 representation.
func (d *DataIdentifier) SetUint16(value uint16) {
d.DataType = DataType(value & dataIdentifierTypeMask)
d.CoordinateSystem = CoordinateSystem(value & dataIdentifierCoordinateSystemMask)
d.Precision = Precision(value & dataIdentifierPrecisionMask)
}
// DataSize returns the data size (in bytes) of measurement data with the current identifier.
//
// Returns 0 for unsupported data identifiers.
func (d DataIdentifier) DataSize() uint8 {
switch d.DataType {
// scalars
case DataTypeTemperature,
DataTypeAltitudeEllipsoid:
return d.Precision.Size()
// vectors
case DataTypeDeltaV,
DataTypeAcceleration,
DataTypeFreeAcceleration,
DataTypeAccelerationHR,
DataTypeRateOfTurn,
DataTypeRateOfTurnHR,
DataTypeEulerAngles,
DataTypePositionECEF,
DataTypeVelocityXYZ,
DataTypeMagneticField:
return 3 * d.Precision.Size()
case DataTypeDeltaQ, DataTypeQuaternion:
return 4 * d.Precision.Size()
case DataTypeUTCTime:
return 12
case DataTypePacketCounter:
return 2
case DataTypeSampleTimeFine:
return 4
case DataTypeSampleTimeCoarse:
return 4
case DataTypeRotationMatrix:
return 9 * d.Precision.Size()
case DataTypeBaroPressure:
return 4
case DataTypeLatLon:
return 2
case DataTypeGNSSPVTData:
return 76
case DataTypeGNSSSatInfo:
return 8 // plus variable number of satellites
case DataTypeStatusByte:
return 1
case DataTypeStatusWord:
return 4
}
return 0
}
// String returns a string representation of the data identifier.
func (d DataIdentifier) String() string {
switch {
case d.DataType.HasCoordinateSystem() && d.DataType.HasPrecision():
return fmt.Sprintf("%v(%v,%v)", d.DataType, d.CoordinateSystem, d.Precision)
case d.DataType.HasPrecision():
return fmt.Sprintf("%v(%v)", d.DataType, d.Precision)
default:
return fmt.Sprintf("%v", d.DataType)
}
}