/[projects]/smsdaemon/tester.cpp
ViewVC logotype

Diff of /smsdaemon/tester.cpp

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

revision 54 by torben, Wed Jun 11 12:57:26 2008 UTC revision 520 by torben, Sat Dec 26 23:01:01 2009 UTC
# Line 1  Line 1 
1  /* using http://sourceforge.net/projects/libserial/  /* using http://sourceforge.net/projects/libserial/
2    
3     *
4   */   */
5    
6    
7  #include <string>  #include <string>
8  #include <iostream>  #include <iostream>
9  #include <vector>  #include <vector>
10  /*#include "SerialPort.h"  #include "serialport/SerialPort.h"
 */  
 #include "GsmModem.h"  
 #include "Sms.h"  
 #include "TogPlugin.h"  
 #include "TrainInfo.h"  
 #include "util.h"  
11    
12    #include "DebugTransceiver.h"
13    #include "SmsToolTransceiver.h"
14    #include "plugins/HostStatusPlugin.h"
15    #include "Sms.h"
16    #include "plugins/TogPlugin.h"
17    #include "plugins/TrainInfo.h"
18    #include "Util.h"
19    #include "plugins/StatusPlugin.h"
20    #include "plugins/WeatherPlugin.h"
21    #include "SmsPdu.h"
22    
23  using namespace std;  using namespace std;
24    using namespace Util;
25    
26    void test_sms(ISmsTransceiver& modem, int len)
 int main()  
