/[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 158 by torben, Mon Dec 8 21:49:49 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  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    
# Line 47  string TogPlugin::CreateStationList() Line 51  string TogPlugin::CreateStationList()
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    
61          data = Util::str_gsm2latin(data);;          data = Util::str_gsm2latin(data);;
62          data = Util::str_tolower(data);          data = Util::str_tolower(data);
63    
64            
65          if (data == "")          if (data == "")
66          {          {
67                  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);
68                  return;                  return;
69          }          }
70    
71          if (data == "list")          if (data == "list")
72          {          {
73                  modem.SendSms(sms.sender, CreateStationList(), true);                  modem.SendSms(sms.GetSender(), CreateStationList(), true);
74                  return;                  return;
75          }          }
76    
# Line 75  void TogPlugin::Execute(IGsmModem& modem Line 79  void TogPlugin::Execute(IGsmModem& modem
79    
80          if (code == "")          if (code == "")
81          {          {
82                  modem.SendSms(sms.sender, "Unknown station", false);                  modem.SendSms(sms.GetSender(), "Unknown station", false);
83                  return;                  return;
84          }          }
85    
# Line 84  void TogPlugin::Execute(IGsmModem& modem Line 88  void TogPlugin::Execute(IGsmModem& modem
88          {          {
89                  infos = GetTrainInfo( code , "" );                  infos = GetTrainInfo( code , "" );
90          }          }
91          catch(...)          catch(std::exception& e)
92          {          {
93                  modem.SendSms(sms.sender, "Connection timeout", false );                  modem.SendSms(sms.GetSender(), e.what(), false );
94                  return;                  return;
95          }          }
96    
# Line 102  void TogPlugin::Execute(IGsmModem& modem Line 106  void TogPlugin::Execute(IGsmModem& modem
106                  os << train.note << "\n";                  os << train.note << "\n";
107          }          }
108    
109          modem.SendSms(sms.sender, Util::str_latin2gsm(os.str()), true);          modem.SendSms(sms.GetSender(), os.str(), true);
110    
111    
112    

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

  ViewVC Help
Powered by ViewVC 1.1.20