La suite du code parce que tout ne rentrer pas :
/*------------------------------------------------------------------------------------FONCTIONS RF12-----------------------------------------------------------------------------*/
/*
* Try to decode the CRC from the packet to check
* if it's a TX29 one.
*
* Protocol : http://fredboboss.free.fr/tx29/
* Implementation : http://gcrnet.net/node/32
*/
boolean CheckITPlusCRC() {
byte nbBytes = 5;
byte reg = 0;
byte curByte, curbit, bitmask;
byte do_xor;
while (nbBytes != 0) {
curByte = rf12_buf[5-nbBytes];
nbBytes--;
bitmask = 0b10000000;
while (bitmask != 0) {
curbit = ((curByte & bitmask) == 0) ? 0 : 1;
bitmask >>= 1;
do_xor = (reg & 0x80);
reg <<=1;
reg |= curbit;
if (do_xor) {
reg ^= CRC_POLY;
}
}
}
return (reg == 0);
}
/*
* The CRC has been check, this method decode the TX29
* packet to extract the data, then store it into the
* sensors array.
*/
int ReadITPlusValue() {
byte temp, decimalTemp, sensorId, resetFlag, hygro, weakBatt;
int pos = -1;
sensorId = (((rf12_buf[0] & 0x0f) << 4) + ((rf12_buf[1] & 0xf0) >> 4)) & 0xfc;
// Reset flag is stored as bit #6 in sensorID.
resetFlag = (rf12_buf[1] & 0b00100000) << 1;
temp = (((rf12_buf[1] & 0x0f) * 10) + ((rf12_buf[2] & 0xf0) >> 4));
decimalTemp = rf12_buf[2] & 0x0f;
// IT+ add a 40° offset to temp, so < 40 means negative
if (temp >= 40) {
temp -= 40;
} else {
if (decimalTemp == 0) {
temp = 40 - temp;
} else {
temp = 39 - temp;
decimalTemp = 10 - decimalTemp;
}
// Sign bit is stored into bit #7 of temperature.
temp |= 0b10000000;
}
//weak battery indicator is the first bit, the rest is hygro
weakBatt = rf12_buf[3] & 0x80;
hygro = rf12_buf[3] & 0x7f;
//check the Sensors array to find a empty space
for (int i = 0 ; i < MAX_SENSORS && pos < 0 ; i++) {
if (sensors[i].sensorId == 0 || sensors[i].sensorId == sensorId) {
//that's a free space, store values in it
pos = i;
sensors[i].sensorId = sensorId;
sensors[i].temp = temp;
sensors[i].decimalTemp = decimalTemp;
sensors[i].hygro = hygro;
sensors[i].resetFlag = resetFlag;
sensors[i].weakBatt = weakBatt;
}
}
}
/*
* Print a number into hex format
*/
void printHex(byte data) {
if (data < 16) Serial.print('0');
Serial.print(data, HEX);
}
/*------------------------------------------------------------------------------------FONCTIONS ETHERNET-------------------------------------------------------------------------*/
void XML_response(EthernetClient cl)
{
//lecture du code sur le RF12
if (rf12_recvDone())
{
//we receive a packet, let's check if it's an IT+ one
if (ITPlusFrame && CheckITPlusCRC())
{
ReadITPlusValue();
}
}
//int analog_val;
cl.print("<?xml version = \"1.0\" ?>");
cl.print("<inputs>");
// read analog pin A2
//analog_val = analogRead(2);
cl.print("<analog>");
//cl.print(analog_val);
cl.print(sensors[0].temp & 0x7f, DEC);
cl.print(".");
cl.println(sensors[0].decimalTemp, DEC);
cl.print("</analog>");
cl.print("<analog>");
//cl.print(analog_val);
cl.print(sensors[1].temp & 0x7f, DEC);
cl.print(".");
cl.println(sensors[1].decimalTemp, DEC);
cl.print("</analog>");
cl.print("</inputs>");
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
for (int i = 0; i < length; i++) {
str[i] = 0;
}
}
// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}
return 0;
}