com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump. 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: Bubble.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
static void AreWeDone() {
    if (s_acumulatedSize < lens) {
        return;
    }
    long now = JoH.tsl();
    String SensorSn = PersistentStore.getString("LibreSN");


    byte[] data = Arrays.copyOfRange(s_full_data, 0, 344);

    boolean checksum_ok = NFCReaderX.HandleGoodReading(SensorSn, data, now, true, patchUid, patchInfo);
    int expectedSize = lens + BUBBLE_FOOTER;
    InitBuffer(expectedSize);
    errorCount = 0;
    Log.e(TAG, "We have all the data that we need " + s_acumulatedSize + " checksum_ok = " + checksum_ok + HexDump.dumpHexString(data));

}
 
Example #2
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void reprocessTxMessage(BaseMessage tm) {
    // rewrite session start messages in case our clock was wrong
    if (tm instanceof SessionStartTxMessage) {
        final SessionStartTxMessage ssm = (SessionStartTxMessage) tm;
        if (usingG6()) {
            final String code = G6CalibrationParameters.getCurrentSensorCode();
            if (code == null) {
                UserError.Log.wtf(TAG, "Cannot reprocess start G6 sensor as calibration code not set!");
            } else {
                // g6
                tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime()), code).byteSequence;
            }
        } else {
            // g5
            tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime())).byteSequence;
        }
        UserError.Log.d(TAG, "New session start: " + ssm.getDexTime() + " for time: " + JoH.dateTimeText(ssm.getStartTime()));
        if (d) {
            UserError.Log.d(TAG, "New packet: " + HexDump.dumpHexString(tm.byteSequence));
        }
    }
}
 
Example #3
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void enqueueUniqueCommand(BaseMessage tm, String msg) {
    if (tm != null) {
        final Class searchClass = tm.getClass();
        Ob1Work item;
        synchronized (commandQueue) {
            if (searchQueue(searchClass)) {
                UserError.Log.d(TAG, "Not adding duplicate: " + searchClass.getSimpleName());
                return;
            }
            item = new Ob1Work(tm, msg);
            if (d) {
                UserError.Log.d(TAG, "Adding to queue packet: " + msg + " " + HexDump.dumpHexString(tm.byteSequence));
            }
            commandQueue.add(item);
            streamCheck(item);
        }
        backupCheck(item);
    }
}
 
Example #4
Source File: Bubble.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
static void AreWeDone() {
    if (s_acumulatedSize < lens) {
        return;
    }
    long now = JoH.tsl();
    String SensorSn = PersistentStore.getString("LibreSN");


    byte[] data = Arrays.copyOfRange(s_full_data, 0, 344);

    boolean checksum_ok = NFCReaderX.HandleGoodReading(SensorSn, data, now, true, patchUid, patchInfo);
    int expectedSize = lens + BUBBLE_FOOTER;
    InitBuffer(expectedSize);
    errorCount = 0;
    Log.e(TAG, "We have all the data that we need " + s_acumulatedSize + " checksum_ok = " + checksum_ok + HexDump.dumpHexString(data));

}
 
Example #5
Source File: LibreAlarmReceiver.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void processReadingDataTransferObject(ReadingData.TransferObject object, long CaptureDateTime, String tagid, boolean allowUpload, byte []patchUid,  byte []patchInfo) {
	Log.i(TAG, "Data that was recieved from librealarm is " + HexDump.dumpHexString(object.data.raw_data));
	// Save raw block record (we start from block 0)
    LibreBlock.createAndSave(tagid, CaptureDateTime, object.data.raw_data, 0, allowUpload, patchUid,  patchInfo);

    if(Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
        if(object.data.raw_data == null) {
            Log.e(TAG, "Please update LibreAlarm to use OOP algorithm");
            JoH.static_toast_long(gs(R.string.please_update_librealarm_to_use_oop_algorithm));
            return;
        }
        LibreOOPAlgorithm.SendData(object.data.raw_data, CaptureDateTime);
        return;
    }
    CalculateFromDataTransferObject(object, use_raw_);
}
 
