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

Contents of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 520 - (show 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 /* using http://sourceforge.net/projects/libserial/
2
3 *
4 */
5
6
7 #include <string>
8 #include <iostream>
9 #include <vector>
10 #include "serialport/SerialPort.h"
11
12 #include "DebugTransceiver.h"
13 #include "SmsToolTransceiver.h"
14 #include "plugins/HostStatusPlugin.h"
15 #include "Sms.h"
16 #include "plugins/TogPlugin.h"
17 #include "plugins/TrainInfo.h"
18 #include "Util.h"
19 #include "plugins/StatusPlugin.h"
20 #include "plugins/WeatherPlugin.h"
21 #include "SmsPdu.h"
22
23 using namespace std;
24 using namespace Util;
25
26 void test_sms(ISmsTransceiver& modem, int len)
27 {
28 cout << "----- test_sms( " << len << " ) ------- " << endl;
29
30 string msg = Util::str_formatint(len);
31 msg.append(1, ' ');
32 msg.append(len - msg.length(), 'a');
33
34 vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("22337617", msg, true);
35
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 // modem.SendSmsPdu(pdu[i].pdu, pdu[i].len);
43 }
44 }
45
46
47 int main()
48 {
49 /*
50 int shift = 6;
51 string start = "Hej med dig";
52 string end = SmsPdu::Decode8to7bit(SmsPdu::Encode7to8bit(start,shift), shift );
53
54 cout << start << endl;
55 cout << end << endl;
56 return 0;
57 */
58
59 std::vector<TrainInfo> info = GetTrainInfo( 10 );
60
61 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 DebugTransceiver trans(true);
70 WeatherPlugin pl;
71
72 SMS sms;
73
74 pl.Execute(trans,sms);
75
76
77
78 return 0;
79 string start = "hej ������";
80 string mid = str_latin2gsm(start);
81 string final = str_gsm2latin(mid);
82
83 str_dump (start);
84 str_dump(mid);
85 str_dump(final);
86
87
88 return 0;
89 */
90 /*
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
98 ModemTransceiver modem(port);
99 modem.Init();
100
101
102 test_sms(modem, 100);
103 return 0;
104
105
106 vector<SMS> res = modem.ReadSms(true);
107
108 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
121 Util::str_dump(sms.message);
122 //modem.SendSms(sms.sender, sms.message, false);
123
124 }
125
126 */
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
132 modem.SendSmsPdu(pdu[0].pdu, pdu[0].len);
133 */
134
135
136
137 /*
138 SMS sms;
139 sms.sender = "12345678";
140 sms.message = "Tog list";
141 DebugModemTransceiver modem;
142 TogPlugin plugin;
143
144 plugin.Execute(modem, sms);
145
146
147 string msg = Util::str_gsm2latin(modem.GetMessage());
148
149 cout << "---- " << msg.length() << " ----" << endl;
150 cout << msg << endl;
151 */
152 /*
153 vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro");
154
155 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
172 sms.message = "Test test2 teste3 test4";
173
174 cout << "|" << GetSmsCommand(sms) << "|" << GetSmsData(sms) << "|" << endl;
175
176 return 0;
177
178
179 SerialPort port("/dev/ttyS1" );
180 port.Open();
181 ModemTransceiver modem(port);
182
183 //modem.SendSms("22337617", "Hello, sir!");
184 //
185 vector<SMS> res = modem.ReadSms();
186
187
188 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 return 0;
205 }

  ViewVC Help
Powered by ViewVC 1.1.20