33 from __future__
import absolute_import, division, print_function
34 from pkg_resources
import resource_filename
38 from lxml
import etree
41 if not isinstance(value,str):
44 tmp = value.lstrip(
'0')
61 indexPoint = tmp.find(
'.')
64 numberOfDigitsAfterPoint = len(tmp) - indexPoint - 1
66 if numberOfDigitsAfterPoint > powerOf10:
68 splitPoint = len(tmp) - (numberOfDigitsAfterPoint - powerOf10)
69 tmp = tmp[0:splitPoint] +
'.' + tmp[splitPoint:]
72 tmp +=
'0' * (powerOf10 - numberOfDigitsAfterPoint)
75 tmp = tmp.replace(
'.',
'',1)
79 tmp +=
'0' * powerOf10
85 for item
in index.split(
','):
86 match = re.match(
"(\d+):(\d+)",item)
89 list(map(
lambda x: result.add(x),list(range(int(match.group(1)),int(match.group(2))+1))))
95 class TDMASchedule(object):
102 tree = etree.parse(scheduleXML)
104 root = tree.getroot()
106 schemaDoc = etree.parse(resource_filename(
'emane.events',
107 'schema/tdmaschedule.xsd'))
109 schema = etree.XMLSchema(etree=schemaDoc,attribute_defaults=
True)
113 for entry
in schema.error_log:
114 message.append(
"%d: %s" % (entry.line,entry.message))
115 print(
"\n".join(message), file=sys.stderr)
119 for structure
in root.xpath(
'/emane-tdma-schedule/structure'):
120 self.
_structure = {
'slotduration' : int(structure.get(
'slotduration')),
121 'slotoverhead' : int(structure.get(
'slotoverhead')),
122 'bandwidth' : int(
decodeSI(structure.get(
'bandwidth'))),
123 'slots' : int(structure.get(
'slots')),
124 'frames' : int(structure.get(
'frames'))}
126 def nodeDefaults(node):
127 frequency =
decodeSI(node.get(
'frequency'));
128 power = node.get(
'power')
129 serviceClass = node.get(
'class')
130 datarate =
decodeSI(node.get(
'datarate'))
133 if frequency !=
None:
134 defaults[
'frequency'] = int(frequency)
137 defaults[
'power'] = float(power)
139 if serviceClass !=
None:
140 defaults[
'service'] = int(serviceClass)
143 defaults[
'datarate'] = int(datarate)
148 multiframe = root.xpath(
'/emane-tdma-schedule/multiframe')[0]
150 defaults = nodeDefaults(multiframe)
155 for frame
in multiframe.xpath(
'frame'):
158 defaults = nodeDefaults(frame)
160 for frameIndex
in frameIndexes:
163 for slot
in frame.xpath(
'slot'):
168 args = {
'type' :
'tx'}
171 if child.tag ==
'tx':
174 frequency =
decodeSI(child.get(
'frequency'))
176 if frequency !=
None:
177 args[
'frequency'] = int(frequency)
179 power = child.get(
'power')
182 args[
'power'] = float(power)
184 serviceClass = child.get(
'class')
186 if serviceClass !=
None:
187 args[
'service'] = int(serviceClass)
190 datarate =
decodeSI(child.get(
'datarate'))
193 args[
'datarate'] = int(datarate)
195 destination = child.get(
'destination')
197 if destination !=
None:
198 args[
'destination'] = int(destination)
200 elif child.tag ==
'rx':
203 frequency =
decodeSI(child.get(
'frequency'))
205 if frequency !=
None:
206 args[
'frequency'] = int(frequency)
209 args[
'type'] =
'idle' 213 for frameIndex
in frameIndexes:
214 for slotIndex
in slotIndexes:
215 if node
not in self.
_info:
216 self.
_info[node] = {}
218 if frameIndex
not in self.
_info[node]:
219 self.
_info[node][frameIndex] = {}
221 self.
_info[node][frameIndex][slotIndex] = args
def __init__(self, scheduleXML)