Git Product home page Git Product logo

microshell's Introduction

Build Status codecov

MicroShell

Lightweight pure C implementation of virtual shell, compatible with VT100 terminal. Support root tree, run-time mounting paths, global commands, and much more. Works out-of-the-box on Arduino-compatible boards. Dedicated for bare-metal embedded systems. Thanks to the asynchronous architecture it does not block operations and can be easily implemented even on small microcontrollers with relatively small resources.

Project Homepage
LIVE DEMO <- needs PC web browser (not mobile)

alt text

Features

  • names autocompletation (do You like a TAB-functionality on You favorite bash shell?)
  • no dynamic allocations (no memory leaks - no problem)
  • hardware independent (works just as well on AVR, PIC, STM32, ESP32 as it on x86 or RPI)
  • rich set of examples (available in the Arduino Library Manager)
  • pure C source code (works on rich set of compilers)
  • backspace key feature (simply works)
  • compatible vith VT100 standard (works out of the box with default putty configuration)
  • easy to extend (adding more "weird" features it has never been easier)
  • buildin commands (must-have, basic support of LS, CAT, PWD, HELP, XXD, ECHO)
  • scalable (configuration allows You to exclude unnecessary modules from building)
  • translation-ready (do You want Hindi translation? no problem!)
  • no internal buffers (support unlimited data stream lengths)
  • no static variables (possibility to use multiple independent shells in single system)
  • object oriented architecture (pointers attack!)
  • support root tree with static virtual files with callbacks (full customization)
  • extremely simple to integrate (only 1 simple interface with IO operations)
  • asynchronous architecture (static callbacks is not a problem)
  • non-blocking api (You just need to call one non-blocking function on main loop)
  • unit and functional tests (for greater certainty that nothing will break down)

Build

In case you didn't use git clone --recursive you'll need to manually pull in additional submodules with:

git submodule update --init

Build, test and run DEMO:

cmake -Bbuild .
cd build
make
make test
make coverage
./bin/demo

Usage

Define I/O interface:

// non-blocking read interface
static int ush_read(struct ush_object *self, char *ch)
{
    // should be implemented as a FIFO
    if (Serial.available() > 0) {
        *ch = Serial.read();
        return 1;
    }
    return 0;
}

// non-blocking write interface
static int ush_write(struct ush_object *self, char ch)
{
    // should be implemented as a FIFO
    return (Serial.write(ch) == 1);
}

// I/O interface descriptor
static const struct ush_io_interface ush_iface = {
    .read = ush_read,
    .write = ush_write,
};

Define shell descriptor and shell instance:

// working buffers allocations (size could be customized)
#define BUF_IN_SIZE    32
#define BUF_OUT_SIZE   32
#define PATH_MAX_SIZE  32

static char ush_in_buf[BUF_IN_SIZE];
static char ush_out_buf[BUF_OUT_SIZE];

// microshell instance handler
static struct ush_object ush;

// microshell descriptor
static const struct ush_descriptor ush_desc = {
    .io = &ush_iface,                           // I/O interface pointer
    .input_buffer = ush_in_buf,                 // working input buffer
    .input_buffer_size = sizeof(ush_in_buf),    // working input buffer size
    .output_buffer = ush_out_buf,               // working output buffer
    .output_buffer_size = sizeof(ush_out_buf),  // working output buffer size
    .path_max_length = PATH_MAX_SIZE,           // path maximum length (stack)
    .hostname = "arduino",                      // hostname (in prompt)
};

// root directory handler
static struct ush_node_object root;

Setup and run:

void setup()
{
    // initialize I/O interface
    Serial.begin(115200UL);

    // initialize microshell instance
    ush_init(&ush, &ush_desc);

    // mount root directory (root must be first)
    ush_node_mount(&ush, "/", &root, NULL, 0);

    // mount other directories here
    // ...
}

void loop()
{
    // non-blocking microshell service
    ush_service(&ush);

    // do other non-blocking stuff here
    // ...
}

Contribution

If You want to contribute this project - excellent! Fork it, make bugs, and send a PR :)
If You want to support me in developing this project - please donate!
paypal

microshell's People

Contributors

ghostfire90 avatar marcinbor85 avatar rostcode avatar synco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microshell's Issues

Failed to build demo_linux

Here's what I did
After adding

cmake_minimum_required(VERSION 3.20)    
project(MicroShell) 

To CMakeLists.txt to top cmake moaning.

mkdir build 
cd build
cmake ..

CMake Error at CMakeLists.txt:7 (build_ush):
  Unknown CMake command "build_ush".


-- Configuring incomplete, errors occurred!
See also "/home/andrewh/Source/microshell/examples/demo_linux/CMakeFiles/CMakeOutput.log".

Please advise

this operator is not allowed in an integral constant expression

compiling environment : IAR 8.50.9

An error is displayed:

void ush_autocomp_check_for_finish(struct ush_object *self)
{
char abs_path[self->desc->path_max_length];
..................
}

Error[Pe060]: this operator is not allowed in an integral constant expression
PATJ: mcushell\src\ush_autocomp_utils.c 72

In several function interfaces, the definition of a character array prompts a similar error。

[Bug] Paste sometimes misses characters on STM32

I have non blocking reads and writes set up over UART using HAL_UART_Transmit_IT and HAL_UART_Receive_IT, and when I paste into the terminal, it sometimes misses characters.

I have adjusted buffer sizes, and various UART settings to no avail.

Would be happy to gather some data to help troubleshoot this issue, but I am not entirely sure where to start.

[BUG] Argument format error in xxd command (ush_cmd_xxd.c)

Compiling with arm-none-eabi GCC 8.3.1 (target is RP2040) - in the hex printing routine of ush_cmd_xxd.c there is a size mismatch of the formatted string and the item passed to sprintf().

Build output:

src/commands/ush_cmd_xxd.c: In function 'ush_buildin_cmd_xxd_service':
src/commands/ush_cmd_xxd.c:80:64: error: format '%X' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int' [-Werror=format=]
                          sprintf(self->desc->output_buffer, "%08X: ", (uint32_t)self->process_index_item);
                                                              ~~~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                              %08lX

As shown above the error can be fixed by using %08lX (long) format rather than %08X. I think perhaps this issue does not arise when compiling for POSIX, but does on ARM?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.