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

Diff of /smsdaemon/tester.cpp

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

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

Legend:
Removed from v.78  
changed lines
  Added in v.1011

  ViewVC Help
Powered by ViewVC 1.1.20