#include "FragmentedMessage.h" void setup() { Serial.begin(57600); } void loop() { TestFragmentation(""); TestFragmentation("a"); TestFragmentation("abcdef"); TestFragmentation("123456789012345678901234567890"); TestFragmentation("1234567890123456789012345678901"); TestFragmentation("12345678901234567890123456789012"); TestFragmentation("123456789012345678901234567890123"); TestFragmentation("1234567890123456789012345678901234"); TestFragmentation("1234567890123456789012345678901234567890"); TestFragmentation("123456789012345678901234567890123456789012345678901234567890"); TestFragmentation("1234567890123456789012345678901234567890123456789012345678901"); TestFragmentation("12345678901234567890123456789012345678901234567890123456789012"); TestFragmentation("123456789012345678901234567890123456789012345678901234567890123"); TestFragmentation("1234567890123456789012345678901234567890123456789012345678901234"); TestFragmentation("12345678901234567890123456789012345678901234567890123456789012345"); TestFragmentation("123456789012345678901234567890123456789012345678901234567890123456"); TestFragmentation("1234567890123456789012345678901234567890123456789012345678901234567"); TestFragmentation("12345678901234567890123456789012345678901234567890123456789012345678"); TestFragmentation("123456789012345678901234567890123456789012345678901234567890123456789"); TestFragmentation("1234567890123456789012345678901234567890123456789012345678901234567890"); //delay(5000); } void TestFragmentation(char* source) { check_mem(); FragmentedMessage messageFragments = FragmentedMessage(source, 1); char* defragmented = messageFragments.DefragmentMessage(); int compare = strcmp(source, defragmented); if(compare != 0) { Serial.println(source); Serial.println(defragmented); Serial.print("Match: "); Serial.println(strcmp(source, defragmented)); } delete[] defragmented; FragmentedMessage newFragment = FragmentedMessage(); for(int i = messageFragments.NumFragments-1; i >=0; i--) { Serial.println("Fragment: "); Serial.println(i); newFragment.AppendMessageFragment(messageFragments.Fragments[i]); } newFragment.AppendMessageFragment(messageFragments.ChecksumFragment); if(newFragment.HasChecksumFragment()) { char* newDefragmented = newFragment.DefragmentMessage(); if(newDefragmented == NULL) { Serial.println("NULL NewDefragmented!"); } Serial.println(source); Serial.println(newDefragmented); int compare = strcmp(source, newDefragmented); if(compare != 0) { Serial.println("Mismatch New"); Serial.println(source); Serial.println(newDefragmented); Serial.print("Match: "); Serial.println(strcmp(source, newDefragmented)); } else { Serial.println("New OK"); } if(newDefragmented != NULL) { delete[] newDefragmented; } } else { Serial.println("No Checksum"); } } void check_mem() { extern int __heap_start, *__brkval; int v; int freemem = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); Serial.print("Free Mem: "); Serial.println(freemem); }