/[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 49 by torben, Wed Jun 11 10:21:47 2008 UTC revision 109 by torben, Sun Aug 24 17:57:04 2008 UTC
# Line 1  Line 1 
1  #include "TogPlugin.h"  #include "TogPlugin.h"
2  #include "GsmModem.h"  #include "IGsmModem.h"
3    #include "Sms.h"
4    
5  #include "TrainInfo.h"  #include "TrainInfo.h"
6  #include "util.h"  #include "util.h"
# Line 7  Line 8 
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å");
20            _stationInfo["ul"] = StationInfo("UP","Ulstrup");
21            _stationInfo["bj"] = StationInfo("BJ","Bjerringbro");
22            _stationInfo["vi"] = StationInfo("VG","Viborg");
23            _stationInfo["ho"] = StationInfo("HØ","Højslev");
24            _stationInfo["sk"] = StationInfo("SK","Skive");
25  }  }
26    
27  string TogPlugin::GetRealStationCode(string code,  string &stationName)  string TogPlugin::GetRealStationCode(string code,  string &stationName)
28  {  {
29          code = Util::str_tolower(code);          map<string, StationInfo>::iterator it = _stationInfo.find(code);
30    
31            if (it != _stationInfo.end())
32            {
33                    stationName = (*it).second.name;
34                    return (*it).second.code;
35            }
36    
37            return "";
38    }
39    
40    string TogPlugin::CreateStationList()
41    {
42            ostringstream os;
43    
44            os << "code - station\n";
45    
46          return "BJ";          map<string, StationInfo>::iterator it;
47    
48            for (it = _stationInfo.begin(); it != _stationInfo.end(); ++it)
49            {
50                    os << (*it).first << " - " << (*it).second.name << "\n";
51            }
52    
53            return Util::str_latin2gsm(os.str());
54  }  }
55    
56  void TogPlugin::Execute(IGsmModem& modem, SMS& sms)  void TogPlugin::Execute(IGsmModem& modem, SMS& sms)
57  {  {
58          string data = GetSmsData(sms);          string data = GetSmsData(sms);
59  //      Util::str_dump(data);  
60          data = Util::str_gsm2latin(data);;          data = Util::str_gsm2latin(data);;
61  /*      Util::str_dump(data);          data = Util::str_tolower(data);
62    
63    
         cout << "1: " << data << endl;  
         data = Util::convertToUnicode(data);  
         cout << "2: " << data << endl;  
         Util::str_dump(data);*/  
           
64          if (data == "")          if (data == "")
65          {          {
66                  modem.SendSms(sms.sender, "Usage: tog <stationskode>");                  modem.SendSms(sms.sender, "Usage: tog <stationskode>\ntog list - liste over stationer", false);
67                  return;                  return;
68          }          }
69    
70            if (data == "list")
71            {
72                    modem.SendSms(sms.sender, CreateStationList(), true);
73                    return;
74            }
75    
76          string stationName;          string stationName;
77          string code = GetRealStationCode(data, stationName);          string code = GetRealStationCode(data, stationName);
78    
79          if (code == "")          if (code == "")
80          {          {
81                  modem.SendSms(sms.sender, "Unknown station");                  modem.SendSms(sms.sender, "Unknown station", false);
82                  return;                  return;
83          }          }
84    
# Line 54  void TogPlugin::Execute(IGsmModem& modem Line 87  void TogPlugin::Execute(IGsmModem& modem
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.sender, e.what(), false );
93                  return;                  return;
94          }          }
95    
96          ostringstream os;          ostringstream os;
97          os << stationName << "\n";          os << stationName << ":\n";
98    
99          for (unsigned int i=0; i< infos.size(); ++i)          for (unsigned int i=0; i< infos.size(); ++i)
100          {          {
# Line 72  void TogPlugin::Execute(IGsmModem& modem Line 105  void TogPlugin::Execute(IGsmModem& modem
105                  os << train.note << "\n";                  os << train.note << "\n";
106          }          }
107    
108          modem.SendSms(sms.sender, Util::str_latin2gsm(os.str()));          modem.SendSms(sms.sender, Util::str_latin2gsm(os.str()), true);
109    
110    
111    

Legend:
Removed from v.49  
changed lines
  Added in v.109

  ViewVC Help
Powered by ViewVC 1.1.20