static bool cmd_settings_reset(Serial* pSer, char* value, size_t len) { if(len > 0 && (value[0] == '1' || value[0] == '2' )) { if(value[0] == '2') { // clear the settings if AT+RESET=1 settings_clear(); SERIAL_PRINT_P(pSer,PSTR("Settings cleared, ")); } SERIAL_PRINT_P(pSer,PSTR("Restarting...\r\n")); //reboot the device soft_reset(); } return true; }
/* * AT+SEND - just send the beacon message once */ static bool cmd_send(Serial* pSer, char* value, size_t len) { (void)value; (void)len; SERIAL_PRINT_P(pSer,PSTR("NOT SUPPRTED YET\r\n")); // if(len == 0){ // // send test message // beacon_send_text(); // SERIAL_PRINT_P(pSer,PSTR("SEND OK\r\n")); // }else{ // //TODO send user input message out, build the ax25 path according settings // SERIAL_PRINT_P(pSer,PSTR("NOT SUPPRTED YET\r\n")); // } return true; }
/* * AT+MODE=[0|1|2] */ static bool cmd_switch_mode(Serial* pSer, char* value, size_t len){ bool modeOK = false; if(len > 0 ){ int i = atoi(value); if(i == (int)currentMode && i == g_settings.run_mode){ // already in this mode, bail out. return true; } modeOK = true; switch(i){ case MODE_CFG: // Enter COMMAND/CONFIG MODE currentMode = MODE_CFG; g_ax25.pass_through = 0; // parse ax25 frames ser_purge(pSer); // clear all rx/tx buffer SERIAL_PRINT_P(pSer,PSTR("Enter Config mode\r\n")); break; #if MOD_KISS case MODE_KISS: // Enter KISS MODE currentMode = MODE_KISS; g_ax25.pass_through = 1; // don't parse ax25 frames ser_purge(pSer); // clear serial rx/tx buffer SERIAL_PRINT_P(pSer,PSTR("Enter KISS mode\r\n")); break; #endif #if MOD_TRACKER case MODE_TRACKER: currentMode = MODE_TRACKER; kfile_printf_P((KFile*)pSer,PSTR("Enter Tracker mode\r\n")); kfile_flush((KFile*)pSer); ser_purge(pSer); // should enable the tracker/gps tracker_init_gps(); break; #endif #if MOD_DIGI case MODE_DIGI: // DIGI MODE currentMode = MODE_DIGI; g_ax25.pass_through = 0; // need parse ax25 frames SERIAL_PRINT_P(pSer,PSTR("Enter Digi mode\r\n")); break; #endif default: // unknown mode modeOK = false; break; } // end of switch // save to settings/run_mode if(modeOK){ if(currentMode != g_settings.run_mode){ settings_set_params(SETTINGS_RUN_MODE,¤tMode,1); settings_save(); } }else{ SERIAL_PRINTF_P(pSer,PSTR("Invalid mode %s, [0|1|2|3] is accepted\r\n"),value); } }else{ // no parameters, just dump the mode SERIAL_PRINTF_P(pSer,PSTR("Current mode %d/%d\r\n"),currentMode,g_settings.run_mode); } return true; }
/* * callback when beacon mode is end */ static void beacon_mode_exit_callback(void){ currentMode = MODE_CFG; SERIAL_PRINT_P((&g_serial),PSTR("Exit Beacon mode\r\n")); }
static void kiss_mode_exit_callback(void){ currentMode = MODE_CFG; SERIAL_PRINT_P((&g_serial),PSTR("Exit KISS mode\r\n")); }
void console_parse_command(char* command, size_t commandLen) { char *key = NULL, *value = NULL; uint8_t valueLen = 0; Serial *pSer = &g_serial; // A simple hack to command "!5" #if CFG_BEACON_TEST if(commandLen > 0 && command[0] == '!') { cmd_test_send(pSer, command+1,commandLen - 1); return; } #endif if(commandLen >0 && command[0] == '?') { cmd_info(pSer,0,0); #if CONSOLE_HELP_COMMAND_ENABLED cmd_help(pSer,0,0); #endif return; } //TinyAPRS AT Command Handler if(commandLen >=6 && (command[0] == 'A' || command[0] == 'a') && (command[1] == 'T' || command[1] == 't') && (command[2] == '+') ) { // looking for the '=' char* t = NULL; uint8_t i = 3; for(; i < commandLen; i++) { if(command[i] == '=') { t = command + i; break; } } if(t != NULL) { *t = 0; // split the key=value string into 2 strings. key = command + 3; value = t + 1; valueLen = strlen(value); } } // Compatible with OT2/Other TNCs KISS init command else if( (commandLen >=10) && (strcasecmp_P(command,PSTR("AMODE KISS")) == 0)) { // enter the kiss mode // reuse the existing command buffer key = command + 6; key[4] = 0; value = command; value[0] = '1'; value[1] = 0; valueLen = 1; } else if( (commandLen >=7) && (strcasecmp_P(command,PSTR("KISS ON")) == 0)) { key = command; key[4] = 0; value = command + 5; value[0] = '1'; value[1] = 0; valueLen = 1; } if(key == NULL && value == NULL) { // bail out SERIAL_PRINTF_P(pSer,PSTR("INVALID CMD: %.*s\r\n"),commandLen,command); return; } // look the command registry // convert to upper case strupr(key); PFUN_CMD_HANDLER fun = console_lookup_command(key); if(fun) { if(!fun(pSer, value, valueLen)) { // handle failure, should be invalid values SERIAL_PRINT_P(pSer,PSTR("INVALID CMD VALUE\r\n")); // user input command is parsed but the value is not valid } } else { SERIAL_PRINTF_P(pSer,PSTR("UNKNOWN CMD: %.*s\r\n"),commandLen,command); } return; }
static bool cmd_help(Serial* pSer, char* command, size_t len) { (void)command; (void)len; SERIAL_PRINT_P(pSer,PSTR("\r\nAT commands supported\r\n")); SERIAL_PRINT_P(pSer,PSTR("-----------------------------------------------------------\r\n")); #if CONSOLE_SETTINGS_COMMANDS_ENABLED SERIAL_PRINT_P(pSer,PSTR("AT+CALL=[CALLSIGN-SSID]\t;Set my callsign\r\n")); SERIAL_PRINT_P(pSer,PSTR("AT+DEST=[CALLSIGN-SSID]\t\t;Set destination callsign\r\n")); SERIAL_PRINT_P(pSer,PSTR("AT+PATH=[WIDE1-1,WIDE2-2]\t;Set PATH, max 2 allowed\r\n")); SERIAL_PRINT_P(pSer,PSTR("AT+SYMBOL=[SYMBOL_TABLE/IDX]\t;Set beacon symbol\r\n")); SERIAL_PRINT_P(pSer,PSTR("AT+BEACON=[45]\t\t;Set beacon interval, 0 to disable \r\n")); SERIAL_PRINT_P(pSer,PSTR("AT+TEXT=[!3011.54N/12007.35E>]\t;Set beacon text \r\n")); #endif SERIAL_PRINT_P(pSer,PSTR("AT+MODE=[0|1|2]\t\t\t;Set device run mode\r\n")); SERIAL_PRINT_P(pSer,PSTR("AT+KISS=[1]\t\t\t;Enter kiss mode\r\n")); SERIAL_PRINT_P(pSer,PSTR("?\t\t\t\t;Display help messages\r\n")); SERIAL_PRINT_P(pSer, PSTR("\r\nCopyright 2015, BG5HHP([email protected])\r\n\r\n")); return true; }