void shellStart(const ShellConfig *p) { int n; Stream *chp = p->sc_channel; const ShellCommand *scp = p->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; char *args[SHELL_MAX_ARGUMENTS + 1]; chp->printf("\r\nEmbed/RX Shell\r\n"); while (true) { chp->printf(">> "); if (shellGetLine(chp, line, sizeof(line))) { chp->printf("\r\nlogout"); break; } lp = _strtok(line, " \t", &tokp); cmd = lp; n = 0; while ((lp = _strtok(NULL, " \t", &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chp->printf("too many arguments\r\n"); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcasecmp(cmd, "exit") == 0) { if (n > 0) { shellUsage(chp, "exit"); continue; } // Break here breaks the outer loop // hence, we exit the shell. break; } else if (strcasecmp(cmd, "help") == 0) { if (n > 0) { shellUsage(chp, "help"); continue; } chp->printf("Commands: help exit "); list_commands(chp, local_commands); if (scp != NULL) list_commands(chp, scp); chp->printf("\r\n"); } else if (cmdexec(local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chp->printf("%s", cmd); chp->printf(" ?\r\n"); } } } }
static void cmd_info(Stream * chp, int argc, char *argv[]) { (void)argv; if (argc > 0) { shellUsage(chp, "info"); return; } long sp = __current_sp(); long pc = __current_pc(); heapinfo(chp); }
void cmd_load(Stream * chp, int argc, char * argv[]) { char filename[256]; if (argc != 1) { shellUsage(chp, "load <bitmapfile>"); return; } sprintf(filename, "/sd/%s", argv[0]); // Load a bitmap startup file int err = TFT.BMP_16(0,0, filename); if (err != 1) TFT.printf(" - Err: %d", err); }
/** * @brief Shell thread function. * * @param[in] p pointer to a @p BaseSequentialStream object */ THD_FUNCTION(shellThread, p) { int n; ShellConfig *scfg = p; BaseSequentialStream *chp = scfg->sc_channel; const ShellCommand *scp = scfg->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; char *args[SHELL_MAX_ARGUMENTS + 1]; #if SHELL_USE_HISTORY == TRUE *(scfg->sc_histbuf) = 0; ShellHistory hist = { scfg->sc_histbuf, scfg->sc_histsize, 0, 0, 0 }; ShellHistory *shp = &hist; #else ShellHistory *shp = NULL; #endif chprintf(chp, SHELL_NEWLINE_STR); chprintf(chp, "ChibiOS/RT Shell"SHELL_NEWLINE_STR); while (true) { chprintf(chp, SHELL_PROMPT_STR); if (shellGetLine(scfg, line, sizeof(line), shp)) { #if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_) chprintf(chp, SHELL_NEWLINE_STR); chprintf(chp, "logout"); break; #else /* Putting a delay in order to avoid an endless loop trying to read an unavailable stream.*/ osalThreadSleepMilliseconds(100); #endif } lp = parse_arguments(line, &tokp); cmd = lp; n = 0; while ((lp = parse_arguments(NULL, &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chprintf(chp, "too many arguments"SHELL_NEWLINE_STR); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcmp(cmd, "help") == 0) { if (n > 0) { shellUsage(chp, "help"); continue; } chprintf(chp, "Commands: help "); list_commands(chp, shell_local_commands); if (scp != NULL) list_commands(chp, scp); chprintf(chp, SHELL_NEWLINE_STR); } else if (cmdexec(shell_local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chprintf(chp, "%s", cmd); chprintf(chp, " ?"SHELL_NEWLINE_STR); } } } shellExit(MSG_OK); }
void cmd_motor(int argc, char *argv[]) { (void)argv; float dutyval = 0.0; int leftorright = 0; if (argc != 2 ) { shellUsage("motor <left/right> <duty>"); return; } // Parse which motor to set. if (strcmp(argv[0], "left") == 0) { leftorright = 0; } else if(strcmp(argv[0], "right") == 0) { leftorright = 1; } else { shellUsage("motor <left/right> <duty>"); return; } if (strcmp(argv[1], "on") == 0) { if (leftorright == 0) // Left motor { // turn on left motor TIM3_StartPWM(TIM_CHANNEL_1); TIM3_StartPWM(TIM_CHANNEL_2); }else { // turn on right motor TIM3_StartPWM(TIM_CHANNEL_3); TIM3_StartPWM(TIM_CHANNEL_4); } return; } if (strcmp(argv[1], "off") == 0) { if (leftorright == 0) // Left motor { // turn off left motor TIM3_StopPWM(TIM_CHANNEL_1); TIM3_StopPWM(TIM_CHANNEL_2); }else { // turn off right motor TIM3_StopPWM(TIM_CHANNEL_3); TIM3_StopPWM(TIM_CHANNEL_4); } return; } // If we get here, we extract the duty cycle // from the second argument. dutyval = atof(argv[1]); // And set the appropriate PWM for the motors if (leftorright == 0) { MotorLeftDuty(dutyval); }else { MotorRightDuty(dutyval); } }