From c2f8037f07ca29d3bed381ab60aa0c41520af3c4 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Mon, 26 Sep 2016 22:21:41 +0200 Subject: [PATCH] WIP: Alert Notification Profile --- .../AlertNotificationProfile.java | 10 ++++ .../profiles/alertnotification/Category.java | 52 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/Category.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java new file mode 100644 index 000000000..a5d2309f1 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java @@ -0,0 +1,10 @@ +package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification; + +import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport; +import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.AbstractBleProfile; + +public class AlertNotificationProfile extends AbstractBleProfile { + public AlertNotificationProfile(T support) { + super(support); + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/Category.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/Category.java new file mode 100644 index 000000000..49eee240f --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/Category.java @@ -0,0 +1,52 @@ +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 enum Category { + Simple(0), + Email(1), + News(2), + IncomingCall(3), + MissedCall(4), + SMS(5), + VoiceMail(6), + Schedule(7), + HighPriorityAlert(8), + InstantMessage(9); + // 10-250 reserved for future use + // 251-255 defined by service specification + + private final int id; + + Category(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + private int asBit() { + return byteNumber() <=7 ? 0 : 1; + } + + private int byteNumber() { + return bitNumber() > 7 ? 0 : 1; + } + + private int bitNumber() { + // the ID corresponds to the bit for the bitset + return id; + } + + public static byte[] toBitmask(Category... categories) { + byte[] result = new byte[2]; + + for (Category category : categories) { + result[category.byteNumber()] |= category.asBit(); + } + return result; + } +}