Data Structures | Typedefs | Functions | Variables

shell.c File Reference

shell interpreter and commands implementation More...

#include "config.h"
#include <stdio.h>
#include <ctype.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <avr/boot.h>
#include <util/crc16.h>
#include <util/atomic.h>
#include "shell.h"
#include "shell-fs.h"
#include "sdcmd.h"
#include "xpal_bat.h"
#include "eeprom-wl.h"
#include "xpal_noise.h"
#include "xpal_selfprog.h"
#include "xpal_power.h"
#include "usarts.h"

Data Structures

struct  sh_progpage_status_s

Typedefs

typedef int( shell_stdin_func_t )(void *datap, int c)
typedef struct sh_progpage_status_s sh_progpage_status_t

Functions

int shell_exec (const char *cmd, const uint8_t argc, const char *argv[])
 execute a named shell functions
void shell_recv_char (int c)
 feed one input character (as read from fgetc()) to command interpreter

Variables

gpsflags_t gpsflags [USARTS_NUMBER]

Detailed Description

shell interpreter and commands implementation


Function Documentation

int shell_exec ( const char *  cmd,
const uint8_t  argc,
const char *  argv[] 
)

execute a named shell functions

execute a command

{
  const char * const *nptr;
  shell_function_t * const * fptr;

  /* find in list */
  for (nptr = shell_names, fptr = shell_commands; ; nptr++, fptr++) {
    const const char * name = (PGM_P)pgm_read_word (nptr);
    if (!name) {
      printf_P (PSTR("command '%s' not found\r\n"), argv[0]);
      return -1;
    }
    if (strcmp_P (argv[0], name) == 0) {
      break;
    }
  }

  /* now execute */
  return (*(shell_function_t*)pgm_read_word(fptr))(argc, argv);

}

void shell_recv_char ( int  c  ) 

feed one input character (as read from fgetc()) to command interpreter

shell_recv_char() buffers the read characters until a complete input line has been received. The command in that line is then executed - depending on the command, the execution may take some time.

{
  int retval;

  /* handle captured STDIN */
  if (shell_status.stdin_func) {
    retval = shell_status.stdin_func(shell_status.stdin_datap, c);
    if (!shell_status.stdin_func) {
      shell_status.last_retval = retval;
    }
    return;
  }

  switch (c) {
  default:
    /* ignore characters which don't fit into buffer */
    if (shell_status.cmdbufidx < SHELL_BUFSIZE) {
      shell_status.cmdbuffer[shell_status.cmdbufidx++] = c;
      putchar(c);
    }
    return;
  case '\n':
    /* ignore */
    return;
  case '\r':
    putchar (c); putchar ('\n');
    shell_status.cmdbuffer[shell_status.cmdbufidx] = '\0';
    shell_status.last_retval = shell_execute (shell_status.cmdbuffer);
    shell_status.cmdbufidx = 0;
    return;
  case '\377':
  case '\b':
    /* erase until start of line */
    if (shell_status.cmdbufidx > 0) {
      putchar ('\b'); putchar (' '); putchar ('\b');
      shell_status.cmdbufidx--;
    }
    return;
  }
}