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

Contents of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 101 - (show annotations) (download)
Mon Jun 16 16:41:18 2008 UTC (15 years, 11 months ago) by torben
File size: 4008 byte(s)
Finally is the version.h working as i want to

Added a StatusPlugin

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

  ViewVC Help
Powered by ViewVC 1.1.20