MeshNet  1.0.0
meshBuffers.h
Go to the documentation of this file.
1 
14 #ifndef INC_MESHBUFFERS_H_
15 #define INC_MESHBUFFERS_H_
16 
17 #include <meshPacket.h>
18 
35 template <typename T, uint8_t BufferSize>
36 class MicroFIFO : public Printable {
37 public:
38 
44  const T& front() const {
45  return buffer[startPos];
46  }
47 
53  T& front() {
54  return buffer[startPos];
55  }
56 
62  const T& back() const {
63  uint8_t index = 0;
64  if (endPos == 0) index = BufferSize - 1;
65  else index = endPos - 1;
66  return buffer[index];
67  }
68 
74  T& back() {
75  uint8_t index = 0;
76  if (endPos == 0) index = BufferSize - 1;
77  else index = endPos - 1;
78  return buffer[index];
79  }
80 
87  bool get(T& item, uint8_t index) const {
88  T* ptr = getRowPtr(index);
89  if (ptr != NULL) {
90  item = *ptr;
91  return true;
92  }
93  else return false;
94  }
95 
101  const T& operator[](int index) const
102  {
103  const T* ptr = getRowPtr(index);
104  return *ptr;
105  }
106 
112  T& operator[](int index)
113  {
114  T* ptr = getRowPtr(index);
115  return *ptr;
116  }
117 
122  void push(T const& item) {
123  buffer[endPos] = item;
124  endPos = (endPos + 1) % BufferSize;
125 
126  if (usedSize >= BufferSize) {
127  startPos = (startPos + 1) % BufferSize; //Buffer overflow - remove first item to store last item
128  lostItems++;
129  }
130  else {
131  usedSize++;
132  }
133  }
134 
140  void push(T&& item) {
141  buffer[endPos] = std::move(item);
142  endPos = (endPos + 1) % BufferSize;
143 
144  if (usedSize >= BufferSize) {
145  startPos = (startPos + 1) % BufferSize; //Buffer overflow - remove first item to store last item
146  lostItems++;
147  }
148  else {
149  usedSize++;
150  }
151  }
152 
159  T&& popMove() {
160  uint8_t index = startPos;
161  startPos = (startPos + 1) % BufferSize;
162  usedSize--;
163  return std::move(buffer[index]);
164  }
165 
171  bool pop() {
172  if(!empty()){
173  startPos = (startPos + 1) % BufferSize;
174  usedSize--;
175  return true;
176  }
177  else{
178  return false;
179  }
180  }
181 
186  inline bool empty() const {
187  return usedSize == 0;
188  }
189 
194  inline uint8_t count() const {
195  return usedSize;
196  }
197 
202  const uint8_t size() const {
203  return BufferSize;
204  }
205 
210  inline uint8_t lostItemsCount() const {
211  return lostItems;
212  }
213 
217  inline void restartLostItemsCounter() {
218  lostItems = 0;
219  }
220 
232  bool removeAt(uint8_t index) {
233  if (index >= count()) return false;
234  if (index < count() / 2) {
235  //Moving items up from start until removed item position.
236  for (uint8_t i = index; i > 0; i--) {
237  buffer[getRawIndex(i)] = std::move(buffer[getRawIndex(i - 1)]);
238  }
239  startPos = (startPos + 1) % BufferSize;
240  }
241  else {
242  //Moving items down from end until removed item position.
243  for (uint8_t i = index+1; i < count(); i++) {
244  buffer[getRawIndex(i - 1)] = std::move(buffer[getRawIndex(i)]);
245  }
246  if (endPos == 0) {
247  endPos = BufferSize - 1;
248  }
249  else {
250  endPos--;
251  }
252  }
253  usedSize--;
254  return true;
255  }
256 
269  uint8_t removeMulti(uint8_t startPos_, uint8_t itmCount) {
270  if (startPos_ >= count() || itmCount == 0) return 0;
271  itmCount--; //To not count item at startPos during calculation
272  bool lowerHalf = (startPos_ + itmCount / 2) < count() / 2;
273  uint8_t i = startPos_ + itmCount; //i is now index of last item
274  if (i >= count()) { //End was reached
275  i = count() - 1;
276  itmCount = i - startPos_;
277  }
278  itmCount++; //Get it back, where it was before
279  if (lowerHalf) {
280  //Moving items up from start until removed item position.
281  i--;
282  for (; i > itmCount; i--) {
283  buffer[getRawIndex(i)] = std::move(buffer[getRawIndex(i - itmCount)]);
284  }
285  startPos = (startPos + itmCount) % BufferSize;
286  }
287  else {
288  //Moving items down from end until removed item position.
289  for (; i < count(); i++) {
290  buffer[getRawIndex(i - itmCount)] = std::move(buffer[getRawIndex(i)]);
291  }
292  if (endPos < itmCount) {
293  endPos = BufferSize - (itmCount - endPos);
294  }
295  else {
296  endPos -= itmCount;
297  }
298  }
299  usedSize -= itmCount;
300  return itmCount;
301  }
302 
312  uint8_t removeIf(bool(*dec)(const T&)) {
313  if (count() == 0) return 0;
314  uint8_t removeCnt = 0;
315  for (uint8_t readPos = 0; readPos < count(); readPos++) {
316  T& item = buffer[getRawIndex(readPos)];
317  if (dec(item)) {
318  //Remove packet
319  removeCnt++;
320  }
321  else if (removeCnt > 0) {
322  //Move packets down
323  buffer[getRawIndex(readPos - removeCnt)] = std::move(item);
324  }
325  }
326  if (endPos < removeCnt) {
327  endPos = BufferSize - (removeCnt - endPos);
328  }
329  else {
330  endPos -= removeCnt;
331  }
332  usedSize -= removeCnt;
333  return removeCnt;
334  }
335 
339  void clear() {
340  for(uint8_t i = 0; i < BufferSize; i++){
341  buffer[0].~T(); //Calling destructor to free allocated memory if any
342  }
343  startPos = 0;
344  endPos = 0;
345  usedSize = 0;
346  lostItems = 0;
347  }
348 
353  size_t getRawDataSize() const {
354  if (std::is_base_of<String, T>::value) { //special code for strings
355  size_t ret = 14;
356  for (uint8_t i = 0; i < usedSize; i++) {
357  const String* item = (String*)getRowPtr(i);
358  ret += item->length() + 4;
359  }
360  return ret;
361  }
362  else if (std::is_base_of<RawPrintable, T>::value) { //special code for raw printables
363  size_t ret = 14;
364  for (uint8_t i = 0; i < usedSize; i++) {
365  const RawPrintable* rp = (RawPrintable*)getRowPtr(i);
366  ret += rp->getRawSize();
367  }
368  return ret;
369  }
370  else {
371  return 14 + usedSize * sizeof(T);
372  }
373  }
374 
392  size_t virtual printRaw(OSTREAM& stream, const char* customTag) {
393  crc.begin();
394  crc.setInputReverse(true);
395  crc.setOutputReverse(true);
396  crc.setPolynomial32();
397  crc.reset(0xFFFFFFFFUL);
398 
399  size_t ret = 0;
400  ret = stream.print("MFF:"); //Micro FIFO
401  union WTB {
402  uint32_t word;
403  uint8_t buffer[4];
404  };
405 
406  char ctag[4] = { 0 };
407  for (uint8_t i = 0; i < 4 && customTag[i] != 0; i++) ctag[i] = customTag[i];
408  ret += stream.write(ctag, 4);
409  crc.append((uint8_t*)ctag, 4);
410 
411  ret += stream.write(BufferSize);
412  crc.append(BufferSize);
413 
414  if (std::is_base_of<String, T>::value || std::is_base_of<RawPrintable, T>::value) { //special code for strings and raw printables
415  ret += stream.write((uint8_t)255);
416  crc.append((uint8_t)255);
417  }
418  else {
419  ret += stream.write((uint8_t)sizeof(T));
420  crc.append((uint8_t)sizeof(T));
421  }
422 
423  ret += stream.write(usedSize);
424  crc.append(usedSize);
425 
426  for (uint8_t i = 0; i < usedSize; i++) { //Printing all used rows
427  const T* item = getRowPtr(i);
428 
429  if (std::is_base_of<String, T>::value) { //special code for strings
430  String txt = (String&)*item;
431  uint32_t len = (uint32_t)txt.length();
432  stream.write((uint8_t*)&len, 4); //Length of string - 4 bytes
433  crc.append((uint8_t*)&len, 4);
434  uint32_t bytesCount = (uint32_t)stream.print(txt);
435  crc.append((uint8_t*)txt.c_str(), bytesCount);
436  ret += bytesCount;
437  }
438  else if (std::is_base_of<RawPrintable, T>::value) { //special code for raw printables
439  const RawPrintable* rp = item;
440  ret += rp->printRaw(&stream, [](uint8_t* buffer, size_t length) {
441  crc.append(buffer, (uint32_t)length);
442  });
443  }
444  else { //Others types
445  uint32_t bytesCount = (uint32_t)stream.write((uint8_t*)item, bytesCount);
446  crc.append((uint8_t*)item, bytesCount);
447  ret += bytesCount;
448  }
449  }
450 
451  uint32_t CRC_val = crc.getLastCRC(0xFFFFFFFFUL);
452  ret += stream.write((uint8_t*)&CRC_val, 4); //Append CRC-32 at the end of message
453 
454  crc.end();
455 
456  return ret;
457  }
458 
465  virtual size_t print(OSTREAM& stream, bool showIndexes = true) const {
466  size_t ret = 0;
467  if (showIndexes) {
468  ret += stream.print("Index|");
469  }
470 
471  //Check if T contains InlinePrintable methods
472  if (std::is_base_of<InlinePrintable, T>::value) {
473  //Header printing
474  if (usedSize == 0) {
475  const T prHeader = T();
476  const InlinePrintable& printable = prHeader;
477  ret += printable.printHeader(&stream);
478  }
479  else {
480  const InlinePrintable& printable = buffer[startPos];
481  ret += printable.printHeader(&stream);
482  }
483 
484  //Dash print
485  size_t dashCount = ret;
486  for (size_t i = 0; i < dashCount; i++) {
487  ret += stream.print('-');
488  }
489  ret += stream.println();
490 
491  //Rows print
492  if (usedSize == 0) {
493  ret += stream.println("Empty");
494  }
495  else
496  {
497  for (int i = 0; i < usedSize; i++) {
498  if (showIndexes) {
499  char txtBuffer[10] = { 0 };
500  ITOA(i, txtBuffer, sizeof(txtBuffer) / sizeof(char), 10);
501  alignText(txtBuffer, 5, ' ', T_LEFT);
502  ret += stream.print(txtBuffer);
503  ret += stream.print('|');
504  }
505 
506  const InlinePrintable* printable = getRowPtr(i);
507  ret += printable->printLine(&stream);
508  }
509  }
510  }
511  else {
512  //Header print
513  ret += stream.println("Value");
514 
515  //Dash print
516  size_t dashCount = ret;
517  for (size_t i = 0; i < dashCount; i++) {
518  ret += stream.print('-');
519  }
520  ret += stream.println();
521 
522  //Rows print
523  if (usedSize == 0) {
524  ret += stream.println("Empty");
525  }
526  else
527  {
528  for (int i = 0; i < usedSize; i++) {
529  if (showIndexes) {
530  char txtBuffer[10] = { 0 };
531  ITOA(i, txtBuffer, sizeof(txtBuffer) / sizeof(char), 10);
532  alignText(txtBuffer, 5, ' ', T_LEFT);
533  ret += stream.print(txtBuffer);
534  ret += stream.print('|');
535  }
536 
537  T item = *getRowPtr(i);
538  ret += stream.println(item);
539  }
540  }
541  ret += stream.println();
542  }
543  return ret;
544  }
545 
550  virtual size_t sizeOf() const {
551  if (std::is_base_of<String, T>::value) { //special code for strings
552  size_t ret = 0;
553  for (uint8_t i = 0; i < usedSize; i++) {
554  const String* item = (String*)getRowPtr(i);
555  ret += item->length();
556 
557  }
558  return sizeof(*this) + ret;
559  }
560  else if (std::is_base_of<RawPrintable, T>::value) { //special code for raw printables
561  size_t ret = 0;
562  for (uint8_t i = 0; i < usedSize; i++) {
563  const RawPrintable* rp = (RawPrintable*)getRowPtr(i);
564  ret += rp->sizeOf() - sizeof(T);
565  }
566  return sizeof(*this) + ret;
567  }
568  return sizeof(*this);
569  }
570 
576  size_t printTo(Print& p) const override
577  {
578  return print(p);
579  }
580 
581 protected:
587  inline int16_t getRawIndex(uint8_t index) const {
588  if (index >= BufferSize) return -1;
589  uint16_t rawIndex = (startPos + index) % BufferSize;
590  return rawIndex;
591  }
592 
598  const T* getRowPtr(uint8_t index) const {
599  int16_t rawIndex = getRawIndex(index);
600  if (rawIndex >= 0) {
601  return &buffer[rawIndex];
602  }
603  return NULL;
604  }
605 
611  T* getRowPtr(uint8_t index) {
612  int16_t rawIndex = getRawIndex(index);
613  if (rawIndex >= 0) {
614  return &buffer[rawIndex];
615  }
616  return NULL;
617  }
618 
624  bool isRawIndexOccupied(uint8_t rawIndex) const {
625  if (usedSize >= BufferSize) {
626  return true; //when buffer is full, it is occupied
627  }
628  else if (startPos == endPos) {
629  return false; //Empty buffer
630  }
631  else if (startPos < endPos) {
632  return rawIndex >= startPos && rawIndex < endPos;
633  }
634  else {
635  return rawIndex >= startPos || rawIndex < endPos;
636  }
637  }
638 
639  T buffer[BufferSize];
640  uint8_t startPos = 0;
641  uint8_t endPos = 0;
642  uint8_t usedSize = 0;
643  uint8_t lostItems = 0;
644 };
645 
646 
663 template <uint8_t BufferSize>
664 class MeshPacketFIFO : public MicroFIFO<MeshPacket, BufferSize> {
665 public:
672  bool existsID(uint8_t ID, uint8_t source) const {
673  for (uint8_t i = 0; i < MicroFIFO<MeshPacket, BufferSize>::count(); i++) {
675  if (packet.PacketHeader.ID == ID && packet.PacketHeader.Source == source) {
676  return true;
677  }
678  }
679  return false;
680  }
681 
688  int16_t getIndexOfPacket(uint8_t ID, uint8_t source) const {
689  for (uint8_t i = 0; i < MicroFIFO<MeshPacket, BufferSize>::count(); i++) {
691  if (packet.PacketHeader.ID == ID && packet.PacketHeader.Source == source) {
692  return i;
693  }
694  }
695  return -1;
696  }
697 
698 
708  uint8_t removeByDestination(uint8_t destination) {
709  if (MicroFIFO<MeshPacket, BufferSize>::count() == 0) return 0;
710  uint8_t removeCnt = 0;
711  for (uint8_t readPos = 0; readPos < MicroFIFO<MeshPacket, BufferSize>::count(); readPos++) {
713  if (readPacket.PacketHeader.Destination == destination) {
714  //Remove packet
715  removeCnt++;
716  }
717  else if(removeCnt > 0) {
718  //Move packets down
720  }
721  }
724  }
725  else {
727  }
729  return removeCnt;
730  }
731 };
732 
751 template <uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
752 class MeshPacketPriorityFIFO : public Printable {
753 
754 public:
760  const MeshPacket& front() const {
761  if (routeBuffer.count()) {
762  return routeBuffer.front();
763  }
764  else {
765  return floodBuffer.front();
766  }
767  }
768 
775  if (routeBuffer.count()) {
776  return routeBuffer.front();
777  }
778  else {
779  return floodBuffer.front();
780  }
781  }
782 
788  const MeshPacket& back() const {
789  if (routeBuffer.count()) {
790  return routeBuffer.back();
791  }
792  else {
793  return floodBuffer.back();
794  }
795  }
796 
803  if (routeBuffer.count()) {
804  return routeBuffer.back();
805  }
806  else {
807  return floodBuffer.back();
808  }
809  }
810 
817  bool get(MeshPacket& item, uint8_t index) const {
818  if (routeBuffer.count() > index) {
819  return routeBuffer.get(item, index);
820  }
821  index -= routeBuffer.count();
822  if (floodBuffer.count() > index) {
823  return floodBuffer.get(item, index);
824  }
825  return false;
826  }
827 
833  const MeshPacket& operator[](int index) const
834  {
835  if (routeBuffer.count() > index) {
836  return routeBuffer[index];
837  }
838  index -= routeBuffer.count();
839  return floodBuffer[index];
840  }
841 
847  MeshPacket& operator[](int index)
848  {
849  if (routeBuffer.count() > index) {
850  return routeBuffer[index];
851  }
852  index -= routeBuffer.count();
853  return floodBuffer[index];
854  }
855 
860  void push(MeshPacket const& item) {
862  routeBuffer.push(item);
863  }
864  else {
865  floodBuffer.push(item);
866  }
867  }
868 
874  void push(MeshPacket&& item) {
875  if (item.PacketHeader.FrameControl.RoutingEnabled) {
876  routeBuffer.push(std::move(item));
877  }
878  else {
879  floodBuffer.push(std::move(item));
880  }
881  }
882 
889  if (routeBuffer.count()) {
890  return routeBuffer.popMove();
891  }
892  else {
893  return floodBuffer.popMove();
894  }
895  }
896 
902  bool pop() {
903  if (routeBuffer.count()) {
904  return routeBuffer.pop();
905  }
906  else {
907  return floodBuffer.pop();
908  }
909  }
910 
922  bool removeAt(uint8_t index) {
923  if (index < routeBuffer.count()) {
924  return routeBuffer.removeAt(index);
925  }
926  else {
927  return floodBuffer.removeAt(index - routeBuffer.count());
928  }
929  }
930 
943  uint8_t removeMulti(uint8_t startPos, uint8_t itmCount) {
944  uint8_t remCnt = 0;
945  uint8_t oldRBCount = routeBuffer.count();
946  if (startPos < routeBuffer.count()) {
947  remCnt = routeBuffer.removeMulti(startPos, itmCount);
948  if (remCnt == 0) return 0;
949  startPos = 0;
950  itmCount -= remCnt;
951  }
952  else {
953  startPos -= oldRBCount;
954  }
955 
956  if(itmCount > 0) {
957  return floodBuffer.removeMulti(startPos, itmCount);
958  }
959  return 0;
960  }
961 
971  uint8_t removeIf(bool(*dec)(const MeshPacket&)) {
972  if (count() == 0) return 0;
973  uint8_t cnt = routeBuffer.removeIf(dec);
974  return cnt + floodBuffer.removeIf(dec);
975  }
976 
986  uint8_t removeByDestination(uint8_t destination) {
987  uint8_t remCnt = floodBuffer.removeByDestination(destination);
988  return remCnt + routeBuffer.removeByDestination(destination);
989  }
990 
997  bool existsID(uint8_t ID, uint8_t source) const {
998  for (uint8_t i = 0; i < floodBuffer.count(); i++) {
999  if (floodBuffer[i].PacketHeader.ID == ID && floodBuffer[i].PacketHeader.Source == source) {
1000  return true;
1001  }
1002  }
1003  for (uint8_t i = 0; i < routeBuffer.count(); i++) {
1004  if (routeBuffer[i].PacketHeader.ID == ID && routeBuffer[i].PacketHeader.Source == source) {
1005  return true;
1006  }
1007  }
1008  return false;
1009  }
1010 
1017  int16_t getIndexOfPacket(uint8_t ID, uint8_t source) const {
1018  int16_t index = floodBuffer.getIndexOfPacket(ID, source);
1019  if (index >= 0) return index + routeBuffer.count();
1020  return routeBuffer.getIndexOfPacket(ID, source);
1021  }
1022 
1027  inline bool empty() const {
1028  return count() == 0;
1029  }
1030 
1035  inline uint8_t count() const {
1036  return routeBuffer.count() + floodBuffer.count();
1037  }
1038 
1043  inline uint8_t highCount() const {
1044  return routeBuffer.count();
1045  }
1046 
1051  inline uint8_t lowCount() const {
1052  return floodBuffer.count();
1053  }
1054 
1059  inline uint8_t size() const {
1060  return routeBuffer.size() + floodBuffer.size();
1061  }
1062 
1067  inline uint8_t highSize() const {
1068  return routeBuffer.size();
1069  }
1070 
1075  inline uint8_t lowSize() const {
1076  return floodBuffer.size();
1077  }
1078 
1083  inline uint8_t lostItemsCount() const {
1085  }
1086 
1090  inline void restartLostItemsCounter() {
1093  }
1094 
1098  inline void clear() {
1099  routeBuffer.clear();
1100  floodBuffer.clear();
1101  }
1102 
1107  return routeBuffer;
1108  }
1109 
1114  return routeBuffer;
1115  }
1116 
1121  return floodBuffer;
1122  }
1123 
1128  return floodBuffer;
1129  }
1130 
1135  size_t getRawDataSize() const {
1136  return routeBuffer.getRawDataSize();
1137  }
1138 
1156  size_t virtual printRaw(OSTREAM& stream, const char* customTag) {
1157  crc.begin();
1158  crc.setInputReverse(true);
1159  crc.setOutputReverse(true);
1160  crc.setPolynomial32();
1161  crc.reset(0xFFFFFFFFUL);
1162 
1163  size_t ret = 0;
1164  ret = stream.print("MFF:"); //Micro FIFO
1165  union WTB {
1166  uint32_t word;
1167  uint8_t buffer[4];
1168  };
1169 
1170  char ctag[4] = { 0 };
1171  for (uint8_t i = 0; i < 4 && customTag[i] != 0; i++) ctag[i] = customTag[i];
1172  ret += stream.write(ctag, 4);
1173  crc.append((uint8_t*)ctag, 4);
1174 
1175  ret += stream.write(size());
1176  crc.append(size());
1177 
1178  ret += stream.write((uint8_t)255);
1179  crc.append((uint8_t)255);
1180 
1181  ret += stream.write(count());
1182  crc.append(count());
1183 
1184  uint8_t index = 0;
1185  uint8_t len_p0 = routeBuffer.count();
1186  for (uint8_t i = 0; i < count(); i++) { //Printing all used rows
1187  const RawPrintable* rp = NULL;
1188 
1189  if (index < len_p0) { //High priority
1190  index = i;
1191  rp = &routeBuffer[index];
1192  }
1193  else { //Low priority
1194  index = i - len_p0;
1195  rp = &floodBuffer[index];
1196  }
1197 
1198  ret += rp->printRaw(&stream, [](uint8_t* buffer, size_t length) {
1199  crc.append(buffer, (uint32_t)length);
1200  });
1201  }
1202 
1203  uint32_t CRC_val = crc.getLastCRC(0xFFFFFFFFUL);
1204  ret += stream.write((uint8_t*)&CRC_val, 4); //Append CRC-32 at the end of message
1205 
1206  crc.end();
1207 
1208  return ret;
1209  }
1210 
1217  virtual size_t print(OSTREAM& stream, bool showIndexes = true) const {
1218  size_t ret = 0;
1219  if (showIndexes) {
1220  ret += stream.print("Index|");
1221  }
1222 
1223  ret += stream.print("Prior |"); //Priority
1224 
1225  uint8_t len = count();
1226  //Header printing
1227  if (len == 0) {
1228  const MeshPacket prHeader = MeshPacket();
1229  const InlinePrintable& printable = prHeader;
1230  ret += printable.printHeader(&stream);
1231  }
1232  else {
1233  const InlinePrintable& printable = front();
1234  ret += printable.printHeader(&stream);
1235  }
1236 
1237  //Dash print
1238  size_t dashCount = ret;
1239  for (size_t i = 0; i < dashCount; i++) {
1240  ret += stream.print('-');
1241  }
1242  ret += stream.println();
1243 
1244  //Rows print
1245  if (len == 0) {
1246  ret += stream.println("Empty");
1247  }
1248  else
1249  {
1250  uint8_t index = 0;
1251  uint8_t len_p0 = routeBuffer.count();
1252  for (int i = 0; i < len; i++) {
1253  //Index
1254  char txtBuffer[10] = { 0 };
1255  if (showIndexes) {
1256  ITOA(i, txtBuffer, sizeof(txtBuffer) / sizeof(char), 10);
1257  alignText(txtBuffer, 5, ' ', T_LEFT);
1258  ret += stream.print(txtBuffer);
1259  ret += stream.print('|');
1260  }
1261 
1262  if (index < len_p0) { //High priority
1263  ret += stream.print(" High |");
1264  index = i;
1265  const InlinePrintable& printable = routeBuffer[index];
1266  ret += printable.printLine(&stream);
1267  }
1268  else { //Low priority
1269  ret += stream.print(" Low |");
1270  index = i - len_p0;
1271  const InlinePrintable& printable = floodBuffer[index];
1272  ret += printable.printLine(&stream);
1273  }
1274  }
1275  }
1276 
1277  return ret;
1278  }
1279 
1284  virtual size_t sizeOf() const {
1285  return routeBuffer.sizeOf() + floodBuffer.sizeOf();
1286  }
1287 
1293  size_t printTo(Print& p) const override
1294  {
1295  return print(p);
1296  }
1297 
1298 protected:
1301 };
1302 
1303 #endif // !INC_MESHBUFFERS_H_
ITOA
#define ITOA
Definition: meshConfig.h:17
MicroFIFO::buffer
T buffer[BufferSize]
Definition: meshBuffers.h:639
MicroFIFO::restartLostItemsCounter
void restartLostItemsCounter()
Restarts lostItemsCount counter.
Definition: meshBuffers.h:217
MeshPacketPriorityFIFO::size
uint8_t size() const
Gets maximum count of items, that can be stored in buffer.
Definition: meshBuffers.h:1059
MeshPacketPriorityFIFO::routeBuffer
MeshPacketFIFO< ROUTE_BufferSize > routeBuffer
Definition: meshBuffers.h:1299
MeshFrameControl::RoutingEnabled
volatile bool RoutingEnabled
Enables or disables routing. When routing is enabled, packet will contain address of next node,...
Definition: meshPacketFlags.h:51
MicroFIFO::removeAt
bool removeAt(uint8_t index)
Removes item at specified index. After removing, count() will return new value.
Definition: meshBuffers.h:232
MeshPacketPriorityFIFO::get
bool get(MeshPacket &item, uint8_t index) const
Gets item from the buffer by index.
Definition: meshBuffers.h:817
InlinePrintable
Interface for printing derived class collection as table with header and rows.
Definition: meshHelper.h:134
MicroFIFO::push
void push(T const &item)
Pushes item after last item in buffer. When buffer is full, first (oldest) item will be overwritten a...
Definition: meshBuffers.h:122
MeshPacketPriorityFIFO::highSize
uint8_t highSize() const
Gets maximum count of items, that can be stored in high priority buffer.
Definition: meshBuffers.h:1067
MeshPacketPriorityFIFO::getIndexOfPacket
int16_t getIndexOfPacket(uint8_t ID, uint8_t source) const
Gets index of packet from unique packet identifier, which consists from ID and packet source address.
Definition: meshBuffers.h:1017
MicroFIFO::clear
void clear()
Clears whole buffer.
Definition: meshBuffers.h:339
MicroFIFO::printRaw
virtual size_t printRaw(OSTREAM &stream, const char *customTag)
Prints raw FIFO data through stream. Those data can be decoded in PC or in another MCU.
Definition: meshBuffers.h:392
MeshPacketPriorityFIFO::operator[]
MeshPacket & operator[](int index)
Gets item from the buffer by index.
Definition: meshBuffers.h:847
RawPrintable::sizeOf
virtual size_t sizeOf() const
Gets size of whole current instance uncompressed (including dynamically allocated memory) in bytes.
Definition: meshHelper.h:168
MeshPacketHeader::ID
uint8_t ID
Unique packet ID.
Definition: meshPacket.h:55
MicroFIFO::getRowPtr
const T * getRowPtr(uint8_t index) const
Gets pointer to the item in buffer by index.
Definition: meshBuffers.h:598
MeshPacketPriorityFIFO::front
const MeshPacket & front() const
Gets the first (oldest with the highest priority) item from the buffer.
Definition: meshBuffers.h:760
MeshPacketPriorityFIFO::removeByDestination
uint8_t removeByDestination(uint8_t destination)
Removes all packets with specified destination.
Definition: meshBuffers.h:986
MicroFIFO::printTo
size_t printTo(Print &p) const override
Makes this class printable.
Definition: meshBuffers.h:576
MicroFIFO::front
const T & front() const
Gets the first (oldest) item from the buffer.
Definition: meshBuffers.h:44
MicroFIFO::back
T & back()
Gets the last (newest) item from the buffer.
Definition: meshBuffers.h:74
MicroFIFO::startPos
uint8_t startPos
Definition: meshBuffers.h:640
MeshPacket::PacketHeader
MeshPacketHeader PacketHeader
Mesh packet header.
Definition: meshPacket.h:192
MicroFIFO::back
const T & back() const
Gets the last (newest) item from the buffer.
Definition: meshBuffers.h:62
MeshPacketPriorityFIFO::count
uint8_t count() const
Gets how many items are stored in buffer.
Definition: meshBuffers.h:1035
MeshPacketPriorityFIFO::operator[]
const MeshPacket & operator[](int index) const
Gets item from the buffer by index.
Definition: meshBuffers.h:833
MicroFIFO::usedSize
uint8_t usedSize
Definition: meshBuffers.h:642
alignText
void alignText(char *text, int size, char fill, TextAlignment alignment)
Aligns text in char array.
Definition: meshHelper.cpp:97
MeshPacketFIFO
Optimized FIFO buffer for microcontrolers, that can store only MeshPacket structure.
Definition: meshBuffers.h:664
MeshPacketPriorityFIFO::printRaw
virtual size_t printRaw(OSTREAM &stream, const char *customTag)
Prints raw FIFO data through stream. Those data can be decoded in PC or in another MCU.
Definition: meshBuffers.h:1156
MicroFIFO::operator[]
T & operator[](int index)
Gets item from the buffer by index.
Definition: meshBuffers.h:112
RawPrintable::printRaw
virtual size_t printRaw(OSTREAM *stream, void(*CRC_calculation)(uint8_t *, size_t)) const
Prints current instance into stream in raw bytes.
Definition: meshHelper.h:178
MeshPacketPriorityFIFO::removeMulti
uint8_t removeMulti(uint8_t startPos, uint8_t itmCount)
Removes number of item from specified index. After removing, count() will return new value.
Definition: meshBuffers.h:943
meshPacket.h
This file contains class which can be used to handling mesh packets.
MicroFIFO::print
virtual size_t print(OSTREAM &stream, bool showIndexes=true) const
Prints items as table from FIFO buffer to stream.
Definition: meshBuffers.h:465
T_LEFT
@ T_LEFT
Definition: meshHelper.h:116
MeshPacketPriorityFIFO::removeIf
uint8_t removeIf(bool(*dec)(const MeshPacket &))
Removes specified items.
Definition: meshBuffers.h:971
MicroFIFO::count
uint8_t count() const
Gets how many items are stored in buffer.
Definition: meshBuffers.h:194
MicroFIFO::get
bool get(T &item, uint8_t index) const
Gets item from the buffer by index.
Definition: meshBuffers.h:87
MeshPacketPriorityFIFO::lowCount
uint8_t lowCount() const
Gets how many items are stored in low priority buffer.
Definition: meshBuffers.h:1051
MeshPacketPriorityFIFO::push
void push(MeshPacket const &item)
Pushes item after last item in buffer. When buffer is full, first (oldest with the highest priority) ...
Definition: meshBuffers.h:860
MeshPacket
Class, that stores mesh packet with it's data. The size of this class can be slightly bigger then rea...
Definition: meshPacket.h:158
MicroFIFO::removeMulti
uint8_t removeMulti(uint8_t startPos_, uint8_t itmCount)
Removes number of item from specified index. After removing, count() will return new value.
Definition: meshBuffers.h:269
RawPrintable
Interface for converting class or structure instance to raw bytes, which can be sent.
Definition: meshHelper.h:161
MicroFIFO::lostItemsCount
uint8_t lostItemsCount() const
Definition: meshBuffers.h:210
MeshPacketHeader::FrameControl
MeshFrameControl FrameControl
Contains flags, that controls frame.
Definition: meshPacket.h:49
MeshPacketHeader::Destination
uint8_t Destination
Address of destination source node.
Definition: meshPacket.h:72
MeshPacketPriorityFIFO::getRawDataSize
size_t getRawDataSize() const
Calculates, how many bytes will be printed, when using command printRaw.
Definition: meshBuffers.h:1135
MeshPacketPriorityFIFO
Optimized FIFO buffer for microcontrolers, that can store only MeshPacket structure....
Definition: meshBuffers.h:752
MicroFIFO::empty
bool empty() const
Checks if buffer is empty.
Definition: meshBuffers.h:186
MeshPacketPriorityFIFO::popMove
MeshPacket && popMove()
Reads and removes first (oldest with the highest priority) item from the buffer. When buffer is empty...
Definition: meshBuffers.h:888
MeshPacketPriorityFIFO::print
virtual size_t print(OSTREAM &stream, bool showIndexes=true) const
Prints items as table from FIFO buffer to stream.
Definition: meshBuffers.h:1217
MeshPacketPriorityFIFO::pop
bool pop()
Removes first (oldest with the highest priority) item from the buffer.
Definition: meshBuffers.h:902
MicroFIFO::removeIf
uint8_t removeIf(bool(*dec)(const T &))
Removes specified items.
Definition: meshBuffers.h:312
OSTREAM
#define OSTREAM
Definition: meshConfig.h:41
MeshPacketPriorityFIFO::lowSize
uint8_t lowSize() const
Gets maximum count of items, that can be stored in low priority buffer.
Definition: meshBuffers.h:1075
MeshPacketPriorityFIFO::lostItemsCount
uint8_t lostItemsCount() const
Definition: meshBuffers.h:1083
MicroFIFO::size
const uint8_t size() const
Gets maximum count of items, that can be stored in buffer.
Definition: meshBuffers.h:202
MicroFIFO::getRowPtr
T * getRowPtr(uint8_t index)
Gets pointer to the item in buffer by index.
Definition: meshBuffers.h:611
MeshPacketPriorityFIFO::floodBuffer
MeshPacketFIFO< FLOOD_BufferSize > floodBuffer
Definition: meshBuffers.h:1300
RawPrintable::getRawSize
virtual size_t getRawSize() const
Gets size of data, that will be printed to stream using printRaw() in bytes.
Definition: meshHelper.h:186
MeshPacketPriorityFIFO::empty
bool empty() const
Checks if buffer is empty.
Definition: meshBuffers.h:1027
MeshPacketPriorityFIFO::lowFIFO
const MeshPacketFIFO< ROUTE_BufferSize > & lowFIFO() const
Gets reference to low priority FIFO.
Definition: meshBuffers.h:1127
InlinePrintable::printHeader
virtual size_t printHeader(OSTREAM *stream) const
Prints header of table.
Definition: meshHelper.h:142
MeshPacketPriorityFIFO::highCount
uint8_t highCount() const
Gets how many items are stored in high priority buffer.
Definition: meshBuffers.h:1043
MeshPacketFIFO::existsID
bool existsID(uint8_t ID, uint8_t source) const
Checks if there is packet in buffer with specified ID and source address, which creates unique packet...
Definition: meshBuffers.h:672
MeshPacketPriorityFIFO::restartLostItemsCounter
void restartLostItemsCounter()
Restarts lostItemsCount counter.
Definition: meshBuffers.h:1090
MeshPacketFIFO::getIndexOfPacket
int16_t getIndexOfPacket(uint8_t ID, uint8_t source) const
Gets index of packet from unique packet identifier, which consists from ID and packet source address.
Definition: meshBuffers.h:688
MeshPacketPriorityFIFO::clear
void clear()
Clears whole buffer.
Definition: meshBuffers.h:1098
MicroFIFO::sizeOf
virtual size_t sizeOf() const
Gets size of the whole FIFO in bytes.
Definition: meshBuffers.h:550
MicroFIFO::getRawDataSize
size_t getRawDataSize() const
Calculates, how many bytes will be printed, when using command printRaw.
Definition: meshBuffers.h:353
MeshPacketPriorityFIFO::back
MeshPacket & back()
Gets the last (newest with the lowest priority) item from the buffer.
Definition: meshBuffers.h:802
MeshPacketPriorityFIFO::sizeOf
virtual size_t sizeOf() const
Gets size of the whole FIFO in bytes.
Definition: meshBuffers.h:1284
MicroFIFO::pop
bool pop()
Removes first (oldest) item from the buffer.
Definition: meshBuffers.h:171
MicroFIFO
Optimized FIFO buffer for microcontrolers.
Definition: meshBuffers.h:36
MeshPacketPriorityFIFO::removeAt
bool removeAt(uint8_t index)
Removes item at specified index. After removing, count() will return new value.
Definition: meshBuffers.h:922
MeshPacketFIFO::removeByDestination
uint8_t removeByDestination(uint8_t destination)
Removes all packets with specified destination.
Definition: meshBuffers.h:708
MicroFIFO::operator[]
const T & operator[](int index) const
Gets item from the buffer by index.
Definition: meshBuffers.h:101
MeshPacketPriorityFIFO::printTo
size_t printTo(Print &p) const override
Makes this class printable.
Definition: meshBuffers.h:1293
MicroFIFO::isRawIndexOccupied
bool isRawIndexOccupied(uint8_t rawIndex) const
Checks if there is item stored at raw index.
Definition: meshBuffers.h:624
MicroFIFO::getRawIndex
int16_t getRawIndex(uint8_t index) const
Gets raw index in buffer from index. Index starts from startPos. Raw index starts from the beginning ...
Definition: meshBuffers.h:587
MeshPacketPriorityFIFO::back
const MeshPacket & back() const
Gets the last (newest with the lowest priority) item from the buffer.
Definition: meshBuffers.h:788
MicroFIFO::lostItems
uint8_t lostItems
Definition: meshBuffers.h:643
MicroFIFO::front
T & front()
Gets the first (oldest) item from the buffer.
Definition: meshBuffers.h:53
MeshPacketPriorityFIFO::lowFIFO
MeshPacketFIFO< ROUTE_BufferSize > & lowFIFO()
Gets reference to low priority FIFO.
Definition: meshBuffers.h:1120
MeshPacketPriorityFIFO::front
MeshPacket & front()
Gets the first (oldest with the highest priority) item from the buffer.
Definition: meshBuffers.h:774
MicroFIFO::popMove
T && popMove()
Reads and removes first (oldest) item from the buffer. When buffer is empty, exception may be thrown....
Definition: meshBuffers.h:159
MeshPacketHeader::Source
uint8_t Source
Address of message source node.
Definition: meshPacket.h:67
MeshPacketPriorityFIFO::highFIFO
const MeshPacketFIFO< ROUTE_BufferSize > & highFIFO() const
Gets reference to high priority FIFO.
Definition: meshBuffers.h:1113
MicroFIFO::push
void push(T &&item)
Pushes item after last item in buffer. When buffer is full, first (oldest) item will be overwritten a...
Definition: meshBuffers.h:140
MeshPacketPriorityFIFO::highFIFO
MeshPacketFIFO< ROUTE_BufferSize > & highFIFO()
Gets reference to high priority FIFO.
Definition: meshBuffers.h:1106
MeshPacketPriorityFIFO::existsID
bool existsID(uint8_t ID, uint8_t source) const
Checks if there is packet in buffer with specified ID and source address, which creates unique packet...
Definition: meshBuffers.h:997
MicroFIFO::endPos
uint8_t endPos
Definition: meshBuffers.h:641
InlinePrintable::printLine
virtual size_t printLine(OSTREAM *stream) const
Prints this data as row to table.
Definition: meshHelper.h:152
MeshPacketPriorityFIFO::push
void push(MeshPacket &&item)
Pushes item after last item in buffer. When buffer is full, first (oldest with the highest priority) ...
Definition: meshBuffers.h:874