/** * update the node rssi information * @param gatt connection * @param rssi rssi with the device * @param status true if the read is successfully */ @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status){ if(status == BluetoothGatt.GATT_SUCCESS){ Node.this.updateRssi(rssi); }else{ Log.e(TAG, "Impossible retrieve the rssi value"); }//if-else }//onReadRemoteRssi
/** * function call when the manager receive a new advertise by this node * @param rssi rssi of the last advertise */ void isAlive(int rssi){ //remove the set lost task if(mHandler!=null) mHandler.removeCallbacks(mSetNodeLost); updateRssi(rssi); //start a new set lost task if(mHandler!=null) mHandler.postDelayed(mSetNodeLost,NODE_LOST_TIMEOUT_MS); }//isAlive
/** * create a new node * @param device android ble device * @param rssi rssi of the advertise message * @param advertise advertise message for this node * @throws InvalidBleAdvertiseFormat if the advertise is not well formed */ public Node(BluetoothDevice device,int rssi,byte advertise[]) throws InvalidBleAdvertiseFormat{ mAdvertise = new BleAdvertiseParser(advertise); mDevice = device; mExternalCharFeatures= new HashMap<>(); updateRssi(rssi); updateNodeStatus(State.Idle); initHandler(); addNodeStateListener(mNotifyCommandChange); Log.i(TAG, mAdvertise.toString()); }
@Test public void testUpdateRssi(){ Node.BleConnectionParamUpdateListener listener = mock(Node .BleConnectionParamUpdateListener.class); Node node = createNode(null); node.addBleConnectionParamListener(listener); int rssi = new Random().nextInt(); node.updateRssi(rssi); TestUtil.execAllAsyncTask(); verify(listener).onRSSIChanged(node, rssi); }