Example #6
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void enqueueUniqueCommand(BaseMessage tm, String msg) {
    if (tm != null) {
        final Class searchClass = tm.getClass();
        Ob1Work item;
        synchronized (commandQueue) {
            if (searchQueue(searchClass)) {
                UserError.Log.d(TAG, "Not adding duplicate: " + searchClass.getSimpleName());
                return;
            }
            item = new Ob1Work(tm, msg);
            if (d) {
                UserError.Log.d(TAG, "Adding to queue packet: " + msg + " " + HexDump.dumpHexString(tm.byteSequence));
            }
            commandQueue.add(item);
            streamCheck(item);
        }
        backupCheck(item);
    }
}
 
Example #7
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void reprocessTxMessage(BaseMessage tm) {
    // rewrite session start messages in case our clock was wrong
    if (tm instanceof SessionStartTxMessage) {
        final SessionStartTxMessage ssm = (SessionStartTxMessage) tm;
        if (usingG6()) {
            final String code = G6CalibrationParameters.getCurrentSensorCode();
            if (code == null) {
                UserError.Log.wtf(TAG, "Cannot reprocess start G6 sensor as calibration code not set!");
            } else {
                // g6
                tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime()), code).byteSequence;
            }
        } else {
            // g5
            tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime())).byteSequence;
        }
        UserError.Log.d(TAG, "New session start: " + ssm.getDexTime() + " for time: " + JoH.dateTimeText(ssm.getStartTime()));
        if (d) {
            UserError.Log.d(TAG, "New packet: " + HexDump.dumpHexString(tm.byteSequence));
        }
    }
}
 
Example #8
Source File: Bubble.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
static void AreWeDone() {
    if (s_acumulatedSize < lens) {
        return;
    }
    long now = JoH.tsl();
    String SensorSn = PersistentStore.getString("LibreSN");


    byte[] data = Arrays.copyOfRange(s_full_data, 0, 344);

    boolean checksum_ok = NFCReaderX.HandleGoodReading(SensorSn, data, now, true, patchUid, patchInfo);
    int expectedSize = lens + BUBBLE_FOOTER;
    InitBuffer(expectedSize);
    errorCount = 0;
    Log.e(TAG, "We have all the data that we need " + s_acumulatedSize + " checksum_ok = " + checksum_ok + HexDump.dumpHexString(data));

}
 
Example #9
Source File: LibreAlarmReceiver.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void processReadingDataTransferObject(ReadingData.TransferObject object, long CaptureDateTime, String tagid, boolean allowUpload, byte []patchUid,  byte []patchInfo) {
	Log.i(TAG, "Data that was recieved from librealarm is " + HexDump.dumpHexString(object.data.raw_data));
	// Save raw block record (we start from block 0)
    LibreBlock.createAndSave(tagid, CaptureDateTime, object.data.raw_data, 0, allowUpload, patchUid,  patchInfo);

    if(Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
        if(object.data.raw_data == null) {
            Log.e(TAG, "Please update LibreAlarm to use OOP algorithm");
            JoH.static_toast_long(gs(R.string.please_update_librealarm_to_use_oop_algorithm));
            return;
        }
        LibreOOPAlgorithm.SendData(object.data.raw_data, CaptureDateTime);
        return;
    }
    CalculateFromDataTransferObject(object, use_raw_);
}
 
Example #10
Source File: LibreAlarmReceiver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void processReadingDataTransferObject(ReadingData.TransferObject object, long CaptureDateTime, String tagid, boolean allowUpload, byte []patchUid,  byte []patchInfo) {
	Log.i(TAG, "Data that was recieved from librealarm is " + HexDump.dumpHexString(object.data.raw_data));
	// Save raw block record (we start from block 0)
    LibreBlock.createAndSave(tagid, CaptureDateTime, object.data.raw_data, 0, allowUpload, patchUid,  patchInfo);

    if(Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
        if(object.data.raw_data == null) {
            Log.e(TAG, "Please update LibreAlarm to use OOP algorithm");
            JoH.static_toast_long(gs(R.string.please_update_librealarm_to_use_oop_algorithm));
            return;
        }
        LibreOOPAlgorithm.SendData(object.data.raw_data, CaptureDateTime);
        return;
    }
    CalculateFromDataTransferObject(object, use_raw_);
}
 
