From ce8133b817a2b3512a35bcd4a03890412340762e Mon Sep 17 00:00:00 2001 From: Marcel Schulz Date: Tue, 12 Dec 2017 21:51:50 +0100 Subject: [PATCH] Minor changes and corrections in debug logs and example sketches. --- .../GettingStartedClient.ino | 10 ++++++---- .../GettingStartedMaster.ino | 17 +++++++++++++++++ src/SBNetwork.cpp | 8 ++++++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/examples/GettingStartedClient/GettingStartedClient.ino b/examples/GettingStartedClient/GettingStartedClient.ino index be706c2..5631f2f 100644 --- a/examples/GettingStartedClient/GettingStartedClient.ino +++ b/examples/GettingStartedClient/GettingStartedClient.ino @@ -37,6 +37,10 @@ SBMacAddress deviceMac(0x05, 0x04, 0x03, 0x02, 0x01); //SBNetwork networkDevice(false, D2, D8); SBNetwork networkDevice(true, 6, 7); +// time variables +uint32_t wait = 4000; +uint32_t lastWait = wait; + void setup() { Serial.begin(19200); @@ -44,11 +48,9 @@ void setup() { // Initialize the network device networkDevice.initialize(deviceMac); -} -// time variables -uint32_t wait = 4000; -uint32_t lastWait = wait; + lastWait = millis(); +} void loop() { diff --git a/examples/GettingStartedMaster/GettingStartedMaster.ino b/examples/GettingStartedMaster/GettingStartedMaster.ino index 60c2f68..fe70bde 100644 --- a/examples/GettingStartedMaster/GettingStartedMaster.ino +++ b/examples/GettingStartedMaster/GettingStartedMaster.ino @@ -45,6 +45,9 @@ void setup() { // Initialize the network device networkDevice.initialize(deviceMac); + // Enables the master to automatically add new clients + networkDevice.enableAutomaticClientAdding(true); + Serial.println(F("*** PRESS 'N' to reset the device")); } @@ -58,6 +61,20 @@ void loop() { if (c == 'N') { networkDevice.resetData(); } + if (c == 'E') { + // Only master should handle the switch of adding new clients + if (!networkDevice.RunAsClient) { + Serial.println("*****"); + if (networkDevice.isAutomaticClientAddingEnabled()) { + Serial.println("Deactivating AutomaticClientAdding"); + } + else { + Serial.println("Activating AutomaticClientAdding"); + } + Serial.println("*****"); + networkDevice.enableAutomaticClientAdding(!networkDevice.isAutomaticClientAddingEnabled()); + } + } } // Call this in the loop() function to maintain the network device diff --git a/src/SBNetwork.cpp b/src/SBNetwork.cpp index cb75198..652117c 100644 --- a/src/SBNetwork.cpp +++ b/src/SBNetwork.cpp @@ -176,7 +176,9 @@ bool SBNetwork::sendToDevice(SBMacAddress mac, void* message, uint8_t messageSiz //Serial.print(F("Fragment count = ")); //Serial.println(fragmentCount, DEC); for (uint8_t i = 0; i < fragmentCount; i++){ +#if defined(_DEBUG) Serial.print("."); +#endif uint8_t buffer[32]; if (i != (fragmentCount - 1)){ memcpy(buffer, (uint8_t*)message + (i * maxPackageSize), maxPackageSize); @@ -193,11 +195,15 @@ bool SBNetwork::sendToDevice(SBMacAddress mac, void* message, uint8_t messageSiz bool bSuccess = this->sendToDevice(frame); if (!bSuccess){ +#if defined(_DEBUG) Serial.println(" Failed"); +#endif return false; } } +#if defined(_DEBUG) Serial.println(" Done"); +#endif return true; } } @@ -396,14 +402,12 @@ bool SBNetwork::connectToNetwork(){ } bool bMasterAvailable = this->pingDevice(this->NetworkDevice.MasterMAC); -#ifdef _DEBUG if (bMasterAvailable) { Serial.println(F("Done - Master available")); } else { Serial.println(F("Failed - Master not responding")); } -#endif return bMasterAvailable; } else {