/* * * 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:47 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.FixedFrequencyTable; import kr.ac.kaist.resl.ltk.generated.parameters.FrequencyHopTable; import org.llrp.ltk.types.Bit; 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.UnsignedShort; import java.util.LinkedList; import java.util.List; /** * Describes the fixed frequency or hopping frequencies supported in this UHFBand. See also {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=50&view=fit">LLRP Specification Section 9.2.4.1.2</a>} and {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=134&view=fit">LLRP Specification Section 16.2.3.4.1.2</a>} */ /** * Describes the fixed frequency or hopping frequencies supported in this UHFBand. See also {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=50&view=fit">LLRP Specification Section 9.2.4.1.2</a>} and {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=134&view=fit">LLRP Specification Section 16.2.3.4.1.2</a>} . */ public class FrequencyInformation extends TLVParameter { public static final SignedShort TYPENUM = new SignedShort(146); private static final Logger LOGGER = Logger.getLogger(FrequencyInformation.class); protected Bit hopping; protected BitList reserved0 = new BitList(7); protected List<FrequencyHopTable> frequencyHopTableList = new LinkedList<FrequencyHopTable>(); protected FixedFrequencyTable fixedFrequencyTable; /** * empty constructor to create new parameter. */ public FrequencyInformation() { } /** * Constructor to create parameter from binary encoded parameter * calls decodeBinary to decode parameter. * @param list to be decoded */ public FrequencyInformation(LLRPBitList list) { decodeBinary(list); } /** * Constructor to create parameter from xml encoded parameter * calls decodeXML to decode parameter. * @param element to be decoded */ public FrequencyInformation(Element element) throws InvalidLLRPMessageException { decodeXML(element); } /** * {@inheritDoc} */ public LLRPBitList encodeBinarySpecific() { LLRPBitList resultBits = new LLRPBitList(); if (hopping == null) { LOGGER.warn(" hopping not set"); throw new MissingParameterException( " hopping not set for Parameter of Type FrequencyInformation"); } resultBits.append(hopping.encodeBinary()); resultBits.append(reserved0.encodeBinary()); if (frequencyHopTableList == null) { //just warn - it is optional LOGGER.info(" frequencyHopTableList not set"); } else { for (FrequencyHopTable field : frequencyHopTableList) { resultBits.append(field.encodeBinary()); } } if (fixedFrequencyTable == null) { // optional parameter, may be null LOGGER.info(" fixedFrequencyTable not set"); } else { resultBits.append(fixedFrequencyTable.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 (hopping == null) { LOGGER.warn(" hopping not set"); throw new MissingParameterException(" hopping not set"); } else { element.addContent(hopping.encodeXML("Hopping", ns)); } //element.addContent(reserved0.encodeXML("reserved",ns)); //parameters if (frequencyHopTableList == null) { LOGGER.info("frequencyHopTableList not set"); } else { for (FrequencyHopTable field : frequencyHopTableList) { element.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } } if (fixedFrequencyTable == null) { LOGGER.info("fixedFrequencyTable not set"); } else { element.addContent(fixedFrequencyTable.encodeXML( fixedFrequencyTable.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; hopping = new Bit(binary.subList(position, Bit.length())); position += Bit.length(); position += reserved0.length(); // list of parameters frequencyHopTableList = new LinkedList<FrequencyHopTable>(); LOGGER.debug("decoding parameter frequencyHopTableList "); while (position < binary.length()) { // store if one parameter matched boolean atLeastOnce = false; // look ahead to see type 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; } //add parameter to list if type number matches if ((type != null) && type.equals(FrequencyHopTable.TYPENUM)) { if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = FrequencyHopTable.length(); } frequencyHopTableList.add(new FrequencyHopTable(binary.subList( position, tempLength))); LOGGER.debug( "adding FrequencyHopTable to frequencyHopTableList "); atLeastOnce = true; position += tempLength; } if (!atLeastOnce) { //no parameter matched therefore we jump out of the loop break; } } //if list is still empty no parameter matched if (frequencyHopTableList.isEmpty()) { LOGGER.info( "encoded message does not contain parameter for optional frequencyHopTableList"); } // 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( "FrequencyInformation misses optional parameter of type FixedFrequencyTable"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = fixedFrequencyTable.length(); } if ((type != null) && type.equals(FixedFrequencyTable.TYPENUM)) { fixedFrequencyTable = new FixedFrequencyTable(binary.subList( position, tempLength)); position += tempLength; LOGGER.debug( " fixedFrequencyTable is instantiated with FixedFrequencyTable with length" + tempLength); } else { LOGGER.info( "FrequencyInformation misses optional parameter of type FixedFrequencyTable"); } } /** * {@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("Hopping", ns); if (temp != null) { hopping = new Bit(temp); } element.removeChild("Hopping", ns); //parameter - not choices - no special actions needed //we expect a list of parameters frequencyHopTableList = new LinkedList<FrequencyHopTable>(); tempList = element.getChildren("FrequencyHopTable", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.info( "FrequencyInformation misses optional parameter of type frequencyHopTableList"); } else { for (Element e : tempList) { frequencyHopTableList.add(new FrequencyHopTable(e)); LOGGER.debug( "adding FrequencyHopTable to frequencyHopTableList "); } } element.removeChildren("FrequencyHopTable", ns); //parameter - not choices - no special actions needed temp = element.getChild("FixedFrequencyTable", ns); if (temp != null) { fixedFrequencyTable = new FixedFrequencyTable(temp); LOGGER.info( "setting parameter fixedFrequencyTable for parameter FrequencyInformation"); } if (temp == null) { LOGGER.info( "FrequencyInformation misses optional parameter of type fixedFrequencyTable"); } element.removeChild("FixedFrequencyTable", ns); if (element.getChildren().size() > 0) { String message = "FrequencyInformation has unknown element " + ((Element) element.getChildren().get(0)).getName(); throw new InvalidLLRPMessageException(message); } } //setters /** * set hopping of type Bit . * @param hopping to be set */ public void setHopping(final Bit hopping) { this.hopping = hopping; } /** * set frequencyHopTableList of type List <FrequencyHopTable>. * @param frequencyHopTableList to be set */ public void setFrequencyHopTableList( final List<FrequencyHopTable> frequencyHopTableList) { this.frequencyHopTableList = frequencyHopTableList; } /** * set fixedFrequencyTable of type FixedFrequencyTable. * @param fixedFrequencyTable to be set */ public void setFixedFrequencyTable( final FixedFrequencyTable fixedFrequencyTable) { this.fixedFrequencyTable = fixedFrequencyTable; } // end setter //getters /** * get hopping of type Bit. * @return type Bit to be set */ public Bit getHopping() { return this.hopping; } /** * get frequencyHopTableList of type List <FrequencyHopTable> . * @return List <FrequencyHopTable> */ public List<FrequencyHopTable> getFrequencyHopTableList() { return frequencyHopTableList; } /** * get fixedFrequencyTable of type FixedFrequencyTable . * @return FixedFrequencyTable */ public FixedFrequencyTable getFixedFrequencyTable() { return fixedFrequencyTable; } // end getters //add methods /** * add element frequencyHopTable of type FrequencyHopTable . * @param frequencyHopTable of type FrequencyHopTable */ public void addToFrequencyHopTableList(FrequencyHopTable frequencyHopTable) { if (this.frequencyHopTableList == null) { this.frequencyHopTableList = new LinkedList<FrequencyHopTable>(); } this.frequencyHopTableList.add(frequencyHopTable); } // 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 "FrequencyInformation"; } /** * return string representation. All field values but no parameters are included * @return String */ public String toString() { String result = "FrequencyInformation: "; result += ", hopping: "; result += hopping; result = result.replaceFirst(", ", ""); return result; } }