waitForConnection(); } catch(InterruptedException e) { Log.i(getTag(), "Interrupted while waiting for connection - stopping the source"); stop(); break; received = read(bytes); } catch(IOException e) { Log.e(getTag(), "Unable to read response", e); disconnect(); continue; Log.e(getTag(), "Error on read - returned -1"); disconnect(); continue; if(JsonStreamer.containsJson(new String(bytes))) { mStreamHandler = new JsonStreamer(); Log.i(getTag(), "Source is sending JSON"); } else { mStreamHandler = new BinaryStreamer(); Log.i(getTag(), "Source is sending protocol buffers"); Log.d(getTag(), "Stopped " + getTag());
public void receive(VehicleMessage command) throws DataSinkException { if(isConnected()) { VehicleMessageStreamer streamer; synchronized(this) { streamer = mStreamHandler; if(streamer == null) { // See https://github.com/openxc/openxc-android/issues/181 streamer = new JsonStreamer(); Log.i(getTag(), "Payload format unknown, guessing JSON"); } } try { if(!write(streamer.serializeForStream(command))) { throw new DataSinkException("Unable to send command"); } } catch(SerializationException e) { throw new DataSinkException( "Unable to serialize command for sending", e); } } else { throw new DataSinkException("Not connected"); } }