1 __all__
= ("UAVObject")
4 ##############################################################################
7 # @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
8 # @brief Base classes for python UAVObject
10 # @see The GNU Public License (GPL) Version 3
12 #############################################################################/
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 3 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write to the Free Software Foundation, Inc.,
26 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 from collections
import namedtuple
32 class UAVMetaData(object):
34 self
.telemetryAcked
= false
35 self
.telemetryUpdateMode
= 0
36 self
.telemetryUpdatePeriod
= 0
37 self
.gcsTelemetryAcked
= false
38 self
.gcsTelemetryUpdateMode
= 0
39 self
.gcsTelemetryUpdatePeriod
= 0
40 self
.loggingUpdateMode
= 0
41 self
.loggingUpdatePeriod
= 0
43 class UAVObject(object):
44 def __init__(self
, objid
, name
, metaname
, instanceid
, issingle
):
47 self
.metaname
= metaname
48 self
.instanceid
= instanceid
49 self
.issingle
= issingle
53 uavobjects
[objid
] = self
55 def add_field(self
, field
):
56 self
.fields
.append(field
)
62 return struct
.Struct(fmt
)
65 fieldnames
= ' '.join([f
.name
for f
in self
.fields
])
66 return namedtuple (self
.name
, fieldnames
)
69 return self
.get_struct().size
71 class UAVObjectField(object):
72 def __init__(self
, fieldname
, type, nelements
, elemnames
, values
):
75 self
.nelements
= nelements
76 self
.elemnames
= elemnames
81 if self
.nelements
> 1:
82 fmt
+= "%u" % self
.nelements
83 fmt
+= "%s" % (self
.type)
86 # List of registered uavobject instances
92 if __name__
== "__main__":
93 #import pdb ; pdb.run('main()')