Java Code Examples for com.vise.log.ViseLog#e()

The following examples show how to use com.vise.log.ViseLog#e() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViseBle.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 连接设备
 *
 * @param bluetoothLeDevice
 * @param connectCallback
 */
public void connect(BluetoothLeDevice bluetoothLeDevice, IConnectCallback connectCallback) {
    if (bluetoothLeDevice == null || connectCallback == null) {
        ViseLog.e("This bluetoothLeDevice or connectCallback is null.");
        return;
    }
    if (deviceMirrorPool != null && !deviceMirrorPool.isContainDevice(bluetoothLeDevice)) {
        DeviceMirror deviceMirror = new DeviceMirror(bluetoothLeDevice);
        if (lastDeviceMirror != null && !TextUtils.isEmpty(lastDeviceMirror.getUniqueSymbol())
                && lastDeviceMirror.getUniqueSymbol().equals(deviceMirror.getUniqueSymbol())) {
            deviceMirror = lastDeviceMirror;//防止重复创建设备镜像
        }
        deviceMirror.connect(connectCallback);
        lastDeviceMirror = deviceMirror;
    } else {
        ViseLog.i("This device is connected.");
    }
}
 
Example 2
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 写入数据
 *
 * @param data
 */
public void writeData(byte[] data) {
    if (data == null || data.length > 20) {
        ViseLog.e("this data is null or length beyond 20 byte.");
        return;
    }
    if (!checkBluetoothGattInfo(writeInfoMap)) {
        return;
    }
    if (handler != null) {
        handler.removeMessages(MSG_WRITE_DATA_TIMEOUT);
        handler.removeMessages(MSG_WRITE_DATA_RETRY);
    }
    writeDataRetryCount = 0;
    writeData = data;
    write(data);
}
 
Example 3
Source File: ViseBle.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 连接指定mac地址的设备
 *
 * @param mac             设备mac地址
 * @param connectCallback 连接回调
 */
public void connectByMac(String mac, final IConnectCallback connectCallback) {
    if (mac == null || connectCallback == null) {
        ViseLog.e("This mac or connectCallback is null.");
        return;
    }
    startScan(new SingleFilterScanCallback(new IScanCallback() {
        @Override
        public void onDeviceFound(BluetoothLeDevice bluetoothLeDevice) {

        }

        @Override
        public void onScanFinish(final BluetoothLeDeviceStore bluetoothLeDeviceStore) {
            if (bluetoothLeDeviceStore.getDeviceList().size() > 0) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        connect(bluetoothLeDeviceStore.getDeviceList().get(0), connectCallback);
                    }
                });
            } else {
                connectCallback.onConnectFailure(new TimeoutException());
            }
        }

        @Override
        public void onScanTimeout() {
            connectCallback.onConnectFailure(new TimeoutException());
        }

    }).setDeviceMac(mac));
}
 
Example 4
Source File: ViseBle.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 连接指定设备名称的设备
 *
 * @param name            设备名称
 * @param connectCallback 连接回调
 */
public void connectByName(String name, final IConnectCallback connectCallback) {
    if (name == null || connectCallback == null) {
        ViseLog.e("This name or connectCallback is null.");
        return;
    }
    startScan(new SingleFilterScanCallback(new IScanCallback() {
        @Override
        public void onDeviceFound(BluetoothLeDevice bluetoothLeDevice) {

        }

        @Override
        public void onScanFinish(final BluetoothLeDeviceStore bluetoothLeDeviceStore) {
            if (bluetoothLeDeviceStore.getDeviceList().size() > 0) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        connect(bluetoothLeDeviceStore.getDeviceList().get(0), connectCallback);
                    }
                });
            } else {
                connectCallback.onConnectFailure(new TimeoutException());
            }
        }

        @Override
        public void onScanTimeout() {
            connectCallback.onConnectFailure(new TimeoutException());
        }

    }).setDeviceName(name));
}
 
Example 5
Source File: HexUtil.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 将字节数组转换为十六进制字符串
 *
 * @param data     byte[]
 * @param toDigits 用于控制输出的char[]
 * @return 十六进制String
 */
