-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandMsg.py
296 lines (251 loc) · 7.08 KB
/
CommandMsg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#
# This class is automatically generated by mig. DO NOT EDIT THIS FILE.
# This class implements a Python interface to the 'CommandMsg'
# message type.
#
import tinyos.message.Message
# The default size of this message type in bytes.
DEFAULT_MESSAGE_SIZE = 28
# The Active Message type associated with this message.
AM_TYPE = 99
class CommandMsg(tinyos.message.Message.Message):
# Create a new CommandMsg of size 28.
def __init__(self, data="", addr=None, gid=None, base_offset=0, data_length=28):
tinyos.message.Message.Message.__init__(self, data, addr, gid, base_offset, data_length)
self.amTypeSet(AM_TYPE)
# Get AM_TYPE
def get_amType(cls):
return AM_TYPE
get_amType = classmethod(get_amType)
#
# Return a String representation of this message. Includes the
# message type name and the non-indexed field values.
#
def __str__(self):
s = "Message <CommandMsg> \n"
try:
s += " [dest=0x%x]\n" % (self.get_dest())
except:
pass
try:
s += " [id=0x%x]\n" % (self.get_id())
except:
pass
try:
s += " [payload=";
for i in range(0, 25):
s += "0x%x " % (self.getElement_payload(i) & 0xff)
s += "]\n";
except:
pass
return s
# Message-type-specific access methods appear below.
#
# Accessor methods for field: dest
# Field type: int
# Offset (bits): 0
# Size (bits): 16
#
#
# Return whether the field 'dest' is signed (False).
#
def isSigned_dest(self):
return False
#
# Return whether the field 'dest' is an array (False).
#
def isArray_dest(self):
return False
#
# Return the offset (in bytes) of the field 'dest'
#
def offset_dest(self):
return (0 / 8)
#
# Return the offset (in bits) of the field 'dest'
#
def offsetBits_dest(self):
return 0
#
# Return the value (as a int) of the field 'dest'
#
def get_dest(self):
return self.getUIntElement(self.offsetBits_dest(), 16, 1)
#
# Set the value of the field 'dest'
#
def set_dest(self, value):
self.setUIntElement(self.offsetBits_dest(), 16, value, 1)
#
# Return the size, in bytes, of the field 'dest'
#
def size_dest(self):
return (16 / 8)
#
# Return the size, in bits, of the field 'dest'
#
def sizeBits_dest(self):
return 16
#
# Accessor methods for field: id
# Field type: short
# Offset (bits): 16
# Size (bits): 8
#
#
# Return whether the field 'id' is signed (False).
#
def isSigned_id(self):
return False
#
# Return whether the field 'id' is an array (False).
#
def isArray_id(self):
return False
#
# Return the offset (in bytes) of the field 'id'
#
def offset_id(self):
return (16 / 8)
#
# Return the offset (in bits) of the field 'id'
#
def offsetBits_id(self):
return 16
#
# Return the value (as a short) of the field 'id'
#
def get_id(self):
return self.getUIntElement(self.offsetBits_id(), 8, 1)
#
# Set the value of the field 'id'
#
def set_id(self, value):
self.setUIntElement(self.offsetBits_id(), 8, value, 1)
#
# Return the size, in bytes, of the field 'id'
#
def size_id(self):
return (8 / 8)
#
# Return the size, in bits, of the field 'id'
#
def sizeBits_id(self):
return 8
#
# Accessor methods for field: payload
# Field type: short[]
# Offset (bits): 24
# Size of each element (bits): 8
#
#
# Return whether the field 'payload' is signed (False).
#
def isSigned_payload(self):
return False
#
# Return whether the field 'payload' is an array (True).
#
def isArray_payload(self):
return True
#
# Return the offset (in bytes) of the field 'payload'
#
def offset_payload(self, index1):
offset = 24
if index1 < 0 or index1 >= 25:
raise IndexError
offset += 0 + index1 * 8
return (offset / 8)
#
# Return the offset (in bits) of the field 'payload'
#
def offsetBits_payload(self, index1):
offset = 24
if index1 < 0 or index1 >= 25:
raise IndexError
offset += 0 + index1 * 8
return offset
#
# Return the entire array 'payload' as a short[]
#
def get_payload(self):
tmp = [None]*25
for index0 in range (0, self.numElements_payload(0)):
tmp[index0] = self.getElement_payload(index0)
return tmp
#
# Set the contents of the array 'payload' from the given short[]
#
def set_payload(self, value):
for index0 in range(0, len(value)):
self.setElement_payload(index0, value[index0])
#
# Return an element (as a short) of the array 'payload'
#
def getElement_payload(self, index1):
return self.getUIntElement(self.offsetBits_payload(index1), 8, 1)
#
# Set an element of the array 'payload'
#
def setElement_payload(self, index1, value):
self.setUIntElement(self.offsetBits_payload(index1), 8, value, 1)
#
# Return the total size, in bytes, of the array 'payload'
#
def totalSize_payload(self):
return (200 / 8)
#
# Return the total size, in bits, of the array 'payload'
#
def totalSizeBits_payload(self):
return 200
#
# Return the size, in bytes, of each element of the array 'payload'
#
def elementSize_payload(self):
return (8 / 8)
#
# Return the size, in bits, of each element of the array 'payload'
#
def elementSizeBits_payload(self):
return 8
#
# Return the number of dimensions in the array 'payload'
#
def numDimensions_payload(self):
return 1
#
# Return the number of elements in the array 'payload'
#
def numElements_payload():
return 25
#
# Return the number of elements in the array 'payload'
# for the given dimension.
#
def numElements_payload(self, dimension):
array_dims = [ 25, ]
if dimension < 0 or dimension >= 1:
raise IndexException
if array_dims[dimension] == 0:
raise IndexError
return array_dims[dimension]
#
# Fill in the array 'payload' with a String
#
def setString_payload(self, s):
l = len(s)
for i in range(0, l):
self.setElement_payload(i, ord(s[i]));
self.setElement_payload(l, 0) #null terminate
#
# Read the array 'payload' as a String
#
def getString_payload(self):
carr = "";
for i in range(0, 4000):
if self.getElement_payload(i) == chr(0):
break
carr += self.getElement_payload(i)
return carr