mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
WIP: A little more Alert Notification Profile
I think we should rather focus on a code generator, though.
This commit is contained in:
parent
fabc52fdad
commit
8f36712342
@ -87,8 +87,8 @@ public class BleNamesResolver {
|
||||
mServices.put("00001530-0000-3512-2118-0009af100700", "(Propr: Xiaomi Weight Service)");
|
||||
|
||||
|
||||
mCharacteristics.put("00002a43-0000-1000-8000-00805f9b34fb", "Alert Category ID");
|
||||
mCharacteristics.put("00002a42-0000-1000-8000-00805f9b34fb", "Alert Category ID Bit Mask");
|
||||
mCharacteristics.put("00002a43-0000-1000-8000-00805f9b34fb", "Alert AlertCategory ID");
|
||||
mCharacteristics.put("00002a42-0000-1000-8000-00805f9b34fb", "Alert AlertCategory ID Bit Mask");
|
||||
mCharacteristics.put("00002a06-0000-1000-8000-00805f9b34fb", "Alert Level");
|
||||
mCharacteristics.put("00002a44-0000-1000-8000-00805f9b34fb", "Alert Notification Control Point");
|
||||
mCharacteristics.put("00002a3f-0000-1000-8000-00805f9b34fb", "Alert Status");
|
||||
@ -155,8 +155,8 @@ public class BleNamesResolver {
|
||||
mCharacteristics.put("00002a25-0000-1000-8000-00805f9b34fb", "Serial Number String");
|
||||
mCharacteristics.put("00002a05-0000-1000-8000-00805f9b34fb", "Service Changed");
|
||||
mCharacteristics.put("00002a28-0000-1000-8000-00805f9b34fb", "Software Revision String");
|
||||
mCharacteristics.put("00002a47-0000-1000-8000-00805f9b34fb", "Supported New Alert Category");
|
||||
mCharacteristics.put("00002a48-0000-1000-8000-00805f9b34fb", "Supported Unread Alert Category");
|
||||
mCharacteristics.put("00002a47-0000-1000-8000-00805f9b34fb", "Supported New Alert AlertCategory");
|
||||
mCharacteristics.put("00002a48-0000-1000-8000-00805f9b34fb", "Supported Unread Alert AlertCategory");
|
||||
mCharacteristics.put("00002a23-0000-1000-8000-00805f9b34fb", "System ID");
|
||||
mCharacteristics.put("00002a1c-0000-1000-8000-00805f9b34fb", "Temperature Measurement");
|
||||
mCharacteristics.put("00002a1d-0000-1000-8000-00805f9b34fb", "Temperature Type");
|
||||
|
@ -184,8 +184,8 @@ public class GattCharacteristic {
|
||||
|
||||
static {
|
||||
GATTCHARACTERISTIC_DEBUG = new HashMap<>();
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_ALERT_CATEGORY_ID, "Alert Category ID");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_ALERT_CATEGORY_ID_BIT_MASK, "Alert Category ID Bit Mask");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_ALERT_CATEGORY_ID, "Alert AlertCategory ID");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_ALERT_CATEGORY_ID_BIT_MASK, "Alert AlertCategory ID Bit Mask");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_ALERT_LEVEL, "Alert Level");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_ALERT_NOTIFICATION_CONTROL_POINT, "Alert Notification Control Point");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_ALERT_STATUS, "Alert Status");
|
||||
@ -221,8 +221,8 @@ public class GattCharacteristic {
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_SERIAL_NUMBER_STRING, "Serial Number String");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_GATT_SERVICE_CHANGED, "Service Changed");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_SOFTWARE_REVISION_STRING, "Software Revision String");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_SUPPORTED_NEW_ALERT_CATEGORY, "Supported New Alert Category");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_SUPPORTED_UNREAD_ALERT_CATEGORY, "Supported Unread Alert Category");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_SUPPORTED_NEW_ALERT_CATEGORY, "Supported New Alert AlertCategory");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_SUPPORTED_UNREAD_ALERT_CATEGORY, "Supported Unread Alert AlertCategory");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_SYSTEM_ID, "System ID");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_TEMPERATURE_MEASUREMENT, "Temperature Measurement");
|
||||
GATTCHARACTERISTIC_DEBUG.put(UUID_CHARACTERISTIC_TEMPERATURE_TYPE, "Temperature DeviceType");
|
||||
|
@ -1,10 +1,13 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_category_id.xml
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_category_id_bit_mask.xml
|
||||
*/
|
||||
public enum Category {
|
||||
public enum AlertCategory {
|
||||
Simple(0),
|
||||
Email(1),
|
||||
News(2),
|
||||
@ -20,33 +23,57 @@ public enum Category {
|
||||
|
||||
private final int id;
|
||||
|
||||
Category(int id) {
|
||||
AlertCategory(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numerical ID value of this category
|
||||
* To be used as uin8 value
|
||||
* @return the uint8 value for this category
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private int asBit() {
|
||||
return byteNumber() <=7 ? 0 : 1;
|
||||
}
|
||||
|
||||
private int byteNumber() {
|
||||
return bitNumber() > 7 ? 0 : 1;
|
||||
}
|
||||
|
||||
private int bitNumber() {
|
||||
private int realBitNumber() {
|
||||
// the ID corresponds to the bit for the bitset
|
||||
return id;
|
||||
}
|
||||
|
||||
public static byte[] toBitmask(Category... categories) {
|
||||
private int bitNumberPerByte() {
|
||||
// the ID corresponds to the bit for the bitset (per byte)
|
||||
return realBitNumber() % 8;
|
||||
}
|
||||
|
||||
private int asBit() {
|
||||
return 1 << bitNumberPerByte();
|
||||
}
|
||||
|
||||
private int byteNumber() {
|
||||
return id <= 7 ? 0 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given categories to an array of bytes.
|
||||
* @param categories
|
||||
* @return
|
||||
*/
|
||||
public static byte[] toBitmask(AlertCategory... categories) {
|
||||
byte[] result = new byte[2];
|
||||
|
||||
for (Category category : categories) {
|
||||
for (AlertCategory category : categories) {
|
||||
result[category.byteNumber()] |= category.asBit();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// SupportedNewAlertCategory
|
||||
public static AlertCategory[] fromBitMask(byte[] bytes) {
|
||||
List<AlertCategory> result = new ArrayList<>();
|
||||
byte b = bytes[0];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification;
|
||||
|
||||
|
||||
/**
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_level.xml
|
||||
*/
|
||||
public enum AlertLevel {
|
||||
NoAlert(0),
|
||||
MildAlert(1),
|
||||
HighAlert(2);
|
||||
// 3-255 reserved
|
||||
|
||||
private final int id;
|
||||
|
||||
AlertLevel(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The alert level ID
|
||||
* To be used as uint8 value
|
||||
* @return
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification;
|
||||
|
||||
/**
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_notification_control_point.xml
|
||||
*/
|
||||
public class AlertNotificationControl {
|
||||
|
||||
}
|
@ -7,4 +7,6 @@ public class AlertNotificationProfile<T extends AbstractBTLEDeviceSupport> exten
|
||||
public AlertNotificationProfile(T support) {
|
||||
super(support);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification;
|
||||
|
||||
/**
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_status.xml
|
||||
* uint8 value (bitmask) of the given values
|
||||
*/
|
||||
public class AlertStatus {
|
||||
public static final int RINGER_ACTIVE_BIT = 1;
|
||||
public static final int VIBRATE_ACTIVE = 1 << 1;
|
||||
public static final int DISPLAY_ALERT_ACTIVE = 1 << 2;
|
||||
|
||||
public static boolean isRingerActive(int status) {
|
||||
return (status & RINGER_ACTIVE_BIT) == RINGER_ACTIVE_BIT;
|
||||
}
|
||||
public static boolean isVibrateActive(int status) {
|
||||
return (status & VIBRATE_ACTIVE) == VIBRATE_ACTIVE;
|
||||
}
|
||||
public static boolean isDisplayAlertActive(int status) {
|
||||
return (status & DISPLAY_ALERT_ACTIVE) == DISPLAY_ALERT_ACTIVE;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification;
|
||||
|
||||
/**
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_category_id.xml
|
||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_category_id_bit_mask.xml
|
||||
*/
|
||||
public class SupportedNewAlertCategory {
|
||||
private final int id;
|
||||
//
|
||||
// public static Ca(byte[] categoryBytes) {
|
||||
//
|
||||
// }
|
||||
|
||||
public SupportedNewAlertCategory(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numerical ID value of this category
|
||||
* To be used as uin8 value
|
||||
* @return the uint8 value for this category
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private int realBitNumber() {
|
||||
// the ID corresponds to the bit for the bitset
|
||||
return id;
|
||||
}
|
||||
|
||||
private int bitNumberPerByte() {
|
||||
// the ID corresponds to the bit for the bitset (per byte)
|
||||
return realBitNumber() % 8;
|
||||
}
|
||||
|
||||
private int asBit() {
|
||||
return 1 << bitNumberPerByte();
|
||||
}
|
||||
|
||||
private int byteNumber() {
|
||||
return id <= 7 ? 0 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given categories to an array of bytes.
|
||||
* @param categories
|
||||
* @return
|
||||
*/
|
||||
public static byte[] toBitmask(SupportedNewAlertCategory... categories) {
|
||||
byte[] result = new byte[2];
|
||||
|
||||
for (SupportedNewAlertCategory category : categories) {
|
||||
result[category.byteNumber()] |= category.asBit();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user