/[projects]/smsdaemon/plugins/TogPlugin.cpp
ViewVC logotype

Diff of /smsdaemon/plugins/TogPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 63 by torben, Thu Jun 12 12:43:29 2008 UTC revision 186 by torben, Mon Dec 15 09:27:56 2008 UTC
# Line 1  Line 1 
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    StationInfo::StationInfo(std::string c, std::string n)
17    {
18            code = Util::str_characters(c);
19            name = Util::str_characters(n);
20    }
21    
22    
23  TogPlugin::TogPlugin()  TogPlugin::TogPlugin()
24    : Plugin("tog", "Henter tog info fra bane.dk")    : Plugin("tog", "Henter tog info fra bane.dk")
25  {  {
26          _stationInfo["la"] = StationInfo("LG","Langå");          _stationInfo["ar"] = StationInfo("AR","&Aring;rhus");
27            _stationInfo["la"] = StationInfo("LG","Lang&aring;");
28          _stationInfo["ul"] = StationInfo("UP","Ulstrup");          _stationInfo["ul"] = StationInfo("UP","Ulstrup");
29          _stationInfo["bj"] = StationInfo("BJ","Bjerringbro");          _stationInfo["bj"] = StationInfo("BJ","Bjerringbro");
30          _stationInfo["vi"] = StationInfo("VG","Viborg");          _stationInfo["vi"] = StationInfo("VG","Viborg");
31          _stationInfo["hø"] = StationInfo("HØ","Højslev");          _stationInfo["ho"] = StationInfo("H&Oslash;","H&oslash;jslev");
32          _stationInfo["sk"] = StationInfo("SK","Skive");          _stationInfo["sk"] = StationInfo("SK","Skive");
33  }  }
34    
# Line 47  string TogPlugin::CreateStationList() Line 58  string TogPlugin::CreateStationList()
58                  os << (*it).first << " - " << (*it).second.name << "\n";                  os << (*it).first << " - " << (*it).second.name << "\n";
59          }          }
60    
61          return Util::str_latin2gsm(os.str());          return os.str();
62  }  }
63    
64  void TogPlugin::Execute(IGsmModem& modem, SMS& sms)  void TogPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
65  {  {
66          string data = GetSmsData(sms);          string data = sms.ExtractParameters();
67    
         data = Util::str_gsm2latin(data);;  
68          data = Util::str_tolower(data);          data = Util::str_tolower(data);
69    
70            
71          if (data == "")          if (data == "")
72          {          {
73                  modem.SendSms(sms.sender, "Usage: tog <stationskode>\ntog list - liste over stationer", false);                  modem.SendSms(sms.GetSender(), "Usage: tog <stationskode>\ntog list - liste over stationer", false);
74                  return;                  return;
75          }          }
76    
77          if (data == "list")          if (data == "list")
78          {          {
79                  modem.SendSms(sms.sender, CreateStationList(), true);                  modem.SendSms(sms.GetSender(), CreateStationList(), true);
80                  return;                  return;
81          }          }
82    
# Line 75  void TogPlugin::Execute(IGsmModem& modem Line 85  void TogPlugin::Execute(IGsmModem& modem
85    
86          if (code == "")          if (code == "")
87          {          {
88                  modem.SendSms(sms.sender, "Unknown station", false);                  modem.SendSms(sms.GetSender(), "Unknown station", false);
89                  return;                  return;
90          }          }
91    
# Line 84  void TogPlugin::Execute(IGsmModem& modem Line 94  void TogPlugin::Execute(IGsmModem& modem
94          {          {
95                  infos = GetTrainInfo( code , "" );                  infos = GetTrainInfo( code , "" );
96          }          }
97          catch(...)          catch(std::exception& e)
98          {          {
99                  modem.SendSms(sms.sender, "Connection timeout", false );                  modem.SendSms(sms.GetSender(), e.what(), false );
100                  return;                  return;
101          }          }
102    
# Line 102  void TogPlugin::Execute(IGsmModem& modem Line 112  void TogPlugin::Execute(IGsmModem& modem
112                  os << train.note << "\n";                  os << train.note << "\n";
113          }          }
114    
115          modem.SendSms(sms.sender, Util::str_latin2gsm(os.str()), true);          modem.SendSms(sms.GetSender(), os.str(), true);
116    
117    
118    

Legend:
Removed from v.63  
changed lines
  Added in v.186

  ViewVC Help
Powered by ViewVC 1.1.20