27  {  {
28            cout << "----- test_sms( " << len << " ) ------- " << endl;
29    
30          SMS sms;          string msg = Util::str_formatint(len);
31          sms.sender = "12345678";          msg.append(1, ' ');
32          sms.message = "Tog list";          msg.append(len - msg.length(), 'a');
         DebugGsmModem modem;  
         TogPlugin plugin;  
33    
34          plugin.Execute(modem, sms);          vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("22337617", msg, true);
35    
36            for (unsigned int i=0; i<pdu.size(); ++i)
37            {
38                    cout << "#" << i << endl;
39                    cout << "Len: " << pdu[i].len << endl;
40                    cout << "Pdu: " << pdu[i].pdu << endl;
41    
42          string msg = Util::str_gsm2latin(modem.GetMessage());  //              modem.SendSmsPdu(pdu[i].pdu, pdu[i].len);
43            }
44    }
45    
         cout << "---- " << msg.length() << " ----" << endl;  
         cout << msg << endl;  
46    
47  /*  int main()
48          vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro");  {
49            /*
50                    int shift = 6;
51                    string start = "Hej med dig";
52                    string end = SmsPdu::Decode8to7bit(SmsPdu::Encode7to8bit(start,shift), shift );
53    
54                    cout << start << endl;
55                    cout << end << endl;
56                    return 0;
57            */
58    
59            std::vector<TrainInfo>  info = GetTrainInfo( 10 );
60    
61          for (unsigned i=0; i<trains.size(); ++i)          for (unsigned int i=0; i<info.size(); ++i)
62          {          {
63                  TrainInfo& train = trains[i];                  TrainInfo ti = info[i];
                 cout << "-------------------------------------" << endl;  
                 cout << "Time:       {" << train.time        << "}" << endl;  
                 cout << "Update:     {" << train.update      << "}" << endl;  
                 cout << "Type:       {" << train.type        << "}" << endl;  
                 cout << "Destination:{" << train.destination << "}" << endl;  
                 cout << "Origin:     {" << train.origin      << "}" << endl;  
                 cout << "Current:    {" << train.current     << "}" << endl;  
                 cout << "Status:     {" << train.status      << "}" << endl;  
                 cout << "Note:       {" << train.note        << "}" << endl;  
         }  
 */  
 /*  
         SMS sms;  
64    
65          sms.message = "Test   test2   teste3 test4";                  cout << ti.time << ":" <<  ti.update << ":" << ti.destination  << endl;
66            }
67    
68          cout << "|" << GetSmsCommand(sms) << "|" << GetSmsData(sms) << "|" << endl;  /*
69            DebugTransceiver trans(true);
70            WeatherPlugin pl;
71    
72          return 0;          SMS sms;
73    
74            pl.Execute(trans,sms);
75    
         SerialPort port("/dev/ttyS1" );  
         port.Open();  
         GsmModem modem(port);  
76    
         //modem.SendSms("22337617", "Hello, sir!");  
         //  
         vector<SMS> res = modem.ReadSms();  
77    
78            return 0;
79            string start = "hej ������";
80            string mid = str_latin2gsm(start);
81            string final = str_gsm2latin(mid);
82    
83            str_dump (start);
84            str_dump(mid);
85            str_dump(final);
86    
         for (unsigned i=0; i<res.size(); ++i)  
         {  
                 cout << "--- SMS Recieved ---" << endl;  
                 cout << "Index:   " << res[i].sms_index << endl;  
                 cout << "From:    " << res[i].sender << endl;  
                 cout << "Time:    " << res[i].timestamp << endl;  
                 cout << "Message:>" << res[i].message << "<" << endl;  
                 cout << endl;  
                 modem.DeleteSms(res[i].sms_index);  
         }  
87    
88          for (int j=0; j<5; j++)          return 0;
         {  
                 modem.SendSms("22337617","Test");  
         }  
89  */  */
90            /*
91                SerialPort port("/dev/ttyS1" );
92                port.Open( SerialPort::BAUD_9600,
93                                    SerialPort::CHAR_SIZE_8,
94                                    SerialPort::PARITY_NONE,
95                            SerialPort::STOP_BITS_1,
96                            SerialPort::FLOW_CONTROL_HARD );
97    
98                    ModemTransceiver modem(port);
99                    modem.Init();
100    
101    
102                    test_sms(modem, 100);
103                    return 0;
104    
105    
106                    vector<SMS> res = modem.ReadSms(true);
107    
108                    for (unsigned int i = 0; i<res.size(); ++i)
109                    {
110                            SMS& sms = res[i];
111                            string cmd = GetSmsCommand(sms);
112                            string data = GetSmsData(sms);
113                            cout << "------------------------------" << endl;
114                            cout << "Index    " << sms.sms_index << endl;
115                            cout << "Sender:  " << sms.sender << endl;
116                            cout << "Time:    " << sms.timestamp << endl;
117                            cout << "Message: >" << sms.message << "<" << endl;
118                            cout << "Cmd:     >" << cmd << "<" << endl;
119                            cout << "Data     >" << data << "<" << endl;
120    
121                            Util::str_dump(sms.message);
122                            //modem.SendSms(sms.sender, sms.message, false);
123    
124                    }
125    
126            */
127            /*
128                    vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("4522337617", "Hej med dig, igen", true);
129                    cout << "Len: " << pdu[0].len << endl;
130                    cout << "Pdu: " << pdu[0].pdu << endl;
131    
132                    modem.SendSmsPdu(pdu[0].pdu, pdu[0].len);
133            */
134    
135    
136    
137            /*
138                    SMS sms;
139                    sms.sender = "12345678";
140                    sms.message = "Tog list";
141                    DebugModemTransceiver modem;
142                    TogPlugin plugin;
143    
144                    plugin.Execute(modem, sms);
145    
146    
147                    string msg = Util::str_gsm2latin(modem.GetMessage());
148    
149                    cout << "---- " << msg.length() << " ----" << endl;
150                    cout << msg << endl;
151            */
152            /*
153                    vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro");
154    
155                    for (unsigned i=0; i<trains.size(); ++i)
156                    {
157                            TrainInfo& train = trains[i];
158                            cout << "-------------------------------------" << endl;
159                            cout << "Time:       {" << train.time        << "}" << endl;
160                            cout << "Update:     {" << train.update      << "}" << endl;
161                            cout << "Type:       {" << train.type        << "}" << endl;
162                            cout << "Destination:{" << train.destination << "}" << endl;
163                            cout << "Origin:     {" << train.origin      << "}" << endl;
164                            cout << "Current:    {" << train.current     << "}" << endl;
165                            cout << "Status:     {" << train.status      << "}" << endl;
166                            cout << "Note:       {" << train.note        << "}" << endl;
167                    }
168            */
169            /*
170                    SMS sms;
171    
172                    sms.message = "Test   test2   teste3 test4";
173    
174                    cout << "|" << GetSmsCommand(sms) << "|" << GetSmsData(sms) << "|" << endl;
175    
176                    return 0;
177    
178    
179                    SerialPort port("/dev/ttyS1" );
180                    port.Open();
181                    ModemTransceiver modem(port);
182    
183                    //modem.SendSms("22337617", "Hello, sir!");
184                    //
185                    vector<SMS> res = modem.ReadSms();
186    
187    
188                    for (unsigned i=0; i<res.size(); ++i)
189                    {
190                            cout << "--- SMS Recieved ---" << endl;
191                            cout << "Index:   " << res[i].sms_index << endl;
192                            cout << "From:    " << res[i].sender << endl;
193                            cout << "Time:    " << res[i].timestamp << endl;
194                            cout << "Message:>" << res[i].message << "<" << endl;
195                            cout << endl;
196                            modem.DeleteSms(res[i].sms_index);
197                    }
198    
199                    for (int j=0; j<5; j++)
200                    {
201                            modem.SendSms("22337617","Test");
202                    }
203            */
204          return 0;          return 0;
205  }  }

Legend:
Removed from v.54  
changed lines
  Added in v.520

  ViewVC Help
Powered by ViewVC 1.1.20