📄 gsmctl.c
字号:
// *************************************************************************
// * GSM TA/ME library
// *
// * File: gsmctl.cc
// *
// * Purpose: GSM mobile phone control program
// *
// * Author: Peter Hofmann (software@pxh.de)
// *
// * Created: 11.7.1999
// *************************************************************************
#ifdef HAVE_CONFIG_H
#include <gsm_config.h>
#endif
#include <gsmlib/gsm_nls.h>
#include <string>
#if defined(HAVE_GETOPT_LONG) || defined(WIN32)
#include <getopt.h>
#endif
#include <strstream>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <gsmlib/gsm_me_ta.h>
#include <gsmlib/gsm_util.h>
#include <gsmlib/gsm_sysdep.h>
#ifdef WIN32
#include <gsmlib/gsm_win32_serial.h>
#else
#include <gsmlib/gsm_unix_serial.h>
#include <unistd.h>
#endif
#include <iostream>
using namespace std;
using namespace gsmlib;
// my ME
static MeTa *m;
// information parameters
enum InfoParameter {AllInfo, // print all info
MeInfo, // MeInfo must be first!
OperatorInfo,
CurrentOperatorInfo,
FacilityLockStateInfo,
FacilityLockCapabilityInfo,
PasswordInfo,
CLIPInfo,
CallForwardingInfo,
BatteryInfo,
BitErrorInfo,
SCAInfo,
CharSetInfo,
SignalInfo}; // SignalInfo must be last!
// operation parameters
// FIXME operations not implemented yet
// options
#ifdef HAVE_GETOPT_LONG
static struct option longOpts[] =
{
{"xonxoff", no_argument, (int*)NULL, 'X'},
{"operation", required_argument, (int*)NULL, 'o'},
{"device", required_argument, (int*)NULL, 'd'},
{"baudrate", required_argument, (int*)NULL, 'b'},
{"init", required_argument, (int*)NULL, 'I'},
{"help", no_argument, (int*)NULL, 'h'},
{"version", no_argument, (int*)NULL, 'v'},
{(char*)NULL, 0, (int*)NULL, 0}
};
#else
#define getopt_long(argc, argv, options, longopts, indexptr) \
getopt(argc, argv, options)
#endif
// helper function, prints forwarding info
void printForwardReason(string s, ForwardInfo &info)
{
cout << s << " "
<< (info._active ? _("active ") : _("inactive "))
<< _("number: ") << info._number
<< _(" subaddr: ") << info._subAddr
<< _(" time: ") << info._time << endl;
}
// print information
static void printInfo(InfoParameter ip)
{
switch (ip)
{
case MeInfo:
{
MEInfo mei = m->getMEInfo();
cout << _("<ME0> Manufacturer: ") << mei._manufacturer << endl
<< _("<ME1> Model: ") << mei._model << endl
<< _("<ME2> Revision: ") << mei._revision << endl
<< _("<ME3> Serial Number: ") << mei._serialNumber << endl;
break;
}
case OperatorInfo:
{
int count = 0;
vector<OPInfo> opis = m->getAvailableOPInfo();
for (vector<OPInfo>::iterator i = opis.begin(); i != opis.end(); ++i)
{
cout << "<OP" << count << _("> Status: ");
switch (i->_status)
{
case UnknownOPStatus: cout << _("unknown"); break;
case CurrentOPStatus: cout << _("current"); break;
case AvailableOPStatus: cout << _("available"); break;
case ForbiddenOPStatus: cout << _("forbidden"); break;
}
cout << _(" Long name: '") << i->_longName << "' "
<< _(" Short name: '") << i->_shortName << "' "
<< _(" Numeric name: ") << i->_numericName << endl;
++count;
}
break;
}
case CurrentOperatorInfo:
{
OPInfo opi = m->getCurrentOPInfo();
cout << "<CURROP0>"
<< _(" Long name: '") << opi._longName << "' "
<< _(" Short name: '") << opi._shortName << "' "
<< _(" Numeric name: ") << opi._numericName
<< _(" Mode: ");
switch (opi._mode)
{
case AutomaticOPMode: cout << _("automatic"); break;
case ManualOPMode: cout << _("manual"); break;
case DeregisterOPMode: cout << _("deregister"); break;
case ManualAutomaticOPMode: cout << _("manual/automatic"); break;
}
cout << endl;
break;
}
case FacilityLockStateInfo:
{
int count = 0;
vector<string> fclc = m->getFacilityLockCapabilities();
for (vector<string>::iterator i = fclc.begin(); i != fclc.end(); ++i)
if (*i != "AB" && *i != "AG" && *i != "AC")
{
cout << "<FLSTAT" << count << "> '" << *i << "'";
try
{
if (m->getFacilityLockStatus(*i, VoiceFacility))
cout << _(" Voice");
}
catch (GsmException &e)
{
cout << _(" unknown");
}
try
{
if (m->getFacilityLockStatus(*i, DataFacility))
cout << _(" Data");
}
catch (GsmException &e)
{
cout << _(" unknown");
}
try
{
if (m->getFacilityLockStatus(*i, FaxFacility))
cout << _(" Fax");
}
catch (GsmException &e)
{
cout << _(" unknown");
}
cout << endl;
++count;
}
break;
}
case FacilityLockCapabilityInfo:
{
cout << "<FLCAP0> ";
vector<string> fclc = m->getFacilityLockCapabilities();
for (vector<string>::iterator i = fclc.begin(); i != fclc.end(); ++i)
cout << "'" << *i << "' ";
cout << endl;
break;
}
case PasswordInfo:
{
vector<PWInfo> pwi = m->getPasswords();
int count = 0;
for (vector<PWInfo>::iterator i = pwi.begin(); i != pwi.end(); ++i)
{
cout << "<PW" << count << "> '"
<< i->_facility << "' " << i->_maxPasswdLen << endl;
++count;
}
break;
}
case CLIPInfo:
{
cout << "<CLIP0> " << (m->getNetworkCLIP() ? _("on") : _("off")) << endl;
break;
}
case CallForwardingInfo:
{
for (int r = 0; r < 4; ++r)
{
string text;
switch (r)
{
case 0: text = _("UnconditionalReason"); break;
case 1: text = _("MobileBusyReason"); break;
case 2: text = _("NoReplyReason"); break;
case 3: text = _("NotReachableReason"); break;
}
ForwardInfo voice, fax, data;
m->getCallForwardInfo((ForwardReason)r, voice, fax, data);
cout << "<FORW" << r << ".";
printForwardReason("0> " + text + _(" Voice"), voice);
cout << "<FORW" << r << ".";
printForwardReason("1> " + text + _(" Data"), data);
cout << "<FORW" << r << ".";
printForwardReason("2> " + text + _(" Fax"), fax);
}
break;
}
case BatteryInfo:
{
cout << "<BATT0> ";
int bcs = m->getBatteryChargeStatus();
switch (bcs)
{
case 0: cout << _("0 ME is powered by the battery") << endl; break;
case 1: cout << _("1 ME has a battery connected, but is not powered by it")
<< endl; break;
case 2: cout << _("2 ME does not have a battery connected") << endl; break;
case 3:
cout << _("3 Recognized power fault, calls inhibited") << endl;
break;
}
cout << "<BATT1> " << m->getBatteryCharge() << endl;
break;
}
case BitErrorInfo:
{
cout << "<BITERR0> " << m->getBitErrorRate() << endl;
break;
}
case SCAInfo:
{
cout << "<SCA0> " << m->getServiceCentreAddress() << endl;
break;
}
case CharSetInfo:
{
cout << "<CSET0> ";
vector<string> cs = m->getSupportedCharSets();
for (vector<string>::iterator i = cs.begin(); i != cs.end(); ++i)
cout << "'" << *i << "' ";
cout << endl;
cout << "<CSET1> '" << m->getCurrentCharSet() << "'" << endl;
break;
}
case SignalInfo:
{
cout << "<SIG0> " << m->getSignalStrength() << endl;
break;
}
default:
assert(0);
break;
}
}
// convert facility class string of the form "", "all", or any combination
// of "v" (voice), "d" (data), or "f" (fax) to numeric form
FacilityClass strToFacilityClass(string facilityClassS)
{
facilityClassS = lowercase(facilityClassS);
FacilityClass facilityClass = (FacilityClass)0;
if (facilityClassS == "all" || facilityClassS == "")
return (FacilityClass)ALL_FACILITIES;
// OR in facility class bits
for (unsigned int i = 0; i < facilityClassS.length(); ++i)
if (facilityClassS[i] == 'v')
facilityClass = (FacilityClass)(facilityClass | VoiceFacility);
else if (facilityClassS[i] == 'd')
facilityClass = (FacilityClass)(facilityClass | DataFacility);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -