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

Annotation of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1011 - (hide 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 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 1011 #include "Logger.h"
23 torben 49
24 torben 26 using namespace std;
25 torben 141 using namespace Util;
26 torben 26
27 torben 149 void test_sms(ISmsTransceiver& modem, int len)
28 torben 60 {
29     cout << "----- test_sms( " << len << " ) ------- " << endl;
30    
31     string msg = Util::str_formatint(len);
32 torben 62 msg.append(1, ' ');
33 torben 61 msg.append(len - msg.length(), 'a');
34 torben 196
35 torben 75 vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("22337617", msg, true);
36 torben 60
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 torben 149 // modem.SendSmsPdu(pdu[i].pdu, pdu[i].len);
44 torben 60 }
45     }
46    
47    
48 torben 26 int main()
49     {
50 torben 196 /*
51     int shift = 6;
52     string start = "Hej med dig";
53     string end = SmsPdu::Decode8to7bit(SmsPdu::Encode7to8bit(start,shift), shift );
54 torben 68
55 torben 196 cout << start << endl;
56     cout << end << endl;
57     return 0;
58     */
59 torben 151
60 torben 1011 Logger::logMessage( "Hello" );
61     /*std::vector<TrainInfo> info = GetTrainInfo( 10 );
62 torben 151
63 torben 520 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 torben 1011 }*/
69 torben 520
70     /*
71 torben 185 DebugTransceiver trans(true);
72 torben 188 WeatherPlugin pl;
73 torben 151
74 torben 185 SMS sms;
75    
76     pl.Execute(trans,sms);
77    
78    
79    
80 torben 151 return 0;
81 torben 149 string start = "hej ������";
82 torben 141 string mid = str_latin2gsm(start);
83     string final = str_gsm2latin(mid);
84 torben 68
85 torben 141 str_dump (start);
86     str_dump(mid);
87     str_dump(final);
88    
89    
90     return 0;
91 torben 520 */
92 torben 196 /*
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 torben 54
100 torben 196 ModemTransceiver modem(port);
101     modem.Init();
102 torben 59
103 torben 75
104 torben 196 test_sms(modem, 100);
105     return 0;
106 torben 83
107    
108 torben 196 vector<SMS> res = modem.ReadSms(true);
109 torben 75
110 torben 196 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 torben 78
123 torben 196 Util::str_dump(sms.message);
124     //modem.SendSms(sms.sender, sms.message, false);
125 torben 78
126 torben 196 }
127 torben 75
128 torben 196 */
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 torben 59
134 torben 196 modem.SendSmsPdu(pdu[0].pdu, pdu[0].len);
135     */
136 torben 59
137    
138 torben 49
139 torben 196 /*
140     SMS sms;
141     sms.sender = "12345678";
142     sms.message = "Tog list";
143     DebugModemTransceiver modem;
144     TogPlugin plugin;
145 torben 49
146 torben 196 plugin.Execute(modem, sms);
147 torben 49
148    
149 torben 196 string msg = Util::str_gsm2latin(modem.GetMessage());
150 torben 26
151 torben 196 cout << "---- " << msg.length() << " ----" << endl;
152     cout << msg << endl;
153     */
154     /*
155     vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro");
156 torben 26
157 torben 196 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 torben 26
174 torben 196 sms.message = "Test test2 teste3 test4";
175 torben 26
176 torben 196 cout << "|" << GetSmsCommand(sms) << "|" << GetSmsData(sms) << "|" << endl;
177 torben 26
178 torben 196 return 0;
179 torben 26
180    
181 torben 196 SerialPort port("/dev/ttyS1" );
182     port.Open();
183     ModemTransceiver modem(port);
184 torben 26
185 torben 196 //modem.SendSms("22337617", "Hello, sir!");
186     //
187     vector<SMS> res = modem.ReadSms();
188 torben 26
189    
190 torben 196 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 torben 26 return 0;
207     }

  ViewVC Help
Powered by ViewVC 1.1.20