use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class MiBandSupport method onTestNewFunction.
@Override
public void onTestNewFunction() {
try {
TransactionBuilder builder = performInitialized("Toggle sensor reading");
if (isReadingSensorData) {
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), stopSensorRead);
isReadingSensorData = false;
} else {
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), startSensorRead);
isReadingSensorData = true;
}
builder.queue(getQueue());
} catch (IOException ex) {
LOG.error("Unable to toggle sensor reading MI", ex);
}
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class FetchActivityOperation method sendAckDataTransfer.
/**
* Acknowledge the transfer of activity data to the Mi Band.
* <p/>
* After receiving data from the band, it has to be acknowledged. This way the Mi Band will delete
* the data it has on record.
*
* @param time
* @param bytesTransferred
*/
private void sendAckDataTransfer(Calendar time, int bytesTransferred) {
byte[] ackTime = MiBandDateConverter.calendarToRawBytes(time);
Prefs prefs = GBApplication.getPrefs();
byte[] ackChecksum = new byte[] { (byte) (bytesTransferred & 0xff), (byte) (0xff & (bytesTransferred >> 8)) };
if (prefs.getBoolean(MiBandConst.PREF_MIBAND_DONT_ACK_TRANSFER, false)) {
ackChecksum = new byte[] { (byte) (~bytesTransferred & 0xff), (byte) (0xff & (~bytesTransferred >> 8)) };
}
byte[] ack = new byte[] { MiBandService.COMMAND_CONFIRM_ACTIVITY_DATA_TRANSFER_COMPLETE, ackTime[0], ackTime[1], ackTime[2], ackTime[3], ackTime[4], ackTime[5], ackChecksum[0], ackChecksum[1] };
try {
TransactionBuilder builder = performInitialized("send acknowledge");
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), ack);
builder.queue(getQueue());
// flush to the DB after queueing the ACK
flushActivityDataHolder();
//When we ack this chunk, the transfer is done.
if (getDevice().isBusy() && bytesTransferred == 0) {
//if we are not clearing miband's data, we have to stop the sync
if (prefs.getBoolean(MiBandConst.PREF_MIBAND_DONT_ACK_TRANSFER, false)) {
builder = performInitialized("send acknowledge");
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), new byte[] { MiBandService.COMMAND_STOP_SYNC_DATA });
getSupport().setHighLatency(builder);
builder.queue(getQueue());
}
handleActivityFetchFinish();
}
} catch (IOException ex) {
LOG.error("Unable to send ack to MI", ex);
}
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class FetchActivityOperation method doPerform.
@Override
protected void doPerform() throws IOException {
// scheduleTaskExecutor = Executors.newScheduledThreadPool(1);
TransactionBuilder builder = performInitialized("fetch activity data");
getSupport().setLowLatency(builder);
builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.busy_task_fetch_activity_data), getContext()));
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), fetch);
builder.queue(getQueue());
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class HPlusHandlerThread method requestNextDaySlots.
/**
* Issue a message requesting the next set of slots
* The process will sync 1h at a time until the device is in sync
* Then it will request samples until the end of the day in order to minimize data loss
* Messages will be provided every 10 minutes after they are available
*/
private void requestNextDaySlots() {
Calendar now = GregorianCalendar.getInstance();
int currentSlot = now.get(Calendar.HOUR_OF_DAY) * 6 + now.get(Calendar.MINUTE) / 10;
//Finished dumping the entire ring buffer
//Sync to current time
mGetDaySlotsTime = now;
if (mSlotsInitialSync) {
if (mLastSlotReceived == 143) {
mSlotsInitialSync = false;
//Sync complete. Delay timer forever
mGetDaySlotsTime.set(Calendar.SECOND, CURRENT_DAY_SYNC_PERIOD);
mLastSlotReceived = -1;
mLastSlotRequested = mLastSlotReceived + 1;
return;
} else {
mGetDaySlotsTime.add(Calendar.SECOND, CURRENT_DAY_SYNC_RETRY_PERIOD);
}
} else {
//Sync complete. Delay timer forever
mGetDaySlotsTime.set(Calendar.SECOND, CURRENT_DAY_SYNC_PERIOD);
return;
}
if (mLastSlotReceived == 143)
mLastSlotReceived = -1;
byte hour = (byte) ((mLastSlotReceived + 1) / 6);
byte minute = (byte) (((mLastSlotReceived + 1) % 6) * 10);
byte nextHour = hour;
byte nextMinute = 59;
mLastSlotRequested = nextHour * 6 + (nextMinute / 10);
byte[] msg = new byte[] { HPlusConstants.CMD_GET_ACTIVE_DAY, hour, minute, nextHour, nextMinute };
TransactionBuilder builder = new TransactionBuilder("getNextDaySlot");
builder.write(mHPlusSupport.ctrlCharacteristic, msg);
builder.queue(mHPlusSupport.getQueue());
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class HPlusHandlerThread method requestDaySummaryData.
/**
* Request a batch of data with the summary of the previous days
*/
public void requestDaySummaryData() {
TransactionBuilder builder = new TransactionBuilder("startSyncDaySummary");
builder.write(mHPlusSupport.ctrlCharacteristic, new byte[] { HPlusConstants.CMD_GET_DAY_DATA });
builder.queue(mHPlusSupport.getQueue());
mGetDaySummaryTime = GregorianCalendar.getInstance();
mGetDaySummaryTime.add(Calendar.SECOND, DAY_SUMMARY_SYNC_RETRY_PERIOD);
}
Aggregations