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

📄 modemgateway.java

📁 华为编程开发规范与案例, 华为编程开发规范与案例,华为编程开发规范与案例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}

	private void readMessagesPDU(LinkedList<InboundMessage> msgList, InboundMessage.MessageClass messageClass, int limit) throws Exception
	{
		int i, j, memIndex;
		String response, line, pdu;
		BufferedReader reader;
		InboundMessage mpMsg;

		if (limit < 0) limit = 0;
		mpMsg = null;
		atHandler.switchToCmdMode();
		for (int ml = 0; ml < (atHandler.getStorageLocations().length() / 2); ml++)
		{
			if (atHandler.setMemoryLocation(atHandler.getStorageLocations().substring((ml * 2), (ml * 2) + 2)))
			{
				response = atHandler.listMessages(messageClass);
				response = response.replaceAll("\\s+OK\\s+", "\nOK");
				reader = new BufferedReader(new StringReader(response));
				for (;;)
				{
					line = reader.readLine().trim();
					if (line == null) break;
					line = line.trim();
					if (line.length() > 0) break;
				}
				while (true)
				{
					if (line == null) break;
					line = line.trim();
					if (line.length() <= 0 || line.equalsIgnoreCase("OK")) break;
					i = line.indexOf(':');
					j = line.indexOf(',');
					memIndex = Integer.parseInt(line.substring(i + 1, j).trim());
					pdu = reader.readLine().trim();
					try
					{
						if (isInboundMessage(pdu))
						{
							InboundMessage msg;

							msg = new InboundMessage(pdu, memIndex, atHandler.getStorageLocations().substring((ml * 2), (ml * 2) + 2));
							msg.setGatewayId(gatewayId);
							logger.debug("IN-DTLS: MI:" + msg.getMemIndex() + " REF:" + msg.getMpRefNo() + " MAX:" + msg.getMpMaxNo() + " SEQ:" + msg.getMpSeqNo());
							if (msg.getMpRefNo() == 0)
							{
								if (mpMsg != null) mpMsg = null;
								msgList.add(msg);
								statistics.inbound ++;
							}
							else
							{
								int k, l;
								LinkedList<InboundMessage> tmpList;
								InboundMessage listMsg;
								boolean found, duplicate;

								found = false;
								for (k = 0; k < mpMsgList.size(); k++)
								{
									tmpList = mpMsgList.get(k);
									listMsg = tmpList.get(0);
									if (listMsg.getMpRefNo() == msg.getMpRefNo())
									{
										duplicate = false;
										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)
								{
									tmpList = new LinkedList<InboundMessage>();
									tmpList.add(msg);
									mpMsgList.add(tmpList);
								}
							}
						}
						else if (isStatusReportMessage(pdu))
						{
							StatusReportMessage msg;

							msg = new StatusReportMessage(pdu, memIndex, atHandler.getStorageLocations().substring((ml * 2), (ml * 2) + 2));
							msg.setGatewayId(gatewayId);
							msgList.add(msg);
							statistics.inbound ++;
						}
					}
					catch (Exception e)
					{
						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(LinkedList<InboundMessage> msgList)
	{
		int k, l, m;
		LinkedList tmpList;
		InboundMessage listMsg, mpMsg;
		boolean found;

		mpMsg = null;
		logger.debug("CheckMpMsgList(): MAINLIST: " + mpMsgList.size());
		for (k = 0; k < mpMsgList.size(); k++)
		{
			tmpList = (LinkedList) 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;
	}

	public void setSimPin(String simPin)
	{
		this.simPin = simPin;
	}

	public String getSimPin()
	{
		return simPin;
	}

	public ModemDriver getModemDriver()
	{
		return driver;
	}

	protected AbstractATHandler getATHandler()
	{
		return atHandler;
	}

	public String getManufacturer() throws Exception
	{
		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;
		}
	}

	public String getModel() throws Exception
	{
		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;
		}
	}

	public String getSerialNo() throws Exception
	{
		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;
		}
	}

	public String getImsi() throws Exception
	{
		// 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; }
		 */
	}

	public String getSwVersion() throws Exception
	{
		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;
		}
	}

	public boolean getGprsStatus() throws Exception
	{
		synchronized (driver.SYNC_Commander)
		{
			return (atHandler.getGprsStatus().matches("\\+CGATT[\\p{ASCII}]*1\\sOK\\s"));
		}
	}

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

		synchronized (driver.SYNC_Commander)
		{
			response = atHandler.getBatteryLevel();
			if (response.indexOf("ERROR") >= 0) return 0;
			response = response.replaceAll("\\s+OK\\s+", "");
			tokens = new StringTokenizer(response, ":,");
			tokens.nextToken();
			tokens.nextToken();
			return Integer.parseInt(tokens.nextToken());
		}
	}

	public int getSignalLevel() throws Exception
	{
		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);
		}
	}

	public int getDelayCmsErrors()
	{
		return delayCmsErrors;
	}

	public void setDelayCmsErrors(int delayCmsErrors)
	{
		this.delayCmsErrors = delayCmsErrors;
	}

	public int getDelayNoResponse()
	{
		return delayNoResponse;
	}

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

	public int getRetriesCmsErrors()
	{
		return retriesCmsErrors;
	}

	public void setRetriesCmsErrors(int retriesCmsErrors)
	{
		this.retriesCmsErrors = retriesCmsErrors;
	}

	public int getRetriesNoResponse()
	{
		return retriesNoResponse;
	}

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

	public String getSmscNumber()
	{
		return smscNumber;
	}

	public void setSmscNumber(String smscNumber)
	{
		this.smscNumber = smscNumber;
	}
}

⌨️ 快捷键说明

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