1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

uavobjects: Added support for generating python classes

The uavobjectgenerator can now generate python classes for each
UAVObject definition.  This is useful for writing simple test
applications in python that can exercise the UAVObject handling
code on the embedded boards.

This is a work in progress so the structure of the generated
classes is likely to change.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@623 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
stac 2010-05-14 04:32:30 +00:00 committed by stac
parent 0e3a5550ba
commit e05f4cf068
16 changed files with 1467 additions and 0 deletions

View File

@ -0,0 +1,161 @@
##
##############################################################################
#
# @file exampleobject1.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the ExampleObject1 object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: exampleobject1.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Field1',
'b',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field2',
'h',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field3',
'i',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field4',
'f',
4,
[
'0',
'1',
'2',
'3',
],
{
}
),
uavobject.UAVObjectField(
'Field5',
'B',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field6',
'H',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field7',
'I',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field8',
'b',
1,
[
'0',
],
{
'0' : 'Option1',
'1' : 'Option2',
}
),
]
class ExampleObject1(uavobject.UAVObject):
## Object constants
OBJID = 3852936276
NAME = "ExampleObject1"
METANAME = "ExampleObject1Meta"
ISSINGLEINST = 0
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = ExampleObject1()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,119 @@
##
##############################################################################
#
# @file exampleobject2.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the ExampleObject2 object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: exampleobject2.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Field1',
'b',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field2',
'h',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field3',
'i',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Field4',
'f',
4,
[
'0',
'1',
'2',
'3',
],
{
}
),
]
class ExampleObject2(uavobject.UAVObject):
## Object constants
OBJID = 2743296914
NAME = "ExampleObject2"
METANAME = "ExampleObject2Meta"
ISSINGLEINST = 0
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = ExampleObject2()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,108 @@
##
##############################################################################
#
# @file examplesettings.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the ExampleSettings object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: examplesettings.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'UpdatePeriod',
'i',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'StepSize',
'i',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'StepDirection',
'b',
1,
[
'0',
],
{
'0' : 'up',
'1' : 'down',
}
),
]
class ExampleSettings(uavobject.UAVObject):
## Object constants
OBJID = 1640607828
NAME = "ExampleSettings"
METANAME = "ExampleSettingsMeta"
ISSINGLEINST = 1
ISSETTINGS = 1
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = ExampleSettings()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,140 @@
##
##############################################################################
#
# @file flighttelemetrystats.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the FlightTelemetryStats object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: flighttelemetrystats.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Status',
'b',
1,
[
'0',
],
{
'0' : 'Disconnected',
'1' : 'HandshakeReq',
'2' : 'HandshakeAck',
'3' : 'Connected',
}
),
uavobject.UAVObjectField(
'TxDataRate',
'f',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'RxDataRate',
'f',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'TxFailures',
'I',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'RxFailures',
'I',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'TxRetries',
'I',
1,
[
'0',
],
{
}
),
]
class FlightTelemetryStats(uavobject.UAVObject):
## Object constants
OBJID = 1712072286
NAME = "FlightTelemetryStats"
METANAME = "FlightTelemetryStatsMeta"
ISSINGLEINST = 1
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = FlightTelemetryStats()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,140 @@
##
##############################################################################
#
# @file gcstelemetrystats.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the GCSTelemetryStats object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: gcstelemetrystats.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Status',
'b',
1,
[
'0',
],
{
'0' : 'Disconnected',
'1' : 'HandshakeReq',
'2' : 'HandshakeAck',
'3' : 'Connected',
}
),
uavobject.UAVObjectField(
'TxDataRate',
'f',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'RxDataRate',
'f',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'TxFailures',
'I',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'RxFailures',
'I',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'TxRetries',
'I',
1,
[
'0',
],
{
}
),
]
class GCSTelemetryStats(uavobject.UAVObject):
## Object constants
OBJID = 1998458950
NAME = "GCSTelemetryStats"
METANAME = "GCSTelemetryStatsMeta"
ISSINGLEINST = 1
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = GCSTelemetryStats()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,126 @@
##
##############################################################################
#
# @file gpsobject.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the GpsObject object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: gpsobject.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Latitude',
'f',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Longitude',
'f',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Altitude',
'f',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Satellites',
'b',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'Updates',
'H',
1,
[
'0',
],
{
}
),
]
class GpsObject(uavobject.UAVObject):
## Object constants
OBJID = 4217926642
NAME = "GpsObject"
METANAME = "GpsObjectMeta"
ISSINGLEINST = 1
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = GpsObject()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,123 @@
##
##############################################################################
#
# @file objectpersistence.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the ObjectPersistence object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: objectpersistence.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Operation',
'b',
1,
[
'0',
],
{
'0' : 'Load',
'1' : 'Save',
'2' : 'Delete',
}
),
uavobject.UAVObjectField(
'Selection',
'b',
1,
[
'0',
],
{
'0' : 'SingleObject',
'1' : 'AllSettings',
'2' : 'AllMetaObjects',
'3' : 'AllObjects',
}
),
uavobject.UAVObjectField(
'ObjectID',
'I',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'InstanceID',
'I',
1,
[
'0',
],
{
}
),
]
class ObjectPersistence(uavobject.UAVObject):
## Object constants
OBJID = 572614706
NAME = "ObjectPersistence"
METANAME = "ObjectPersistenceMeta"
ISSINGLEINST = 1
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = ObjectPersistence()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,95 @@
##
##############################################################################
#
# @file systemalarms.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the SystemAlarms object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: systemalarms.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Alarm',
'b',
6,
[
'OutOfMemory',
'StackOverflow',
'CPUOverload',
'EventSystem',
'SDCard',
'Telemetry',
],
{
'0' : 'OK',
'1' : 'Warning',
'2' : 'Error',
'3' : 'Critical',
}
),
]
class SystemAlarms(uavobject.UAVObject):
## Object constants
OBJID = 2311311458
NAME = "SystemAlarms"
METANAME = "SystemAlarmsMeta"
ISSINGLEINST = 1
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = SystemAlarms()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,106 @@
##
##############################################################################
#
# @file systemstats.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the SystemStats object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: systemstats.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'FlightTime',
'I',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'HeapRemaining',
'H',
1,
[
'0',
],
{
}
),
uavobject.UAVObjectField(
'CPULoad',
'B',
1,
[
'0',
],
{
}
),
]
class SystemStats(uavobject.UAVObject):
## Object constants
OBJID = 680908530
NAME = "SystemStats"
METANAME = "SystemStatsMeta"
ISSINGLEINST = 1
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = SystemStats()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,89 @@
##
##############################################################################
#
# @file telemetrysettings.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the TelemetrySettings object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: telemetrysettings.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'Speed',
'b',
1,
[
'0',
],
{
'0' : '9600',
'1' : '38400',
'2' : '57600',
}
),
]
class TelemetrySettings(uavobject.UAVObject):
## Object constants
OBJID = 2785592614
NAME = "TelemetrySettings"
METANAME = "TelemetrySettingsMeta"
ISSINGLEINST = 1
ISSETTINGS = 1
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = TelemetrySettings()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,94 @@
__all__ = ("UAVObject")
##
##############################################################################
#
# @file uavobject.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Base classes for python UAVObject
#
# @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
#
import struct
from collections import namedtuple
class UAVMetaData(object):
def __init__(self):
self.telemetryAcked = false
self.telemetryUpdateMode = 0
self.telemetryUpdatePeriod = 0
self.gcsTelemetryAcked = false
self.gcsTelemetryUpdateMode = 0
self.gcsTelemetryUpdatePeriod = 0
self.loggingUpdateMode = 0
self.loggingUpdatePeriod = 0
class UAVObject(object):
def __init__(self, objid, name, metaname, instanceid, issingle):
self.objid = objid
self.name = name
self.metaname = metaname
self.instanceid = instanceid
self.issingle = issingle
self.fields = []
uavobjects[objid] = self
def add_field(self, field):
self.fields.append(field)
def get_struct(self):
fmt = "<"
for f in self.fields:
fmt += f.get_struct()
return struct.Struct(fmt)
def get_tuple(self):
fieldnames = ' '.join([f.name for f in self.fields])
return namedtuple (self.name, fieldnames)
def get_size(self):
return self.get_struct().size
class UAVObjectField(object):
def __init__(self, fieldname, type, nelements, elemnames, values):
self.name = fieldname
self.type = type
self.nelements = nelements
self.elemnames = elemnames
self.values = values
def get_struct(self):
fmt = ""
if self.nelements > 1:
fmt += "%u" % self.nelements
fmt += "%s" % (self.type)
return fmt
# List of registered uavobject instances
uavobjects = {}
def main():
pass
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -0,0 +1,74 @@
##
##############################################################################
#
# @file $(NAMELC).py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the $(NAME) object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: $(XMLFILE).
# This is an automatically generated file.
# DO NOT modify manually.
#
# @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
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = $(DATAFIELDS)
class $(NAME)(uavobject.UAVObject):
## Object constants
OBJID = $(OBJID)
NAME = "$(NAME)"
METANAME = "$(NAME)Meta"
ISSINGLEINST = $(ISSINGLEINST)
ISSETTINGS = $(ISSETTINGS)
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = $(NAME)()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -47,6 +47,11 @@ UAVObjectGenerator::UAVObjectGenerator(QString& basepath, FILE* out) :
xmlPath = QDir( basepath + QString("ground/src/shared/uavobjectdefinition"));
flightCodePath = QDir( basepath + QString("flight/OpenPilot/UAVObjects"));
gcsCodePath = QDir( basepath + QString("ground/src/plugins/uavobjects"));
pythonTemplatePath = QDir( basepath + QString("flight/OpenPilot/UAVObjects"));
// synthetic output files should go into the build directory once the various GUI build systems
// learn how to find these output files in the build directory.
//pythonCodePath = QDir( basepath + QString("build/uavobjects"));
pythonCodePath = QDir( basepath + QString("flight/OpenPilot/UAVObjects"));
objectTemplateFilename = QString("uavobjecttemplate");
objectsInitTemplateFilename = QString("uavobjectsinittemplate");
objectsInitFilename = QString("uavobjectsinit");
@ -65,8 +70,10 @@ bool UAVObjectGenerator::processAll()
QString gcsCodeTemplate = readFile( gcsCodePath.absoluteFilePath(objectTemplateFilename + ".cpp") );
QString gcsIncludeTemplate = readFile( gcsCodePath.absoluteFilePath(objectTemplateFilename + ".h") );
QString gcsInitTemplate = readFile( gcsCodePath.absoluteFilePath(objectsInitTemplateFilename + ".cpp") );
QString pythonCodeTemplate = readFile( pythonTemplatePath.absoluteFilePath(objectTemplateFilename + ".py") );
if ( flightCodeTemplate.isNull() || flightIncludeTemplate.isNull() ||
gcsCodeTemplate.isNull() || gcsIncludeTemplate.isNull() ||
pythonCodeTemplate.isNull() ||
flightInitTemplate.isNull() || gcsInitTemplate.isNull() )
{
sout << "Error: Could not open template files." << endl;
@ -100,8 +107,10 @@ bool UAVObjectGenerator::processAll()
// Generate the code for each object and write it to the destination directory
QList<quint32> objIDList;
QString objInc;
QString pythonImport;
QString flightObjInit;
QString gcsObjInit;
QString pythonObjInit;
bool res;
for (int parseridx = 0; parseridx < parsers.length(); ++ parseridx)
{
@ -142,6 +151,14 @@ bool UAVObjectGenerator::processAll()
sout << "Error: Improperly formatted GCS object template file" << endl;
return false;
}
// Generate the Python code
QString pythonCode;
res = parser->generatePythonObject(objidx, pythonCodeTemplate, pythonCode);
if (!res)
{
sout << "Error: Improperly formatted Python object template file" << endl;
return false;
}
// Write the flight code
// TODO: Only write file if modified
res = writeFile( flightCodePath.absolutePath() + "/" + namelc + ".c", flightCode );
@ -170,10 +187,20 @@ bool UAVObjectGenerator::processAll()
sout << "Error: Could not write output files" << endl;
return false;
}
// Write the Python code
// TODO: Only write file if modified
res = writeFile( pythonCodePath.absolutePath() + "/" + namelc + ".py", pythonCode );
if (!res)
{
sout << "Error: Could not write output files" << endl;
return false;
}
// Update strings for the object initialization
objInc.append("#include \"" + namelc + ".h\"\n");
pythonImport.append("import " + namelc + "\n");
flightObjInit.append(" " + name + "Initialize();\n");
gcsObjInit.append(" objMngr->registerObject( new " + name + "() );\n");
pythonObjInit.append("\tuavobjectsinit.uavobjects.append(" + name + "." + name + "())\n");
}
}

