Put some const char* into F() Makro.

Cleaned up some debug messages.
Standard mode now is non debug.
This commit is contained in:
Marcel Schulz 2017-12-11 01:02:26 +01:00
parent bf01311e36
commit 4815cc7f02
3 changed files with 27 additions and 15 deletions

View File

@ -135,7 +135,9 @@ void SBNetwork::resetData(){
bool SBNetwork::sendToDevice(SBMacAddress mac, void* message, uint8_t messageSize){ bool SBNetwork::sendToDevice(SBMacAddress mac, void* message, uint8_t messageSize){
#if defined(_DEBUG)
Serial.print("Sending transmission"); Serial.print("Sending transmission");
#endif
SBNetworkHeader header; SBNetworkHeader header;
header.ToAddress = mac; header.ToAddress = mac;
header.FromAddress = this->NetworkDevice.MAC; header.FromAddress = this->NetworkDevice.MAC;
@ -145,7 +147,7 @@ bool SBNetwork::sendToDevice(SBMacAddress mac, void* message, uint8_t messageSiz
frame.Header = header; frame.Header = header;
uint8_t maxPackageSize = MAX_PACKAGE_SIZE; uint8_t maxPackageSize = MAX_PACKAGE_SIZE;
if (messageSize <= maxPackageSize){ if (messageSize <= maxPackageSize){
Serial.print(" with no fragmentation"); //Serial.print(" with no fragmentation");
// We can send directly without fragmentation // We can send directly without fragmentation
frame.Header.FragmentNr = 0; frame.Header.FragmentNr = 0;
frame.Header.FragmentCount = 1; frame.Header.FragmentCount = 1;
@ -153,16 +155,18 @@ bool SBNetwork::sendToDevice(SBMacAddress mac, void* message, uint8_t messageSiz
frame.MessageSize = messageSize; frame.MessageSize = messageSize;
frame.Message = (uint8_t*)message; frame.Message = (uint8_t*)message;
bool bSuccess = this->sendToDevice(frame); bool bSuccess = this->sendToDevice(frame);
#if defined(_DEBUG)
if (bSuccess) { if (bSuccess) {
Serial.println(" Done"); Serial.println(" Done");
} }
else { else {
Serial.println(" Failed"); Serial.println(" Failed");
} }
#endif
return bSuccess; return bSuccess;
} }
else{ else{
Serial.print(" with fragmentation "); //Serial.print(" with fragmentation ");
// We have to send it in fragments // We have to send it in fragments
uint8_t fragmentCount = messageSize / maxPackageSize; uint8_t fragmentCount = messageSize / maxPackageSize;
if ((fragmentCount * maxPackageSize) < messageSize){ if ((fragmentCount * maxPackageSize) < messageSize){
@ -248,9 +252,11 @@ bool SBNetwork::receiveMessage(void **message, uint8_t *messageSize, SBMacAddres
SBNetworkFrame frame; SBNetworkFrame frame;
bool bReceive = this->receive(&frame); bool bReceive = this->receive(&frame);
if (bReceive) { if (bReceive) {
#ifdef _DEBUG
Serial.print("Incomming transmission from "); Serial.print("Incomming transmission from ");
printAddress(frame.Header.FromAddress); printAddress(frame.Header.FromAddress);
Serial.println(); Serial.println();
#endif
if (frame.Header.FragmentCount == 1) { if (frame.Header.FragmentCount == 1) {
// We only have to receive this package // We only have to receive this package
memcpy(_ReadBuffer, frame.Message, maxPackageSize); memcpy(_ReadBuffer, frame.Message, maxPackageSize);
@ -307,7 +313,7 @@ bool SBNetwork::connectToNetwork(){
Serial.print(F("Try to connect to master...")); Serial.print(F("Try to connect to master..."));
// First we have to check, if we already have a master stored // First we have to check, if we already have a master stored
if (!this->NetworkDevice.ConnectedToMaster) { if (!this->NetworkDevice.ConnectedToMaster) {
Serial.println("Warning - Not paired to a master"); Serial.println(F("Warning - Not paired to a master"));
Serial.print(F("Sending broadcast transmission to find a master...")); Serial.print(F("Sending broadcast transmission to find a master..."));
// If not, we have to search for a master // If not, we have to search for a master
SBNetworkHeader header; SBNetworkHeader header;
@ -358,7 +364,7 @@ bool SBNetwork::connectToNetwork(){
conFrame.Header.ToAddress = frame.Header.FromAddress; conFrame.Header.ToAddress = frame.Header.FromAddress;
conFrame.MessageSize = 0; conFrame.MessageSize = 0;
if (!this->sendToDevice(conFrame)) { if (!this->sendToDevice(conFrame)) {
Serial.println("Failed - Sending pairing request"); Serial.println(F("Failed - Sending pairing request"));
} }
else { else {
while (!this->receive(&frame)) { while (!this->receive(&frame)) {
@ -390,12 +396,14 @@ 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 {
@ -435,7 +443,7 @@ bool SBNetwork::handleCommandPackage(SBNetworkFrame *frame){
if (!bFound) { if (!bFound) {
// If an unknown device was detected, then never handle the network control traffic and never handle the messages // If an unknown device was detected, then never handle the network control traffic and never handle the messages
#ifdef _DEBUG #ifdef _DEBUG
Serial.print("Unknown device detected with MAC: "); Serial.print(F("Unknown device detected with MAC: "));
printAddress(frame->Header.FromAddress); printAddress(frame->Header.FromAddress);
Serial.println(); Serial.println();
#endif #endif
@ -444,39 +452,39 @@ bool SBNetwork::handleCommandPackage(SBNetworkFrame *frame){
switch (frame->Header.CommandType) { switch (frame->Header.CommandType) {
case SBS_COMMAND_PING: { case SBS_COMMAND_PING: {
#ifdef _DEBUG #ifdef _DEBUG
Serial.println("Received 'PING'"); Serial.println(F("Received 'PING'"));
#endif #endif
break; break;
} }
case SBS_COMMAND_SEARCH_MASTER: { case SBS_COMMAND_SEARCH_MASTER: {
#ifdef _DEBUG #ifdef _DEBUG
Serial.print("Received 'SEARCH_MASTER' Package. "); Serial.print(F("Received 'SEARCH_MASTER' Package. "));
#endif #endif
if (_EnableAutomaticClientAdding) { if (_EnableAutomaticClientAdding) {
#ifdef _DEBUG #ifdef _DEBUG
Serial.println("Send MasterACK..."); Serial.println(F("Send MasterACK..."));
#endif #endif
delay(100); delay(100);
bool bSend = sendMasterAck(frame->Header.FromAddress); bool bSend = sendMasterAck(frame->Header.FromAddress);
if (bSend) { if (bSend) {
return false; return false;
} }
Serial.println("Done"); Serial.println(F("Done"));
} }
#if defined(_DEBUG) #if defined(_DEBUG)
else { else {
Serial.println("AutomaticClientAdding is deactivaed. Ignoring package."); Serial.println(F("AutomaticClientAdding is deactivaed. Ignoring package."));
} }
#endif #endif
break; break;
} }
case SBS_COMMAND_REQUEST_PAIRING: { case SBS_COMMAND_REQUEST_PAIRING: {
#ifdef _DEBUG #ifdef _DEBUG
Serial.print("Received 'PAIRING_REQUEST' Package. "); Serial.print(F("Received 'PAIRING_REQUEST' Package. "));
#endif #endif
if (_EnableAutomaticClientAdding) { if (_EnableAutomaticClientAdding) {
#ifdef _DEBUG #ifdef _DEBUG
Serial.println("Send MasterACK..."); Serial.println(F("Send MasterACK..."));
#endif #endif
delay(100); delay(100);
// This is the point where we could stop orpcessing and wait for an user input on the controller to let the new device access the network // This is the point where we could stop orpcessing and wait for an user input on the controller to let the new device access the network
@ -487,7 +495,7 @@ bool SBNetwork::handleCommandPackage(SBNetworkFrame *frame){
} }
#if defined(_DEBUG) #if defined(_DEBUG)
else { else {
Serial.println("AutomaticClientAdding is deactivaed. Ignoring package."); Serial.println(F("AutomaticClientAdding is deactivaed. Ignoring package."));
} }
#endif #endif
break; break;
@ -552,11 +560,15 @@ bool SBNetwork::sendPairingAck(SBMacAddress mac){
bool SBNetwork::checkMaster(){ bool SBNetwork::checkMaster(){
if (this->RunAsClient) { if (this->RunAsClient) {
if (this->pingDevice(this->NetworkDevice.MasterMAC)) { if (this->pingDevice(this->NetworkDevice.MasterMAC)) {
#ifdef _DEBUG
Serial.println("Master OK"); Serial.println("Master OK");
#endif
return true; return true;
} }
else { else {
#ifdef _DEBUG
Serial.println("Master ERROR"); Serial.println("Master ERROR");
#endif
return false; return false;
} }
} }

View File

@ -2,7 +2,7 @@
#ifndef _SB_NETWORK_ #ifndef _SB_NETWORK_
#define _SB_NETWORK_ #define _SB_NETWORK_
#define SB_VERSION "1.0.1" #define SB_VERSION "1.0.2"
#include <RF24_config.h> #include <RF24_config.h>
#include <RF24.h> #include <RF24.h>

View File

@ -5,7 +5,7 @@
// Uncomment the following line, to compile the library for a master device. // Uncomment the following line, to compile the library for a master device.
//#define RUN_AS_MASTER //#define RUN_AS_MASTER
#define _DEBUG //#define _DEBUG
#define MASTER_CHECK_INTERVAL 0 // All sensors will ping the master every xxx milliseconds. if set to 0, they will not ping the master #define MASTER_CHECK_INTERVAL 0 // All sensors will ping the master every xxx milliseconds. if set to 0, they will not ping the master