From 3f53d5a746a7101cdc8791dc10489d5287dce1f4 Mon Sep 17 00:00:00 2001
From: kruger <kruger@astron.nl>
Date: Wed, 3 Feb 2021 16:59:36 +0100
Subject: [PATCH] test scripts

---
 scripts/ADCreset.py    | 13 +++++++++
 scripts/Att.py         | 20 ++++++++++++++
 scripts/LED.py         | 18 ++++++++++++
 scripts/RCUupdate.py   |  8 ++++++
 scripts/SetHBA_BF.py   | 27 ++++++++++++++++++
 scripts/SetHBA_LED.py  | 26 +++++++++++++++++
 scripts/SetMonitor.py  | 10 +++++++
 scripts/test_common.py | 63 ++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 185 insertions(+)
 create mode 100644 scripts/ADCreset.py
 create mode 100644 scripts/Att.py
 create mode 100644 scripts/LED.py
 create mode 100644 scripts/RCUupdate.py
 create mode 100644 scripts/SetHBA_BF.py
 create mode 100644 scripts/SetHBA_LED.py
 create mode 100644 scripts/SetMonitor.py
 create mode 100644 scripts/test_common.py

diff --git a/scripts/ADCreset.py b/scripts/ADCreset.py
new file mode 100644
index 0000000..b0f208a
--- /dev/null
+++ b/scripts/ADCreset.py
@@ -0,0 +1,13 @@
+from test_common import *
+
+RCUs=[0];
+setRCUmask(RCUs)
+
+callmethod("RCU_off")
+time.sleep(1)
+callmethod("RCU_on")
+callmethod("RCU_on")
+time.sleep(1)
+callmethod("ADC_on")
+
+disconnect();
diff --git a/scripts/Att.py b/scripts/Att.py
new file mode 100644
index 0000000..91fcf28
--- /dev/null
+++ b/scripts/Att.py
@@ -0,0 +1,20 @@
+from test_common import *
+
+name="RCU_attenuator"
+RCU=0;
+Att=[5,5,5]
+
+
+setAntmask([RCU])
+
+att=get_value(name+"_R")
+print("Att old:",att[3*RCU:3*RCU+3])
+
+att[3*RCU:3*RCU+3]=Att
+set_value(name+"_RW",att)
+
+time.sleep(0.5)
+att=get_value(name+"_R")
+print("Att new:",att[3*RCU:3*RCU+3])
+
+disconnect()
\ No newline at end of file
diff --git a/scripts/LED.py b/scripts/LED.py
new file mode 100644
index 0000000..acb861c
--- /dev/null
+++ b/scripts/LED.py
@@ -0,0 +1,18 @@
+from test_common import *
+
+name="RCU_LED0"
+RCU=0;
+LEDvalue=0;
+
+setRCUmask([RCU])
+
+led=get_value(name+"_R")
+print("LED old:",led)
+led[RCU]=LEDvalue
+
+set_value(name+"_RW",led)
+time.sleep(0.1)
+
+print("LED new:",get_value(name+"_R"))
+
+disconnect()
diff --git a/scripts/RCUupdate.py b/scripts/RCUupdate.py
new file mode 100644
index 0000000..42dde84
--- /dev/null
+++ b/scripts/RCUupdate.py
@@ -0,0 +1,8 @@
+from test_common import *
+
+RCUs=[0];
+setRCUmask(RCUs)
+
+callmethod("RCU_update")
+
+disconnect();
\ No newline at end of file
diff --git a/scripts/SetHBA_BF.py b/scripts/SetHBA_BF.py
new file mode 100644
index 0000000..263e91c
--- /dev/null
+++ b/scripts/SetHBA_BF.py
@@ -0,0 +1,27 @@
+RCU=0
+HBAT=1 #HBAT on RCU 0..2
+HBA=5; #HBA Element in HBAT
+BFX=11 #delay in 0.5ns
+BFY=BFX+1
+name="HBA_element_beamformer_delays"
+
+from test_common import *
+import numpy as np
+
+AntMask=[(x==HBAT) for x in range(3)]
+setAntmask([RCU],AntMask)
+
+i=(RCU*3+HBAT)*32+HBA*2
+
+val=get_value(name+"_R")
+print("old:",val[i:i+2])
+
+val[i]=BFX
+val[i+1]=BFY
+
+set_value(name+"_RW",val)
+time.sleep(1)
+val=get_value(name+"_R")
+print("new:",val[i:i+2])
+
+disconnect()
diff --git a/scripts/SetHBA_LED.py b/scripts/SetHBA_LED.py
new file mode 100644
index 0000000..5cfc1b1
--- /dev/null
+++ b/scripts/SetHBA_LED.py
@@ -0,0 +1,26 @@
+RCU=0
+HBAT=1 #HBAT on RCU 0..2
+HBA=5; #HBA Element in HBAT
+LED=1 #on
+name="HBA_element_led"
+
+from test_common import *
+import numpy as np
+
+AntMask=[(x==HBAT) for x in range(3)]
+setAntmask([RCU],AntMask)
+
+i=(RCU*3+HBAT)*32+HBA*2
+
+val=get_value(name+"_R")
+print("old:",val[i:i+2])
+
+val[i]=LED #Not needed for LED
+val[i+1]=LED
+
+set_value(name+"_RW",val)
+time.sleep(1)
+val=get_value(name+"_R")
+print("new:",val[i:i+2])
+
+disconnect()
diff --git a/scripts/SetMonitor.py b/scripts/SetMonitor.py
new file mode 100644
index 0000000..fa97710
--- /dev/null
+++ b/scripts/SetMonitor.py
@@ -0,0 +1,10 @@
+from test_common import *
+
+rate= 60 #seconds
+name="RCU_monitor_rate_RW"
+
+print("old:",get_value(name))
+set_value(name,rate)
+print("new:",get_value(name))
+
+disconnect()
diff --git a/scripts/test_common.py b/scripts/test_common.py
new file mode 100644
index 0000000..40d6ba1
--- /dev/null
+++ b/scripts/test_common.py
@@ -0,0 +1,63 @@
+Address="opc.tcp://odroidRCU2:4842/"
+import sys
+sys.path.insert(0, "..")
+import logging
+import time
+
+from opcua import Client
+from opcua import ua
+#import numpy as np
+
+def connect():
+    global client,root
+#    logging.basicConfig(level=logging.INFO)
+    logging.basicConfig(level=logging.WARN)
+#    client = Client("opc.tcp://localhost:4840/freeopcua/server/")
+    client = Client(Address)
+    client.connect()
+    client.load_type_definitions()  # load definition of server specific structures/extension objects
+    root = client.get_root_node()
+    return root
+
+root=connect()
+
+def disconnect():
+    client.disconnect()
+
+def get_value(name):
+  var1 = root.get_child(["0:Objects", "2:PCC", "2:"+name])
+  return var1.get_value()
+
+def set_value(name,value):
+  var1 = root.get_child(["0:Objects", "2:PCC", "2:"+name])
+  var1.set_value(value)
+
+def setRCUmask(rcu=[]):
+    name="RCU_mask_RW"
+    M=get_value(name)
+    print(name," old:",M)
+    M=[0 for m in M]
+    for r in rcu:
+        M[r]=1
+    set_value(name,M)
+    print(name," new:",get_value(name))
+
+def setAntmask(rcu=[],ant=[True,True,True]):
+    name="Ant_mask_RW"
+    M=get_value(name)
+    print(name," old:",M)
+    for i,j in enumerate(M):
+      M[i]=False
+    for r in rcu:
+      for i in range(3):
+         M[r*3+i]=ant[i]
+    set_value(name,M)
+    print(name," new:",get_value(name))
+
+def callmethod(name):
+          try:
+            obj = root.get_child(["0:Objects", "2:PCC"])#
+            return obj.call_method("2:"+name)
+          except:
+#            print("error")
+            return None
-- 
GitLab