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

Annotation of /smsdaemon/tester.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 141 - (hide annotations) (download)
Sun Dec 7 13:28:52 2008 UTC (15 years, 5 months ago) by torben
File size: 4233 byte(s)
Make a better latin1<->gsm conversion

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

  ViewVC Help
Powered by ViewVC 1.1.20