Search in sources :

Example 1 with GBDeviceEventSendBytes

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.

the class LiveviewProtocol method decodeResponse.

@Override
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
    int length = responseData.length;
    if (length < 4) {
        // empty message
        return null;
    } else {
        ByteBuffer buffer = ByteBuffer.wrap(responseData, 0, length);
        byte msgId = buffer.get();
        buffer.get();
        int payloadLen = buffer.getInt();
        GBDeviceEventSendBytes reply = new GBDeviceEventSendBytes();
        if (payloadLen + 6 == length) {
            switch(msgId) {
                case LiveviewConstants.MSG_DEVICESTATUS:
                    reply.encodedBytes = constructMessage(LiveviewConstants.MSG_DEVICESTATUS_ACK, new byte[] { LiveviewConstants.RESULT_OK });
                    break;
                case LiveviewConstants.MSG_DISPLAYPANEL_ACK:
                    // hack to make the notifications vibrate!
                    reply.encodedBytes = encodeVibrateRequest((short) 100, (short) 200);
                    break;
                default:
            }
            GBDeviceEventSendBytes ack = new GBDeviceEventSendBytes();
            ack.encodedBytes = constructMessage(LiveviewConstants.MSG_ACK, new byte[] { msgId });
            return new GBDeviceEvent[] { ack, reply };
        }
    }
    return super.decodeResponse(responseData);
}
Also used : GBDeviceEvent(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent) GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes) ByteBuffer(java.nio.ByteBuffer)

Example 2 with GBDeviceEventSendBytes

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.

the class SonyHeadphonesProtocol method handleAck.

private GBDeviceEvent handleAck() {
    pendingAcks--;
    if (!requestQueue.isEmpty()) {
        LOG.debug("Outstanding requests in queue: {}", requestQueue.size());
        final Request request = requestQueue.remove();
        return new GBDeviceEventSendBytes(request.encode(sequenceNumber));
    }
    if (GBDevice.State.INITIALIZING.equals(getDevice().getState())) {
        return new GBDeviceEventUpdateDeviceState(GBDevice.State.INITIALIZED);
    }
    return null;
}
Also used : Request(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request) GBDeviceEventUpdateDeviceState(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceState) GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)

Example 3 with GBDeviceEventSendBytes

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.

the class PebbleProtocol method decodeVoiceControl.

private GBDeviceEvent decodeVoiceControl(ByteBuffer buf) {
    buf.order(ByteOrder.LITTLE_ENDIAN);
    byte command = buf.get();
    int flags = buf.getInt();
    // 0x01 dictation 0x02 command
    byte session_type = buf.get();
    short session_id = buf.getShort();
    // attributes
    byte count = buf.get();
    byte type = buf.get();
    short length = buf.getShort();
    byte[] version = new byte[20];
    // it's a string like "1.2rc1"
    buf.get(version);
    int sample_rate = buf.getInt();
    short bit_rate = buf.getShort();
    byte bitstream_version = buf.get();
    short frame_size = buf.getShort();
    GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
    if (command == 0x01) {
        // session setup
        int replLenght = 7;
        // 5 = disabled,  change to 0 to send success
        byte replStatus = 5;
        ByteBuffer repl = ByteBuffer.allocate(LENGTH_PREFIX + replLenght);
        repl.order(ByteOrder.BIG_ENDIAN);
        repl.putShort((short) replLenght);
        repl.putShort(ENDPOINT_VOICECONTROL);
        repl.put(command);
        repl.putInt(flags);
        repl.put(session_type);
        repl.put(replStatus);
        sendBytes.encodedBytes = repl.array();
    } else if (command == 0x02) {
        // dictation result (possibly it is something we send, not something we receive)
        sendBytes.encodedBytes = null;
    }
    return sendBytes;
}
Also used : GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes) ByteBuffer(java.nio.ByteBuffer)

Example 4 with GBDeviceEventSendBytes

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;
}
Also used : GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)

Example 5 with GBDeviceEventSendBytes

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.

the class PebbleProtocol method decodeDatalog.

