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

📄 cmessage.java

📁 用JAVA实现串口GSM发信息
💻 JAVA
字号:
//	SMSLib for Java
//	An open-source API Library for sending and receiving SMS via a GSM modem.
//	Copyright (C) 2002-2006, Thanasis Delenikas, Athens/GREECE
//		Web Site: http://www.smslib.org
//
//	SMSLib is distributed under the LGPL license.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

package com;

import java.util.*;

public class CMessage implements java.io.Serializable
{
	public static final int MESSAGE_ENCODING_7BIT = 1;
	public static final int MESSAGE_ENCODING_8BIT = 2;
	public static final int MESSAGE_ENCODING_UNICODE = 3;

	public static final int TYPE_INCOMING = 1;
	public static final int TYPE_OUTGOING = 2;
	public static final int TYPE_STATUS_REPORT = 3;

	public static final int CLASS_ALL = 0;	
	public static final int CLASS_REC_UNREAD = 1;
	public static final int CLASS_REC_READ = 2;
	public static final int CLASS_STO_UNSENT = 3;
	public static final int CLASS_STO_SENT = 4;

	private int type;
	protected String id;
	protected int refNo;
	protected int memIndex;
	protected Date date;
	protected Date dispatchDate;
	protected String originator;
	protected String recipient;
	protected String text;
	protected int messageEncoding;

	protected Date dateOriginal;
	protected Date dateReceived;

	protected int mpRefNo;
	protected int mpMaxNo;
	protected int mpSeqNo;
	protected String mpMemIndex;

	protected int validityPeriod;
	protected boolean statusReport;
	protected boolean flashSms;

	protected int srcPort;
	protected int dstPort;

	public CMessage(int type, Date date, String originator, String recipient, String text, int memIndex)
	{
		this.type = type;
		this.id = null;
		this.refNo = -1;
		this.memIndex = memIndex;
		this.date = date;
		this.originator = originator;
		this.recipient = recipient;
		this.text = text;
		this.messageEncoding = MESSAGE_ENCODING_7BIT;

		dispatchDate = null;
		dateOriginal = null;
		dateReceived = null;

		mpRefNo = 0;
		mpMaxNo = 0;
		mpSeqNo = 0;
		mpMemIndex = "";

		validityPeriod = -1;
		statusReport = false;
		flashSms = false;
		srcPort = -1;
		dstPort = -1;
	}

	public int getType() { return type; }
	public String getId() { return id; }
	public int getRefNo() { return refNo; }
	public int getMemIndex() { return memIndex; }
	public Date getDate() { return date; }
	public String getOriginator() { return originator; }
	public String getRecipient() { return recipient; }
	public String getText() { return text; }
	public Date getDispatchDate() { return dispatchDate; }
	public Date getDateOriginal() { return dateOriginal; } 
 	public Date getDateReceived() { return dateReceived; }
	public int getMessageEncoding() { return messageEncoding; }
	public int getMpRefNo() { return mpRefNo; }
	public int getMpMaxNo() { return mpMaxNo; }
	public int getMpSeqNo() { return mpSeqNo; }
	public String getMpMemIndex() { return mpMemIndex; }
	public int getValidityPeriod() { return validityPeriod; }
	public boolean getStatusReport() { return statusReport; }
	public boolean getFlashSms() { return flashSms; }
	public int getSourcePort() { return srcPort; }
	public int getDestinationPort() { return dstPort; }

	public void setId(String id) { this.id = id; }
	public void setRefNo(int refNo) { this.refNo = refNo; }
	public void setText(String text) { this.text = text; }
	public void addText(String text) { this.text += text; }
	public void setDate(Date date) { this.date = date; }
	public void setDispatchDate(Date date) { this.dispatchDate = date; }
	public void setRecipient(String recipient) { this.recipient = recipient; }
	public void setMessageEncoding(int messageEncoding) { this.messageEncoding = messageEncoding; }
	public void setValidityPeriod(int hours) { this.validityPeriod = hours; }
	public void setStatusReport(boolean statusReport) { this.statusReport = statusReport; }
	public void setFlashSms(boolean flashSms) { this.flashSms = flashSms; }
	public void setSourcePort(int port) { this.srcPort = port; }
	public void setDestinationPort(int port) { this.dstPort = port; }

	protected void setMpRefNo(int mpRefNo) { this.mpRefNo = mpRefNo; }
	protected void setMpSeqNo(int mpSeqNo) { this.mpSeqNo = mpSeqNo; }
	protected void setMemIndex(int memIndex) { this.memIndex = memIndex; }
	protected void setMpMemIndex(int memIndex) { this.mpMemIndex += (mpMemIndex.length() == 0 ? "" : ",") + memIndex; }

	public String toString()
	{
		String str;

		str = "** GSM MESSAGE **\n";
		str += "  Type: " + (type == TYPE_INCOMING ? "Incoming" : (type == TYPE_OUTGOING ? "Outgoing" : "Status Report")) + "\n";
		if (type == TYPE_INCOMING) str += "  RefNo: " + mpRefNo + " / MaxNo: " + mpMaxNo + " / SeqNo: " + mpSeqNo + "\n";
		str += "  Id: " + id + "\n";
		str += "  SMSC Ref No: " + refNo + "\n";
		str += "  Memory Index: " + memIndex + "\n";
		str += "  MP Memory Index: " + mpMemIndex + "\n";
		str += "  Date: " + date + "\n";
		str += "  Originator: " + originator + "\n";
		str += "  Recipient: " + recipient + "\n";
		str += "  Text: " + text + "\n";
		str += "  Encoding: ";
		switch (messageEncoding)
		{
			case MESSAGE_ENCODING_7BIT:
				str += "7-Bit\n";
				break;
			case MESSAGE_ENCODING_8BIT:
				str += "8-Bit\n";
				break;
			case MESSAGE_ENCODING_UNICODE:
				str += "Unicode\n";
				break;
		}
		if (type == TYPE_OUTGOING)
		{
			str += "  Dispatch Date: " + dispatchDate + "\n";
			str += "  Validity Period (hours): " + validityPeriod + "\n";
			str += "  Source Port: " + srcPort + "\n";
			str += "  Destination Port: " + dstPort + "\n";
			str += "  Flash SMS: " + flashSms + "\n";
		}
		if (type == TYPE_STATUS_REPORT)
		{
			str += "  Status Report extra information:\n";
			str += "    Reference No: " + refNo + "\n";
			str += "    Original Sent Date: " + dateOriginal + "\n";
			str += "    Date Received by Recipient: " + dateReceived + "\n";
		}
		str += "***\n";
		System.out.println("~="+str);
		return str;
	}
}

⌨️ 快捷键说明

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