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

📄 epcgscalar.java

📁 关于 RFID 读写器的相关内容
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (C) 2007 ETH Zurich
 *
 * This file is part of Fosstrak (www.fosstrak.org).
 *
 * Fosstrak is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software Foundation.
 *
 * Fosstrak 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 Fosstrak; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package org.fosstrak.reader.rprm.core.mgmt.agent.snmp;

import java.util.Date;

import org.fosstrak.reader.rprm.core.ReaderDevice;
import org.fosstrak.reader.rprm.core.ReaderProtocolException;
import org.fosstrak.reader.rprm.core.mgmt.agent.snmp.mib.EpcglobalReaderMib;
import org.fosstrak.reader.rprm.core.mgmt.agent.snmp.table.SnmpTable;
import org.fosstrak.reader.rprm.core.mgmt.agent.snmp.table.SnmpTable.TableTypeEnum;
import org.fosstrak.reader.rprm.core.mgmt.alarm.AlarmLevel;
import org.fosstrak.reader.rprm.core.mgmt.util.SnmpUtil;
import org.apache.log4j.Logger;
import org.snmp4j.agent.MOAccess;
import org.snmp4j.agent.mo.MOScalar;
import org.snmp4j.smi.Counter32;
import org.snmp4j.smi.Gauge32;
import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.TimeTicks;
import org.snmp4j.smi.UnsignedInteger32;
import org.snmp4j.smi.Variable;

public class EpcgScalar extends MOScalar {
	
	/**
	 * Default value of the refresh time.
	 */
	private long refreshTimeInMs = 100;
	
	/**
	 * The logger.
	 */
	private static Logger log = Logger.getLogger(EpcgScalar.class);
	
	/**
	 * The time stamp of the last refresh.
	 */
	private long lastRefreshTime;
	
	/**
	 * The scalar type.
	 */
	private EpcgScalarType type;
	
	/**
	 * The objects needed by this scalar.
	 */
	private Object[] objects;

	/**
	 * Constructor.
	 * 
	 * @param type
	 *            The scalar type
	 * @param access
	 *            The maximum access level supported by this instance
	 * @param value
	 *            The initial value of the scalar instance. If the initial value
	 *            is null or a Counter syntax, the scalar is created as a
	 *            volatile (non-persistent) instance by default
	 * @param object
	 *            The object needed by this scalar
	 */
	public EpcgScalar(EpcgScalarType type, MOAccess access, Variable value, Object object) {
		super(EpcgScalar.computeOID(type), access, value);
		objects = new Object[] { object };
		this.type = type;
	}
	
	/**
	 * Constructor.
	 * 
	 * @param type
	 *            The scalar type
	 * @param access
	 *            The maximum access level supported by this instance
	 * @param value
	 *            The initial value of the scalar instance. If the initial value
	 *            is null or a Counter syntax, the scalar is created as a
	 *            volatile (non-persistent) instance by default
	 * @param objects
	 *            The objects needed by this scalar
	 */
	public EpcgScalar(EpcgScalarType type, MOAccess access, Variable value, Object[] objects) {
		super(EpcgScalar.computeOID(type), access, value);
		this.objects = objects;
		this.type = type;
	}
	
