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

Annotation of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 151 - (hide annotations) (download)
Mon Dec 8 10:42:04 2008 UTC (15 years, 5 months ago) by torben
File size: 4388 byte(s)
Added a transceiver which uses smstools for interfaceing with the gsm modem.
-> http://smstools3.kekekasvi.com/


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

  ViewVC Help
Powered by ViewVC 1.1.20