few changes for RTS/CTS control

Dependencies:   MTS-Serial libmDot mbed-rtos mbed

Fork of mDot_AT_firmware by MultiTech

Files at this revision

API Documentation at this revision

Comitter:
serg838
Date:
Tue Oct 25 05:39:39 2016 +0000
Parent:
10:6a12bf1f6723
Commit message:
RTS/CTS changes

Changed in this revision

ATSerialFlowControl.cpp Show annotated file Show diff for this revision Revisions of this file
ATSerialFlowControl.h Show annotated file Show diff for this revision Revisions of this file
CommandTerminal/CmdSendBinary.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ATSerialFlowControl.cpp	Mon Apr 04 16:37:01 2016 +0000
+++ b/ATSerialFlowControl.cpp	Tue Oct 25 05:39:39 2016 +0000
@@ -10,6 +10,7 @@
     , rxReadyFlag(false)
     , rts(RTS)
     , cts(CTS)
+    , dtr(PA_11)
 {
     notifyStartSending();
 
@@ -59,7 +60,21 @@
 }
 
 void ATSerialFlowControl::handleWrite()
-{
-    ATSerial::handleWrite();
+{  
+     while(txBuffer.size() != 0) {        
+        if (serial.writeable() && cts.read() == 0) {  
+            dtr.write(0);                  
+            char byte;
+            if(txBuffer.read(byte) == 1) {
+                serial.attach(NULL, Serial::RxIrq);
+                serial.putc(byte);
+                serial.attach(this, &ATSerialFlowControl::handleRead, Serial::RxIrq);
+            }
+        } 
+        else { 
+            if (cts.read() == 1) dtr.write(1);             
+            return;
+        }
+    }
 }
 
--- a/ATSerialFlowControl.h	Mon Apr 04 16:37:01 2016 +0000
+++ b/ATSerialFlowControl.h	Tue Oct 25 05:39:39 2016 +0000
@@ -46,6 +46,7 @@
     
     //This device acts as a DTE
     bool rxReadyFlag;   //Tracks state change for rts signaling
+    DigitalOut dtr;
     DigitalOut rts; // Used to tell DCE to send or not send data
     DigitalIn cts; // Used to check if DCE is ready for data
     int highThreshold; // High water mark for setting cts to stop
--- a/CommandTerminal/CmdSendBinary.cpp	Mon Apr 04 16:37:01 2016 +0000
+++ b/CommandTerminal/CmdSendBinary.cpp	Tue Oct 25 05:39:39 2016 +0000
@@ -36,8 +36,17 @@
     if (_dot->getTxWait() && _dot->recv(data) == mDot::MDOT_OK) {
         if (!data.empty()) {
             if (_dot->getVerbose())
-                _serial.writef("Packet data:\r\n");
-            _serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str());
+                _serial.writef("Packet data:\r\n");            
+            
+                 if (_dot->getRxOutput() == mDot::HEXADECIMAL) {
+                    for (size_t i = 0; i < data.size(); i++) {
+                         _serial.writef("%02x", data[i]);
+                    }
+                     _serial.writef("\r\n");
+                } else {
+                    _serial.writef("%s\r\n", CommandTerminal::formatPacketData(data, _dot->getRxOutput()).c_str());
+                }
+            
         }
     }
 
--- a/main.cpp	Mon Apr 04 16:37:01 2016 +0000
+++ b/main.cpp	Tue Oct 25 05:39:39 2016 +0000
@@ -4,7 +4,7 @@
 #include "ATSerial.h"
 #include "ATSerialFlowControl.h"
 
-#define SERIAL_BUFFER_SIZE 512
+#define SERIAL_BUFFER_SIZE 1024
 
 mts::ATSerial debug(USBTX, USBRX);
 
@@ -19,7 +19,7 @@
 
     mts::ATSerial* serial;
 
-    if (dot->getFlowControl())
+    if (true)//(dot->getFlowControl())
         serial = new mts::ATSerialFlowControl(XBEE_DOUT, XBEE_DIN, XBEE_RTS, XBEE_CTS, SERIAL_BUFFER_SIZE, SERIAL_BUFFER_SIZE);
     else
         serial = new mts::ATSerial(XBEE_DOUT, XBEE_DIN, SERIAL_BUFFER_SIZE, SERIAL_BUFFER_SIZE);