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

Annotation of /smsdaemon/Sms.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 75 - (hide annotations) (download)
Fri Jun 13 10:10:06 2008 UTC (15 years, 11 months ago) by torben
File size: 1874 byte(s)
Make gsmmodem::readsms use pdu mode 

Cleaned up some unneeded cout and <iostream>


1 torben 26
2     #include <string>
3     #include <vector>
4    
5     #include "Sms.h"
6     #include "util.h"
7 torben 75 #include "SmsPdu.h"
8 torben 26
9    
10 torben 75
11 torben 26 std::string GetSmsCommand(SMS& sms)
12     {
13     unsigned int pos = sms.message.find(" ");
14    
15     if (pos == std::string::npos)
16     return sms.message;
17     else
18     return sms.message.substr(0, pos);
19     }
20    
21     std::string GetSmsData(SMS& sms)
22     {
23     unsigned int pos = sms.message.find(" ");
24    
25     if (pos == std::string::npos)
26     return "";
27     else
28     {
29     pos++;
30    
31     std::string data = sms.message.substr(pos, sms.message.length()-pos );
32    
33 torben 39 data = Util::str_trim(data);
34 torben 26 return data;
35     }
36     }
37    
38     SMS::SMS()
39     {
40     }
41    
42     SMS::SMS(std::string _sender, std::string _message, std::string _timestamp)
43     : sender(_sender), message(_message), timestamp(_timestamp)
44     {
45     }
46    
47     SMS SMS::FromRawString(const std::string& input)
48     {
49     std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: "
50    
51     std::vector<std::string> lines = Util::str_split(smsline, "\r\n");
52     std::vector<std::string> fields = Util::str_split(lines[0],",");
53    
54     std::string body;
55     for (unsigned i=1; i<lines.size(); ++i)
56     {
57     std::string body_line = lines[i];
58    
59    
60     if (body_line != "")
61     {
62     if (body.length() > 0)
63     body += "\r\n";
64     body += body_line;
65     }
66     }
67    
68 torben 39 body = Util::str_trim(body);
69 torben 26
70     SMS newsms;
71    
72     newsms.sms_index = fields[0];
73    
74     newsms.sender = fields[2];
75 torben 38 newsms.sender = Util::str_replace(newsms.sender, "\"");
76 torben 26
77 torben 38 newsms.timestamp = fields[4] + std::string(",") + fields[5];
78     newsms.timestamp = Util::str_replace(newsms.timestamp, "\"");
79 torben 26
80     newsms.message = body;
81    
82     return newsms;
83     }
84    
85 torben 75 SMS SMS::FromPduString(const std::string& input)
86     {
87     std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: "
88    
89     std::vector<std::string> lines = Util::str_split(smsline, "\r\n");
90     std::vector<std::string> fields = Util::str_split(lines[0],",");
91    
92     SMS newsms = SmsPdu::ParseSmsPdu(lines[1]);
93    
94     newsms.sms_index = fields[0];
95    
96     return newsms;
97     }

  ViewVC Help
Powered by ViewVC 1.1.20