1 |
#include "TogPlugin.h" |
#include "TogPlugin.h" |
2 |
#include "GsmModem.h" |
#include "ISmsTransceiver.h" |
3 |
|
#include "Sms.h" |
4 |
|
|
5 |
#include "TrainInfo.h" |
#include "TrainInfo.h" |
6 |
#include "util.h" |
#include "Util.h" |
7 |
|
|
8 |
#include <iostream> |
#include <iostream> |
9 |
#include <sstream> |
#include <sstream> |
10 |
|
|
11 |
|
#include "Common.h" |
12 |
|
|
13 |
using namespace std; |
using namespace std; |
14 |
|
|
15 |
|
|
16 |
TogPlugin::TogPlugin() |
TogPlugin::TogPlugin() |
17 |
: Plugin("tog", "Henter tog info fra bane.dk") |
: Plugin("tog", "Henter tog info fra bane.dk") |
18 |
{ |
{ |
19 |
_stationInfo["la"] = StationInfo("LG","Langå"); |
_stationInfo["ar"] = StationInfo("AR","�rhus"); |
20 |
|
_stationInfo["la"] = StationInfo("LG","Lang�"); |
21 |
_stationInfo["ul"] = StationInfo("UP","Ulstrup"); |
_stationInfo["ul"] = StationInfo("UP","Ulstrup"); |
22 |
_stationInfo["bj"] = StationInfo("BJ","Bjerringbro"); |
_stationInfo["bj"] = StationInfo("BJ","Bjerringbro"); |
23 |
_stationInfo["vi"] = StationInfo("VG","Viborg"); |
_stationInfo["vi"] = StationInfo("VG","Viborg"); |
24 |
_stationInfo["hø"] = StationInfo("HØ","Højslev"); |
_stationInfo["ho"] = StationInfo("H�","H�jslev"); |
25 |
_stationInfo["sk"] = StationInfo("SK","Skive"); |
_stationInfo["sk"] = StationInfo("SK","Skive"); |
26 |
} |
} |
27 |
|
|
51 |
os << (*it).first << " - " << (*it).second.name << "\n"; |
os << (*it).first << " - " << (*it).second.name << "\n"; |
52 |
} |
} |
53 |
|
|
54 |
return Util::str_latin2gsm(os.str()); |
return os.str(); |
55 |
} |
} |
56 |
|
|
57 |
void TogPlugin::Execute(IGsmModem& modem, SMS& sms) |
void TogPlugin::Execute(ISmsTransceiver& modem, SMS& sms) |
58 |
{ |
{ |
59 |
string data = GetSmsData(sms); |
string data = sms.ExtractParameters(); |
60 |
|
|
|
data = Util::str_gsm2latin(data);; |
|
61 |
data = Util::str_tolower(data); |
data = Util::str_tolower(data); |
62 |
|
|
63 |
|
|
64 |
if (data == "") |
if (data == "") |
65 |
{ |
{ |
66 |
modem.SendSms(sms.sender, "Usage: tog <stationskode>\ntog list - liste over stationer"); |
modem.SendSms(sms.GetSender(), "Usage: tog <stationskode>\ntog list - liste over stationer", false); |
67 |
return; |
return; |
68 |
} |
} |
69 |
|
|
70 |
if (data == "list") |
if (data == "list") |
71 |
{ |
{ |
72 |
modem.SendSms(sms.sender, CreateStationList()); |
modem.SendSms(sms.GetSender(), CreateStationList(), true); |
73 |
return; |
return; |
74 |
} |
} |
75 |
|
|
78 |
|
|
79 |
if (code == "") |
if (code == "") |
80 |
{ |
{ |
81 |
modem.SendSms(sms.sender, "Unknown station"); |
modem.SendSms(sms.GetSender(), "Unknown station", false); |
82 |
return; |
return; |
83 |
} |
} |
84 |
|
|
87 |
{ |
{ |
88 |
infos = GetTrainInfo( code , "" ); |
infos = GetTrainInfo( code , "" ); |
89 |
} |
} |
90 |
catch(...) |
catch(std::exception& e) |
91 |
{ |
{ |
92 |
modem.SendSms(sms.sender, "Connection timeout"); |
modem.SendSms(sms.GetSender(), e.what(), false ); |
93 |
return; |
return; |
94 |
} |
} |
95 |
|
|
105 |
os << train.note << "\n"; |
os << train.note << "\n"; |
106 |
} |
} |
107 |
|
|
108 |
modem.SendSms(sms.sender, Util::str_latin2gsm(os.str())); |
modem.SendSms(sms.GetSender(), os.str(), true); |
109 |
|
|
110 |
|
|
111 |
|
|