📄 gsm_me_ta.cc
字号:
} Parser p(_at->chat("+COPS?", "+COPS:")); result._mode = (OPModes)p.parseInt(); // some phones (e.g. Nokia Card Phone 2.0) just return "+COPS: 0" // if no network connection if (p.parseComma(true)) { if (p.parseInt() == 0) { p.parseComma(); result._longName = p.parseString(); } } } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } // get short format try { try { _at->chat("+COPS=3,1"); } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } Parser p(_at->chat("+COPS?", "+COPS:")); result._mode = (OPModes)p.parseInt(); // some phones (e.g. Nokia Card Phone 2.0) just return "+COPS: 0" // if no network connection if (p.parseComma(true)) { if (p.parseInt() == 1) { p.parseComma(); result._shortName = p.parseString(); } } } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } // get numeric format try { try { _at->chat("+COPS=3,2"); } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } Parser p(_at->chat("+COPS?", "+COPS:")); result._mode = (OPModes)p.parseInt(); // some phones (e.g. Nokia Card Phone 2.0) just return "+COPS: 0" // if no network connection if (p.parseComma(true)) { if (p.parseInt() == 2) { p.parseComma(); try { result._numericName = p.parseInt(); } catch (GsmException &e) { if (e.getErrorClass() == ParserError) { // the Ericsson GM12 GSM modem returns the numeric ID as string string s = p.parseString(); result._numericName = checkNumber(s); } else throw e; } } } } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } return result;}void MeTa::setCurrentOPInfo(OPModes mode, string longName, string shortName, int numericName) throw(GsmException){ bool done = false; if (longName != "") { try { _at->chat("+COPS=" + intToStr((int)mode) + ",0,\"" + longName + "\""); done = true; } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } } if (shortName != "" && ! done) { try { _at->chat("+COPS=" + intToStr((int)mode) + ",1,\"" + shortName + "\""); done = true; } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } } if (numericName != NOT_SET && ! done) { try { _at->chat("+COPS=" + intToStr((int)mode) + ",2," + intToStr(numericName)); done = true; } catch (GsmException &e) { if (e.getErrorClass() != ChatError) throw; } } if (! done) throw GsmException(_("unable to set operator"), OtherError);}vector<string> MeTa::getFacilityLockCapabilities() throw(GsmException){ string locks = _at->chat("+CLCK=?", "+CLCK:"); // some TA don't add '(' and ')' (Option FirstFone) if (locks.length() && locks[0] != '(') { locks.insert(locks.begin(),'('); locks += ')'; } Parser p(locks); return p.parseStringList();}bool MeTa::getFacilityLockStatus(string facility, FacilityClass cl) throw(GsmException){ // some TA return always multiline response with all classes // (Option FirstFone) // !!! errors handling is correct (responses.empty() true) ? vector<string> responses = _at->chatv("+CLCK=\"" + facility + "\",2,," + intToStr((int)cl),"+CLCK:",true); for (vector<string>::iterator i = responses.begin(); i != responses.end(); ++i) { Parser p(*i); int enabled = p.parseInt(); // if the first time and there is no comma this // return direct state of classes // else return all classes if (i == responses.begin()) { if (!p.parseComma(true)) return enabled == 1; } else p.parseComma(); if ( p.parseInt() == (int)cl ) return enabled == 1; } return false;// Parser p(_at->chat("+CLCK=\"" + facility + "\",2,," + intToStr((int)cl),// "+CLCK:"));// return p.parseInt() == 1;}void MeTa::lockFacility(string facility, FacilityClass cl, string passwd) throw(GsmException){ if (passwd == "") _at->chat("+CLCK=\"" + facility + "\",1,," + intToStr((int)cl)); else _at->chat("+CLCK=\"" + facility + "\",1,\"" + passwd + "\"," + intToStr((int)cl));}void MeTa::unlockFacility(string facility, FacilityClass cl, string passwd) throw(GsmException){ if (passwd == "") _at->chat("+CLCK=\"" + facility + "\",0,," + intToStr((int)cl)); else _at->chat("+CLCK=\"" + facility + "\",0,\"" + passwd + "\"," + intToStr((int)cl));}vector<PWInfo> MeTa::getPasswords() throw(GsmException){ vector<PWInfo> result; Parser p(_at->chat("+CPWD=?", "+CPWD:")); while (1) { PWInfo pwi; if (!p.parseChar('(', true)) break; // exit if no new tuple pwi._facility = p.parseString(); p.parseComma(); pwi._maxPasswdLen = p.parseInt(); p.parseChar(')'); p.parseComma(true); result.push_back(pwi); } return result;}void MeTa::setPassword(string facility, string oldPasswd, string newPasswd) throw(GsmException){ _at->chat("+CPWD=\"" + facility + "\",\"" + oldPasswd + "\",\"" + newPasswd + "\"");}bool MeTa::getNetworkCLIP() throw(GsmException){ Parser p(_at->chat("+CLIP?", "+CLIP:")); p.parseInt(); // ignore result code presentation p.parseComma(); return p.parseInt() == 1;}void MeTa::setCLIPPresentation(bool enable) throw(GsmException){ if (enable) _at->chat("+CLIP=1"); else _at->chat("+CLIP=0");}bool MeTa::getCLIPPresentation() throw(GsmException){ Parser p(_at->chat("+CLIP?", "+CLIP:")); return p.parseInt() == 1; // ignore rest of line}void MeTa::setCallForwarding(ForwardReason reason, ForwardMode mode, string number, string subaddr, FacilityClass cl, int forwardTime) throw(GsmException){ // FIXME subaddr is currently ignored if (forwardTime != NOT_SET && (forwardTime < 0 || forwardTime > 30)) throw GsmException(_("call forward time must be in the range 0..30"), ParameterError); int numberType; number = removeWhiteSpace(number); if (number.length() > 0 && number[0] == '+') { numberType = InternationalNumberFormat; number = number.substr(1); // skip the '+' at the beginning } else numberType = UnknownNumberFormat; _at->chat("+CCFC=" + intToStr(reason) + "," + intToStr(mode) + "," "\"" + number + "\"," + (number.length() > 0 ? intToStr(numberType) : "") + "," + intToStr(cl) + // FIXME subaddr and type (forwardTime == NOT_SET ? "" : (",,," + intToStr(forwardTime))));} void MeTa::getCallForwardInfo(ForwardReason reason, ForwardInfo &voice, ForwardInfo &fax, ForwardInfo &data) throw(GsmException){ // Initialize to some sensible values: voice._active = false; voice._cl = VoiceFacility; voice._time = -1; voice._reason = NoReason; data._active = false; data._cl = DataFacility; data._time = -1; data._reason = NoReason; fax._active = false; fax._cl = FaxFacility; fax._time = -1; fax._reason = NoReason; vector<string> responses = _at->chatv("+CCFC=" + intToStr(reason) + ",2", "+CCFC:"); if (responses.size() == 1) { // only one line was returned. We have to ask for all three classes // (voice, data, fax) separately responses.clear(); responses.push_back(_at->chat("+CCFC=" + intToStr(reason) + ",2,,,1", "+CCFC:")); responses.push_back(_at->chat("+CCFC=" + intToStr(reason) + ",2,,,2", "+CCFC:")); responses.push_back(_at->chat("+CCFC=" + intToStr(reason) + ",2,,,4", "+CCFC:")); } for (vector<string>::iterator i = responses.begin(); i != responses.end(); ++i) { Parser p(*i); int status = p.parseInt(); p.parseComma(); FacilityClass cl = (FacilityClass)p.parseInt(); string number; string subAddr; int forwardTime = NOT_SET; // parse number if (p.parseComma(true)) { number = p.parseString(); p.parseComma(); unsigned int numberType = p.parseInt(); if (numberType == InternationalNumberFormat) number = "+" + number; // parse subaddr if (p.parseComma(true)) { // FIXME subaddr type not handled subAddr = p.parseString(true); p.parseComma(); p.parseInt(true); // parse forwardTime if (p.parseComma(true)) { forwardTime = p.parseInt(); } } } switch (cl) { case VoiceFacility: voice._active = (status == 1); voice._cl = VoiceFacility; voice._number = number; voice._subAddr = subAddr; voice._time = forwardTime; voice._reason = reason; break; case DataFacility: data._active = (status == 1); data._cl = DataFacility; data._number = number; data._subAddr = subAddr; data._time = forwardTime; data._reason = reason; break; case FaxFacility: fax._active = (status == 1); fax._cl = FaxFacility; fax._number = number; fax._subAddr = subAddr; fax._time = forwardTime; fax._reason = reason; break; } }}int MeTa::getBatteryChargeStatus() throw(GsmException){ Parser p(_at->chat("+CBC", "+CBC:")); return p.parseInt();}int MeTa::getBatteryCharge() throw(GsmException){ Parser p(_at->chat("+CBC", "+CBC:")); p.parseInt(); p.parseComma(); return p.parseInt();}int MeTa::getFunctionalityLevel() throw(GsmException){ try { Parser p(_at->chat("+CFUN?", "+CFUN:")); // some phones return functionality level like "(2)" bool expectClosingParen = p.parseChar('(', true); int result = p.parseInt(); if (expectClosingParen) p.parseChar(')'); return result; } catch (GsmException &x) { if (x.getErrorClass() == ChatError) { throw GsmException(_("Functionality Level commands not supported by ME"), MeTaCapabilityError); } else { throw; } }}void MeTa::setFunctionalityLevel(int level) throw(GsmException){ try { Parser p(_at->chat("+CFUN=" + intToStr(level))); } catch (GsmException &x) { if (x.getErrorClass() == ChatError) { // If the command AT+CFUN commands really aren't supported by the ME, // then this will throw an appropriate exception for us. getFunctionalityLevel(); // If the number was just out of range, we get here. throw GsmException(_("Requested Functionality Level out of range"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -