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

Annotation of /smsdaemon/plugins/TogPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (hide annotations) (download)
Wed Jun 11 10:21:47 2008 UTC (15 years, 11 months ago) by torben
File size: 1374 byte(s)
Make togplugin work

GsmModem.cpp - when sending SMS - truncate message body to 160 chars

1 torben 44 #include "TogPlugin.h"
2     #include "GsmModem.h"
3    
4     #include "TrainInfo.h"
5     #include "util.h"
6    
7     #include <iostream>
8     #include <sstream>
9    
10     using namespace std;
11    
12    
13     TogPlugin::TogPlugin()
14     : Plugin("tog", "Henter tog info fra bane.dk")
15     {
16     }
17    
18     string TogPlugin::GetRealStationCode(string code, string &stationName)
19     {
20     code = Util::str_tolower(code);
21    
22     return "BJ";
23     }
24    
25     void TogPlugin::Execute(IGsmModem& modem, SMS& sms)
26     {
27     string data = GetSmsData(sms);
28     // Util::str_dump(data);
29     data = Util::str_gsm2latin(data);;
30     /* Util::str_dump(data);
31    
32     cout << "1: " << data << endl;
33     data = Util::convertToUnicode(data);
34     cout << "2: " << data << endl;
35     Util::str_dump(data);*/
36    
37     if (data == "")
38     {
39     modem.SendSms(sms.sender, "Usage: tog <stationskode>");
40     return;
41     }
42    
43     string stationName;
44     string code = GetRealStationCode(data, stationName);
45    
46     if (code == "")
47     {
48     modem.SendSms(sms.sender, "Unknown station");
49     return;
50     }
51    
52 torben 49 vector<TrainInfo> infos;
53     try
54     {
55     infos = GetTrainInfo( code , "" );
56     }
57     catch(...)
58     {
59     modem.SendSms(sms.sender, "Connection timeout");
60     return;
61     }
62 torben 44
63     ostringstream os;
64     os << stationName << "\n";
65    
66     for (unsigned int i=0; i< infos.size(); ++i)
67     {
68     TrainInfo& train = infos[i];
69     os << train.time << " ";
70     os << train.destination << " ";
71     os << train.status << " ";
72     os << train.note << "\n";
73     }
74    
75     modem.SendSms(sms.sender, Util::str_latin2gsm(os.str()));
76    
77    
78    
79     }

  ViewVC Help
Powered by ViewVC 1.1.20