2011-01-13 03:26:00 +01:00
/**
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @ file uavobjectgeneratorflight . cpp
* @ author The OpenPilot Team , http : //www.openpilot.org Copyright (C) 2010.
* @ brief produce flight code for uavobjects
*
* @ see The GNU Public License ( GPL ) Version 3
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License
* for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
# include "uavobjectgeneratorflight.h"
using namespace std ;
2013-05-19 16:37:30 +02:00
bool UAVObjectGeneratorFlight : : generate ( UAVObjectParser * parser , QString templatepath , QString outputpath )
{
fieldTypeStrC < < " int8_t " < < " int16_t " < < " int32_t " < < " uint8_t "
< < " uint16_t " < < " uint32_t " < < " float " < < " uint8_t " ;
2011-01-13 03:26:00 +01:00
2013-05-19 16:37:30 +02:00
QString flightObjInit , objInc , objFileNames , objNames ;
2011-06-24 02:08:20 +02:00
qint32 sizeCalc ;
2013-05-19 16:37:30 +02:00
flightCodePath = QDir ( templatepath + QString ( FLIGHT_CODE_DIR ) ) ;
flightOutputPath = QDir ( outputpath + QString ( " flight " ) ) ;
2011-01-22 18:38:43 +01:00
flightOutputPath . mkpath ( flightOutputPath . absolutePath ( ) ) ;
2011-01-13 03:26:00 +01:00
2013-05-19 16:37:30 +02:00
flightCodeTemplate = readFile ( flightCodePath . absoluteFilePath ( " uavobject.c.template " ) ) ;
flightIncludeTemplate = readFile ( flightCodePath . absoluteFilePath ( " inc/uavobject.h.template " ) ) ;
flightInitTemplate = readFile ( flightCodePath . absoluteFilePath ( " uavobjectsinit.c.template " ) ) ;
flightInitIncludeTemplate = readFile ( flightCodePath . absoluteFilePath ( " inc/uavobjectsinit.h.template " ) ) ;
flightMakeTemplate = readFile ( flightCodePath . absoluteFilePath ( " Makefile.inc.template " ) ) ;
2011-01-13 03:26:00 +01:00
2013-05-19 16:37:30 +02:00
if ( flightCodeTemplate . isNull ( ) | | flightIncludeTemplate . isNull ( ) | | flightInitTemplate . isNull ( ) ) {
cerr < < " Error: Could not open flight template files. " < < endl ;
return false ;
}
2011-01-13 03:26:00 +01:00
2011-06-24 02:08:20 +02:00
sizeCalc = 0 ;
2011-01-13 03:26:00 +01:00
for ( int objidx = 0 ; objidx < parser - > getNumObjects ( ) ; + + objidx ) {
2013-05-19 16:37:30 +02:00
ObjectInfo * info = parser - > getObjectByIndex ( objidx ) ;
2011-01-13 03:26:00 +01:00
process_object ( info ) ;
2013-05-19 16:37:30 +02:00
flightObjInit . append ( " #ifdef UAVOBJ_INIT_ " + info - > namelc + " \n " ) ;
2013-04-30 02:02:36 +02:00
flightObjInit . append ( " " + info - > name + " Initialize(); \n " ) ;
flightObjInit . append ( " #endif \n " ) ;
objInc . append ( " #include \" " + info - > namelc + " .h \" \n " ) ;
2013-05-19 16:37:30 +02:00
objFileNames . append ( " " + info - > namelc ) ;
objNames . append ( " " + info - > name ) ;
if ( parser - > getNumBytes ( objidx ) > sizeCalc ) {
sizeCalc = parser - > getNumBytes ( objidx ) ;
}
2011-01-13 03:26:00 +01:00
}
// Write the flight object inialization files
2013-05-19 16:37:30 +02:00
flightInitTemplate . replace ( QString ( " $(OBJINC) " ) , objInc ) ;
flightInitTemplate . replace ( QString ( " $(OBJINIT) " ) , flightObjInit ) ;
2015-03-29 06:27:07 +02:00
bool res = writeFileIfDifferent ( flightOutputPath . absolutePath ( ) + " /uavobjectsinit.c " ,
2015-05-02 16:46:35 +02:00
flightInitTemplate ) ;
2011-01-13 03:26:00 +01:00
if ( ! res ) {
2011-06-24 02:08:20 +02:00
cout < < " Error: Could not write flight object init file " < < endl ;
return false ;
}
// Write the flight object initialization header
2013-05-19 16:37:30 +02:00
flightInitIncludeTemplate . replace ( QString ( " $(SIZECALCULATION) " ) , QString ( ) . setNum ( sizeCalc ) ) ;
2015-03-29 06:27:07 +02:00
res = writeFileIfDifferent ( flightOutputPath . absolutePath ( ) + " /uavobjectsinit.h " ,
2015-05-02 16:46:35 +02:00
flightInitIncludeTemplate ) ;
2011-06-24 02:08:20 +02:00
if ( ! res ) {
cout < < " Error: Could not write flight object init header file " < < endl ;
2011-01-13 03:26:00 +01:00
return false ;
}
2011-02-02 21:15:28 +01:00
// Write the flight object Makefile
2013-05-19 16:37:30 +02:00
flightMakeTemplate . replace ( QString ( " $(UAVOBJFILENAMES) " ) , objFileNames ) ;
flightMakeTemplate . replace ( QString ( " $(UAVOBJNAMES) " ) , objNames ) ;
2015-03-29 06:27:07 +02:00
res = writeFileIfDifferent ( flightOutputPath . absolutePath ( ) + " /Makefile.inc " ,
2015-05-02 16:46:35 +02:00
flightMakeTemplate ) ;
2011-02-02 21:15:28 +01:00
if ( ! res ) {
cout < < " Error: Could not write flight Makefile " < < endl ;
return false ;
}
2011-01-13 03:26:00 +01:00
return true ; // if we come here everything should be fine
}
/**
* Generate the Flight object files
2013-05-19 16:37:30 +02:00
* */
bool UAVObjectGeneratorFlight : : process_object ( ObjectInfo * info )
2011-01-13 03:26:00 +01:00
{
2013-05-19 16:37:30 +02:00
if ( info = = NULL ) {
2011-01-13 03:26:00 +01:00
return false ;
2013-05-19 16:37:30 +02:00
}
2011-01-13 03:26:00 +01:00
// Prepare output strings
QString outInclude = flightIncludeTemplate ;
2013-05-19 16:37:30 +02:00
QString outCode = flightCodeTemplate ;
2011-01-13 03:26:00 +01:00
// Replace common tags
replaceCommonTags ( outInclude , info ) ;
replaceCommonTags ( outCode , info ) ;
2015-04-09 01:38:49 +02:00
// Use the appropriate typedef for enums where we find them. Set up
// that StringList here for use below.
//
QStringList typeList ;
2015-05-02 16:46:35 +02:00
for ( int n = 0 ; n < info - > fields . length ( ) ; + + n ) {
if ( info - > fields [ n ] - > type = = FIELDTYPE_ENUM ) {
2015-04-09 01:38:49 +02:00
typeList < < QString ( " %1%2Options " ) . arg ( info - > name ) . arg ( info - > fields [ n ] - > name ) ;
2015-05-02 16:46:35 +02:00
} else {
2015-04-09 01:38:49 +02:00
typeList < < fieldTypeStrC [ info - > fields [ n ] - > type ] ;
}
}
2011-01-13 03:26:00 +01:00
// Replace the $(DATAFIELDS) tag
QString type ;
QString fields ;
2013-07-31 15:23:43 +02:00
QString dataStructures ;
2013-05-19 16:37:30 +02:00
for ( int n = 0 ; n < info - > fields . length ( ) ; + + n ) {
2011-01-13 03:26:00 +01:00
// Determine type
2015-04-09 01:38:49 +02:00
type = typeList [ n ] ;
2011-01-13 03:26:00 +01:00
// Append field
2013-07-31 15:23:43 +02:00
// Check if it a named set and creates structures accordingly
2013-05-19 16:37:30 +02:00
if ( info - > fields [ n ] - > numElements > 1 ) {
2013-08-01 01:28:50 +02:00
if ( info - > fields [ n ] - > elementNames [ 0 ] . compare ( QString ( " 0 " ) ) ! = 0 ) {
2013-09-01 12:10:55 +02:00
QString structTypeName = QString ( " %1%2Data " ) . arg ( info - > name ) . arg ( info - > fields [ n ] - > name ) ;
QString structType = QString ( " typedef struct __attribute__ ((__packed__)) { \n " ) ;
2013-08-01 01:28:50 +02:00
for ( int f = 0 ; f < info - > fields [ n ] - > elementNames . count ( ) ; f + + ) {
2013-09-01 12:10:55 +02:00
structType . append ( QString ( " %1 %2; \n " ) . arg ( type ) . arg ( info - > fields [ n ] - > elementNames [ f ] ) ) ;
2013-07-31 15:23:43 +02:00
}
2014-08-24 00:16:34 +02:00
structType . append ( QString ( " } %1 ; \n " ) . arg ( structTypeName ) ) ;
structType . append ( QString ( " typedef struct __attribute__ ((__packed__)) { \n " ) ) ;
structType . append ( QString ( " %1 array[%2]; \n " ) . arg ( type ) . arg ( info - > fields [ n ] - > elementNames . count ( ) ) ) ;
structType . append ( QString ( " } %1Array ; \n " ) . arg ( structTypeName ) ) ;
structType . append ( QString ( " #define %1%2ToArray( var ) UAVObjectFieldToArray( %3, var ) \n \n " ) . arg ( info - > name ) . arg ( info - > fields [ n ] - > name ) . arg ( structTypeName ) ) ;
2013-07-31 15:23:43 +02:00
2013-09-01 12:10:55 +02:00
dataStructures . append ( structType ) ;
2013-07-31 15:23:43 +02:00
2013-09-01 12:10:55 +02:00
fields . append ( QString ( " %1 %2; \n " ) . arg ( structTypeName )
2013-07-31 15:23:43 +02:00
. arg ( info - > fields [ n ] - > name ) ) ;
} else {
2013-08-01 01:28:50 +02:00
fields . append ( QString ( " %1 %2[%3]; \n " ) . arg ( type )
. arg ( info - > fields [ n ] - > name ) . arg ( info - > fields [ n ] - > numElements ) ) ;
2013-07-31 15:23:43 +02:00
}
2013-05-19 16:37:30 +02:00
} else {
fields . append ( QString ( " %1 %2; \n " ) . arg ( type ) . arg ( info - > fields [ n ] - > name ) ) ;
2011-01-13 03:26:00 +01:00
}
}
outInclude . replace ( QString ( " $(DATAFIELDS) " ) , fields ) ;
2013-07-31 15:23:43 +02:00
outInclude . replace ( QString ( " $(DATASTRUCTURES) " ) , dataStructures ) ;
2011-01-13 03:26:00 +01:00
// Replace the $(DATAFIELDINFO) tag
QString enums ;
2013-05-19 16:37:30 +02:00
for ( int n = 0 ; n < info - > fields . length ( ) ; + + n ) {
2013-04-30 02:02:36 +02:00
enums . append ( QString ( " /* Field %1 information */ \n " ) . arg ( info - > fields [ n ] - > name ) ) ;
2011-01-13 03:26:00 +01:00
// Only for enum types
2013-05-19 16:37:30 +02:00
if ( info - > fields [ n ] - > type = = FIELDTYPE_ENUM ) {
2013-04-30 02:02:36 +02:00
enums . append ( QString ( " \n // Enumeration options for field %1 \n " ) . arg ( info - > fields [ n ] - > name ) ) ;
2015-04-20 15:31:26 +02:00
enums . append ( " typedef enum __attribute__ ((__packed__)) { \n " ) ;
2011-01-13 03:26:00 +01:00
// Go through each option
QStringList options = info - > fields [ n ] - > options ;
for ( int m = 0 ; m < options . length ( ) ; + + m ) {
2013-05-19 16:37:30 +02:00
QString s = ( m = = ( options . length ( ) - 1 ) ) ? " %1_%2_%3=%4 \n " : " %1_%2_%3=%4, \n " ;
enums . append ( s
. arg ( info - > name . toUpper ( ) )
. arg ( info - > fields [ n ] - > name . toUpper ( ) )
. arg ( options [ m ] . toUpper ( ) . replace ( QRegExp ( ENUM_SPECIAL_CHARS ) , " " ) )
. arg ( m ) ) ;
2011-01-13 03:26:00 +01:00
}
2013-05-19 16:37:30 +02:00
enums . append ( QString ( " } %1%2Options; \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
2011-01-13 03:26:00 +01:00
}
// Generate element names (only if field has more than one element)
2013-05-19 16:37:30 +02:00
if ( info - > fields [ n ] - > numElements > 1 & & ! info - > fields [ n ] - > defaultElementNames ) {
2013-04-30 02:02:36 +02:00
enums . append ( QString ( " \n // Array element names for field %1 \n " ) . arg ( info - > fields [ n ] - > name ) ) ;
enums . append ( " typedef enum { \n " ) ;
2011-01-13 03:26:00 +01:00
// Go through the element names
QStringList elemNames = info - > fields [ n ] - > elementNames ;
2013-05-19 16:37:30 +02:00
for ( int m = 0 ; m < elemNames . length ( ) ; + + m ) {
QString s = ( m ! = ( elemNames . length ( ) - 1 ) ) ? " %1_%2_%3=%4, \n " : " %1_%2_%3=%4 \n " ;
enums . append ( s
. arg ( info - > name . toUpper ( ) )
. arg ( info - > fields [ n ] - > name . toUpper ( ) )
. arg ( elemNames [ m ] . toUpper ( ) )
. arg ( m ) ) ;
2011-01-13 03:26:00 +01:00
}
2013-05-19 16:37:30 +02:00
enums . append ( QString ( " } %1%2Elem; \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
2011-01-13 03:26:00 +01:00
}
// Generate array information
2013-05-19 16:37:30 +02:00
if ( info - > fields [ n ] - > numElements > 1 ) {
2013-04-30 02:02:36 +02:00
enums . append ( QString ( " \n // Number of elements for field %1 \n " ) . arg ( info - > fields [ n ] - > name ) ) ;
2013-05-19 16:37:30 +02:00
enums . append ( QString ( " #define %1_%2_NUMELEM %3 \n " )
. arg ( info - > name . toUpper ( ) )
. arg ( info - > fields [ n ] - > name . toUpper ( ) )
. arg ( info - > fields [ n ] - > numElements ) ) ;
2011-01-13 03:26:00 +01:00
}
2013-04-30 02:02:36 +02:00
enums . append ( QString ( " \n " ) ) ;
2011-01-13 03:26:00 +01:00
}
outInclude . replace ( QString ( " $(DATAFIELDINFO) " ) , enums ) ;
// Replace the $(INITFIELDS) tag
QString initfields ;
2013-05-19 16:37:30 +02:00
for ( int n = 0 ; n < info - > fields . length ( ) ; + + n ) {
if ( ! info - > fields [ n ] - > defaultValues . isEmpty ( ) ) {
2011-01-13 03:26:00 +01:00
// For non-array fields
2013-05-19 16:37:30 +02:00
if ( info - > fields [ n ] - > numElements = = 1 ) {
if ( info - > fields [ n ] - > type = = FIELDTYPE_ENUM ) {
initfields . append ( QString ( " data.%1 = %2; \n " )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > options . indexOf ( info - > fields [ n ] - > defaultValues [ 0 ] ) ) ) ;
} else if ( info - > fields [ n ] - > type = = FIELDTYPE_FLOAT32 ) {
initfields . append ( QString ( " data.%1 = %2f; \n " )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > defaultValues [ 0 ] . toFloat ( ) , 0 , ' e ' , 6 ) ) ;
} else {
initfields . append ( QString ( " data.%1 = %2; \n " )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > defaultValues [ 0 ] . toInt ( ) ) ) ;
2011-01-13 03:26:00 +01:00
}
2013-05-19 16:37:30 +02:00
} else {
2011-01-13 03:26:00 +01:00
// Initialize all fields in the array
2013-05-19 16:37:30 +02:00
for ( int idx = 0 ; idx < info - > fields [ n ] - > numElements ; + + idx ) {
2013-09-01 12:10:55 +02:00
if ( info - > fields [ n ] - > elementNames [ 0 ] . compare ( QString ( " 0 " ) ) = = 0 ) {
initfields . append ( QString ( " data.%1[%2] = " )
. arg ( info - > fields [ n ] - > name )
. arg ( idx ) ) ;
} else {
initfields . append ( QString ( " data.%1.%2 = " )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > elementNames [ idx ] ) ) ;
2013-07-31 15:23:43 +02:00
}
2013-09-01 12:10:55 +02:00
2013-05-19 16:37:30 +02:00
if ( info - > fields [ n ] - > type = = FIELDTYPE_ENUM ) {
2013-09-01 12:10:55 +02:00
initfields . append ( QString ( " %1; \n " )
2013-05-19 16:37:30 +02:00
. arg ( info - > fields [ n ] - > options . indexOf ( info - > fields [ n ] - > defaultValues [ idx ] ) ) ) ;
} else if ( info - > fields [ n ] - > type = = FIELDTYPE_FLOAT32 ) {
2013-09-01 12:10:55 +02:00
initfields . append ( QString ( " %1f; \n " )
2013-05-19 16:37:30 +02:00
. arg ( info - > fields [ n ] - > defaultValues [ idx ] . toFloat ( ) , 0 , ' e ' , 6 ) ) ;
} else {
2013-09-01 12:10:55 +02:00
initfields . append ( QString ( " %1; \n " )
2013-05-19 16:37:30 +02:00
. arg ( info - > fields [ n ] - > defaultValues [ idx ] . toInt ( ) ) ) ;
2011-01-13 03:26:00 +01:00
}
}
}
}
}
outCode . replace ( QString ( " $(INITFIELDS) " ) , initfields ) ;
2011-06-03 06:18:34 +02:00
// Replace the $(SETGETFIELDS) tag
QString setgetfields ;
2013-05-19 16:37:30 +02:00
for ( int n = 0 ; n < info - > fields . length ( ) ; + + n ) {
// if (!info->fields[n]->defaultValues.isEmpty() )
2011-06-03 06:18:34 +02:00
{
// For non-array fields
2013-05-19 16:37:30 +02:00
if ( info - > fields [ n ] - > numElements = = 1 ) {
/* Set */
setgetfields . append ( QString ( " void %2%3Set(%1 *New%3) \n " )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] )
2013-05-19 16:37:30 +02:00
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
setgetfields . append ( QString ( " { \n " ) ) ;
setgetfields . append ( QString ( " UAVObjSetDataField(%1Handle(), (void *)New%2, offsetof(%1Data, %2), sizeof(%3)); \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] ) ) ;
2013-05-19 16:37:30 +02:00
setgetfields . append ( QString ( " } \n " ) ) ;
/* GET */
setgetfields . append ( QString ( " void %2%3Get(%1 *New%3) \n " )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] )
2013-05-19 16:37:30 +02:00
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
setgetfields . append ( QString ( " { \n " ) ) ;
setgetfields . append ( QString ( " UAVObjGetDataField(%1Handle(), (void *)New%2, offsetof(%1Data, %2), sizeof(%3)); \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] ) ) ;
2013-05-19 16:37:30 +02:00
setgetfields . append ( QString ( " } \n " ) ) ;
} else {
2013-09-01 13:23:20 +02:00
// When no struct accessor is available for a field array accessor is the default.
QString suffix = QString ( " " ) ;
if ( info - > fields [ n ] - > elementNames [ 0 ] . compare ( QString ( " 0 " ) ) ! = 0 ) {
// struct based field accessor
QString structTypeName = QString ( " %1%2Data " ) . arg ( info - > name ) . arg ( info - > fields [ n ] - > name ) ;
/* SET */
setgetfields . append ( QString ( " void %2%3Set( %1 *New%3 ) \n " )
. arg ( structTypeName )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
setgetfields . append ( QString ( " { \n " ) ) ;
setgetfields . append ( QString ( " UAVObjSetDataField(%1Handle(), (void *)New%2, offsetof(%1Data, %2), %3*sizeof(%4)); \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > numElements )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] ) ) ;
2013-09-01 13:23:20 +02:00
setgetfields . append ( QString ( " } \n " ) ) ;
/* GET */
setgetfields . append ( QString ( " void %2%3Get( %1 *New%3 ) \n " )
. arg ( structTypeName )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
setgetfields . append ( QString ( " { \n " ) ) ;
setgetfields . append ( QString ( " UAVObjGetDataField(%1Handle(), (void *)New%2, offsetof(%1Data, %2), %3*sizeof(%4)); \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > numElements )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] ) ) ;
2013-09-01 13:23:20 +02:00
setgetfields . append ( QString ( " } \n " ) ) ;
// Append array suffix to array accessors
suffix = QString ( " Array " ) ;
}
// array based field accessor
2013-05-19 16:37:30 +02:00
/* SET */
2013-09-01 13:23:20 +02:00
setgetfields . append ( QString ( " void %2%3%4Set( %1 *New%3 ) \n " )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] )
2013-05-19 16:37:30 +02:00
. arg ( info - > name )
2013-09-01 13:23:20 +02:00
. arg ( info - > fields [ n ] - > name )
. arg ( suffix ) ) ;
2013-05-19 16:37:30 +02:00
setgetfields . append ( QString ( " { \n " ) ) ;
setgetfields . append ( QString ( " UAVObjSetDataField(%1Handle(), (void *)New%2, offsetof(%1Data, %2), %3*sizeof(%4)); \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > numElements )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] ) ) ;
2013-05-19 16:37:30 +02:00
setgetfields . append ( QString ( " } \n " ) ) ;
/* GET */
2013-09-01 13:23:20 +02:00
setgetfields . append ( QString ( " void %2%3%4Get( %1 *New%3 ) \n " )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] )
2013-05-19 16:37:30 +02:00
. arg ( info - > name )
2013-09-01 13:23:20 +02:00
. arg ( info - > fields [ n ] - > name )
. arg ( suffix ) ) ;
2013-05-19 16:37:30 +02:00
setgetfields . append ( QString ( " { \n " ) ) ;
setgetfields . append ( QString ( " UAVObjGetDataField(%1Handle(), (void *)New%2, offsetof(%1Data, %2), %3*sizeof(%4)); \n " )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name )
. arg ( info - > fields [ n ] - > numElements )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] ) ) ;
2013-05-19 16:37:30 +02:00
setgetfields . append ( QString ( " } \n " ) ) ;
2011-06-03 06:18:34 +02:00
}
}
}
outCode . replace ( QString ( " $(SETGETFIELDS) " ) , setgetfields ) ;
// Replace the $(SETGETFIELDSEXTERN) tag
2013-05-19 16:37:30 +02:00
QString setgetfieldsextern ;
for ( int n = 0 ; n < info - > fields . length ( ) ; + + n ) {
// if (!info->fields[n]->defaultValues.isEmpty() )
{
2013-09-01 13:23:20 +02:00
QString suffix = QString ( " " ) ;
if ( info - > fields [ n ] - > elementNames [ 0 ] . compare ( QString ( " 0 " ) ) ! = 0 ) {
// struct based field accessor
QString structTypeName = QString ( " %1%2Data " ) . arg ( info - > name ) . arg ( info - > fields [ n ] - > name ) ;
/* SET */
setgetfieldsextern . append ( QString ( " extern void %2%3Set(%1 *New%3); \n " )
. arg ( structTypeName )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
/* GET */
setgetfieldsextern . append ( QString ( " extern void %2%3Get(%1 *New%3); \n " )
. arg ( structTypeName )
. arg ( info - > name )
. arg ( info - > fields [ n ] - > name ) ) ;
suffix = QString ( " Array " ) ;
}
2013-05-19 16:37:30 +02:00
/* SET */
2013-09-01 13:23:20 +02:00
setgetfieldsextern . append ( QString ( " extern void %2%3%4Set(%1 *New%3); \n " )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] )
2013-05-19 16:37:30 +02:00
. arg ( info - > name )
2013-09-01 13:23:20 +02:00
. arg ( info - > fields [ n ] - > name )
. arg ( suffix ) ) ;
2013-05-19 16:37:30 +02:00
/* GET */
2013-09-01 13:23:20 +02:00
setgetfieldsextern . append ( QString ( " extern void %2%3%4Get(%1 *New%3); \n " )
2015-04-09 01:38:49 +02:00
. arg ( typeList [ n ] )
2013-05-19 16:37:30 +02:00
. arg ( info - > name )
2013-09-01 13:23:20 +02:00
. arg ( info - > fields [ n ] - > name )
. arg ( suffix ) ) ;
2013-05-19 16:37:30 +02:00
}
}
outInclude . replace ( QString ( " $(SETGETFIELDSEXTERN) " ) , setgetfieldsextern ) ;
2011-06-03 06:18:34 +02:00
2011-01-13 03:26:00 +01:00
// Write the flight code
2015-03-29 06:27:07 +02:00
bool res = writeFileIfDifferent ( flightOutputPath . absolutePath ( ) + " / " + info - > namelc + " .c " , outCode ) ;
2011-01-13 03:26:00 +01:00
if ( ! res ) {
cout < < " Error: Could not write flight code files " < < endl ;
return false ;
}
2015-03-29 06:27:07 +02:00
res = writeFileIfDifferent ( flightOutputPath . absolutePath ( ) + " / " + info - > namelc + " .h " , outInclude ) ;
2011-01-13 03:26:00 +01:00
if ( ! res ) {
cout < < " Error: Could not write flight include files " < < endl ;
return false ;
}
return true ;
}