Example #11
Source File: Bubble.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
static void AreWeDone() {
    if (s_acumulatedSize < lens) {
        return;
    }
    long now = JoH.tsl();
    String SensorSn = PersistentStore.getString("LibreSN");


    byte[] data = Arrays.copyOfRange(s_full_data, 0, 344);

    boolean checksum_ok = NFCReaderX.HandleGoodReading(SensorSn, data, now, true, patchUid, patchInfo);
    int expectedSize = lens + BUBBLE_FOOTER;
    InitBuffer(expectedSize);
    errorCount = 0;
    Log.e(TAG, "We have all the data that we need " + s_acumulatedSize + " checksum_ok = " + checksum_ok + HexDump.dumpHexString(data));

}
 
Example #12
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void reprocessTxMessage(BaseMessage tm) {
    // rewrite session start messages in case our clock was wrong
    if (tm instanceof SessionStartTxMessage) {
        final SessionStartTxMessage ssm = (SessionStartTxMessage) tm;
        if (usingG6()) {
            final String code = G6CalibrationParameters.getCurrentSensorCode();
            if (code == null) {
                UserError.Log.wtf(TAG, "Cannot reprocess start G6 sensor as calibration code not set!");
            } else {
                // g6
                tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime()), code).byteSequence;
            }
        } else {
            // g5
            tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime())).byteSequence;
        }
        UserError.Log.d(TAG, "New session start: " + ssm.getDexTime() + " for time: " + JoH.dateTimeText(ssm.getStartTime()));
        if (d) {
            UserError.Log.d(TAG, "New packet: " + HexDump.dumpHexString(tm.byteSequence));
        }
    }
}
 
Example #13
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void enqueueUniqueCommand(BaseMessage tm, String msg) {
    if (tm != null) {
        final Class searchClass = tm.getClass();
        Ob1Work item;
        synchronized (commandQueue) {
            if (searchQueue(searchClass)) {
                UserError.Log.d(TAG, "Not adding duplicate: " + searchClass.getSimpleName());
                return;
            }
            item = new Ob1Work(tm, msg);
            if (d) {
                UserError.Log.d(TAG, "Adding to queue packet: " + msg + " " + HexDump.dumpHexString(tm.byteSequence));
            }
            commandQueue.add(item);
            streamCheck(item);
        }
        backupCheck(item);
    }
}
 
Example #14
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void enqueueUniqueCommand(BaseMessage tm, String msg) {
    if (tm != null) {
        final Class searchClass = tm.getClass();
        Ob1Work item;
        synchronized (commandQueue) {
            if (searchQueue(searchClass)) {
                UserError.Log.d(TAG, "Not adding duplicate: " + searchClass.getSimpleName());
                return;
            }
            item = new Ob1Work(tm, msg);
            if (d) {
                UserError.Log.d(TAG, "Adding to queue packet: " + msg + " " + HexDump.dumpHexString(tm.byteSequence));
            }
            commandQueue.add(item);
            streamCheck(item);
        }
        backupCheck(item);
    }
}
 
