Hi guys, I've been really diligent to solve this problem and I have to appreciate your help. A good news is that 50% of the problem was solved. In the code I changed what you suggested below on methods "converteBeaconParaString", "enviaBeacon" and "converteStringParaBeacon". Look that in the last now I looking for the "#" ah hand an
#include "Service.h"
#include "Beacon.h"
#include <stdio.h>
#include <string.h>
short meu_id; //identificação do no raiz
//Estrutura do pacote de controle
Service::Service() {
}
Service::~Service() {/*nothing to destruct*/
}
void Service::enviaBeacon(Beacon beacon) {
if(beacon.getDhost() != 0){
converteBeaconParaString(beacon);
}
}
Beacon Service::recebeBeacon(short id) {
Beacon beacon;
String msg;
while(Serial.available() > 0) {
byte temp = Serial.read();
if (temp != 255){
msg = msg + (char) temp;
}
}
if (msg.length() > 0) {
beacon = converteStringParaBeacon(msg);
delay(1000);
Serial.flush();
if (verificaMensagemBeacon(beacon,id)) {
return beacon;
}
}
return beacon;
}
void Service::converteBeaconParaString(Beacon beacon){
Serial.print(beacon.getDhost());
Serial.print("#");
Serial.print(beacon.getShost());
Serial.print("#");
Serial.println(beacon.getSALTO());
}
Beacon Service::converteStringParaBeacon(String msg) {
int c=0;
int i=0;
short vet[3];
Beacon beacon;
while (msg[i] == '\0') {
if (msg[i] != '#') {
vet[c] = vet[c] * 10 + (msg[i] - '0');
}
else {
c = c + 1;
}
i = i + 1;
}
beacon.setDhost(vet[0]);
beacon.setShost(vet[1]);
beacon.setSALTO(vet[2]);
return beacon;
}
bool Service::verificaMensagemBeacon(Beacon beacon, short id) {
if (beacon.getDhost() == id) {
return true;
}
return false;
}
Now, when I send the information from ard_8 -> ard_5, I get what I wanted (2#1#0+1). 50% of the problem solved!!!!
HOWEVER, when I get this information (2#1#0+1) and change de destination for ard_x, the thrird arduino, I get like this (76656#56663#88877)
Really, annoying!!!
Any suggestion?
Thanks a lot folks.