Minor changes and corrections in debug logs and example sketches.

This commit is contained in:
Marcel Schulz 2017-12-12 21:51:50 +01:00
parent 4815cc7f02
commit ce8133b817
3 changed files with 29 additions and 6 deletions

View File

@ -37,6 +37,10 @@ SBMacAddress deviceMac(0x05, 0x04, 0x03, 0x02, 0x01);
//SBNetwork networkDevice(false, D2, D8); //SBNetwork networkDevice(false, D2, D8);
SBNetwork networkDevice(true, 6, 7); SBNetwork networkDevice(true, 6, 7);
// time variables
uint32_t wait = 4000;
uint32_t lastWait = wait;
void setup() { void setup() {
Serial.begin(19200); Serial.begin(19200);
@ -44,11 +48,9 @@ void setup() {
// Initialize the network device // Initialize the network device
networkDevice.initialize(deviceMac); networkDevice.initialize(deviceMac);
}
// time variables lastWait = millis();
uint32_t wait = 4000; }
uint32_t lastWait = wait;
void loop() { void loop() {

View File

@ -45,6 +45,9 @@ void setup() {
// Initialize the network device // Initialize the network device
networkDevice.initialize(deviceMac); networkDevice.initialize(deviceMac);
// Enables the master to automatically add new clients
networkDevice.enableAutomaticClientAdding(true);
Serial.println(F("*** PRESS 'N' to reset the device")); Serial.println(F("*** PRESS 'N' to reset the device"));
} }
@ -58,6 +61,20 @@ void loop() {
if (c == 'N') { if (c == 'N') {
networkDevice.resetData(); 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 // Call this in the loop() function to maintain the network device

View File

@ -176,7 +176,9 @@ bool SBNetwork::sendToDevice(SBMacAddress mac, void* message, uint8_t messageSiz
//Serial.print(F("Fragment count = ")); //Serial.print(F("Fragment count = "));
//Serial.println(fragmentCount, DEC); //Serial.println(fragmentCount, DEC);
for (uint8_t i = 0; i < fragmentCount; i++){ for (uint8_t i = 0; i < fragmentCount; i++){
#if defined(_DEBUG)
Serial.print("."); Serial.print(".");
#endif
uint8_t buffer[32]; uint8_t buffer[32];
if (i != (fragmentCount - 1)){ if (i != (fragmentCount - 1)){
memcpy(buffer, (uint8_t*)message + (i * maxPackageSize), maxPackageSize); 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); bool bSuccess = this->sendToDevice(frame);
if (!bSuccess){ if (!bSuccess){
#if defined(_DEBUG)
Serial.println(" Failed"); Serial.println(" Failed");
#endif
return false; return false;
} }
} }
#if defined(_DEBUG)
Serial.println(" Done"); Serial.println(" Done");
#endif
return true; return true;
} }
} }
@ -396,14 +402,12 @@ bool SBNetwork::connectToNetwork(){
} }
bool bMasterAvailable = this->pingDevice(this->NetworkDevice.MasterMAC); bool bMasterAvailable = this->pingDevice(this->NetworkDevice.MasterMAC);
#ifdef _DEBUG
if (bMasterAvailable) { if (bMasterAvailable) {
Serial.println(F("Done - Master available")); Serial.println(F("Done - Master available"));
} }
else { else {
Serial.println(F("Failed - Master not responding")); Serial.println(F("Failed - Master not responding"));
} }
#endif
return bMasterAvailable; return bMasterAvailable;
} }
else { else {