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

Contents of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations) (download)
Sun Dec 7 20:58:41 2008 UTC (15 years, 5 months ago) by torben
File size: 4297 byte(s)
Refactoring / rename:
        IGsmModem -> ISmsTransceiver
        GsmModem -> ModemTransceiver
        DebugGsmModem -> DebugTransceiver

Move DebugTransceiver to its own files.


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

  ViewVC Help
Powered by ViewVC 1.1.20