6 |
#include <string> |
#include <string> |
7 |
#include <iostream> |
#include <iostream> |
8 |
#include <vector> |
#include <vector> |
9 |
#include "SerialPort.h" |
#include "serialport/SerialPort.h" |
10 |
|
|
11 |
#include "GsmModem.h" |
#include "DebugTransceiver.h" |
12 |
|
#include "SmsToolTransceiver.h" |
13 |
|
#include "plugins/HostStatusPlugin.h" |
14 |
#include "Sms.h" |
#include "Sms.h" |
15 |
#include "TogPlugin.h" |
#include "plugins/TogPlugin.h" |
16 |
#include "TrainInfo.h" |
#include "plugins/TrainInfo.h" |
17 |
#include "util.h" |
#include "Util.h" |
18 |
|
#include "plugins/StatusPlugin.h" |
19 |
|
#include "plugins/WeatherPlugin.h" |
20 |
#include "SmsPdu.h" |
#include "SmsPdu.h" |
21 |
|
|
22 |
using namespace std; |
using namespace std; |
23 |
|
using namespace Util; |
24 |
|
|
25 |
|
void test_sms(ISmsTransceiver& modem, int len) |
|
void test_sms(GsmModem& modem, int len) |
|
26 |
{ |
{ |
27 |
cout << "----- test_sms( " << len << " ) ------- " << endl; |
cout << "----- test_sms( " << len << " ) ------- " << endl; |
28 |
|
|
29 |
string msg = Util::str_formatint(len); |
string msg = Util::str_formatint(len); |
30 |
msg.append(1, ' '); |
msg.append(1, ' '); |
31 |
msg.append(len - msg.length(), 'a'); |
msg.append(len - msg.length(), 'a'); |
32 |
|
|
33 |
vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("4522337617", msg, true); |
vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("22337617", msg, true); |
34 |
|
|
35 |
for (unsigned int i=0; i<pdu.size(); ++i) |
for (unsigned int i=0; i<pdu.size(); ++i) |
36 |
{ |
{ |
38 |
cout << "Len: " << pdu[i].len << endl; |
cout << "Len: " << pdu[i].len << endl; |
39 |
cout << "Pdu: " << pdu[i].pdu << endl; |
cout << "Pdu: " << pdu[i].pdu << endl; |
40 |
|
|
41 |
modem.SendSmsPdu(pdu[i].pdu, pdu[i].len); |
// modem.SendSmsPdu(pdu[i].pdu, pdu[i].len); |
42 |
} |
} |
43 |
} |
} |
44 |
|
|
45 |
|
|
46 |
int main() |
int main() |
47 |
{ |
{ |
48 |
vector<unsigned char> temp = SmsPdu::Encode7to8bit("Dette er en test af encode"); |
/* |
49 |
cout << SmsPdu::HexformatVector(temp) << endl; |
int shift = 6; |
50 |
|
string start = "Hej med dig"; |
51 |
string result = SmsPdu::Decode8to7bit(temp); |
string end = SmsPdu::Decode8to7bit(SmsPdu::Encode7to8bit(start,shift), shift ); |
52 |
cout << result << endl; |
|
53 |
|
cout << start << endl; |
54 |
return 0; |
cout << end << endl; |
55 |
|
return 0; |
56 |
|
*/ |
57 |
|
|
58 |
|
|
59 |
SerialPort port("/dev/ttyS1" ); |
DebugTransceiver trans(true); |
60 |
port.Open( SerialPort::BAUD_9600, |
WeatherPlugin pl; |
|
SerialPort::CHAR_SIZE_8, |
|
|
SerialPort::PARITY_NONE, |
|
|
SerialPort::STOP_BITS_1, |
|
|
SerialPort::FLOW_CONTROL_HARD ); |
|
|
|
|
|
GsmModem modem(port); |
|
|
modem.Init(); |
|
|
|
|
|
test_sms(modem, 161); |
|
|
/* |
|
|
vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("4522337617", "Hej med dig, igen", true); |
|
|
cout << "Len: " << pdu[0].len << endl; |
|
|
cout << "Pdu: " << pdu[0].pdu << endl; |
|
61 |
|
|
|
modem.SendSmsPdu(pdu[0].pdu, pdu[0].len); |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
62 |
SMS sms; |
SMS sms; |
|
sms.sender = "12345678"; |
|
|
sms.message = "Tog list"; |
|
|
DebugGsmModem modem; |
|
|
TogPlugin plugin; |
|
|
|
|
|
plugin.Execute(modem, sms); |
|
63 |
|
|
64 |
|
pl.Execute(trans,sms); |
65 |
|
|
|
string msg = Util::str_gsm2latin(modem.GetMessage()); |
|
66 |
|
|
|
cout << "---- " << msg.length() << " ----" << endl; |
|
|
cout << msg << endl; |
|
|
*/ |
|
|
/* |
|
|
vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro"); |
|
|
|
|
|
for (unsigned i=0; i<trains.size(); ++i) |
|
|
{ |
|
|
TrainInfo& train = trains[i]; |
|
|
cout << "-------------------------------------" << endl; |
|
|
cout << "Time: {" << train.time << "}" << endl; |
|
|
cout << "Update: {" << train.update << "}" << endl; |
|
|
cout << "Type: {" << train.type << "}" << endl; |
|
|
cout << "Destination:{" << train.destination << "}" << endl; |
|
|
cout << "Origin: {" << train.origin << "}" << endl; |
|
|
cout << "Current: {" << train.current << "}" << endl; |
|
|
cout << "Status: {" << train.status << "}" << endl; |
|
|
cout << "Note: {" << train.note << "}" << endl; |
|
|
} |
|
|
*/ |
|
|
/* |
|
|
SMS sms; |
|
|
|
|
|
sms.message = "Test test2 teste3 test4"; |
|
|
|
|
|
cout << "|" << GetSmsCommand(sms) << "|" << GetSmsData(sms) << "|" << endl; |
|
67 |
|
|
68 |
return 0; |
return 0; |
69 |
|
string start = "hej ������"; |
70 |
|
string mid = str_latin2gsm(start); |
71 |
|
string final = str_gsm2latin(mid); |
72 |
|
|
73 |
|
str_dump (start); |
74 |
|
str_dump(mid); |
75 |
|
str_dump(final); |
76 |
|
|
77 |
|
|
78 |
SerialPort port("/dev/ttyS1" ); |
return 0; |
|
port.Open(); |
|
|
GsmModem modem(port); |
|
|
|
|
|
//modem.SendSms("22337617", "Hello, sir!"); |
|
|
// |
|
|
vector<SMS> res = modem.ReadSms(); |
|
|
|
|
|
|
|
|
for (unsigned i=0; i<res.size(); ++i) |
|
|
{ |
|
|
cout << "--- SMS Recieved ---" << endl; |
|
|
cout << "Index: " << res[i].sms_index << endl; |
|
|
cout << "From: " << res[i].sender << endl; |
|
|
cout << "Time: " << res[i].timestamp << endl; |
|
|
cout << "Message:>" << res[i].message << "<" << endl; |
|
|
cout << endl; |
|
|
modem.DeleteSms(res[i].sms_index); |
|
|
} |
|
79 |
|
|
80 |
for (int j=0; j<5; j++) |
/* |
81 |
{ |
SerialPort port("/dev/ttyS1" ); |
82 |
modem.SendSms("22337617","Test"); |
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 |
|
|
88 |
|
ModemTransceiver modem(port); |
89 |
|
modem.Init(); |
90 |
|
|
91 |
|
|
92 |
|
test_sms(modem, 100); |
93 |
|
return 0; |
94 |
|
|
95 |
|
|
96 |
|
vector<SMS> res = modem.ReadSms(true); |
97 |
|
|
98 |
|
for (unsigned int i = 0; i<res.size(); ++i) |
99 |
|
{ |
100 |
|
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 |
|
} |
115 |
|
|
116 |
|
*/ |
117 |
|
/* |
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 |
|
|
122 |
|
modem.SendSmsPdu(pdu[0].pdu, pdu[0].len); |
123 |
|
*/ |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
/* |
128 |
|
SMS sms; |
129 |
|
sms.sender = "12345678"; |
130 |
|
sms.message = "Tog list"; |
131 |
|
DebugModemTransceiver modem; |
132 |
|
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 |
|
*/ |
142 |
|
/* |
143 |
|
vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro"); |
144 |
|
|
145 |
|
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 |
|
*/ |
159 |
|
/* |
160 |
|
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 |
|
ModemTransceiver modem(port); |
172 |
|
|
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 |
|
*/ |
194 |
return 0; |
return 0; |
195 |
} |
} |