Did some corrections regarding the new ping method. Now everything should work as mentioned.

This commit is contained in:
Marcel Schulz 2017-12-15 00:03:49 +01:00
parent bb6da7e5d7
commit 21e31893f2
4 changed files with 38 additions and 22 deletions

View File

@ -1,5 +1,5 @@
name=SBNetwork
version=1.0.3
version=1.0.4
author=Schullebernd,schullebernd@googlemail.com
maintainer=Schullebernd,schullebernd@googlemail.com
sentence=Build simple master/client networks with nRF24L01 transmitter.

View File

@ -408,28 +408,14 @@ bool SBNetwork::connectToNetwork(){
}
bool bMasterAvailable = this->pingDevice(this->NetworkDevice.MasterMAC);
if (bMasterAvailable) {
long lNow = millis();
SBNetworkFrame pingAckFrame;
while ((lNow + 100) > millis()) {
if (this->receiveInternal(&pingAckFrame)) {
if (pingAckFrame.Header.CommandType == SB_COMMAND_PING) {
Serial.println(F("Done - Master available"));
return true;
}
}
}
Serial.println(F("Failed - Master not responding"));
}
Serial.println("Error - Sending Ping to Master");
return false;
return bMasterAvailable;
}
else {
return false;
}
}
bool SBNetwork::pingDevice(SBMacAddress mac){
bool SBNetwork::pingDeviceInternal(SBMacAddress mac, bool waitForAck) {
SBNetworkHeader header;
header.ToAddress = mac;
header.FromAddress = this->NetworkDevice.MAC;
@ -443,7 +429,35 @@ bool SBNetwork::pingDevice(SBMacAddress mac){
frame.Message = NULL;
frame.MessageSize = 0;
return this->sendToDevice(frame);
bool bSend = this->sendToDevice(frame);
if (bSend) {
if (waitForAck) {
long lNow = millis();
SBNetworkFrame pingAckFrame;
while ((lNow + 100) > millis()) {
if (this->receiveInternal(&pingAckFrame)) {
if (pingAckFrame.Header.CommandType == SB_COMMAND_PING) {
Serial.println(F("Done - Device available"));
return true;
}
}
}
#if defined(_DEBUG)
Serial.println(F("Failed - Device not responding"));
#endif
return false;
}
}
#if defined(_DEBUG)
else {
Serial.println("Failed - Device not responding");
}
#endif
return bSend;
}
bool SBNetwork::pingDevice(SBMacAddress mac){
return pingDeviceInternal(mac, true);
}
bool SBNetwork::handleCommandPackage(SBNetworkFrame *frame){
@ -473,7 +487,7 @@ bool SBNetwork::handleCommandPackage(SBNetworkFrame *frame){
Serial.println(F("Received 'PING'"));
#endif
if (bFound) {
pingDevice(frame->Header.FromAddress);
pingDeviceInternal(frame->Header.FromAddress, false);
}
break;
}
@ -614,7 +628,7 @@ void SBNetwork::update(){
if (NetworkDevice.ConnectedToMaster && MASTER_CHECK_INTERVAL) {
if (_Uptime > _NextCheck) {
// Now we have to check our sensors if they are still available
_NextCheck += MASTER_CHECK_INTERVAL;
_NextCheck = _Uptime + MASTER_CHECK_INTERVAL;
checkMaster();
}
}

View File

@ -2,7 +2,7 @@
#ifndef _SB_NETWORK_
#define _SB_NETWORK_
#define SB_VERSION "1.0.3"
#define SB_VERSION "1.0.4"
#include <RF24_config.h>
#include <RF24.h>
@ -80,6 +80,8 @@ class SBNetwork{
bool receiveMessage(void **message, uint8_t *messageSize, SBMacAddress *mac);
bool pingDeviceInternal(SBMacAddress mac, bool waitForAck);
public:
/*
* Define the standard addresses for the sensor network

View File

@ -7,7 +7,7 @@
//#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 slaves will ping the master every xxx milliseconds. if set to 0, they will not ping the master
#define MAX_CLIENTS 10