1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-16 10:00:08 +02:00

Refactoring: rename GBDeviceCommand to GBDeviceEvent

This commit is contained in:
Andreas Shimokawa 2015-06-23 11:54:33 +02:00
parent c2582e1e1f
commit 73da7fff0a
27 changed files with 214 additions and 295 deletions

View File

@ -5,8 +5,8 @@ import org.slf4j.LoggerFactory;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandSendBytes;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport {
@ -60,22 +60,22 @@ public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport {
}
}
public void handleGBDeviceCommand(GBDeviceCommandSendBytes sendBytes) {
public void handleGBDeviceEvent(GBDeviceEventSendBytes sendBytes) {
sendToDevice(sendBytes.encodedBytes);
}
@Override
public void evaluateGBDeviceCommand(GBDeviceCommand deviceCmd) {
public void evaluateGBDeviceEvent(GBDeviceEvent deviceEvent) {
switch (deviceCmd.commandClass) {
switch (deviceEvent.eventClass) {
case SEND_BYTES:
handleGBDeviceCommand((GBDeviceCommandSendBytes) deviceCmd);
handleGBDeviceEvent((GBDeviceEventSendBytes) deviceEvent);
return;
default:
break;
}
super.evaluateGBDeviceCommand(deviceCmd);
super.evaluateGBDeviceEvent(deviceEvent);
}
@Override

View File

@ -9,12 +9,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.activities.SleepChartActivity;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandMusicControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandSleepMonitorResult;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSleepMonitorResult;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
// TODO: support option for a single reminder notification when notifications could not be delivered?
// conditions: app was running and received notifications, but device was not connected.
@ -56,77 +56,77 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
return context;
}
public void evaluateGBDeviceCommand(GBDeviceCommand deviceCmd) {
public void evaluateGBDeviceEvent(GBDeviceEvent deviceEvent) {
switch (deviceCmd.commandClass) {
switch (deviceEvent.eventClass) {
case MUSIC_CONTROL:
handleGBDeviceCommand((GBDeviceCommandMusicControl) deviceCmd);
handleGBDeviceEvent((GBDeviceEventMusicControl) deviceEvent);
break;
case CALL_CONTROL:
handleGBDeviceCommand((GBDeviceCommandCallControl) deviceCmd);
handleGBDeviceEvent((GBDeviceEventCallControl) deviceEvent);
break;
case VERSION_INFO:
handleGBDeviceCommand((GBDeviceCommandVersionInfo) deviceCmd);
handleGBDeviceEvent((GBDeviceEventVersionInfo) deviceEvent);
break;
case APP_INFO:
handleGBDeviceCommand((GBDeviceCommandAppInfo) deviceCmd);
handleGBDeviceEvent((GBDeviceEventAppInfo) deviceEvent);
break;
case SLEEP_MONITOR_RES:
handleGBDeviceCommand((GBDeviceCommandSleepMonitorResult) deviceCmd);
handleGBDeviceEvent((GBDeviceEventSleepMonitorResult) deviceEvent);
break;
default:
break;
}
}
public void handleGBDeviceCommand(GBDeviceCommandMusicControl musicCmd) {
public void handleGBDeviceEvent(GBDeviceEventMusicControl musicEvent) {
Context context = getContext();
LOG.info("Got command for MUSIC_CONTROL");
LOG.info("Got event for MUSIC_CONTROL");
Intent musicIntent = new Intent(GBMusicControlReceiver.ACTION_MUSICCONTROL);
musicIntent.putExtra("command", musicCmd.command.ordinal());
musicIntent.putExtra("event", musicEvent.event.ordinal());
musicIntent.setPackage(context.getPackageName());
context.sendBroadcast(musicIntent);
}
public void handleGBDeviceCommand(GBDeviceCommandCallControl callCmd) {
public void handleGBDeviceEvent(GBDeviceEventCallControl callEvent) {
Context context = getContext();
LOG.info("Got command for CALL_CONTROL");
LOG.info("Got event for CALL_CONTROL");
Intent callIntent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
callIntent.putExtra("command", callCmd.command.ordinal());
callIntent.putExtra("event", callEvent.event.ordinal());
callIntent.setPackage(context.getPackageName());
context.sendBroadcast(callIntent);
}
public void handleGBDeviceCommand(GBDeviceCommandVersionInfo infoCmd) {
public void handleGBDeviceEvent(GBDeviceEventVersionInfo infoEvent) {
Context context = getContext();
LOG.info("Got command for VERSION_INFO");
LOG.info("Got event for VERSION_INFO");
if (gbDevice == null) {
return;
}
gbDevice.setFirmwareVersion(infoCmd.fwVersion);
gbDevice.setHardwareVersion(infoCmd.hwVersion);
gbDevice.setFirmwareVersion(infoEvent.fwVersion);
gbDevice.setHardwareVersion(infoEvent.hwVersion);
gbDevice.sendDeviceUpdateIntent(context);
}
public void handleGBDeviceCommand(GBDeviceCommandAppInfo appInfoCmd) {
public void handleGBDeviceEvent(GBDeviceEventAppInfo appInfoEvent) {
Context context = getContext();
LOG.info("Got command for APP_INFO");
LOG.info("Got event for APP_INFO");
Intent appInfoIntent = new Intent(AppManagerActivity.ACTION_REFRESH_APPLIST);
int appCount = appInfoCmd.apps.length;
int appCount = appInfoEvent.apps.length;
appInfoIntent.putExtra("app_count", appCount);
for (Integer i = 0; i < appCount; i++) {
appInfoIntent.putExtra("app_name" + i.toString(), appInfoCmd.apps[i].getName());
appInfoIntent.putExtra("app_creator" + i.toString(), appInfoCmd.apps[i].getCreator());
appInfoIntent.putExtra("app_uuid" + i.toString(), appInfoCmd.apps[i].getUUID().toString());
appInfoIntent.putExtra("app_type" + i.toString(), appInfoCmd.apps[i].getType().ordinal());
appInfoIntent.putExtra("app_name" + i.toString(), appInfoEvent.apps[i].getName());
appInfoIntent.putExtra("app_creator" + i.toString(), appInfoEvent.apps[i].getCreator());
appInfoIntent.putExtra("app_uuid" + i.toString(), appInfoEvent.apps[i].getUUID().toString());
appInfoIntent.putExtra("app_type" + i.toString(), appInfoEvent.apps[i].getType().ordinal());
}
LocalBroadcastManager.getInstance(context).sendBroadcast(appInfoIntent);
}
public void handleGBDeviceCommand(GBDeviceCommandSleepMonitorResult sleepMonitorResult) {
public void handleGBDeviceEvent(GBDeviceEventSleepMonitorResult sleepMonitorResult) {
Context context = getContext();
LOG.info("Got command for SLEEP_MONIOR_RES");
LOG.info("Got event for SLEEP_MONIOR_RES");
Intent sleepMontiorIntent = new Intent(SleepChartActivity.ACTION_REFRESH);
sleepMontiorIntent.putExtra("smartalarm_from", sleepMonitorResult.smartalarm_from);
sleepMontiorIntent.putExtra("smartalarm_to", sleepMonitorResult.smartalarm_to);

View File

@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
public class GBCallControlReceiver extends BroadcastReceiver {
public static final String ACTION_CALLCONTROL = "nodomain.freeyourgadget.gadgetbridge.callcontrol";
@ -20,7 +20,7 @@ public class GBCallControlReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
GBDeviceCommandCallControl.Command callCmd = GBDeviceCommandCallControl.Command.values()[intent.getIntExtra("command", 0)];
GBDeviceEventCallControl.Event callCmd = GBDeviceEventCallControl.Event.values()[intent.getIntExtra("event", 0)];
switch (callCmd) {
case END:
case START:
@ -30,7 +30,7 @@ public class GBCallControlReceiver extends BroadcastReceiver {
Method method = clazz.getDeclaredMethod("getITelephony");
method.setAccessible(true);
ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager);
if (callCmd == GBDeviceCommandCallControl.Command.END) {
if (callCmd == GBDeviceEventCallControl.Event.END) {
telephonyService.endCall();
} else {
telephonyService.answerRingingCall();

View File

@ -10,7 +10,7 @@ import android.view.KeyEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandMusicControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
public class GBMusicControlReceiver extends BroadcastReceiver {
private static final Logger LOG = LoggerFactory.getLogger(GBMusicControlReceiver.class);
@ -19,7 +19,7 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
GBDeviceCommandMusicControl.Command musicCmd = GBDeviceCommandMusicControl.Command.values()[intent.getIntExtra("command", 0)];
GBDeviceEventMusicControl.Event musicCmd = GBDeviceEventMusicControl.Event.values()[intent.getIntExtra("event", 0)];
int keyCode = -1;
int volumeAdjust = AudioManager.ADJUST_LOWER;
@ -43,8 +43,7 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
// change default and fall through, :P
volumeAdjust = AudioManager.ADJUST_RAISE;
case VOLUMEDOWN:
AudioManager audioManager =
(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, volumeAdjust, 0);
break;
default:

View File

@ -13,7 +13,6 @@ import android.view.MenuItem;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;

View File

@ -5,8 +5,6 @@ import android.bluetooth.BluetoothGatt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
/**
* A special action that checks for an abort-condition, and if met, the currently
* executing transaction will be aborted by returning false.

View File

@ -1,7 +1,5 @@
package nodomain.freeyourgadget.gadgetbridge.btle;
import android.bluetooth.BluetoothGatt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,10 +1,10 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public abstract class GBDeviceCommand {
public CommandClass commandClass = CommandClass.UNKNOWN;
public abstract class GBDeviceEvent {
public EventClass eventClass = EventClass.UNKNOWN;
public enum CommandClass {
public enum EventClass {
UNKNOWN,
MUSIC_CONTROL,
CALL_CONTROL,

View File

@ -0,0 +1,12 @@
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
public class GBDeviceEventAppInfo extends GBDeviceEvent {
public GBDeviceApp apps[];
public byte freeSlot = -1;
public GBDeviceEventAppInfo() {
eventClass = EventClass.APP_INFO;
}
}

View File

@ -0,0 +1,24 @@
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceEventAppManagementResult extends GBDeviceEvent {
public Result result = Result.UNKNOWN;
public EventType type = EventType.UNKNOWN;
public int token = -1;
public GBDeviceEventAppManagementResult() {
eventClass = EventClass.APP_MANAGEMENT_RES;
}
public enum EventType {
UNKNOWN,
INSTALL,
DELETE,
}
public enum Result {
UNKNOWN,
SUCCESS,
ACKNOLEDGE,
FAILURE,
}
}

View File

@ -0,0 +1,20 @@
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceEventCallControl extends GBDeviceEvent {
public Event event = Event.UNKNOWN;
public GBDeviceEventCallControl() {
eventClass = EventClass.CALL_CONTROL;
}
public enum Event {
UNKNOWN,
ACCEPT,
END,
INCOMING,
OUTGOING,
REJECT,
START,
}
}

View File

@ -0,0 +1,21 @@
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceEventMusicControl extends GBDeviceEvent {
public Event event = Event.UNKNOWN;
public GBDeviceEventMusicControl() {
eventClass = EventClass.MUSIC_CONTROL;
}
public enum Event {
UNKNOWN,
PLAY,
PAUSE,
PLAYPAUSE,
NEXT,
PREVIOUS,
VOLUMEUP,
VOLUMEDOWN,
}
}

View File

@ -0,0 +1,9 @@
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceEventSendBytes extends GBDeviceEvent {
public byte[] encodedBytes;
public GBDeviceEventSendBytes() {
eventClass = EventClass.SEND_BYTES;
}
}

View File

@ -1,13 +1,13 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceCommandSleepMonitorResult extends GBDeviceCommand {
public class GBDeviceEventSleepMonitorResult extends GBDeviceEvent {
// FIXME: this is just the low-level data from Morpheuz, we need something generic
public int smartalarm_from = -1; // time in minutes relative from 0:00 for smart alarm (earliest)
public int smartalarm_to = -1;// time in minutes relative from 0:00 for smart alarm (latest)
public int recording_base_timestamp = -1; // timestamp for the first "point", all folowing are +10 minutes offset each
public int alarm_gone_off = -1; // time in minutes relative from 0:00 when alarm gone off
public GBDeviceCommandSleepMonitorResult() {
commandClass = CommandClass.SLEEP_MONITOR_RES;
public GBDeviceEventSleepMonitorResult() {
eventClass = EventClass.SLEEP_MONITOR_RES;
}
}

View File

@ -1,13 +1,13 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
public class GBDeviceCommandVersionInfo extends GBDeviceCommand {
public class GBDeviceEventVersionInfo extends GBDeviceEvent {
public String fwVersion = GBApplication.getContext().getString(R.string.n_a);
public String hwVersion = GBApplication.getContext().getString(R.string.n_a);
public GBDeviceCommandVersionInfo() {
commandClass = CommandClass.VERSION_INFO;
public GBDeviceEventVersionInfo() {
eventClass = EventClass.VERSION_INFO;
}
}

View File

@ -5,8 +5,6 @@ import android.content.SharedPreferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.R;
public final class MiBandConst {
private static final Logger LOG = LoggerFactory.getLogger(MiBandConst.class);

View File

@ -29,7 +29,6 @@ import nodomain.freeyourgadget.gadgetbridge.btle.SetDeviceBusyAction;
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_PROFILE;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_DURATION;
@ -37,6 +36,7 @@ import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VA
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_DURATION;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_PAUSE;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_PROFILE;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.FLASH_COLOUR;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.FLASH_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.FLASH_DURATION;

View File

@ -13,9 +13,9 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandSendBytes;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandSleepMonitorResult;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSleepMonitorResult;
public class MorpheuzSupport {
@ -66,7 +66,7 @@ public class MorpheuzSupport {
return buf.array();
}
public GBDeviceCommand handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
public GBDeviceEvent handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
for (Pair<Integer, Object> pair : pairs) {
int ctrl_message = 0;
switch (pair.first) {
@ -84,7 +84,7 @@ public class MorpheuzSupport {
if (sent_to_gadgetbridge) {
ctrl_message = MorpheuzSupport.CTRL_VERSION_DONE | MorpheuzSupport.CTRL_GONEOFF_DONE | MorpheuzSupport.CTRL_TRANSMIT_DONE | MorpheuzSupport.CTRL_SET_LAST_SENT;
} else {
GBDeviceCommandSleepMonitorResult sleepMonitorResult = new GBDeviceCommandSleepMonitorResult();
GBDeviceEventSleepMonitorResult sleepMonitorResult = new GBDeviceEventSleepMonitorResult();
sleepMonitorResult.smartalarm_from = smartalarm_from;
sleepMonitorResult.smartalarm_to = smartalarm_to;
sleepMonitorResult.alarm_gone_off = alarm_gone_off;
@ -144,12 +144,12 @@ public class MorpheuzSupport {
break;
}
if (ctrl_message > 0) {
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeMorpheuzMessage(MorpheuzSupport.KEY_CTRL, ctrl_message);
return sendBytes;
}
}
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(uuid, mPebbleProtocol.last_id);
return sendBytes;
}

View File

@ -28,9 +28,9 @@ import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppManagementResult;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagementResult;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
public class PebbleIoThread extends GBDeviceIoThread {
@ -245,12 +245,12 @@ public class PebbleIoThread extends GBDeviceIoThread {
bytes += mInStream.read(buffer, bytes + 4, length - bytes);
}
GBDeviceCommand deviceCmd = mPebbleProtocol.decodeResponse(buffer);
if (deviceCmd == null) {
GBDeviceEvent deviceEvent = mPebbleProtocol.decodeResponse(buffer);
if (deviceEvent == null) {
LOG.info("unhandled message to endpoint " + endpoint + " (" + length + " bytes)");
} else {
if (!evaluateGBDeviceCommandPebble(deviceCmd)) {
mPebbleSupport.evaluateGBDeviceCommand(deviceCmd);
if (!evaluateGBDeviceEventPebble(deviceEvent)) {
mPebbleSupport.evaluateGBDeviceEvent(deviceEvent);
}
}
try {
@ -305,10 +305,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
}
// FIXME: parts are supporsed to be generic code
private boolean evaluateGBDeviceCommandPebble(GBDeviceCommand deviceCmd) {
Context context = getContext();
private boolean evaluateGBDeviceEventPebble(GBDeviceEvent deviceEvent) {
switch (deviceCmd.commandClass) {
switch (deviceEvent.eventClass) {
case VERSION_INFO:
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (sharedPrefs.getBoolean("datetime_synconconnect", true)) {
@ -317,7 +316,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
}
return false;
case APP_MANAGEMENT_RES:
GBDeviceCommandAppManagementResult appMgmtRes = (GBDeviceCommandAppManagementResult) deviceCmd;
GBDeviceEventAppManagementResult appMgmtRes = (GBDeviceEventAppManagementResult) deviceEvent;
switch (appMgmtRes.type) {
case DELETE:
// right now on the Pebble we also receive this on a failed/successful installation ;/
@ -371,9 +370,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
}
return true;
case APP_INFO:
LOG.info("Got command for APP_INFO");
GBDeviceCommandAppInfo appInfoCmd = (GBDeviceCommandAppInfo) deviceCmd;
setInstallSlot(appInfoCmd.freeSlot);
LOG.info("Got event for APP_INFO");
GBDeviceEventAppInfo appInfoEvent = (GBDeviceEventAppInfo) deviceEvent;
setInstallSlot(appInfoEvent.freeSlot);
return false;
default:
return false;

View File

@ -15,13 +15,13 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppManagementResult;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandMusicControl;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandSendBytes;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagementResult;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
public class PebbleProtocol extends GBDeviceProtocol {
@ -715,57 +715,57 @@ public class PebbleProtocol extends GBDeviceProtocol {
@Override
public GBDeviceCommand decodeResponse(byte[] responseData) {
public GBDeviceEvent decodeResponse(byte[] responseData) {
ByteBuffer buf = ByteBuffer.wrap(responseData);
buf.order(ByteOrder.BIG_ENDIAN);
short length = buf.getShort();
short endpoint = buf.getShort();
byte pebbleCmd = buf.get();
GBDeviceCommand cmd = null;
GBDeviceEvent devEvt = null;
switch (endpoint) {
case ENDPOINT_MUSICCONTROL:
GBDeviceCommandMusicControl musicCmd = new GBDeviceCommandMusicControl();
GBDeviceEventMusicControl musicCmd = new GBDeviceEventMusicControl();
switch (pebbleCmd) {
case MUSICCONTROL_NEXT:
musicCmd.command = GBDeviceCommandMusicControl.Command.NEXT;
musicCmd.event = GBDeviceEventMusicControl.Event.NEXT;
break;
case MUSICCONTROL_PREVIOUS:
musicCmd.command = GBDeviceCommandMusicControl.Command.PREVIOUS;
musicCmd.event = GBDeviceEventMusicControl.Event.PREVIOUS;
break;
case MUSICCONTROL_PLAY:
musicCmd.command = GBDeviceCommandMusicControl.Command.PLAY;
musicCmd.event = GBDeviceEventMusicControl.Event.PLAY;
break;
case MUSICCONTROL_PAUSE:
musicCmd.command = GBDeviceCommandMusicControl.Command.PAUSE;
musicCmd.event = GBDeviceEventMusicControl.Event.PAUSE;
break;
case MUSICCONTROL_PLAYPAUSE:
musicCmd.command = GBDeviceCommandMusicControl.Command.PLAYPAUSE;
musicCmd.event = GBDeviceEventMusicControl.Event.PLAYPAUSE;
break;
case MUSICCONTROL_VOLUMEUP:
musicCmd.command = GBDeviceCommandMusicControl.Command.VOLUMEUP;
musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
break;
case MUSICCONTROL_VOLUMEDOWN:
musicCmd.command = GBDeviceCommandMusicControl.Command.VOLUMEDOWN;
musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEDOWN;
break;
default:
break;
}
cmd = musicCmd;
devEvt = musicCmd;
break;
case ENDPOINT_PHONECONTROL:
GBDeviceCommandCallControl callCmd = new GBDeviceCommandCallControl();
GBDeviceEventCallControl callCmd = new GBDeviceEventCallControl();
switch (pebbleCmd) {
case PHONECONTROL_HANGUP:
callCmd.command = GBDeviceCommandCallControl.Command.END;
callCmd.event = GBDeviceEventCallControl.Event.END;
break;
default:
LOG.info("Unknown PHONECONTROL command" + pebbleCmd);
LOG.info("Unknown PHONECONTROL event" + pebbleCmd);
break;
}
cmd = callCmd;
devEvt = callCmd;
break;
case ENDPOINT_FIRMWAREVERSION:
GBDeviceCommandVersionInfo versionCmd = new GBDeviceCommandVersionInfo();
GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
buf.getInt(); // skip
byte[] tmp = new byte[32];
@ -781,12 +781,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
if (hwRev > 0 && hwRev < hwRevisions.length) {
versionCmd.hwVersion = hwRevisions[hwRev];
}
cmd = versionCmd;
devEvt = versionCmd;
break;
case ENDPOINT_APPMANAGER:
switch (pebbleCmd) {
case APPMANAGER_GETAPPBANKSTATUS:
GBDeviceCommandAppInfo appInfoCmd = new GBDeviceCommandAppInfo();
GBDeviceEventAppInfo appInfoCmd = new GBDeviceEventAppInfo();
int slotCount = buf.getInt();
int slotsUsed = buf.getInt();
byte[] appName = new byte[32];
@ -820,12 +820,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
break;
}
}
cmd = appInfoCmd;
devEvt = appInfoCmd;
break;
case APPMANAGER_GETUUIDS:
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeSimpleMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETAPPBANKSTATUS);
cmd = sendBytes;
devEvt = sendBytes;
tmpUUIDS.clear();
slotsUsed = buf.getInt();
for (int i = 0; i < slotsUsed; i++) {
@ -837,39 +837,39 @@ public class PebbleProtocol extends GBDeviceProtocol {
}
break;
case APPMANAGER_REMOVEAPP:
GBDeviceCommandAppManagementResult deleteRes = new GBDeviceCommandAppManagementResult();
deleteRes.type = GBDeviceCommandAppManagementResult.CommandType.DELETE;
GBDeviceEventAppManagementResult deleteRes = new GBDeviceEventAppManagementResult();
deleteRes.type = GBDeviceEventAppManagementResult.EventType.DELETE;
int result = buf.getInt();
switch (result) {
case APPMANAGER_RES_SUCCESS:
deleteRes.result = GBDeviceCommandAppManagementResult.Result.SUCCESS;
deleteRes.result = GBDeviceEventAppManagementResult.Result.SUCCESS;
break;
default:
deleteRes.result = GBDeviceCommandAppManagementResult.Result.FAILURE;
deleteRes.result = GBDeviceEventAppManagementResult.Result.FAILURE;
break;
}
cmd = deleteRes;
devEvt = deleteRes;
break;
default:
LOG.info("Unknown APPMANAGER command" + pebbleCmd);
LOG.info("Unknown APPMANAGER event" + pebbleCmd);
break;
}
break;
case ENDPOINT_PUTBYTES:
GBDeviceCommandAppManagementResult installRes = new GBDeviceCommandAppManagementResult();
installRes.type = GBDeviceCommandAppManagementResult.CommandType.INSTALL;
GBDeviceEventAppManagementResult installRes = new GBDeviceEventAppManagementResult();
installRes.type = GBDeviceEventAppManagementResult.EventType.INSTALL;
switch (pebbleCmd) {
case PUTBYTES_INIT:
installRes.token = buf.getInt();
installRes.result = GBDeviceCommandAppManagementResult.Result.SUCCESS;
installRes.result = GBDeviceEventAppManagementResult.Result.SUCCESS;
break;
default:
installRes.token = buf.getInt();
installRes.result = GBDeviceCommandAppManagementResult.Result.FAILURE;
installRes.result = GBDeviceEventAppManagementResult.Result.FAILURE;
break;
}
cmd = installRes;
devEvt = installRes;
break;
case ENDPOINT_APPLICATIONMESSAGE:
last_id = buf.get();
@ -882,10 +882,10 @@ public class PebbleProtocol extends GBDeviceProtocol {
LOG.info("got APPLICATIONMESSAGE PUSH from UUID " + uuid);
if (WeatherNeatSupport.uuid.equals(uuid)) {
ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
cmd = mWeatherNeatSupport.handleMessage(dict);
devEvt = mWeatherNeatSupport.handleMessage(dict);
} else if (MorpheuzSupport.uuid.equals(uuid)) {
ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
cmd = mMorpheuzSupport.handleMessage(dict);
devEvt = mMorpheuzSupport.handleMessage(dict);
}
break;
case APPLICATIONMESSAGE_ACK:
@ -905,9 +905,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
if (pebbleCmd != DATALOG_TIMEOUT) {
byte id = buf.get();
LOG.info("DATALOG id " + id + " - sending 0x85 (ACK?)");
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeDatalog(id, (byte) 0x85);
cmd = sendBytes;
devEvt = sendBytes;
} else {
LOG.info("DATALOG TIMEOUT - ignoring");
}
@ -916,9 +916,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
switch (pebbleCmd) {
case PHONEVERSION_REQUEST:
LOG.info("Pebble asked for Phone/App Version - repLYING!");
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodePhoneVersion(PHONEVERSION_REMOTE_OS_ANDROID);
cmd = sendBytes;
devEvt = sendBytes;
break;
default:
break;
@ -928,7 +928,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
break;
}
return cmd;
return devEvt;
}
public void setForceProtocol(boolean force) {

View File

@ -9,8 +9,8 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandSendBytes;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
public class WeatherNeatSupport {
@ -48,8 +48,8 @@ public class WeatherNeatSupport {
return buf.array();
}
public GBDeviceCommand handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
public GBDeviceEvent handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeWeatherNeatMessage("Berlin", "22 C", "cloudy", 0);
return sendBytes;
}

View File

@ -1,12 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
public class GBDeviceCommandAppInfo extends GBDeviceCommand {
public GBDeviceApp apps[];
public byte freeSlot = -1;
public GBDeviceCommandAppInfo() {
commandClass = CommandClass.APP_INFO;
}
}

View File

@ -1,24 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
public class GBDeviceCommandAppManagementResult extends GBDeviceCommand {
public Result result = Result.UNKNOWN;
public CommandType type = CommandType.UNKNOWN;
public int token = -1;
public GBDeviceCommandAppManagementResult() {
commandClass = CommandClass.APP_MANAGEMENT_RES;
}
public enum CommandType {
UNKNOWN,
INSTALL,
DELETE,
}
public enum Result {
UNKNOWN,
SUCCESS,
ACKNOLEDGE,
FAILURE,
}
}

View File

@ -1,20 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
public class GBDeviceCommandCallControl extends GBDeviceCommand {
public Command command = Command.UNKNOWN;
public GBDeviceCommandCallControl() {
commandClass = CommandClass.CALL_CONTROL;
}
public enum Command {
UNKNOWN,
ACCEPT,
END,
INCOMING,
OUTGOING,
REJECT,
START,
}
}

View File

@ -1,21 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
public class GBDeviceCommandMusicControl extends GBDeviceCommand {
public Command command = Command.UNKNOWN;
public GBDeviceCommandMusicControl() {
commandClass = CommandClass.MUSIC_CONTROL;
}
public enum Command {
UNKNOWN,
PLAY,
PAUSE,
PLAYPAUSE,
NEXT,
PREVIOUS,
VOLUMEUP,
VOLUMEDOWN,
}
}

View File

@ -1,9 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
public class GBDeviceCommandSendBytes extends GBDeviceCommand {
public byte[] encodedBytes;
public GBDeviceCommandSendBytes() {
commandClass = CommandClass.SEND_BYTES;
}
}

View File

@ -1,72 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.protocol;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
public abstract class GBDeviceProtocol {
public byte[] encodeSMS(String from, String body) {
return null;
}
public byte[] encodeEmail(String from, String subject, String body) {
return null;
}
public byte[] encodeGenericNotification(String title, String details) {
return null;
}
public byte[] encodeSetTime(long ts) {
return null;
}
public byte[] encodeSetCallState(String number, String name, GBCommand command) {
return null;
}
public byte[] encodeSetMusicInfo(String artist, String album, String track) {
return null;
}
public byte[] encodeFirmwareVersionReq() {
return null;
}
public byte[] encodeBatteryInfoReq() {
return null;
}
public byte[] encodeAppInfoReq() {
return null;
}
public byte[] encodeAppDelete(UUID uuid) {
return null;
}
public byte[] encodeAppStart(UUID uuid) {
return null;
}
public byte[] encodePhoneVersion(byte os) {
return null;
}
public byte[] encodeSynchronizeActivityData() {
return null;
}
public byte[] encodeReboot() {
return null;
}
public byte[] encodeFindDevice(boolean start) {
return null;
}
public GBDeviceCommand decodeResponse(byte[] responseData) {
return null;
}
}