portado para MBED OS 6

Dependents:   Navitec-Firmware

Revision:
11:49f6346e02d7
Parent:
6:06522f3a6642
--- a/XBee/XBee.cpp	Tue Nov 06 16:42:26 2018 +0000
+++ b/XBee/XBee.cpp	Sun Apr 04 14:38:34 2021 +0000
@@ -82,7 +82,7 @@
         _reset = new DigitalOut(reset, 1);
     }
 
-    _uart = new RawSerial(tx, rx);
+    _uart = new UnbufferedSerial(tx, rx);
     _uart->baud(baud);
 
     _serial_flow_type = SerialBase::Disabled;
@@ -99,7 +99,8 @@
     }
 #endif
     /* Enable the reception of bytes on the serial interface by providing a cb */
-    _uart->attach(this, &XBee::uart_read_cb, Serial::RxIrq);
+    //_uart->attach(this, &XBee::uart_read_cb, Serial::RxIrq);
+    _uart->attach(callback(this,&XBee::uart_read_cb), SerialBase::RxIrq);
 
     for (int i = 0; i < MAX_FRAME_HANDLERS; i++) {
         _fhandlers[i] = NULL;
@@ -204,7 +205,8 @@
         volatile uint16_t * const rst_cnt_p = &_hw_reset_cnt;
         const uint16_t init_rst_cnt = *rst_cnt_p;
         *_reset = 0;
-        wait_ms(10);
+        //wait_ms(10);
+        ThisThread::sleep_for(chrono::milliseconds(10));
         *_reset = 1;
         return wait_for_module_to_reset(rst_cnt_p, init_rst_cnt);
     }
@@ -226,8 +228,11 @@
     Timer timer = Timer();
     timer.start();
 
-    while (*rst_cnt_p == init_rst_cnt && timer.read_ms() < RESET_TIMEOUT_MS) {
-        wait_ms(100);
+    //while (*rst_cnt_p == init_rst_cnt && timer.read_ms() < RESET_TIMEOUT_MS) {
+    //wait_ms(100);
+    while (*rst_cnt_p == init_rst_cnt && timer.elapsed_time().count() < RESET_TIMEOUT_MS) {
+     
+        ThisThread::sleep_for(chrono::milliseconds(100));
     }
 
     if (*rst_cnt_p == init_rst_cnt) {
@@ -249,7 +254,9 @@
     static FrameBuffer * framebuf = NULL;
 
     while (_uart->readable()) {
-        uint8_t data = _uart->getc();
+        //uint8_t data = _uart->getc();
+        uint8_t data;
+        _uart->read(&data, 1);
 
         if (IS_API2() && rxstate != WAITING_FOR_START_FRAME) {
             if (last_byte_escaped) {
@@ -499,23 +506,28 @@
     Timer timer = Timer();
     timer.start();
 
-    while (timer.read_ms() < _timeout_ms) {
+    //while (timer.read_ms() < _timeout_ms) {
+    while (timer.elapsed_time().count() < _timeout_ms) {
+        
         ApiFrame * frame = _framebuf_syncr.get_next_complete_frame();
         if (frame == NULL) {
-            wait_ms(10);
+            //wait_ms(10);
+            ThisThread::sleep_for(chrono::milliseconds(10));
             continue;
         }
 
         if ((frame->get_frame_type() != type) &&
             (frame->get_frame_type() != type2)) {
             _framebuf_syncr.complete_frame(frame);
-            wait_ms(1);
+            //wait_ms(1);
+            ThisThread::sleep_for(chrono::milliseconds(1));
             continue;
         }
 
         if (frame->get_data_at(ATCMD_RESP_FRAME_ID_OFFSET) != id) {
             _framebuf_syncr.complete_frame(frame);
-            wait_ms(1);
+            //wait_ms(1);
+            ThisThread::sleep_for(chrono::milliseconds(1));
             continue;
         }
 
@@ -536,14 +548,18 @@
             case DR_ESCAPE_BYTE:
             case DR_XON_BYTE:
             case DR_XOFF_BYTE:
-                _uart->putc(DR_ESCAPE_BYTE);
-                _uart->putc(data ^ DR_ESCAPE_XOR_BYTE);
+                //_uart->putc(DR_ESCAPE_BYTE);
+                //_uart->putc(data ^ DR_ESCAPE_XOR_BYTE);
+                _uart->write((uint8_t *)DR_ESCAPE_BYTE, 1);
+                _uart->write((uint8_t *)(data ^ DR_ESCAPE_XOR_BYTE),1);
                 break;
             default:
-                _uart->putc(data);
+                //_uart->putc(data);
+               _uart->write(&data,1);
         }
     } else {
-        _uart->putc(data);
+        //_uart->putc(data);
+        _uart->write(&data,1);
     }
 }
 
@@ -559,7 +575,8 @@
     data = frame->get_data();
 
     /* Send the start of frame delimiter */
-    _uart->putc(DR_START_OF_FRAME);
+    //_uart->putc(DR_START_OF_FRAME);
+    _uart->write((uint8_t *)DR_START_OF_FRAME,1);
 
     /* Now the length */
     send_byte_escaping_if((uint8_t)(frame_len >> 8));