| 1 | // ************************************************************************* |
| 2 | // * GSM TA/ME library |
| 3 | // * |
| 4 | // * File: gsm_sie_me.cc |
| 5 | // * |
| 6 | // * Purpose: Mobile Equipment/Terminal Adapter and SMS functions |
| 7 | // * (According to "AT command set for S45 Siemens mobile phones" |
| 8 | // * v1.8, 26. July 2001 - Common AT prefix is "^S") |
| 9 | // * |
| 10 | // * Author: Christian W. Zuckschwerdt <[email protected]> |
| 11 | // * |
| 12 | // * Created: 2001-12-15 |
| 13 | // ************************************************************************* |
| 14 | |
| 15 | #ifdef HAVE_CONFIG_H |
| 16 | #include <gsm_config.h> |
| 17 | #endif |
| 18 | #include <gsmlib/gsm_nls.h> |
| 19 | #include <gsmlib/gsm_me_ta.h> |
| 20 | #include <gsmlib/gsm_parser.h> |
| 21 | #include <gsmlib/gsm_util.h> |
| 22 | #include <gsm_sie_me.h> |
| 23 | #include <iostream> |
| 24 | |
| 25 | using namespace gsmlib; |
| 26 | |
| 27 | // SieMe members |
| 28 | |
| 29 | void SieMe::init() throw(GsmException) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | SieMe::SieMe(Ref<Port> port) throw(GsmException) : MeTa::MeTa(port) |
| 34 | { |
| 35 | // initialize Siemens ME |
| 36 | |
| 37 | init(); |
| 38 | } |
| 39 | |
| 40 | std::vector<std::string> SieMe::getSupportedPhonebooks() throw(GsmException) |
| 41 | { |
| 42 | Parser p(_at->chat("^SPBS=?", "^SPBS:")); |
| 43 | return p.parseStringList(); |
| 44 | } |
| 45 | |
| 46 | std::string SieMe::getCurrentPhonebook() throw(GsmException) |
| 47 | { |
| 48 | if (_lastPhonebookName == "") |
| 49 | { |
| 50 | Parser p(_at->chat("^SPBS?", "^SPBS:")); |
| 51 | // answer is e.g. ^SPBS: "SM",41,250 |
| 52 | _lastPhonebookName = p.parseString(); |
| 53 | p.parseComma(); |
| 54 | p.parseInt(); |
| 55 | p.parseComma(); |
| 56 | p.parseInt(); |
| 57 | } |
| 58 | return _lastPhonebookName; |
| 59 | } |
| 60 | |
| 61 | void SieMe::setPhonebook(std::string phonebookName) throw(GsmException) |
| 62 | { |
| 63 | if (phonebookName != _lastPhonebookName) |
| 64 | { |
| 65 | _at->chat("^SPBS=\"" + phonebookName + "\""); |
| 66 | _lastPhonebookName = phonebookName; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | |
| 71 | IntRange SieMe:: getSupportedSignalTones() throw(GsmException) |
| 72 | { |
| 73 | Parser p(_at->chat("^SPST=?", "^SPST:")); |
| 74 | // ^SPST: (0-4),(0,1) |
| 75 | IntRange typeRange = p.parseRange(); |
| 76 | p.parseComma(); |
| 77 | std::vector<bool> volumeList = p.parseIntList(); |
| 78 | return typeRange; |
| 79 | } |
| 80 | |
| 81 | void SieMe:: playSignalTone(int tone) throw(GsmException) |
| 82 | { |
| 83 | _at->chat("^SPST=" + intToStr(tone) + ",1"); |
| 84 | } |
| 85 | |
| 86 | void SieMe:: stopSignalTone(int tone) throw(GsmException) |
| 87 | { |
| 88 | _at->chat("^SPST=" + intToStr(tone) + ",0"); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | IntRange SieMe::getSupportedRingingTones() throw(GsmException) // (AT^SRTC=?) |
| 93 | { |
| 94 | Parser p(_at->chat("^SRTC=?", "^SRTC:")); |
| 95 | // ^SRTC: (0-42),(1-5) |
| 96 | IntRange typeRange = p.parseRange(); |
| 97 | p.parseComma(); |
| 98 | p.parseRange(); |
| 99 | return typeRange; |
| 100 | } |
| 101 | |
| 102 | int SieMe::getCurrentRingingTone() throw(GsmException) // (AT^SRTC?) |
| 103 | { |
| 104 | Parser p(_at->chat("^SRTC?", "^SRTC:")); |
| 105 | // ^SRTC: 41,2,0 |
| 106 | int type = p.parseInt(); |
| 107 | p.parseComma(); |
| 108 | p.parseInt(); |
| 109 | p.parseComma(); |
| 110 | p.parseInt(); |
| 111 | return type; |
| 112 | } |
| 113 | |
| 114 | void SieMe::setRingingTone(int tone, int volume) throw(GsmException) |
| 115 | { |
| 116 | _at->chat("^SRTC=" + intToStr(tone) + "," + intToStr(volume)); |
| 117 | } |
| 118 | |
| 119 | void SieMe:: playRingingTone() throw(GsmException) |
| 120 | { |
| 121 | // get ringing bool |
| 122 | Parser p(_at->chat("^SRTC?", "^SRTC:")); |
| 123 | // ^SRTC: 41,2,0 |
| 124 | p.parseInt(); |
| 125 | p.parseComma(); |
| 126 | p.parseInt(); |
| 127 | p.parseComma(); |
| 128 | int ringing = p.parseInt(); |
| 129 | |
| 130 | if (ringing == 0) |
| 131 | toggleRingingTone(); |
| 132 | } |
| 133 | |
| 134 | void SieMe::stopRingingTone() throw(GsmException) |
| 135 | { |
| 136 | // get ringing bool |
| 137 | Parser p(_at->chat("^SRTC?", "^SRTC:")); |
| 138 | // ^SRTC: 41,2,0 |
| 139 | p.parseInt(); |
| 140 | p.parseComma(); |
| 141 | p.parseInt(); |
| 142 | p.parseComma(); |
| 143 | int ringing = p.parseInt(); |
| 144 | |
| 145 | if (ringing == 1) |
| 146 | toggleRingingTone(); |
| 147 | } |
| 148 | |
| 149 | void SieMe::toggleRingingTone() throw(GsmException) // (AT^SRTC) |
| 150 | { |
| 151 | _at->chat("^SRTC"); |
| 152 | } |
| 153 | |
| 154 | // Siemens get supported binary read |
| 155 | std::vector<ParameterRange> SieMe::getSupportedBinaryReads() throw(GsmException) |
| 156 | { |
| 157 | Parser p(_at->chat("^SBNR=?", "^SBNR:")); |
| 158 | // ^SBNR: ("bmp",(0-3)),("mid",(0-4)),("vcf",(0-500)),("vcs",(0-50)) |
| 159 | |
| 160 | return p.parseParameterRangeList(); |
| 161 | } |
| 162 | |
| 163 | // Siemens get supported binary write |
| 164 | std::vector<ParameterRange> SieMe::getSupportedBinaryWrites() throw(GsmException) |
| 165 | { |
| 166 | Parser p(_at->chat("^SBNW=?", "^SBNW:")); |
| 167 | // ^SBNW: ("bmp",(0-3)),("mid",(0-4)),("vcf",(0-500)),("vcs",(0-50)),("t9d",(0)) |
| 168 | |
| 169 | return p.parseParameterRangeList(); |
| 170 | } |
| 171 | |
| 172 | // Siemens Binary Read |
| 173 | BinaryObject SieMe::getBinary(std::string type, int subtype) throw(GsmException) |
| 174 | { |
| 175 | // expect several response lines |
| 176 | std::vector<std::string> result; |
| 177 | result = _at->chatv("^SBNR=\"" + type + "\"," + intToStr(subtype), "^SBNR:"); |
| 178 | // "bmp",0,1,5 <CR><LF> pdu <CR><LF> "bmp",0,2,5 <CR><LF> ... |
| 179 | // most likely to be PDUs of 382 chars (191 * 2) |
| 180 | std::string pdu; |
| 181 | int fragmentCount = 0; |
| 182 | for (std::vector<std::string>::iterator i = result.begin(); i != result.end(); ++i) |
| 183 | { |
| 184 | ++fragmentCount; |
| 185 | // parse header |
| 186 | Parser p(*i); |
| 187 | std::string fragmentType = p.parseString(); |
| 188 | if (fragmentType != type) |
| 189 | throw GsmException(_("bad PDU type"), ChatError); |
| 190 | p.parseComma(); |
| 191 | int fragmentSubtype = p.parseInt(); |
| 192 | if (fragmentSubtype != subtype) |
| 193 | throw GsmException(_("bad PDU subtype"), ChatError); |
| 194 | p.parseComma(); |
| 195 | int fragmentNumber = p.parseInt(); |
| 196 | if (fragmentNumber != fragmentCount) |
| 197 | throw GsmException(_("bad PDU number"), ChatError); |
| 198 | p.parseComma(); |
| 199 | int numberOfFragments = p.parseInt(); |
| 200 | if (fragmentNumber > numberOfFragments) |
| 201 | throw GsmException(_("bad PDU number"), ChatError); |
| 202 | |
| 203 | // concat pdu fragment |
| 204 | ++i; |
| 205 | pdu += *i; |
| 206 | } |
| 207 | |
| 208 | BinaryObject bnr; |
| 209 | bnr._type = type; |
| 210 | bnr._subtype = subtype; |
| 211 | bnr._size = pdu.length() / 2; |
| 212 | bnr._data = new unsigned char[pdu.length() / 2]; |
| 213 | if (! hexToBuf(pdu, bnr._data)) |
| 214 | throw GsmException(_("bad hexadecimal PDU format"), ChatError); |
| 215 | |
| 216 | return bnr; |
| 217 | } |
| 218 | |
| 219 | // Siemens Binary Write |
| 220 | void SieMe::setBinary(std::string type, int subtype, BinaryObject obj) |
| 221 | throw(GsmException) |
| 222 | { |
| 223 | if (obj._size <= 0) |
| 224 | throw GsmException(_("bad object"), ParameterError); |
| 225 | |
| 226 | // Limitation: The maximum pdu size is 176 bytes (or 352 characters) |
| 227 | // this should be a configurable field |
| 228 | int maxPDUsize = 176; |
| 229 | int numberOfPDUs = (obj._size + maxPDUsize - 1) / maxPDUsize; |
| 230 | unsigned char *p = obj._data; |
| 231 | |
| 232 | for (int i = 1; i <= numberOfPDUs; ++i) |
| 233 | { |
| 234 | // construct pdu |
| 235 | int size = maxPDUsize; |
| 236 | if (i == numberOfPDUs) |
| 237 | size = obj._size - (numberOfPDUs - 1) * maxPDUsize; |
| 238 | std::string pdu = bufToHex(p, size); |
| 239 | p += size; |
| 240 | |
| 241 | cout << "processing " << i << " of " << numberOfPDUs |
| 242 | << " of " << size << " bytes." << endl; |
| 243 | cout << "^SBNW=\"" + type + "\"," + intToStr(subtype) + "," |
| 244 | + intToStr(i) + "," + intToStr(numberOfPDUs) << endl; |
| 245 | cout << pdu << endl; |
| 246 | |
| 247 | _at->sendPdu("^SBNW=\"" + type + "\"," + intToStr(subtype) + "," |
| 248 | + intToStr(i) + "," + intToStr(numberOfPDUs), "", |
| 249 | pdu, true); |
| 250 | cout << "OK" << endl; |
| 251 | } |
| 252 | } |