amiro-os / core / src / aos_shell.c @ 10b520a8
History | View | Annotate | Download (49.382 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 4 | e545e620 | Thomas Schöpping | |
| 5 | This program is free software: you can redistribute it and/or modify
|
||
| 6 | it under the terms of the GNU General Public License as published by
|
||
| 7 | the Free Software Foundation, either version 3 of the License, or
|
||
| 8 | (at your option) any later version.
|
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful,
|
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 13 | GNU General Public License for more details.
|
||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License
|
||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
| 17 | */
|
||
| 18 | |||
| 19 | 53710ca3 | Marc Rothmann | /**
|
| 20 | * @file aos_shell.c
|
||
| 21 | * @brief Shell code.
|
||
| 22 | * @details Shell code as well as shell related channels and streams.
|
||
| 23 | *
|
||
| 24 | * @addtogroup aos_shell
|
||
| 25 | * @{
|
||
| 26 | */
|
||
| 27 | |||
| 28 | 3940ba8a | Thomas Schöpping | #include <amiroos.h> |
| 29 | #include <string.h> |
||
| 30 | e545e620 | Thomas Schöpping | |
| 31 | 2dd2e257 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) |
| 32 | 3940ba8a | Thomas Schöpping | |
| 33 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 34 | /* LOCAL DEFINITIONS */
|
||
| 35 | /******************************************************************************/
|
||
| 36 | ba516b61 | Thomas Schöpping | |
| 37 | /**
|
||
| 38 | * @brief Event mask to be set on OS related events.
|
||
| 39 | */
|
||
| 40 | #define AOS_SHELL_EVENTMASK_OS EVENT_MASK(0) |
||
| 41 | |||
| 42 | /**
|
||
| 43 | * @brief Event mask to be set on a input event.
|
||
| 44 | */
|
||
| 45 | #define AOS_SHELL_EVENTMASK_INPUT EVENT_MASK(1) |
||
| 46 | |||
| 47 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 48 | /* EXPORTED VARIABLES */
|
||
| 49 | /******************************************************************************/
|
||
| 50 | |||
| 51 | /******************************************************************************/
|
||
| 52 | /* LOCAL TYPES */
|
||
| 53 | /******************************************************************************/
|
||
| 54 | |||
| 55 | /*
|
||
| 56 | * forward declarations
|
||
| 57 | */
|
||
| 58 | static size_t _channelwrite(void *instance, const uint8_t *bp, size_t n); |
||
| 59 | static size_t _channelread(void *instance, uint8_t *bp, size_t n); |
||
| 60 | static msg_t _channelput(void *instance, uint8_t b); |
||
| 61 | static msg_t _channelget(void *instance); |
||
| 62 | static msg_t _channelputt(void *instance, uint8_t b, sysinterval_t time); |
||
| 63 | static msg_t _channelgett(void *instance, sysinterval_t time); |
||
| 64 | static size_t _channelwritet(void *instance, const uint8_t *bp, size_t n, sysinterval_t time); |
||
| 65 | static size_t _channelreadt(void *instance, uint8_t *bp, size_t n, sysinterval_t time); |
||
| 66 | static msg_t _channelctl(void *instance, unsigned int operation, void *arg); |
||
| 67 | static size_t _streamwrite(void *instance, const uint8_t *bp, size_t n); |
||
| 68 | static size_t _stremread(void *instance, uint8_t *bp, size_t n); |
||
| 69 | static msg_t _streamput(void *instance, uint8_t b); |
||
| 70 | static msg_t _streamget(void *instance); |
||
| 71 | |||
| 72 | static const struct AosShellChannelVMT _channelvmt = { |
||
| 73 | (size_t) 0,
|
||
| 74 | _channelwrite, |
||
| 75 | _channelread, |
||
| 76 | _channelput, |
||
| 77 | _channelget, |
||
| 78 | _channelputt, |
||
| 79 | _channelgett, |
||
| 80 | _channelwritet, |
||
| 81 | _channelreadt, |
||
| 82 | _channelctl, |
||
| 83 | }; |
||
| 84 | |||
| 85 | static const struct AosShellStreamVMT _streamvmt = { |
||
| 86 | (size_t) 0,
|
||
| 87 | _streamwrite, |
||
| 88 | _stremread, |
||
| 89 | _streamput, |
||
| 90 | _streamget, |
||
| 91 | }; |
||
| 92 | |||
| 93 | /**
|
||
| 94 | * @brief Enumerator of special keyboard keys.
|
||
| 95 | */
|
||
| 96 | typedef enum special_key { |
||
| 97 | KEY_UNKNOWN, /**< any/unknow key */
|
||
| 98 | KEY_AMBIGUOUS, /**< key is ambiguous */
|
||
| 99 | KEY_TAB, /**< tabulator key */
|
||
| 100 | KEY_ESCAPE, /**< escape key */
|
||
| 101 | KEY_BACKSPACE, /**< backspace key */
|
||
| 102 | KEY_INSERT, /**< insert key */
|
||
| 103 | KEY_DELETE, /**< delete key */
|
||
| 104 | KEY_HOME, /**< home key */
|
||
| 105 | KEY_END, /**< end key */
|
||
| 106 | KEY_PAGE_UP, /**< page up key */
|
||
| 107 | KEY_PAGE_DOWN, /**< page down key */
|
||
| 108 | KEY_ARROW_UP, /**< arrow up key */
|
||
| 109 | KEY_ARROW_DOWN, /**< arrow down key */
|
||
| 110 | KEY_ARROW_LEFT, /**< arrow left key */
|
||
| 111 | KEY_ARROW_RIGHT, /**< arrow right key */
|
||
| 112 | } special_key_t; |
||
| 113 | |||
| 114 | /**
|
||
| 115 | * @brief Enumerator for case (in)sensitive character matching.
|
||
| 116 | */
|
||
| 117 | typedef enum charmatch { |
||
| 118 | CHAR_MATCH_NOT = 0, /**< Characters do not match at all. */ |
||
| 119 | CHAR_MATCH_NCASE = 1, /**< Characters would match case insensitive. */ |
||
| 120 | CHAR_MATCH_CASE = 2, /**< Characters do match with case. */ |
||
| 121 | } charmatch_t; |
||
| 122 | |||
| 123 | /******************************************************************************/
|
||
| 124 | /* LOCAL VARIABLES */
|
||
| 125 | /******************************************************************************/
|
||
| 126 | |||
| 127 | /******************************************************************************/
|
||
| 128 | /* LOCAL FUNCTIONS */
|
||
| 129 | /******************************************************************************/
|
||
| 130 | |||
| 131 | ba516b61 | Thomas Schöpping | /**
|
| 132 | * @brief Implementation of the BaseAsynchronous write() method (inherited from BaseSequentialStream).
|
||
| 133 | */
|
||
| 134 | static size_t _channelwrite(void *instance, const uint8_t *bp, size_t n) |
||
| 135 | {
|
||
| 136 | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_OUTPUT_ENABLED) {
|
||
| 137 | dd8738ea | Thomas Schöpping | return streamWrite(((AosShellChannel*)instance)->asyncchannel, bp, n);
|
| 138 | ba516b61 | Thomas Schöpping | } else {
|
| 139 | return 0; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | /**
|
||
| 144 | * @brief Implementation of the BaseAsynchronous read() method (inherited from BaseSequentialStream).
|
||
| 145 | */
|
||
| 146 | static size_t _channelread(void *instance, uint8_t *bp, size_t n) |
||
| 147 | {
|
||
| 148 | dd8738ea | Thomas Schöpping | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_INPUT_ENABLED) {
|
| 149 | return streamRead(((AosShellChannel*)instance)->asyncchannel, bp, n);
|
||
| 150 | } else {
|
||
| 151 | return 0; |
||
| 152 | } |
||
| 153 | ba516b61 | Thomas Schöpping | } |
| 154 | |||
| 155 | /**
|
||
| 156 | * @brief Implementation of the BaseAsynchronous put() method (inherited from BaseSequentialStream).
|
||
| 157 | */
|
||
| 158 | static msg_t _channelput(void *instance, uint8_t b) |
||
| 159 | {
|
||
| 160 | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_OUTPUT_ENABLED) {
|
||
| 161 | dd8738ea | Thomas Schöpping | return streamPut(((AosShellChannel*)instance)->asyncchannel, b);
|
| 162 | ba516b61 | Thomas Schöpping | } else {
|
| 163 | return MSG_RESET;
|
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | /**
|
||
| 168 | * @brief Implementation of the BaseAsynchronous get() method (inherited from BaseSequentialStream).
|
||
| 169 | */
|
||
| 170 | static msg_t _channelget(void *instance) |
||
| 171 | {
|
||
| 172 | dd8738ea | Thomas Schöpping | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_INPUT_ENABLED) {
|
| 173 | return streamGet(((AosShellChannel*)instance)->asyncchannel);
|
||
| 174 | } else {
|
||
| 175 | return MSG_RESET;
|
||
| 176 | } |
||
| 177 | ba516b61 | Thomas Schöpping | } |
| 178 | |||
| 179 | /**
|
||
| 180 | * @brief Implementation of the BaseAsynchronous putt() method.
|
||
| 181 | */
|
||
| 182 | 2c99037f | Marc Rothmann | static msg_t _channelputt(void *instance, uint8_t b, sysinterval_t time) |
| 183 | ba516b61 | Thomas Schöpping | {
|
| 184 | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_OUTPUT_ENABLED) {
|
||
| 185 | dd8738ea | Thomas Schöpping | return chnPutTimeout(((AosShellChannel*)instance)->asyncchannel, b, time);
|
| 186 | ba516b61 | Thomas Schöpping | } else {
|
| 187 | return MSG_RESET;
|
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | /**
|
||
| 192 | * @brief Implementation of the BaseAsynchronous gett() method.
|
||
| 193 | */
|
||
| 194 | 2c99037f | Marc Rothmann | static msg_t _channelgett(void *instance, sysinterval_t time) |
| 195 | ba516b61 | Thomas Schöpping | {
|
| 196 | dd8738ea | Thomas Schöpping | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_INPUT_ENABLED) {
|
| 197 | return chnGetTimeout(((AosShellChannel*)instance)->asyncchannel, time);
|
||
| 198 | } else {
|
||
| 199 | return MSG_RESET;
|
||
| 200 | } |
||
| 201 | ba516b61 | Thomas Schöpping | } |
| 202 | |||
| 203 | /**
|
||
| 204 | * @brief Implementation of the BaseAsynchronous writet() method.
|
||
| 205 | */
|
||
| 206 | 2c99037f | Marc Rothmann | static size_t _channelwritet(void *instance, const uint8_t *bp, size_t n, sysinterval_t time) |
| 207 | ba516b61 | Thomas Schöpping | {
|
| 208 | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_OUTPUT_ENABLED) {
|
||
| 209 | dd8738ea | Thomas Schöpping | return chnWriteTimeout(((AosShellChannel*)instance)->asyncchannel, bp, n, time);
|
| 210 | ba516b61 | Thomas Schöpping | } else {
|
| 211 | return 0; |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | /**
|
||
| 216 | * @brief Implementation of the BaseAsynchronous readt() method.
|
||
| 217 | */
|
||
| 218 | 2c99037f | Marc Rothmann | static size_t _channelreadt(void *instance, uint8_t *bp, size_t n, sysinterval_t time) |
| 219 | ba516b61 | Thomas Schöpping | {
|
| 220 | dd8738ea | Thomas Schöpping | if (((AosShellChannel*)instance)->flags & AOS_SHELLCHANNEL_INPUT_ENABLED) {
|
| 221 | return chnReadTimeout(((AosShellChannel*)instance)->asyncchannel, bp, n, time);
|
||
| 222 | } else {
|
||
| 223 | return 0; |
||
| 224 | } |
||
| 225 | ba516b61 | Thomas Schöpping | } |
| 226 | |||
| 227 | 2c99037f | Marc Rothmann | /**
|
| 228 | * @brief Implementation of the BaseAsynchronousChannel ctl() method.
|
||
| 229 | */
|
||
| 230 |