private GBDeviceEvent[] decodeDatalog(ByteBuffer buf, short length) {
    byte command = buf.get();
    byte id = buf.get();
    GBDeviceEvent[] devEvtsDataLogging = null;
    switch(command) {
        case DATALOG_TIMEOUT:
            LOG.info("DATALOG TIMEOUT. id=" + (id & 0xff) + " - ignoring");
            return null;
        case DATALOG_SENDDATA:
            buf.order(ByteOrder.LITTLE_ENDIAN);
            int items_left = buf.getInt();
            int crc = buf.getInt();
            DatalogSession datalogSession = mDatalogSessions.get(id);
            LOG.info("DATALOG SENDDATA. id=" + (id & 0xff) + ", items_left=" + items_left + ", total length=" + (length - 10));
            if (datalogSession != null) {
                LOG.info("DATALOG UUID=" + datalogSession.uuid + ", tag=" + datalogSession.tag + datalogSession.getTaginfo() + ", itemSize=" + datalogSession.itemSize + ", itemType=" + datalogSession.itemType);
                if (!datalogSession.uuid.equals(UUID_ZERO) && datalogSession.getClass().equals(DatalogSession.class) && mEnablePebbleKit) {
                    devEvtsDataLogging = datalogSession.handleMessageForPebbleKit(buf, length - 10);
                } else {
                    devEvtsDataLogging = datalogSession.handleMessage(buf, length - 10);
                }
            }
            break;
        case DATALOG_OPENSESSION:
            UUID uuid = getUUID(buf);
            buf.order(ByteOrder.LITTLE_ENDIAN);
            int timestamp = buf.getInt();
            int log_tag = buf.getInt();
            byte item_type = buf.get();
            short item_size = buf.getShort();
            LOG.info("DATALOG OPENSESSION. id=" + (id & 0xff) + ", App UUID=" + uuid.toString() + ", log_tag=" + log_tag + ", item_type=" + item_type + ", itemSize=" + item_size);
            if (!mDatalogSessions.containsKey(id)) {
                if (uuid.equals(UUID_ZERO) && log_tag == 78) {
                    mDatalogSessions.put(id, new DatalogSessionAnalytics(id, uuid, timestamp, log_tag, item_type, item_size, getDevice()));
                } else if (uuid.equals(UUID_ZERO) && log_tag == 81) {
                    mDatalogSessions.put(id, new DatalogSessionHealthSteps(id, uuid, timestamp, log_tag, item_type, item_size, getDevice()));
                } else if (uuid.equals(UUID_ZERO) && log_tag == 83) {
                    mDatalogSessions.put(id, new DatalogSessionHealthSleep(id, uuid, timestamp, log_tag, item_type, item_size, getDevice()));
                } else if (uuid.equals(UUID_ZERO) && log_tag == 84) {
                    mDatalogSessions.put(id, new DatalogSessionHealthOverlayData(id, uuid, timestamp, log_tag, item_type, item_size, getDevice()));
                } else if (uuid.equals(UUID_ZERO) && log_tag == 85) {
                    mDatalogSessions.put(id, new DatalogSessionHealthHR(id, uuid, timestamp, log_tag, item_type, item_size, getDevice()));
                } else {
                    mDatalogSessions.put(id, new DatalogSession(id, uuid, timestamp, log_tag, item_type, item_size));
                }
            }
            devEvtsDataLogging = new GBDeviceEvent[] { null };
            break;
        case DATALOG_CLOSE:
            LOG.info("DATALOG_CLOSE. id=" + (id & 0xff));
            datalogSession = mDatalogSessions.get(id);
            if (datalogSession != null) {
                if (!datalogSession.uuid.equals(UUID_ZERO) && datalogSession.getClass().equals(DatalogSession.class) && mEnablePebbleKit) {
                    GBDeviceEventDataLogging dataLogging = new GBDeviceEventDataLogging();
                    dataLogging.command = GBDeviceEventDataLogging.COMMAND_FINISH_SESSION;
                    dataLogging.appUUID = datalogSession.uuid;
                    dataLogging.tag = datalogSession.tag;
                    devEvtsDataLogging = new GBDeviceEvent[] { dataLogging, null };
                }
                if (datalogSession.uuid.equals(UUID_ZERO) && (datalogSession.tag == 81 || datalogSession.tag == 83 || datalogSession.tag == 84)) {
                    GB.signalActivityDataFinish();
                }
                mDatalogSessions.remove(id);
            }
            break;
        default:
            LOG.info("unknown DATALOG command: " + (command & 0xff));
            break;
    }
    GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
    if (devEvtsDataLogging != null) {
        // append ack
        LOG.info("sending ACK (0x85)");
        sendBytes.encodedBytes = encodeDatalog(id, DATALOG_ACK);
        devEvtsDataLogging[devEvtsDataLogging.length - 1] = sendBytes;
    } else {
        LOG.info("sending NACK (0x86)");
        sendBytes.encodedBytes = encodeDatalog(id, DATALOG_NACK);
        devEvtsDataLogging = new GBDeviceEvent[] { sendBytes };
    }
    return devEvtsDataLogging;
}
Also used : GBDeviceEvent(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent) GBDeviceEventDataLogging(nodomain.freeyourgadget.gadgetbridge.deviceevents.pebble.GBDeviceEventDataLogging) GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes) UUID(java.util.UUID)

Aggregations

GBDeviceEventSendBytes (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)24 GBDeviceEvent (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent)21 WeatherSpec (nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec)11 ByteBuffer (java.nio.ByteBuffer)4 UUID (java.util.UUID)3 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)2 GBDeviceEventAppMessage (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppMessage)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Pair (android.util.Pair)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GBDeviceEventAppInfo (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo)1 GBDeviceEventAppManagement (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagement)1 GBDeviceEventCallControl (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl)1 GBDeviceEventFindPhone (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone)1 GBDeviceEventMusicControl (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl)1 GBDeviceEventNotificationControl (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl)1 GBDeviceEventUpdateDeviceState (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceState)1