From 2859abec45f5e74ae027826c3fc8f3bf20ea35f2 Mon Sep 17 00:00:00 2001
From: kruger <kruger@astron.nl>
Date: Tue, 30 Jan 2024 09:04:34 +0000
Subject: [PATCH] lmp_id script added

---
 pypcc/testing/check_ip.py | 27 ++++++++++++++++-----------
 pypcc/testing/lmp_id.py   | 18 ++++++++++++++++++
 setup.cfg                 |  1 +
 3 files changed, 35 insertions(+), 11 deletions(-)
 create mode 100644 pypcc/testing/lmp_id.py

diff --git a/pypcc/testing/check_ip.py b/pypcc/testing/check_ip.py
index 5dc0e13..cb8ee62 100644
--- a/pypcc/testing/check_ip.py
+++ b/pypcc/testing/check_ip.py
@@ -3,20 +3,25 @@ IP_APSCT_TEST='10.99.100.100'
 #IP_APSCT_subrack='10.99.x.100'
 
 import logging
-import RPi.GPIO as GPIO
 import subprocess
 
-def get_LMP_ID():
-    pins=[21,20,16,12,7,8]
-    Npins=len(pins);
-    GPIO.setmode(GPIO.BCM)
-    for i,pin in enumerate(pins):
-       GPIO.setup(pin,GPIO.IN)
+try:
+  from .lmp_id import get_LMP_ID
+except:
+  from lmp_id import get_LMP_ID
 
-    value=0;
-    for pin in pins:
-      value=2*value+1 if GPIO.input(pin) else 2*value
-    return value
+#import RPi.GPIO as GPIO
+#def get_LMP_ID():
+#    pins=[21,20,16,12,7,8]
+#    Npins=len(pins);
+#    GPIO.setmode(GPIO.BCM)
+#    for i,pin in enumerate(pins):
+#       GPIO.setup(pin,GPIO.IN)
+#
+#    value=0;
+#    for pin in pins:
+#      value=2*value+1 if GPIO.input(pin) else 2*value
+#    return value
 
 def get_eth0_ip_ifconfig():
     result=subprocess.run(['ifconfig','eth0'],stdout=subprocess.PIPE).stdout.decode()
diff --git a/pypcc/testing/lmp_id.py b/pypcc/testing/lmp_id.py
new file mode 100644
index 0000000..c0466c3
--- /dev/null
+++ b/pypcc/testing/lmp_id.py
@@ -0,0 +1,18 @@
+import RPi.GPIO as GPIO
+
+def get_LMP_ID():
+    pins=[21,20,16,12,7,8]
+    Npins=len(pins);
+    GPIO.setmode(GPIO.BCM)
+    for i,pin in enumerate(pins):
+       GPIO.setup(pin,GPIO.IN)
+
+    value=0;
+    for pin in pins:
+      value=2*value+1 if GPIO.input(pin) else 2*value
+    return value
+
+if __name__ in ['__main__','pypcc.testing.lmp_id']:
+    lmpid=get_LMP_ID()
+    print(lmpid)
+    exit(lmpid)
diff --git a/setup.cfg b/setup.cfg
index a176d71..7463ac6 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -26,6 +26,7 @@ where=.
 console_scripts =
     hwtr = pypcc.pypcc
     pitr = pypcc.testing.pitr_main
+    read_lmp_id = pypcc.testing.lmp_id
 
 
 [options.package_data]
-- 
GitLab