EMANE  1.2.1
emane/ota/otamessage.py
Go to the documentation of this file.
1 #
2 # Copyright (c) 2014,2017 - Adjacent Link LLC, Bridgewater, New Jersey
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in
13 # the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Adjacent Link LLC nor the names of its
16 # contributors may be used to endorse or promote products derived
17 # from this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31 #
32 
33 from . import otaheader_pb2
34 from . import commonphyheader_pb2
35 import uuid
36 import struct
37 
38 class OTAMessage:
39  def __init__(self,
40  source,
41  destination,
42  registrationId,
43  subId,
44  bandwidthHz,
45  transmitters,
46  segments,
47  fixedAntennaGain = None):
48 
49  self._sequence = 0
50  self._otaHeader = otaheader_pb2.OTAHeader()
51  self._otaHeader.source = source
52  self._otaHeader.destination = destination
53  self._otaHeader.payloadInfo.eventLength = 0
54  self._otaHeader.payloadInfo.controlLength = 2
55  self._otaHeader.payloadInfo.dataLength = 0
56 
57  self._phyHeader = commonphyheader_pb2.CommonPHYHeader()
58  self._phyHeader.registrationId = registrationId;
59  self._phyHeader.subId = subId;
60  self._phyHeader.bandwidthHz = bandwidthHz;
61 
62  if fixedAntennaGain is not None:
63  self._phyHeader.fixedAntennaGain = fixedAntennaGain
64 
65  for nemId,powerdBm in transmitters:
66  transmitter = self._phyHeader.transmitters.add()
67  transmitter.nemId = nemId
68  transmitter.powerdBm = powerdBm
69 
70  for frequencyHz, offsetMicroseconds, durationMicroseconds in segments:
71  segment = self._phyHeader.frequencySegments.add()
72  segment.frequencyHz = frequencyHz
73  segment.offsetMicroseconds = offsetMicroseconds
74  segment.durationMicroseconds = durationMicroseconds
75 
76  def generate(self,txTimeMicroseconds,sequence,uuid):
77  self._otaHeader.uuid = uuid.bytes
78  self._otaHeader.sequence = sequence
79  self._phyHeader.sequenceNumber = self._sequence;
80  self._sequence += 1
81  self._phyHeader.txTimeMicroseconds = txTimeMicroseconds;
82 
83  phyHeader = self._phyHeader.SerializeToString()
84 
85  self._otaHeader.payloadInfo.dataLength = len(phyHeader) + 2;
86 
87  otaHeader = self._otaHeader.SerializeToString()
88 
89  return "".join((struct.pack("!H",len(otaHeader)),
90  otaHeader,
91  # PartInfo: no more parts, offset 0, size
92  struct.pack("!BII",
93  0,
94  0,
95  self._otaHeader.payloadInfo.dataLength +
96  self._otaHeader.payloadInfo.controlLength +
97  self._otaHeader.payloadInfo.eventLength),
98  struct.pack("!H",0),
99  struct.pack("!H",len(phyHeader)),
100  phyHeader))
def generate(self, txTimeMicroseconds, sequence, uuid)
def __init__(self, source, destination, registrationId, subId, bandwidthHz, transmitters, segments, fixedAntennaGain=None)