⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsm_me_ta.cc

📁 对各种手机进行编程的工具包源码gsmlib 1.9版本。
💻 CC
📖 第 1 页 / 共 2 页
字号:
  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:"));    return p.parseInt();  } 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"),			 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();}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(SMSMessageRef smsMessage) throw(GsmException){  smsMessage->setAt(_at);  smsMessage->send();}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::lockCallWaiting(FacilityClass cl)  throw(GsmException){  _at->chat("+CCWA=0,1," + intToStr((int)cl));}void MeTa::unlockCallWaiting(FacilityClass cl)  throw(GsmException){  _at->chat("+CCWA=0,0," + intToStr((int)cl));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -