Skip to content

Commit daad0bd

Browse files
committed
Use the new PSU reader in aspSUB20. Plus, clean up some old code.
1 parent 45f39ff commit daad0bd

File tree

1 file changed

+29
-62
lines changed

1 file changed

+29
-62
lines changed

aspThreads.py

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -117,37 +117,13 @@ def monitorThread(self):
117117
self.temp[i] = entry['temp_C']
118118
else:
119119
missingSUB20 = True
120-
121-
122-
p = subprocess.Popen('/usr/local/bin/readThermometers %s' % self.sub20SN, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
123-
output, output2 = p.communicate()
124-
try:
125-
output = output.decode('ascii')
126-
output2 = output2.decode('ascii')
127-
except AttributeError:
128-
pass
129120

130-
if p.returncode != 0:
131-
aspThreadsLogger.warning("readThermometers: command returned %i; '%s;%s'", p.returncode, output, output2)
132-
self.lastError = str(output2)
133-
134-
missingSUB20 = True
135-
136-
else:
137-
for i,line in enumerate(output.split('\n')):
138-
if len(line) < 4:
139-
continue
140-
psu, desc, tempC = line.split(None, 2)
141-
self.description[i] = '%s %s' % (psu, desc)
142-
self.temp[i] = float(tempC)
143-
144121
# Open the log file and save the temps
145122
try:
146-
log = open(self.logfile, 'a+')
147-
log.write('%s,' % time.time())
148-
log.write('%s\n' % ','.join(["%.2f" % t for t in self.temp]))
149-
log.flush()
150-
log.close()
123+
with open(self.logfile, 'a+') as log:
124+
log.write('%s,' % time.time())
125+
log.write('%s\n' % ','.join(["%.2f" % t for t in self.temp]))
126+
log.flush()
151127
except IOError:
152128
aspThreadsLogger.error("%s: could not open flag logfile %s for writing", type(self).__name__, self.logfile)
153129
pass
@@ -354,40 +330,29 @@ def monitorThread(self):
354330
tStart = time.time()
355331

356332
try:
357-
missingSUB20 = False
358-
359-
p = subprocess.Popen('/usr/local/bin/readPSU %s 0x%02X' % (self.sub20SN, self.deviceAddress), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
360-
output, output2 = p.communicate()
361-
try:
362-
output = output.decode('ascii')
363-
output2 = output2.decode('ascii')
364-
except AttributeError:
365-
pass
333+
data = psuRead(self.sub20SN, self.deviceAddress)
334+
if data:
335+
missingSUB20 = False
336+
337+
self.description = '%s - %s' % (data['address'], data['description'])
338+
self.voltage = data['voltage']
339+
self.current = data['current']
340+
self.onoff = data['onoff']
341+
self.status = data['status']
342+
else:
343+
missingSUB20 = True
366344

367-
if p.returncode != 0:
368-
aspThreadsLogger.warning("readPSU: command returned %i; '%s;%s'", p.returncode, output, output2)
369345
self.voltage = 0.0
370346
self.current = 0.0
371347
self.onoff = "UNK"
372348
self.status = "UNK"
373-
self.lastError = str(output2)
374-
375-
missingSUB20 = True
376-
377-
else:
378-
psu, desc, onoffHuh, statusHuh, voltageV, currentA, = output.replace('\n', '').split(None, 5)
379-
self.description = '%s - %s' % (psu, desc)
380-
self.voltage = float(voltageV)
381-
self.current = float(currentA)
382-
self.onoff = '%-3s' % onoffHuh
383-
self.status = statusHuh
349+
self.lastError = 'No data returned'
384350

385351
try:
386-
log = open(self.logfile, 'a+')
387-
log.write('%s,' % time.time())
388-
log.write('%s\n' % ','.join(["%.2f" % self.voltage, "%.3f" % self.current, self.onoff, self.status]))
389-
log.flush()
390-
log.close()
352+
with open(self.logfile, 'a+') as log:
353+
log.write('%s,' % time.time())
354+
log.write('%s\n' % ','.join(["%.2f" % self.voltage, "%.3f" % self.current, self.onoff, self.status]))
355+
log.flush()
391356
except IOError:
392357
aspThreadsLogger.error("%s: could not open flag logfile %s for writing", type(self).__name__, self.logfile)
393358
pass
@@ -599,9 +564,10 @@ def monitorThread(self):
599564

600565
if status:
601566
try:
602-
with open(self.temp_logfile, 'a') as fh:
603-
fh.write('%s,' % time.time())
604-
fh.write('%s\n' % ','.join(['%.2f' % t for t in temps]))
567+
with open(self.temp_logfile, 'a') as log:
568+
log.write('%s,' % time.time())
569+
log.write('%s\n' % ','.join(['%.2f' % t for t in temps]))
570+
log.flush()
605571
except Exception as e:
606572
aspThreadsLogger.error("%s: monitorThread failed to update board temperature log - %s", type(self).__name__, str(e))
607573

@@ -611,9 +577,10 @@ def monitorThread(self):
611577
self.fee_currents = fees
612578

613579
try:
614-
with open(self.fee_logfile, 'a') as fh:
615-
fh.write('%s,' % time.time())
616-
fh.write('%s\n' % ','.join(['%.3f' % v for v in self.fee_currents]))
580+
with open(self.fee_logfile, 'a') as log:
581+
log.write('%s,' % time.time())
582+
log.write('%s\n' % ','.join(['%.3f' % v for v in self.fee_currents]))
583+
log.flush()
617584
except Exception as e:
618585
aspThreadsLogger.error("%s: monitorThread failed to update FEE power log - %s", type(self).__name__, str(e))
619586

@@ -633,7 +600,7 @@ def monitorThread(self):
633600
self.lastError = str(e)
634601

635602
loop_counter += 1
636-
loop_counter %= 5
603+
loop_counter %= 3
637604

638605
# Stop time
639606
tStop = time.time()

0 commit comments

Comments
 (0)