dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobject.py
Go to the documentation of this file.
1 __all__ = ("UAVObject")
2 
3 ##
4 ##############################################################################
5 #
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
11 #
12 #############################################################################/
13 #
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.
18 #
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.
23 #
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, see <http://www.gnu.org/licenses/>
26 #
27 
28 import struct
29 from collections import namedtuple
30 
31 class UAVMetaData(object):
32  def __init__(self):
33  self.telemetryAcked = false
36  self.gcsTelemetryAcked = false
41 
42 class UAVObject(object):
43  def __init__(self, objid, name, metaname, instanceid, issingle):
44  self.objid = objid
45  self.name = name
46  self.metaname = metaname
47  self.instanceid = instanceid
48  self.issingle = issingle
49 
50  self.fields = []
51 
52  uavobjects[objid] = self
53 
54  def add_field(self, field):
55  self.fields.append(field)
56 
57  def get_struct(self):
58  fmt = "<"
59  for f in self.fields:
60  fmt += f.get_struct()
61  return struct.Struct(fmt)
62 
63  def get_tuple(self):
64  fieldnames = ' '.join([f.name for f in self.fields])
65  return namedtuple (self.name, fieldnames)
66 
67  def get_size(self):
68  return self.get_struct().size
69 
70 class UAVObjectField(object):
71  def __init__(self, fieldname, type, nelements, elemnames, values):
72  self.name = fieldname
73  self.type = type
74  self.nelements = nelements
75  self.elemnames = elemnames
76  self.values = values
77 
78  def get_struct(self):
79  fmt = ""
80  if self.nelements > 1:
81  fmt += "%u" % self.nelements
82  fmt += "%s" % (self.type)
83  return fmt
84 
85 # List of registered uavobject instances
86 uavobjects = {}
87 
88 def main():
89  pass
90 
91 if __name__ == "__main__":
92  #import pdb ; pdb.run('main()')
93  main()
def main
Definition: uavobject.py:88