mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-01 17:26:18 +02:00
78 lines
3.1 KiB
Java
78 lines
3.1 KiB
Java
/* Copyright (C) 2024 Martin.JM
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
|
|
|
import android.location.Location;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.GpsAndTime;
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
|
|
|
public class SendGpsDataRequest extends Request {
|
|
Location location;
|
|
GpsAndTime.GpsParameters.Response gpsParametersResponse;
|
|
|
|
public SendGpsDataRequest(HuaweiSupportProvider support, Location location, GpsAndTime.GpsParameters.Response gpsParametersResponse) {
|
|
super(support);
|
|
this.serviceId = GpsAndTime.id;
|
|
this.commandId = GpsAndTime.GpsData.id;
|
|
this.location = location;
|
|
this.gpsParametersResponse = gpsParametersResponse;
|
|
}
|
|
|
|
@Override
|
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
|
ArrayList<GpsAndTime.GpsData.Request.GpsDataContainer> gpsList = new ArrayList<>();
|
|
GpsAndTime.GpsData.Request.GpsDataContainer gpsData = new GpsAndTime.GpsData.Request.GpsDataContainer();
|
|
|
|
if (this.gpsParametersResponse.supportsSpeed && location.hasSpeed()) {
|
|
gpsData.hasSpeed = true;
|
|
gpsData.speed = (short) location.getSpeed();
|
|
}
|
|
if (this.gpsParametersResponse.supportsAltitude && location.hasAltitude()) {
|
|
gpsData.hasAltitude = true;
|
|
gpsData.altitude = (short) location.getAltitude();
|
|
}
|
|
if (this.gpsParametersResponse.supportsLatLon) {
|
|
gpsData.hasLatLon = true;
|
|
gpsData.lat = location.getLatitude();
|
|
gpsData.lon = location.getLongitude();
|
|
}
|
|
if (this.gpsParametersResponse.supportsDirection && location.hasBearing()) {
|
|
gpsData.hasBearing = true;
|
|
gpsData.bearing = location.getBearing();
|
|
}
|
|
if (this.gpsParametersResponse.supportsPrecision && location.hasAccuracy()) {
|
|
gpsData.hasAccuracy = true;
|
|
gpsData.accuracy = location.getAccuracy();
|
|
}
|
|
|
|
gpsList.add(gpsData);
|
|
try {
|
|
return new GpsAndTime.GpsData.Request(
|
|
this.paramsProvider,
|
|
gpsList
|
|
).serialize();
|
|
} catch (HuaweiPacket.CryptoException e) {
|
|
throw new RequestCreationException(e);
|
|
}
|
|
}
|
|
}
|