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

📄 cservice.java

📁 gsm modem 发送短信 闪信 WAP PUSH开发包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			<li>A deleted message cannot be recovered.</li>
			<li>It is highly recommended to use the other form of the deleteMessage()
				method.</li>
		</ul>

		@param	memIndex	the memory index of the GSM device's memory from where
				the message (if there is any message there) should be deleted.
		@throws NotConnectedException
		@see	CService#deleteMessage(CIncomingMessage)
	*/
	public void deleteMessage(int memIndex) throws Exception
	{
		if (getConnected()) atHandler.deleteMessage(memIndex);
		else throw new NotConnectedException();
	}

	/**
		Deletes an SMS message from the GSM device memory.
		<br><br>
		<strong>Notes:</strong>
		<ul>
			<li>A deleted message cannot be recovered.</li>
		</ul>

		@param	message	a valid CIncomingMessage object, i.e. an object which is
				previously read with readMessages() from the GSM device.
		@throws NotConnectedException
		@see	CIncomingMessage
		@see	CService#deleteMessage(int)
	*/
	public void deleteMessage(CIncomingMessage message) throws Exception
	{
		if (message.getMemIndex() > 0) deleteMessage(message.getMemIndex());
		else
		if ((message.getMemIndex() == -1) && (message.getMpMemIndex().length() != 0))
			{
				StringTokenizer tokens = new StringTokenizer(message.getMpMemIndex(), ",");
				while (tokens.hasMoreTokens()) deleteMessage(Integer.parseInt(tokens.nextToken()));
			}
	}

	/**
		Sets the preferred message storage of the GSM device to SIM memory.

		@return  true if the change of preferred message storage succeded.
	*/
	public boolean setStorageSIM() throws Exception
	{
		if (getConnected()) return atHandler.setStorageSIM();
		else throw new NotConnectedException();
	}

	/**
		Sets the preferred message storage of the GSM device to build-in memory.

		@return  true if the change of preferred message storage succeded.
	*/
	public boolean setStorageMEM() throws Exception
	{
		if (getConnected()) return atHandler.setStorageMEM();
		else throw new NotConnectedException();
	}

	/**
		Refreshes the GSM device specific information. This method is called once during
		connection. Its up to the developer to call it periodically in order to get the latest
		information.

		Note: Information about Manufacturer, Model, SerialNo, IMSI, S/W Version are
		refreshed only once, since they don't change during a session.

		@see	CDeviceInfo
		@see	CService#connect()
		@see	CService#getDeviceInfo()
	*/
	public void refreshDeviceInfo() throws Exception
	{
		if (getConnected())
		{
			if (deviceInfo.manufacturer.length() == 0) deviceInfo.manufacturer = getManufacturer();
			if (deviceInfo.model.length() == 0) deviceInfo.model = getModel();
			if (deviceInfo.serialNo.length() == 0) deviceInfo.serialNo = getSerialNo();
			if (deviceInfo.imsi.length() == 0) deviceInfo.imsi = getImsi();
			if (deviceInfo.swVersion.length() == 0) deviceInfo.swVersion = getSwVersion();
			deviceInfo.batteryLevel = getBatteryLevel();
			deviceInfo.signalLevel = getSignalLevel();
		}
		else throw new NotConnectedException();
	}

	private String getManufacturer() throws Exception
	{
		String response;

		response = atHandler.getManufacturer();
		if (response.matches("\\s*[\\p{ASCII}]*\\s+ERROR\\s+")) return VALUE_NOT_REPORTED;
		response = response.replaceAll("\\s+OK\\s+", "");
		response = response.replaceAll("\\s+", "");
		return response;
	}

	private String getModel() throws Exception
	{
		String response;

		response = atHandler.getModel();
		if (response.matches("\\s*[\\p{ASCII}]*\\s+ERROR\\s+")) return VALUE_NOT_REPORTED;
		response = response.replaceAll("\\s+OK\\s+", "");
		response = response.replaceAll("\\s+", "");
		return response;
	}

	private String getSerialNo() throws Exception
	{
		String response;

		response = atHandler.getSerialNo();
		if (response.matches("\\s*[\\p{ASCII}]*\\s+ERROR\\s+")) return VALUE_NOT_REPORTED;
		response = response.replaceAll("\\s+OK\\s+", "");
		response = response.replaceAll("\\s+", "");
		return response;
	}

	private String getImsi() throws Exception
	{
		return "** MASKED **";
//		IMSI is masked on purpose.
//		Uncomment following code for IMSI to be reported.
/*
		String response;

		response = atHandler.getImsi();
		if (response.matches("\\s*[\\p{ASCII}]*\\s+ERROR\\s+")) return VALUE_NOT_REPORTED;
		response = response.replaceAll("\\s+OK\\s+", "");
		response = response.replaceAll("\\s+", "");
		return response;
*/
	}

	private String getSwVersion() throws Exception
	{
		String response;

		response = atHandler.getSwVersion();
		if (response.matches("\\s*[\\p{ASCII}]*\\s+ERROR\\s+")) return VALUE_NOT_REPORTED;
		response = response.replaceAll("\\s+OK\\s+", "");
		response = response.replaceAll("\\s+", "");
		return response;
	}

	private int getBatteryLevel() throws Exception
	{
		String response;
		StringTokenizer tokens;

		response = atHandler.getBatteryLevel();
		if (response.matches("\\s*[\\p{ASCII}]*\\s+ERROR\\s+")) return 0;
		response = response.replaceAll("\\s+OK\\s+", "");
		response = response.replaceAll("\\s+", "");
		tokens = new StringTokenizer(response, ":,");
		tokens.nextToken(); tokens.nextToken();
		return Integer.parseInt(tokens.nextToken());
	}

	private int getSignalLevel() throws Exception
	{
		String response;
		StringTokenizer tokens;

		response = atHandler.getSignalLevel();
		if (response.matches("\\s*[\\p{ASCII}]*\\s+ERROR\\s+")) return 0;
		response = response.replaceAll("\\s+OK\\s+", "");
		response = response.replaceAll("\\s+", "");
		tokens = new StringTokenizer(response, ":,");
		tokens.nextToken();
		return (Integer.parseInt(tokens.nextToken().trim()) * 100 / 31);
	}

	/**
		Checks if the message is SMS-DELIVER.

		@param pdu the message pdu
		@return true if the message is SMS-DELIVER
	*/
	private boolean isIncomingMessage(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;
	}

	/**
		Checks if the message is SMS-STATUS-REPORT.

		@param pdu the message pdu
		@return true if the message is SMS-STATUS-REPORT
	*/
	private boolean isStatusReportMessage(String pdu)
	{
		String str;
		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;
	}

	/**
		Virtual method, called upon receipt of a message (Asynchronous mode only!)
		<br><br>
		<strong>Notes:</strong>
		<ul>
			<li>If you plan to use jSMSEngine API in asynchronous mode, you should
				override this method, making it do your job upon message receipt.</li>
		</ul>

		@param	message the received message.
		@return  return true if you wish the message to be deleted from the GSM device's memory.
					Otherwise false.
		@see	CService#setReceiveMode(int)
	*/
	public @Deprecated boolean received(CIncomingMessage message)
	{
		return false;
	}

	private class CKeepAliveThread extends Thread
	{
		private boolean stopFlag;
		private boolean stopped;

		public CKeepAliveThread()
		{
			stopFlag = false;
			stopped = false;
		}

		public void killMe() { stopFlag = true; }
		public boolean killed() { return stopped; }
		public void run()
		{
			while (!stopFlag)
			{
				try { sleep(KEEP_ALIVE_INTERVAL); } catch (Exception e) {}
				if (stopFlag) break;
				if (getConnected()) try { atHandler.isAlive(); } catch (Exception e) {}
			}
			stopped = true;
		}
	}

	private class CReceiveThread extends Thread
	{
		private boolean stopFlag;
		private boolean stopped;

		public CReceiveThread()
		{
			stopFlag = false;
			stopped = false;
		}

		public void killMe() { stopFlag = true; }
		public boolean killed() { return stopped; }

		public void run()
		{
			LinkedList messageList;

			messageList = new LinkedList();
			while (!stopFlag)
			{
				try { sleep(ASYNC_RECV_INTERVAL); } catch (Exception e) {}
				if (stopFlag) break;
				if ((getConnected()) && (getReceiveMode() == RECEIVE_MODE_ASYNC))
				{
					messageList.clear();
					try
					{
						readMessages(messageList, CIncomingMessage.CLASS_ALL);
						for (int i = 0; i < messageList.size(); i ++)
						{
							CIncomingMessage message = (CIncomingMessage) messageList.get(i);
							if (getMessageHandler() == null)
							{
								if (received(message)) deleteMessage(message);
							}
							else
							{
								if (getMessageHandler() != null && getMessageHandler().received(CService.this, message)) deleteMessage(message);
							}

						}
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
			}
			stopped = true;
		}
	}

	public static void main(String[] args)
	{
		System.out.println("jSMSEngine API.");
		System.out.println("	An open source Java API to process SMS messages from your ");
		System.out.println("	 mobile phone or gsm modem.");
		System.out.println("	This software is distributed under the GPL license.");
		System.out.println("");
		System.out.println("Copyright (C) 2002-2006, Thanasis Delenikas, Athens / GREECE.");
		System.out.println("Visit http://www.jsmsengine.org for latest information.\n");
		System.out.println(_name + " v" + _version + " { " + _reldate + " }");
	}
}

⌨️ 快捷键说明

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