protected static String encodeHexStr(byte[] data, char[] toDigits) {
    if (data == null) {
        ViseLog.e("this data is null.");
        return "";
    }
    return new String(encodeHex(data, toDigits));
}
 
Example 6
Source File: HexUtil.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 将十六进制字符串转换为字节数组
 *
 * @param data
 * @return
 */
public static byte[] decodeHex(String data) {
    if (data == null) {
        ViseLog.e("this data is null.");
        return new byte[0];
    }
    return decodeHex(data.toCharArray());
}
 
Example 7
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 连接设备
 *
 * @param connectCallback
 */
public synchronized void connect(IConnectCallback connectCallback) {
    if (connectState == ConnectState.CONNECT_SUCCESS || connectState == ConnectState.CONNECT_PROCESS
            || (connectState == ConnectState.CONNECT_INIT && connectRetryCount != 0)) {
        ViseLog.e("this connect state is connecting, connectSuccess or current retry count less than config connect retry count.");
        return;
    }
    if (handler != null) {
        handler.removeCallbacksAndMessages(null);
    }
    this.connectCallback = connectCallback;
    connectRetryCount = 0;
    connect();
}
 
Example 8
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 刷新设备缓存
 *
 * @return 返回是否刷新成功
 */
public synchronized boolean refreshDeviceCache() {
    try {
        final Method refresh = BluetoothGatt.class.getMethod("refresh");
        if (refresh != null && bluetoothGatt != null) {
            final boolean success = (Boolean) refresh.invoke(getBluetoothGatt());
            ViseLog.i("Refreshing result: " + success);
            return success;
        }
    } catch (Exception e) {
        ViseLog.e("An exception occured while refreshing device" + e);
    }
    return false;
}
 
Example 9
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 检查BluetoothGattChannel集合是否有值
 *
 * @param bluetoothGattInfoHashMap
 * @return
 */
private boolean checkBluetoothGattInfo(HashMap<String, BluetoothGattChannel> bluetoothGattInfoHashMap) {
    if (bluetoothGattInfoHashMap == null || bluetoothGattInfoHashMap.size() == 0) {
        ViseLog.e("this bluetoothGattInfo map is not value.");
        return false;
    }
    return true;
}
 
Example 10
Source File: MainActivity.java    From ViseLog with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.print_normal_message:
            Log.v("message", "test message");
            ViseLog.v("test message");
            break;
        case R.id.print_normal_object:
            ViseLog.i(new Boolean(true));
            break;
        case R.id.print_bundle_object:
            ViseLog.d(new Bundle());
            break;
        case R.id.print_collection_object:
            printList();
            break;
        case R.id.print_intent_object:
            ViseLog.w(new Intent());
            break;
        case R.id.print_map_object:
            printMap();
            break;
        case R.id.print_reference_object:
            ViseLog.wtf(new SoftReference(0));
            break;
        case R.id.print_throwable_object:
            ViseLog.e(new NullPointerException("this object is null!"));
            break;
        case R.id.print_json_message:
            printJson();
            break;
        case R.id.print_xml_message:
            printXml();
            break;
        default:
            break;
    }
}
 
Example 11
Source File: DefaultBleExceptionHandler.java    From BLE with Apache License 2.0 4 votes vote down vote up
@Override
protected void onConnectException(ConnectException e) {
    ViseLog.e(e.getDescription());
}
 
Example 12
Source File: DefaultBleExceptionHandler.java    From BLE with Apache License 2.0 4 votes vote down vote up
@Override
protected void onGattException(GattException e) {
    ViseLog.e(e.getDescription());
}
 
Example 13
Source File: DefaultBleExceptionHandler.java    From BLE with Apache License 2.0 4 votes vote down vote up
@Override
protected void onTimeoutException(TimeoutException e) {
    ViseLog.e(e.getDescription());
}
 
Example 14
Source File: DefaultBleExceptionHandler.java    From BLE with Apache License 2.0 4 votes vote down vote up
@Override
protected void onInitiatedException(InitiatedException e) {
    ViseLog.e(e.getDescription());
}
 
Example 15
Source File: DefaultBleExceptionHandler.java    From BLE with Apache License 2.0 4 votes vote down vote up
@Override
protected void onOtherException(OtherException e) {
    ViseLog.e(e.getDescription());
}