From c04f9161f0be7e8ac128e93626e1ea3ac85f382f Mon Sep 17 00:00:00 2001 From: Apres Antonyan Date: Mon, 5 Jul 2021 14:50:31 +0400 Subject: [PATCH 1/4] add atom support --- .../eveningoutpost/dexdrip/Models/Atom.java | 182 ++++++++++++++++++ .../dexdrip/Models/LibreBlock.java | 4 + .../Services/DexCollectionService.java | 41 +++- app/src/main/res/values-de/strings-de.xml | 1 + app/src/main/res/values-es/strings-es.xml | 1 + app/src/main/res/values-fr/strings-fr.xml | 1 + app/src/main/res/values-he/strings-he.xml | 1 + app/src/main/res/values-it/strings-it.xml | 1 + app/src/main/res/values-nl/strings-nl.xml | 1 + app/src/main/res/values-pt/strings-pt.xml | 1 + app/src/main/res/values-ru/strings-ru.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../eveningoutpost/dexdrip/Models/Atom.java | 173 +++++++++++++++++ .../Services/DexCollectionService.java | 41 +++- wear/src/main/res/values/strings.xml | 1 + 15 files changed, 447 insertions(+), 4 deletions(-) create mode 100755 app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java create mode 100644 wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java b/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java new file mode 100755 index 0000000000..f7e2c097ec --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java @@ -0,0 +1,182 @@ +package com.eveningoutpost.dexdrip.Models; + +import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.NFCReaderX; +import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.UtilityModels.BridgeResponse; +import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; +import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.UtilityModels.Pref; + +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; + +import static com.eveningoutpost.dexdrip.xdrip.gs; + +/** + * + */ + +public class Atom { + private static final String TAG = "Atom";//?????"Atom"; + + private static volatile byte[] s_full_data = null; + private static volatile int s_acumulatedSize = 0; + + public static boolean isAtom() { + final ActiveBluetoothDevice activeBluetoothDevice = ActiveBluetoothDevice.first(); + if (activeBluetoothDevice == null || activeBluetoothDevice.name == null) { + return false; + } + return activeBluetoothDevice.name.contentEquals("Atom"); + } + + + public static BridgeResponse getAtomResponse() { + final BridgeResponse reply = new BridgeResponse(); + ByteBuffer ackMessage = ByteBuffer.allocate(6); + ackMessage.put(0, (byte) 0x02); + ackMessage.put(1, (byte) 0x01); + ackMessage.put(2, (byte) 0x00); + ackMessage.put(3, (byte) 0x00); + ackMessage.put(4, (byte) 0x00); + ackMessage.put(5, (byte) 0x2B); + reply.add(ackMessage); + return reply; + } + + public static int lens = 344; + public static int ATOM_FOOTER = 8; + + static int errorCount = 0; + + + static byte[] patchUid = null; + static byte[] patchInfo = null; + + public static BridgeResponse decodeAtomPacket(byte[] buffer, int len) { + final BridgeResponse reply = new BridgeResponse(); + int first = 0xff & buffer[0]; + if (first == 0x80) { + PersistentStore.setString("Atombattery", Integer.toString(buffer[4])); + Pref.setInt("bridge_battery", buffer[4]); + String atomfirmware = buffer[2] + "." + buffer[3]; + String atomHArdware = buffer[buffer.length-2] + "." + buffer[buffer.length-1]; + PersistentStore.setString("AtomHArdware", atomHArdware); + PersistentStore.setString("AtomFirmware", atomfirmware); + ByteBuffer ackMessage = ByteBuffer.allocate(6); + ackMessage.put(0, (byte) 0x02); + ackMessage.put(1, (byte) 0x01); + ackMessage.put(2, (byte) 0x00); + ackMessage.put(3, (byte) 0x00); + ackMessage.put(4, (byte) 0x00); + ackMessage.put(5, (byte) 0x2B); + reply.add(ackMessage); + s_full_data = null; + return getAtomResponse(); + } + if (first == 0xC0) { + patchUid = Arrays.copyOfRange(buffer, 2, 10); + String SensorSn = LibreUtils.decodeSerialNumberKey(patchUid); + PersistentStore.setString("LibreSN", SensorSn); + + if (SensorSanity.checkLibreSensorChangeIfEnabled(SensorSn)) { + Log.e(TAG, "Problem with Libre Serial Number - not processing"); + } + + return reply; + } + if (first == 0xC1) { + double fv = JoH.tolerantParseDouble(PersistentStore.getString("AtomFirmware")); + if (fv < 1.35) { + patchInfo = Arrays.copyOfRange(buffer, 3, 9); + } else { + if (buffer.length >= 11) { + patchInfo = Arrays.copyOfRange(buffer, 5, 11); + } + } + return reply; + } + if (first == 0x82) { + int expectedSize = lens + ATOM_FOOTER; + if (s_full_data == null) { + InitBuffer(expectedSize); + } + addData(buffer); + return reply; + + } + + if (first == 0xBF) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Log.e(TAG, "No sensor has been found"); + reply.setError_message(gs(R.string.no_sensor_found)); + s_full_data = null; + errorCount++; + if (errorCount <= 2) { + return getAtomResponse(); + } + return reply; + } + + + return reply; + } + + + static void addData(byte[] buffer) { + System.arraycopy(buffer, 4, s_full_data, s_acumulatedSize, buffer.length-4); + s_acumulatedSize = s_acumulatedSize + buffer.length - 4; + AreWeDone(); + } + + + 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, Constants.LIBRE_1_2_FRAM_SIZE); + + // Set the time of the current reading + PersistentStore.setLong("libre-reading-timestamp", JoH.tsl()); + + boolean checksum_ok = NFCReaderX.HandleGoodReading(SensorSn, data, now, true, patchUid, patchInfo); + int expectedSize = lens + ATOM_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)); + + } + + + static void InitBuffer(int expectedSize) { + s_full_data = new byte[expectedSize]; + s_acumulatedSize = 0; + } + + public static ArrayList initialize() { + Log.e(TAG, "initialize!"); + Pref.setInt("bridge_battery", 0); //force battery to no-value before first reading + return resetAtomState(); + } + + private static ArrayList resetAtomState() { + ArrayList ret = new ArrayList<>(); + + // Make Atom send data every 5 minutes + ByteBuffer ackMessage = ByteBuffer.allocate(3); + ackMessage.put(0, (byte) 0x00); + ackMessage.put(1, (byte) 0x01); + ackMessage.put(2, (byte) 0x05); + ret.add(ackMessage); + return ret; + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBlock.java b/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBlock.java index 0221cb22a6..2cee287b17 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBlock.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBlock.java @@ -253,6 +253,8 @@ class ExtendedLibreBlock { @Expose public int Bubblebattery; @Expose + public int Atombattery; + @Expose public int nfc_sensor_age; @Expose public LibreBlock libreBlock; @@ -263,6 +265,7 @@ public String toExtendedJson() { elb.bridge_battery = Pref.getInt("bridge_battery", 0); elb.Tomatobattery = PersistentStore.getStringToInt("Tomatobattery", 0); elb.Bubblebattery = PersistentStore.getStringToInt("Bubblebattery", 0); + elb.Atombattery = PersistentStore.getStringToInt("Atombattery", 0); elb.nfc_sensor_age = Pref.getInt("nfc_sensor_age", 0); elb.libreBlock = this; return JoH.defaultGsonInstance().toJson(elb); @@ -284,6 +287,7 @@ public static LibreBlock createFromExtendedJson(String json) { Pref.setInt("bridge_battery", elb.bridge_battery); PersistentStore.setString("Tomatobattery", Integer.toString(elb.Tomatobattery)); PersistentStore.setString("Bubblebattery", Integer.toString(elb.Bubblebattery)); + PersistentStore.setString("Atombattery", Integer.toString(elb.Atombattery)); Pref.setInt("nfc_sensor_age", elb.nfc_sensor_age); return elb.libreBlock; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java index 5c30e46968..803140f580 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java @@ -44,6 +44,7 @@ import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.Models.Atom; import com.eveningoutpost.dexdrip.Models.BgReading; import com.eveningoutpost.dexdrip.Models.Bubble; import com.eveningoutpost.dexdrip.Models.JoH; @@ -405,7 +406,7 @@ public synchronized void onServicesDiscovered(BluetoothGatt gatt, int status) { final BluetoothGattService gattService = mBluetoothGatt.getService(xDripDataService); if (gattService == null) { - if (!(static_use_blukon || blueReader.isblueReader() || Tomato.isTomato()||Bubble.isBubble() || LibreBluetooth.isLibreBluettoh())) { + if (!(static_use_blukon || blueReader.isblueReader() || Tomato.isTomato()||Bubble.isBubble()||Atom.isAtom() || LibreBluetooth.isLibreBluettoh())) { Log.w(TAG, "onServicesDiscovered: xdrip service " + xDripDataService + " not found"); //TODO the selection of nrf is not active at the beginning,so this error will be trown one time unneeded, mey to be optimized. // TODO this should be reworked to be an efficient selector listAvailableServices(mBluetoothGatt); @@ -533,6 +534,22 @@ public void run() { } }); + servicesDiscovered = DISCOVERED.NULL; // reset this state + }else if (Atom.isAtom()) { + status("Enabled atom"); + Log.d(TAG, "Queueing atom initialization.."); + Inevitable.task("initialize-atom", 4000, new Runnable() { + @Override + public void run() { + final List buffers = Atom.initialize(); + for (ByteBuffer buffer : buffers) { + sendBtMessage(buffer); + JoH.threadSleep(150); + } + Log.d(TAG, "atom initialized and data requested"); + } + }); + servicesDiscovered = DISCOVERED.NULL; // reset this state } } @@ -901,6 +918,8 @@ public static String getBestLimitterHardwareName() { return xdrip.getAppContext().getString(R.string.tomato); } else if (static_use_nrf && Bubble.isBubble()) { return xdrip.getAppContext().getString(R.string.bubble); + }else if (static_use_nrf && Atom.isAtom()) { + return xdrip.getAppContext().getString(R.string.atom); } else if (static_use_blukon) { return xdrip.getAppContext().getString(R.string.blukon); } else if (static_use_transmiter_pl_bluetooth) { @@ -1099,7 +1118,12 @@ public void run() { l.add(new StatusItem("Bubble Firmware", PersistentStore.getString("BubbleFirmware"))); l.add(new StatusItem("Libre SN", PersistentStore.getString("LibreSN"))); } - + if (Atom.isAtom()) { + l.add(new StatusItem("Atom Battery", PersistentStore.getString("Atombattery"))); + l.add(new StatusItem("Atom Hardware", PersistentStore.getString("AtomHArdware"))); + l.add(new StatusItem("Atom Firmware", PersistentStore.getString("AtomFirmware"))); + l.add(new StatusItem("Libre SN", PersistentStore.getString("LibreSN"))); + } if (static_use_blukon) { l.add(new StatusItem("Battery", Pref.getInt("bridge_battery", 0) + "%")); l.add(new StatusItem("Sensor age", JoH.qs(((double) Pref.getInt("nfc_sensor_age", 0)) / 1440, 1) + "d")); @@ -1719,6 +1743,19 @@ public synchronized void setSerialDataToTransmitterRawData(byte[] buffer, int le } gotValidPacket(); + }else if (Atom.isAtom()) { + final BridgeResponse reply = Atom.decodeAtomPacket(buffer, len); + if (reply.shouldDelay()) { + Inevitable.task("send-atom-reply", reply.getDelay(), () -> sendReply(reply)); + } else { + sendReply(reply); + } + if (reply.hasError()) { + JoH.static_toast_long(reply.getError_message()); + error(reply.getError_message()); + } + gotValidPacket(); + } else if (LibreBluetooth.isLibreBluettoh()) { final BridgeResponse reply = LibreBluetooth.decodeLibrePacket(buffer, len); if (reply.shouldDelay()) { diff --git a/app/src/main/res/values-de/strings-de.xml b/app/src/main/res/values-de/strings-de.xml index 9382c8ea01..82a7172a1d 100644 --- a/app/src/main/res/values-de/strings-de.xml +++ b/app/src/main/res/values-de/strings-de.xml @@ -848,6 +848,7 @@ BluCon Tomato Bubble + Atom Verwende Schwerkraftsensor um Ansicht zu drehen Niedrige Transmitter Batterie Erinnerungen diff --git a/app/src/main/res/values-es/strings-es.xml b/app/src/main/res/values-es/strings-es.xml index 87354c08c7..ac121dd766 100644 --- a/app/src/main/res/values-es/strings-es.xml +++ b/app/src/main/res/values-es/strings-es.xml @@ -848,6 +848,7 @@ Blucon Tomato Bubble + Atom Usa el Sensor de Gravedad para rotar items Bateria baja bridge Recordatorios diff --git a/app/src/main/res/values-fr/strings-fr.xml b/app/src/main/res/values-fr/strings-fr.xml index 991e8dc763..bbf52b1040 100644 --- a/app/src/main/res/values-fr/strings-fr.xml +++ b/app/src/main/res/values-fr/strings-fr.xml @@ -848,6 +848,7 @@ Blucon Tomato Bubble + Atom Utiliser le capteur de gravité pour faire pivoter les éléments Batterie transmetteur faible Rappels diff --git a/app/src/main/res/values-he/strings-he.xml b/app/src/main/res/values-he/strings-he.xml index 4d24f91c12..797bb35cf2 100644 --- a/app/src/main/res/values-he/strings-he.xml +++ b/app/src/main/res/values-he/strings-he.xml @@ -843,6 +843,7 @@ BluCon מיאומיאו Bubble + Atom השתמש בחיישן כח המשיכה כדי לסובב פריטים סוללת מכשיר גישור נמוכה תזכורות diff --git a/app/src/main/res/values-it/strings-it.xml b/app/src/main/res/values-it/strings-it.xml index d6a1b7ccae..4c40e8ad18 100644 --- a/app/src/main/res/values-it/strings-it.xml +++ b/app/src/main/res/values-it/strings-it.xml @@ -848,6 +848,7 @@ Blucon Miaomiao Bubble + Atom Usa il sensore gravità per ruotare gli elementi Batteria bridge bassa Promemoria diff --git a/app/src/main/res/values-nl/strings-nl.xml b/app/src/main/res/values-nl/strings-nl.xml index fc51a3c37b..ec75c65ee3 100644 --- a/app/src/main/res/values-nl/strings-nl.xml +++ b/app/src/main/res/values-nl/strings-nl.xml @@ -848,6 +848,7 @@ Blucon Tomato Bubble + Atom Gebruik de zwaartekrachtsensor om items te roteren Lage zenderbatterij Herinneringen diff --git a/app/src/main/res/values-pt/strings-pt.xml b/app/src/main/res/values-pt/strings-pt.xml index d8b96a32e3..77a545993f 100644 --- a/app/src/main/res/values-pt/strings-pt.xml +++ b/app/src/main/res/values-pt/strings-pt.xml @@ -847,6 +847,7 @@ Blucon Tomato Bubble + Atom Usar Sensor Gravidade para rodar Bridge bateria fraca Lembretes diff --git a/app/src/main/res/values-ru/strings-ru.xml b/app/src/main/res/values-ru/strings-ru.xml index 5a669923c7..ebfe3e7952 100644 --- a/app/src/main/res/values-ru/strings-ru.xml +++ b/app/src/main/res/values-ru/strings-ru.xml @@ -847,6 +847,7 @@ Blucon Tomato Bubble + Atom Использовать гироскоп для ориентации Низкий уровень заряда трансмиттера Напоминания diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba1403127b..bdc49e8dfa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -880,6 +880,7 @@ BluCon Tomato Bubble + Atom Use Gravity Sensor to rotate items Low bridge battery Reminders diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java new file mode 100644 index 0000000000..4086366883 --- /dev/null +++ b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java @@ -0,0 +1,173 @@ +package com.eveningoutpost.dexdrip.Models; + +import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.NFCReaderX; +import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.UtilityModels.BridgeResponse; +import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; +import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.UtilityModels.Pref; + +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; + +import static com.eveningoutpost.dexdrip.xdrip.gs; + +/** + * + */ + +public class Atom { + private static final String TAG = "Atom";//?????; + + private static volatile byte[] s_full_data = null; + private static volatile int s_acumulatedSize = 0; + + public static boolean isAtom() { + final ActiveBluetoothDevice activeBluetoothDevice = ActiveBluetoothDevice.first(); + if (activeBluetoothDevice == null || activeBluetoothDevice.name == null) { + return false; + } + return activeBluetoothDevice.name.contentEquals("Atom"); + } + + + public static BridgeResponse getAtomResponse() { + final BridgeResponse reply = new BridgeResponse(); + ByteBuffer ackMessage = ByteBuffer.allocate(6); + ackMessage.put(0, (byte) 0x02); + ackMessage.put(1, (byte) 0x01); + ackMessage.put(2, (byte) 0x00); + ackMessage.put(3, (byte) 0x00); + ackMessage.put(4, (byte) 0x00); + ackMessage.put(5, (byte) 0x2B); + reply.add(ackMessage); + return reply; + } + + public static int lens = 344; + public static int ATOM_FOOTER = 8; + + static int errorCount = 0; + + + static byte[] patchUid = null; + static byte[] patchInfo = null; + + public static BridgeResponse decodeAtomPacket(byte[] buffer, int len) { + final BridgeResponse reply = new BridgeResponse(); + int first = 0xff & buffer[0]; + if (first == 0x80) { + PersistentStore.setString("Atombattery", Integer.toString(buffer[4])); + Pref.setInt("bridge_battery", buffer[4]); + String atomfirmware = buffer[2] + "." + buffer[3]; + String atomHArdware = buffer[buffer.length-2] + "." + buffer[buffer.length-1]; + PersistentStore.setString("AtomHArdware", atomHArdware); + PersistentStore.setString("AtomFirmware", atomfirmware); + ByteBuffer ackMessage = ByteBuffer.allocate(6); + ackMessage.put(0, (byte) 0x02); + ackMessage.put(1, (byte) 0x01); + ackMessage.put(2, (byte) 0x00); + ackMessage.put(3, (byte) 0x00); + ackMessage.put(4, (byte) 0x00); + ackMessage.put(5, (byte) 0x2B); + reply.add(ackMessage); + s_full_data = null; + return getAtomResponse(); + } + if (first == 0xC0) { + patchUid = Arrays.copyOfRange(buffer, 2, 10); + String SensorSn = LibreUtils.decodeSerialNumberKey(patchUid); + PersistentStore.setString("LibreSN", SensorSn); + return reply; + } + if (first == 0xC1) { + double fv = JoH.tolerantParseDouble(PersistentStore.getString("AtomFirmware")); + if (fv < 1.35) { + patchInfo = Arrays.copyOfRange(buffer, 3, 9); + } else { + if (buffer.length >= 11) { + patchInfo = Arrays.copyOfRange(buffer, 5, 11); + } + } + return reply; + } + if (first == 0x82) { + int expectedSize = lens + ATOM_FOOTER; + if (s_full_data == null) { + InitBuffer(expectedSize); + } + addData(buffer); + return reply; + + } + + if (first == 0xBF) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Log.e(TAG, "No sensor has been found"); + reply.setError_message(gs(R.string.no_sensor_found)); + s_full_data = null; + errorCount++; + if (errorCount <= 2) { + return getAtomResponse(); + } + return reply; + } + + + return reply; + } + + + static void addData(byte[] buffer) { + System.arraycopy(buffer, 4, s_full_data, s_acumulatedSize, buffer.length-4); + s_acumulatedSize = s_acumulatedSize + buffer.length - 4; + AreWeDone(); + } + + + 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 + ATOM_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)); + + } + + + static void InitBuffer(int expectedSize) { + s_full_data = new byte[expectedSize]; + s_acumulatedSize = 0; + } + + public static ArrayList initialize() { + Log.e(TAG, "initialize!"); + Pref.setInt("bridge_battery", 0); //force battery to no-value before first reading + return resetAtomState(); + } + + private static ArrayList resetAtomState() { + ArrayList ret = new ArrayList<>(); + + // Make Atom send data every 5 minutes + ByteBuffer ackMessage = ByteBuffer.allocate(3); + ackMessage.put(0, (byte) 0x00); + ackMessage.put(1, (byte) 0x01); + ackMessage.put(2, (byte) 0x05); + ret.add(ackMessage); + return ret; + } +} diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java b/wear/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java index 73fcd039ac..550e724cae 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java +++ b/wear/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java @@ -44,6 +44,7 @@ import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.Models.Atom; import com.eveningoutpost.dexdrip.Models.BgReading; import com.eveningoutpost.dexdrip.Models.Bubble; import com.eveningoutpost.dexdrip.Models.JoH; @@ -400,7 +401,7 @@ public synchronized void onServicesDiscovered(BluetoothGatt gatt, int status) { final BluetoothGattService gattService = mBluetoothGatt.getService(xDripDataService); if (gattService == null) { - if (!(static_use_blukon || blueReader.isblueReader() || Tomato.isTomato()||Bubble.isBubble())) { + if (!(static_use_blukon || blueReader.isblueReader() || Tomato.isTomato()||Bubble.isBubble()||Atom.isAtom())) { Log.w(TAG, "onServicesDiscovered: xdrip service " + xDripDataService + " not found"); //TODO the selection of nrf is not active at the beginning,so this error will be trown one time unneeded, mey to be optimized. // TODO this should be reworked to be an efficient selector listAvailableServices(mBluetoothGatt); @@ -528,6 +529,22 @@ public void run() { } }); + servicesDiscovered = DISCOVERED.NULL; // reset this state + }else if (Atom.isAtom()) { + status("Enabled atom"); + Log.d(TAG, "Queueing atom initialization.."); + Inevitable.task("initialize-atom", 4000, new Runnable() { + @Override + public void run() { + final List buffers = Atom.initialize(); + for (ByteBuffer buffer : buffers) { + sendBtMessage(buffer); + JoH.threadSleep(150); + } + Log.d(TAG, "atom initialized and data requested"); + } + }); + servicesDiscovered = DISCOVERED.NULL; // reset this state } } @@ -854,6 +871,8 @@ public static String getBestLimitterHardwareName() { return xdrip.getAppContext().getString(R.string.tomato); } else if (static_use_nrf && Bubble.isBubble()) { return xdrip.getAppContext().getString(R.string.bubble); + } else if (static_use_nrf && Atom.isAtom()) { + return xdrip.getAppContext().getString(R.string.atom); } else if (static_use_blukon) { return xdrip.getAppContext().getString(R.string.blukon); } else if (static_use_transmiter_pl_bluetooth) { @@ -1052,7 +1071,12 @@ public void run() { l.add(new StatusItem("Bubble Firmware", PersistentStore.getString("BubbleFirmware"))); l.add(new StatusItem("Libre SN", PersistentStore.getString("LibreSN"))); } - + if (Atom.isAtom()) { + l.add(new StatusItem("Atom Battery", PersistentStore.getString("Atombattery"))); + l.add(new StatusItem("Atom Hardware", PersistentStore.getString("AtomHArdware"))); + l.add(new StatusItem("Atom Firmware", PersistentStore.getString("AtomFirmware"))); + l.add(new StatusItem("Libre SN", PersistentStore.getString("LibreSN"))); + } if (static_use_blukon) { l.add(new StatusItem("Battery", Pref.getInt("bridge_battery", 0) + "%")); l.add(new StatusItem("Sensor age", JoH.qs(((double) Pref.getInt("nfc_sensor_age", 0)) / 1440, 1) + "d")); @@ -1659,6 +1683,19 @@ public synchronized void setSerialDataToTransmitterRawData(byte[] buffer, int le } gotValidPacket(); + }else if (Atom.isAtom()) { + final BridgeResponse reply = Atom.decodeAtomPacket(buffer, len); + if (reply.shouldDelay()) { + Inevitable.task("send-atom-reply", reply.getDelay(), () -> sendReply(reply)); + } else { + sendReply(reply); + } + if (reply.hasError()) { + JoH.static_toast_long(reply.getError_message()); + error(reply.getError_message()); + } + gotValidPacket(); + } else if (XbridgePlus.isXbridgeExtensionPacket(buffer)) { // handle xBridge+ protocol packets final byte[] reply = XbridgePlus.decodeXbridgeExtensionPacket(buffer); diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index 77d0aa648b..ef81420824 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -205,6 +205,7 @@ Enable Permission Tomato Bubble + Atom " Minutes ago" " Minute ago" Snooze Alert From 774c96535c91557ddd25fd2d230f873b2102cac0 Mon Sep 17 00:00:00 2001 From: Apres Antonyan Date: Thu, 15 Jul 2021 18:50:41 +0400 Subject: [PATCH 2/4] removed unused variable in Atom.java --- app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java | 1 - wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java b/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java index f7e2c097ec..f6ccfa7361 100755 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java @@ -112,7 +112,6 @@ public static BridgeResponse decodeAtomPacket(byte[] buffer, int len) { } if (first == 0xBF) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Log.e(TAG, "No sensor has been found"); reply.setError_message(gs(R.string.no_sensor_found)); s_full_data = null; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java index 4086366883..c89c72d5c0 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java +++ b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java @@ -98,7 +98,7 @@ public static BridgeResponse decodeAtomPacket(byte[] buffer, int len) { if (first == 0x82) { int expectedSize = lens + ATOM_FOOTER; if (s_full_data == null) { - InitBuffer(expectedSize); + InitBuffer(expectedSize) } addData(buffer); return reply; @@ -106,7 +106,6 @@ public static BridgeResponse decodeAtomPacket(byte[] buffer, int len) { } if (first == 0xBF) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Log.e(TAG, "No sensor has been found"); reply.setError_message(gs(R.string.no_sensor_found)); s_full_data = null; From ebe4d9b51c95b84da973e1f41023fff55bcde3e8 Mon Sep 17 00:00:00 2001 From: Apres Antonyan Date: Sat, 21 Aug 2021 16:11:38 +0400 Subject: [PATCH 3/4] removed unnecessary translation changes --- app/src/main/res/values-de/strings-de.xml | 1 - app/src/main/res/values-es/strings-es.xml | 1 - app/src/main/res/values-fr/strings-fr.xml | 1 - app/src/main/res/values-he/strings-he.xml | 1 - app/src/main/res/values-it/strings-it.xml | 1 - app/src/main/res/values-nl/strings-nl.xml | 1 - app/src/main/res/values-pt/strings-pt.xml | 1 - app/src/main/res/values-ru/strings-ru.xml | 1 - 8 files changed, 8 deletions(-) diff --git a/app/src/main/res/values-de/strings-de.xml b/app/src/main/res/values-de/strings-de.xml index 82a7172a1d..9382c8ea01 100644 --- a/app/src/main/res/values-de/strings-de.xml +++ b/app/src/main/res/values-de/strings-de.xml @@ -848,7 +848,6 @@ BluCon Tomato Bubble - Atom Verwende Schwerkraftsensor um Ansicht zu drehen Niedrige Transmitter Batterie Erinnerungen diff --git a/app/src/main/res/values-es/strings-es.xml b/app/src/main/res/values-es/strings-es.xml index ac121dd766..87354c08c7 100644 --- a/app/src/main/res/values-es/strings-es.xml +++ b/app/src/main/res/values-es/strings-es.xml @@ -848,7 +848,6 @@ Blucon Tomato Bubble - Atom Usa el Sensor de Gravedad para rotar items Bateria baja bridge Recordatorios diff --git a/app/src/main/res/values-fr/strings-fr.xml b/app/src/main/res/values-fr/strings-fr.xml index bbf52b1040..991e8dc763 100644 --- a/app/src/main/res/values-fr/strings-fr.xml +++ b/app/src/main/res/values-fr/strings-fr.xml @@ -848,7 +848,6 @@ Blucon Tomato Bubble - Atom Utiliser le capteur de gravité pour faire pivoter les éléments Batterie transmetteur faible Rappels diff --git a/app/src/main/res/values-he/strings-he.xml b/app/src/main/res/values-he/strings-he.xml index 797bb35cf2..4d24f91c12 100644 --- a/app/src/main/res/values-he/strings-he.xml +++ b/app/src/main/res/values-he/strings-he.xml @@ -843,7 +843,6 @@ BluCon מיאומיאו Bubble - Atom השתמש בחיישן כח המשיכה כדי לסובב פריטים סוללת מכשיר גישור נמוכה תזכורות diff --git a/app/src/main/res/values-it/strings-it.xml b/app/src/main/res/values-it/strings-it.xml index 4c40e8ad18..d6a1b7ccae 100644 --- a/app/src/main/res/values-it/strings-it.xml +++ b/app/src/main/res/values-it/strings-it.xml @@ -848,7 +848,6 @@ Blucon Miaomiao Bubble - Atom Usa il sensore gravità per ruotare gli elementi Batteria bridge bassa Promemoria diff --git a/app/src/main/res/values-nl/strings-nl.xml b/app/src/main/res/values-nl/strings-nl.xml index ec75c65ee3..fc51a3c37b 100644 --- a/app/src/main/res/values-nl/strings-nl.xml +++ b/app/src/main/res/values-nl/strings-nl.xml @@ -848,7 +848,6 @@ Blucon Tomato Bubble - Atom Gebruik de zwaartekrachtsensor om items te roteren Lage zenderbatterij Herinneringen diff --git a/app/src/main/res/values-pt/strings-pt.xml b/app/src/main/res/values-pt/strings-pt.xml index 77a545993f..d8b96a32e3 100644 --- a/app/src/main/res/values-pt/strings-pt.xml +++ b/app/src/main/res/values-pt/strings-pt.xml @@ -847,7 +847,6 @@ Blucon Tomato Bubble - Atom Usar Sensor Gravidade para rodar Bridge bateria fraca Lembretes diff --git a/app/src/main/res/values-ru/strings-ru.xml b/app/src/main/res/values-ru/strings-ru.xml index ebfe3e7952..5a669923c7 100644 --- a/app/src/main/res/values-ru/strings-ru.xml +++ b/app/src/main/res/values-ru/strings-ru.xml @@ -847,7 +847,6 @@ Blucon Tomato Bubble - Atom Использовать гироскоп для ориентации Низкий уровень заряда трансмиттера Напоминания From 378e645d30eee5816ff16e901b98591e86386fb4 Mon Sep 17 00:00:00 2001 From: Apres Antonyan Date: Mon, 4 Oct 2021 14:39:35 +0400 Subject: [PATCH 4/4] added a missing semicolon --- wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java index c89c72d5c0..3a22f6aade 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java +++ b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java @@ -98,7 +98,7 @@ public static BridgeResponse decodeAtomPacket(byte[] buffer, int len) { if (first == 0x82) { int expectedSize = lens + ATOM_FOOTER; if (s_full_data == null) { - InitBuffer(expectedSize) + InitBuffer(expectedSize); } addData(buffer); return reply;