static int8_t _gsmWriteLine(const char *cmd) { size_t i; // NOTE: debugging should no be mixed to modem command and response to // avoid timeing issues and discrepancy between debug and release // versions gsmDebug("TX [%s]\n", cmd); // Purge any buffered data before sending a new command ser_purge(gsm); // Clear error flags ser_setstatus(gsm, 0); // Sending the AT command WATCHDOG_RESET(); for (i=0; cmd[i]!='\0'; i++) { kfile_putc(cmd[i], &(gsm->fd)); WATCHDOG_RESET(); } kfile_write(&(gsm->fd), "\r\n", 2); return i; }
/* * 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; }