Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / uavobjects / uavobject.py
blob2138f1f2099395de185921564e3372176a3c583e
1 __all__ = ("UAVObject")
3 ##
4 ##############################################################################
6 # @file uavobject.py
7 # @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
8 # @brief Base classes for python UAVObject
9 #
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
22 # for more details.
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
29 import struct
30 from collections import namedtuple
32 class UAVMetaData(object):
33 def __init__(self):
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):
45 self.objid = objid
46 self.name = name
47 self.metaname = metaname
48 self.instanceid = instanceid
49 self.issingle = issingle
51 self.fields = []
53 uavobjects[objid] = self
55 def add_field(self, field):
56 self.fields.append(field)
58 def get_struct(self):
59 fmt = "<"
60 for f in self.fields:
61 fmt += f.get_struct()
62 return struct.Struct(fmt)
64 def get_tuple(self):
65 fieldnames = ' '.join([f.name for f in self.fields])
66 return namedtuple (self.name, fieldnames)
68 def get_size(self):
69 return self.get_struct().size
71 class UAVObjectField(object):
72 def __init__(self, fieldname, type, nelements, elemnames, values):
73 self.name = fieldname
74 self.type = type
75 self.nelements = nelements
76 self.elemnames = elemnames
77 self.values = values
79 def get_struct(self):
80 fmt = ""
81 if self.nelements > 1:
82 fmt += "%u" % self.nelements
83 fmt += "%s" % (self.type)
84 return fmt
86 # List of registered uavobject instances
87 uavobjects = {}
89 def main():
90 pass
92 if __name__ == "__main__":
93 #import pdb ; pdb.run('main()')
94 main()