|
| 1 | +/* |
| 2 | + * Below is the copyright agreement for IMCJava. |
| 3 | + * |
| 4 | + * Copyright (c) 2010-2014, 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 | + * IMC Message Crude Oil (286)<br/> |
| 34 | + * Crude oil measurement.<br/> |
| 35 | + */ |
| 36 | + |
| 37 | +public class CrudeOil extends IMCMessage { |
| 38 | + |
| 39 | + public static final int ID_STATIC = 286; |
| 40 | + |
| 41 | + public CrudeOil() { |
| 42 | + super(ID_STATIC); |
| 43 | + } |
| 44 | + |
| 45 | + public CrudeOil(IMCMessage msg) { |
| 46 | + super(ID_STATIC); |
| 47 | + try{ |
| 48 | + copyFrom(msg); |
| 49 | + } |
| 50 | + catch (Exception e) { |
| 51 | + e.printStackTrace(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + public CrudeOil(IMCDefinition defs) { |
| 56 | + super(defs, ID_STATIC); |
| 57 | + } |
| 58 | + |
| 59 | + public static CrudeOil create(Object... values) { |
| 60 | + CrudeOil m = new CrudeOil(); |
| 61 | + for (int i = 0; i < values.length-1; i+= 2) |
| 62 | + m.setValue(values[i].toString(), values[i+1]); |
| 63 | + return m; |
| 64 | + } |
| 65 | + |
| 66 | + public static CrudeOil clone(IMCMessage msg) throws Exception { |
| 67 | + |
| 68 | + CrudeOil m = new CrudeOil(); |
| 69 | + if (msg == null) |
| 70 | + return m; |
| 71 | + if(msg.definitions != m.definitions){ |
| 72 | + msg = msg.cloneMessage(); |
| 73 | + IMCUtil.updateMessage(msg, m.definitions); |
| 74 | + } |
| 75 | + else if (msg.getMgid()!=m.getMgid()) |
| 76 | + throw new Exception("Argument "+msg.getAbbrev()+" is incompatible with message "+m.getAbbrev()); |
| 77 | + |
| 78 | + m.getHeader().values.putAll(msg.getHeader().values); |
| 79 | + m.values.putAll(msg.values); |
| 80 | + return m; |
| 81 | + } |
| 82 | + |
| 83 | + public CrudeOil(float value) { |
| 84 | + super(ID_STATIC); |
| 85 | + setValue(value); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @return Value (ppb) - fp32_t |
| 90 | + */ |
| 91 | + public double getValue() { |
| 92 | + return getDouble("value"); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @param value Value (ppb) |
| 97 | + */ |
| 98 | + public CrudeOil setValue(double value) { |
| 99 | + values.put("value", value); |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments