-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgen_schedule_sf.py
executable file
·692 lines (649 loc) · 22.6 KB
/
gen_schedule_sf.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# History:
# 2016-Mar-08 DG
# Started this history log. Made maximum delay 16000, to reflect
# new maximum in the 16-ant correlator design.
# 2017-Mar-05 DG
# Made maximum delay 32000, to reflect new maximum in the now-working
# 300 MHz correlator.
#
import struct
import numpy as np
def gen_schedule_sf(sf_dict,mk_xml=False):
'''Writes the schedule stateframe items from the stateframe dictionary
created by the schedule. Optionally creates the corresponding XML
file but always returns its file name (in xmlfile in the /tmp directory).
Also returns the binary data buffer (buf), and format string (fmt).
The format string fmt can be used with struct.unpack() to read
the data from buf, although that usage is not anticipated except
for testing.
This routine does something sensible even if the supplied
dictionary sf_dict is empty (i.e. is {}).
'''
dtor = np.pi/180.
xmlfile = '/tmp/schedule_stateframe.xml'
if mk_xml:
xml = open(xmlfile,'w')
xml.write('<Cluster>\n')
xml.write('<Name>Data</Name>\n')
xml.write('<NumElts>13</NumElts>\n')
# Schedule_Timestamp (double) [s, in LabVIEW format]
# To be compatible with other timestamps in the stateframe, this
# will be in LabVIEW format, which is s since 1904/01/01 (don't ask).
# It is the time (should be exact second, no microseconds) for
# which the UVW coordinates and Delays are calculated.
item = sf_dict.get('timestamp',0.0)
fmt = '<d'
buf = struct.pack('d',item)
if mk_xml:
xml.write('<DBL>\n')
xml.write('<Name>Timestamp</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</DBL>\n')
# Schedule version (double) [N/A]
# Version of the schedule stateframe.
item = sf_dict.get('Version',0.4)
fmt += 'd'
buf += struct.pack('d',item)
if mk_xml:
xml.write('<DBL>\n')
xml.write('<Name>Version</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</DBL>\n')
# Scan_State (unsigned integer bool)
# Flag (=1 to indicate that DPP should be recording data, =0 otherwise)
item = sf_dict.get('scan_state',0)
fmt += 'i'
buf += struct.pack('i',item)
if mk_xml:
xml.write('<I32>\n')
xml.write('<Name>ScanState</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</I32>\n')
# Phase_Tracking (unsigned integer bool)
# Flag (=1 to indicate that uvw coordinates are valid, =0 otherwise)
item = sf_dict.get('phase_tracking',0)
fmt += 'I'
buf += struct.pack('I',item)
if mk_xml:
xml.write('<U32>\n')
xml.write('<Name>PhaseTracking</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
# UVW (3 x 16 array of doubles) [ns]
# u, v, w coordinates for each antenna, relative to antenna 1.
# Default is array of zeros (=> not tracking phase center)
item = sf_dict.get('uvw',np.array([[0.0,0.0,0.0]]*16))
# Write dimensions into data stream
fmt += 'II'
buf += struct.pack('II',3,16)
fmt += str(3*16)+'d'
for i in range(16):
buf += struct.pack('3d',item[i,0],item[i,1],item[i,2])
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>UVW</Name>\n')
xml.write('<Dimsize>3</Dimsize><Dimsize>16</Dimsize>\n<DBL>\n<Name></Name>\n<Val></Val>\n</DBL>\n')
xml.write('</Array>\n')
# Delay (length 16 x 2 array of doubles) [ns]
# Geometric delay (-w coordinate) for each antenna, relative to antenna 1,
# for current time (stateframe timestamp), and again for current time plus
# 1 s (delay1).
# Default is array of zeros (=> not tracking phase center)
# Write dimensions into data stream
fmt += 'II'
buf += struct.pack('II',16,2)
item = sf_dict.get('delay',np.zeros(16))
fmt += '32d'
for i in item:
buf += struct.pack('d',i)
item = sf_dict.get('delay1',np.zeros(16))
for i in item:
buf += struct.pack('d',i)
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>Delay</Name>\n')
xml.write('<Dimsize>16</Dimsize><Dimsize>2</Dimsize>\n<DBL>\n<Name></Name>\n<Val></Val>\n</DBL>\n')
xml.write('</Array>\n')
# Azimuth (length 16 array of doubles) [radians]
# Current azimuth pointing for each antenna
# Default is zero for any missing antennas
fmt += 'I'
buf += struct.pack('I',16)
item = sf_dict.get('ActualAzimuth',np.zeros(15))*dtor # Convert degrees to radians
if len(item) == 15:
item = np.append(item,0.0) # Add antenna 16, whose Az position is zero by definition
fmt += '16d'
for i in item:
buf += struct.pack('d',i)
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>Azimuth</Name>\n')
xml.write('<Dimsize>16</Dimsize>\n<DBL>\n<Name></Name>\n<Val></Val>\n</DBL>\n')
xml.write('</Array>\n')
# Elevation (length 16 array of doubles) [radians]
# Current elevation pointing for each antenna
# Default is zero for any missing antennas
fmt += 'I'
buf += struct.pack('I',16)
item = sf_dict.get('ActualElevation',np.zeros(15))*dtor # Convert degrees to radians
if len(item) == 15:
item = np.append(item,0.0) # Add antenna 16, whose El position is zero by definition
fmt += '16d'
for i in item:
buf += struct.pack('d',i)
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>Elevation</Name>\n')
xml.write('<Dimsize>16</Dimsize>\n<DBL>\n<Name></Name>\n<Val></Val>\n</DBL>\n')
xml.write('</Array>\n')
# Chi (length 16 array of doubles) [radians]
# Current parallactic angle for each antenna
# Default is zero for any missing antennas
fmt += 'I'
buf += struct.pack('I',16)
item = sf_dict.get('ParallacticAngle',np.zeros(15))*dtor # Convert degrees to radians
item = np.append(item,0.0) # Add antenna 16, whose parallactic angle is zero by definition
fmt += '16d'
for i in item:
buf += struct.pack('d',i)
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>Chi</Name>\n')
xml.write('<Dimsize>16</Dimsize>\n<DBL>\n<Name></Name>\n<Val></Val>\n</DBL>\n')
xml.write('</Array>\n')
# Antenna Tracking (unsigned integer bool array)
# Flags (=1 to indicate that antenna is tracking)
item = sf_dict.get('TrackFlag',np.array([False]*16))
# Write dimension (16) into data stream
fmt += 'I'
buf += struct.pack('I',16)
fmt += '16I'
for i in item:
buf += struct.pack('I',i)
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>TrackFlag</Name>\n')
xml.write('<Dimsize>16</Dimsize>\n<U32>\n<Name></Name>\n<Val></Val>\n</U32>\n')
xml.write('</Array>\n')
# XML encapsulation of weather info
if mk_xml:
xml.write('<Cluster>\n')
xml.write('<Name>Weather</Name>\n')
xml.write('<NumElts>10</NumElts>\n')
# Wind (float) [mph]
# Current "instantaneous" wind speed
# Default is zero
# item = sf_dict.get('Wind Speed',0.0)
item = sf_dict.get('mtWindSpeed',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>Wind</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# Wind_Direction (float) [radians]
# Current "instantaneous" wind direction +ve East of North
# Default is zero
# item = sf_dict.get('Adjusted Wind Direction',0.0)
item = sf_dict.get('mtAdjWindDir',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
item = item*dtor
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>WindDirection</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# AvgWind (float) [mph]
# 10-min rolling average wind speed
# Default is zero
# item = sf_dict.get('2m Wind Speed',0.0)
item = sf_dict.get('mt2MinRollAvgWindSpeed',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>AvgWind</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# AvgWind_Direction (float) [radians]
# 10-min rolling average wind direction +ve East of North
# Default is zero
# item = sf_dict.get('2m Wind Direction',0.0)
item = sf_dict.get('mt2MinRollAvgWindDir',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
item = item*dtor
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>AvgWindDirection</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# AvgWind_Gust (float) [mph]
# 10-min rolling max wind speed
# Default is zero
# item = sf_dict.get('10m Wind Gust Speed',0.0)
item = sf_dict.get('mt10MinWindGustSpeed',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
item = item
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>AvgWindGust</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# Temperature (float) [degrees F]
# Current air temperature
# Default is zero
# item = sf_dict.get('Temperature',0.0)
item = sf_dict.get('mtTemp1',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>Temperature</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# Pressure (float) [mbar]
# Current air pressure
# Default is zero
# item = sf_dict.get('Raw Barometric Pressure',0.0)
item = sf_dict.get('mtRawBaromPress',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>Pressure</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# Humidity (float) [percent]
# Current relative humidity
# Default is zero
# item = sf_dict.get('Relative Humidity',0.0)
item = sf_dict.get('mtRelHumidity',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>Humidity</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# Rain_Rate (float) [inches/hour]
# Running 5-min rate of rainfall
# Default is zero
# item = sf_dict.get('Rain Rate',0.0)
item = sf_dict.get('mtRainRate',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>RainRate</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
# Rain_Today (float) [inches]
# Rainfall in past 24-h
# Default is zero
# item = sf_dict.get('Rain Today',0.0)
item = sf_dict.get('mtRainToday',0.0)
try:
item = float(item)
except ValueError:
item = 0.0
fmt += 'f'
buf += struct.pack('f',item)
if mk_xml:
xml.write('<SGL>\n')
xml.write('<Name>RainToday</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
if mk_xml:
# End Weather Cluster
xml.write('</Cluster>\n')
# XML encapsulation of solar power station info (array of 2)
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>SolarPower</Name>\n')
xml.write('<Dimsize>2</Dimsize>\n')
# Put array dimension into data
fmt += 'I'
buf += struct.pack('I',2)
# This is an array, but the definitions only go in once
# Here are the definitions for the 8 elements in the cluster
if mk_xml:
xml.write('<Cluster>\n')
xml.write('<Name/>\n')
xml.write('<NumElts>8</NumElts>\n')
xml.write('<DBL>\n')
xml.write('<Name>Timestamp</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</DBL>\n')
xml.write('<U32>\n')
xml.write('<Name>Charge</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<SGL>\n')
xml.write('<Name>Volts</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Amps</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<I32>\n')
xml.write('<Name>AmpHours</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</I32>\n')
xml.write('<I32>\n')
xml.write('<Name>BatteryTemp</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</I32>\n')
xml.write('<I32>\n')
xml.write('<Name>TransformerTemp</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</I32>\n')
xml.write('<I32>\n')
xml.write('<Name>FETTemp</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</I32>\n')
# End SolarPower Cluster
xml.write('</Cluster>\n')
# Get the solar power array of dictionaries (defaults to two empty dicts)
solpwr = sf_dict.get('SolPwr',[{},{}])
# The actual data has to go in twice
for i in range(2):
# Solar Power Timestamp (double) [s, in LabVIEW format]
# Time that data were reported, in seconds since 1904 Jan 1
# Default is zero
item = solpwr[i].get('Time',0.0)
fmt += 'd'
buf += struct.pack('d',item)
# Charge (unsigned int) [% of full charge]
# Default is zero
item = solpwr[i].get('Charge',0)
fmt += 'I'
buf += struct.pack('I',item)
# Volts (float) [DC voltage]
# Default is zero
item = solpwr[i].get('Volts',0.0)
fmt += 'f'
buf += struct.pack('f',item)
# Amps (float) [DC amps]
# Default is zero
item = solpwr[i].get('Amps',0.0)
fmt += 'f'
buf += struct.pack('f',item)
# AmpHours (int) [Charge available]
# Default is zero
item = solpwr[i].get('AmpHours',0.0)
fmt += 'i'
buf += struct.pack('i',item)
# BatteryTemp (int) [degrees C]
# Battery Temperature in degrees C
# Default is zero
item = solpwr[i].get('BatteryTemp',0)
fmt += 'i'
buf += struct.pack('i',item)
# TransformerTemp (int) [degrees C]
# Transformer Temperature in degrees C
# Default is zero
item = solpwr[i].get('TransformerTemp',0)
fmt += 'i'
buf += struct.pack('i',item)
# FETTemp (int) [degrees C]
# FET Temperature in degrees C
# Default is zero
item = solpwr[i].get('FETTemp',0)
fmt += 'i'
buf += struct.pack('i',item)
if mk_xml:
# End SolarPower Array
xml.write('</Array>\n')
# XML encapsulation of roach info (array of 8)
if mk_xml:
xml.write('<Array>\n')
xml.write('<Name>Roach</Name>\n')
xml.write('<Dimsize>8</Dimsize>\n')
# Put array dimension into data
fmt += 'I'
buf += struct.pack('I',8)
# This is an array, but the definitions only go in once
# Here are the definitions for the 8 elements in the cluster
if mk_xml:
xml.write('<Cluster>\n')
xml.write('<Name/>\n')
xml.write('<NumElts>30</NumElts>\n')
xml.write('<U32>\n')
xml.write('<Name>Status</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<SGL>\n')
xml.write('<Name>Current.12v</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Current.1v</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Current.1v5</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Current.1v8</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Current.2v5</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Current.3v3</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Current.5v</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<U32>\n')
xml.write('<Name>Fan.chs0</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<U32>\n')
xml.write('<Name>Fan.csh1</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<U32>\n')
xml.write('<Name>Fan.csh2</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<U32>\n')
xml.write('<Name>Fan.fpga</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<SGL>\n')
xml.write('<Name>Temp.ambient</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Temp.fpga</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Temp.inlet</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Temp.outlet</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Temp.ppc</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.12v</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.1v</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.1v5</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.1v8</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.2v5</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.3v3</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.3v3aux</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.5v</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<SGL>\n')
xml.write('<Name>Voltage.5vaux</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</SGL>\n')
xml.write('<U32>\n')
xml.write('<Name>Delay0x</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<U32>\n')
xml.write('<Name>Delay0y</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<U32>\n')
xml.write('<Name>Delay1x</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
xml.write('<U32>\n')
xml.write('<Name>Delay1y</Name>\n')
xml.write('<Val></Val>\n')
xml.write('</U32>\n')
# End Roaches Cluster
xml.write('</Cluster>\n')
# Get the roach array of dictionaries (defaults to eight empty dicts)
sensors = sf_dict.get('sensors',[{},{},{},{},{},{},{},{}])
delays = sf_dict.get('delays',[{},{},{},{},{},{},{},{}])
# The actual data has to go in eight times
for i in range(8):
# Handle case of empty dictionary
if sensors[i] == {}:
fmt += 'IfffffffIIIIffffffffffffff'
buf += struct.pack('I',0)
for j in range(7):
buf += struct.pack('f',0.0)
for j in range(4):
buf += struct.pack('I',0)
for j in range(14):
buf += struct.pack('f',0.0)
else:
# Status (int) [bit list]
# Each bit signifies whether corresponding sensor is nominal [0] or in error [1]
# Order is alphabetical, msb to lsb.
# Default is zero
status = 0
keys = sorted(sensors[i].keys())
for key in keys:
if key.find('status') != -1:
if sensors[i][key] == 'nominal':
status = status<<1
else:
status = (status<<1) + 1
item = status
fmt += 'I'
buf += struct.pack('I',item)
# Just add the sorted list of sensors
# Default is zero
for key in keys:
if key.find('status') == -1:
item = sensors[i][key]
if key.find('fan') == -1:
# This is not a fan, so type is float (SGL)
fmt += 'f'
buf += struct.pack('f',item)
else:
# This is a fan, so type is uint (U32)
fmt += 'I'
buf += struct.pack('I',item)
# Handle case of empty dictionary
if delays[i] == {}:
fmt += 'IIII'
for j in range(4):
buf += struct.pack('I',0)
else:
# Not empty, so add delays
# Default is zero
item = delays[i].get('dx0',0.0)
fmt += 'I'
item = np.clip(item,0,32000)
buf += struct.pack('I',item)
item = delays[i].get('dy0',0.0)
fmt += 'I'
item = np.clip(item,0,32000)
buf += struct.pack('I',item)
item = delays[i].get('dx1',0.0)
fmt += 'I'
item = np.clip(item,0,32000)
buf += struct.pack('I',item)
item = delays[i].get('dy1',0.0)
fmt += 'I'
item = np.clip(item,0,32000)
buf += struct.pack('I',item)
if mk_xml:
# End Roach Array
xml.write('</Array>\n')
if mk_xml:
# End Schedule Cluster
xml.write('</Cluster>\n')
xml.close()
return fmt, buf, xmlfile