Janus Erasmus / Console

Dependents:   Nucleo_blink_led

Revision:
2:4c8b24eb7ad5
Parent:
1:ffc6a669f391
Child:
3:c97f4e7f2685
Child:
5:4624aed3b143
--- a/Console.cpp	Sat Mar 17 14:05:07 2018 +0200
+++ b/Console.cpp	Sat Mar 17 14:36:57 2018 +0200
@@ -48,11 +48,12 @@
 
 void Console::dumpThreadInfo(int argc,char *argv[])
 {
+    printf("Thread Info:\n");
     mbed_stats_stack_t stacks[10];
     int cnt = mbed_stats_stack_get_each(stacks, 10);
     for(int k = 0; k < cnt; k++)
     {
-        printf("%d - TH[%lu]: max: %lu, res: %lu\r\n", k, stacks[k].thread_id, stacks[k].max_size, stacks[k].reserved_size);
+        printf("%d - TH[%lu]: max: %lu, res: %lu\n", k, stacks[k].thread_id, stacks[k].max_size, stacks[k].reserved_size);
     }
 }
 
@@ -60,22 +61,22 @@
 {
       {"MBED OS"    ,0,0,0},
       {"h",       "",            "Show this help info", Console::help},
-      {"dt",       "",           "Dump Thread info", Console::dumpThreadInfo},
+      {"dt",      "",            "Dump Thread info", Console::dumpThreadInfo},
       {0,0,0}
 };
 
 
 Console *Console ::__instance = 0;
 
-void Console::init(Serial *serial)
+void Console::init(Serial *serial, const char *prompt)
 {
     if(!__instance)
-        __instance = new Console(serial);
+        __instance = new Console(serial, prompt);
 }
 
-Console::Console(Serial *serial) : mSerial(serial)
+Console::Console(Serial *serial, const char *prompt) : mSerial(serial), mPrompt(prompt)
 {
-    printf("New Console\r\n");
+    printf("New Console\n%s $", mPrompt);
     work.start(callback(ReceiveSerial, this));
 
     mIndex = 0;
@@ -150,7 +151,6 @@
 
 void Console::ReceiveSerial(Console *instance)
 {
-    printf("Console listening\r\n");
     while(__instance)
     {
         __instance->handleByte(__instance->mSerial->getc());
@@ -159,6 +159,8 @@
 
 void Console::handleByte(char byte)
 {
+    mSerial->putc(byte);
+
     mBuffer[mIndex] = byte;
 
     if(mIndex++ > 128)
@@ -169,15 +171,20 @@
 
     if((byte == '\n') || (byte == '\r'))
     {
+        mSerial->putc('\n');
+
         mBuffer[mIndex - 1] = 0;
-        handleCommand(mBuffer);
+        if(mIndex > 1)
+            handleCommand(mBuffer);
+
         mIndex = 0;
+
+        printf("\n%s $", mPrompt);
     }
 }
 
 void Console::handleCommand(char *cmd)
 {
-    printf("Console: %s\n\r", cmd);
     char *argv[10];
     int argc = 10;