2 ******************************************************************************
4 * @file generator_common.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief common functions for generating uavobjects code
8 * @see The GNU Public License (GPL) Version 3
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "generator_common.h"
28 void replaceCommonTags(QString
& out
)
30 // Replace $(GENERATEDWARNING) tag
31 out
.replace(QString("$(GENERATEDWARNING)"), "This is a autogenerated file!! Do not modify and expect a result.");
34 * Replace all the common tags from the template file with actual object information.
36 void replaceCommonTags(QString
& out
, ObjectInfo
*info
)
38 QStringList updateModeStr
, accessModeStr
;
40 updateModeStr
<< "UPDATEMODE_MANUAL" << "UPDATEMODE_PERIODIC"
41 << "UPDATEMODE_ONCHANGE"
42 << "UPDATEMODE_THROTTLED";
44 accessModeStr
<< "ACCESS_READWRITE" << "ACCESS_READONLY";
48 // replace the tags which don't need info
49 replaceCommonTags(out
);
51 // Replace $(XMLFILE) tag
52 out
.replace(QString("$(XMLFILE)"), info
->filename
);
53 // Replace $(NAME) tag
54 out
.replace(QString("$(NAME)"), info
->name
);
55 // Replace $(NAMELC) tag
56 out
.replace(QString("$(NAMELC)"), info
->namelc
);
57 // Replace $(DESCRIPTION) tag
58 out
.replace(QString("$(DESCRIPTION)"), info
->description
);
59 // Replace $(CATEGORY) tag
60 out
.replace(QString("$(CATEGORY)"), info
->category
);
61 // Replace $(NAMEUC) tag
62 out
.replace(QString("$(NAMEUC)"), info
->name
.toUpper());
63 // Replace $(OBJID) tag
64 out
.replace(QString("$(OBJID)"), QString().setNum(info
->id
));
65 // Replace $(UOBJID) tag
66 out
.replace(QString("$(UOBJID)"), QString().setNum((qint32
)info
->id
));
67 // Replace $(OBJIDHEX) tag
68 out
.replace(QString("$(OBJIDHEX)"), QString("0x") + QString().setNum(info
->id
, 16).toUpper());
69 // Replace $(ISSINGLEINST) tag
70 out
.replace(QString("$(ISSINGLEINST)"), boolTo01String(info
->isSingleInst
));
71 out
.replace(QString("$(ISSINGLEINSTTF)"), boolToTRUEFALSEString(info
->isSingleInst
));
72 // Replace $(ISSETTINGS) tag
73 out
.replace(QString("$(ISSETTINGS)"), boolTo01String(info
->isSettings
));
74 out
.replace(QString("$(ISSETTINGSTF)"), boolToTRUEFALSEString(info
->isSettings
));
75 // Replace $(ISPRIORITY) tag
76 out
.replace(QString("$(ISPRIORITY)"), boolTo01String(info
->isPriority
));
77 out
.replace(QString("$(ISPRIORITYTF)"), boolToTRUEFALSEString(info
->isPriority
));
78 // Replace $(GCSACCESS) tag
79 value
= accessModeStr
[info
->gcsAccess
];
80 out
.replace(QString("$(GCSACCESS)"), value
);
81 // Replace $(FLIGHTACCESS) tag
82 value
= accessModeStr
[info
->flightAccess
];
83 out
.replace(QString("$(FLIGHTACCESS)"), value
);
84 // Replace $(FLIGHTTELEM_ACKED) tag
85 out
.replace(QString("$(FLIGHTTELEM_ACKED)"), boolTo01String(info
->flightTelemetryAcked
));
86 out
.replace(QString("$(FLIGHTTELEM_ACKEDTF)"), boolToTRUEFALSEString(info
->flightTelemetryAcked
));
87 // Replace $(FLIGHTTELEM_UPDATEMODE) tag
88 value
= updateModeStr
[info
->flightTelemetryUpdateMode
];
89 out
.replace(QString("$(FLIGHTTELEM_UPDATEMODE)"), value
);
90 // Replace $(FLIGHTTELEM_UPDATEPERIOD) tag
91 out
.replace(QString("$(FLIGHTTELEM_UPDATEPERIOD)"), QString().setNum(info
->flightTelemetryUpdatePeriod
));
92 // Replace $(GCSTELEM_ACKED) tag
93 out
.replace(QString("$(GCSTELEM_ACKED)"), boolTo01String(info
->gcsTelemetryAcked
));
94 out
.replace(QString("$(GCSTELEM_ACKEDTF)"), boolToTRUEFALSEString(info
->gcsTelemetryAcked
));
95 // Replace $(GCSTELEM_UPDATEMODE) tag
96 value
= updateModeStr
[info
->gcsTelemetryUpdateMode
];
97 out
.replace(QString("$(GCSTELEM_UPDATEMODE)"), value
);
98 // Replace $(GCSTELEM_UPDATEPERIOD) tag
99 out
.replace(QString("$(GCSTELEM_UPDATEPERIOD)"), QString().setNum(info
->gcsTelemetryUpdatePeriod
));
100 // Replace $(LOGGING_UPDATEMODE) tag
101 value
= updateModeStr
[info
->loggingUpdateMode
];
102 out
.replace(QString("$(LOGGING_UPDATEMODE)"), value
);
103 // Replace $(LOGGING_UPDATEPERIOD) tag
104 out
.replace(QString("$(LOGGING_UPDATEPERIOD)"), QString().setNum(info
->loggingUpdatePeriod
));
108 * Convert a boolean to string "0" or "1"
110 QString
boolTo01String(bool value
)
120 * Convert a boolean to string "TRUE" or "FALSE"
122 QString
boolToTRUEFALSEString(bool value
)
125 return QString("TRUE");
128 return QString("FALSE");