Custom Notifications Library failing

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

Custom Notifications Library failing

Postby johnbchron » Thu Mar 26, 2020 3:24 pm

Hello All!

I've made a notification library which has a class which provides a data container for the attribute data of notifications retrieved from the apple ANCS ble service. It isn't performing as expected, which I think is because of the structure of how I'm trying to store the strings, but I don't know how I should re-structure it or what the error means.

There are 4 files; the notification.cpp and notification.h, the test code (.ino), and the log generated from that. I know it's a crap ton of text; bear with me here

  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. }

  1. 10:20:40.680 -> Beginning Notification Library Test
  2. 10:20:40.680 ->
  3. 10:20:40.680 -> Beginning creation test:
  4. 10:20:40.680 ->  assertion "%s" failed: file "%s", line %d%s%s
  5. 10:20:40.680 -> ssertion "%s" failed: file "%s", line %d%s%s
  6. 10:20:40.680 -> sertion "%s" failed: file "%s", line %d%s%s
  7. 10:20:40.680 -> ertion "%s" failed: file "%s", line %d%s%s
  8. 10:20:40.680 -> rtion "%s" failed: file "%s", line %d%s%s
  9. 10:20:40.680 -> tion "%s" failed: file "%s", line %d%s%s
  10. 10:20:40.680 -> ion "%s" failed: file "%s", line %d%s%s
  11. 10:20:40.680 -> on "%s" failed: file "%s", line %d%s%s
  12. 10:20:40.715 ->
  13. 10:20:40.715 ->
  14. 10:20:40.715 -> Creation test finished. Success!!
  15. 10:20:40.715 ->
  16. 10:20:40.715 -> Assigning titles:
  17. 10:20:40.715 ->  assertion "%s" failed: file "%s", line %d%s%s
  18. 10:20:40.715 -> ssertion "%s" failed: file "%s", line %d%s%s
  19. 10:20:40.715 -> sertion "%s" failed: file "%s", line %d%s%s
  20. 10:20:40.715 -> ertion "%s" failed: file "%s", line %d%s%s
  21. 10:20:40.715 -> rtion "%s" failed: file "%s", line %d%s%s
  22. 10:20:40.715 -> tion "%s" failed: file "%s", line %d%s%s
  23. 10:20:40.715 -> ion "%s" failed: file "%s", line %d%s%s
  24. 10:20:40.715 -> on "%s" failed: file "%s", line %d%s%s
  25. 10:20:40.749 ->
  26. 10:20:40.749 ->
  27. 10:20:40.749 -> Title creation finished. Success!!

  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. #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

So if you have any suggestions on how to restructure my library so it's more efficient or actually works or whatever you have for me, I'm all ears. I'm not super attached to this code, I just want it to work.

Who is online

Users browsing this forum: No registered users and 10 guests