|
| 1 | +/* |
| 2 | + * Below is the copyright agreement for IMCJava. |
| 3 | + * |
| 4 | + * Copyright (c) 2010-2025, Laboratório de Sistemas e Tecnologia Subaquática |
| 5 | + * All rights reserved. |
| 6 | + * |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are met: |
| 9 | + * - Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * - Redistributions in binary form must reproduce the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer in the |
| 13 | + * documentation and/or other materials provided with the distribution. |
| 14 | + * - Neither the names of IMC, LSTS, IMCJava nor the names of its |
| 15 | + * contributors may be used to endorse or promote products derived from |
| 16 | + * this software without specific prior written permission. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 19 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | + * DISCLAIMED. IN NO EVENT SHALL LABORATORIO DE SISTEMAS E TECNOLOGIA SUBAQUATICA |
| 22 | + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 27 | + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + * |
| 29 | + */ |
| 30 | +package pt.lsts.imc; |
| 31 | + |
| 32 | + |
| 33 | +/** |
| 34 | + * IMC Message Query Typed Entity Parameters (2016)<br/> |
| 35 | + * This message can be used to query/report the entities and respective parameters in the system<br/> |
| 36 | + */ |
| 37 | + |
| 38 | +public class QueryTypedEntityParameters extends IMCMessage { |
| 39 | + |
| 40 | + public enum OP { |
| 41 | + REQUEST(0), |
| 42 | + REPLY(1); |
| 43 | + |
| 44 | + protected long value; |
| 45 | + |
| 46 | + public long value() { |
| 47 | + return value; |
| 48 | + } |
| 49 | + |
| 50 | + OP(long value) { |
| 51 | + this.value = value; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + public static final int ID_STATIC = 2016; |
| 56 | + |
| 57 | + public QueryTypedEntityParameters() { |
| 58 | + super(ID_STATIC); |
| 59 | + } |
| 60 | + |
| 61 | + public QueryTypedEntityParameters(IMCMessage msg) { |
| 62 | + super(ID_STATIC); |
| 63 | + try{ |
| 64 | + copyFrom(msg); |
| 65 | + } |
| 66 | + catch (Exception e) { |
| 67 | + e.printStackTrace(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public QueryTypedEntityParameters(IMCDefinition defs) { |
| 72 | + super(defs, ID_STATIC); |
| 73 | + } |
| 74 | + |
| 75 | + public static QueryTypedEntityParameters create(Object... values) { |
| 76 | + QueryTypedEntityParameters m = new QueryTypedEntityParameters(); |
| 77 | + for (int i = 0; i < values.length-1; i+= 2) |
| 78 | + m.setValue(values[i].toString(), values[i+1]); |
| 79 | + return m; |
| 80 | + } |
| 81 | + |
| 82 | + public static QueryTypedEntityParameters clone(IMCMessage msg) throws Exception { |
| 83 | + |
| 84 | + QueryTypedEntityParameters m = new QueryTypedEntityParameters(); |
| 85 | + if (msg == null) |
| 86 | + return m; |
| 87 | + if(msg.definitions != m.definitions){ |
| 88 | + msg = msg.cloneMessage(); |
| 89 | + IMCUtil.updateMessage(msg, m.definitions); |
| 90 | + } |
| 91 | + else if (msg.getMgid()!=m.getMgid()) |
| 92 | + throw new Exception("Argument "+msg.getAbbrev()+" is incompatible with message "+m.getAbbrev()); |
| 93 | + |
| 94 | + m.getHeader().values.putAll(msg.getHeader().values); |
| 95 | + m.values.putAll(msg.values); |
| 96 | + return m; |
| 97 | + } |
| 98 | + |
| 99 | + public QueryTypedEntityParameters(OP op, long request_id, String entity_name, java.util.Collection<TypedEntityParameter> parameters) { |
| 100 | + super(ID_STATIC); |
| 101 | + setOp(op); |
| 102 | + setRequestId(request_id); |
| 103 | + if (entity_name != null) |
| 104 | + setEntityName(entity_name); |
| 105 | + if (parameters != null) |
| 106 | + setParameters(parameters); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * @return Operation (enumerated) - uint8_t |
| 111 | + */ |
| 112 | + public OP getOp() { |
| 113 | + try { |
| 114 | + OP o = OP.valueOf(getMessageType().getFieldPossibleValues("op").get(getLong("op"))); |
| 115 | + return o; |
| 116 | + } |
| 117 | + catch (Exception e) { |
| 118 | + return null; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + public String getOpStr() { |
| 123 | + return getString("op"); |
| 124 | + } |
| 125 | + |
| 126 | + public short getOpVal() { |
| 127 | + return (short) getInteger("op"); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @param op Operation (enumerated) |
| 132 | + */ |
| 133 | + public QueryTypedEntityParameters setOp(OP op) { |
| 134 | + values.put("op", op.value()); |
| 135 | + return this; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @param op Operation (as a String) |
| 140 | + */ |
| 141 | + public QueryTypedEntityParameters setOpStr(String op) { |
| 142 | + setValue("op", op); |
| 143 | + return this; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * @param op Operation (integer value) |
| 148 | + */ |
| 149 | + public QueryTypedEntityParameters setOpVal(short op) { |
| 150 | + setValue("op", op); |
| 151 | + return this; |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * @return Request identitier - uint32_t |
| 156 | + */ |
| 157 | + public long getRequestId() { |
| 158 | + return getLong("request_id"); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * @param request_id Request identitier |
| 163 | + */ |
| 164 | + public QueryTypedEntityParameters setRequestId(long request_id) { |
| 165 | + values.put("request_id", request_id); |
| 166 | + return this; |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * @return Entity Name - plaintext |
| 171 | + */ |
| 172 | + public String getEntityName() { |
| 173 | + return getString("entity_name"); |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * @param entity_name Entity Name |
| 178 | + */ |
| 179 | + public QueryTypedEntityParameters setEntityName(String entity_name) { |
| 180 | + values.put("entity_name", entity_name); |
| 181 | + return this; |
| 182 | + } |
| 183 | + |
| 184 | + /** |
| 185 | + * @return Parameters - message-list |
| 186 | + */ |
| 187 | + public java.util.Vector<TypedEntityParameter> getParameters() { |
| 188 | + try { |
| 189 | + return getMessageList("parameters", TypedEntityParameter.class); |
| 190 | + } |
| 191 | + catch (Exception e) { |
| 192 | + return null; |
| 193 | + } |
| 194 | + |
| 195 | + } |
| 196 | + |
| 197 | + /** |
| 198 | + * @param parameters Parameters |
| 199 | + */ |
| 200 | + public QueryTypedEntityParameters setParameters(java.util.Collection<TypedEntityParameter> parameters) { |
| 201 | + values.put("parameters", parameters); |
| 202 | + return this; |
| 203 | + } |
| 204 | + |
| 205 | +} |
0 commit comments