def interruptcheck(refsensor): logger.info('Starting Interrupt Evaluation, Sensor: %s', refsensor) # iterate among the actuators elementlist = interruptdbmod.getelementlist() for element in elementlist: sensor = interruptdbmod.searchdata("element", element, "sensor") if sensor == refsensor: interruptexecute(refsensor, element) return
def cyclereset(element): #AUTO_data["default"]={"lasteventtime":datetime.utcnow()- timedelta(minutes=waitingtime),"lastinterrupttime":datetime.utcnow(), #"validinterruptcount":0,"eventactivated":False,"lastactiontime":datetime.utcnow()- timedelta(minutes=waitingtime), #"actionvalue":0, "alertcounter":0, "infocounter":0, "status":"ok" , "threadID":None , "blockingstate":False} #SENSOR_data["default"]={"Startcounttime":datetime.utcnow(),"InterruptCount":0} # this is for the actual frequency sensor #PIN_attributes["default"]={"logic":"pos","refsensor":"","bouncetimeSec":0.001} # this is relebant to the PINs #BLOCKING_data["default"]={"BlockingNumbers":0,"BlockingNumbersThreadID":None} # tihs is relenat to the Interrupt trigger global AUTO_data waitingtime = hardwaremod.toint( interruptdbmod.searchdata("element", element, "preemptive_period"), 0) statusdataDBmod.write_status_data( AUTO_data, element, "lastactiontime", datetime.utcnow() - timedelta(minutes=waitingtime)) statusdataDBmod.write_status_data( AUTO_data, element, "lasteventtime", datetime.utcnow() - timedelta(minutes=waitingtime)) statusdataDBmod.write_status_data(AUTO_data, element, "status", "ok") statusdataDBmod.write_status_data(AUTO_data, element, "actionvalue", 0) statusdataDBmod.write_status_data(AUTO_data, element, "alertcounter", 0) statusdataDBmod.write_status_data(AUTO_data, element, "infocounter", 0) statusdataDBmod.write_status_data(AUTO_data, element, "validinterruptcount", 0) # start procedure to stop blocking on this element endblocking(element) # reassess all the interrupt sensor related shit elementlist = interruptdbmod.getelementlist() sensorblockingcounter = {} #print "elementlist" , elementlist #print elementlist for element in elementlist: #print " ELEMENT " , element workmode = checkworkmode(element) if (workmode != "None") and (workmode != ""): sensor = interruptdbmod.searchdata("element", element, "sensor") #print " SENSOR " , sensor if sensor != "": #print "Blocking starte " , statusdataDBmod.read_status_data(AUTO_data,element,"blockingstate") if statusdataDBmod.read_status_data( AUTO_data, element, "blockingstate"): # blocking state is TRUE #print " TRUE ------------------------------------------------------- " , element if sensor in sensorblockingcounter: sensorblockingcounter[ sensor] = sensorblockingcounter[sensor] + 1 else: sensorblockingcounter[sensor] = 1 print(sensorblockingcounter) global BLOCKING_data for sensor in sensorblockingcounter: statusdataDBmod.write_status_data(BLOCKING_data, sensor, "BlockingNumbers", sensorblockingcounter[sensor])
def interruptcheck(refsensor, mode): #logger.info('Starting Interrupt Evaluation, Sensor: %s' , refsensor) # iterate among the actuators elementlist = interruptdbmod.getelementlist() #print elementlist for element in elementlist: sensor = interruptdbmod.searchdata("element", element, "sensor") #print sensor if sensor == refsensor: sensormode = interruptdbmod.searchdata("element", element, "sensor_mode") #print "mode ", mode , "sensormode ", sensormode if (mode in sensormode) or ("both" in sensormode): interruptexecute(refsensor, element) return
def cycleresetall(): global AUTO_data elementlist = interruptdbmod.getelementlist() for element in elementlist: cyclereset(element)
def setinterruptevents(): hardwaremod.removeallinterruptevents() print("load interrupt list ") interruptlist = interruptdbmod.sensorlist() print("len interrupt list ", len(interruptlist)) for item in interruptlist: print("got into the loop ") # get PIN number recordkey = hardwaremod.HW_INFO_NAME recordvalue = item keytosearch = hardwaremod.HW_CTRL_PIN PINstr = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) print("set event for the PIN ", PINstr) if not PINstr == "": keytosearch = hardwaremod.HW_CTRL_LOGIC logic = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) # set Sw pull up / down mode if logic == "pos": hardwaremod.GPIO_setup(PINstr, "in", "pull_down") evenslopetype = "both" else: hardwaremod.GPIO_setup(PINstr, "in", "pull_up") evenslopetype = "both" #GPIO.RISING, GPIO.FALLING or GPIO.BOTH. # link to the callback function # the bouncetime is set by the frequency parameter, if this parameter is empty, the default bouncetime would be 200 keytosearch = hardwaremod.HW_CTRL_FREQ frequency = hardwaremod.searchdata(recordkey, recordvalue, keytosearch) if frequency == "": bouncetimeINT = 200 else: frequencyINT = hardwaremod.toint(frequency, 5) bouncetimeINT = old_div( 1000, frequencyINT ) # in ms. this is ok to be trunk of the int. For frequencies higher than 1000 the bouncetime is exactly zero # RPI.GPIO library does not accept bouncetime=0, it gives runtime error if bouncetimeINT <= 0: bouncetimeINT = 1 #ms hardwaremod.GPIO_add_event_detect(PINstr, evenslopetype, eventcallback, bouncetimeINT) # set fast reference call indexed with the PIN number which is the variable used when interrupt is called: # search now to avoid searching later global PIN_attributes PIN = hardwaremod.toint(PINstr, 0) statusdataDBmod.write_status_data(PIN_attributes, PIN, "logic", logic) recordkey = hardwaremod.HW_CTRL_PIN recordvalue = PINstr keytosearch = hardwaremod.HW_INFO_NAME refsensor = hardwaremod.searchdata( recordkey, recordvalue, keytosearch) # return first occurence statusdataDBmod.write_status_data(PIN_attributes, PIN, "refsensor", refsensor) statusdataDBmod.write_status_data( PIN_attributes, PIN, "bouncetimeSec", 0.4 * float(bouncetimeINT) / 1000) # code below to enable blocking for N sec, it is necessary to trigger the bloccking status in case of levels already present when starting. elementlist = interruptdbmod.getelementlist() #print elementlist for element in elementlist: workmode = checkworkmode(element) if (workmode != "None") and (workmode != ""): sensor = interruptdbmod.searchdata("element", element, "sensor") #saveblockingdiff(sensor) print(" what a sensor ", sensor) if sensor != "": startblockingstate(element, 10, False) t.sleep(0.02) return ""
import time as t ACTIONPRIORITYLEVEL = 5 NONBLOCKINGPRIORITY = 0 SAVEBLOCKINGBUSY = False SAVEBLOCKINGDIFFBUSY = False NOWTIMELIST = [] #In hardware, an internal 10K resistor between the input channel and 3.3V (pull-up) or 0V (pull-down) is commonly used. #https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/ logger = logging.getLogger("hydrosys4." + __name__) # status array, required to check the ongoing actions elementlist = interruptdbmod.getelementlist() waitingtime = 1200 # ///////////////// -- STATUS VARIABLES -- /////////////////////////////// AUTO_data = {} # dictionary of dictionary AUTO_data["default"] = { "lasteventtime": datetime.utcnow() - timedelta(minutes=waitingtime), "lastinterrupttime": datetime.utcnow(), "validinterruptcount": 0, "eventactivated": False, "lastactiontime": datetime.utcnow() - timedelta(minutes=waitingtime), "actionvalue": 0, "alertcounter": 0, "infocounter": 0, "status": "ok",