Revision ae8211ea
| core/src/aos_shell.c | ||
|---|---|---|
| 716 | 716 |
* |
| 717 | 717 |
* @param[in] shell Pointer to the shell object. |
| 718 | 718 |
* @param[in] channel The channel to read from. |
| 719 |
* @param[out] n Pointer to a variable to store the number of read characters to.
|
|
| 719 |
* @param[out] n Optional pointer to a variable to store the number of read characters to.
|
|
| 720 | 720 |
* |
| 721 |
* @return |
|
| 721 |
* @return Indicator, whether the read character(s) indicated, that a command shall be executed.
|
|
| 722 | 722 |
*/ |
| 723 |
static aos_status_t _readChannel(aos_shell_t* shell, AosShellChannel* channel, size_t* n)
|
|
| 723 |
static bool _readChannel(aos_shell_t* shell, AosShellChannel* channel, size_t* n)
|
|
| 724 | 724 |
{
|
| 725 | 725 |
aosDbgCheck(shell != NULL); |
| 726 | 726 |
aosDbgCheck(channel != NULL); |
| 727 |
aosDbgCheck(n != NULL); |
|
| 728 | 727 |
|
| 729 | 728 |
// local variables |
| 730 | 729 |
aos_shellaction_t action = AOS_SHELL_ACTION_NONE; |
| ... | ... | |
| 732 | 731 |
special_key_t key; |
| 733 | 732 |
|
| 734 | 733 |
// initialize output variables |
| 735 |
*n = 0; |
|
| 734 |
if (n) {
|
|
| 735 |
*n = 0; |
|
| 736 |
} |
|
| 736 | 737 |
|
| 737 | 738 |
// read character by character from the channel |
| 738 | 739 |
while (chnReadTimeout(channel, (uint8_t*)&c, 1, TIME_IMMEDIATE)) {
|
| ... | ... | |
| 1149 | 1150 |
streamPut(&shell->stream, '\n'); |
| 1150 | 1151 |
// set the number of read bytes and return |
| 1151 | 1152 |
if (!shell->inputdata.noinput) {
|
| 1152 |
*n = shell->input.length - shell->inputdata.lineend; |
|
| 1153 |
if (n) {
|
|
| 1154 |
*n = shell->input.length - shell->inputdata.lineend; |
|
| 1155 |
} |
|
| 1153 | 1156 |
// fill the remainder of the line with NUL bytes |
| 1154 |
memset(&(shell->input.line[shell->inputdata.lineend]), '\0', *n); |
|
| 1155 |
// reset static variables |
|
| 1156 |
shell->inputdata.noinput = true; |
|
| 1157 |
memset(&(shell->input.line[shell->inputdata.lineend]), '\0', (shell->input.length - shell->inputdata.lineend)); |
|
| 1157 | 1158 |
} |
| 1158 |
return AOS_SUCCESS;
|
|
| 1159 |
return true;
|
|
| 1159 | 1160 |
} |
| 1160 | 1161 |
|
| 1161 | 1162 |
case AOS_SHELL_ACTION_ESCSTART: |
| ... | ... | |
| 1186 | 1187 |
} /* end of while */ |
| 1187 | 1188 |
|
| 1188 | 1189 |
// no more data could be read from the channel |
| 1189 |
return AOS_WARNING;
|
|
| 1190 |
return false;
|
|
| 1190 | 1191 |
} |
| 1191 | 1192 |
|
| 1192 | 1193 |
/** |
| ... | ... | |
| 1286 | 1287 |
shell->execstatus.retval = 0; |
| 1287 | 1288 |
shell->input.line = line; |
| 1288 | 1289 |
shell->input.length = linesize; |
| 1290 |
shell->input.nargs= numargs; |
|
| 1289 | 1291 |
shell->inputdata.lastaction = AOS_SHELL_ACTION_NONE; |
| 1290 | 1292 |
memset(shell->inputdata.escseq, '\0', sizeof(shell->inputdata.escseq)*sizeof(shell->inputdata.escseq[0])); |
| 1291 | 1293 |
shell->inputdata.cursorpos = 0; |
| 1292 | 1294 |
shell->inputdata.lineend = 0; |
| 1293 | 1295 |
shell->inputdata.noinput = true; |
| 1294 |
shell->input.nargs= numargs; |
|
| 1295 | 1296 |
shell->config = 0x00; |
| 1296 | 1297 |
|
| 1297 | 1298 |
// initialize buffers |
| ... | ... | |
| 1601 | 1602 |
eventflags_t eventflags; |
| 1602 | 1603 |
AosShellChannel* channel; |
| 1603 | 1604 |
aos_status_t readeval; |
| 1604 |
size_t nchars = 0; |
|
| 1605 | 1605 |
char* args[((aos_shell_t*)shell)->input.nargs]; |
| 1606 | 1606 |
size_t nargs = 0; |
| 1607 | 1607 |
aos_shellcommand_t* cmd; |
| ... | ... | |
| 1653 | 1653 |
channel = ((aos_shell_t*)shell)->stream.channel; |
| 1654 | 1654 |
while (channel != NULL) {
|
| 1655 | 1655 |
eventflags = chEvtGetAndClearFlags(&channel->listener); |
| 1656 |
// if there is new input |
|
| 1657 |
if (eventflags & CHN_INPUT_AVAILABLE) {
|
|
| 1658 |
// read input from channel |
|
| 1659 |
readeval = _readChannel((aos_shell_t*)shell, channel, &nchars); |
|
| 1660 |
// parse input line to argument list only if the input shall be executed |
|
| 1661 |
nargs = (readeval == AOS_SUCCESS && nchars > 0) ? _parseArguments((aos_shell_t*)shell, args) : 0; |
|
| 1656 |
// if there is new input and a command shall be executed |
|
| 1657 |
if ((eventflags & CHN_INPUT_AVAILABLE) && _readChannel((aos_shell_t*)shell, channel, NULL)) {
|
|
| 1658 |
// parse input line to argument list |
|
| 1659 |
nargs = _parseArguments((aos_shell_t*)shell, args); |
|
| 1662 | 1660 |
// check number of arguments |
| 1663 | 1661 |
if (nargs > ((aos_shell_t*)shell)->input.nargs) {
|
| 1664 | 1662 |
// error too many arguments |
| ... | ... | |
| 1691 | 1689 |
if (readeval == AOS_SUCCESS && !chThdShouldTerminateX()) {
|
| 1692 | 1690 |
((aos_shell_t*)shell)->inputdata.cursorpos = 0; |
| 1693 | 1691 |
((aos_shell_t*)shell)->inputdata.lineend = 0; |
| 1692 |
((aos_shell_t*)shell)->inputdata.noinput = true; |
|
| 1694 | 1693 |
_printPrompt((aos_shell_t*)shell); |
| 1695 | 1694 |
} |
| 1696 | 1695 |
} |
Also available in: Unified diff