Pebble: Support sending byte arrays from app configuration data

Also add debug output if trying to encode unknown classes in PebbleProtocol

(Fixes #421)
This commit is contained in:
Andreas Shimokawa 2016-10-28 00:32:45 +02:00
parent bdf403210e
commit d6b9e6d64b
2 changed files with 12 additions and 0 deletions

View File

@ -1645,6 +1645,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
} else if (pair.second instanceof byte[]) {
length += ((byte[]) pair.second).length;
}
else {
LOG.warn("unknown type: " + pair.second.getClass().toString());
}
}
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);

View File

@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.net.Uri;
import android.util.Pair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -59,6 +60,14 @@ public class PebbleSupport extends AbstractSerialDeviceSupport {
while (keysIterator.hasNext()) {
String keyStr = keysIterator.next();
Object object = json.get(keyStr);
if (object instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) object;
byte[] byteArray = new byte[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
byteArray[i] = ((Integer) jsonArray.get(i)).byteValue();
}
object = byteArray;
}
pairs.add(new Pair<>(Integer.parseInt(keyStr), object));
}
getDeviceIOThread().write(((PebbleProtocol) getDeviceProtocol()).encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, uuid, pairs));