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