📄 modemgateway.java
字号:
if (listMsg.getMpRefNo() == msg.getMpRefNo())
{
duplicate = false;
// check if the message is already in the message list
for (l = 0; l < tmpList.size(); l++)
{
listMsg = tmpList.get(l);
if (listMsg.getMpSeqNo() == msg.getMpSeqNo())
{
duplicate = true;
break;
}
}
if (!duplicate) tmpList.add(msg);
found = true;
break;
}
}
if (!found)
{
// no existing list present for this message
// add one
tmpList = new ArrayList<InboundMessage>();
tmpList.add(msg);
this.mpMsgList.add(tmpList);
}
}
}
else if (pdu instanceof SmsStatusReportPdu)
{
StatusReportMessage msg;
msg = new StatusReportMessage((SmsStatusReportPdu) pdu, memIndex, getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2));
msg.setGatewayId(getGatewayId());
msgList.add(msg);
incInboundMessageCount();
}
else
{
// this theoretically will never happen
// but is here for completeness
throw new RuntimeException();
}
}
catch (Exception e)
{
// PduFactory will give an exception
// for PDUs it can't understand
UnknownMessage msg;
msg = new UnknownMessage(pduString, memIndex, getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2));
msg.setGatewayId(getGatewayId());
msgList.add(msg);
incInboundMessageCount();
getService().getLogger().logError("Unhandled SMS in inbox, skipping...", e, getGatewayId());
getService().getLogger().logError("ERROR PDU: " + pduString, null, getGatewayId());
}
line = reader.readLine().trim();
while (line.length() == 0)
line = reader.readLine().trim();
if ((limit > 0) && (msgList.size() == limit)) break;
}
reader.close();
}
}
checkMpMsgList(msgList);
}
public String getMessageByIndex(int msgIndex) throws TimeoutException, GatewayException, IOException, InterruptedException
{
synchronized (this.driver.SYNC_Commander)
{
return getATHandler().getMessageByIndex(msgIndex);
}
}
private void checkMpMsgList(Collection<InboundMessage> msgList)
{
int k, l, m;
List<InboundMessage> tmpList;
InboundMessage listMsg, mpMsg;
boolean found;
mpMsg = null;
getService().getLogger().logDebug("CheckMpMsgList(): MAINLIST: " + this.mpMsgList.size(), null, getGatewayId());
for (k = 0; k < this.mpMsgList.size(); k++)
{
tmpList = this.mpMsgList.get(k);
getService().getLogger().logDebug("CheckMpMsgList(): SUBLIST[" + k + "]: " + tmpList.size(), null, getGatewayId());
listMsg = tmpList.get(0);
found = false;
if (listMsg.getMpMaxNo() == tmpList.size())
{
found = true;
for (l = 0; l < tmpList.size(); l++)
for (m = 0; m < tmpList.size(); m++)
{
listMsg = tmpList.get(m);
if (listMsg.getMpSeqNo() == (l + 1))
{
if (listMsg.getMpSeqNo() == 1)
{
mpMsg = listMsg;
mpMsg.setMpMemIndex(mpMsg.getMemIndex());
}
else
{
if (mpMsg != null)
{
if (mpMsg instanceof InboundBinaryMessage)
{
InboundBinaryMessage mpMsgBinary = (InboundBinaryMessage) mpMsg;
InboundBinaryMessage listMsgBinary = (InboundBinaryMessage) listMsg;
mpMsgBinary.addDataBytes(listMsgBinary.getDataBytes());
}
else
{
try
{
mpMsg.addText(listMsg.getText());
}
catch (UnsupportedEncodingException e)
{
// TODO: What to do with this?
}
}
mpMsg.setMpSeqNo(listMsg.getMpSeqNo());
mpMsg.setMpMemIndex(listMsg.getMemIndex());
if (listMsg.getMpSeqNo() == listMsg.getMpMaxNo())
{
mpMsg.setMemIndex(-1);
msgList.add(mpMsg);
incInboundMessageCount();
mpMsg = null;
}
}
}
break;
}
}
tmpList.clear();
tmpList = null;
}
if (found)
{
this.mpMsgList.remove(k);
k--;
}
}
}
/**
* Sets the SIM PIN.
*
* @param mySimPin
* The SIM PIN.
*/
public void setSimPin(String mySimPin)
{
this.simPin = mySimPin;
}
/**
* 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;
}
protected 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 (this.driver.SYNC_Commander)
{
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 (this.driver.SYNC_Commander)
{
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 (this.driver.SYNC_Commander)
{
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().S.MASK_IMSI) return "** MASKED **";
synchronized (this.driver.SYNC_Commander)
{
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 (this.driver.SYNC_Commander)
{
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 (this.driver.SYNC_Commander)
{
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 (this.driver.SYNC_Commander)
{
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 (this.driver.SYNC_Commander)
{
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -