/* (C) 2003 XDA Developers * Author: Willem Jan Hengeveld * Web: http://www.xda-developers.com/ * * $Header$ */ #include "stdafx.h" #include "switcher.h" #include "debug.h" BandSwitcher::BandSwitcher() { g_gsm.open(); g_gsm.send(CString(L"ATV1E1\r")); CString reply; g_gsm.receive(reply); // ignore reply } BandSwitcher::~BandSwitcher() { g_gsm.close(); } Band BandSwitcher::GetCurrentBand() { g_gsm.flush(); if (!g_gsm.send(CString(L"AT%BAND\r"))) { debug("error getting band\n"); return BAND_UNKNOWN; } Sleep(200); CString reply; if (!g_gsm.receive(reply)) { debug("error getting band - no reply\n"); return BAND_UNKNOWN; } int bandpos= reply.Find(L"+BAND:"); if (bandpos<0) { debug("error getting band - unknown reply: %ls\n", reply.GetBuffer(0)); return BAND_UNKNOWN; } long curband= _tcstol(reply.Mid(bandpos+7).GetBuffer(0), 0, 0); switch (curband) { case 1: return BAND_900; case 3: return BAND_1900; case 6: return BAND_900_1800; default: debug("current band: unknown reply: %ls\n", reply.GetBuffer(0)); return BAND_UNKNOWN; } } bool BandSwitcher::SwitchTo(Band band) { TCHAR *req= NULL; switch(band) { case BAND_900: req= L"AT%CHG900\r"; break; case BAND_1900: req= L"AT%CHG1900\r"; break; case BAND_900_1800: req= L"AT%CHGDUAL\r"; break; } if (req==NULL) return false; g_gsm.flush(); if (!g_gsm.send(CString(req))) return false; CString reply; if (!g_gsm.receive(reply)) return false; int okpos= reply.Find(L"OK"); if (okpos<0) return false; return true; }