#include "Xbee.h" #include "common.h" #include "usart.h" #include #include char xbee_compute_checksum(char *buffer, int length); static void xbee_debug_send(int address, char *str); int xbeeSend(int addr_destination, char *str) { int i; char buffer[TRAME_SIZE_SEND]; #ifdef __DEBUG__ //xbee_debug_send(addr_destination, str); #endif /* __DEBUG__ */ /* Allocation d'un buffer suffisant */ if ((addr_destination>0xFFFF) || (addr_destination<0)) return XBEE_INVALID_ADDRESS; /* Remplissage du buffer */ buffer[0] = 0x7E; buffer[1] = 0; buffer[2] = 7; buffer[3] = 0x01; buffer[4] = 0; // frame id set to 0 to disable ack buffer[5] = addr_destination>>8; buffer[6] = addr_destination&0xFF; buffer[7] = 0x0; for (i=0; i<3; i++){ if((str[i]== 0x7E) ||(str[i]== 0x11) ||(str[i]== 0x13)){ buffer[8+i] = str[i] + 1; } else if(str[i] == 0x7D){ buffer[8+i]=str[i] + 2; } else { buffer[8+i] = str[i]; } } buffer[TRAME_SIZE_SEND - 1]=xbee_compute_checksum(buffer, TRAME_SIZE_SEND-1); //HAL_UART_Transmit_DMA(&huart1,(uint8_t *)buffer, TRAME_SIZE); HAL_UART_Transmit(&huart1,(uint8_t *)buffer, TRAME_SIZE_SEND,1000); return XBEE_SUCCESS; } char xbee_compute_checksum(char *buffer, int length){ int i; unsigned char checksum=0; for (i =3; i