/[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 51 by torben, Wed Jun 11 10:21:47 2008 UTC revision 52 by torben, Wed Jun 11 12:15:14 2008 UTC
# Line 13  using namespace std; Line 13  using namespace std;
13  TogPlugin::TogPlugin()  TogPlugin::TogPlugin()
14    : Plugin("tog", "Henter tog info fra bane.dk")    : Plugin("tog", "Henter tog info fra bane.dk")
15  {  {
16            _stationInfo["la"] = StationInfo("LG","Langå");
17            _stationInfo["ul"] = StationInfo("UP","Ulstrup");
18            _stationInfo["bj"] = StationInfo("BJ","Bjerringbro");
19            _stationInfo["vi"] = StationInfo("VG","Viborg");
20            _stationInfo["hø"] = StationInfo("HØ","Højslev");
21            _stationInfo["sk"] = StationInfo("SK","Skive");
22  }  }
23    
24  string TogPlugin::GetRealStationCode(string code,  string &stationName)  string TogPlugin::GetRealStationCode(string code,  string &stationName)
25  {  {
26          code = Util::str_tolower(code);          map<string, StationInfo>::iterator it = _stationInfo.find(code);
27    
28          return "BJ";          if (it != _stationInfo.end())
29            {
30                    stationName = (*it).second.name;
31                    return (*it).second.code;
32            }
33    
34            return "";
35    }
36    
37    string TogPlugin::CreateStationList()
38    {
39            ostringstream os;
40    
41            os << "code - station\n";
42    
43            map<string, StationInfo>::iterator it;
44    
45            for (it = _stationInfo.begin(); it != _stationInfo.end(); ++it)
46            {
47                    os << (*it).first << " - " << (*it).second.name << "\n";
48            }
49    
50            return Util::str_latin2gsm(os.str());
51  }  }
52    
53  void TogPlugin::Execute(IGsmModem& modem, SMS& sms)  void TogPlugin::Execute(IGsmModem& modem, SMS& sms)
54  {  {
55          string data = GetSmsData(sms);          string data = GetSmsData(sms);
56  //      Util::str_dump(data);  
57          data = Util::str_gsm2latin(data);;          data = Util::str_gsm2latin(data);;
58  /*      Util::str_dump(data);          data = Util::str_tolower(data);
59    
         cout << "1: " << data << endl;  
         data = Util::convertToUnicode(data);  
         cout << "2: " << data << endl;  
         Util::str_dump(data);*/  
60                    
61          if (data == "")          if (data == "")
62          {          {
63                  modem.SendSms(sms.sender, "Usage: tog <stationskode>");                  modem.SendSms(sms.sender, "Usage: tog <stationskode>\ntog list - liste over stationer");
64                  return;                  return;
65          }          }
66    
67            if (data == "list")
68            {
69                    modem.SendSms(sms.sender, CreateStationList());
70                    return;
71            }
72    
73          string stationName;          string stationName;
74          string code = GetRealStationCode(data, stationName);          string code = GetRealStationCode(data, stationName);
75    
# Line 61  void TogPlugin::Execute(IGsmModem& modem Line 91  void TogPlugin::Execute(IGsmModem& modem
91          }          }
92    
93          ostringstream os;          ostringstream os;
94          os << stationName << "\n";          os << stationName << ":\n";
95    
96          for (unsigned int i=0; i< infos.size(); ++i)          for (unsigned int i=0; i< infos.size(); ++i)
97          {          {

Legend:
Removed from v.51  
changed lines
  Added in v.52

  ViewVC Help
Powered by ViewVC 1.1.20