diff --git a/bin/pitr.service b/bin/pitr.service new file mode 100644 index 0000000000000000000000000000000000000000..d6a1a6bc3d864ae2702917d64b7097ab08bae3d2 --- /dev/null +++ b/bin/pitr.service @@ -0,0 +1,11 @@ +[Unit] +Description=pi translator +After=multi-user.target +#After=network-online.target + +[Service] +Type=simple +ExecStart=pitr + +[Install] +WantedBy=multi-user.target diff --git a/install_services.sh b/install_services.sh index cc54b0d9595f67bb145dbc8048833e016e21bfc9..df1da9754cecd6ef4717ed54e0d751f442c84c23 100755 --- a/install_services.sh +++ b/install_services.sh @@ -1,7 +1,8 @@ #!/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 +sudo systemctl enable pitr.service +#sudo systemctl enable recvtr.service +#sudo systemctl enable apscttr.service +#sudo systemctl enable apsputr.service +#sudo systemctl enable unb2tr.service diff --git a/install_services_ccd.sh b/install_services_ccd.sh index 69f044bbe508892135616aae6211bc3f1d09a528..9e28488d95e9f30faf583ff729a9cfb0c9226697 100755 --- a/install_services_ccd.sh +++ b/install_services_ccd.sh @@ -1,4 +1,5 @@ #!/bin/bash sudo cp bin/*.service /lib/systemd/system/. sudo systemctl daemon-reload +sudo systemctl enable pitr.service sudo systemctl enable ccdtr.service diff --git a/pypcc/check_ip.py b/pypcc/check_ip.py new file mode 100644 index 0000000000000000000000000000000000000000..5dc0e134b299263d3286b660ac35fddfb76f28da --- /dev/null +++ b/pypcc/check_ip.py @@ -0,0 +1,74 @@ +IP_CCD= '10.99.250.90' +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) + + 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() + result=result.split('\n')[1].split() +# print(result) + if result[0]=='inet': return result[1] + return None + +def get_eth0_ip(): + result=subprocess.run(['grep','static ip_address=10.99','/etc/dhcpcd.conf'],stdout=subprocess.PIPE).stdout.decode() + for line in result.split('\n'): + line=line.split(' ') + if (len(line)==0) or not(line[0]=='static'): continue + line=line[1].split('='); + if len(line)<2: continue + line=line[1].split('/')[0] + return line +# if result[0]=='inet': return result[1] + return None + +def replace_IP(old,new): + s="sudo sed -i ""s/%s/%s/g"" /etc/dhcpcd.conf" % (old,new) + logging.info(s) + subprocess.run(s.split(' ')) + result=subprocess.run(['grep',new,'/etc/dhcpcd.conf'],stdout=subprocess.PIPE).stdout.decode() + if len(result.split('\n'))!=2: + logging.error("IP replacement error") + return + logging.info("Restart eth0") + subprocess.run(['sudo','ifconfig','eth0','down']) +# sleep(1) + subprocess.run(['sudo','ifconfig','eth0','up']) + + +def check_ip(): + ip_current=get_eth0_ip() + logging.info("current IP="+str(ip_current)) + ID=get_LMP_ID() + logging.info("LMP id="+hex(ID)) + + ip_new=IP_CCD #default (CCD) + if ID==0x3F: #APSCT in test setup + ip_new=IP_APSCT_TEST + logging.info("APSCT test setup, ip=%s"%ip_new) + if ID in [0,1,2,3]: #APSCT in subrack + ip_new='10.99.%i.100'%ID + logging.info("APSCT subrack, ip=%s"%ip_new) + + if (ip_new!=ip_current) and not(ip_current is None): + logging.warning("Change IP to %s"%ip_new) + replace_IP(ip_current,ip_new) +#print(get_value()); +if __name__=='__main__': + logging.getLogger().setLevel('INFO') + check_ip() diff --git a/pypcc/config/APSCTTR_L2TS1.yaml b/pypcc/config/APSCTTR_L2TS1.yaml index 512d1caad9b7a5271f29e9f298ff2df848c8bff1..0b1dc87f79542ce73622cff56e1fed881edbf1be 100644 --- a/pypcc/config/APSCTTR_L2TS1.yaml +++ b/pypcc/config/APSCTTR_L2TS1.yaml @@ -1,5 +1,6 @@ version: "1.0" description: "1234" +name: "APSCTTR" drivers: - name: I2C diff --git a/pypcc/config/UNB2TR_L2TS1.yaml b/pypcc/config/UNB2TR_L2TS1.yaml index a804f92b67ee2bd98dc848de9517ba41e2b300f5..55222b007e11a61f311e8d498e9ff838ac0fa7cc 100644 --- a/pypcc/config/UNB2TR_L2TS1.yaml +++ b/pypcc/config/UNB2TR_L2TS1.yaml @@ -1,5 +1,6 @@ version: "0.0" description: "UNB2 DTS first draft" +name: "UNB2TR" drivers: - name: I2C1 diff --git a/pypcc/pytr.py b/pypcc/pitr.py similarity index 91% rename from pypcc/pytr.py rename to pypcc/pitr.py index 31c0af6d59aac1e8e4742039bb0ac9cc5a05e515..62c4ee2246c80b2a8fd0dc2eec2baae25a4d7e98 100644 --- a/pypcc/pytr.py +++ b/pypcc/pitr.py @@ -4,11 +4,16 @@ import subprocess import signal import logging from queue import Queue +from pypcc.check_ip import check_ip port=4899 logging.basicConfig(encoding='utf-8', level=logging.INFO) + +if True: + check_ip() + #stop program neatly when stopped #global running #running=True; @@ -97,6 +102,11 @@ def EEPROM_code_changed(value): # except: # logging.error("Get ID failed") +def update_temperature(): + temp=subprocess.run(['/usr/bin/vcgencmd','measure_temp'],stdout=subprocess.PIPE).stdout.decode() +# print(temp[5:-3]) + pi_temp.set_value(float(temp[5:-3])) + if True: # global server,running,PCCobj,DEBUGobj,idx,sub; @@ -142,11 +152,19 @@ if True: EEPROM_version_new = obj.add_variable(idx, 'pytr_EEPROM_version_RW', 'None') EEPROM_version_new.set_writable() + pi_temp = obj.add_variable(idx, 'pytr_pi_temperature_R', 0.0) + update_temperature() + # logging.info("Add variables:") nodeid=0 while nodeid!=-1: - nodeid=datachanged.get() + try: + nodeid=datachanged.get(timeout=10) + except: + update_temperature() + continue if (nodeid==EEPROM_code.nodeid.Identifier): EEPROM_code_changed(EEPROM_code.get_value()) + # sleep(10) #P1.GetVarNames("",AddVar); server.stop() diff --git a/scripts/TR_test.py b/scripts/TR_test.py new file mode 100644 index 0000000000000000000000000000000000000000..5930b97f8aacec335b094165b362e084c74184ac --- /dev/null +++ b/scripts/TR_test.py @@ -0,0 +1,11 @@ +from test_common import * +connect("opc.tcp://localhost:4899/") + +#set_value("pytr_translator_select","apscttr") +#callmethod("pytr_start") +#callmethod("pytr_stop") + +set_value("pytr_EEPROM_passcode_RW","4899") + + +disconnect(); diff --git a/scripts/get_all_apsct.py b/scripts/get_all_apsct.py new file mode 100644 index 0000000000000000000000000000000000000000..90c84f7975788e6697aae3eb56869e628609648e --- /dev/null +++ b/scripts/get_all_apsct.py @@ -0,0 +1,11 @@ +from test_common import * +from time import sleep +connect("opc.tcp://localhost:4843/") + + +names=get_all_variables() +for name in names: + att=get_value(name) + print(name,'=',att) + +disconnect(); diff --git a/scripts/get_all_unb2tr.py b/scripts/get_all_unb2tr.py new file mode 100644 index 0000000000000000000000000000000000000000..5d5b91c35f0d4ed5e07d7cae42abe040579c4566 --- /dev/null +++ b/scripts/get_all_unb2tr.py @@ -0,0 +1,11 @@ +from test_common import * +from time import sleep +connect("opc.tcp://localhost:4841/") + + +names=get_all_variables() +for name in names: + att=get_value(name) + print(name,'=',att) + +disconnect(); diff --git a/setup.cfg b/setup.cfg index 4f53dd44ab5bcff1ad2c7c276e12e8937c4ebfd9..15aa2d761a6a320fda4da8d178a07a601c2229a8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,7 @@ where=. [options.entry_points] console_scripts = hwtr = pypcc.pypcc + pitr = pypcc.pitr [options.package_data]