📄 modemgateway.java
字号:
/**
* Sets the SIM PIN 2.
*
* @param mySimPin2
* The SIM PIN 2.
*/
public void setSimPin2(String mySimPin2)
{
this.simPin2 = mySimPin2;
}
/**
* Returns the SIM PIN.
*
* @return The SIM PIN.
*/
public String getSimPin()
{
return this.simPin;
}
/**
* Returns the SIM PIN 2.
*
* @return The SIM PIN 2.
*/
public String getSimPin2()
{
return this.simPin2;
}
public AModemDriver getModemDriver()
{
return this.driver;
}
public AATHandler getATHandler()
{
return this.atHandler;
}
/**
* Returns the Manufacturer string of the modem or phone.
*
* @return The Manufacturer string.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public String getManufacturer() throws TimeoutException, GatewayException, IOException, InterruptedException
{
String response;
synchronized (getDriver().getSYNCCommander())
{
response = getATHandler().getManufacturer();
if (response.indexOf("ERROR") >= 0) return "N/A";
response = response.replaceAll("\\s+OK\\s+", "");
return response;
}
}
/**
* Returns the Model string.
*
* @return The Model string.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public String getModel() throws TimeoutException, GatewayException, IOException, InterruptedException
{
String response;
synchronized (getDriver().getSYNCCommander())
{
response = getATHandler().getModel();
if (response.indexOf("ERROR") >= 0) return "N/A";
response = response.replaceAll("\\s+OK\\s+", "");
return response;
}
}
/**
* Returns the Serial Number of the modem.
*
* @return The Serial Number.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public String getSerialNo() throws TimeoutException, GatewayException, IOException, InterruptedException
{
String response;
synchronized (getDriver().getSYNCCommander())
{
response = getATHandler().getSerialNo();
if (response.indexOf("ERROR") >= 0) return "N/A";
response = response.replaceAll("\\s+OK\\s+", "");
return response;
}
}
/**
* Returns the IMSI (International Mobile Subscriber Identity) number.
* <p>
* This number is stored in the SIM. Since this number may be used for
* several illegal activities, the method is remarked. If you wish to see
* your IMSI, just uncomment the method.
*
* @return The IMSI.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public String getImsi() throws TimeoutException, GatewayException, IOException, InterruptedException
{
if (getService().getSettings().MASK_IMSI) return "** MASKED **";
synchronized (getDriver().getSYNCCommander())
{
String response;
response = getATHandler().getImsi();
if (response.indexOf("ERROR") >= 0) return "N/A";
response = response.replaceAll("\\s+OK\\s+", "");
return response;
}
}
/**
* Returns the modem's firmware version.
*
* @return The modem's firmware version.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public String getSwVersion() throws TimeoutException, GatewayException, IOException, InterruptedException
{
String response;
synchronized (getDriver().getSYNCCommander())
{
response = getATHandler().getSwVersion();
if (response.indexOf("ERROR") >= 0) return "N/A";
response = response.replaceAll("\\s+OK\\s+", "");
return response;
}
}
boolean getGprsStatus() throws TimeoutException, GatewayException, IOException, InterruptedException
{
synchronized (getDriver().getSYNCCommander())
{
return (getATHandler().getGprsStatus().matches("\\+CGATT[\\p{ASCII}]*1\\sOK\\s"));
}
}
/**
* Returns the battery level (0-100).
*
* @return The battery level.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public int getBatteryLevel() throws TimeoutException, GatewayException, IOException, InterruptedException
{
String response;
synchronized (getDriver().getSYNCCommander())
{
response = getATHandler().getBatteryLevel();
if (response.indexOf("ERROR") >= 0) return 0;
Matcher m = Pattern.compile("\\+CBC: (\\d+),\\s*(\\d+)").matcher(response);
if (m.find()) return Integer.parseInt(m.group(2));
return 0;
}
}
/**
* Returns the signal level (0-100). Although the number returned is 0-100,
* the actual signal level is a logarithmic value.
*
* @return The signal level.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public int getSignalLevel() throws TimeoutException, GatewayException, IOException, InterruptedException
{
String response;
StringTokenizer tokens;
synchronized (getDriver().getSYNCCommander())
{
response = getATHandler().getSignalLevel();
if (response.indexOf("ERROR") >= 0) return 0;
response = response.replaceAll("\\s+OK\\s+", "");
tokens = new StringTokenizer(response, ":,");
tokens.nextToken();
return (Integer.parseInt(tokens.nextToken().trim()) * 100 / 31);
}
}
/**
* Returns the SMSC number used by SMSLib. If no SMSC number has been set
* with setSmscNumber() call, this method returns nothing.
*
* @return The SMSC number.
* @see #setSmscNumber(String)
*/
public String getSmscNumber()
{
return this.smscNumber;
}
/**
* Sets the SMSC number used by SMSLib.
* <p>
* Note that in most cases, you will <b>not</b> need to call this method, as
* the modem knows the SMSC it should use by reading the SIM card. In rare
* cases when the modem/phone cannot read the SMSC from the SIM card or you
* would like to set a different SMSC than the default, you can use this
* method.
*
* @param mySmscNumber
* The SMSC number used from now on.
*/
public void setSmscNumber(String mySmscNumber)
{
this.smscNumber = mySmscNumber;
}
/**
* Returns the custom modem init string (if any).
*
* @return the custom init string.
* @see #setCustomInitString(String)
*/
public String getCustomInitString()
{
return this.customInitString;
}
/**
* Sets the custom modem init string. The init string (if defined) is sent
* to the modem right before the SIM PIN check.
*
* @param myCustomInitString
* The custom init string.
* @see #getCustomInitString()
*/
public void setCustomInitString(String myCustomInitString)
{
this.customInitString = myCustomInitString;
}
/**
* Send a custom AT command to the modem and returns the response received.
*
* @param atCommand
* The AT Command.
* @return The modem's response.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
*/
public String sendCustomATCommand(String atCommand) throws GatewayException, TimeoutException, IOException, InterruptedException
{
synchronized (getDriver().getSYNCCommander())
{
return getATHandler().sendCustomATCommand(atCommand);
}
}
protected AModemDriver getDriver()
{
return this.driver;
}
protected void setDriver(AModemDriver myDriver)
{
this.driver = myDriver;
}
protected AATHandler getAtHandler()
{
return this.atHandler;
}
protected void setAtHandler(AATHandler myAtHandler)
{
this.atHandler = myAtHandler;
}
protected String getModemDevice()
{
return this.modemDevice;
}
protected void setModemDevice(String myModemDevice)
{
this.modemDevice = myModemDevice;
}
protected int getModemParms()
{
return this.modemParms;
}
protected void setModemParms(int myModemParms)
{
this.modemParms = myModemParms;
}
public int getQueueSchedulingInterval()
{
return 5000;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -