Issues with custom ANCS Notification library

johnbchron
Posts: 6
Joined: Wed Mar 25, 2020 2:34 pm

Issues with custom ANCS Notification library

Postby johnbchron » Wed Mar 25, 2020 3:05 pm

Hello all!

I'm trying to build a library for the arduino framework for the ESP32 which is intended to provide a class which will work as a data container for notifications provided by the ANCS ble service. For those of you who don't know, ANCS stands for Apple Notification Center Service. It's the service you subscribe to in order to read and modify apple system notifications over bluetooth.

Basically, there are a bunch of attributes that a notification can have which the bluetooth device retrieves lazily based on UID's. When a device subscribes to the ANCS, it begins a session, and for the length of that session each notification that the device encounters uses a UID to identify itself. These start at 0 at the beginning of the session and they are 32 bit unsigned integers. The attributes which are retrievable are as follows:
  • AppIdentrifier: the ID apple uses to identify the notification's source (i.e. com.apple.messaging.SMS)
  • Title
  • Subtitle
  • Message
  • MessageSize
  • Date
  • PositiveActionLabel: there are always two actions available for ANCS notifications: a positive action and a negative action. For an incoming call notification for example, the label for the positive action would be "Accept", and the negative action label would be "Decline".
  • NegativeActionLabel
A final note: in every communication with the iPhone, the UID is separated into 4 individual bytes, however I would like to also have a version which is unified for iterations and such. There are two constructors, one with each type, and both should generate the other when run. This functionality hasn't been implemented yet though.
Basically, there are private variables for each attribute, and also "set", "get", and "has" methods ("has" methods confirm or deny whether or not the attribute has been set).

