EMANE  1.2.1
emane/events/antennaprofileevent.py
Go to the documentation of this file.
1 #
2 # Copyright (c) 2013-2014,2017 - Adjacent Link LLC, Bridgewater,
3 # New Jersey
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in
14 # the documentation and/or other materials provided with the
15 # distribution.
16 # * Neither the name of Adjacent Link LLC nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 #
33 
34 from . import Event
35 from . import antennaprofileevent_pb2
36 
38  IDENTIFIER = 102
39 
40  def __init__(self):
41  self._event = antennaprofileevent_pb2.AntennaProfileEvent()
42 
43  def append(self,nemId,**kwargs):
44  hasProfile = False
45  hasAzimuth = False
46  hasElevation = False
47 
48  profile = self._event.profiles.add()
49 
50  profile.nemId = nemId
51 
52  for (name,value) in list(kwargs.items()):
53 
54  if name == 'profile':
55  if isinstance(value,int):
56  hasProfile = True
57  profile.profileId = value
58  else:
59  raise ValueError("profile must be an integer")
60 
61  elif name == 'azimuth':
62  if isinstance(value,int) or \
63  isinstance(value,float):
64  hasAzimuth = True
65  profile.antennaAzimuthDegrees = value
66  else:
67  raise ValueError("azimuth must be numeric")
68 
69  elif name == 'elevation':
70  if isinstance(value,int) or \
71  isinstance(value,float):
72  hasElevation = True
73  profile.antennaElevationDegrees = value
74  else:
75  raise ValueError("elevation must be numeric")
76 
77  else:
78  raise KeyError("unknown parameter: %s" % name)
79 
80  if not (hasProfile and hasAzimuth and hasElevation):
81  raise KeyError("must specify profile, azimuth and elevation")
82 
83 
84  def serialize(self):
85  return self._event.SerializeToString()
86 
87  def restore(self,data):
88  self._event.ParseFromString(data)
89 
90  def __iter__(self):
91  for profile in self._event.profiles:
92  kwargs = {'profile': profile.profileId,
93  'azimuth' : profile.antennaAzimuthDegrees,
94  'elevation' : profile.antennaElevationDegrees}
95 
96  yield (profile.nemId,kwargs)