Example #15
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void reprocessTxMessage(BaseMessage tm) {
    // rewrite session start messages in case our clock was wrong
    if (tm instanceof SessionStartTxMessage) {
        final SessionStartTxMessage ssm = (SessionStartTxMessage) tm;
        if (usingG6()) {
            final String code = G6CalibrationParameters.getCurrentSensorCode();
            if (code == null) {
                UserError.Log.wtf(TAG, "Cannot reprocess start G6 sensor as calibration code not set!");
            } else {
                // g6
                tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime()), code).byteSequence;
            }
        } else {
            // g5
            tm.byteSequence = new SessionStartTxMessage(ssm.getStartTime(), DexTimeKeeper.getDexTime(getTransmitterID(), ssm.getStartTime())).byteSequence;
        }
        UserError.Log.d(TAG, "New session start: " + ssm.getDexTime() + " for time: " + JoH.dateTimeText(ssm.getStartTime()));
        if (d) {
            UserError.Log.d(TAG, "New packet: " + HexDump.dumpHexString(tm.byteSequence));
        }
    }
}
 
Example #16
Source File: LibreAlarmReceiver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void processReadingDataTransferObject(ReadingData.TransferObject object, long CaptureDateTime, String tagid, boolean allowUpload, byte []patchUid,  byte []patchInfo) {
	Log.i(TAG, "Data that was recieved from librealarm is " + HexDump.dumpHexString(object.data.raw_data));
	// Save raw block record (we start from block 0)
    LibreBlock.createAndSave(tagid, CaptureDateTime, object.data.raw_data, 0, allowUpload, patchUid,  patchInfo);

    if(Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
        if(object.data.raw_data == null) {
            Log.e(TAG, "Please update LibreAlarm to use OOP algorithm");
            JoH.static_toast_long(gs(R.string.please_update_librealarm_to_use_oop_algorithm));
            return;
        }
        LibreOOPAlgorithm.SendData(object.data.raw_data, CaptureDateTime);
        return;
    }
    CalculateFromDataTransferObject(object, use_raw_);
}
 
Example #17
Source File: PendiqService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void enableNotification() {
    UserError.Log.d(TAG, "Enabling notifications");
    connection.setupNotification(INCOMING_CHAR)
            // .timeout(10, TimeUnit.SECONDS)
            .timeout(15, TimeUnit.SECONDS) // WARN
            //.observeOn(Schedulers.newThread()) // needed?
            .doOnNext(notificationObservable -> {
                JoH.threadSleep(1000);
                changeState(GET_STATUS);
            }).flatMap(notificationObservable -> notificationObservable)
            //.timeout(5, TimeUnit.SECONDS)
            .observeOn(Schedulers.newThread())
            .subscribe(bytes -> {
                        // incoming notifications
                        if (d)
                            UserError.Log.d(TAG, "Received data notification bytes: " + HexDump.dumpHexString(bytes));

                        processAndAction(bytes);

                    }, throwable -> {
                        if (!(throwable instanceof TimeoutException)) {
                            UserError.Log.e(TAG, "Throwable inside setup notification: " + throwable);
                        } else {
                            UserError.Log.d(TAG, "OUTER TIMEOUT INSIDE NOTIFICATION LISTENER");
                        }
                        stopConnect();
                    }
            );

}
 
Example #18
Source File: AuthMessages.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public AuthMessages(MiBand.MiBandType mibandType, String authKey) {
    if (mibandType == MiBand.MiBandType.MI_BAND4) {
        cryptFlags = OperationCodes.AUTH_MIBAND4_CRYPT_FLAG;
    }
    localKey = CipherUtils.getRandomKey();
    if (authKey != null && !authKey.isEmpty()) {
        byte[] srcBytes = authKey.trim().getBytes();
        if (authKey.length() == 34 && authKey.substring(0, 2).equals("0x")) {
            srcBytes = HexDump.hexStringToByteArray(authKey.substring(2));
        } else srcBytes = HexDump.hexStringToByteArray(authKey);
        System.arraycopy(srcBytes, 0, localKey, 0, Math.min(srcBytes.length, 16));
    }
}
 
