/* using http://sourceforge.net/projects/libserial/ */ #include #include #include "util.h" using namespace std; namespace SmsPdu { vector BcdEncode(string input) { char buf[2] = " "; vector result; unsigned char current; for (unsigned int i=0; i vec) { ostringstream os; for (unsigned int i=0; i(vec.at(i)); } return os.str(); } vector Encode7to8bit(std::string str) { vector buf; int shift = 0; for (unsigned int i=0; i>= shift; next <<= (7-shift); unsigned char byte = current | next; buf.push_back(byte); if (shift == 6) i++; shift = (shift+1) % 7; } return buf; } string CreateSmsPdu(string to, string message, int& len) { message = message.substr(0,160); //truncate to 160 vector pdu; pdu.push_back(0x00); // use SMSC from phone pdu.push_back(0x01); // first octet -- no timeout pdu.push_back(0x00); // TP-MR message reference pdu.push_back(to.length() ); //length of phone nr pdu.push_back(0x91); // type of address (international nr + ISDN/telephone range) - else try 0x81 vector phone = BcdEncode(to); pdu.insert( pdu.end(), phone.begin(), phone.end()); pdu.push_back(0x00); // Protocol identifier pdu.push_back(0x00); // Data coding scheme pdu.push_back( message.length() ); //UserDataLength vector userData = Encode7to8bit(message); pdu.insert( pdu.end(), userData.begin(), userData.end()); len = pdu.size()-1; return HexformatVector(pdu); } }