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

Annotation of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 520 - (hide annotations) (download)
Sat Dec 26 23:01:01 2009 UTC (14 years, 4 months ago) by torben
File size: 4633 byte(s)
Added delayspam plugin+task


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

  ViewVC Help
Powered by ViewVC 1.1.20