Last active
June 8, 2017 09:31
-
-
Save gtortone/514302df79439bc59a9c905c48e8543f to your computer and use it in GitHub Desktop.
fake IOC for ECL endcap temperature / relative humidity data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 -B | |
# temperature between 20 and 30 degC | |
# rel.humidity between 0 and 10 RH% | |
import os | |
import sys | |
import logging | |
import random | |
from threading import Thread, Event, Lock | |
from pcaspy import Driver, SimpleServer | |
prefix = 'S' | |
debug = False | |
pvdb = { | |
'1F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'2F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'3F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'4F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'5F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'6F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'7F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'8F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'9F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'10F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'11F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'12F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'13F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'14F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'15F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'16F:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16F:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16F:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16F:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16F:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'1B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'1B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'2B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'2B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'3B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'3B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'4B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'4B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'5B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'5B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'6B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'6B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'7B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'7B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'8B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'8B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'9B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'9B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'10B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'10B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'11B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'11B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'12B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'12B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'13B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'13B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'14B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'14B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'15B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'15B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
'16B:TEMP:TEMP01' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16B:TEMP:TEMP02' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16B:TEMP:TEMP03' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16B:TEMP:AVG' : { 'type' : 'float', 'value': 25, 'unit': 'C' }, | |
'16B:RH' : { 'type' : 'float', 'value': 5, 'unit': '%' }, | |
} | |
class myDriver(Driver): | |
def __init__(self): | |
Driver.__init__(self) | |
self.eid = Event() | |
self.tid = Thread(target = self.runIOC) | |
self.tid.setDaemon(True) | |
self.tid.start() | |
self.logger = logging.getLogger('') | |
def runIOC(self): | |
if debug: | |
fmt = "%(asctime)s - %(funcName)s - %(levelname)s - %(message)s" | |
logging.basicConfig(level=logging.DEBUG, format=fmt) | |
while True: | |
for key,value in pvdb.items(): | |
val = self.getParam(key) | |
#print(key + " -> " + str(val)) | |
delta = random.uniform(-0.2, 0.2) | |
if 'RH' in key: | |
if (val + delta <= 10) and (val + delta >= 0): | |
self.setParam(key, val + delta) | |
if 'TEMP0' in key: | |
if (val + delta <= 30) and (val + delta >= 20): | |
self.setParam(key, val + delta) | |
sector = key.split(':')[0] | |
# calculate average | |
avg = (self.getParam(sector + ':' + "TEMP:TEMP01") + self.getParam(sector + ':' + "TEMP:TEMP02") + \ | |
self.getParam(sector + ':' + "TEMP:TEMP03")) / 3 | |
self.setParam(sector + ':' + "TEMP:AVG", avg) | |
self.updatePVs() | |
self.eid.wait(2) | |
if __name__ == '__main__': | |
server = SimpleServer() | |
server.createPV(prefix, pvdb) | |
driver = myDriver() | |
# process CA transactions | |
while True: | |
server.process(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment