2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief Template for an uavobject in java
10 * @see The GNU Public License (GPL) Version 3
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 package org.openpilot.uavtalk.uavobjects;
31 import java.nio.ByteBuffer;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.ListIterator;
36 import org.openpilot.uavtalk.UAVObjectManager;
37 import org.openpilot.uavtalk.UAVObject;
38 import org.openpilot.uavtalk.UAVDataObject;
39 import org.openpilot.uavtalk.UAVObjectField;
44 generated from $(XMLFILE)
46 public class $(NAME) extends UAVDataObject {
49 super(OBJID, ISSINGLEINST, ISSETTINGS, NAME);
51 List<UAVObjectField> fields = new ArrayList<UAVObjectField>();
55 // Compute the number of bytes for this object
57 ListIterator<UAVObjectField> li = fields.listIterator();
59 numBytes += li.next().getNumBytes();
64 initializeFields(fields, ByteBuffer.allocate(NUMBYTES), NUMBYTES);
65 // Set the default field values
66 setDefaultFieldValues();
67 // Set the object description
68 setDescription(DESCRIPTION);
72 * Create a Metadata object filled with default values for this object
73 * @return Metadata object with default values
75 public Metadata getDefaultMetadata() {
76 UAVObject.Metadata metadata = new UAVObject.Metadata();
78 UAVObject.Metadata.AccessModeNum(UAVObject.AccessMode.$(FLIGHTACCESS)) << UAVOBJ_ACCESS_SHIFT |
79 UAVObject.Metadata.AccessModeNum(UAVObject.AccessMode.$(GCSACCESS)) << UAVOBJ_GCS_ACCESS_SHIFT |
80 $(FLIGHTTELEM_ACKED) << UAVOBJ_TELEMETRY_ACKED_SHIFT |
81 $(GCSTELEM_ACKED) << UAVOBJ_GCS_TELEMETRY_ACKED_SHIFT |
82 UAVObject.Metadata.UpdateModeNum(UAVObject.UpdateMode.$(FLIGHTTELEM_UPDATEMODE)) << UAVOBJ_TELEMETRY_UPDATE_MODE_SHIFT |
83 UAVObject.Metadata.UpdateModeNum(UAVObject.UpdateMode.$(GCSTELEM_UPDATEMODE)) << UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT |
84 UAVObject.Metadata.UpdateModeNum(UAVObject.UpdateMode.$(LOGGING_UPDATEMODE)) << UAVOBJ_LOGGING_UPDATE_MODE_SHIFT;
85 metadata.flightTelemetryUpdatePeriod = $(FLIGHTTELEM_UPDATEPERIOD);
86 metadata.gcsTelemetryUpdatePeriod = $(GCSTELEM_UPDATEPERIOD);
87 metadata.loggingUpdatePeriod = $(LOGGING_UPDATEPERIOD);
93 * Initialize object fields with the default values.
94 * If a default value is not specified the object fields
95 * will be initialized to zero.
97 public void setDefaultFieldValues()
103 * Create a clone of this object, a new instance ID must be specified.
104 * Do not use this function directly to create new instances, the
105 * UAVObjectManager should be used instead.
107 public UAVDataObject clone(long instID) {
108 // TODO: Need to get specific instance to clone
110 $(NAME) obj = new $(NAME)();
111 obj.initialize(instID, this.getMetaObject());
113 } catch (Exception e) {
119 * Returns a new instance of this UAVDataObject with default field
120 * values. This is intended to be used by 'reset to default' functionality.
122 * @return new instance of this class with default values.
125 public UAVDataObject getDefaultInstance(){
126 return new $(NAME)();
130 * Static function to retrieve an instance of the object.
132 public $(NAME) GetInstance(UAVObjectManager objMngr, long instID)
134 return ($(NAME))(objMngr.getObject($(NAME).OBJID, instID));
138 protected static final long OBJID = $(OBJIDHEX)l;
139 protected static final String NAME = "$(NAME)";
140 protected static String DESCRIPTION = "$(DESCRIPTION)";
141 protected static final boolean ISSINGLEINST = $(ISSINGLEINST) > 0;
142 protected static final boolean ISSETTINGS = $(ISSETTINGS) > 0;
143 protected static int NUMBYTES = 0;