Example #19
Source File: PendiqService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void enableNotification() {
    UserError.Log.d(TAG, "Enabling notifications");
    connection.setupNotification(INCOMING_CHAR)
            // .timeout(10, TimeUnit.SECONDS)
            .timeout(15, TimeUnit.SECONDS) // WARN
            //.observeOn(Schedulers.newThread()) // needed?
            .doOnNext(notificationObservable -> {
                JoH.threadSleep(1000);
                changeState(GET_STATUS);
            }).flatMap(notificationObservable -> notificationObservable)
            //.timeout(5, TimeUnit.SECONDS)
            .observeOn(Schedulers.newThread())
            .subscribe(bytes -> {
                        // incoming notifications
                        if (d)
                            UserError.Log.d(TAG, "Received data notification bytes: " + HexDump.dumpHexString(bytes));

                        processAndAction(bytes);

                    }, throwable -> {
                        if (!(throwable instanceof TimeoutException)) {
                            UserError.Log.e(TAG, "Throwable inside setup notification: " + throwable);
                        } else {
                            UserError.Log.d(TAG, "OUTER TIMEOUT INSIDE NOTIFICATION LISTENER");
                        }
                        stopConnect();
                    }
            );

}
 
Example #20
Source File: Home.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void HebrewAppendDisplayData() {
    // Do the append for the hebrew language
    String original_text = notificationText.getText().toString();
    Log.d(TAG, "original_text = " + HexDump.dumpHexString(original_text.getBytes()));
    if (original_text.length() >= 1 && original_text.charAt(0) == 0x0a) {
        Log.d(TAG, "removing first and appending " + display_delta);
        notificationText.setText(display_delta + "  " + original_text.substring(1));
    } else {
        notificationText.setText(display_delta + "  " + original_text);
    }
}
 
Example #21
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {

    final PowerManager.WakeLock wakeLock1 = JoH.getWakeLock("DexCollectionService", 60000);
    try {
        final byte[] data = characteristic.getValue();

        if (data != null && data.length > 0) {
            setSerialDataToTransmitterRawData(data, data.length);

            final String hexdump = HexDump.dumpHexString(data);
            //if (!hexdump.contains("0x00000000 00      ")) {
            if (data.length > 1 || data[0] != 0x00) {
                static_last_hexdump = hexdump;
            }
            if (d) Log.i(TAG, "onCharacteristicChanged entered " + hexdump);

        }
        lastdata = data;

        Inevitable.task("dex-set-failover", 1000, () -> {
            setFailoverTimer(); // restart the countdown
            // intentionally left hanging wakelock for 5 seconds after we receive something
            final PowerManager.WakeLock wakeLock2 = JoH.getWakeLock("DexCollectionLinger", 5000);
        });

    } finally {
       /* if (Pref.getBoolean("bluetooth_frequent_reset", false)) {
            Log.e(TAG, "Resetting bluetooth due to constant reset option being set!");
            JoH.restartBluetooth(getApplicationContext(), 5000);
        }*/
        JoH.releaseWakeLock(wakeLock1);
    }
}
 
Example #22
Source File: InPenService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processRecordsQueue() {
    boolean newRecord = false;
    while (!records.isEmpty()) {
        final byte[] record = records.poll();
        if (record != null) {
            final RecordRx recordRx = new RecordRx(currentPenTime).fromBytes(record);
            if (recordRx != null) {
                UserError.Log.d(TAG, "RECORD RECORD: " + recordRx.toS());
                final PenData penData = PenData.create(I.address, ID_INPEN, recordRx.index, recordRx.units, recordRx.getRealTimeStamp(), recordRx.temperature, record);
                if (penData == null) {
                    UserError.Log.wtf(TAG, "Error creating PenData record from " + HexDump.dumpHexString(record));
                } else {
                    penData.battery = recordRx.battery;
                    penData.flags = recordRx.flags;
                    UserError.Log.d(TAG, "Saving Record index: " + penData.index);
                    penData.save();
                    newRecord = true;
                    gotIndex = (int) penData.index;
                    gotAll = lastIndex == gotIndex;
                    if (InPen.soundsEnabled() && JoH.ratelimit("pen_data_in", 1)) {
                        JoH.playResourceAudio(R.raw.bt_meter_data_in);
                    }
                    lastPenData = penData;
                }
            } else {
                UserError.Log.e(TAG, "Error creating record from: " + HexDump.dumpHexString(record));
            }
        }
    }
    if (newRecord) {
        Inevitable.task("process-inpen-data", 1000, ProcessPenData::process);
    }
}
 
