/* * * This file was generated by LLRP Code Generator * see http://llrp-toolkit.cvs.sourceforge.net/llrp-toolkit * for more information * Generated on: Mon Mar 10 14:26:48 KST 2014; * */ /* * Copyright 2007 ETH Zurich * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions * and limitations under the License. * */ package kr.ac.kaist.resl.ltk.generated.parameters; import org.apache.log4j.Logger; import org.jdom.Content; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.llrp.ltk.exceptions.InvalidLLRPMessageException; import org.llrp.ltk.exceptions.MissingParameterException; import kr.ac.kaist.resl.ltk.generated.LLRPConstants; import kr.ac.kaist.resl.ltk.generated.parameters.C1G2TagInventoryStateAwareSingulationAction; import org.llrp.ltk.types.BitList; import org.llrp.ltk.types.LLRPBitList; import org.llrp.ltk.types.LLRPMessage; import org.llrp.ltk.types.SignedShort; import org.llrp.ltk.types.TLVParameter; import org.llrp.ltk.types.TVParameter; import org.llrp.ltk.types.TwoBitField; import org.llrp.ltk.types.UnsignedInteger; import org.llrp.ltk.types.UnsignedShort; import java.util.LinkedList; import java.util.List; /** * This C1G2SingulationControl Parameter provides controls particular to the singulation process in the C1G2 air protocol. The singulation process is started using a Query command in the C1G2 protocol. The Query command describes the session number, tag state, the start Q value to use, and the RF link parameters. The RF link parameters are specified using the C1G2RFControl Parameter (see section 15.2.1.2.1.2). This Singulation Parameter specifies the session, tag state and description of the target singulation environment. The following attributes are specified to provide guidance to the Reader for the singulation algorithm:Tag transit time: This is the measure of expected tag mobility in the field of view of the antenna where this inventory operation is getting executed.Tag population: This is the expected tag population in the field of view of the antenna. In addition, the Singulation Parameter allows setting of the following:Session ID: This is the C1G2 session number that the tags use to update the inventory state upon successful singulation.TagInventoryStateAwareSingulationAction: This is used if the TagInventoryStateAware flag is set to true in the InventoryParameterSpec. I: This is the inventoried state of the target tag population in the selected session. Only tags that match the session state participate in the inventory round. If the Ignore value is specified, the Reader ignores this field, and its up to the Reader implementation to determine the value of I used in the inventory round. S: This is the state of the SL flag in the tag. Only tags that match that tag state participate in the inventory round. If the Ignore value is specified, the Reader ignores this field, and its up to the Reader implementation to determine the value of S used in the inventory round. If a reader sets CanDoTagInventoryStateAwareSingulation to False in LLRPCapabilities (section 9.2.2), it SHALL ignore the TagInventoryStateAwareSingulationAction field. See also {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=104&view=fit">LLRP Specification Section 15.2.1.2.1.3</a>} and {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=155&view=fit">LLRP Specification Section 16.3.1.2.1.3</a>} */ /** * This C1G2SingulationControl Parameter provides controls particular to the singulation process in the C1G2 air protocol. The singulation process is started using a Query command in the C1G2 protocol. The Query command describes the session number, tag state, the start Q value to use, and the RF link parameters. The RF link parameters are specified using the C1G2RFControl Parameter (see section 15.2.1.2.1.2). This Singulation Parameter specifies the session, tag state and description of the target singulation environment. The following attributes are specified to provide guidance to the Reader for the singulation algorithm:Tag transit time: This is the measure of expected tag mobility in the field of view of the antenna where this inventory operation is getting executed.Tag population: This is the expected tag population in the field of view of the antenna. In addition, the Singulation Parameter allows setting of the following:Session ID: This is the C1G2 session number that the tags use to update the inventory state upon successful singulation.TagInventoryStateAwareSingulationAction: This is used if the TagInventoryStateAware flag is set to true in the InventoryParameterSpec. I: This is the inventoried state of the target tag population in the selected session. Only tags that match the session state participate in the inventory round. If the Ignore value is specified, the Reader ignores this field, and its up to the Reader implementation to determine the value of I used in the inventory round. S: This is the state of the SL flag in the tag. Only tags that match that tag state participate in the inventory round. If the Ignore value is specified, the Reader ignores this field, and its up to the Reader implementation to determine the value of S used in the inventory round. If a reader sets CanDoTagInventoryStateAwareSingulation to False in LLRPCapabilities (section 9.2.2), it SHALL ignore the TagInventoryStateAwareSingulationAction field. See also {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=104&view=fit">LLRP Specification Section 15.2.1.2.1.3</a>} and {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=155&view=fit">LLRP Specification Section 16.3.1.2.1.3</a>} . */ public class C1G2SingulationControl extends TLVParameter { public static final SignedShort TYPENUM = new SignedShort(336); private static final Logger LOGGER = Logger.getLogger(C1G2SingulationControl.class); protected TwoBitField session; protected BitList reserved0 = new BitList(6); protected UnsignedShort tagPopulation; protected UnsignedInteger tagTransitTime; protected C1G2TagInventoryStateAwareSingulationAction c1G2TagInventoryStateAwareSingulationAction; /** * empty constructor to create new parameter. */ public C1G2SingulationControl() { } /** * Constructor to create parameter from binary encoded parameter * calls decodeBinary to decode parameter. * @param list to be decoded */ public C1G2SingulationControl(LLRPBitList list) { decodeBinary(list); } /** * Constructor to create parameter from xml encoded parameter * calls decodeXML to decode parameter. * @param element to be decoded */ public C1G2SingulationControl(Element element) throws InvalidLLRPMessageException { decodeXML(element); } /** * {@inheritDoc} */ public LLRPBitList encodeBinarySpecific() { LLRPBitList resultBits = new LLRPBitList(); if (session == null) { LOGGER.warn(" session not set"); throw new MissingParameterException( " session not set for Parameter of Type C1G2SingulationControl"); } resultBits.append(session.encodeBinary()); resultBits.append(reserved0.encodeBinary()); if (tagPopulation == null) { LOGGER.warn(" tagPopulation not set"); throw new MissingParameterException( " tagPopulation not set for Parameter of Type C1G2SingulationControl"); } resultBits.append(tagPopulation.encodeBinary()); if (tagTransitTime == null) { LOGGER.warn(" tagTransitTime not set"); throw new MissingParameterException( " tagTransitTime not set for Parameter of Type C1G2SingulationControl"); } resultBits.append(tagTransitTime.encodeBinary()); if (c1G2TagInventoryStateAwareSingulationAction == null) { // optional parameter, may be null LOGGER.info(" c1G2TagInventoryStateAwareSingulationAction not set"); } else { resultBits.append(c1G2TagInventoryStateAwareSingulationAction.encodeBinary()); } return resultBits; } /** * {@inheritDoc} */ public Content encodeXML(String name, Namespace ns) { // element in namespace defined by parent element Element element = new Element(name, ns); // child element are always in default LLRP namespace ns = Namespace.getNamespace("llrp", LLRPConstants.LLRPNAMESPACE); if (session == null) { LOGGER.warn(" session not set"); throw new MissingParameterException(" session not set"); } else { element.addContent(session.encodeXML("Session", ns)); } //element.addContent(reserved0.encodeXML("reserved",ns)); if (tagPopulation == null) { LOGGER.warn(" tagPopulation not set"); throw new MissingParameterException(" tagPopulation not set"); } else { element.addContent(tagPopulation.encodeXML("TagPopulation", ns)); } if (tagTransitTime == null) { LOGGER.warn(" tagTransitTime not set"); throw new MissingParameterException(" tagTransitTime not set"); } else { element.addContent(tagTransitTime.encodeXML("TagTransitTime", ns)); } //parameters if (c1G2TagInventoryStateAwareSingulationAction == null) { LOGGER.info("c1G2TagInventoryStateAwareSingulationAction not set"); } else { element.addContent(c1G2TagInventoryStateAwareSingulationAction.encodeXML( c1G2TagInventoryStateAwareSingulationAction.getClass() .getSimpleName(), ns)); } return element; } /** * {@inheritDoc} */ protected void decodeBinarySpecific(LLRPBitList binary) { int position = 0; int tempByteLength; int tempLength = 0; int count; SignedShort type; int fieldCount; Custom custom; session = new TwoBitField(binary.subList(position, TwoBitField.length())); position += TwoBitField.length(); position += reserved0.length(); tagPopulation = new UnsignedShort(binary.subList(position, UnsignedShort.length())); position += UnsignedShort.length(); tagTransitTime = new UnsignedInteger(binary.subList(position, UnsignedInteger.length())); position += UnsignedInteger.length(); // look ahead to see type // may be optional or exactly once type = null; tempByteLength = 0; tempLength = 0; try { // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } } catch (IllegalArgumentException le) { // if an IllegalArgumentException is thrown, list was not long enough so the parameter is missing LOGGER.info( "C1G2SingulationControl misses optional parameter of type C1G2TagInventoryStateAwareSingulationAction"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = c1G2TagInventoryStateAwareSingulationAction.length(); } if ((type != null) && type.equals(C1G2TagInventoryStateAwareSingulationAction.TYPENUM)) { c1G2TagInventoryStateAwareSingulationAction = new C1G2TagInventoryStateAwareSingulationAction(binary.subList( position, tempLength)); position += tempLength; LOGGER.debug( " c1G2TagInventoryStateAwareSingulationAction is instantiated with C1G2TagInventoryStateAwareSingulationAction with length" + tempLength); } else { LOGGER.info( "C1G2SingulationControl misses optional parameter of type C1G2TagInventoryStateAwareSingulationAction"); } } /** * {@inheritDoc} */ public void decodeXML(Element element) throws InvalidLLRPMessageException { List<Element> tempList = null; boolean atLeastOnce = false; Custom custom; Element temp = null; // child element are always in default LLRP namespace Namespace ns = Namespace.getNamespace(LLRPConstants.LLRPNAMESPACE); temp = element.getChild("Session", ns); if (temp != null) { session = new TwoBitField(temp); } element.removeChild("Session", ns); temp = element.getChild("TagPopulation", ns); if (temp != null) { tagPopulation = new UnsignedShort(temp); } element.removeChild("TagPopulation", ns); temp = element.getChild("TagTransitTime", ns); if (temp != null) { tagTransitTime = new UnsignedInteger(temp); } element.removeChild("TagTransitTime", ns); //parameter - not choices - no special actions needed temp = element.getChild("C1G2TagInventoryStateAwareSingulationAction", ns); if (temp != null) { c1G2TagInventoryStateAwareSingulationAction = new C1G2TagInventoryStateAwareSingulationAction(temp); LOGGER.info( "setting parameter c1G2TagInventoryStateAwareSingulationAction for parameter C1G2SingulationControl"); } if (temp == null) { LOGGER.info( "C1G2SingulationControl misses optional parameter of type c1G2TagInventoryStateAwareSingulationAction"); } element.removeChild("C1G2TagInventoryStateAwareSingulationAction", ns); if (element.getChildren().size() > 0) { String message = "C1G2SingulationControl has unknown element " + ((Element) element.getChildren().get(0)).getName(); throw new InvalidLLRPMessageException(message); } } //setters /** * set session of type TwoBitField . * @param session to be set */ public void setSession(final TwoBitField session) { this.session = session; } /** * set tagPopulation of type UnsignedShort . * @param tagPopulation to be set */ public void setTagPopulation(final UnsignedShort tagPopulation) { this.tagPopulation = tagPopulation; } /** * set tagTransitTime of type UnsignedInteger . * @param tagTransitTime to be set */ public void setTagTransitTime(final UnsignedInteger tagTransitTime) { this.tagTransitTime = tagTransitTime; } /** * set c1G2TagInventoryStateAwareSingulationAction of type C1G2TagInventoryStateAwareSingulationAction. * @param c1G2TagInventoryStateAwareSingulationAction to be set */ public void setC1G2TagInventoryStateAwareSingulationAction( final C1G2TagInventoryStateAwareSingulationAction c1G2TagInventoryStateAwareSingulationAction) { this.c1G2TagInventoryStateAwareSingulationAction = c1G2TagInventoryStateAwareSingulationAction; } // end setter //getters /** * get session of type TwoBitField. * @return type TwoBitField to be set */ public TwoBitField getSession() { return this.session; } /** * get tagPopulation of type UnsignedShort. * @return type UnsignedShort to be set */ public UnsignedShort getTagPopulation() { return this.tagPopulation; } /** * get tagTransitTime of type UnsignedInteger. * @return type UnsignedInteger to be set */ public UnsignedInteger getTagTransitTime() { return this.tagTransitTime; } /** * get c1G2TagInventoryStateAwareSingulationAction of type C1G2TagInventoryStateAwareSingulationAction . * @return C1G2TagInventoryStateAwareSingulationAction */ public C1G2TagInventoryStateAwareSingulationAction getC1G2TagInventoryStateAwareSingulationAction() { return c1G2TagInventoryStateAwareSingulationAction; } // end getters //add methods // end add /** * For TLV Parameter length can not be determined at compile time. This method therefore always returns 0. * @return Integer always zero */ public static Integer length() { return 0; } /** * {@inheritDoc} */ public SignedShort getTypeNum() { return TYPENUM; } /** * {@inheritDoc} */ public String getName() { return "C1G2SingulationControl"; } /** * return string representation. All field values but no parameters are included * @return String */ public String toString() { String result = "C1G2SingulationControl: "; result += ", session: "; result += session; result += ", tagPopulation: "; result += tagPopulation; result += ", tagTransitTime: "; result += tagTransitTime; result = result.replaceFirst(", ", ""); return result; } }