/[projects]/smsdaemon/SmsPdu.cpp
ViewVC logotype

Diff of /smsdaemon/SmsPdu.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 67 by torben, Thu Jun 12 15:16:12 2008 UTC revision 68 by torben, Thu Jun 12 18:54:24 2008 UTC
# Line 21  namespace SmsPdu Line 21  namespace SmsPdu
21  {  {
22    
23    
 vector<unsigned char> BcdEncode(string input)  
 {  
         char buf[2] = " ";  
         vector<unsigned char> result;  
24    
25          unsigned char current;  string SwitchChars(string input)
26          for (unsigned int i=0; i<input.length(); ++i)  {
27            for (unsigned int i=1; i<input.length(); i+=2)
28          {          {
29                  buf[0] = input.at(i);                  char tmp = input[i];
30                  unsigned char tmp = atoi(buf);                  input[i] = input[i-1];
31                    input[i-1] = tmp;
                 if ( (i%2) == 0)  
                 {  
                         current = tmp;  
                 }  
                 else  
                 {  
                         current |= (tmp<<4);  
                         result.push_back(current);  
                 }  
32          }          }
33            return input;
34    }
35    
36          if ((input.length() % 2) == 1)  string EncodePhonenr(string input)
37          {  {
38                  current |= 0xF0;          if ( (input.length() % 2) == 1)
39                  result.push_back(current);                  input.append("F");
40          }          return SwitchChars(input);
41    }
42    
43          return result;  string DecodePhonenr(string input)
44    {
45            input = SwitchChars(input);
46            int last = input.length() -1;
47    
48            if (input.at(last) == 'F')
49                    input.erase(last,1);
50            return input;
51  }  }
52    
53    
54    
55    
56  string HexformatVector(vector<unsigned char> vec)  string HexformatVector(vector<unsigned char> vec)
57  {  {
58          ostringstream os;          ostringstream os;
# Line 67  string HexformatVector(vector<unsigned c Line 68  string HexformatVector(vector<unsigned c
68          return os.str();          return os.str();
69  }  }
70    
71  std::string Encode8to7bit(vector<unsigned char> vec)  std::string Decode8to7bit(vector<unsigned char> input)
72  {  {
73          string result;          string result;
74    
75            int shift = 0;
76            for (unsigned int i=0; i<input.size(); ++i)
77            {
78                    unsigned char current = input.at(i);
79                    unsigned char prev = (i>0) ? input.at(i-1) : 0;
80    
81                    current <<= shift;
82    
83                    prev >>= (8-shift);
84    
85                    unsigned char byte = current | prev;
86                    byte &= 0x7F;
87    
88                    result.append(1, byte);
89    
90                    if (shift == 6)
91                            result.append(1, input.at(i) >> 1);
92    
93                    shift = (shift+1) % 7;
94    
95            }
96    
97          return result;          return result;
98  }  }
99    
100    
101    
102    
103  vector<unsigned char> Encode7to8bit(std::string str)  vector<unsigned char> Encode7to8bit(std::string str)
104  {  {
105          vector<unsigned char> buf;          vector<unsigned char> buf;
# Line 142  vector<PduInfo> CreateSmsPdu(string to, Line 168  vector<PduInfo> CreateSmsPdu(string to,
168                  pdu.push_back(to.length() ); //length of phone nr                  pdu.push_back(to.length() ); //length of phone nr
169                  pdu.push_back(0x81); // type of address (international nr  + ISDN/telephone range) - else try 0x81                  pdu.push_back(0x81); // type of address (international nr  + ISDN/telephone range) - else try 0x81
170    
171                  vector<unsigned char> phone = BcdEncode(to);                  
172                    string phone = EncodePhonenr(to);
173                  pdu.insert( pdu.end(), phone.begin(), phone.end());                  pdu.insert( pdu.end(), phone.begin(), phone.end());
174    
175                  pdu.push_back(0x00); // Protocol identifier                  pdu.push_back(0x00); // Protocol identifier

Legend:
Removed from v.67  
changed lines
  Added in v.68

  ViewVC Help
Powered by ViewVC 1.1.20