Untitled

 avatar
unknown
java
5 years ago
13 kB
7
Indexable
public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bArr) {
        boolean z;
        int i2;
        boolean z2;
        long j;
        long currentTimeMillis;
        long j2;
        String str;
        StringBuilder sb;
        byte[] bArr2 = bArr;
        if (!this.isDestroy && bluetoothDevice.getName() != null && bluetoothDevice.getName().equals(Const.DEVICE_NAME)) {
            String address = bluetoothDevice.getAddress();
            final Device device = null;
            final int i3 = -1;
            for (int i4 = 0; i4 < this.deviceList.size(); i4++) {
                if (((Device) this.deviceList.get(i4)).getDeviceMac().toLowerCase().equals(address.toLowerCase())) {
                    device = (Device) this.deviceList.get(i4);
                    i3 = i4;
                }
            }
            if (device != null) {
                ObjectAnimator objectAnimator = this.animator;
                if (objectAnimator != null) {
                    objectAnimator.cancel();
                }
                String str2 = "";
                for (byte b : bArr2) {
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append(str2);
                    byte b2 = b & 255;
                    if (Integer.toHexString(b2).length() == 2) {
                        sb = new StringBuilder();
                        str = " ";
                    } else {
                        sb = new StringBuilder();
                        str = " 0";
                    }
                    sb.append(str);
                    sb.append(Integer.toHexString(b2));
                    sb2.append(sb.toString());
                    str2 = sb2.toString();
                }
                String str3 = this.TAG;
                StringBuilder sb3 = new StringBuilder();
                sb3.append("onLeScan: scanRecord: ");
                sb3.append(str2);
                Log.d(str3, sb3.toString());
                int customDataStartIndex = Utils.getCustomDataStartIndex(bArr);
                if (customDataStartIndex == -1) {
                    String str4 = this.TAG;
                    StringBuilder sb4 = new StringBuilder();
                    sb4.append("unavailable device: ");
                    sb4.append(bluetoothDevice.getName());
                    sb4.append(": ");
                    sb4.append(address);
                    Log.e(str4, "onLeScan: ", new Exception(sb4.toString()));
                    return;
                }
                boolean z3 = true;
                if (bArr2[customDataStartIndex] == 21 || bArr2[customDataStartIndex] == 19) {
                    int littleEndianDataParse = Utils.littleEndianDataParse(bArr2, customDataStartIndex + 12, 2);
                    float littleEndianDataParseHaveSign = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 14, 2)) / 16.0f;
                    int i5 = customDataStartIndex + 2;
                    if (bArr2[i5] == 16 || bArr2[i5] == 17 || bArr2[i5] == 18) {
                        float littleEndianDataParseHaveSign2 = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 16, 2)) / 16.0f;
                        j = (long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 18, 4);
                        if (((device.getHumidityType() & 1) == 1 && littleEndianDataParseHaveSign2 <= device.getPresetLowestHumidity() && device.getRecentHumidity() > device.getPresetLowestHumidity()) || ((device.getHumidityType() & 2) == 2 && littleEndianDataParseHaveSign2 >= device.getPresetHighestHumidity() && device.getRecentHumidity() < device.getPresetHighestHumidity())) {
                            NotificationSender.getInstance().notify(this, 2, device, littleEndianDataParseHaveSign2);
                        }
                        if (device.getRecentHumidity() != littleEndianDataParseHaveSign2) {
                            device.setRecentHumidity(littleEndianDataParseHaveSign2);
                            z2 = true;
                            long j3 = 1000 * j;
                            currentTimeMillis = System.currentTimeMillis() - j3;
                            long j4 = j3 + currentTimeMillis;
                            if (!Utils.isNew(currentTimeMillis, device.getStartTime(), j)) {
                                String str5 = this.TAG;
                                StringBuilder sb5 = new StringBuilder();
                                sb5.append("onLeScan: start change: ");
                                j2 = j4;
                                sb5.append(Math.abs(device.getStartTime() - currentTimeMillis));
                                sb5.append(", ");
                                sb5.append(Math.ceil((double) Math.abs(((float) (device.getStartTime() - currentTimeMillis)) / 1000.0f)));
                                Log.e(str5, sb5.toString());
                                device.setStartTime(currentTimeMillis);
                                try {
                                    MyApplication myApplication = this.myApplication;
                                    Session session = new Session(currentTimeMillis, device.getHighestTemp(), device.getHighestTempTime(), device.getLowestTemp(), device.getLowestTempTime(), device.getTempType(), device.getName(), device.getLocation(), device.getPresetHighest(), device.getPresetLowest(), device.getImgName(), device.getDeviceType());
                                    device.setSessionID(myApplication.addSession(session));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                z2 = true;
                            } else {
                                j2 = j4;
                            }
                            if (((device.getTempType() & 1) == 1 && littleEndianDataParseHaveSign <= device.getPresetLowest() && device.getRecentTemp() > device.getPresetLowest()) || ((device.getTempType() & 2) == 2 && littleEndianDataParseHaveSign >= device.getPresetHighest() && device.getRecentTemp() < device.getPresetHighest())) {
                                NotificationSender.getInstance().notify(this, 1, device, littleEndianDataParseHaveSign);
                            }
                            if (device.getRecentTempTime() != j2) {
                                long j5 = j2;
                                device.setRecentTempTime(j5);
                                device.setRecentTemp(littleEndianDataParseHaveSign);
                                if (littleEndianDataParseHaveSign > device.getHighestTemp()) {
                                    device.setHighestTemp(littleEndianDataParseHaveSign);
                                    device.setHighestTempTime(j5);
                                }
                                if (littleEndianDataParseHaveSign < device.getLowestTemp()) {
                                    device.setLowestTemp(littleEndianDataParseHaveSign);
                                    device.setLowestTempTime(j5);
                                }
                                z2 = true;
                            }
                            if (device.getBattery() == littleEndianDataParse) {
                                device.setBattery(littleEndianDataParse);
                            } else {
                                z3 = z2;
                            }
                            String str6 = this.TAG;
                            StringBuilder sb6 = new StringBuilder();
                            sb6.append("onLeScan: battery: ");
                            sb6.append(littleEndianDataParse);
                            sb6.append(", currentTemperature: ");
                            sb6.append(littleEndianDataParseHaveSign);
                            sb6.append(", currentTempDeviceRuntime: ");
                            sb6.append(j);
                            Log.i(str6, sb6.toString());
                            i2 = i;
                            z = z3;
                        }
                    } else {
                        j = (long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 16, 4);
                    }
                    z2 = false;
                    long j32 = 1000 * j;
                    currentTimeMillis = System.currentTimeMillis() - j32;
                    long j42 = j32 + currentTimeMillis;
                    if (!Utils.isNew(currentTimeMillis, device.getStartTime(), j)) {
                    }
                    NotificationSender.getInstance().notify(this, 1, device, littleEndianDataParseHaveSign);
                    if (device.getRecentTempTime() != j2) {
                    }
                    if (device.getBattery() == littleEndianDataParse) {
                    }
                    String str62 = this.TAG;
                    StringBuilder sb62 = new StringBuilder();
                    sb62.append("onLeScan: battery: ");
                    sb62.append(littleEndianDataParse);
                    sb62.append(", currentTemperature: ");
                    sb62.append(littleEndianDataParseHaveSign);
                    sb62.append(", currentTempDeviceRuntime: ");
                    sb62.append(j);
                    Log.i(str62, sb62.toString());
                    i2 = i;
                    z = z3;
                } else if (bArr2[customDataStartIndex] != 23 || device.getStartTime() == 0) {
                    i2 = i;
                    z = false;
                } else {
                    float littleEndianDataParseHaveSign3 = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 12, 2)) / 16.0f;
                    float littleEndianDataParseHaveSign4 = ((float) Utils.littleEndianDataParseHaveSign(bArr2, customDataStartIndex + 18, 2)) / 16.0f;
                    long startTime = device.getStartTime() + (((long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 14, 4)) * 1000);
                    long startTime2 = device.getStartTime() + (((long) Utils.littleEndianDataParse(bArr2, customDataStartIndex + 20, 4)) * 1000);
                    String str7 = this.TAG;
                    StringBuilder sb7 = new StringBuilder();
                    sb7.append("onLeScan: highest: ");
                    sb7.append(littleEndianDataParseHaveSign3);
                    sb7.append(", lowest: ");
                    sb7.append(littleEndianDataParseHaveSign4);
                    Log.i(str7, sb7.toString());
                    if (device.getHighestTempTime() == startTime && device.getHighestTemp() == littleEndianDataParseHaveSign3) {
                        z = false;
                    } else {
                        device.setHighestTempTime(startTime);
                        device.setHighestTemp(littleEndianDataParseHaveSign3);
                        z = true;
                    }
                    if (!(device.getLowestTempTime() == startTime2 && device.getLowestTemp() == littleEndianDataParseHaveSign4)) {
                        device.setLowestTempTime(startTime2);
                        device.setLowestTemp(littleEndianDataParseHaveSign4);
                        z = true;
                    }
                    if (z) {
                        Session sessionBySessionID = this.myApplication.getSessionBySessionID(device.getSessionID());
                        sessionBySessionID.setHighest(littleEndianDataParseHaveSign3);
                        sessionBySessionID.setHighestTime(startTime);
                        sessionBySessionID.setLowest(littleEndianDataParseHaveSign4);
                        sessionBySessionID.setLowestTime(startTime2);
                        String str8 = this.TAG;
                        StringBuilder sb8 = new StringBuilder();
                        sb8.append("getShowData3 lowestValue: ");
                        sb8.append(littleEndianDataParseHaveSign4);
                        sb8.append(", time: ");
                        sb8.append(startTime2);
                        Log.i(str8, sb8.toString());
                        this.myApplication.updateSession(sessionBySessionID);
                    }
                    i2 = i;
                }
                device.setSignal(i2);
                if (z) {
                    this.handler.post(new Runnable() {
                        public void run() {
                            CurrentActivity.this.deviceAdapter.notifyItemChanged(i3);
                            CurrentActivity.this.myApplication.updateDevice(device);
                        }
                    });
                }
            }
        }
    }
Editor is loading...