Hamburger Hamburger

Heating and Ventilation Control

/HvcRaw2phys

Keine Erläuterungen gefunden.

import  os
from HvcTables import  *

class HvcRaw2phys:
    """
    Convert electronic raw values to physical units.
    """
    def  __init__(self):
        pass

    def  ADCverbose(self,raw,weight,HvcTables):
        """
        The verbose mode is good to understand, what is going on,
        used at initializations.
        """
        phys = {}
        message = "HvcRaw2phys.ADC \n"
        
        #initialize LowPass not set yet
        for  val in raw:
            value = float(raw[val])
            try:
                foo = HvcRaw2phys.LowPass[val]
            except:
                HvcRaw2phys.LowPass[val] = value
        
        #check validity of signals
        for  val in raw:
            value = raw[val]
            if value<=1 or value>=4095:
                message = message + "WARNING: check electrical connection of port: "+val+"\n"
            elif value<0.9*HvcRaw2phys.LowPass[val] or value>1.1*HvcRaw2phys.LowPass[val]:
                message = message + "WARNING: check connection of floating port: "+val+"\n"
        
        #reduce noise by low pass filter
        for  val in raw:
            value = float(raw[val])
#            last = HvcRaw2phys.LowPass[val] #arne
            HvcRaw2phys.LowPass[val] = (1.0-weight)*HvcRaw2phys.LowPass[val] + weight * value
 #           if val=="haus":
  #              print("LowPass",last,value,HvcRaw2phys.LowPass[val],weight) #arne

        #convert raw to physical value
        for  val in raw:
            if val=="TLow":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="THot":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="ret":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="flow":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="coll":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Pt1000", "no-saturate" )
            elif val=="fire":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "NTCoven", "saturate" )
            elif val=="haus":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "NTCoven", "saturate" )
            elif val=="erde":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            elif val=="zulu":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            elif val=="ablu":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            elif val=="folu":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            #    phys["folu"] = phys["ablu"]  - (phys["zulu"]-phys["erde"])
            else:
                message = message + "WARNING: for  "+val+" there is no conversion! \n"
                phys[val] = HvcRaw2phys.LowPass[val]
                

        message = message+"\t\t"
        for  val in raw:
            message = message+('\t{}'.format(val))
        message = message + "\n"
        message = message + "lowPass \t"
        for  val in raw:
            message = message+('\t{:.2f}'.format(HvcRaw2phys.LowPass[val]))
        message = message + "\n"
        message = message + "physical \t"
        for  val in raw:
            message = message+('\t{:.2f}'.format(phys[val]))
        message = message + "\n"
        
        return phys, message

    
    def  ADC(self,raw,weight,HvcTables):
        """
        For regular calls, drop the messages.
        """
        phys, message = HvcRaw2phys.ADCverbose(self,raw,weight,HvcTables)
        return phys

        
    #persistant values:
    LowPass={}



if __name__ == "__main__":
    #first init tables
    HvcTables = HvcTables()
    r2p = HvcRaw2phys()
    
    myRaw = {'coll': 1936, 'TLow': 2128, 'THot': 2016, 'flow': 2160, 'ret': 2164, 'fire': 682, 'haus': 707, 'erde': 1735, 'zulu': 2412, 'ablu': 1768, 'posBp': 401}
    
    weight=0.5
    phys, message = r2p.ADCverbose(myRaw,weight,HvcTables)
    print(message)

    print("============================")
    print("second call, all LowPass +1 ?")
    for  val in myRaw:
        myRaw[val] = myRaw[val]+2
        
    weight=0.5
    phys, message = r2p.ADCverbose(myRaw,weight,HvcTables)
    print(message)
    print("============================")
    print("execute short function")
    phys = r2p.ADC(myRaw,weight,HvcTables)
    print(phys)

python

1/HvcLightControl.py
2/HvcHCSR04ultrasonic.py
3/HvcPV.py
4/HvcMotorDriver.py
5/HvcRollerShutter.py
6/manGenMqttMap.py
7/HvcReadSPI.py
8/HvcMqtt.py
9/HvcTables.py
10/HvcMain.py
11/HvcSetGPIO.py
12/HvcWifiRelay.py
13/HvcOperationMode.py
14/HvcControl.py
15/HvcRaw2phys.py
16/HvcWeather.py
17/HvcOneWire.py
18/makeDoc.py
19/HvcFronius.py
20/EnergyManager.py
21/HvcSendI2C.py

php

1/HV_colorMap.php
2/HV_Admin_Login.php
3/HV_readOperationState.php
4/HV_setParameters.php
5/HV_config.php
6/EM_handleJSON.php
7/index.php
8/readFilenames.php
9/HV_restart.php
10/HV_moveGate.php
11/HV_showLog.php
12/HV_RollerShutter.php
13/EM_editParameter.php
14/HV_serviceLog.php
15/HV_H2Olevel.php
16/HV_TempCal.php
17/HV_Fronius.php
18/EM_plot.php
19/readNamedData.php
20/HV_composeH2Oplot.php
21/HVdoc.php
22/HV_showWeatherForecast.php
23/HV_showHouse.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.