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

Contents of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20