	/**
	 * Returns the <code>OID</code> for a <code>EpcgScalarType</code>.
	 * 
	 * @param type
	 *            The <code>EpcgScalarType</code>
	 * @return The <code>OID</code> for a <code>EpcgScalarType</code>
	 */
	private static OID computeOID(EpcgScalarType type) {
		switch (type) {
			case EPCG_RDR_DEV_DESCRIPTION:
				return EpcglobalReaderMib.oidEpcgRdrDevDescription;
			case EPCG_RDR_DEV_ROLE:
				return EpcglobalReaderMib.oidEpcgRdrDevRole;
			case EPCG_RDR_DEV_EPC:
				return EpcglobalReaderMib.oidEpcgRdrDevEpc;
			case EPCG_RDR_DEV_SERIAL_NUMBER:
				return EpcglobalReaderMib.oidEpcgRdrDevSerialNumber;
			case EPCG_RDR_DEV_TIME_UTC:
				return EpcglobalReaderMib.oidEpcgRdrDevTimeUtc;
			case EPCG_RDR_DEV_CURRENT_SOURCE:
				return EpcglobalReaderMib.oidEpcgRdrDevCurrentSource;
			case EPCG_RDR_DEV_REBOOT:
				return EpcglobalReaderMib.oidEpcgRdrDevReboot;
			case EPCG_RDR_DEV_RESET_STATISTICS:
				return EpcglobalReaderMib.oidEpcgRdrDevResetStatistics;
			case EPCG_RDR_DEV_RESET_TIMESTAMP:
				return EpcglobalReaderMib.oidEpcgRdrDevResetTimestamp;
			case EPCG_RDR_DEV_NORMALIZE_POWER_LEVEL:
				return EpcglobalReaderMib.oidEpcgRdrDevNormalizePowerLevel;
			case EPCG_RDR_DEV_NORMALIZE_NOISE_LEVEL:
				return EpcglobalReaderMib.oidEpcgRdrDevNormalizeNoiseLevel;
			case EPCG_RDR_DEV_OPER_STATUS:
				return EpcglobalReaderMib.oidEpcgRdrDevOperStatus;
			case EPCG_RDR_DEV_OPER_STATUS_PRIOR:
				return EpcglobalReaderMib.oidTrapVarEpcgRdrDevOperStatusPrior;
			case EPCG_RDR_DEV_OPER_STATE_ENABLE:
				return EpcglobalReaderMib.oidEpcgRdrDevOperStateEnable;
			case EPCG_RDR_DEV_OPER_NOTIF_FROM_STATE:
				return EpcglobalReaderMib.oidEpcgRdrDevOperNotifFromState;
			case EPCG_RDR_DEV_OPER_NOTIF_TO_STATE:
				return EpcglobalReaderMib.oidEpcgRdrDevOperNotifToState;
			case EPCG_RDR_DEV_OPER_NOTIF_STATE_LEVEL:
				return EpcglobalReaderMib.oidEpcgRdrDevOperNotifStateLevel;
			case EPCG_RDR_DEV_OPER_STATE_SUPPRESS_INTERVAL:
				return EpcglobalReaderMib.oidEpcgRdrDevOperStateSuppressInterval;
			case EPCG_RDR_DEV_OPER_STATE_SUPPRESSIONS:
				return EpcglobalReaderMib.oidEpcgRdrDevOperStateSuppressions;
			case EPCG_RDR_DEV_FREE_MEMORY:
				return EpcglobalReaderMib.oidEpcgRdrDevFreeMemory;
			case EPCG_RDR_DEV_FREE_MEMORY_NOTIF_ENABLE:
				return EpcglobalReaderMib.oidEpcgRdrDevFreeMemoryNotifEnable;
			case EPCG_RDR_DEV_FREE_MEMORY_NOTIF_LEVEL:
				return EpcglobalReaderMib.oidEpcgRdrDevFreeMemoryNotifLevel;
			case EPCG_RDR_DEV_FREE_MEMORY_ONSET_THRESHOLD:
				return EpcglobalReaderMib.oidEpcgRdrDevFreeMemoryOnsetThreshold;
			case EPCG_RDR_DEV_FREE_MEMORY_ABATE_THRESHOLD:
				return EpcglobalReaderMib.oidEpcgRdrDevFreeMemoryAbateThreshold;
			case EPCG_RDR_DEV_FREE_MEMORY_STATUS:
				return EpcglobalReaderMib.oidEpcgRdrDevFreeMemoryStatus;
			case EPCG_RDR_DEV_MEM_STATE_SUPPRESS_INTERVAL:
				return EpcglobalReaderMib.oidEpcgRdrDevMemStateSuppressInterval;
			case EPCG_RDR_DEV_MEM_STATE_SUPPRESSIONS:
				return EpcglobalReaderMib.oidEpcgRdrDevMemStateSuppressions;
//			case EPCG_READ_POINT_PRIOR_OPER_STATUS:
//				return EpcglobalReaderMib.oidTrapVarEpcgReadPointPriorOperStatus;
//			case EPCG_READ_POINT_OPER_STATE_SUPPRESS_INTERVAL:
//				return EpcglobalReaderMib.oidEpcgReadPointOperStateSuppressInterval;
//			case EPCG_READ_POINT_OPER_STATE_SUPPRESSIONS:
//				return EpcglobalReaderMib.oidEpcgReadPointOperStateSuppressions;
//			case EPCG_ANT_RD_PNT_SUPPRESS_INTERVAL:
//				return EpcglobalReaderMib.oidEpcgAntRdPntSuppressInterval;
//			case EPCG_IO_PORT_OPER_STATUS_PRIOR:
//				return EpcglobalReaderMib.oidTrapVarEpcgIoPortOperStatusPrior;
//			case EPCG_IO_PORT_OPER_STATE_SUPPRESS_INTERVAL:
//				return EpcglobalReaderMib.oidEpcgIoPortOperStateSuppressInterval;
//			case EPCG_IO_PORT_OPER_STATE_SUPPRESSIONS:
//				return EpcglobalReaderMib.oidEpcgIoPortOperStateSuppressions;
//			case EPCG_SRC_OPER_PRIOR_STATUS:
//				return EpcglobalReaderMib.oidTrapVarEpcgSrcOperStatusPrior;
//			case EPCG_SRC_OPER_STATE_SUPPRESS_INTERVAL:
//				return EpcglobalReaderMib.oidEpcgSrcOperStateSuppressInterval;
//			case EPCG_SRC_OPER_STATE_SUPPRESSIONS:
//				return EpcglobalReaderMib.oidEpcgSrcOperStateSuppressions;
//			case EPCG_NOTIF_CHAN_OPER_STATUS_PRIOR:
//				return EpcglobalReaderMib.oidTrapVarEpcgNotifChanOperStatusPrior;
//			case EPCG_NOTIF_CHAN_OPER_STATE_SUPPRESS_INTERVAL:
//				return EpcglobalReaderMib.oidEpcgNotifChanOperStateSuppressInterval;
//			case EPCG_NOTIF_CHAN_OPER_STATE_SUPPRESSIONS:
//				return EpcglobalReaderMib.oidEpcgNotifChanOperStateSuppressions;
			case SYS_DESCR:
				return new OID(new int[] { 1,3,6,1,2,1,1,1,0 });
			case SYS_LOCATION:
				return new OID(new int[] { 1,3,6,1,2,1,1,6,0 });
			case SYS_CONTACT:
				return new OID(new int[] { 1,3,6,1,2,1,1,4,0 });
			case SYS_UP_TIME:
				return new OID(new int[] { 1,3,6,1,2,1,1,3,0 });
			case SYS_NAME:
				return new OID(new int[] { 1,3,6,1,2,1,1,5,0 });
		}
		return null;
	}

//	/**
//	 * Commits a previously prepared <code>SET</code> (sub)request. This is
//	 * the second phase of a two phase commit. The change is committed but the
//	 * resources locked during prepare not freed yet.
//	 * 
//	 * @param request
//	 *            The <code>SubRequest</code> to process
//	 */
//	@Override
//	public void commit(SubRequest request) {
//		setValue(request.getVariableBinding().getVariable());
//		super.commit(request);
//	}

	/**
	 * Returns the actual value of this scalar managed object.
	 * 
	 * @return A non <code>null</code> <code>Variable</code> with the same
	 *         syntax defined for this scalar object
	 */
	@Override
	public Variable getValue() {
		
		boolean refresh = ((System.currentTimeMillis() - lastRefreshTime) > refreshTimeInMs);
		if (refresh) {
			log.debug("refreshing " + type);
			lastRefreshTime = System.currentTimeMillis();
		} else {
			log.debug("no need to refresh " + type);
		}
		
		if (refresh) {
			
			ReaderDevice readerDevice = null;
			
			switch (type) {
				case EPCG_RDR_DEV_DESCRIPTION:

⌨️ 快捷键说明

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