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