My library code is as follows (I used the arduino Library tutorial to help me create this):

  1. #ifndef Notification_h
  2. #define Notification_h
  3.  
  4. #include "Arduino.h"
  5.  
  6. class Notification {
  7.     public:
  8.         Notification();
  9.         void create(uint8_t _uuid1, uint8_t _uuid2, uint8_t _uuid3, uint8_t _uuid4);
  10.         void create(uint32_t _uuid);
  11.         uint8_t uuid1;
  12.         uint8_t uuid2;
  13.         uint8_t uuid3;
  14.         uint8_t uuid4;
  15.         uint32_t uuid;
  16.         String getAppIdentifier();
  17.         String getTitle();
  18.         String getSubtitle();
  19.         String getMessage();
  20.         String getMessageSizeString();
  21.         uint16_t getMessageSize();
  22.         String getDateString();
  23.         String getPositiveActionLabel();
  24.         String getNegativeActionLabel();
  25.  
  26.         String setAppIdentifier(String _appIdentifier);
  27.         String setTitle(String _title);
  28.         String setSubtitle(String _subtitle);
  29.         String setMessage(String _message);
  30.         String setMessageSizeString(String _messageSizeString);
  31.         String setDateString(String _dateString);
  32.         String setPositiveActionLabel(String _positiveActionLabel);
  33.         String setNegativeActionLabel(String _negativeActionLabel);
  34.  
  35.         bool hasAppIdentifier();
  36.         bool hasTitle();
  37.         bool hasSubtitle();
  38.         bool hasMessage();
  39.         bool hasMessageSizeString();
  40.         bool hasMessageSize();
  41.         bool hasDateString();
  42.         bool hasPositiveActionLabel();
  43.         bool hasNegativeActionLabel();
  44.  
  45.     private:
  46.         String appIdentifier;
  47.         String title;
  48.         String subtitle;
  49.         String message;
  50.         String messageSizeString;
  51.         String dateString;
  52.         String positiveActionLabel;
  53.         String negativeActionLabel;
  54.         uint16_t messageSize;
  55. };
  56.  
  57. #endif

  1. #include "Arduino.h"
  2. #include "String.h"
  3. #include "Notification.h"
  4.  
  5. Notification::Notification(){}
  6.  
  7. void Notification::create(uint8_t _uuid1, uint8_t _uuid2, uint8_t _uuid3, uint8_t _uuid4){
  8.     uuid1 = _uuid1;
  9.     uuid2 = _uuid2;
  10.     uuid3 = _uuid3;
  11.     uuid4 = _uuid4;
  12. }
  13.  
  14. void Notification::create(uint32_t _uuid){
  15.     uuid = _uuid;
  16. }
  17.  
  18. String Notification::getAppIdentifier() {
  19.     if (appIdentifier == NULL) {
  20.         return "";
  21.     } else {
  22.         return appIdentifier;
  23.     }
  24. }
  25.  
  26. String Notification::getTitle() {
  27.     if (title == NULL) {
  28.         return "";
  29.     } else {
  30.         return title;
  31.     }
  32. }
  33.  
  34. String Notification::getSubtitle() {
  35.     if (subtitle == NULL) {
  36.         return "";
  37.     } else {
  38.         return subtitle;
  39.     }
  40. }
  41.  
  42. String Notification::getMessage() {
  43.     if (message == NULL) {
  44.         return "";
  45.     } else {
  46.         return message;
  47.     }
  48. }
  49.  
  50. String Notification::getMessageSizeString() {
  51.     if (messageSizeString == NULL) {
  52.         return "";
  53.     } else {
  54.         return messageSizeString;
  55.     }
  56. }
  57.  
  58. uint16_t Notification::getMessageSize() {
  59.     if (messageSize == NULL) {
  60.         if (messageSizeString == NULL) {
  61.             return NULL;
  62.         } else {
  63.             messageSize = messageSizeString.toInt();
  64.             return messageSize;
  65.         }
  66.     } else {
  67.         return messageSize;
  68.     }
  69. }
  70.  
  71. String Notification::getDateString() {
  72.     if (dateString == NULL) {
  73.         return "";
  74.     } else {
  75.         return dateString;
  76.     }
  77. }
  78.  
  79. String Notification::getPositiveActionLabel() {
  80.     if (positiveActionLabel == NULL) {
  81.         return "";
  82.     } else {
  83.         return positiveActionLabel;
  84.     }
  85. }
  86.  
  87. String Notification::getNegativeActionLabel() {
  88.     if (negativeActionLabel == NULL) {
  89.         return "";
  90.     } else {
  91.         return negativeActionLabel;
  92.     }
  93. }
  94.  
  95. String Notification::setAppIdentifier(String _appIdentifier) {
  96.     appIdentifier = _appIdentifier;
  97. }
  98.  
  99. String Notification::setTitle(String _title) {
  100.     title = _title;
  101. }
  102.  
  103. String Notification::setSubtitle(String _subtitle) {
  104.     subtitle = _subtitle;
  105. }
  106.  
  107. String Notification::setMessage(String _message) {
  108.     message = _message;
  109. }
  110.  
  111. String Notification::setMessageSizeString(String _messageSizeString) {
  112.     messageSizeString = _messageSizeString;
  113. }
  114.  
  115. String Notification::setDateString(String _dateString) {
  116.     dateString = _dateString;
  117. }
  118.  
  119. String Notification::setPositiveActionLabel(String _positiveActionLabel) {
  120.     positiveActionLabel = _positiveActionLabel;
  121. }
  122.  
  123. String Notification::setNegativeActionLabel(String _negativeActionLabel) {
  124.     negativeActionLabel = _negativeActionLabel;
  125. }
  126.  
  127. bool Notification::hasAppIdentifier() {
  128.     if (appIdentifier == NULL) {
  129.         return false;
  130.     } else {
  131.         return true;
  132.     }
  133. }
  134.  
  135. bool Notification::hasTitle() {
  136.     if (title == NULL) {
  137.         return false;
  138.     } else {
  139.         return true;
  140.     }
  141. }
  142.  
  143. bool Notification::hasSubtitle() {
  144.     if (subtitle == NULL) {
  145.         return false;
  146.     } else {
  147.         return true;
  148.     }
  149. }
  150.  
  151. bool Notification::hasMessage() {
  152.     if (message == NULL) {
  153.         return false;
  154.     } else {
  155.         return true;
  156.     }
  157. }
  158.  
  159. bool Notification::hasMessageSizeString() {
  160.     if (messageSizeString == NULL) {
  161.         return false;
  162.     } else {
  163.         return true;
  164.     }
  165. }
  166.  
  167. bool Notification::hasMessageSize() {
  168.     if (messageSize == NULL) {
  169.         return false;
  170.     } else {
  171.         return true;
  172.     }
  173. }
  174.  
  175. bool Notification::hasDateString() {
  176.     if (dateString == NULL) {
  177.         return false;
  178.     } else {
  179.         return true;
  180.     }
  181. }
  182.  
  183. bool Notification::hasPositiveActionLabel() {
  184.     if (positiveActionLabel == NULL) {
  185.         return false;
  186.     } else {
  187.         return true;
  188.     }
  189. }
  190.  
  191. bool Notification::hasNegativeActionLabel() {
  192.     if (negativeActionLabel == NULL) {
  193.         return false;
  194.     } else {
  195.         return true;
  196.     }
  197. }

  1. #include <notification.h>
  2.  
  3. #define NUMBER_OF_TESTS 10
  4.  
  5. Notification notifications[NUMBER_OF_TESTS];
  6.  
  7. void setup() {
  8.   Serial.begin(115200);
  9.   delay(5000);
  10.   Serial.println("Beginning Notification Library Test");
  11.   Serial.println("");
  12.   Serial.println("Beginning creation test:");
  13.  
  14.   // put your setup code here, to run once:
  15.   for (int i = 0; i < NUMBER_OF_TESTS; i++) {
  16.     notifications[i].create(i);
  17.     Serial.print(i + " ");
  18.   }
  19.   Serial.println("\n");
  20.  
  21.   Serial.println("Creation test finished. Success!!");
  22.   Serial.println("");
  23.  
  24.   Serial.println("Assigning titles:");
  25.   for (int i = 0; i < NUMBER_OF_TESTS; i++) {
  26.     String title = "Notification Title";
  27.     for (int j = 0; j < i; j++) {
  28.       title = title + " Blah";
  29.     }
  30.     notifications[i].setTitle(title);
  31.     Serial.print(i + " ");
  32.   }
  33.   Serial.println("\n");
  34.   Serial.println("Title creation finished. Success!!");
  35. }
  36.  
  37. void loop() {
  38.   // put your main code here, to run repeatedly:
  39.  
  40. }

