P542-Labs / Mbed 2 deprecated Lab1

Dependencies:   mbed

Revision:
2:04d8e2ad8cff
Parent:
0:ece62a42511f
--- a/SerialConsole.h	Sun Aug 31 06:46:52 2014 +0000
+++ b/SerialConsole.h	Sun Aug 31 08:34:56 2014 +0000
@@ -1,3 +1,4 @@
+#pragma once
 #include "mbed.h"
 #include "Command.h"
 #include <vector>
@@ -9,145 +10,42 @@
 {
     const char* prompt_str;
     char buffer[100];
-    vector<Cmd*> cmds;
+    int param;
     
-    int param;
+    //command list
+    vector<Cmd*> cmds;
     //available commands
     Led_On_Cmd cmd1;
     Led_Off_Cmd cmd2;
+    Help_cmd cmd3;
     Cmd null_cmd;
-    
-public:
-    SerialConsole() {
-        prompt_str = "p542% ";
-        init();
-    };
-
-    SerialConsole(char* pr) {
-        prompt_str = pr;
-        init();
-    };
 
-    void start() {
-        //start with prompt
-        prompt();
-        //
-        int count = 0 ;
-        while(1) {
-            char ch = pc.getc();
-            buffer[count++] = ch ;
-            //check for carriage return or new line
-            if(ch == 0x0a || ch == 0x0d ) {
-                //for each new line parse command then execute command
-                Cmd* in_cmd = parse_command(count);
-                in_cmd->execute(param);
-                //reset count/buffer
-                count = 0;
-                //go to a new command line
-                newline();
-                prompt();
-                continue ;
-            } else if (ch == 'q') {
-                //exit
-                newline();
-                prompt();
-                return;
-            }
-            pc.putc(ch);
-        }
-    };
-
+public:
+    SerialConsole();
+    SerialConsole(char* pr) ;
+    void start() ;
+    void newline() ;
+    
 private:
-    void init() {
-        //default param
-        param = 1 ;
-        //default commands
-        cmds.push_back(&cmd1);
-        cmds.push_back(&cmd2);
-    }
+    void init() ;
+    Cmd* parse_command(int count);
+    void prompt();
+    
 
-    Cmd* parse_command(int count) {
-        //parse command from buffer
-        int curr_pos = 0;
-        //loop until a space is encounterred
-        //discard any leading spaces
-        bool check_leading_spaces = true;
-        bool check_cmd_str = true;
-        bool check_arg_str = false;
-        char cmd_str[100];
-        char arg_str[100];
-        int cmd_str_idx = 0;
-        int arg_str_idx = 0;
-        while (curr_pos < count) {
-            if(buffer[curr_pos] == '\0') {
-                break;
-            }
-            if (check_leading_spaces && buffer[curr_pos] == ' ') {
-                curr_pos++;
-                continue;
-            } else if (check_cmd_str && buffer[curr_pos] != ' ') {
-                //we have come to the command string start
-                check_leading_spaces = false;
-                cmd_str[cmd_str_idx++] = buffer[curr_pos];
-            } else if (check_arg_str && buffer[curr_pos] != ' ') {
-                //we have come to the arg string start
-                check_leading_spaces = false;
-                arg_str[arg_str_idx++] = buffer[curr_pos];
-            } else if (buffer[curr_pos] == ' ') {
-                if(check_arg_str) break;
-                // we have come to the spaces after cmd string
-                check_cmd_str = false;
-                check_leading_spaces = true;
-                check_arg_str = true;
-            }
-            curr_pos++;
-        };
-        
-        //make valid C string for comparison
-        cmd_str[cmd_str_idx]= '\0';
-        arg_str[arg_str_idx]= '\0';
-        
-        //find any command matching input
-        for(vector<Cmd*>::iterator it = cmds.begin(); it != cmds.end(); it++){
-            Cmd* curr_cmd = *it;   
-            if(strcmp(curr_cmd->get_name(), cmd_str) == 0){
-                //success : command found for given input
-                param = atoi(arg_str);
-                //todo remove
-                newline();
-                pc.puts("CMD SUCCESS  param : ");
-                pc.printf("%d", param);
-                newline();
-                return curr_cmd;
-            }
-        }
-        return &null_cmd;
-    }
-
-    void prompt() {
-        pc.puts(prompt_str);
-    };
-
-    void newline() {
-        pc.putc(0x0d);
-        pc.putc(0x0a);
-    };
+    /*   STARTUP MESSAGE
+    ************************************************
+    *************Simple LED Console*****************
+    ************************************************
+    *A Console Application to manage LED Digital****
+    *ouput for ARM cortex M4 - LPC1768, covered by**
+    *Apache General Public License  ****************
+    ************************************************
+    ***Author : U.S. Wickramasinghe*****************
+    ***Corperation : Indiana University*************
+    *Please email uswickra@umail.iu.edu for source**
+    ************************************************
+    */
+    void print_startup_msg() ;
+    
 
 };
-
-/*
-        newline();
-        pc.puts("DEBUG CMD : ");
-        pc.putc(char(cmd_str_idx+'0'));
-        newline();
-        for(int i = 0 ; i < cmd_str_idx ; i++ ){
-            pc.putc(cmd_str[i]);
-        }
-        newline();
-        pc.puts("DEBUG ARG: ");
-        pc.putc(char(arg_str_idx+ '0'));
-        newline();
-        for(int i = 0 ; i < arg_str_idx ; i++ ){
-            pc.putc(arg_str[i]);
-        }
-        newline();*/
\ No newline at end of file