Example #23
Source File: RouterFinderTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void validResponse(String subroute, WebResponse response) {
    assertWithMessage(subroute + " instance null data response")
            .that(response)
            .isNotNull();

    log("\n\n" + subroute + " Result code: " + response.resultCode);
    log(HexDump.dumpHexString(response.bytes));

    assertWithMessage(subroute + " result code")
            .that(response.resultCode)
            .isEqualTo(200);
    assertWithMessage(subroute + " instance data length")
            .that(response.bytes.length)
            .isAtLeast(1);
}
 
Example #24
Source File: RouterFinderTest.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void validResponse(String subroute, WebResponse response) {
    assertWithMessage(subroute + " instance null data response")
            .that(response)
            .isNotNull();

    log("\n\n" + subroute + " Result code: " + response.resultCode);
    log(HexDump.dumpHexString(response.bytes));

    assertWithMessage(subroute + " result code")
            .that(response.resultCode)
            .isEqualTo(200);
    assertWithMessage(subroute + " instance data length")
            .that(response.bytes.length)
            .isAtLeast(1);
}
 
Example #25
Source File: InPenService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processRecordsQueue() {
    boolean newRecord = false;
    while (!records.isEmpty()) {
        final byte[] record = records.poll();
        if (record != null) {
            final RecordRx recordRx = new RecordRx(currentPenTime).fromBytes(record);
            if (recordRx != null) {
                UserError.Log.d(TAG, "RECORD RECORD: " + recordRx.toS());
                final PenData penData = PenData.create(I.address, ID_INPEN, recordRx.index, recordRx.units, recordRx.getRealTimeStamp(), recordRx.temperature, record);
                if (penData == null) {
                    UserError.Log.wtf(TAG, "Error creating PenData record from " + HexDump.dumpHexString(record));
                } else {
                    penData.battery = recordRx.battery;
                    penData.flags = recordRx.flags;
                    UserError.Log.d(TAG, "Saving Record index: " + penData.index);
                    penData.save();
                    newRecord = true;
                    gotIndex = (int) penData.index;
                    gotAll = lastIndex == gotIndex;
                    if (InPen.soundsEnabled() && JoH.ratelimit("pen_data_in", 1)) {
                        JoH.playResourceAudio(R.raw.bt_meter_data_in);
                    }
                    lastPenData = penData;
                }
            } else {
                UserError.Log.e(TAG, "Error creating record from: " + HexDump.dumpHexString(record));
            }
        }
    }
    if (newRecord) {
        Inevitable.task("process-inpen-data", 1000, ProcessPenData::process);
    }
}
 
Example #26
Source File: Home.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void HebrewAppendDisplayData() {
    // Do the append for the hebrew language
    String original_text = notificationText.getText().toString();
    Log.d(TAG, "original_text = " + HexDump.dumpHexString(original_text.getBytes()));
    if (original_text.length() >= 1 && original_text.charAt(0) == 0x0a) {
        Log.d(TAG, "removing first and appending " + display_delta);
        notificationText.setText(display_delta + "  " + original_text.substring(1));
    } else {
        notificationText.setText(display_delta + "  " + original_text);
    }
}
 