When I run this however, the test... I guess it fails? This is the output:

  1. ets Jun  8 2016 00:22:57
  2.  
  3. rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  4. configsip: 0, SPIWP:0xee
  5. clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
  6. mode:DIO, clock div:1
  7. load:0x3fff0018,len:4
  8. load:0x3fff001c,len:1216
  9. ho 0 tail 12 room 4
  10. load:0x40078000,len:9720
  11. ho 0 tail 12 room 4
  12. load:0x40080400,len:6352
  13. entry 0x400806b8
  14. Beginning Notification Library Test
  15.  
  16. Beginning creation test:
  17.  assertion "%s" failed: file "%s", line %d%s%s
  18. ssertion "%s" failed: file "%s", line %d%s%s
  19. sertion "%s" failed: file "%s", line %d%s%s
  20. ertion "%s" failed: file "%s", line %d%s%s
  21. rtion "%s" failed: file "%s", line %d%s%s
  22. tion "%s" failed: file "%s", line %d%s%s
  23. ion "%s" failed: file "%s", line %d%s%s
  24. on "%s" failed: file "%s", line %d%s%s
  25.  
  26.  
  27. Creation test finished. Success!!
  28.  
  29. Assigning titles:
  30.  assertion "%s" failed: file "%s", line %d%s%s
  31. ssertion "%s" failed: file "%s", line %d%s%s
  32. sertion "%s" failed: file "%s", line %d%s%s
  33. ertion "%s" failed: file "%s", line %d%s%s
  34. rtion "%s" failed: file "%s", line %d%s%s
  35. tion "%s" failed: file "%s", line %d%s%s
  36. ion "%s" failed: file "%s", line %d%s%s
  37. on "%s" failed: file "%s", line %d%s%s
  38.  
  39.  
  40. Title creation finished. Success!!

Can somebody please tell me what "assertion "%s" failed: file "%s", line %d%s%s" means? I looked but I couldn't find anything. Also, if you have any recommendations for my library, please let me know!

johnbchron
Posts: 6
Joined: Wed Mar 25, 2020 2:34 pm

Re: Issues with custom ANCS Notification library

Postby johnbchron » Thu Apr 02, 2020 2:17 pm

Can somebody please help me with this? I would really like to continue moving forward on this project.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Issues with custom ANCS Notification library

Postby chegewara » Thu Apr 02, 2020 6:38 pm

You just cant use Serial.print this way:

Code: Select all

Serial.print(i + " ");
Try :

Code: Select all

Serial.println(i);
Serial.printf("%d%s\n", i, " ");
Or any similar.

johnbchron
Posts: 6
Joined: Wed Mar 25, 2020 2:34 pm

Re: Issues with custom ANCS Notification library

Postby johnbchron » Sun Apr 05, 2020 11:17 pm

Thanks, it worked!

Who is online

Users browsing this forum: No registered users and 32 guests