Custom Notifications Library failing
Posted: 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
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.
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
- #include <notification.h>
- #define NUMBER_OF_TESTS 10
- Notification notifications[NUMBER_OF_TESTS];
- void setup() {
- Serial.begin(115200);
- delay(5000);
- Serial.println("Beginning Notification Library Test");
- Serial.println("");
- Serial.println("Beginning creation test:");
- // put your setup code here, to run once:
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- notifications[i].create(i);
- Serial.print(i + " ");
- }
- Serial.println("\n");
- Serial.println("Creation test finished. Success!!");
- Serial.println("");
- Serial.println("Assigning titles:");
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- String title = "Notification Title";
- for (int j = 0; j < i; j++) {
- title = title + " Blah";
- }
- notifications[i].setTitle(title);
- Serial.print(i + " ");
- }
- Serial.println("\n");
- Serial.println("Title creation finished. Success!!");
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
- 10:20:40.680 -> Beginning Notification Library Test
- 10:20:40.680 ->
- 10:20:40.680 -> Beginning creation test:
- 10:20:40.680 -> assertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.680 -> ssertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.680 -> sertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.680 -> ertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.680 -> rtion "%s" failed: file "%s", line %d%s%s
- 10:20:40.680 -> tion "%s" failed: file "%s", line %d%s%s
- 10:20:40.680 -> ion "%s" failed: file "%s", line %d%s%s
- 10:20:40.680 -> on "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 ->
- 10:20:40.715 ->
- 10:20:40.715 -> Creation test finished. Success!!
- 10:20:40.715 ->
- 10:20:40.715 -> Assigning titles:
- 10:20:40.715 -> assertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 -> ssertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 -> sertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 -> ertion "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 -> rtion "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 -> tion "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 -> ion "%s" failed: file "%s", line %d%s%s
- 10:20:40.715 -> on "%s" failed: file "%s", line %d%s%s
- 10:20:40.749 ->
- 10:20:40.749 ->
- 10:20:40.749 -> Title creation finished. Success!!
- #include "Arduino.h"
- #include "String.h"
- #include "Notification.h"
- Notification::Notification(){}
- void Notification::create(uint8_t _uuid1, uint8_t _uuid2, uint8_t _uuid3, uint8_t _uuid4){
- uuid1 = _uuid1;
- uuid2 = _uuid2;
- uuid3 = _uuid3;
- uuid4 = _uuid4;
- }
- void Notification::create(uint32_t _uuid){
- uuid = _uuid;
- }
- String Notification::getAppIdentifier() {
- if (appIdentifier == NULL) {
- return "";
- } else {
- return appIdentifier;
- }
- }
- String Notification::getTitle() {
- if (title == NULL) {
- return "";
- } else {
- return title;
- }
- }
- String Notification::getSubtitle() {
- if (subtitle == NULL) {
- return "";
- } else {
- return subtitle;
- }
- }
- String Notification::getMessage() {
- if (message == NULL) {
- return "";
- } else {
- return message;
- }
- }
- String Notification::getMessageSizeString() {
- if (messageSizeString == NULL) {
- return "";
- } else {
- return messageSizeString;
- }
- }
- uint16_t Notification::getMessageSize() {
- if (messageSize == NULL) {
- if (messageSizeString == NULL) {
- return NULL;
- } else {
- messageSize = messageSizeString.toInt();
- return messageSize;
- }
- } else {
- return messageSize;
- }
- }
- String Notification::getDateString() {
- if (dateString == NULL) {
- return "";
- } else {
- return dateString;
- }
- }
- String Notification::getPositiveActionLabel() {
- if (positiveActionLabel == NULL) {
- return "";
- } else {
- return positiveActionLabel;
- }
- }
- String Notification::getNegativeActionLabel() {
- if (negativeActionLabel == NULL) {
- return "";
- } else {
- return negativeActionLabel;
- }
- }
- String Notification::setAppIdentifier(String _appIdentifier) {
- appIdentifier = _appIdentifier;
- }
- String Notification::setTitle(String _title) {
- title = _title;
- }
- String Notification::setSubtitle(String _subtitle) {
- subtitle = _subtitle;
- }
- String Notification::setMessage(String _message) {
- message = _message;
- }
- String Notification::setMessageSizeString(String _messageSizeString) {
- messageSizeString = _messageSizeString;
- }
- String Notification::setDateString(String _dateString) {
- dateString = _dateString;
- }
- String Notification::setPositiveActionLabel(String _positiveActionLabel) {
- positiveActionLabel = _positiveActionLabel;
- }
- String Notification::setNegativeActionLabel(String _negativeActionLabel) {
- negativeActionLabel = _negativeActionLabel;
- }
- bool Notification::hasAppIdentifier() {
- if (appIdentifier == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasTitle() {
- if (title == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasSubtitle() {
- if (subtitle == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasMessage() {
- if (message == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasMessageSizeString() {
- if (messageSizeString == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasMessageSize() {
- if (messageSize == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasDateString() {
- if (dateString == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasPositiveActionLabel() {
- if (positiveActionLabel == NULL) {
- return false;
- } else {
- return true;
- }
- }
- bool Notification::hasNegativeActionLabel() {
- if (negativeActionLabel == NULL) {
- return false;
- } else {
- return true;
- }
- }
- #ifndef Notification_h
- #define Notification_h
- #include "Arduino.h"
- class Notification {
- public:
- Notification();
- void create(uint8_t _uuid1, uint8_t _uuid2, uint8_t _uuid3, uint8_t _uuid4);
- void create(uint32_t _uuid);
- uint8_t uuid1;
- uint8_t uuid2;
- uint8_t uuid3;
- uint8_t uuid4;
- uint32_t uuid;
- String getAppIdentifier();
- String getTitle();
- String getSubtitle();
- String getMessage();
- String getMessageSizeString();
- uint16_t getMessageSize();
- String getDateString();
- String getPositiveActionLabel();
- String getNegativeActionLabel();
- String setAppIdentifier(String _appIdentifier);
- String setTitle(String _title);
- String setSubtitle(String _subtitle);
- String setMessage(String _message);
- String setMessageSizeString(String _messageSizeString);
- String setDateString(String _dateString);
- String setPositiveActionLabel(String _positiveActionLabel);
- String setNegativeActionLabel(String _negativeActionLabel);
- bool hasAppIdentifier();
- bool hasTitle();
- bool hasSubtitle();
- bool hasMessage();
- bool hasMessageSizeString();
- bool hasMessageSize();
- bool hasDateString();
- bool hasPositiveActionLabel();
- bool hasNegativeActionLabel();
- private:
- String appIdentifier;
- String title;
- String subtitle;
- String message;
- String messageSizeString;
- String dateString;
- String positiveActionLabel;
- String negativeActionLabel;
- uint16_t messageSize;
- };
- #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.