Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Lib is cleaner than before.

  • Loading branch information...
commit b892554a59d911b69e0bd359b67e7eb2216dcf6b 1 parent 783a9b6
Vianney Bouchaud authored
Showing with 75 additions and 81 deletions.
  1. +74 −80 ext/gsm_sie_me.cc
  2. +1 −1  ext/gsmsiexfer.cc
154 ext/gsm_sie_me.cc
View
@@ -13,7 +13,7 @@
// *************************************************************************
#ifdef HAVE_CONFIG_H
-#include <gsm_config.h>
+ #include <gsm_config.h>
#endif
#include <gsmlib/gsm_nls.h>
#include <gsmlib/gsm_me_ta.h>
@@ -22,7 +22,6 @@
#include <gsm_sie_me.h>
#include <iostream>
-using namespace std;
using namespace gsmlib;
// SieMe members
@@ -38,34 +37,34 @@ SieMe::SieMe(Ref<Port> port) throw(GsmException) : MeTa::MeTa(port)
init();
}
-vector<string> SieMe::getSupportedPhonebooks() throw(GsmException)
+std::vector<std::string> SieMe::getSupportedPhonebooks() throw(GsmException)
{
Parser p(_at->chat("^SPBS=?", "^SPBS:"));
- return p.parseStringList();
+ return p.parseStd::StringList();
}
-string SieMe::getCurrentPhonebook() throw(GsmException)
+std::string SieMe::getCurrentPhonebook() throw(GsmException)
{
if (_lastPhonebookName == "")
- {
- Parser p(_at->chat("^SPBS?", "^SPBS:"));
- // answer is e.g. ^SPBS: "SM",41,250
- _lastPhonebookName = p.parseString();
- p.parseComma();
- int _currentNumberOfEntries = p.parseInt();
- p.parseComma();
- int _maxNumberOfEntries = p.parseInt();
- }
+ {
+ Parser p(_at->chat("^SPBS?", "^SPBS:"));
+ // answer is e.g. ^SPBS: "SM",41,250
+ _lastPhonebookName = p.parseStd::String();
+ p.parseComma();
+ p.parseInt();
+ p.parseComma();
+ p.parseInt();
+ }
return _lastPhonebookName;
}
-void SieMe::setPhonebook(string phonebookName) throw(GsmException)
+void SieMe::setPhonebook(std::string phonebookName) throw(GsmException)
{
if (phonebookName != _lastPhonebookName)
- {
- _at->chat("^SPBS=\"" + phonebookName + "\"");
- _lastPhonebookName = phonebookName;
- }
+ {
+ _at->chat("^SPBS=\"" + phonebookName + "\"");
+ _lastPhonebookName = phonebookName;
+ }
}
@@ -75,7 +74,7 @@ IntRange SieMe:: getSupportedSignalTones() throw(GsmException)
// ^SPST: (0-4),(0,1)
IntRange typeRange = p.parseRange();
p.parseComma();
- vector<bool> volumeList = p.parseIntList();
+ std::vector<bool> volumeList = p.parseIntList();
return typeRange;
}
@@ -96,7 +95,7 @@ IntRange SieMe::getSupportedRingingTones() throw(GsmException) // (AT^SRTC=?)
// ^SRTC: (0-42),(1-5)
IntRange typeRange = p.parseRange();
p.parseComma();
- IntRange volumeRange = p.parseRange();
+ p.parseRange();
return typeRange;
}
@@ -106,9 +105,9 @@ int SieMe::getCurrentRingingTone() throw(GsmException) // (AT^SRTC?)
// ^SRTC: 41,2,0
int type = p.parseInt();
p.parseComma();
- int volume = p.parseInt();
+ p.parseInt();
p.parseComma();
- int ringing = p.parseInt();
+ p.parseInt();
return type;
}
@@ -122,9 +121,9 @@ void SieMe:: playRingingTone() throw(GsmException)
// get ringing bool
Parser p(_at->chat("^SRTC?", "^SRTC:"));
// ^SRTC: 41,2,0
- int type = p.parseInt();
+ p.parseInt();
p.parseComma();
- int volume = p.parseInt();
+ p.parseInt();
p.parseComma();
int ringing = p.parseInt();
@@ -137,9 +136,9 @@ void SieMe::stopRingingTone() throw(GsmException)
// get ringing bool
Parser p(_at->chat("^SRTC?", "^SRTC:"));
// ^SRTC: 41,2,0
- int type = p.parseInt();
+ p.parseInt();
p.parseComma();
- int volume = p.parseInt();
+ p.parseInt();
p.parseComma();
int ringing = p.parseInt();
@@ -153,7 +152,7 @@ void SieMe::toggleRingingTone() throw(GsmException) // (AT^SRTC)
}
// Siemens get supported binary read
-vector<ParameterRange> SieMe::getSupportedBinaryReads() throw(GsmException)
+std::vector<ParameterRange> SieMe::getSupportedBinaryReads() throw(GsmException)
{
Parser p(_at->chat("^SBNR=?", "^SBNR:"));
// ^SBNR: ("bmp",(0-3)),("mid",(0-4)),("vcf",(0-500)),("vcs",(0-50))
@@ -162,7 +161,7 @@ vector<ParameterRange> SieMe::getSupportedBinaryReads() throw(GsmException)
}
// Siemens get supported binary write
-vector<ParameterRange> SieMe::getSupportedBinaryWrites() throw(GsmException)
+std::vector<ParameterRange> SieMe::getSupportedBinaryWrites() throw(GsmException)
{
Parser p(_at->chat("^SBNW=?", "^SBNW:"));
// ^SBNW: ("bmp",(0-3)),("mid",(0-4)),("vcf",(0-500)),("vcs",(0-50)),("t9d",(0))
@@ -171,40 +170,40 @@ vector<ParameterRange> SieMe::getSupportedBinaryWrites() throw(GsmException)
}
// Siemens Binary Read
-BinaryObject SieMe::getBinary(string type, int subtype) throw(GsmException)
+BinaryObject SieMe::getBinary(std::string type, int subtype) throw(GsmException)
{
// expect several response lines
- vector<string> result;
+ std::vector<std::string> result;
result = _at->chatv("^SBNR=\"" + type + "\"," + intToStr(subtype), "^SBNR:");
// "bmp",0,1,5 <CR><LF> pdu <CR><LF> "bmp",0,2,5 <CR><LF> ...
// most likely to be PDUs of 382 chars (191 * 2)
- string pdu;
+ std::string pdu;
int fragmentCount = 0;
- for (vector<string>::iterator i = result.begin(); i != result.end(); ++i)
- {
- ++fragmentCount;
- // parse header
- Parser p(*i);
- string fragmentType = p.parseString();
- if (fragmentType != type)
- throw GsmException(_("bad PDU type"), ChatError);
- p.parseComma();
- int fragmentSubtype = p.parseInt();
- if (fragmentSubtype != subtype)
- throw GsmException(_("bad PDU subtype"), ChatError);
- p.parseComma();
- int fragmentNumber = p.parseInt();
- if (fragmentNumber != fragmentCount)
- throw GsmException(_("bad PDU number"), ChatError);
- p.parseComma();
- int numberOfFragments = p.parseInt();
- if (fragmentNumber > numberOfFragments)
- throw GsmException(_("bad PDU number"), ChatError);
-
- // concat pdu fragment
- ++i;
- pdu += *i;
- }
+ for (std::vector<std::string>::iterator i = result.begin(); i != result.end(); ++i)
+ {
+ ++fragmentCount;
+ // parse header
+ Parser p(*i);
+ std::string fragmentType = p.parseStd::String();
+ if (fragmentType != type)
+ throw GsmException(_("bad PDU type"), ChatError);
+ p.parseComma();
+ int fragmentSubtype = p.parseInt();
+ if (fragmentSubtype != subtype)
+ throw GsmException(_("bad PDU subtype"), ChatError);
+ p.parseComma();
+ int fragmentNumber = p.parseInt();
+ if (fragmentNumber != fragmentCount)
+ throw GsmException(_("bad PDU number"), ChatError);
+ p.parseComma();
+ int numberOfFragments = p.parseInt();
+ if (fragmentNumber > numberOfFragments)
+ throw GsmException(_("bad PDU number"), ChatError);
+
+ // concat pdu fragment
+ ++i;
+ pdu += *i;
+ }
BinaryObject bnr;
bnr._type = type;
@@ -218,7 +217,7 @@ BinaryObject SieMe::getBinary(string type, int subtype) throw(GsmException)
}
// Siemens Binary Write
-void SieMe::setBinary(string type, int subtype, BinaryObject obj)
+void SieMe::setBinary(std::string type, int subtype, BinaryObject obj)
throw(GsmException)
{
if (obj._size <= 0)
@@ -231,28 +230,23 @@ void SieMe::setBinary(string type, int subtype, BinaryObject obj)
unsigned char *p = obj._data;
for (int i = 1; i <= numberOfPDUs; ++i)
- {
- // construct pdu
- int size = maxPDUsize;
- if (i == numberOfPDUs)
- size = obj._size - (numberOfPDUs - 1) * maxPDUsize;
- string pdu = bufToHex(p, size);
- p += size;
-
- cout << "processing " << i << " of " << numberOfPDUs
- << " of " << size << " bytes." << endl;
- cout << "^SBNW=\"" + type + "\"," + intToStr(subtype) + ","
+ {
+ // construct pdu
+ int size = maxPDUsize;
+ if (i == numberOfPDUs)
+ size = obj._size - (numberOfPDUs - 1) * maxPDUsize;
+ std::string pdu = bufToHex(p, size);
+ p += size;
+
+ cout << "processing " << i << " of " << numberOfPDUs
+ << " of " << size << " bytes." << endl;
+ cout << "^SBNW=\"" + type + "\"," + intToStr(subtype) + ","
+ intToStr(i) + "," + intToStr(numberOfPDUs) << endl;
- cout << pdu << endl;
+ cout << pdu << endl;
- _at->sendPdu("^SBNW=\"" + type + "\"," + intToStr(subtype) + ","
- + intToStr(i) + "," + intToStr(numberOfPDUs), "",
- pdu, true);
- cout << "OK" << endl;
- }
+ _at->sendPdu("^SBNW=\"" + type + "\"," + intToStr(subtype) + ","
+ + intToStr(i) + "," + intToStr(numberOfPDUs), "",
+ pdu, true);
+ cout << "OK" << endl;
+ }
}
-
-
-
-
-
2  ext/gsmsiexfer.cc
View
@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
string type;
string subtype;
int subtypeN;
- bool verbose = false;
+ bool verbose;
string initString = DEFAULT_INIT_STRING;
bool swHandshake = false;
Ref<SieMe> sourceMeTa, destMeTa;
Please sign in to comment.
Something went wrong with that request. Please try again.