dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobjecttemplate.cpp
Go to the documentation of this file.
1 
19 /*
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful, but
26  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28  * for more details.
29  *
30  * You should have received a copy of the GNU General Public License along
31  * with this program; if not, see <http://www.gnu.org/licenses/>
32  *
33  * Additional note on redistribution: The copyright and license notices above
34  * must be maintained in each individual source file that is a derivative work
35  * of this source file; otherwise redistribution is prohibited.
36  */
37 
38 #include "$(NAMELC).h"
40 
41 const QString $(NAME)::NAME = QString("$(NAME)");
42 const QString $(NAME)::DESCRIPTION = QString("$(DESCRIPTION)");
43 const QHash<QString, QString> $(NAME)::FIELD_DESCRIPTIONS{
44 $(FIELDDESCRIPTIONS_STRINGS)};
45 
49 $(NAME)::$(NAME)(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
50 {
51  // Create fields
53 $(FIELDSINIT)
54  // Initialize object
55  initializeFields(fields, reinterpret_cast <quint8 *> (&data), NUMBYTES);
56  // Set the default field values
57  setDefaultFieldValues();
58  // Set the object description
59  setDescription(DESCRIPTION);
60 
61  connect(this, &$(NAME)::objectUpdated, this, &$(NAME)::emitNotifications);
62 }
63 
67 UAVObject::Metadata $(NAME)::getDefaultMetadata()
68 {
69  UAVObject::Metadata metadata;
70  metadata.flags =
71  $(FLIGHTACCESS) << UAVOBJ_ACCESS_SHIFT |
72  $(GCSACCESS) << UAVOBJ_GCS_ACCESS_SHIFT |
73  $(FLIGHTTELEM_ACKED) << UAVOBJ_TELEMETRY_ACKED_SHIFT |
74  $(GCSTELEM_ACKED) << UAVOBJ_GCS_TELEMETRY_ACKED_SHIFT |
75  $(FLIGHTTELEM_UPDATEMODE) << UAVOBJ_TELEMETRY_UPDATE_MODE_SHIFT |
76  $(GCSTELEM_UPDATEMODE) << UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT;
77  metadata.flightTelemetryUpdatePeriod = $(FLIGHTTELEM_UPDATEPERIOD);
78  metadata.gcsTelemetryUpdatePeriod = $(GCSTELEM_UPDATEPERIOD);
79  metadata.loggingUpdatePeriod = $(LOGGING_UPDATEPERIOD);
80  return metadata;
81 }
82 
88 void $(NAME)::setDefaultFieldValues()
89 {
90 $(INITFIELDS)
91 }
92 
96 $(NAME)::DataFields $(NAME)::getData()
97 {
98  return data;
99 }
100 
104 void $(NAME)::setData(const DataFields& data)
105 {
106  // Get metadata
107  Metadata mdata = getMetadata();
108  // Update object if the access mode permits
109  if (UAVObject::GetGcsAccess(mdata) == ACCESS_READWRITE) {
110  this->data = data;
111  emit objectUpdatedAuto(this); // trigger object updated event
112  emit objectUpdated(this);
113  }
114 }
115 
116 void $(NAME)::emitNotifications()
117 {
118  $(NOTIFY_PROPERTIES_CHANGED)
119 }
120 
126 UAVDataObject* $(NAME)::clone(quint32 instID)
127 {
128  $(NAME)* obj = new $(NAME)();
129  obj->initialize(instID, this->getMetaObject());
130  return obj;
131 }
132 
137 {
138  $(NAME)* obj = new $(NAME)();
139  return obj;
140 }
141 
145 $(NAME)* $(NAME)::GetInstance(UAVObjectManager* objMngr, quint32 instID)
146 {
147  return dynamic_cast<$(NAME)*>(objMngr->getObject($(NAME)::OBJID, instID));
148 }
149 
150 $(PROPERTIES_IMPL)
void initialize(quint32 instID, UAVMetaObject *mobj)
Metadata getDefaultMetadata()
DataFields getData()
UAVDataObject * dirtyClone()
DataFields data
() NAME()
void setData(const DataFields &data)
const QString(NAME) const QString(NAME) const QHash< QString, QString >(NAME)
UAVObject * getObject(const QString &name, quint32 instId=0)
UAVDataObject * clone(quint32 instID)
static AccessMode GetGcsAccess(const Metadata &meta)
Definition: uavobject.cpp:397