1 |
torben |
44 |
#include "TogPlugin.h" |
2 |
|
|
#include "GsmModem.h" |
3 |
|
|
|
4 |
|
|
#include "TrainInfo.h" |
5 |
|
|
#include "util.h" |
6 |
|
|
|
7 |
|
|
#include <iostream> |
8 |
|
|
#include <sstream> |
9 |
|
|
|
10 |
|
|
using namespace std; |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
TogPlugin::TogPlugin() |
14 |
|
|
: Plugin("tog", "Henter tog info fra bane.dk") |
15 |
|
|
{ |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
string TogPlugin::GetRealStationCode(string code, string &stationName) |
19 |
|
|
{ |
20 |
|
|
code = Util::str_tolower(code); |
21 |
|
|
|
22 |
|
|
return "BJ"; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
void TogPlugin::Execute(IGsmModem& modem, SMS& sms) |
26 |
|
|
{ |
27 |
|
|
string data = GetSmsData(sms); |
28 |
|
|
// Util::str_dump(data); |
29 |
|
|
data = Util::str_gsm2latin(data);; |
30 |
|
|
/* Util::str_dump(data); |
31 |
|
|
|
32 |
|
|
cout << "1: " << data << endl; |
33 |
|
|
data = Util::convertToUnicode(data); |
34 |
|
|
cout << "2: " << data << endl; |
35 |
|
|
Util::str_dump(data);*/ |
36 |
|
|
|
37 |
|
|
if (data == "") |
38 |
|
|
{ |
39 |
|
|
modem.SendSms(sms.sender, "Usage: tog <stationskode>"); |
40 |
|
|
return; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
string stationName; |
44 |
|
|
string code = GetRealStationCode(data, stationName); |
45 |
|
|
|
46 |
|
|
if (code == "") |
47 |
|
|
{ |
48 |
|
|
modem.SendSms(sms.sender, "Unknown station"); |
49 |
|
|
return; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
vector<TrainInfo> infos = GetTrainInfo( code , "" ); |
53 |
|
|
|
54 |
|
|
ostringstream os; |
55 |
|
|
os << stationName << "\n"; |
56 |
|
|
|
57 |
|
|
for (unsigned int i=0; i< infos.size(); ++i) |
58 |
|
|
{ |
59 |
|
|
TrainInfo& train = infos[i]; |
60 |
|
|
os << train.time << " "; |
61 |
|
|
os << train.destination << " "; |
62 |
|
|
os << train.status << " "; |
63 |
|
|
os << train.note << "\n"; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
modem.SendSms(sms.sender, Util::str_latin2gsm(os.str())); |
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
} |