@@ -58,7 +58,7 @@ func (e *encoder) WriteTo(w io.Writer) (int64, error) {
58
58
}
59
59
60
60
func (e * encoder ) AddPort (channel uint8 , value float64 ) {
61
- val := uint16 (value * 100 )
61
+ val := int16 (value * 100 )
62
62
e .buf .WriteByte (channel )
63
63
binary .Write (e .buf , binary .BigEndian , val )
64
64
}
@@ -76,14 +76,14 @@ func (e *encoder) AddDigitalOutput(channel, value uint8) {
76
76
}
77
77
78
78
func (e * encoder ) AddAnalogInput (channel uint8 , value float64 ) {
79
- val := uint16 (value * 100 )
79
+ val := int16 (value * 100 )
80
80
e .buf .WriteByte (channel )
81
81
e .buf .WriteByte (AnalogInput )
82
82
binary .Write (e .buf , binary .BigEndian , val )
83
83
}
84
84
85
85
func (e * encoder ) AddAnalogOutput (channel uint8 , value float64 ) {
86
- val := uint16 (value * 100 )
86
+ val := int16 (value * 100 )
87
87
e .buf .WriteByte (channel )
88
88
e .buf .WriteByte (AnalogOutput )
89
89
binary .Write (e .buf , binary .BigEndian , val )
@@ -102,7 +102,7 @@ func (e *encoder) AddPresence(channel, value uint8) {
102
102
}
103
103
104
104
func (e * encoder ) AddTemperature (channel uint8 , celcius float64 ) {
105
- val := uint16 (celcius * 10 )
105
+ val := int16 (celcius * 10 )
106
106
e .buf .WriteByte (channel )
107
107
e .buf .WriteByte (Temperature )
108
108
binary .Write (e .buf , binary .BigEndian , val )
@@ -115,9 +115,9 @@ func (e *encoder) AddRelativeHumidity(channel uint8, rh float64) {
115
115
}
116
116
117
117
func (e * encoder ) AddAccelerometer (channel uint8 , x , y , z float64 ) {
118
- valX := uint16 (x * 1000 )
119
- valY := uint16 (y * 1000 )
120
- valZ := uint16 (z * 1000 )
118
+ valX := int16 (x * 1000 )
119
+ valY := int16 (y * 1000 )
120
+ valZ := int16 (z * 1000 )
121
121
e .buf .WriteByte (channel )
122
122
e .buf .WriteByte (Accelerometer )
123
123
binary .Write (e .buf , binary .BigEndian , valX )
@@ -126,16 +126,16 @@ func (e *encoder) AddAccelerometer(channel uint8, x, y, z float64) {
126
126
}
127
127
128
128
func (e * encoder ) AddBarometricPressure (channel uint8 , hpa float64 ) {
129
- val := uint16 (hpa * 10 )
129
+ val := int16 (hpa * 10 )
130
130
e .buf .WriteByte (channel )
131
131
e .buf .WriteByte (BarometricPressure )
132
132
binary .Write (e .buf , binary .BigEndian , val )
133
133
}
134
134
135
135
func (e * encoder ) AddGyrometer (channel uint8 , x , y , z float64 ) {
136
- valX := uint16 (x * 100 )
137
- valY := uint16 (y * 100 )
138
- valZ := uint16 (z * 100 )
136
+ valX := int16 (x * 100 )
137
+ valY := int16 (y * 100 )
138
+ valZ := int16 (z * 100 )
139
139
e .buf .WriteByte (channel )
140
140
e .buf .WriteByte (Gyrometer )
141
141
binary .Write (e .buf , binary .BigEndian , valX )
@@ -144,18 +144,18 @@ func (e *encoder) AddGyrometer(channel uint8, x, y, z float64) {
144
144
}
145
145
146
146
func (e * encoder ) AddGPS (channel uint8 , latitude , longitude , meters float64 ) {
147
- valLat := uint32 (latitude * 10000 )
148
- valLon := uint32 (longitude * 10000 )
149
- valAlt := uint32 (meters * 100 )
147
+ valLat := int32 (latitude * 10000 )
148
+ valLon := int32 (longitude * 10000 )
149
+ valAlt := int32 (meters * 100 )
150
150
e .buf .WriteByte (channel )
151
151
e .buf .WriteByte (GPS )
152
- e .buf .WriteByte (uint8 (valLat >> 16 ))
153
- e .buf .WriteByte (uint8 (valLat >> 8 ))
154
- e .buf .WriteByte (uint8 (valLat ))
155
- e .buf .WriteByte (uint8 (valLon >> 16 ))
156
- e .buf .WriteByte (uint8 (valLon >> 8 ))
157
- e .buf .WriteByte (uint8 (valLon ))
158
- e .buf .WriteByte (uint8 (valAlt >> 16 ))
159
- e .buf .WriteByte (uint8 (valAlt >> 8 ))
160
- e .buf .WriteByte (uint8 (valAlt ))
152
+ e .buf .WriteByte (byte (valLat >> 16 ))
153
+ e .buf .WriteByte (byte (valLat >> 8 ))
154
+ e .buf .WriteByte (byte (valLat ))
155
+ e .buf .WriteByte (byte (valLon >> 16 ))
156
+ e .buf .WriteByte (byte (valLon >> 8 ))
157
+ e .buf .WriteByte (byte (valLon ))
158
+ e .buf .WriteByte (byte (valAlt >> 16 ))
159
+ e .buf .WriteByte (byte (valAlt >> 8 ))
160
+ e .buf .WriteByte (byte (valAlt ))
161
161
}
0 commit comments