@Override public void onStateChange(Node node, Node.State newState, Node.State prevState) { Log.d("NodeStateListener", node.getName() + " " + prevState + "->" + newState); } };
/** * if present it return a node with that name * <p>Note: the name is not unique, we will return the fist node that match the name</p> * <p>Note: the match is case sensitive</p> * * @param name name of the device * @return the device with that name or null otherwise */ public @Nullable Node getNodeWithName(String name) { synchronized (mDiscoverNode) { for (Node n : mDiscoverNode) { if (n.getName().equals(name)) return n; }//for }// synchronized return null; }//getNodeWithName
public void upDateAdvertising(byte advertise[]){ try { mAdvertise = new BleAdvertiseParser(advertise); }catch (Exception e){Log.e(TAG,"Error updating advertising for:"+ getName());} }
/** * get the device name with some product tag info (BLE Address) * @return the device friendly Name */ public String getFriendlyName(){ if (mFriendlyName == null) { String strTagClean = "NA"; if (getTag() != null && getTag().length() > 0) strTagClean = getTag().replace(":", ""); mFriendlyName = getName() + " @" + strTagClean.substring(strTagClean.length() - Math.min(6, strTagClean.length()), strTagClean.length()); } return mFriendlyName; }//getFriendlyName
@Override public void onStateChange(Node node, State newState, State prevState) { if(newState == State.Connected && mFeatureCommand !=null) { changeNotificationStatus(mFeatureCommand,true); }//if //error during connection (connecting ->dead or connected -> dead ) if((prevState == State.Connecting || prevState== State.Connected ) && newState==State .Dead){ Log.e(TAG,"Error connecting to the node:"+node.getName()); //we disconnect -> free the gatt resource and connect again if(mConnection!=null){ mConnection.close();} cleanConnectionData(); } if(newState==State.Dead || newState==State.Disconnecting){ if(mBoundStateChange !=null) { //clean the broadcast receiver mContext.getApplicationContext().unregisterReceiver(mBoundStateChange); mBoundStateChange = null; } } }//onStateChange };
case Dead: msg = String.format(getResources().getString(R.string.progressDialogConnMsgDeadNodeError), node.getName()); break; case Unreachable: msg = String.format(getResources().getString(R.string.progressDialogConnMsgUnreachableNodeError), node.getName()); break; case Lost: msg = String.format(getResources().getString(R.string .progressDialogConnMsgLostNodeError), node.getName()); break;
viewHolder.sensorName.setText(sensor.getName()); viewHolder.sensorTag.setText(sensor.getTag()); switch (sensor.getType()) {
/** * set this fragment as retain state + recover the node from the manager * * @param savedInstanceState data stored from the previous instance (not used) */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); String nodeTag = getArguments().getString(NODE_TAG); mNode = Manager.getSharedInstance().getNodeWithTag(nodeTag); if (mNode != null) setUpProgressDialog(mNode.getName()); }//onCreate
@Test public void TestGetNodeByName() { final String nodeName1 = "TestNode1"; final String nodeName2 = "TestNode2"; Node node1 = buildMockNode(); Node node2 = buildMockNode(); when(node1.getName()).thenReturn(nodeName1); when(node2.getName()).thenReturn(nodeName2); mManager.addNode(node1); mManager.addNode(node2); Assert.assertEquals(node1, mManager.getNodeWithName(nodeName1)); Assert.assertEquals(node2, mManager.getNodeWithName(nodeName2)); }
Log.d(TAG,"Node: "+Node.this.getName()+" Status: "+status+" newState: " + ""+newState+" boundState:"+mDevice.getBondState()); if(status==BluetoothGatt.GATT_SUCCESS){