Skip to content
Snippets Groups Projects
Commit 79fca3e5 authored by Paulus Kruger's avatar Paulus Kruger
Browse files

PPS counter added

parent f67f3563
No related branches found
No related tags found
No related merge requests found
Pipeline #21573 passed
version: "1.0"
description: "1234"
drivers:
- name: pps
type: gpio_pps
parameters: [24] #PPS pin
status: RECVTR_PPS_counter
device_registers:
- name: X1 #dummy
driver: pps
registers:
- name: X1
address: 0
variables:
- name: RECVTR_PPS_counter
driver: pps
rw: ro
dtype: uint64
width: 64
- name: RECVTR_PPS_time
driver: pps
rw: rw
dtype: uint64
width: 64
methods:
- name: PPS_Init #Called after startup to load. Should have all stored registers
driver: pps
debug: True
instructions:
- RECVTR_PPS_counter : Update
from .hwdev import hwdev;
import logging
import threading
from queuetypes import *
import time;
import struct
#import signal
try:
import RPi.GPIO as GPIO
except:
GPIO=False;
class gpio_pps(hwdev):
def __init__(self,config):
hwdev.__init__(self,config);
self.pin=config['parameters'][0];
self.cnt=0;
self.timesec=None;
self.timeid=None;
logging.info("PPS on pin %i",self.pin)
if GPIO:
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.pin,GPIO.IN)
else:
logging.warn("RPi GPIO module not found, PPS input disable!")
return
self.PPSid=config.get('maskid',None)
if self.PPSid is None:
logging.warn("PPS cnt variable not linked to driver!")
return
self.thread=threading.Thread(target=self.PPS_wait_loop);
self.thread.start();
def ppsdata(self):
data=struct.pack('>Q',self.cnt)
return [d for d in data];
def incPPS(self):
self.cnt+=1;
if not(self.timesec is None):
self.Qout.put(OPCUAset(self.timeid,InstType.varSet,self.timesec,[]))
self.cnt=0;
self.timesec=None;
logging.debug("PPS cnt=%i" % self.cnt)
self.Qout.put(OPCUAset(self.PPSid,InstType.varSet,self.ppsdata(),[]))
def PPS_wait_loop(self):
time.sleep(3);
while True:
self.Qout=self.conf.get('Qout',None)
if self.Qout is None:
logging.warn("PPS thread end (No Qout)")
return
channel=GPIO.wait_for_edge(self.pin,GPIO.RISING,timeout=2500)
if not(channel is None):
self.incPPS();
else:
logging.debug("PPS not received!")
channel=GPIO.wait_for_edge(self.pin,GPIO.FALLING,timeout=1500)
if not(channel is None):
self.incPPS();
else:
logging.debug("PPS not received!")
def OPCUAReadVariable(self,varid,var1,mask):
if varid==self.PPSid:
return [OPCUAset(self.PPSid,InstType.varSet,self.ppsdata(),[])]
else:
self.timeid=varid;
print("timeid=",varid);
return [OPCUAset(self.PPSid,InstType.varSet,[0,0,0,0,0,0,0,0],[])]
def OPCUASetVariable(self,varid,var1,data,mask):
if varid==self.PPSid:
logging.warn("Can not set PPS count");
return []
if self.timeid is None: self.timeid=varid;
if not(varid==self.timeid):
logging.warn("Unknown variable");
return []
logging.info("Set PPS time");
self.timesec=data.copy();
return []
...@@ -108,11 +108,16 @@ def I2Cserver(Qin,Qout,name): ...@@ -108,11 +108,16 @@ def I2Cserver(Qin,Qout,name):
conf=yc.yamlconfig(name) conf=yc.yamlconfig(name)
conf.linkdevices() conf.linkdevices()
conf.loaddrivers() conf.loaddrivers()
for c in conf.conf['drivers']:
c['Qout']=Qout;
conf.linkdrivers() conf.linkdrivers()
statusid=conf.getvarid(name+"_translator_busy"); statusid=conf.getvarid(name+"_translator_busy");
while True: while True:
item = Qin.get() item = Qin.get()
if item is None: break; if item is None:
for c in conf.conf['drivers']:
c['Qout']=None;
break;
# print("TODO: Set busy") # print("TODO: Set busy")
# self.statevar.set_value("busy"); # self.statevar.set_value("busy");
#print("SetVar",item)#,self.conf.variables[item.id]) #print("SetVar",item)#,self.conf.variables[item.id])
......
...@@ -117,9 +117,9 @@ class yamlreader(yamlconfig): ...@@ -117,9 +117,9 @@ class yamlreader(yamlconfig):
def setvar(self,id1,data=[]): def setvar(self,id1,data=[]):
v=self.conf['variables'][id1]; v=self.conf['variables'][id1];
if v['rw']=='variable': if v['rw']=='variable':
var1=v.get('OPCR') var1=v.get('OPCR',None)
# if not(var1): var1=v.get('OPCW') # if not(var1): var1=v.get('OPCW')
if not(var1): if var1 is None:
logging.warn("OPCR variable not found!!"); logging.warn("OPCR variable not found!!");
return; return;
logging.info("Update variable") logging.info("Update variable")
...@@ -235,9 +235,9 @@ class yamlreader(yamlconfig): ...@@ -235,9 +235,9 @@ class yamlreader(yamlconfig):
if convert: data2=[eval("convert_unit."+convert)(d) for d in data2] if convert: data2=[eval("convert_unit."+convert)(d) for d in data2]
for x in range(cnt): for x in range(cnt):
if notvalid[x]: data2[x]=float('nan') if notvalid[x]: data2[x]=float('nan')
var1=v.get('OPCR') var1=v.get('OPCR',None)
if not(var1): var1=v.get('OPCW') if var1 is None: var1=v.get('OPCW',None)
if not(var1): if var1 is None:
logging.warn("OPC variable not found!!"); logging.warn("OPC variable not found!!");
return; return;
data3=var1.get_value(); data3=var1.get_value();
......
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
import time import time
PIN=23 PIN=24
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN,GPIO.IN) GPIO.setup(PIN,GPIO.IN)
...@@ -8,3 +8,5 @@ GPIO.setup(PIN,GPIO.IN) ...@@ -8,3 +8,5 @@ GPIO.setup(PIN,GPIO.IN)
for x in range(3): for x in range(3):
channel=GPIO.wait_for_edge(PIN,GPIO.RISING,timeout=1500) channel=GPIO.wait_for_edge(PIN,GPIO.RISING,timeout=1500)
print("Timeout!" if channel is None else "PPS") print("Timeout!" if channel is None else "PPS")
channel=GPIO.wait_for_edge(PIN,GPIO.FALLING,timeout=1500)
print("Timeout!" if channel is None else "PPS")
from test_common import *
connect("opc.tcp://localhost:4850/")
import time
var1="RECVTR_PPS_counter_R"
vart="RECVTR_PPS_time"
# for x in range(20):#
for x in range(4):
time.sleep(0.5);
print("PPS=",get_value(var1)," time=",get_value(vart+"_R"));
for y in range(5):
print("Set time");
set_value(vart+"_RW",10+y)
time.sleep(0.1);
print("PPS=",get_value(var1)," time=",get_value(vart+"_R"));
for x in range(5):
time.sleep(0.5);
print("PPS=",get_value(var1)," time=",get_value(vart+"_R"));
disconnect();
tmux new -s translators 'cd ~/pypcc;python3 pypcc2.py -p 4840 -c RECVTR' \; \ tmux new -s translators 'cd ~/pypcc;python3 pypcc2.py -p 4840 -c RECVTR,PPS' \; \
new-window 'cd ~/pypcc;python3 pypcc2.py -p 4841 -c UNB2TR' \; \ new-window 'cd ~/pypcc;python3 pypcc2.py -p 4841 -c UNB2TR' \; \
new-window 'cd ~/pypcc;python3 pypcc2.py -p 4842 -c APSPUTR' \; \ new-window 'cd ~/pypcc;python3 pypcc2.py -p 4842 -c APSPUTR' \; \
new-window 'cd ~/pypcc;python3 pypcc2.py -p 4843 -c APSCTTR' \; \ new-window 'cd ~/pypcc;python3 pypcc2.py -p 4843 -c APSCTTR' \; \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment