📄 gsm_me_ta.cc
字号:
ParameterError); } throw; }}int MeTa::getSignalStrength() throw(GsmException){ Parser p(_at->chat("+CSQ", "+CSQ:")); return p.parseInt();}int MeTa::getBitErrorRate() throw(GsmException){ Parser p(_at->chat("+CSQ", "+CSQ:")); p.parseInt(); p.parseComma(); return p.parseInt();}vector<string> MeTa::getPhoneBookStrings() throw(GsmException){ Parser p(_at->chat("+CPBS=?", "+CPBS:")); return p.parseStringList(false, _capabilities._noCPBxParentheses);}PhonebookRef MeTa::getPhonebook(string phonebookString, bool preload) throw(GsmException){ for (PhonebookVector::iterator i = _phonebookCache.begin(); i != _phonebookCache.end(); ++i) { if ((*i)->name() == phonebookString) return *i; } PhonebookRef newPb(new Phonebook(phonebookString, _at, *this, preload)); _phonebookCache.push_back(newPb); return newPb;}string MeTa::getServiceCentreAddress() throw(GsmException){ Parser p(_at->chat("+CSCA?", "+CSCA:")); return p.parseString();}void MeTa::setServiceCentreAddress(string sca) throw(GsmException){ int type; sca = removeWhiteSpace(sca); if (sca.length() > 0 && sca[0] == '+') { type = InternationalNumberFormat; sca = sca.substr(1, sca.length() - 1); } else type = UnknownNumberFormat; Parser p(_at->chat("+CSCA=\"" + sca + "\"," + intToStr(type)));}vector<string> MeTa::getSMSStoreNames() throw(GsmException){ Parser p(_at->chat("+CPMS=?", "+CPMS:")); // only return <mem1> values return p.parseStringList();}SMSStoreRef MeTa::getSMSStore(string storeName) throw(GsmException){ for (SMSStoreVector::iterator i = _smsStoreCache.begin(); i != _smsStoreCache.end(); ++i) { if ((*i)->name() == storeName) return *i; } SMSStoreRef newSs(new SMSStore(storeName, _at, *this)); _smsStoreCache.push_back(newSs); return newSs;}void MeTa::sendSMS(Ref<SMSSubmitMessage> smsMessage) throw(GsmException){ smsMessage->setAt(_at); smsMessage->send();}void MeTa::sendSMSs(Ref<SMSSubmitMessage> smsTemplate, string text, bool oneSMS, int concatenatedMessageId) throw(GsmException){ assert(! smsTemplate.isnull()); // compute maximum text length for normal SMSs and concatenated SMSs unsigned int maxTextLength, concMaxTextLength; switch (smsTemplate->dataCodingScheme().getAlphabet()) { case DCS_DEFAULT_ALPHABET: maxTextLength = 160; concMaxTextLength = 152; break; case DCS_EIGHT_BIT_ALPHABET: maxTextLength = 140; concMaxTextLength = 134; break; case DCS_SIXTEEN_BIT_ALPHABET: maxTextLength = 70; concMaxTextLength = 67; break; default: throw GsmException(_("unsupported alphabet for SMS"), ParameterError); break; } // simple case, only send one SMS if (oneSMS || text.length() <= maxTextLength) { if (text.length() > maxTextLength) throw GsmException(_("SMS text is larger than allowed"), ParameterError); smsTemplate->setUserData(text); sendSMS(smsTemplate); } else // send multiple SMSs { if (concatenatedMessageId != -1) maxTextLength = concMaxTextLength; int numMessages = (text.length() + maxTextLength - 1) / maxTextLength; if (numMessages > 255) throw GsmException(_("not more than 255 concatenated SMSs allowed"), ParameterError); unsigned char numMessage = 0; while (true) { if (concatenatedMessageId != -1) { unsigned char udhs[] = {0x00, 0x03, concatenatedMessageId, numMessages, ++numMessage}; UserDataHeader udh(string((char*)udhs, 5)); smsTemplate->setUserDataHeader(udh); } smsTemplate->setUserData(text.substr(0, maxTextLength)); sendSMS(smsTemplate); if (text.length() < maxTextLength) break; text.erase(0, maxTextLength); } }}void MeTa::setMessageService(int serviceLevel) throw(GsmException){ string s; switch (serviceLevel) { case 0: s = "0"; break; case 1: s = "1"; break; default: throw GsmException(_("only serviceLevel 0 or 1 supported"), ParameterError); } // some devices (eg. Origo 900) don't support service level setting _at->chat("+CSMS=" + s, "+CSMS:", true);}unsigned int MeTa::getMessageService() throw(GsmException){ Parser p(_at->chat("+CSMS?", "+CSMS:")); return p.parseInt();}void MeTa::getSMSRoutingToTA(bool &smsRouted, bool &cbsRouted, bool &statusReportsRouted) throw(GsmException){ Parser p(_at->chat("+CNMI?", "+CNMI:")); p.parseInt(); int smsMode = 0; int cbsMode = 0; int statMode = 0; int bufferMode = 0; if (p.parseComma(true)) { smsMode = p.parseInt(); if (p.parseComma(true)) { cbsMode = p.parseInt(); if (p.parseComma(true)) { statMode = p.parseInt(); if (p.parseComma(true)) { bufferMode = p.parseInt(); } } } } smsRouted = (smsMode == 2) || (smsMode == 3); cbsRouted = (cbsMode == 2) || (cbsMode == 3); statusReportsRouted = (statMode == 1);}void MeTa::setSMSRoutingToTA(bool enableSMS, bool enableCBS, bool enableStatReport, bool onlyReceptionIndication) throw(GsmException){ bool smsModesSet = false; bool cbsModesSet = false; bool statModesSet = false; bool bufferModesSet = false; // find out capabilities Parser p(_at->chat("+CNMI=?", "+CNMI:")); vector<bool> modes = p.parseIntList(); vector<bool> smsModes(1); vector<bool> cbsModes(1); vector<bool> statModes(1); vector<bool> bufferModes(1); if (p.parseComma(true)) { smsModes = p.parseIntList(); smsModesSet = true; if (p.parseComma(true)) { cbsModes = p.parseIntList(); cbsModesSet = true; if (p.parseComma(true)) { statModes = p.parseIntList(); statModesSet = true; if (p.parseComma(true)) { bufferModes = p.parseIntList(); bufferModesSet = true; } } } } // now set the mode vectors to the default if not set if (! smsModesSet) smsModes[0] = true; if (! cbsModesSet) cbsModes[0] = true; if (! statModesSet) statModes[0] = true; if (! bufferModesSet) bufferModes[0] = true; string chatString; // now try to set some optimal combination depending on // ME/TA's capabilities // handle modes if (isSet(modes, 2)) chatString = "2"; else if (isSet(modes, 1)) chatString = "1"; else if (isSet(modes, 0)) chatString = "0"; else if (isSet(modes, 3)) chatString = "3"; if (onlyReceptionIndication) { // handle sms mode if (enableSMS) { if (isSet(smsModes, 1)) chatString += ",1"; else throw GsmException(_("cannot route SMS messages to TE"), MeTaCapabilityError); } else chatString += ",0"; // handle cbs mode if (enableCBS) { if (isSet(cbsModes, 1)) chatString += ",1"; else if (isSet(cbsModes, 2)) chatString += ",2"; else throw GsmException(_("cannot route cell broadcast messages to TE"), MeTaCapabilityError); } else chatString += ",0"; // handle stat mode if (enableStatReport) { if (isSet(statModes, 2)) chatString += ",2"; else throw GsmException(_("cannot route status reports messages to TE"), MeTaCapabilityError); } else chatString += ",0"; } else { // handle sms mode if (enableSMS) { if (isSet(smsModes, 2)) chatString += ",2"; else if (isSet(smsModes, 3)) chatString += ",3"; else throw GsmException(_("cannot route SMS messages to TE"), MeTaCapabilityError); } else chatString += ",0"; // handle cbs mode if (enableCBS) { if (isSet(cbsModes, 2)) chatString += ",2"; else if (isSet(cbsModes, 3)) chatString += ",3"; else throw GsmException(_("cannot route cell broadcast messages to TE"), MeTaCapabilityError); } else chatString += ",0"; // handle stat mode if (enableStatReport) { if (isSet(statModes, 1)) chatString += ",1"; else if (isSet(statModes, 2)) chatString += ",2"; else throw GsmException(_("cannot route status report messages to TE"), MeTaCapabilityError); } else chatString += ",0"; } // handle buffer mode but only if it was reported by the +CNMI=? command // the Ericsson GM12 GSM modem does not like it otherwise if (bufferModesSet) if (isSet(bufferModes, 1)) chatString += ",1"; else chatString += ",0"; _at->chat("+CNMI=" + chatString);}bool MeTa::getCallWaitingLockStatus(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("+CCWA=0,2," + intToStr((int)cl),"+CCWA:",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;}void MeTa::setCallWaitingLockStatus(FacilityClass cl, bool lock) throw(GsmException){ if(lock) _at->chat("+CCWA=0,1," + intToStr((int)cl)); else _at->chat("+CCWA=0,0," + intToStr((int)cl));}void MeTa::setCLIRPresentation(bool enable) throw(GsmException){ if (enable) _at->chat("+CLIR=1"); else _at->chat("+CLIR=0");}int MeTa::getCLIRPresentation() throw(GsmException){ // 0:according to the subscription of the CLIR service // 1:CLIR invocation // 2:CLIR suppression Parser p(_at->chat("+CLIR?", "+CLIR:")); return p.parseInt();}MeTa::~MeTa(){ // Take Motorola 60t out of GSM command mode. if (_capabilities._MotorolaModeCmd) { _at->chat("+MODE=0", "", true, true); // allow to fail }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -