?? pdu.cpp
字號:
this->tp_dcs = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; //TIMESTAMP this->tp_scts = pduString.substr(stringLocation, 14); stringLocation += 14; //DATA Lenght this->tp_length = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; //DATA raw unencoded this->tp_data = pduString.substr(stringLocation, pduString.length() - stringLocation); stringLocation += pduString.length() - stringLocation; }/** * void parsePDU_send ( string ) * --------------------------------------------------------------- * Parses a string representing a SMS in PDU mode * * Example: * pdu MyPDU; * int MyResult = MyPDU.parsePDU("ADGHJ....5F"); * cout << MyResult << endl; * * ( will result in 1 , being printed if ok, -1 on failure ) * * */void pdu::parsePDU_send(string pduString) { int stringLocation = 0; this->tp_msgref = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; this->sender_length = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; cout << stringLocation << endl; int evenSenderLength = this->sender_length + ( this->sender_length % 2 ); this->sender_type_of_address = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; cout << stringLocation << endl; this->sender_number = semiOctetToString( pduString.substr(stringLocation, evenSenderLength )); this->sender_number = this->sender_number.substr(0, this->sender_length); stringLocation += evenSenderLength; this->tp_pid = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; //DATA Coding scheme tp_dcs this->tp_dcs = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; this->tp_validity = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; this->tp_length = hexStringToInt(pduString.substr(stringLocation, 2)); stringLocation += 2; //DATA raw unencoded this->tp_data = pduString.substr(stringLocation, (pduString.length() - stringLocation) + 2); stringLocation += pduString.length() - stringLocation; cout<< "tp_data " << this->tp_data << endl;}/** * string userData7_to_8 ( void ) * --------------------------------------------------------------- * Parses the user data in a SMS in PDU mode with 7bit encoding * * Example: * pdu MyPDU; * int MyResult = MyPDU.parsePDU("ADGHJ....5F"); * cout << MyPDU.userData() << endl;// always use this method, * // it will select the correct * // decoding algorithm * * returns a human readable string * * */string pdu::userData7_to_8() { unsigned int pos; int septetCnt = 1; string byteString = ""; string messageAscii; if ( this->tp_data.length() == 0 || this->tp_data.length() % 2 != 0 ) { return ""; } for (pos = 0; pos < this->tp_data.length(); pos += 2) { byteString += intToBinString(hexStringToInt(this->tp_data.substr(pos, 2))); } string * octetArray = new string[(byteString.length() / 8) + 1]; string * restArray = new string[(byteString.length() / 8) + 1]; string * septetsArray = new string[(byteString.length() / 8) + 1]; for (pos = 0; pos < byteString.length(); pos += 8) { octetArray[pos/8] = byteString.substr(pos, 8); restArray[pos/8] = octetArray[pos/8].substr(0, septetCnt % 8); septetsArray[pos/8] = octetArray[pos/8].substr(septetCnt % 8, 8); septetCnt++; if (septetCnt == 8){ septetCnt = 1; } } for (pos = 0; pos < (byteString.length() / 8); pos++) { if (pos % 7 == 0){ if (pos != 0) { messageAscii = messageAscii + lookup_ascii7to8[binStringToInt(restArray[pos - 1])]; } messageAscii = messageAscii + lookup_ascii7to8[binStringToInt(septetsArray[pos])]; } else { messageAscii = messageAscii + lookup_ascii7to8[binStringToInt(septetsArray[pos] + restArray[pos - 1])]; } } return messageAscii; }/** * string userData8_to_8 ( void ) * --------------------------------------------------------------- * Parses the user data in a SMS in PDU mode with 8bit encoding * * Example: * pdu MyPDU; * int MyResult = MyPDU.parsePDU("ADGHJ....5F"); * cout << MyPDU.userData() << endl;// always use this method, * // it will select the correct * // decoding algorithm * * returns a human readable string * * */string pdu::userData8_to_8() { unsigned int pos; string messageAscii = ""; for (pos = 0; pos < this->tp_data.length(); pos+=2) { messageAscii += (char) hexStringToInt(this->tp_data.substr(pos, 2)); } cout << "userdata8_to_8" << endl; return messageAscii;}/** * string userData16_to_8 ( void ) * --------------------------------------------------------------- * Parses the user data in a SMS in PDU mode with 16bit encoding * * Example: * pdu MyPDU; * int MyResult = MyPDU.parsePDU("ADGHJ....5F"); * cout << MyPDU.userData() << endl;// always use this method, * // it will select the correct * // decoding algorithm * * returns a human readable string * * */string pdu::userData16_to_8() { unsigned int pos; string messageAscii = ""; for (pos = 0; pos < this->tp_data.length(); pos+=4) { messageAscii += (char) ( hexStringToInt(this->tp_data.substr(pos, 2)) * 256 ) + hexStringToInt(this->tp_data.substr(pos+2, 2)); } return messageAscii;}string pdu::userData() { switch ( getDCSAlphabet() ) { case 0: return userData7_to_8(); break; case 4: return userData8_to_8(); break; case 8: return userData16_to_8(); break; } return ""; }int pdu::getDCSAlphabet() { switch (this->tp_dcs & 192) { case 0: return this->tp_dcs & 12; break; case 192: switch (this->tp_dcs & 0x30) { case 0x20: return 8; break; case 0x30: if ( this->tp_dcs & 0x4 ) { return 0; } else { return 4; } break; default: return 0; break; } default: return 0; break; }}string pdu::getText() { return userData();}string pdu::getSender() { if ( this->sender_type_of_address == 145 ){ return "+" + this->sender_number; } return this->sender_number;}int pdu::setText( string smstext ) { if ( smstext.length() > 160 ) { return 0; } this->tp_text = smstext; return 1;}int pdu::setSender( string number ) { this->sender_type_of_address = 146; if ( number.substr(0,1) == "+" ) { this->sender_type_of_address = 145; this->sender_number = number.substr(1, number.length() - 1); } else { this->sender_number = number; } this->sender_length = this->sender_number.length(); if ( this->sender_number.length() % 2 == 1 ) { this->sender_number + "F"; } return 1;}string pdu::userTextTo7(void) { unsigned int pos; string current, octetFirst, octetSecond, currentOctet; string output; for (pos = 0; pos < this->tp_text.length(); pos++) { current = intToBinString(lookup_ascii8to7[ this->tp_text[pos] ]); if ( ( pos != 0 ) && ( pos % 8 != 0 ) ) { octetFirst = current.substr(7 - ( pos % 8 ), current.length() ); currentOctet = octetFirst + octetSecond; output += intToHexString(binStringToInt(currentOctet)); octetSecond = current.substr(0, 7 - (pos % 8)); } else { octetSecond = current.substr(0, 7 - (pos % 8)); } if ( ( pos + 1 == this->tp_text.length() ) && ( octetSecond != "" ) ) { output += intToHexString(binStringToInt(octetSecond)); } } return output;}string pdu::encodePDU() { string pduString; pduString = "00"; // SMSC_LENGHT pduString += "1100"; // FIRST OCTET ( message submit & tp reference) pduString += intToHexString(this->sender_length); // SENDER_LENGHT pduString += intToHexString(this->sender_type_of_address); // SENDER_TYPE pduString += stringToSemiOctet(this->sender_number); // SENDER_NUMBER pduString += "0000"; // TP-PID TP-DCS ( 7-bit default encoding ) pduString += "AA"; // VALIDITY ( 4 days ) pduString += intToHexString(this->tp_text.length()); pduString += userTextTo7(); cout << "end of encodePdu" << endl; return pduString;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -