///////////////////////////////////////////////////////////////////////////// // Parser for a complete line - also used by shell.c for telnet ///////////////////////////////////////////////////////////////////////////// s32 TERMINAL_ParseLine(char *input, void *_output_function) { void (*out)(char *format, ...) = _output_function; char *separators = " \t"; char *brkt; char *parameter; if( (parameter = strtok_r(input, separators, &brkt)) ) { if( strcmp(parameter, "help") == 0 ) { out("Welcome to " MIOS32_LCD_BOOT_MSG_LINE1 "!"); out("Following commands are available:"); out(" kissbox <message>: send a message to kissbox"); out(" system: print system info"); out(" reset: resets the MIDIbox (!)\n"); out(" help: this page"); } else if( strcmp(parameter, "kissbox") == 0 ) { if( brkt == NULL ) { out("SYNTAX: kissbox <message>"); } else { // store MIDI port so that we know which port should get the debug message kissbox_debug_port = MIOS32_MIDI_DebugPortGet(); TERMINAL_KissboxSendMsg(brkt); } } else if( strcmp(parameter, "system") == 0 ) { TERMINAL_PrintSystem(_output_function); } else if( strcmp(parameter, "reset") == 0 ) { MIOS32_SYS_Reset(); } else { out("Unknown command - type 'help' to list available commands!"); } } return 0; // no error }
///////////////////////////////////////////////////////////////////////////// //! Parser for a complete line - also used by shell.c for telnet ///////////////////////////////////////////////////////////////////////////// s32 TERMINAL_ParseLine(char *input, void *_output_function) { void (*out)(char *format, ...) = _output_function; char *separators = " \t"; char *brkt; char *parameter; if( UIP_TERMINAL_ParseLine(input, _output_function) > 0 ) return 0; // command parsed by UIP Terminal if( KEYBOARD_TerminalParseLine(input, _output_function) > 0 ) return 0; // command parsed by Keyboard Terminal if( MIDIMON_TerminalParseLine(input, _output_function) > 0 ) return 0; // command parsed if( MIDI_ROUTER_TerminalParseLine(input, _output_function) > 0 ) return 0; // command parsed #if !defined(MIOS32_FAMILY_EMULATION) if( AOUT_TerminalParseLine(input, _output_function) >= 1 ) return 0; // command parsed #endif #ifdef MIOS32_LCD_universal if( APP_LCD_TerminalParseLine(input, _output_function) >= 1 ) return 0; // command parsed #endif if( (parameter = strtok_r(input, separators, &brkt)) ) { if( strcmp(parameter, "help") == 0 ) { out("Welcome to " MIOS32_LCD_BOOT_MSG_LINE1 "!"); out("Following commands are available:"); out(" system: print system info"); out(" memory: print memory allocation info\n"); out(" sdcard: print SD Card info\n"); out(" sdcard_format: formats the SD Card (you will be asked for confirmation)\n"); UIP_TERMINAL_Help(_output_function); KEYBOARD_TerminalHelp(_output_function); MIDIMON_TerminalHelp(_output_function); MIDI_ROUTER_TerminalHelp(_output_function); AOUT_TerminalHelp(_output_function); #ifdef MIOS32_LCD_universal APP_LCD_TerminalHelp(_output_function); #endif out(" set dout <pin> <0|1>: directly sets DOUT (all or 0..%d) to given level (1 or 0)", MIOS32_SRIO_NUM_SR*8 - 1); out(" show douts: prints the current DOUT patterns"); out(" set debug <on|off>: enables debug messages (current: %s)", debug_verbose_level ? "on" : "off"); out(" set autoload <on|off>: enables autoload after filebrowser upload (current: %s)", autoload_enabled ? "on" : "off"); out(" save <name>: stores current config on SD Card"); out(" load <name>: restores config from SD Card"); out(" show file: shows the current configuration file"); out(" show pool: shows the items of the event pool"); out(" show poolbin: shows the event pool in binary format"); out(" show id <element>:<id> shows informations about the given element id (e.g. BUTTON:1)"); out(" show hw_id <element>:<hw_id> shows informations about the given element hw_id (e.g. BUTTON:1)"); out(" show ngr_tokens: shows .NGR token information"); out(" lcd <string>: directly prints a string on LCD (can be formatted!)"); out(" run [<section>] [<value>]: executes the .NGR script with the optional section and value"); out(" ngr_value: value used for 'run' (without parameter) and 'ngr' (is: %d)", ngr_value); out(" ngr_section: section used for 'run' (without parameter) and 'ngr' (is: %d)", ngr_section); out(" ngr <command>: directly executes a NGR command"); out(" ngc <command>: directly executes a NGC command"); out(" msd <on|off>: enables Mass Storage Device driver"); out(" reset: resets the MIDIbox (!)\n"); out(" help: this page"); out(" exit: (telnet only) exits the terminal"); } else if( strcmp(parameter, "system") == 0 ) { TERMINAL_PrintSystem(_output_function); } else if( strcmp(parameter, "memory") == 0 ) { TERMINAL_PrintMemoryInfo(out); } else if( strcmp(parameter, "sdcard") == 0 ) { TERMINAL_PrintSdCardInfo(out); } else if( strcmp(parameter, "sdcard_format") == 0 ) { if( !brkt || strcasecmp(brkt, "yes, I'm sure") != 0 ) { out("ATTENTION: this command will format your SD Card!!!"); out(" ALL DATA WILL BE DELETED FOREVER!!!"); out(" Check the current content with the 'sdcard' command"); out(" Create a backup on your computer if necessary!"); out("To start formatting, please enter: sdcard_format yes, I'm sure"); if( brkt ) { out("('%s' wasn't the right \"password\")", brkt); } } else { MUTEX_SDCARD_TAKE; out("Formatting SD Card..."); FRESULT res; if( (res=f_mkfs(0,0,0)) != FR_OK ) { out("Formatting failed with error code: %d!", res); } else { out("...with success!"); MBNG_FILE_UnloadAllFiles(); MBNG_FILE_CreateDefaultFiles(); } MUTEX_SDCARD_GIVE; } } else if( strcmp(parameter, "msd") == 0 ) { char *arg = NULL; if( (arg = strtok_r(NULL, separators, &brkt)) ) { if( strcmp(arg, "on") == 0 ) { if( TASK_MSD_EnableGet() ) { out("Mass Storage Device Mode already activated!\n"); } else { out("Mass Storage Device Mode activated - USB MIDI will be disabled!!!\n"); // wait a second to ensure that this message is print in MIOS Terminal int d; for(d=0; d<1000; ++d) MIOS32_DELAY_Wait_uS(1000); // activate MSD mode TASK_MSD_EnableSet(1); } } else if( strcmp(arg, "off") == 0 ) { if( !TASK_MSD_EnableGet() ) { out("Mass Storage Device Mode already deactivated!\n"); } else { out("Mass Storage Device Mode deactivated - USB MIDI will be available again\n"); TASK_MSD_EnableSet(0); } } else arg = NULL; } if( arg == NULL ) { out("Please enter 'msd on' or 'msd off'\n"); } } else if( strcmp(parameter, "lcd") == 0 ) { if( !brkt || !strlen(brkt) ) { out("Please specify string (can be optionally formatted)"); } else { out("Print '%s'", brkt); MUTEX_LCD_TAKE; // print from a dummy item mbng_event_item_t item; MBNG_EVENT_ItemInit(&item, MBNG_EVENT_CONTROLLER_DISABLED); item.label = brkt; MBNG_LCD_PrintItemLabel(&item, NULL, 0); MUTEX_LCD_GIVE; } } else if( strcmp(parameter, "run") == 0 ) { s32 section, value; if( (parameter = strtok_r(NULL, separators, &brkt)) ) { if( (section=get_dec(parameter)) < 0 || section >= 256 ) { out("Section number should be between 0..255!"); } else { ngr_section = section; } if( (parameter = strtok_r(NULL, separators, &brkt)) ) { if( (value=get_dec(parameter)) < -16384 || value >= 16383 ) { out("Value should be between -16384..16383!"); } else { ngr_value = value; } } } if( !MBNG_FILE_R_Valid() ) { out("ERROR: can't execute - missing %s.NGR file!", mbng_file_r_script_name); } else { out("Executing %s.NGR with ^section==%d ^value==%d", mbng_file_r_script_name, ngr_section, ngr_value); MBNG_FILE_R_ReadRequest(NULL, ngr_section, ngr_value, 1); } } else if( strcmp(parameter, "runstop") == 0 ) { if( MBNG_FILE_R_RunStop() > 0 ) { out("Stopped the execution of %s.NGR", mbng_file_r_script_name); } else { out("%s.NGR script not running.", mbng_file_r_script_name); } } else if( strcasecmp(parameter, "ngr_section") == 0 ) { s32 section; if( !(parameter = strtok_r(NULL, separators, &brkt)) ) { out("Please specify <ngr-section>! Current value: %d", ngr_section); } else if( (section=get_dec(parameter)) < 0 || section >= 256 ) { out("Section number should be between 0..255!"); } else { ngr_section = section; out(".NGR section set to %d", ngr_section); } } else if( strcasecmp(parameter, "ngr_value") == 0 ) { s32 value; if( !(parameter = strtok_r(NULL, separators, &brkt)) ) { out("Please specify <ngr-value>! Current value: %d", ngr_value); } else if( (value=get_dec(parameter)) < -16384 || value >= 16383 ) { out("Value should be between -16384..16383!"); } else { ngr_value = value; out(".NGR value set to %d", ngr_value); } } else if( strcasecmp(parameter, "ngr") == 0 ) { if( brkt == NULL ) { out("Please specify command!"); } else { char load_filename[9]; load_filename[0] = 0; MBNG_FILE_R_VarSectionSet(ngr_section); MBNG_FILE_R_VarValueSet(ngr_value); MBNG_FILE_R_Parser(0, brkt, NULL, NULL, load_filename, 0); out("Executed command with ^section==%d ^value==%d", ngr_section, ngr_value); if( load_filename[0] ) { s32 status = MBNG_PATCH_Load(parameter); if( status < 0 ) { out("ERROR: failed to load patch '%s' on SD Card (status %d)!", parameter, status); } } } } else if( strcasecmp(parameter, "ngc") == 0 ) { if( brkt == NULL ) { out("Please specify command!"); } else { u8 got_first_event_item = 0; MBNG_FILE_C_Parser(0, brkt, &got_first_event_item); out("Executed command."); } } else if( strcmp(parameter, "save") == 0 ) { if( !(parameter = strtok_r(NULL, separators, &brkt)) ) { out("ERROR: please specify filename for patch (up to 8 characters)!"); } else { if( strlen(parameter) > 8 ) { out("ERROR: 8 characters maximum!"); } else { s32 status = MBNG_PATCH_Store(parameter); if( status >= 0 ) { out("Patch '%s' stored on SD Card!", parameter); } else { out("ERROR: failed to store patch '%s' on SD Card (status %d)!", parameter, status); } } } } else if( strcmp(parameter, "load") == 0 ) { if( !(parameter = strtok_r(NULL, separators, &brkt)) ) { out("ERROR: please specify filename for patch (up to 8 characters)!"); } else { if( strlen(parameter) > 8 ) { out("ERROR: 8 characters maximum!"); } else { s32 status = MBNG_PATCH_Load(parameter); if( status >= 0 ) { out("Patch '%s' loaded from SD Card!", parameter); } else { out("ERROR: failed to load patch '%s' on SD Card (status %d)!", parameter, status); } } } } else if( strcmp(parameter, "show") == 0 ) { if( !(parameter = strtok_r(NULL, separators, &brkt)) ) { out("ERROR: please specify the item which should be displayed!"); } else { if( strcmp(parameter, "file") == 0 ) { MBNG_FILE_C_Debug(); } else if( strcmp(parameter, "douts") == 0 ) { int page; for(page=0; page<MIOS32_SRIO_NUM_DOUT_PAGES; ++page) { char buffer[3*MIOS32_SRIO_NUM_SR + 20]; sprintf(buffer, "Page %2d:", page+0); int i; for(i=0; i<MIOS32_SRIO_NUM_SR; ++i) { sprintf((char *)&buffer[8+i*3], " %02x", mios32_srio_dout[page][MIOS32_SRIO_NUM_SR-i-1]); } MIOS32_MIDI_SendDebugString(buffer); } } else if( strcmp(parameter, "ngr_tokens") == 0 || strcmp(parameter, "ngrtokens") == 0 ) { MBNG_FILE_R_TokenMemPrint(); } else if( strcmp(parameter, "poolbin") == 0 ) { MBNG_EVENT_PoolPrint(); } else if( strcmp(parameter, "pool") == 0 ) { MBNG_EVENT_PoolItemsPrint(); MBNG_EVENT_PoolMapsPrint(); } else if( strcmp(parameter, "id") == 0 || strcmp(parameter, "hw_id") == 0 ) { u8 search_hw_id = strcmp(parameter, "hw_id") == 0; const char *separator_colon = ":"; char *id_str = brkt; if( id_str == NULL || !strlen(id_str) ) { out("Please specify <element>:<id> (e.g. LED:1)!"); } else { char *values_str; mbng_event_item_id_t id; if( !(values_str = strtok_r(NULL, separator_colon, &brkt)) || (id=MBNG_EVENT_ItemIdFromControllerStrGet(values_str)) == MBNG_EVENT_CONTROLLER_DISABLED ) { out("Invalid element name '%s'!", id_str); } else { char *id_lower_str = brkt; int id_lower = 0; if( !(values_str = strtok_r(NULL, separator_colon, &brkt)) || (id_lower=get_dec(values_str)) < 1 || id_lower > 0xfff ) { out("Invalid element %s '%s:%s' (expecting %s:1 .. %s:4095)!", search_hw_id ? "hw_id" : "id", id_str, id_lower_str, id_str, id_str); } else { id = id | id_lower; if( search_hw_id ) { u8 num = MBNG_EVENT_ItemSearchByHwIdAndPrint(id); if( num < 1 ) { out("No items found which are assigned to this hw_id!"); } } else { u8 num = MBNG_EVENT_ItemSearchByIdAndPrint(id); if( num < 1 ) { out("No items found which are assigned to this id!"); } } } } } } else { out("ERROR: invalid item which should be showed - see 'show pool' for available items!"); } } } else if( strcmp(parameter, "reset") == 0 ) { MIOS32_SYS_Reset(); } else if( strcmp(parameter, "set") == 0 ) { if( (parameter = strtok_r(NULL, separators, &brkt)) ) { if( strcmp(parameter, "dout") == 0 ) { s32 pin = -1; if( (parameter = strtok_r(NULL, separators, &brkt)) ) { if( strcmp(parameter, "all") == 0 ) { pin = -42; } else { pin = get_dec(parameter); } } if( (pin < 0 && pin != -42) || pin >= (MIOS32_SRIO_NUM_SR*8) ) { out("Pin number should be between 0..%d", MIOS32_SRIO_NUM_SR*8 - 1); } else { s32 value = -1; if( (parameter = strtok_r(NULL, separators, &brkt)) ) value = get_dec(parameter); if( value < 0 || value > 1 ) { out("Expecting value 1 or 0 for DOUT pin %d", pin); } else { if( pin == -42 ) { for(pin=0; pin<(MIOS32_SRIO_NUM_SR*8); ++pin) MIOS32_DOUT_PinSet(pin, value); out("All DOUT pins set to %d", value); } else { MIOS32_DOUT_PinSet(pin, value); out("DOUT Pin %d (SR#%d.D%d) set to %d", pin, (pin/8)+1, 7-(pin%8), value); } } } } else if( strcmp(parameter, "debug") == 0 ) { int on_off = -1; if( (parameter = strtok_r(NULL, separators, &brkt)) ) on_off = get_on_off(parameter); if( on_off < 0 ) { out("Expecting 'on' or 'off'"); } else { debug_verbose_level = on_off ? DEBUG_VERBOSE_LEVEL_INFO : DEBUG_VERBOSE_LEVEL_ERROR; out("Debug mode turned %s", on_off ? "on" : "off"); } } else if( strcmp(parameter, "autoload") == 0 ) { int on_off = -1; if( (parameter = strtok_r(NULL, separators, &brkt)) ) on_off = get_on_off(parameter); if( on_off < 0 ) { out("Expecting 'on' or 'off'"); } else { autoload_enabled = on_off; out("Autoload of .NGC file after filebrowser upload %s", on_off ? "on" : "off"); } } else { out("Unknown set parameter: '%s'!", parameter); } } else { out("Missing parameter after 'set'!"); } } else { out("Unknown command - type 'help' to list available commands!"); } } return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // Parser for a complete line - also used by shell.c for telnet ///////////////////////////////////////////////////////////////////////////// s32 TERMINAL_ParseLine(char *input, void *_output_function) { void (*out)(char *format, ...) = _output_function; char *separators = " \t"; char *brkt; char *parameter; if( UIP_TERMINAL_ParseLine(input, _output_function) > 0 ) return 0; // command parsed by UIP Terminal if( MIDIMON_TerminalParseLine(input, _output_function) > 0 ) return 0; // command parsed if( MIDI_ROUTER_TerminalParseLine(input, _output_function) > 0 ) return 0; // command parsed if( AOUT_TerminalParseLine(input, _output_function) > 0 ) return 0; // command parsed #ifdef MIOS32_LCD_universal if( APP_LCD_TerminalParseLine(input, _output_function) >= 1 ) return 0; // command parsed #endif if( (parameter = strtok_r(input, separators, &brkt)) ) { if( strcmp(parameter, "help") == 0 ) { out("Welcome to " MIOS32_LCD_BOOT_MSG_LINE1 "!"); out("Following commands are available:"); out(" system: print system info"); out(" memory: print memory allocation info\n"); out(" sdcard: print SD Card info\n"); out(" sdcard_format: formats the SD Card (you will be asked for confirmation)\n"); UIP_TERMINAL_Help(_output_function); MIDIMON_TerminalHelp(_output_function); MIDI_ROUTER_TerminalHelp(_output_function); out(" set dout <pin> <0|1>: directly sets DOUT (all or 0..%d) to given level (1 or 0)", MIOS32_SRIO_NUM_SR*8 - 1); out(" set update_rate <1..%d>: sets update rate of sound engine (factor*500 Hz), current: %d\n", APP_CV_UPDATE_RATE_FACTOR_MAX, APP_CvUpdateRateFactorGet()); AOUT_TerminalHelp(_output_function); #ifdef MIOS32_LCD_universal APP_LCD_TerminalHelp(_output_function); #endif out(" save <name>: stores current config on SD Card"); out(" load <name>: restores config from SD Card"); out(" show: shows the current configuration file"); out(" nrpn: shows the current NRPN parameters"); out(" msd <on|off>: enables Mass Storage Device driver"); out(" reset: resets the MIDIbox (!)\n"); out(" help: this page"); out(" exit: (telnet only) exits the terminal"); } else if( strcmp(parameter, "system") == 0 ) { TERMINAL_PrintSystem(_output_function); } else if( strcmp(parameter, "memory") == 0 ) { TERMINAL_PrintMemoryInfo(out); } else if( strcmp(parameter, "sdcard") == 0 ) { TERMINAL_PrintSdCardInfo(out); } else if( strcmp(parameter, "sdcard_format") == 0 ) { if( !brkt || strcasecmp(brkt, "yes, I'm sure") != 0 ) { out("ATTENTION: this command will format your SD Card!!!"); out(" ALL DATA WILL BE DELETED FOREVER!!!"); out(" Check the current content with the 'sdcard' command"); out(" Create a backup on your computer if necessary!"); out("To start formatting, please enter: sdcard_format yes, I'm sure"); if( brkt ) { out("('%s' wasn't the right \"password\")", brkt); } } else { MUTEX_SDCARD_TAKE; out("Formatting SD Card..."); FRESULT res; if( (res=f_mkfs(0,0,0)) != FR_OK ) { out("Formatting failed with error code: %d!", res); } else { out("...with success!"); MBCV_FILE_UnloadAllFiles(); MBCV_FILE_CreateDefaultFiles(); } MUTEX_SDCARD_GIVE; } } else if( strcmp(parameter, "msd") == 0 ) { char *arg = NULL; if( (arg = strtok_r(NULL, separators, &brkt)) ) { if( strcmp(arg, "on") == 0 ) { if( TASK_MSD_EnableGet() ) { out("Mass Storage Device Mode already activated!\n"); } else { out("Mass Storage Device Mode activated - USB MIDI will be disabled!!!\n"); // wait a second to ensure that this message is print in MIOS Terminal int d; for(d=0; d<1000; ++d) MIOS32_DELAY_Wait_uS(1000); // activate MSD mode TASK_MSD_EnableSet(1); } } else if( strcmp(arg, "off") == 0 ) { if( !TASK_MSD_EnableGet() ) { out("Mass Storage Device Mode already deactivated!\n"); } else { out("Mass Storage Device Mode deactivated - USB MIDI will be available again.n"); TASK_MSD_EnableSet(0); } } else arg = NULL; } if( arg == NULL ) { out("Please enter 'msd on' or 'msd off'\n"); } } else if( strcmp(parameter, "save") == 0 ) { if( !(parameter = strtok_r(NULL, separators, &brkt)) ) { out("ERROR: please specify filename for patch (up to 8 characters)!"); } else { if( strlen(parameter) > 8 ) { out("ERROR: 8 characters maximum!"); } else { s32 status = MBCV_PATCH_StoreGlobal(parameter); if( status >= 0 ) { out("Patch '%s' stored on SD Card!", parameter); } else { out("ERROR: failed to store patch '%s' on SD Card (status %d)!", parameter, status); } } } } else if( strcmp(parameter, "load") == 0 ) { if( !(parameter = strtok_r(NULL, separators, &brkt)) ) { out("ERROR: please specify filename for patch (up to 8 characters)!"); } else { if( strlen(parameter) > 8 ) { out("ERROR: 8 characters maximum!"); } else { s32 status = MBCV_PATCH_LoadGlobal(parameter); if( status >= 0 ) { out("Patch '%s' loaded from SD Card!", parameter); } else { out("ERROR: failed to load patch '%s' on SD Card (status %d)!", parameter, status); } } } } else if( strcmp(parameter, "show") == 0 ) { MBCV_FILE_P_Debug(); } else if( strcmp(parameter, "nrpn") == 0 || strcmp(parameter, "nrpns") == 0 ) { TERMINAL_ShowNrpns(out); } else if( strcmp(parameter, "reset") == 0 ) { MIOS32_SYS_Reset(); } else if( strcmp(parameter, "set") == 0 ) { if( (parameter = strtok_r(NULL, separators, &brkt)) ) { if( strcmp(parameter, "dout") == 0 ) { s32 pin = -1; if( (parameter = strtok_r(NULL, separators, &brkt)) ) { if( strcmp(parameter, "all") == 0 ) { pin = -42; } else { pin = get_dec(parameter); } } if( (pin < 0 && pin != -42) || pin >= (MIOS32_SRIO_NUM_SR*8) ) { out("Pin number should be between 0..%d", MIOS32_SRIO_NUM_SR*8 - 1); } else { s32 value = -1; if( (parameter = strtok_r(NULL, separators, &brkt)) ) value = get_dec(parameter); if( value < 0 || value > 1 ) { out("Expecting value 1 or 0 for DOUT pin %d", pin); } else { if( pin == -42 ) { for(pin=0; pin<(MIOS32_SRIO_NUM_SR*8); ++pin) MIOS32_DOUT_PinSet(pin, value); out("All DOUT pins set to %d", value); } else { MIOS32_DOUT_PinSet(pin, value); out("DOUT Pin %d (SR#%d.D%d) set to %d", pin, (pin/8)+1, 7-(pin%8), value); } } } } else if( strcmp(parameter, "update_rate") == 0 ) { s32 factor = -1; if( (parameter = strtok_r(NULL, separators, &brkt)) ) { factor = get_dec(parameter); } if( (factor < 1 || factor > APP_CV_UPDATE_RATE_FACTOR_MAX) ) { out("Update Rate should be between 1..%d!", APP_CV_UPDATE_RATE_FACTOR_MAX); } else { APP_CvUpdateRateFactorSet(factor); out("Update Rate set to %d Hz (factor %d)", 500*APP_CvUpdateRateFactorGet(), APP_CvUpdateRateFactorGet()); } } else { out("Unknown set parameter: '%s'!", parameter); } } else { out("Missing parameter after 'set'!"); } } else { out("Unknown command - type 'help' to list available commands!"); } } return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // Parser ///////////////////////////////////////////////////////////////////////////// s32 SEQ_TERMINAL_Parse(mios32_midi_port_t port, u8 byte) { // temporary change debug port (will be restored at the end of this function) mios32_midi_port_t prev_debug_port = MIOS32_MIDI_DebugPortGet(); MIOS32_MIDI_DebugPortSet(port); if( byte == '\r' ) { // ignore } else if( byte == '\n' ) { // example for parsing the command: char *separators = " \t"; char *brkt; char *parameter; if( (parameter = strtok_r(line_buffer, separators, &brkt)) ) { if( strcmp(parameter, "help") == 0 ) { SEQ_TERMINAL_PrintHelp(DEBUG_MSG); } else if( strcmp(parameter, "system") == 0 ) { SEQ_TERMINAL_PrintSystem(DEBUG_MSG); } else if( strcmp(parameter, "global") == 0 ) { SEQ_TERMINAL_PrintGlobalConfig(DEBUG_MSG); } else if( strcmp(parameter, "bookmarks") == 0 ) { SEQ_TERMINAL_PrintBookmarks(DEBUG_MSG); } else if( strcmp(parameter, "config") == 0 ) { SEQ_TERMINAL_PrintSessionConfig(DEBUG_MSG); } else if( strcmp(parameter, "tracks") == 0 ) { SEQ_TERMINAL_PrintTracks(DEBUG_MSG); } else if( strcmp(parameter, "track") == 0 ) { char *arg; if( (arg = strtok_r(NULL, separators, &brkt)) ) { int track = get_dec(arg); if( track < 1 || track > SEQ_CORE_NUM_TRACKS ) { MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Wrong track number %d - expected track 1..%d\n", track, SEQ_CORE_NUM_TRACKS); MUTEX_MIDIOUT_GIVE; } else { SEQ_TERMINAL_PrintTrack(DEBUG_MSG, track-1); } } else { MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Please specify track, e.g. \"track 1\"\n"); MUTEX_MIDIOUT_GIVE; } } else if( strcmp(parameter, "mixer") == 0 ) { SEQ_TERMINAL_PrintCurrentMixerMap(DEBUG_MSG); } else if( strcmp(parameter, "song") == 0 ) { SEQ_TERMINAL_PrintCurrentSong(DEBUG_MSG); } else if( strcmp(parameter, "grooves") == 0 ) { SEQ_TERMINAL_PrintGrooveTemplates(DEBUG_MSG); } else if( strcmp(parameter, "memory") == 0 ) { SEQ_TERMINAL_PrintMemoryInfo(DEBUG_MSG); #if !defined(MIOS32_FAMILY_EMULATION) } else if( strcmp(parameter, "network") == 0 ) { SEQ_TERMINAL_PrintNetworkInfo(DEBUG_MSG); } else if( strcmp(parameter, "udpmon") == 0 ) { MUTEX_MIDIOUT_TAKE; char *arg; if( (arg = strtok_r(NULL, separators, &brkt)) ) { int level = get_dec(arg); switch( level ) { case UDP_MONITOR_LEVEL_0_OFF: DEBUG_MSG("Set UDP monitor level to %d (off)\n", level); break; case UDP_MONITOR_LEVEL_1_OSC_REC: DEBUG_MSG("Set UDP monitor level to %d (received packets assigned to a OSC1..4 port)\n", level); break; case UDP_MONITOR_LEVEL_2_OSC_REC_AND_SEND: DEBUG_MSG("Set UDP monitor level to %d (received and sent packets assigned to a OSC1..4 port)\n", level); break; case UDP_MONITOR_LEVEL_3_ALL_GEQ_1024: DEBUG_MSG("Set UDP monitor level to %d (all received and sent packets with port number >= 1024)\n", level); break; case UDP_MONITOR_LEVEL_4_ALL: DEBUG_MSG("Set UDP monitor level to %d (all received and sent packets)\n", level); break; default: DEBUG_MSG("Invalid level %d - please specify monitor level 0..4\n", level); level = -1; // invalidate level for next if() check } if( level >= 0 ) UIP_TASK_UDP_MonitorLevelSet(level); } else { DEBUG_MSG("Please specify monitor level (0..4)\n"); } MUTEX_MIDIOUT_GIVE; #endif } else if( strcmp(parameter, "sdcard") == 0 ) { SEQ_TERMINAL_PrintSdCardInfo(DEBUG_MSG); } else if( strcmp(parameter, "testaoutpin") == 0 ) { char *arg; int pin_number = -1; int level = -1; if( (arg = strtok_r(NULL, separators, &brkt)) ) { if( strcmp(arg, "cs") == 0 ) pin_number = 1; else if( strcmp(arg, "si") == 0 ) pin_number = 2; else if( strcmp(arg, "sc") == 0 ) pin_number = 3; else if( strcmp(arg, "reset") == 0 ) { pin_number = 0; level = 0; // dummy } } if( pin_number < 0 ) { MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Please specifiy valid AOUT pin name: cs, si or sc\n"); MUTEX_MIDIOUT_GIVE; } else { if( (arg = strtok_r(NULL, separators, &brkt)) ) level = get_dec(arg); if( level != 0 && level != 1 ) { MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Please specifiy valid logic level for AOUT pin: 0 or 1\n"); MUTEX_MIDIOUT_GIVE; } } if( pin_number >= 0 && level >= 0 ) { SEQ_TERMINAL_TestAoutPin(DEBUG_MSG, pin_number, level); } else { MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Following commands are supported:\n"); DEBUG_MSG("testaoutpin cs 0 -> sets AOUT:CS to 0.4V"); DEBUG_MSG("testaoutpin cs 1 -> sets AOUT:CS to ca. 4V"); DEBUG_MSG("testaoutpin si 0 -> sets AOUT:SI to ca. 0.4V"); DEBUG_MSG("testaoutpin si 1 -> sets AOUT:SI to ca. 4V"); DEBUG_MSG("testaoutpin sc 0 -> sets AOUT:SC to ca. 0.4V"); DEBUG_MSG("testaoutpin sc 1 -> sets AOUT:SC to ca. 4V"); DEBUG_MSG("testaoutpin reset -> re-initializes AOUT module so that it can be used again."); MUTEX_MIDIOUT_GIVE; } } else if( strcmp(parameter, "play") == 0 ) { SEQ_UI_Button_Play(0); MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Sequencer started...\n"); MUTEX_MIDIOUT_GIVE; } else if( strcmp(parameter, "stop") == 0 ) { SEQ_UI_Button_Stop(0); MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Sequencer stopped...\n"); MUTEX_MIDIOUT_GIVE; } else if( strcmp(parameter, "reset") == 0 ) { MIOS32_SYS_Reset(); } else { MUTEX_MIDIOUT_TAKE; DEBUG_MSG("Unknown command - type 'help' to list available commands!\n"); MUTEX_MIDIOUT_GIVE; } } line_ix = 0; } else if( line_ix < (STRING_MAX-1) ) { line_buffer[line_ix++] = byte; line_buffer[line_ix] = 0; } // restore debug port MIOS32_MIDI_DebugPortSet(prev_debug_port); return 0; // no error }