From 9561105beebe1b4e8a7356b352b6f28e669655bc Mon Sep 17 00:00:00 2001
From: kruger <kruger@astron.nl>
Date: Tue, 11 Apr 2023 08:42:03 +0100
Subject: [PATCH] L2TS ADCs GPIO pin change

---
 install.sh                  | 14 +++++---------
 install_services.sh         |  7 +++++++
 pypcc/config/RECVTR_HB.yaml | 33 +++++++++++++++++++++++----------
 setip/getip.py              | 18 ++++++++++++++++++
 setip/setip.service         | 11 +++++++++++
 setip/setip.sh              | 14 ++++++++++++++
 stop_all.sh                 |  5 +++++
 7 files changed, 83 insertions(+), 19 deletions(-)
 create mode 100755 install_services.sh
 create mode 100755 setip/getip.py
 create mode 100644 setip/setip.service
 create mode 100755 setip/setip.sh
 create mode 100755 stop_all.sh

diff --git a/install.sh b/install.sh
index d93e7b4..6249379 100755
--- a/install.sh
+++ b/install.sh
@@ -1,10 +1,6 @@
 #!/bin/bash
-sudo systemctl stop recvtr.service
-sudo systemctl stop apscttr.service
-sudo systemctl stop apsputr.service
-sudo systemctl stop unb2tr.service
-sudo python3 setup.py install
-sudo systemctl start recvtr.service
-sudo systemctl start apscttr.service
-sudo systemctl start apsputr.service
-sudo systemctl start unb2tr.service
+sudo python3.11 setup.py install
+sudo systemctl restart recvtr.service
+sudo systemctl restart apscttr.service
+sudo systemctl restart apsputr.service
+sudo systemctl restart unb2tr.service
diff --git a/install_services.sh b/install_services.sh
new file mode 100755
index 0000000..cc54b0d
--- /dev/null
+++ b/install_services.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+sudo cp bin/*.service /lib/systemd/system/.
+sudo systemctl daemon-reload
+sudo systemctl enable recvtr.service
+sudo systemctl enable apscttr.service
+sudo systemctl enable apsputr.service
+sudo systemctl enable unb2tr.service
diff --git a/pypcc/config/RECVTR_HB.yaml b/pypcc/config/RECVTR_HB.yaml
index 4ebc0e8..26d41db 100644
--- a/pypcc/config/RECVTR_HB.yaml
+++ b/pypcc/config/RECVTR_HB.yaml
@@ -50,12 +50,12 @@ drivers:
  - name: SPIbb2
    type: spibitbang1
    devreg: [IO3.GPIO1,IO3.GPIO1,IO3.CONF1,IO3.GPIO2]
-   parameters: [3,2,2,1]
+   parameters: [1,2,2,1]
    parent: I2C_RCU
  - name: SPIbb3
    type: spibitbang1
    devreg: [IO3.GPIO1,IO3.GPIO1,IO3.CONF1,IO3.GPIO2]
-   parameters: [5,4,4,2]
+   parameters: [1,4,4,2]
    parent: I2C_RCU
 
 # - name: SPI3bb 
@@ -474,9 +474,22 @@ variables:
    - name: RCU_DTH_shutdown
      description: False means dither source & ADC powered on.
      driver: I2C_RCU
-     devreg:  [IO3.GPIO1,IO3.GPIO1,IO3.GPIO2]
+     devreg:  IO3.GPIO2
      width: 1
-     bitoffset: [7,6,7]
+     bitoffset: 7
+     rw:  ro
+     dtype: boolean
+     dim: 32
+#     dim2: [3,32]
+     mask: RCU_mask
+     debug: True
+
+   - name: RCU_ADC_shutdown
+     description: False means ADC powered on.
+     driver: I2C_RCU
+     devreg:  [IO3.GPIO1,IO3.GPIO1,IO3.GPIO1]
+     width: 1
+     bitoffset: [6,3,5]
      rw:  ro
      dtype: boolean
      dim: 96
@@ -511,7 +524,7 @@ variables:
      description: RCU version number
      driver: I2C_RCU
      devreg:  ROM.Version
-     width: 0x80  #16 characters
+     width: 0x100  #32 characters
      rw:  ro
      dtype: string
      dim: 32
@@ -522,7 +535,7 @@ variables:
      description: PCB number (astron.nl/webforms/IenS-Boarden/view.php?id=xxx)
      driver: I2C_RCU
      devreg:  ROM.Serial
-     width: 0x80  #16 characters
+     width: 0x100  #32 characters
      rw:  ro
      dtype: string
      dim: 32
@@ -744,8 +757,8 @@ methods:
 #     - IO3.GPIO2: 0xC7 #ADC SC=high, DTH_SDA=high
      - IO3.POL1: 0
      - IO3.POL2: 0
-     - IO3.GPIO1: 0x15 #ADC_SDIO=high, clk=low, DTH_EN=low
-     - IO3.GPIO2: 0x47 #ADC SC=high, DTH_SDA=high
+     - IO3.GPIO1: 0x15 #  x001 0101 #ADC_SDIO=high, clk=low, PWDN=low=on  DTH_EN=low
+     - IO3.GPIO2: 0x47 #  0100 0111 #ADC SC=high, DTH_SDA=high
      - IO1.GPIO1: 0x0A #0x0a = 10dB att
      - IO1.GPIO2: 0x8A #0x80 Analog on, 0x0a=10dB att
      - IO2.CONF2: 0
@@ -770,9 +783,9 @@ methods:
      - ADC3_on: 0
 #     - IO3.GPIO1: 0xD5 #DTH_EN=high -> ADCs disables
 #     - IO3.GPIO2: 0xC7 #
-     - RCU_DTH_shutdown : [1,1,1]
+     - RCU_ADC_shutdown : [1,1,1]
      - WAIT: 100         #ms to wait
-     - RCU_DTH_shutdown : [0,0,0]
+     - RCU_ADC_shutdown : [0,0,0]
 #     - IO3.GPIO1: 0x15 #DTH_EN=low -> ADC enabled
 #     - IO3.GPIO2: 0x47 
      - RCU_DTH_on: Update #check dither while giving ADCs some time to lock
diff --git a/setip/getip.py b/setip/getip.py
new file mode 100755
index 0000000..304a57d
--- /dev/null
+++ b/setip/getip.py
@@ -0,0 +1,18 @@
+#!/usr/local/bin/python3.11
+import RPi.GPIO as gpio
+
+ID_PINS = [7, 8, 16, 12, 21] # Reverse ID bits
+
+gpio.setmode(gpio.BCM)  # Set IO pins used for the APSCT-ID
+for pin in ID_PINS:
+    gpio.setup(pin, gpio.IN)
+
+bits=[gpio.input(pin) for pin in ID_PINS]
+#print(bits)
+
+loc_id=0
+for bit in bits:
+    loc_id = 2*loc_id + bit
+ip='10.99.0.%i'%(100+loc_id)
+#ip='10.87.6.213'
+print(ip)
diff --git a/setip/setip.service b/setip/setip.service
new file mode 100644
index 0000000..396f72d
--- /dev/null
+++ b/setip/setip.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=change ip address
+After=dhcpcd.service
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/root/setip/setip.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/setip/setip.sh b/setip/setip.sh
new file mode 100755
index 0000000..5f41e19
--- /dev/null
+++ b/setip/setip.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+loc_id=`/root/setip/getip.py`
+if [ -z  "$loc_id" ]
+then
+  echo "error"
+else
+  echo ifconfig eth0 $loc_id netmask 255.255.0.0
+  sleep 1
+  ifconfig eth0
+  ifconfig -v eth0 down
+  ifconfig -v eth0 $loc_id netmask 255.255.0.0
+  ifconfig -v eth0 up
+  ifconfig eth0
+fi
diff --git a/stop_all.sh b/stop_all.sh
new file mode 100755
index 0000000..f2e4baa
--- /dev/null
+++ b/stop_all.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+sudo systemctl stop recvtr.service
+sudo systemctl stop apscttr.service
+sudo systemctl stop apsputr.service
+sudo systemctl stop unb2tr.service
-- 
GitLab