Bonjour à tous, je bloque sur un truc bête ![]()
Je cherche la présence d'une string dans une autre (message UDP) et bien ca soit basique ca fait planter mon programme qui reboot dés que j'essaye de manipuler les strings.
Au début je pensais que cela venait de caractères spéciaux présents mais je m'aperçois que non et qu'en sortant la ligne de commande d'une condition donnée ca marche :~
Ci dessous mon code modifié avec un exemple (j'ai fait un copier/coller de ce bout de code test sur les string) :
//test string
String stringOne = "/1/push1/z";
int firstClosingBracket = stringOne.indexOf("push1");
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
//fin de test
Quand il est dans dans la condition :
if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
}
ca fait planter mon code, par contre si je le sors de la condition ca passe très bien !?
Help .... je suis à court d'idée là =(
Le code avec le commentaire :
#include "EtherShield.h"
uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x25};
uint8_t myip[4] = {192,168,1,25};
uint16_t MYWWWPORT = 80;
uint16_t outgoingport = 12345;
#define BUFFER_SIZE 750
static uint8_t buf[BUFFER_SIZE+1];
char reply[]="00000000";
String UDPMsg;
char c;
EtherShield es=EtherShield();
uint16_t plen, dat_p;
static uint8_t udp_length;
static uint8_t udp_buffer[50];
///----------------------------------------------------------
void setup(){
Serial.begin(9600);
Setup_Pins();
es.ES_enc28j60Init(mymac);
es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
Serial.println("Start");
} // end setup
///----------------------------------------------------------
void loop(){
// read packet, handle ping and wait for a tcp packet:
dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
//Serial.println(buf[IP_PROTO_P]);
udp_length=buf[39]-16; // calculate UDP data lenght
// udp_length=buf[39]-8; // calculate UDP data lenght
for (int i = 0; i < udp_length; i++)
{
//Serial.write(buf[42+i]);
c = buf[42+i];
UDPMsg += c;
}//end for
Serial.println(UDPMsg);
//test string -> ca fait planter mon code
String stringOne = "/1/push1/z";
int firstClosingBracket = stringOne.indexOf("push1");
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
//fin de test
//Relay_Control();
//Status_Reply();
//es.ES_make_udp_reply_from_request(buf,reply,8,outgoingport);
buf[IP_PROTO_P]=0;
UDPMsg="";
} //end if
//test string -> ca marche
String stringOne = "/1/push1/z";
int firstClosingBracket = stringOne.indexOf("push1");
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
//fin de test
} // end loop