52
52
STLINK DEBUG OUTPUT
53
53
******************************************************************************/
54
54
55
- // Report memory usage when enabled
56
- #if defined(LOG_MEMORY_USAGE)
57
- #include < malloc.h>
58
-
59
- void logMemoryUsage (const char *ctx_, bool enter_ = false ) {
60
- struct mallinfo mi = mallinfo ();
61
- Debug.print (DBG_DEBUG, F (" [MEMORY][%s %s] Allocated: %d bytes" ), (enter_ ? " >>>>" : " <<<<" ), ctx_, mi.uordblks );
62
- }
63
- #endif
64
-
65
55
// Provide Notehub debug output via STLINK serial port when available
66
56
#if defined(ARDUINO_SWAN_R5) || defined(ARDUINO_CYGNET)
67
57
#define STLINK_DEBUG
@@ -328,9 +318,6 @@ int NotecardConnectionHandler::write(const uint8_t * buf_, size_t size_)
328
318
NetworkConnectionState NotecardConnectionHandler::update_handleInit ()
329
319
{
330
320
NetworkConnectionState result = NetworkConnectionState::INIT;
331
- #if defined(LOG_MEMORY_USAGE)
332
- logMemoryUsage (__FUNCTION__, true );
333
- #endif
334
321
335
322
// Configure Hardware
336
323
// /////////////////////
@@ -527,18 +514,12 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit()
527
514
}
528
515
}
529
516
530
- #if defined(LOG_MEMORY_USAGE)
531
- logMemoryUsage (__FUNCTION__);
532
- #endif
533
517
return result;
534
518
}
535
519
536
520
NetworkConnectionState NotecardConnectionHandler::update_handleConnecting ()
537
521
{
538
522
NetworkConnectionState result;
539
- #if defined(LOG_MEMORY_USAGE)
540
- logMemoryUsage (__FUNCTION__, true );
541
- #endif
542
523
543
524
// Check the connection status
544
525
const NotecardConnectionStatus conn_status = connected ();
@@ -566,18 +547,12 @@ NetworkConnectionState NotecardConnectionHandler::update_handleConnecting()
566
547
}
567
548
}
568
549
569
- #if defined(LOG_MEMORY_USAGE)
570
- logMemoryUsage (__FUNCTION__);
571
- #endif
572
550
return result;
573
551
}
574
552
575
553
NetworkConnectionState NotecardConnectionHandler::update_handleConnected ()
576
554
{
577
555
NetworkConnectionState result;
578
- #if defined(LOG_MEMORY_USAGE)
579
- logMemoryUsage (__FUNCTION__, true );
580
- #endif
581
556
582
557
const NotecardConnectionStatus conn_status = connected ();
583
558
if (!conn_status.connected_to_notehub ) {
@@ -591,34 +566,22 @@ NetworkConnectionState NotecardConnectionHandler::update_handleConnected()
591
566
result = NetworkConnectionState::CONNECTED;
592
567
}
593
568
594
- #if defined(LOG_MEMORY_USAGE)
595
- logMemoryUsage (__FUNCTION__);
596
- #endif
597
569
return result;
598
570
}
599
571
600
572
NetworkConnectionState NotecardConnectionHandler::update_handleDisconnecting ()
601
573
{
602
574
NetworkConnectionState result;
603
- #if defined(LOG_MEMORY_USAGE)
604
- logMemoryUsage (__FUNCTION__, true );
605
- #endif
606
575
607
576
Debug.print (DBG_ERROR, F (" Connection to the network lost." ));
608
577
result = NetworkConnectionState::DISCONNECTED;
609
578
610
- #if defined(LOG_MEMORY_USAGE)
611
- logMemoryUsage (__FUNCTION__);
612
- #endif
613
579
return result;
614
580
}
615
581
616
582
NetworkConnectionState NotecardConnectionHandler::update_handleDisconnected ()
617
583
{
618
584
NetworkConnectionState result;
619
- #if defined(LOG_MEMORY_USAGE)
620
- logMemoryUsage (__FUNCTION__, true );
621
- #endif
622
585
623
586
if (_keep_alive)
624
587
{
@@ -636,9 +599,6 @@ NetworkConnectionState NotecardConnectionHandler::update_handleDisconnected()
636
599
}
637
600
}
638
601
639
- #if defined(LOG_MEMORY_USAGE)
640
- logMemoryUsage (__FUNCTION__);
641
- #endif
642
602
return result;
643
603
}
644
604
@@ -649,9 +609,6 @@ NetworkConnectionState NotecardConnectionHandler::update_handleDisconnected()
649
609
bool NotecardConnectionHandler::armInterrupt (void ) const
650
610
{
651
611
bool result;
652
- #if defined(LOG_MEMORY_USAGE)
653
- logMemoryUsage (__FUNCTION__, true );
654
- #endif
655
612
656
613
if (J *req = _notecard.newRequest (" card.attn" )) {
657
614
JAddStringToObject (req, " mode" ," rearm,files" );
@@ -681,18 +638,12 @@ bool NotecardConnectionHandler::armInterrupt (void) const
681
638
result = false ;
682
639
}
683
640
684
- #if defined(LOG_MEMORY_USAGE)
685
- logMemoryUsage (__FUNCTION__);
686
- #endif
687
641
return result;
688
642
}
689
643
690
644
bool NotecardConnectionHandler::configureConnection (bool connect_) const
691
645
{
692
646
bool result;
693
- #if defined(LOG_MEMORY_USAGE)
694
- logMemoryUsage (__FUNCTION__, true );
695
- #endif
696
647
697
648
if (J *req = _notecard.newRequest (" hub.set" )) {
698
649
// Only update the product if it is not empty or the default value
@@ -733,18 +684,12 @@ bool NotecardConnectionHandler::configureConnection (bool connect_) const
733
684
result = false ; // Assume the worst
734
685
}
735
686
736
- #if defined(LOG_MEMORY_USAGE)
737
- logMemoryUsage (__FUNCTION__);
738
- #endif
739
687
return result;
740
688
}
741
689
742
690
uint_fast8_t NotecardConnectionHandler::connected (void ) const
743
691
{
744
692
NotecardConnectionStatus result;
745
- #if defined(LOG_MEMORY_USAGE)
746
- logMemoryUsage (__FUNCTION__, true );
747
- #endif
748
693
749
694
// Query the connection status from the Notecard
750
695
if (J *rsp = _notecard.requestAndResponse (_notecard.newRequest (" hub.status" ))) {
@@ -775,18 +720,12 @@ uint_fast8_t NotecardConnectionHandler::connected (void) const
775
720
result.host_error = true ;
776
721
}
777
722
778
- #if defined(LOG_MEMORY_USAGE)
779
- logMemoryUsage (__FUNCTION__);
780
- #endif
781
723
return result;
782
724
}
783
725
784
726
J * NotecardConnectionHandler::getNote (bool pop_) const
785
727
{
786
728
J * result;
787
- #if defined(LOG_MEMORY_USAGE)
788
- logMemoryUsage (__FUNCTION__, true );
789
- #endif
790
729
791
730
// Look for a Note in the NOTEFILE_SECURE_INBOUND file
792
731
if (J *req = _notecard.newRequest (" note.get" )) {
@@ -824,15 +763,13 @@ J * NotecardConnectionHandler::getNote (bool pop_) const
824
763
result = nullptr ;
825
764
}
826
765
827
- #if defined(LOG_MEMORY_USAGE)
828
- logMemoryUsage (__FUNCTION__);
829
- #endif
830
766
return result;
831
767
}
832
768
833
769
int NotecardConnectionHandler::initiateNotehubSync (void ) const
834
770
{
835
771
int result;
772
+
836
773
Debug.print (DBG_DEBUG, F (" Initiating Notehub sync..." ));
837
774
if (J *rsp = _notecard.requestAndResponse (_notecard.newRequest (" hub.sync" ))) {
838
775
// Check the response for errors
@@ -856,9 +793,6 @@ int NotecardConnectionHandler::initiateNotehubSync (void) const
856
793
bool NotecardConnectionHandler::updateUidCache (void )
857
794
{
858
795
bool result;
859
- #if defined(LOG_MEMORY_USAGE)
860
- logMemoryUsage (__FUNCTION__, true );
861
- #endif
862
796
863
797
// This operation is safe to perform before a sync has occurred, because the
864
798
// Notecard UID is static and the cloud value of Serial Number is strictly
@@ -885,9 +819,6 @@ bool NotecardConnectionHandler::updateUidCache (void)
885
819
result = false ;
886
820
}
887
821
888
- #if defined(LOG_MEMORY_USAGE)
889
- logMemoryUsage (__FUNCTION__);
890
- #endif
891
822
return result;
892
823
}
893
824
0 commit comments