⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modemgateway.java

📁 基于java开发的一套短信应用框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					{
						logger.error("*****");
						logger.error("Unhandled SMS in inbox, skipping!");
						logger.error("Err: " + e.getMessage());
						logger.error("*****");
					}
					line = reader.readLine().trim();
					while (line.length() == 0)
						line = reader.readLine().trim();
					if ((limit > 0) && (msgList.size() == limit)) break;
				}
				reader.close();
			}
		}
		checkMpMsgList(msgList);
	}

	private void checkMpMsgList(List msgList)
	{
		int k, l, m;
		List tmpList;
		InboundMessage listMsg, mpMsg;
		boolean found;
		mpMsg = null;
		logger.debug("CheckMpMsgList(): MAINLIST: " + mpMsgList.size());
		for (k = 0; k < mpMsgList.size(); k++)
		{
			tmpList = (List) mpMsgList.get(k);
			logger.debug("CheckMpMsgList(): SUBLIST[" + k + "]: " + tmpList.size());
			listMsg = (InboundMessage) 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 = (InboundMessage) tmpList.get(m);
						if (listMsg.getMpSeqNo() == (l + 1))
						{
							if (listMsg.getMpSeqNo() == 1)
							{
								mpMsg = listMsg;
								mpMsg.setMpMemIndex(mpMsg.getMemIndex());
							}
							else
							{
								if (mpMsg != null)
								{
									mpMsg.addText(listMsg.getText());
									mpMsg.setMpSeqNo(listMsg.getMpSeqNo());
									mpMsg.setMpMemIndex(listMsg.getMemIndex());
									if (listMsg.getMpSeqNo() == listMsg.getMpMaxNo())
									{
										mpMsg.setMemIndex(-1);
										msgList.add(mpMsg);
										statistics.inbound++;
										mpMsg = null;
									}
								}
							}
							break;
						}
					}
				tmpList.clear();
				tmpList = null;
			}
			if (found)
			{
				mpMsgList.remove(k);
				k--;
			}
		}
	}

	private boolean isInboundMessage(String pdu)
	{
		int index, i;
		i = Integer.parseInt(pdu.substring(0, 2), 16);
		index = (i + 1) * 2;
		i = Integer.parseInt(pdu.substring(index, index + 2), 16);
		if ((i & 0x03) == 0) return true;
		else return false;
	}

	private boolean isStatusReportMessage(String pdu)
	{
		int index, i;
		i = Integer.parseInt(pdu.substring(0, 2), 16);
		index = (i + 1) * 2;
		i = Integer.parseInt(pdu.substring(index, index + 2), 16);
		if ((i & 0x02) == 2) return true;
		else return false;
	}

	/**
	 * Sets the SIM PIN.
	 * 
	 * @param simPin
	 *            The SIM PIN.
	 */
	public void setSimPin(String simPin)
	{
		this.simPin = simPin;
	}

	/**
	 * Sets the SIM PIN 2.
	 * 
	 * @param simPin
	 *            The SIM PIN 2.
	 */
	public void setSimPin2(String simPin)
	{
		this.simPin2 = simPin;
	}

	/**
	 * Returns the SIM PIN.
	 * 
	 * @return The SIM PIN.
	 */
	public String getSimPin()
	{
		return simPin;
	}

	/**
	 * Returns the SIM PIN 2.
	 * 
	 * @return The SIM PIN 2.
	 */
	public String getSimPin2()
	{
		return simPin2;
	}

	ModemDriver getModemDriver()
	{
		return driver;
	}

	protected AATHandler getATHandler()
	{
		return 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 (driver.SYNC_Commander)
		{
			response = atHandler.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 (driver.SYNC_Commander)
		{
			response = atHandler.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 (driver.SYNC_Commander)
		{
			response = atHandler.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
	{
		// return "** MASKED **";
		// IMSI is masked on purpose.
		// Uncomment following code for IMSI to be reported.
		//
		return "* MASKED *";
		/*
		 * synchronized (driver.SYNC_Commander) { String response; response =
		 * atHandler.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 (driver.SYNC_Commander)
		{
			response = atHandler.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 (driver.SYNC_Commander)
		{
			return (atHandler.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 (driver.SYNC_Commander)
		{
			response = atHandler.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));
			else 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 (driver.SYNC_Commander)
		{
			response = atHandler.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 delay (in milliseconds) that SMSLib will wait when it
	 * encounters CMS errors during the sending of the message.
	 * 
	 * @return The delay (milliseconds)
	 * @see #setDelayCmsErrors(int)
	 * @see #getRetriesCmsErrors()
	 */
	public int getDelayCmsErrors()
	{
		return delayCmsErrors;
	}

	/**
	 * Sets the delay (in milliseconds) that SMSLib will wait when it encounters
	 * CMS errors during the sending of the message.
	 * 
	 * @param delayCmsErrors
	 *            The delay in milliseconds.
	 * @see #getDelayCmsErrors()
	 */
	public void setDelayCmsErrors(int delayCmsErrors)
	{
		this.delayCmsErrors = delayCmsErrors;
	}

	int getDelayNoResponse()
	{
		return delayNoResponse;
	}

	void setDelayNoResponse(int delayNoResponse)
	{
		this.delayNoResponse = delayNoResponse;
	}

	/**
	 * Returns the number of times that SMSLib will retry to send a message when
	 * it encounters CMS errors during its dispatch.
	 * 
	 * @return The number of retries.
	 * @see #setRetriesCmsErrors(int)
	 * @see #getDelayCmsErrors()
	 */
	public int getRetriesCmsErrors()
	{
		return retriesCmsErrors;
	}

	/**
	 * Sets the number of times that SMSLib will retry to send a message when it
	 * encounters CMS errors during its dispatch.
	 * 
	 * @param retriesCmsErrors
	 * @see #getRetriesCmsErrors()
	 */
	public void setRetriesCmsErrors(int retriesCmsErrors)
	{
		this.retriesCmsErrors = retriesCmsErrors;
	}

	int getRetriesNoResponse()
	{
		return retriesNoResponse;
	}

	void setRetriesNoResponse(int retriesNoResponse)
	{
		this.retriesNoResponse = retriesNoResponse;
	}

	/**
	 * 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 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 smscNumber
	 *            The SMSC number used from now on.
	 */
	public void setSmscNumber(String smscNumber)
	{
		this.smscNumber = smscNumber;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -