use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerMarioTime method onAppStart.
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[] { null };
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec);
return new GBDeviceEvent[] { sendBytes };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerMisfit method handleMessage.
@Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
GBDevice device = getDevice();
for (Pair<Integer, Object> pair : pairs) {
switch(pair.first) {
case KEY_INCOMING_DATA_BEGIN:
LOG.info("incoming data start");
break;
case KEY_INCOMING_DATA_END:
LOG.info("incoming data end");
break;
case KEY_INCOMING_DATA:
byte[] data = (byte[]) pair.second;
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ByteOrder.LITTLE_ENDIAN);
int timestamp = buf.getInt();
int key = buf.getInt();
int samples = (data.length - 8) / 2;
if (samples <= 0) {
break;
}
if (mPebbleProtocol.mFwMajor < 3) {
timestamp -= SimpleTimeZone.getDefault().getOffset(timestamp * 1000L) / 1000;
}
Date startDate = new Date((long) timestamp * 1000L);
Date endDate = new Date((long) (timestamp + samples * 60) * 1000L);
LOG.info("got data from " + startDate + " to " + endDate);
int totalSteps = 0;
PebbleMisfitSample[] misfitSamples = new PebbleMisfitSample[samples];
try (DBHandler db = GBApplication.acquireDB()) {
PebbleMisfitSampleProvider sampleProvider = new PebbleMisfitSampleProvider(device, db.getDaoSession());
Long userId = DBHelper.getUser(db.getDaoSession()).getId();
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
for (int i = 0; i < samples; i++) {
short sample = buf.getShort();
misfitSamples[i] = new PebbleMisfitSample(timestamp + i * 60, deviceId, userId, sample & 0xffff);
misfitSamples[i].setProvider(sampleProvider);
int steps = misfitSamples[i].getSteps();
totalSteps += steps;
LOG.info("got steps for sample " + i + " : " + steps + "(" + Integer.toHexString(sample & 0xffff) + ")");
}
LOG.info("total steps for above period: " + totalSteps);
sampleProvider.addGBActivitySamples(misfitSamples);
} catch (Exception e) {
LOG.error("Error acquiring database", e);
return null;
}
break;
default:
LOG.info("unhandled key: " + pair.first);
break;
}
}
// always ack
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
return new GBDeviceEvent[] { sendBytesAck };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerTimeStylePebble method onAppStart.
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[] { null };
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeTimeStylePebbleWeather(weatherSpec);
return new GBDeviceEvent[] { sendBytes };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerTrekVolle method onAppStart.
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[] { null };
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeTrekVolleWeather(weatherSpec);
return new GBDeviceEvent[] { sendBytes };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class PebbleProtocol method decodePing.
private GBDeviceEventSendBytes decodePing(ByteBuffer buf) {
byte command = buf.get();
if (command == PING_PING) {
int cookie = buf.getInt();
LOG.info("Received PING - will reply");
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodePing(PING_PONG, cookie);
return sendBytes;
}
return null;
}
Aggregations