LSE_PUCRS / Mbed 2 deprecated XBEE_capada

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
giovanniwsn
Date:
Sun Oct 14 05:56:14 2018 +0000
Parent:
0:7c9e8aaa85d4
Commit message:
removido os comentarios, codigo limpo

Changed in this revision

XBEE/XBEE.cpp Show annotated file Show diff for this revision Revisions of this file
XBEE/XBEE.h Show annotated file Show diff for this revision Revisions of this file
--- a/XBEE/XBEE.cpp	Sun Oct 14 05:47:42 2018 +0000
+++ b/XBEE/XBEE.cpp	Sun Oct 14 05:56:14 2018 +0000
@@ -4,7 +4,6 @@
 XBEE::XBEE(Serial* serial, int baud):xbee(serial)
 {
     xbee->baud(baud);
-    /* Enable the reception of bytes on the serial interface by providing a cb */
     xbee->attach(callback(this, &XBEE::recvAttach), Serial::RxIrq);
     init();
 }
@@ -19,14 +18,10 @@
 }
 
 /* Send message to the destination */
-//int XBEE::send_msg(char * str, int dest)
 int XBEE::send_msg(char * str)
 {
     int n = strlen(str);
-    if(n > 92) {
-        return -1;
-    }
-    //create_TX(str,dest);
+    if(n > 92) return -1;
     create_TX(str);
     sendBuffer();
     wait(0.2);
@@ -40,20 +35,17 @@
     int i;
     int ptam = 0;
     int j = 0;
-    
     memset(buf,0,tam);
     
     for(i = 0; i < count_rx; i++) {
         if(buf_rx[i] == 0x7E) {
-            
             p = (pkt_tx *) &buf_rx[i];
-            
             if(p->frame_type == 0x90) {
                 ptam = p->length - 0x0C;
                 if(tam < ptam + j) {
                     return -1;
                 }
-                // posicao aonde comeca a msg em um pacote de Receive
+                // posicao aonde comeca msg
                 memcpy(&buf[j], ((char *)(&p->broadcast_radius)), ptam);
                 j += ptam;
             }
@@ -65,11 +57,10 @@
 /* Chamada por Interrupcao, RX */
 void XBEE::recvAttach (void) 
 {
-    //if (serial_RX_ctrl == 1)
-        while(xbee->readable()) {
-            buf_rx[count_rx%sizeof(buf_rx)] = xbee->getc();
-            count_rx++;
-        }
+    while(xbee->readable()) {
+        buf_rx[count_rx%sizeof(buf_rx)] = xbee->getc();
+        count_rx++;
+    }
 }
 
 /* Envia pacote do buffer_tx */
@@ -79,26 +70,18 @@
         for(int i = 0; i < count_tx; i++) {
             xbee->putc(buf_tx[i]);
         }
-        //pode zerar pacote aqui
     }
 }
 
 /* Cria pacote de mensagem */
-//int XBEE::create_TX(char * str, int dest)
 int XBEE::create_TX(char * str)
 {
     int i = 0;
     int n = strlen(str);
     uint8_t count = 0;
-
     pkt_tx *p = (pkt_tx *) buf_tx; // ponteiro para buffer global
     
-
-    if(n > 92) {
-        // Error: data nao pode exceder 92 bytes
-        return -1;
-    }
-
+    if(n > 92) return -1; // nao pode exceder 92 bytes
     count_tx = 0;
     memset(&buf_tx,0,sizeof(buf_tx));
 
@@ -106,92 +89,20 @@
     p->length = 0x0E + n;   // pacote vazio + dados
     p->frame_type = 0x10;   // transmit request
     p->frame_id = 1;
-
-    //if(dest == XBEE_COORD) {
-        p->dest_addr64[6] = 0x00;   //SL_H
-        p->dest_addr64[7] = 0x00;   //SL_L
-    /*} else if(dest == XBEE_BROAD) {
-        p->dest_addr64[6] = 0xFF;   //SL_H
-        p->dest_addr64[7] = 0xFF;   //SL_L
-    } else {
-        p->dest_addr64[0] = 0x00;
-        p->dest_addr64[1] = 0x13;
-        p->dest_addr64[2] = 0xA2;
-        p->dest_addr64[3] = 0x00;
-        
-        p->dest_addr64[4] = (dest >> 24);
-        p->dest_addr64[5] = (dest & 0x00FF0000) >> 16;
-        p->dest_addr64[6] = (dest & 0x0000FF00) >> 8;
-        p->dest_addr64[7] = (dest & 0x000000FF);
-    } */
+    p->dest_addr64[6] = 0x00;   //SL_H
+    p->dest_addr64[7] = 0x00;   //SL_L
     p->dest_addr16[0] = 0xFF;   //MY_H
     p->dest_addr16[1] = 0xFF;   //MY_L
-    
     memcpy(&p->rf_data, str, n);
 
-    // Calcula Checksum
-
-    // comeca 3 pra frente, tenq passar 3 adiante no final
-    // para ler o mesmo tamanho de pacote
-    for(i = 3; i < p->length + 3; i++) {
-        count += buf_tx[i];
-        //printf("\n%d\n", count);
-    }
+    // Calc. Checksum: comeca 3 pra frente, tenq passar 3 adiante no final
+    for(i = 3; i < p->length + 3; i++) count += buf_tx[i];
+    
     count = 0xFF - count;
-
     p->rf_data[n] = count;
 
     //p->length tem o tamanho soh do frame, 
     //pacote total eh o starter + length alto + length baixo + checksum
     count_tx = p->length + 4;
     return count_tx;
-}
-
-/* Active or Desactive Serial RX */
-/*
-void XBEE::read_active(uint8_t val){
-    serial_RX_ctrl = val;
-}*/
-
-/* Printa todo o buffer de Receive, e limpa */
-/*
-void XBEE::printBuffer(void) 
-{
-    char flag_msg = 0;
-    int size = sizeof(buf_rx);
-    if(count_rx < size) {
-        size = count_rx;
-    }
-    for(int i = 0; i < size; i++) {
-        printf("%c", buf_rx[i]);
-        flag_msg++;
-    }
-    if (flag_msg) {
-        printf("\n");
-    }
-    
-    //Limpa buffer
-    count_rx = 0;
-    memset(&buf_rx,0,sizeof(buf_rx));
-} 
-*/
-
-// Verify Packet Checksum return 0 if msg OK, just work with Transmit Package
-/*
-char XBEE::validPackage(uint8_t * buf, int tam) 
-{
-    int i = 0;
-    uint8_t count = 0;
-    
-    if(buf[0] != 0x7E) return 1;
-    if(buf[1] != 0) return 2;
-    if(buf[2] != tam-4) return 3;
-    
-    for(i = 3; i < tam; i++) {
-        count += buf[i];
-    }
-    if(count != 0xFF) return 4;
-    
-    return 0; // OK
-}
-*/
+}
\ No newline at end of file
--- a/XBEE/XBEE.h	Sun Oct 14 05:47:42 2018 +0000
+++ b/XBEE/XBEE.h	Sun Oct 14 05:56:14 2018 +0000
@@ -13,11 +13,6 @@
 
 #define XB_SIZEBUF  64
 
-//#define XBEE_COORD  0
-//#define XBEE_BROAD  1
-
-//#define XBEE_NAME   "R1"
-
 // para poder declarar como typedef
 typedef struct __attribute__ ((__packed__)) {
     uint8_t start_delimiter;
@@ -33,7 +28,6 @@
     uint8_t rf_data[100]; //NOTE: last byte MUST be checksum
 }pkt_tx;
 
-// Classe para controlar XBEE Zigbee usando API
 class XBEE {
     public:
         char buf_tx[XB_SIZEBUF];     // Serial TX
@@ -45,20 +39,13 @@
         
         // High Level Function
         void init (void);
-        //int send_msg(char * str, int dest);
         int send_msg(char * str);
         int recv_msg(char * buf, int tam);
         
         // Low Level Function
         void recvAttach (void);
         void sendBuffer(void);
-        //int create_TX(char * str, int dest);
         int create_TX(char * str);
-        //void read_active(uint8_t val);
-        
-        // Auxiliar Function
-        //void printBuffer(void);
-        //char validPackage (uint8_t * buf, int tam);
         
     protected:
         Serial* xbee;