Example #27
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {

    final PowerManager.WakeLock wakeLock1 = JoH.getWakeLock("DexCollectionService", 60000);
    try {
        final byte[] data = characteristic.getValue();

        if (data != null && data.length > 0) {
            setSerialDataToTransmitterRawData(data, data.length);

            final String hexdump = HexDump.dumpHexString(data);
            //if (!hexdump.contains("0x00000000 00      ")) {
            if (data.length > 1 || data[0] != 0x00) {
                static_last_hexdump = hexdump;
            }
            if (d) Log.i(TAG, "onCharacteristicChanged entered " + hexdump);

        }
        lastdata = data;

        Inevitable.task("dex-set-failover", 1000, () -> {
            setFailoverTimer(); // restart the countdown
            // intentionally left hanging wakelock for 5 seconds after we receive something
            final PowerManager.WakeLock wakeLock2 = JoH.getWakeLock("DexCollectionLinger", 5000);
        });

    } finally {
       /* if (Pref.getBoolean("bluetooth_frequent_reset", false)) {
            Log.e(TAG, "Resetting bluetooth due to constant reset option being set!");
            JoH.restartBluetooth(getApplicationContext(), 5000);
        }*/
        JoH.releaseWakeLock(wakeLock1);
    }
}
 
Example #28
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {

    final PowerManager.WakeLock wakeLock1 = JoH.getWakeLock("DexCollectionService", 60000);
    try {
        final byte[] data = characteristic.getValue();

        if (data != null && data.length > 0) {
            setSerialDataToTransmitterRawData(data, data.length);

            final String hexdump = HexDump.dumpHexString(data);
            //if (!hexdump.contains("0x00000000 00      ")) {
            if (data.length > 1 || data[0] != 0x00) {
                static_last_hexdump = hexdump;
            }
            if (d) Log.i(TAG, "onCharacteristicChanged entered " + hexdump);

        }
        lastdata = data;

        Inevitable.task("dex-set-failover", 1000, () -> {
            setFailoverTimer(); // restart the countdown
            // intentionally left hanging wakelock for 5 seconds after we receive something
            final PowerManager.WakeLock wakeLock2 = JoH.getWakeLock("DexCollectionLinger", 5000);
        });

    } finally {
       /* if (Pref.getBoolean("bluetooth_frequent_reset", false)) {
            Log.e(TAG, "Resetting bluetooth due to constant reset option being set!");
            JoH.restartBluetooth(getApplicationContext(), 5000);
        }*/
        JoH.releaseWakeLock(wakeLock1);
    }
}
 
Example #29
Source File: AuthMessages.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public AuthMessages(MiBand.MiBandType mibandType, String authKey) {
    if (mibandType == MiBand.MiBandType.MI_BAND4) {
        cryptFlags = OperationCodes.AUTH_MIBAND4_CRYPT_FLAG;
    }
    localKey = CipherUtils.getRandomKey();
    if (authKey != null && !authKey.isEmpty()) {
        byte[] srcBytes = authKey.trim().getBytes();
        if (authKey.length() == 34 && authKey.substring(0, 2).equals("0x")) {
            srcBytes = HexDump.hexStringToByteArray(authKey.substring(2));
        } else srcBytes = HexDump.hexStringToByteArray(authKey);
        System.arraycopy(srcBytes, 0, localKey, 0, Math.min(srcBytes.length, 16));
    }
}
 
Example #30
Source File: BlueJayService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void sendGlucose() {
    val last = BgReading.last();
    if (last != null && msSince(last.timestamp) < Constants.HOUR_IN_MS) {
        val info = BlueJayInfo.getInfo(BlueJay.getMac());
        if (Math.abs(info.lastReadingTime - last.timestamp) > Constants.MINUTE_IN_MS * 3) {
            val glucoseTx = new GlucoseTx(last);
            if (glucoseTx.isValid()) {
                val item = new QueueMe()
                        .setBytes(glucoseTx.getBytes())
                        .expireInSeconds(60)
                        .setDescription("Glucose to watch");

                item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) {
                    @Override
                    public void process(byte[] bytes) {
                        UserError.Log.d(TAG, "Glucose Incoming reply processor: " + HexDump.dumpHexString(bytes));
                        info.displayUpdated();
                    }
                }).setTag(item));

                item.queue();
                doQueue();
            } else {
                UserError.Log.d(TAG, "GlucoseTX wasn't valid so not sending.");
            }
        } else {
            UserError.Log.d(TAG, "Watch already has recent reading");
            // watch reading too close to the reading we were going to send
        }
    }
}