--- smsdaemon/plugins/TogPlugin.cpp 2008/12/07 20:58:41 149 +++ smsdaemon/plugins/TogPlugin.cpp 2009/09/16 09:08:40 323 @@ -3,39 +3,46 @@ #include "Sms.h" #include "TrainInfo.h" -#include "util.h" +#include "Util.h" #include #include -#include "common.h" +#include "Common.h" using namespace std; +StationInfo::StationInfo(int i, std::string n) +{ + id = i; + name = Util::str_characters(n); +} + + TogPlugin::TogPlugin() - : Plugin("tog", "Henter tog info fra bane.dk") + : Plugin("tog", "Henter tog info fra bane.dk") { - _stationInfo["ar"] = StationInfo("AR","�rhus"); - _stationInfo["la"] = StationInfo("LG","Lang�"); - _stationInfo["ul"] = StationInfo("UP","Ulstrup"); - _stationInfo["bj"] = StationInfo("BJ","Bjerringbro"); - _stationInfo["vi"] = StationInfo("VG","Viborg"); - _stationInfo["ho"] = StationInfo("H�","H�jslev"); - _stationInfo["sk"] = StationInfo("SK","Skive"); + _stationInfo["ar"] = StationInfo(278, "Århus"); + _stationInfo["la"] = StationInfo(122, "Langå"); + _stationInfo["ul"] = StationInfo(240, "Ulstrup"); + _stationInfo["bj"] = StationInfo(10, "Bjerringbro"); + _stationInfo["vi"] = StationInfo(253, "Viborg"); + _stationInfo["ho"] = StationInfo(94, "Højslev"); + _stationInfo["sk"] = StationInfo(190, "Skive"); } -string TogPlugin::GetRealStationCode(string code, string &stationName) +int TogPlugin::GetStationId(string code, string &stationName) { map::iterator it = _stationInfo.find(code); if (it != _stationInfo.end()) { stationName = (*it).second.name; - return (*it).second.code; + return (*it).second.id; } - return ""; + return -1; } string TogPlugin::CreateStationList() @@ -58,14 +65,13 @@ { string data = sms.ExtractParameters(); - data = Util::str_gsm2latin(data);; data = Util::str_tolower(data); if (data == "") { modem.SendSms(sms.GetSender(), "Usage: tog \ntog list - liste over stationer", false); - return; + return; } if (data == "list") @@ -75,9 +81,9 @@ } string stationName; - string code = GetRealStationCode(data, stationName); + int id = GetStationId(data, stationName); - if (code == "") + if (id < 0) { modem.SendSms(sms.GetSender(), "Unknown station", false); return; @@ -86,9 +92,9 @@ vector infos; try { - infos = GetTrainInfo( code , "" ); + infos = GetTrainInfo( id ); } - catch(std::exception& e) + catch (std::exception& e) { modem.SendSms(sms.GetSender(), e.what(), false ); return;