2 ******************************************************************************
3 * @addtogroup UAVObjects OpenPilot UAVObjects
5 * @addtogroup $(NAME) $(NAME)
6 * @brief $(DESCRIPTION)
8 * Autogenerated files and functions for $(NAME) Object
12 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010-2013.
13 * @brief Implementation of the $(NAME) object. This file has been
14 * automatically generated by the UAVObjectGenerator.
16 * @note Object definition file: $(XMLFILE).
17 * This is an automatically generated file.
18 * DO NOT modify manually.
20 * @see The GNU Public License (GPL) Version 3
22 *****************************************************************************/
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful, but
30 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
31 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34 * You should have received a copy of the GNU General Public License along
35 * with this program; if not, write to the Free Software Foundation, Inc.,
36 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 #include <openpilot.h>
40 #include "$(NAMELC).h"
43 #if (defined(__MACH__) && defined(__APPLE__))
44 static UAVObjHandle handle __attribute__((section("__DATA,_uavo_handles")));
46 static UAVObjHandle handle __attribute__((section("_uavo_handles")));
49 #if $(NAMEUC)_ISSETTINGS
50 SETTINGS_INITCALL($(NAME)Initialize);
56 * \return -1 Failure to initialize or -2 for already initialized
58 int32_t $(NAME)Initialize(void)
60 // Compile time assertion that the $(NAME)DataPacked and $(NAME)Data structs
61 // have the same size (though instances of $(NAME)Data
62 // should be placed in memory by the linker/compiler on a 4 byte alignment).
63 PIOS_STATIC_ASSERT(sizeof($(NAME)DataPacked) == sizeof($(NAME)Data));
65 // Don't set the handle to null if already registered
66 if (UAVObjGetByID($(NAMEUC)_OBJID)) {
70 static const UAVObjType objType = {
71 .id = $(NAMEUC)_OBJID,
72 .instance_size = $(NAMEUC)_NUMBYTES,
73 .init_callback = &$(NAME)SetDefaults,
76 // Register object with the object manager
77 handle = UAVObjRegister(&objType,
78 $(NAMEUC)_ISSINGLEINST, $(NAMEUC)_ISSETTINGS, $(NAMEUC)_ISPRIORITY);
81 return handle ? 0 : -1;
84 static inline void DataOverrideDefaults(__attribute__((unused)) $(NAME)Data * data) {}
86 void $(NAME)DataOverrideDefaults($(NAME)Data * data) __attribute__((weak, alias("DataOverrideDefaults")));
89 * Initialize object fields and metadata with the default values.
90 * If a default value is not specified the object fields
91 * will be initialized to zero.
93 void $(NAME)SetDefaults(UAVObjHandle obj, uint16_t instId)
97 // Initialize object fields to their default values
98 UAVObjGetInstanceData(obj, instId, &data);
99 memset(&data, 0, sizeof($(NAME)Data));
101 $(NAME)DataOverrideDefaults(&data);
102 UAVObjSetInstanceData(obj, instId, &data);
104 // Initialize object metadata to their default values
106 UAVObjMetadata metadata;
108 $(FLIGHTACCESS) << UAVOBJ_ACCESS_SHIFT |
109 $(GCSACCESS) << UAVOBJ_GCS_ACCESS_SHIFT |
110 $(FLIGHTTELEM_ACKED) << UAVOBJ_TELEMETRY_ACKED_SHIFT |
111 $(GCSTELEM_ACKED) << UAVOBJ_GCS_TELEMETRY_ACKED_SHIFT |
112 $(FLIGHTTELEM_UPDATEMODE) << UAVOBJ_TELEMETRY_UPDATE_MODE_SHIFT |
113 $(GCSTELEM_UPDATEMODE) << UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT |
114 $(LOGGING_UPDATEMODE) << UAVOBJ_LOGGING_UPDATE_MODE_SHIFT;
115 metadata.telemetryUpdatePeriod = $(FLIGHTTELEM_UPDATEPERIOD);
116 metadata.gcsTelemetryUpdatePeriod = $(GCSTELEM_UPDATEPERIOD);
117 metadata.loggingUpdatePeriod = $(LOGGING_UPDATEPERIOD);
118 UAVObjSetMetadata(obj, &metadata);
125 UAVObjHandle $(NAME)Handle()
131 * Get/Set object Functions