Skip to content
Snippets Groups Projects
Commit 8ec769f8 authored by Arno Schoenmakers's avatar Arno Schoenmakers
Browse files

TAsk #10718: Adding scripts of Pieter for handling broken antenna information:...

TAsk #10718: Adding scripts of Pieter for handling broken antenna information: dump all from OTDB and read into station WinCC DB.
parent be7c7736
No related branches found
No related tags found
No related merge requests found
......@@ -4083,6 +4083,9 @@ MAC/Test/TestHarness/THPVSSBridge/src/THPVSSBridge_Protocol.prot -text svneol=na
MAC/Test/TestHarness/TSE/doc/OTSE-UserManual.doc -text
MAC/Test/TestHarness/TSE/doc/OTSE-UserManual.pdf -text
MAC/Test/TestHarness/TSE/scripts/demo.tar.bz2 -text
MAC/Tools/Antennas/CMakeLists.txt -text
MAC/Tools/Antennas/dumpAntennaStates.py -text
MAC/Tools/Antennas/putback_pvss.py -text
MAC/Tools/Clock/ppsctl.c -text
MAC/Tools/NTP/PPSkit-light-alpha-3932m-2.6.17.8.diff -text
MAC/Tools/NTP/kernel-2.6.18-NANO.config -text
......
# $Id: $
lofar_add_sbin_scripts(
putback_pvss.py
dumpAntennaStates.py)
#!/usr/bin/env python
#coding: iso-8859-15
import os,sys,time,pg
from optparse import OptionParser
#
# MAIN
#
if __name__ == '__main__':
"""
dumpAntennaStates dumps teh state of all antennas as set in OTDB into a
file (default file is 'hardware_states.out') so it can be used to restore
that info in a station's WinCC database. Use putback_pvss.py for that.
"""
parser = OptionParser("Usage: %prog [options]" )
parser.add_option("-D", "--database",
dest="dbName",
type="string",
default="LOFAR_4",
help="Name of OTDB database to use")
parser.add_option("-H", "--host",
dest="dbHost",
type="string",
default="sasdb.control.lofar",
help="Hostname of OTDB database")
parser.add_option("-F", "--file",
dest="outfile",
type="string",
default="/globalhome/lofarsys/AntennaInfo/hardware_states.out",
help="File to write the result to")
# parse arguments
(options, args) = parser.parse_args()
if not options.dbName:
print "Provide the name of OTDB database to use!"
print
parser.print_help()
sys.exit(0)
dbName = options.dbName
dbHost = options.dbHost
filename = options.outfile
# calling stored procedures only works from the pg module for some reason.
print "Connecting...",
otdb = pg.connect(user="postgres", host=dbHost, dbname=dbName)
print "\nQuerying database...",
HWstates = otdb.query("""select p.pvssname,k.value,k.time from pickvt k left join picparamref p on p.paramid=k.paramid
where pvssname like '%%RCU%%state' OR pvssname like '%%BA%%state' order by p.pvssname,k.time
""").dictresult()
otdb.close()
print "\nWriting file...",
file = open(filename, 'w');
for rec in HWstates:
file.write("%s | %s | %s\n" % (rec['pvssname'], rec['value'], rec['time']))
file.close()
print "\nDone"
sys.exit(0)
#! /usr/bin/python
#
# Restore a station's WinCC broken hardware info from a dumpfile
# created by dumpAntennaStates.py.
#
from time import mktime, strptime, sleep, asctime, gmtime
from subprocess import Popen, PIPE
from socket import gethostname
#station = 'CS302'
station = gethostname()[:5].upper()
f = open('/globalhome/lofarsys/AntennaInfo/hardware_states.out', 'r')
pvss_old = f.readlines()
f.close()
bad_states = {}
# LOFAR.PIC.Core.CS302.LBA094.status_state | 50 | 2013-08-14 13:30:04.508
for line in pvss_old:
if station not in line:
continue
info = line.split('|')
key_list = info[0].split('.')
key = '%s_%s_%s' % (key_list[0], key_list[1], key_list[4])
value = int(info[1].strip()[0])
timestamp_string = info[2].strip().split('.')[0]
timestamp = mktime(strptime(timestamp_string, '%Y-%m-%d %H:%M:%S'))
if key in bad_states:
if timestamp > bad_states[key]['timestamp']:
bad_states[key] = {'timestamp': timestamp, 'asctime': asctime(gmtime(timestamp)), 'value':value}
else:
bad_states[key] = {'timestamp': timestamp, 'value':value}
# put back values greeter than 10
for key, vals in sorted(bad_states.iteritems()):
if vals['value'] > 1:
print key, vals
# add extra argument to setObjectState force=true to reset failure.
cmdline = Popen(['setObjectState', 'pvss_restore', key, str(vals['value'])], stdout=PIPE, stderr=PIPE)
so, se = cmdline.communicate()
sleep(0.2)
......@@ -6,3 +6,4 @@ add_subdirectory(Clock)
add_subdirectory(NTP)
add_subdirectory(Rubidium)
add_subdirectory(Power)
add_subdirectory(Antennas)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment