Did some corrections regarding the new ping method. Now everything should work as mentioned.
This commit is contained in:
parent
bb6da7e5d7
commit
21e31893f2
@ -1,5 +1,5 @@
|
|||||||
name=SBNetwork
|
name=SBNetwork
|
||||||
version=1.0.3
|
version=1.0.4
|
||||||
author=Schullebernd,schullebernd@googlemail.com
|
author=Schullebernd,schullebernd@googlemail.com
|
||||||
maintainer=Schullebernd,schullebernd@googlemail.com
|
maintainer=Schullebernd,schullebernd@googlemail.com
|
||||||
sentence=Build simple master/client networks with nRF24L01 transmitter.
|
sentence=Build simple master/client networks with nRF24L01 transmitter.
|
||||||
|
@ -408,28 +408,14 @@ bool SBNetwork::connectToNetwork(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool bMasterAvailable = this->pingDevice(this->NetworkDevice.MasterMAC);
|
bool bMasterAvailable = this->pingDevice(this->NetworkDevice.MasterMAC);
|
||||||
if (bMasterAvailable) {
|
return 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;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SBNetwork::pingDevice(SBMacAddress mac){
|
bool SBNetwork::pingDeviceInternal(SBMacAddress mac, bool waitForAck) {
|
||||||
SBNetworkHeader header;
|
SBNetworkHeader header;
|
||||||
header.ToAddress = mac;
|
header.ToAddress = mac;
|
||||||
header.FromAddress = this->NetworkDevice.MAC;
|
header.FromAddress = this->NetworkDevice.MAC;
|
||||||
@ -443,7 +429,35 @@ bool SBNetwork::pingDevice(SBMacAddress mac){
|
|||||||
frame.Message = NULL;
|
frame.Message = NULL;
|
||||||
frame.MessageSize = 0;
|
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){
|
bool SBNetwork::handleCommandPackage(SBNetworkFrame *frame){
|
||||||
@ -473,7 +487,7 @@ bool SBNetwork::handleCommandPackage(SBNetworkFrame *frame){
|
|||||||
Serial.println(F("Received 'PING'"));
|
Serial.println(F("Received 'PING'"));
|
||||||
#endif
|
#endif
|
||||||
if (bFound) {
|
if (bFound) {
|
||||||
pingDevice(frame->Header.FromAddress);
|
pingDeviceInternal(frame->Header.FromAddress, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -614,7 +628,7 @@ void SBNetwork::update(){
|
|||||||
if (NetworkDevice.ConnectedToMaster && MASTER_CHECK_INTERVAL) {
|
if (NetworkDevice.ConnectedToMaster && MASTER_CHECK_INTERVAL) {
|
||||||
if (_Uptime > _NextCheck) {
|
if (_Uptime > _NextCheck) {
|
||||||
// Now we have to check our sensors if they are still available
|
// Now we have to check our sensors if they are still available
|
||||||
_NextCheck += MASTER_CHECK_INTERVAL;
|
_NextCheck = _Uptime + MASTER_CHECK_INTERVAL;
|
||||||
checkMaster();
|
checkMaster();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#ifndef _SB_NETWORK_
|
#ifndef _SB_NETWORK_
|
||||||
#define _SB_NETWORK_
|
#define _SB_NETWORK_
|
||||||
|
|
||||||
#define SB_VERSION "1.0.3"
|
#define SB_VERSION "1.0.4"
|
||||||
|
|
||||||
#include <RF24_config.h>
|
#include <RF24_config.h>
|
||||||
#include <RF24.h>
|
#include <RF24.h>
|
||||||
@ -80,6 +80,8 @@ class SBNetwork{
|
|||||||
|
|
||||||
bool receiveMessage(void **message, uint8_t *messageSize, SBMacAddress *mac);
|
bool receiveMessage(void **message, uint8_t *messageSize, SBMacAddress *mac);
|
||||||
|
|
||||||
|
bool pingDeviceInternal(SBMacAddress mac, bool waitForAck);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
* Define the standard addresses for the sensor network
|
* Define the standard addresses for the sensor network
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
//#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 slaves will ping the master every xxx milliseconds. if set to 0, they will not ping the master
|
||||||
|
|
||||||
#define MAX_CLIENTS 10
|
#define MAX_CLIENTS 10
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user