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

Annotation of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 78 - (hide annotations) (download)
Sat Jun 14 08:39:40 2008 UTC (15 years, 11 months ago) by torben
File size: 3799 byte(s)
Remove any leading/trailing 0x00 from the strings.


1 torben 26 /* using http://sourceforge.net/projects/libserial/
2 torben 59 *
3 torben 26 */
4    
5    
6     #include <string>
7     #include <iostream>
8 torben 38 #include <vector>
9 torben 59 #include "SerialPort.h"
10    
11 torben 26 #include "GsmModem.h"
12 torben 49 #include "Sms.h"
13     #include "TogPlugin.h"
14 torben 54 #include "TrainInfo.h"
15 torben 49 #include "util.h"
16 torben 26
17 torben 59 #include "SmsPdu.h"
18 torben 49
19 torben 26 using namespace std;
20    
21    
22 torben 60 void test_sms(GsmModem& modem, int len)
23     {
24     cout << "----- test_sms( " << len << " ) ------- " << endl;
25    
26     string msg = Util::str_formatint(len);
27 torben 62 msg.append(1, ' ');
28 torben 61 msg.append(len - msg.length(), 'a');
29 torben 60
30 torben 75 vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("22337617", msg, true);
31 torben 60
32     for (unsigned int i=0; i<pdu.size(); ++i)
33     {
34     cout << "#" << i << endl;
35     cout << "Len: " << pdu[i].len << endl;
36     cout << "Pdu: " << pdu[i].pdu << endl;
37    
38     modem.SendSmsPdu(pdu[i].pdu, pdu[i].len);
39     }
40     }
41    
42    
43 torben 26 int main()
44     {
45 torben 75 /*
46     int shift = 6;
47     string start = "Hej med dig";
48     string end = SmsPdu::Decode8to7bit(SmsPdu::Encode7to8bit(start,shift), shift );
49 torben 68
50 torben 75 cout << start << endl;
51     cout << end << endl;
52 torben 68 return 0;
53 torben 75 */
54 torben 68
55 torben 59 SerialPort port("/dev/ttyS1" );
56     port.Open( SerialPort::BAUD_9600,
57     SerialPort::CHAR_SIZE_8,
58     SerialPort::PARITY_NONE,
59     SerialPort::STOP_BITS_1,
60     SerialPort::FLOW_CONTROL_HARD );
61 torben 54
62 torben 59 GsmModem modem(port);
63     modem.Init();
64    
65 torben 75
66     vector<SMS> res = modem.ReadSms(true);
67    
68     for (unsigned int i = 0; i<res.size(); ++i)
69     {
70 torben 78 SMS& sms = res[i];
71     string cmd = GetSmsCommand(sms);
72     string data = GetSmsData(sms);
73     cout << "------------------------------" << endl;
74     cout << "Index " << sms.sms_index << endl;
75     cout << "Sender: " << sms.sender << endl;
76     cout << "Time: " << sms.timestamp << endl;
77     cout << "Message: >" << sms.message << "<" << endl;
78     cout << "Cmd: >" << cmd << "<" << endl;
79     cout << "Data >" << data << "<" << endl;
80    
81     Util::str_dump(sms.message);
82     //modem.SendSms(sms.sender, sms.message, false);
83    
84 torben 75 }
85    
86    
87 torben 61 /*
88     vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("4522337617", "Hej med dig, igen", true);
89     cout << "Len: " << pdu[0].len << endl;
90     cout << "Pdu: " << pdu[0].pdu << endl;
91 torben 59
92 torben 61 modem.SendSmsPdu(pdu[0].pdu, pdu[0].len);
93     */
94 torben 59
95    
96    
97     /*
98 torben 49 SMS sms;
99     sms.sender = "12345678";
100 torben 54 sms.message = "Tog list";
101 torben 49 DebugGsmModem modem;
102     TogPlugin plugin;
103    
104     plugin.Execute(modem, sms);
105    
106    
107     string msg = Util::str_gsm2latin(modem.GetMessage());
108    
109     cout << "---- " << msg.length() << " ----" << endl;
110     cout << msg << endl;
111 torben 59 */
112 torben 49 /*
113 torben 38 vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro");
114 torben 26
115 torben 38 for (unsigned i=0; i<trains.size(); ++i)
116     {
117     TrainInfo& train = trains[i];
118     cout << "-------------------------------------" << endl;
119     cout << "Time: {" << train.time << "}" << endl;
120     cout << "Update: {" << train.update << "}" << endl;
121     cout << "Type: {" << train.type << "}" << endl;
122     cout << "Destination:{" << train.destination << "}" << endl;
123     cout << "Origin: {" << train.origin << "}" << endl;
124     cout << "Current: {" << train.current << "}" << endl;
125     cout << "Status: {" << train.status << "}" << endl;
126     cout << "Note: {" << train.note << "}" << endl;
127     }
128 torben 49 */
129 torben 38 /*
130 torben 26 SMS sms;
131    
132     sms.message = "Test test2 teste3 test4";
133    
134     cout << "|" << GetSmsCommand(sms) << "|" << GetSmsData(sms) << "|" << endl;
135    
136     return 0;
137    
138    
139     SerialPort port("/dev/ttyS1" );
140     port.Open();
141     GsmModem modem(port);
142    
143     //modem.SendSms("22337617", "Hello, sir!");
144     //
145     vector<SMS> res = modem.ReadSms();
146    
147    
148     for (unsigned i=0; i<res.size(); ++i)
149     {
150     cout << "--- SMS Recieved ---" << endl;
151     cout << "Index: " << res[i].sms_index << endl;
152     cout << "From: " << res[i].sender << endl;
153     cout << "Time: " << res[i].timestamp << endl;
154     cout << "Message:>" << res[i].message << "<" << endl;
155     cout << endl;
156     modem.DeleteSms(res[i].sms_index);
157     }
158    
159     for (int j=0; j<5; j++)
160     {
161     modem.SendSms("22337617","Test");
162     }
163 torben 38 */
164 torben 26 return 0;
165     }

  ViewVC Help
Powered by ViewVC 1.1.20