?? gsm_me_ta.c
字號:
// 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::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);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -