@Override public void run() { if(!mSource.isRunning() || mSource.isConnected()) { return; } try { mSource.connect(); } catch(DataSourceException e) { Log.d(mSource.toString(), "Unable to connect because of exception", e); } } }
protected void setFastPolling(boolean enabled) { mReconnectionAttempts = 0; if(enabled) { resetConnectionAttempts(0, RECONNECTION_ATTEMPT_WAIT_TIME_S); } else if(mFastPolling) { resetConnectionAttempts(SLOW_RECONNECTION_ATTEMPT_WAIT_TIME_S, SLOW_RECONNECTION_ATTEMPT_WAIT_TIME_S); } mFastPolling = enabled; }
@Override public void run() { while(isRunning()) { try { waitForConnection(); } catch(InterruptedException e) { Log.i(getTag(), "Interrupted while waiting for connection - stopping the source"); stop(); break; byte[] bytes = new byte[READ_BATCH_SIZE]; try { 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"); VehicleMessage message;
if(!isConnected() && mConnectionCheckTask == null) { setFastPolling(true); while(isRunning() && !isConnected()) { ++mReconnectionAttempts; mConnectionLock.writeLock().lock(); " attempts, slowing down attempts to every " + SLOW_RECONNECTION_ATTEMPT_WAIT_TIME_S + " seconds"); setFastPolling(false);
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"); } }
@Override public boolean isConnected() { return mConnection != null && super.isConnected(); }
@Override public boolean isConnected() { return isRunning(); }
@Override public synchronized void start() { super.start(); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); getContext().registerReceiver(mBroadcastReceiver, filter); filter = new IntentFilter(); filter.addAction(ACTION_USB_DEVICE_ATTACHED); getContext().registerReceiver(mBroadcastReceiver, filter); filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); getContext().registerReceiver(mBroadcastReceiver, filter); initializeDevice(); }
@Override public boolean isConnected() { boolean connected = false; // If we can't get the lock in 100ms, must be blocked waiting for a // connection so we consider it disconnected. try { if(mConnectionLock.readLock().tryLock(100, TimeUnit.MILLISECONDS)) { connected = mSocket != null && mSocket.isConnected() && super.isConnected(); mConnectionLock.readLock().unlock(); } } catch(InterruptedException e) {} return connected; }
connected = super.isConnected(); if (!connectingToBLE) { if (mSocket == null) {