View File

@ -45,6 +45,8 @@ private:
QDir xmlPath;
QDir flightCodePath;
QDir gcsCodePath;
QDir pythonTemplatePath;
QDir pythonCodePath;
QString objectTemplateFilename;
QString objectsInitTemplateFilename;
QString objectsInitFilename;

View File

@ -41,6 +41,10 @@ UAVObjectParser::UAVObjectParser()
QString( "quint8") << QString("quint16") << QString("quint32") <<
QString("float") << QString("quint8");
fieldTypeStrPython << QString("b") << QString("h") << QString("i") <<
QString( "B") << QString("H") << QString("I") <<
QString("f") << QString("b");
fieldTypeStrCPPClass << QString("INT8") << QString("INT16") << QString("INT32") <<
QString( "UINT8") << QString("UINT16") << QString("UINT32") <<
QString("FLOAT32") << QString("ENUM");
@ -844,3 +848,60 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
// Done
return true;
}
/**
* Generate the Python object files
*/
bool UAVObjectParser::generatePythonObject(int objIndex, const QString& templateCode, QString& outCode)
{
// Get object
ObjectInfo* info = objInfo[objIndex];
if (info == NULL) return false;
// Prepare output strings
outCode = templateCode;
// Replace common tags
replaceCommonTags(outCode, info);
// Replace the $(DATAFIELDS) tag
QString fields;
fields.append(QString("[ \\\n"));
for (int n = 0; n < info->fields.length(); ++n)
{
fields.append(QString("\tuavobject.UAVObjectField(\n"));
fields.append(QString("\t\t'%1',\n").arg(info->fields[n]->name));
fields.append(QString("\t\t'%1',\n").arg(fieldTypeStrPython[info->fields[n]->type]));
fields.append(QString("\t\t%1,\n").arg(info->fields[n]->numElements));
QStringList elemNames = info->fields[n]->elementNames;
fields.append(QString("\t\t[\n"));
for (int m = 0; m < elemNames.length(); ++m)
{
fields.append(QString("\t\t\t'%1',\n").arg(elemNames[m]));
}
fields.append(QString("\t\t],\n"));
fields.append(QString("\t\t{\n"));
if (info->fields[n]->type == FIELDTYPE_ENUM)
{
// Go through each option
QStringList options = info->fields[n]->options;
for (int m = 0; m < options.length(); ++m)
{
fields.append( QString("\t\t\t'%1' : '%2',\n")
.arg(m)
.arg( options[m] ) );
}
}
fields.append(QString("\t\t}\n"));
fields.append(QString("\t),\n"));
}
fields.append(QString("]\n"));
outCode.replace(QString("$(DATAFIELDS)"), fields);
// Done
return true;
}

View File

@ -97,12 +97,14 @@ public:
QString& outInclude, QString& outCode);
bool generateGCSObject(int objIndex, const QString& templateInclude, const QString& templateCode,
QString& outInclude, QString& outCode);
bool generatePythonObject(int objIndex, const QString& templateCode, QString& outCode);
private:
QList<ObjectInfo*> objInfo;
QString filename;
QStringList fieldTypeStrC;
QStringList fieldTypeStrCPP;
QStringList fieldTypeStrPython;
QStringList fieldTypeStrCPPClass;
QStringList fieldTypeStrXML;
QStringList updateModeStr;