port http://sourceforge.net/projects/tinysh to mbed enviroment
Dependents: kl25z-tinyshell-demo HelloWorld_IHM02A1
This library is a port of tiny shell library to mbed enviroment.
Features
- Autocomplete
- Command history
- Linux like
Tiny Shell minimal example
#include "mbed.h" #include "tinysh.h" //serial port to use Serial pc(USBTX, USBRX); //custom function void foo_fnt(int argc, char **argv) { printf("foo command called\r\n"); for(int i=0; i<argc; i++) { printf("argv[%d]=\"%s\"\r\n",i,argv[i]); } } //custom command tinysh_cmd_t myfoocmd= {0,"foo","foo command","[args]",foo_fnt,0,0,0}; //mandatory tiny shell output function void tinysh_char_out(unsigned char c) { pc.putc(c); } void main(void){ //configure serial baudrate pc.baud(115200); //print build date pc.printf("tiny shell build %s %s\r\n",__DATE__,__TIME__); //set prompt tinysh_set_prompt("$ "); //add custom commands here tinysh_add_command(&myfoocmd); //run command parser loop foverer while(true) { tinysh_char_in( pc.getc() ); } }
tinysh.h
- Committer:
- murilopontes
- Date:
- 2014-03-11
- Revision:
- 1:71580bf962fe
- Parent:
- 0:78b46c0d5246
File content as of revision 1:71580bf962fe:
/* * tinysh.h * * Header for minimal portable shell * * Copyright (C) 2001 Michel Gutierrez <mig@nerim.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ typedef void (*tinysh_fnt_t)(int argc, char **argv); typedef struct tinysh_cmd_t { struct tinysh_cmd_t *parent; /* 0 if top level command */ char *name; /* command input name, not 0 */ char *help; /* help string, can be 0 */ char *usage; /* usage string, can be 0 */ tinysh_fnt_t function; /* function to launch on cmd, can be 0 */ void *arg; /* current argument when function called */ struct tinysh_cmd_t *next; /* must be set to 0 at init */ struct tinysh_cmd_t *child; /* must be set to 0 at init */ } tinysh_cmd_t; #ifdef __cplusplus extern "C" { #endif /* * function void tinysh_char_out(unsigned char) must be provided by * the application */ void tinysh_char_out(unsigned char c); /* * Functions below are provided by the tinysh module */ /* new character input */ void tinysh_char_in(unsigned char c); /* add a new command */ void tinysh_add_command(tinysh_cmd_t *cmd); /* change tinysh prompt */ void tinysh_set_prompt(char *str); /* get command argument back */ void *tinysh_get_arg(); /* provide conversion string to scalar (decimal or hexadecimal) */ unsigned long tinysh_atoxi(char *s); #ifdef __cplusplus } #endif