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

Diff of /smsdaemon/tester.cpp

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

revision 149 by torben, Sun Dec 7 20:58:41 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    
# Line 9  Line 10 
10  #include "serialport/SerialPort.h"  #include "serialport/SerialPort.h"
11    
12  #include "DebugTransceiver.h"  #include "DebugTransceiver.h"
13    #include "SmsToolTransceiver.h"
14    #include "plugins/HostStatusPlugin.h"
15  #include "Sms.h"  #include "Sms.h"
16  #include "plugins/TogPlugin.h"  #include "plugins/TogPlugin.h"
17  #include "plugins/TrainInfo.h"  #include "plugins/TrainInfo.h"
18  #include "util.h"  #include "Util.h"
19  #include "plugins/StatusPlugin.h"  #include "plugins/StatusPlugin.h"
20    #include "plugins/WeatherPlugin.h"
21  #include "SmsPdu.h"  #include "SmsPdu.h"
22    
23  using namespace std;  using namespace std;
# Line 26  void test_sms(ISmsTransceiver& modem, in Line 30  void test_sms(ISmsTransceiver& modem, in
30          string msg = Util::str_formatint(len);          string msg = Util::str_formatint(len);
31          msg.append(1, ' ');          msg.append(1, ' ');
32          msg.append(len - msg.length(), 'a');          msg.append(len - msg.length(), 'a');
33            
34          vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("22337617", msg, true);          vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("22337617", msg, true);
35    
36          for (unsigned int i=0; i<pdu.size(); ++i)          for (unsigned int i=0; i<pdu.size(); ++i)
# Line 42  void test_sms(ISmsTransceiver& modem, in Line 46  void test_sms(ISmsTransceiver& modem, in
46    
47  int main()  int main()
48  {  {
49  /*          /*
50          int shift = 6;                  int shift = 6;
51          string start = "Hej med dig";                  string start = "Hej med dig";
52          string end = SmsPdu::Decode8to7bit(SmsPdu::Encode7to8bit(start,shift), shift );                  string end = SmsPdu::Decode8to7bit(SmsPdu::Encode7to8bit(start,shift), shift );
53    
54                    cout << start << endl;
55                    cout << end << endl;
56                    return 0;
57            */
58    
59          cout << start << endl;          std::vector<TrainInfo>  info = GetTrainInfo( 10 );
         cout << end << endl;  
         return 0;  
 */  
         string start = "hej ������";  
         string mid = str_latin2gsm(start);  
         string final = str_gsm2latin(mid);  
   
         str_dump (start);  
         str_dump(mid);  
         str_dump(final);  
   
   
         return 0;  
60    
61          DebugTransceiver modem(true);          for (unsigned int i=0; i<info.size(); ++i)
         SMS sms;  
         sms.SetSender("1234");  
         sms.SetMessage("status");  
         StatusPlugin status;  
         status.Execute(modem,sms);  
   
         return 0;  
 /*  
     SerialPort port("/dev/ttyS1" );  
     port.Open( SerialPort::BAUD_9600,  
                         SerialPort::CHAR_SIZE_8,  
                         SerialPort::PARITY_NONE,  
                 SerialPort::STOP_BITS_1,  
                 SerialPort::FLOW_CONTROL_HARD );  
   
         ModemTransceiver modem(port);  
         modem.Init();  
   
   
         test_sms(modem, 100);  
         return 0;  
   
   
         vector<SMS> res = modem.ReadSms(true);  
   
         for (unsigned int i = 0; i<res.size(); ++i)  
62          {          {
63                  SMS& sms = res[i];                  TrainInfo ti = info[i];
                 string cmd = GetSmsCommand(sms);  
                 string data = GetSmsData(sms);  
                 cout << "------------------------------" << endl;  
                 cout << "Index    " << sms.sms_index << endl;  
                 cout << "Sender:  " << sms.sender << endl;  
                 cout << "Time:    " << sms.timestamp << endl;  
                 cout << "Message: >" << sms.message << "<" << endl;  
                 cout << "Cmd:     >" << cmd << "<" << endl;  
                 cout << "Data     >" << data << "<" << endl;  
   
                 Util::str_dump(sms.message);  
                 //modem.SendSms(sms.sender, sms.message, false);  
64    
65                    cout << ti.time << ":" <<  ti.update << ":" << ti.destination  << endl;
66          }          }
67    
 */  
68  /*  /*
69          vector<PduInfo> pdu = SmsPdu::CreateSmsPdu("4522337617", "Hej med dig, igen", true);          DebugTransceiver trans(true);
70          cout << "Len: " << pdu[0].len << endl;          WeatherPlugin pl;
         cout << "Pdu: " << pdu[0].pdu << endl;  
71    
         modem.SendSmsPdu(pdu[0].pdu, pdu[0].len);  
 */  
   
                         
   
 /*  
72          SMS sms;          SMS sms;
         sms.sender = "12345678";  
         sms.message = "Tog list";  
         DebugModemTransceiver modem;  
         TogPlugin plugin;  
   
         plugin.Execute(modem, sms);  
   
   
         string msg = Util::str_gsm2latin(modem.GetMessage());  
   
         cout << "---- " << msg.length() << " ----" << endl;  
         cout << msg << endl;  
 */  
 /*  
         vector<TrainInfo> trains = GetTrainInfo("BJ","Bjerringbro");  
73    
74          for (unsigned i=0; i<trains.size(); ++i)          pl.Execute(trans,sms);
         {  
                 TrainInfo& train = trains[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;  
75    
         sms.message = "Test   test2   teste3 test4";  
76    
         cout << "|" << GetSmsCommand(sms) << "|" << GetSmsData(sms) << "|" << endl;  
77    
78          return 0;          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    
         SerialPort port("/dev/ttyS1" );  
         port.Open();  
         ModemTransceiver modem(port);  
   
         //modem.SendSms("22337617", "Hello, sir!");  
         //  
         vector<SMS> res = modem.ReadSms();  
   
   
         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.149  
changed lines
  Added in v.520

  ViewVC Help
Powered by ViewVC 1.1.20