Debian Codegraph @

tests/testgsmlib.cc

raw symbols SCIP
1 // *************************************************************************
2 // * GSM TA/ME library
3 // *
4 // * File: testgsmlib.cc
5 // *
6 // * Purpose: Test general gsm functions (without SMS/phonebook)
7 // *
8 // * Author: Peter Hofmann ([email protected])
9 // *
10 // * Created: 17.5.1999
11 // *************************************************************************
12 #ifdef HAVE_CONFIG_H
13 #include <gsm_config.h>
14 #endif
15 #ifdef WIN32
16 #include <gsmlib/gsm_win32_serial.h>
17 #else
18 #include <gsmlib/gsm_unix_serial.h>
19 #endif
20 #include <gsmlib/gsm_me_ta.h>
21 #include <iostream>
22
23 using namespace std;
24 using namespace gsmlib;
25
26 // some time-consuming tests can be switched off by commenting out the
27 // following macros
28 #define TEST_OPERATOR_INFO
29
30 void printForwardReason(string s, ForwardInfo &info)
31 {
32 cout << " " << s << ": "
33 << (info._active ? "active " : "inactive ")
34 << "number: " << info._number
35 << " subaddr: " << info._subAddr
36 << " time: " << info._time << endl;
37 }
38
39 int main(int argc, char *argv[])
40 {
41 try
42 {
43 cout << (string)"Opening device " + argv[1] << endl;
44 #ifdef WIN32
45 Ref<Port> port = new Win32SerialPort((string)argv[1], 38400);
46 #else
47 Ref<Port> port = new UnixSerialPort((string)argv[1], B38400);
48 #endif
49
50 cout << "Creating MeTa object" << endl;
51 MeTa m(port);
52
53 cout << "Getting ME info" << endl;
54 MEInfo mei = m.getMEInfo();
55
56 cout << " Manufacturer: " << mei._manufacturer << endl
57 << " Model: " << mei._model << endl
58 << " Revision: " << mei._revision << endl
59 << " Serial Number: " << mei._serialNumber << endl << endl;
60
61 #ifdef TEST_OPERATOR_INFO
62 try
63 {
64 cout << "Getting operator info" << endl;
65 vector<OPInfo> opis = m.getAvailableOPInfo();
66 for (vector<OPInfo>::iterator i = opis.begin(); i != opis.end(); ++i)
67 {
68 cout << " Status: ";
69 switch (i->_status)
70 {
71 case 0: cout << "unknown"; break;
72 case 1: cout << "current"; break;
73 case 2: cout << "available"; break;
74 case 3: cout << "forbidden"; break;
75 }
76 cout << endl
77 << " Long name: '" << i->_longName << "' "
78 << " Short name: '" << i->_shortName << "' "
79 << " Numeric name: " << i->_numericName << endl;
80 }
81 }
82 catch (GsmException &ge)
83 {
84 if (ge.getErrorCode() == 0)
85 cout << "phone failure ignored" << endl;
86 else
87 throw;
88 }
89 cout << endl;
90 #endif // TEST_OPERATOR_INFO
91
92 cout << "Current operator info" << endl;
93 OPInfo opi = m.getCurrentOPInfo();
94 cout << " Long name: '" << opi._longName << "' "
95 << " Short name: '" << opi._shortName << "' "
96 << " Numeric name: " << opi._numericName << endl
97 << " Mode: ";
98 switch (opi._mode)
99 {
100 case 0: cout << "automatic"; break;
101 case 1: cout << "manual"; break;
102 case 2: cout << "deregister"; break;
103 case 4: cout << "manual/automatic"; break;
104 }
105 cout << endl;
106
107 cout << "Facility lock capabilities" << endl << " ";
108 vector<string> fclc = m.getFacilityLockCapabilities();
109 for (vector<string>::iterator i = fclc.begin(); i != fclc.end(); ++i)
110 cout << *i << " ";
111 cout << endl << endl;
112
113 cout << "Facility lock states" << endl;
114 for (vector<string>::iterator k = fclc.begin(); k != fclc.end(); ++k)
115 if (*k != "AB" && *k != "AG" && *k != "AC")
116 {
117 cout << " " << *k;
118 if (m.getFacilityLockStatus(*k, VoiceFacility))
119 cout << " Voice";
120 if (m.getFacilityLockStatus(*k, DataFacility))
121 cout << " Data";
122 if (m.getFacilityLockStatus(*k, FaxFacility))
123 cout << " Fax";
124 }
125 cout << endl;
126
127 cout << "Facilities with password" << endl;
128 vector<PWInfo> pwi = m.getPasswords();
129 for (vector<PWInfo>::iterator j = pwi.begin(); j != pwi.end(); ++j)
130 cout << " " << j->_facility << " len " << j->_maxPasswdLen << endl;
131 cout << endl;
132
133 cout << "Network caller line identification identification: "
134 << (m.getNetworkCLIP() ? "on" : "off") << endl << endl;
135
136 cout << "Call forwarding information" << endl;
137 for (int r = 0; r < 4; ++r)
138 {
139 switch (r)
140 {
141 case 0: cout << "UnconditionalReason" << endl; break;
142 case 1: cout << "MobileBusyReason" << endl; break;
143 case 2: cout << "NoReplyReason" << endl; break;
144 case 3: cout << "NotReachableReason" << endl; break;
145 }
146 ForwardInfo voice, fax, data;
147 m.getCallForwardInfo((ForwardReason)r, voice, fax, data);
148 printForwardReason("Voice", voice);
149 printForwardReason("Data", data);
150 printForwardReason("Fax", fax);
151 }
152 cout << endl;
153
154 cout << "Battery charge status" << endl;
155 int bcs = m.getBatteryChargeStatus();
156 switch (bcs)
157 {
158 case 0: cout << "ME is powered by the battery" << endl; break;
159 case 1: cout << "ME has a battery connected, but is not powered by it"
160 << endl; break;
161 case 2: cout << "ME does not have a battery connected" << endl; break;
162 case 3: cout << "Recognized power fault, calls inhibited" << endl; break;
163 }
164 cout << endl;
165
166 cout << "Battery charge: " << m.getBatteryCharge() << endl << endl;
167
168 cout << "Signal strength: " << m.getSignalStrength() << endl << endl;
169
170 cout << "Bit error rate: " << m.getBitErrorRate() << endl << endl;
171 }
172 catch (GsmException &ge)
173 {
174 cerr << "GsmException '" << ge.what() << "'" << endl;
175 return 1;
176 }
177 return 0;
178 }