MCPcopy Create free account
hub / github.com/XCSoar/XCSoar / onCharacteristicChanged

Method onCharacteristicChanged

android/src/BluetoothSensor.java:165–222  ·  view source on GitHub ↗
(BluetoothGatt gatt,
                                                   BluetoothGattCharacteristic c)

Source from the content-addressed store, hash-verified

163 }
164
165 @Override
166 public synchronized void onCharacteristicChanged(BluetoothGatt gatt,
167 BluetoothGattCharacteristic c) {
168 if (!safeDestruct.increment())
169 return;
170
171 try {
172 if (BluetoothUuids.HEART_RATE_SERVICE.equals(c.getService().getUuid())) {
173 if (BluetoothUuids.HEART_RATE_MEASUREMENT_CHARACTERISTIC.equals(c.getUuid())) {
174 readHeartRateMeasurement(c);
175 }
176 }
177
178 if (BluetoothUuids.FLYTEC_SENSBOX_SERVICE.equals(c.getService().getUuid())) {
179 if (BluetoothUuids.FLYTEC_SENSBOX_NAVIGATION_SENSOR_CHARACTERISTIC.equals(c.getUuid())) {
180 /* protocol documentation:
181 https://github.com/flytec/SensBoxLib_iOS/blob/master/_SensBox%20Documentation/SensorBox%20BLE%20Protocol.pdf */
182 final int gps_status = c.getIntValue(c.FORMAT_UINT8, 18) & 0x7;
183 final boolean hasAltitude = (gps_status == 2 || gps_status == 4);
184
185 final long time = 1000 *
186 toUnsignedLong(c.getIntValue(c.FORMAT_UINT32, 0));
187
188 listener.onLocationSensor(time,
189 flytecSatellites,
190 c.getIntValue(c.FORMAT_SINT32, 8) / 10000000.,
191 c.getIntValue(c.FORMAT_SINT32, 4) / 10000000.,
192 hasAltitude, true,
193 c.getIntValue(c.FORMAT_SINT16, 12),
194 haveFlytecMovement, flytecTrack,
195 haveFlytecMovement, flytecGroundSpeed,
196 false, 0);
197
198 listener.onPressureAltitudeSensor(c.getIntValue(c.FORMAT_SINT16, 14));
199 } else if (BluetoothUuids.FLYTEC_SENSBOX_MOVEMENT_SENSOR_CHARACTERISTIC.equals(c.getUuid())) {
200 flytecGroundSpeed = c.getIntValue(c.FORMAT_SINT16, 6) / 10.;
201 flytecTrack = c.getIntValue(c.FORMAT_SINT16, 8) / 10.;
202
203 listener.onVarioSensor(c.getIntValue(c.FORMAT_SINT16, 4) / 100.f);
204 listener.onAccelerationSensor1(c.getIntValue(c.FORMAT_UINT16, 16) / 10.);
205
206 haveFlytecMovement = true;
207 } else if (BluetoothUuids.FLYTEC_SENSBOX_SECOND_GPS_CHARACTERISTIC.equals(c.getUuid())) {
208 flytecSatellites = c.getIntValue(c.FORMAT_UINT8, 6);
209 } else if (BluetoothUuids.FLYTEC_SENSBOX_SYSTEM_CHARACTERISTIC.equals(c.getUuid())) {
210 listener.onBatteryPercent(c.getIntValue(c.FORMAT_UINT8, 4));
211
212 final double CELSIUS_OFFSET = 273.15;
213 double temperatureCelsius = c.getIntValue(c.FORMAT_SINT16, 6) / 10.;
214 listener.onTemperature(CELSIUS_OFFSET + temperatureCelsius);
215 }
216 }
217 } catch (NullPointerException e) {
218 /* probably caused by a malformed value - ignore */
219 } finally {
220 safeDestruct.decrement();
221 }
222 }

Callers

nothing calls this directly

Calls 11

toUnsignedLongMethod · 0.95
incrementMethod · 0.80
equalsMethod · 0.80
decrementMethod · 0.80
onLocationSensorMethod · 0.65
onVarioSensorMethod · 0.65
onAccelerationSensor1Method · 0.65
onBatteryPercentMethod · 0.65
onTemperatureMethod · 0.65

Tested by

no test coverage detected