serial debug Monitor

Files at this revision

API Documentation at this revision

Comitter:
duchonic
Date:
Thu Aug 23 17:53:34 2018 +0000
Parent:
0:de1f07a7cd82
Commit message:
serial communication tx/rx works

Changed in this revision

debugMonitor.cpp Show annotated file Show diff for this revision Revisions of this file
debugMonitor.h Show annotated file Show diff for this revision Revisions of this file
--- a/debugMonitor.cpp	Thu Aug 23 10:32:26 2018 +0000
+++ b/debugMonitor.cpp	Thu Aug 23 17:53:34 2018 +0000
@@ -1,22 +1,50 @@
 #include "debugMonitor.h"
 #include "main.h"
 
-debugMonitor::debugMonitor(PinName tx, PinName rx) : serial(tx, rx) {}
+
+using namespace std;
+
+debugMonitor::debugMonitor(PinName tx, PinName rx) : serial(tx, rx) {
+  commando = "";    
+}
 
 uint8_t debugMonitor::debugMonitor_Init(void)
 {
     serial.baud(115200);
-    serial.printf("debugMonitor_Init\n");
+    //serial.printf("debugMonitor_Init\n");
+    printLine("debugMonitor_Init()");
+    
+    serial.attach(this, &debugMonitor::readLineCallback);
+    
     return(0);
 }
 
 debugMonitor::~debugMonitor(void) {
 };
 
-void debugMonitor::debugMonitor_Job(void)
+/** Private Functions */
+
+void debugMonitor::readLineCallback()
 {
-    if(serial.readable())
+    char inputChar = serial.getc();
+    
+    if(commando == "test")
     {
-        serial.putc(serial.getc());
+        printLine("cmd was test");
     }
+    
+    commando += inputChar;
+    
+    if(inputChar == '\r')
+    {
+        commando = "";
+        serial.putc('\n');
+    }
+    serial.putc(inputChar);
+}
+
+void debugMonitor::printLine(char *string_p)
+{
+    serial.printf(string_p);
+    serial.printf("\r\n");   
 }
\ No newline at end of file
--- a/debugMonitor.h	Thu Aug 23 10:32:26 2018 +0000
+++ b/debugMonitor.h	Thu Aug 23 17:53:34 2018 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include <string>
 
 class debugMonitor
 {
@@ -20,16 +21,13 @@
         * @returns -1 on error
         */
         uint8_t debugMonitor_Init(void);
-  
-        /**
-        * @param led led to set
-        * @param color color to set
-        */
-        void debugMonitor_Job(void);
-  
-
+        
   private:
         /** i2c handler */
         Serial serial;
-      
-};
\ No newline at end of file
+        string commando;
+        void printLine(char *string_p);
+        void readLineCallback();  
+};
+
+