Skip to content

Commit

Permalink
fix formating and spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Jan 26, 2022
1 parent 588fd48 commit c9fb8f1
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 93 deletions.
18 changes: 8 additions & 10 deletions modules/keballlp1/check502.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# import getopt
import socket

named_tuple = time.localtime() # getstruct_time
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S check502.py", named_tuple)

ipaddress = str(sys.argv[1])
file_string= '/var/www/html/openWB/ramdisk/port_502_' + ipaddress
file_string = '/var/www/html/openWB/ramdisk/port_502_' + ipaddress

try:
f = open( file_string , 'r')
port =int(f.read())
f = open(file_string, 'r')
port = int(f.read())
f.close()
except:
except Exception:
port = 9

if (port == 1) or (port == 0):
Expand All @@ -24,14 +24,12 @@
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
location = (ipaddress, 502)
result_of_check = a_socket.connect_ex(location)
f = open( file_string , 'w')
f = open(file_string, 'w')
if result_of_check == 0:
f.write(str(1))
print ('%s ipadr %s Port 502 is open ' % (time_string,ipaddress))
#print(ipaddress," Port 502 is open")
print('%s ipadr %s Port 502 is open ' % (time_string, ipaddress))
else:
f.write(str(0))
print ('%s ipadr %s Port 502 is not open ' % (time_string,ipaddress))
#print(ipaddress," Port 502 is not open")
print('%s ipadr %s Port 502 is not open ' % (time_string, ipaddress))
a_socket.close()
f.close()
88 changes: 47 additions & 41 deletions modules/keballlp1/setcurrkeba.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,88 @@
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder

named_tuple = time.localtime() # getstruct_time
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S keba setcurr.py", named_tuple)

file_string= '/var/www/html/openWB/ramdisk/keba_setcurr.log'
file_string = '/var/www/html/openWB/ramdisk/keba_setcurr.log'


def getstat(ip):
# 1 enabled, 0 disable, 9 undef
file_ip= '/var/www/html/openWB/ramdisk/keba_' + ip
file_ip = '/var/www/html/openWB/ramdisk/keba_' + ip
status = 9
if os.path.isfile(file_ip):
f = open(file_ip, 'r')
status=int(f.read())
status = int(f.read())
f.close()
return status

def setstat(ip,status):
file_ip= '/var/www/html/openWB/ramdisk/keba_' + ip

def setstat(ip, status):
file_ip = '/var/www/html/openWB/ramdisk/keba_' + ip
f1 = open(file_ip, 'w')
f1.write(str(status))
f1.close()


if os.path.isfile(file_string):
f = open( file_string , 'a')
f = open(file_string, 'a')
else:
f = open( file_string , 'w')
f = open(file_string, 'w')

ipaddress=str(sys.argv[1])
newcurr=int(sys.argv[2])
ipaddress = str(sys.argv[1])
newcurr = int(sys.argv[2])

client = ModbusTcpClient(ipaddress, port=502)

# maxcurr state 1100
resp= client.read_holding_registers(1100,2,unit=255)
decoder = BinaryPayloadDecoder.fromRegisters(resp.registers,byteorder=Endian.Big,wordorder=Endian.Big)
final = float( decoder.decode_32bit_uint()) / 1000
# maxcurrent state 1100
resp = client.read_holding_registers(1100, 2, unit=255)
decoder = BinaryPayloadDecoder.fromRegisters(resp.registers, byteorder=Endian.Big, wordorder=Endian.Big)
final = float(decoder.decode_32bit_uint()) / 1000
oldcurr = int("%.f" % final)

# cabel state 1004
resp= client.read_holding_registers(1004,2,unit=255)
decoder = BinaryPayloadDecoder.fromRegisters(resp.registers,byteorder=Endian.Big,wordorder=Endian.Big)
final2 = float( decoder.decode_32bit_uint())
plugs = "%.f" % final2
# cable state 1004
resp = client.read_holding_registers(1004, 2, unit=255)
decoder = BinaryPayloadDecoder.fromRegisters(resp.registers, byteorder=Endian.Big, wordorder=Endian.Big)
final2 = float(decoder.decode_32bit_uint())
plugs = "%.f" % final2

# max supported curr 1110
resp= client.read_holding_registers(1110,2,unit=255)
decoder = BinaryPayloadDecoder.fromRegisters(resp.registers,byteorder=Endian.Big,wordorder=Endian.Big)
final2 = float( decoder.decode_32bit_uint()) / 1000
# max supported current 1110
resp = client.read_holding_registers(1110, 2, unit=255)
decoder = BinaryPayloadDecoder.fromRegisters(resp.registers, byteorder=Endian.Big, wordorder=Endian.Big)
final2 = float(decoder.decode_32bit_uint()) / 1000
supcur = int("%.f" % final2)
if plugs == "7":
if (oldcurr != newcurr):
if (newcurr == 0):
# disable station
print ('%s oldcurr %d, newcurr %d, ipadr %s disable station' % (time_string,oldcurr,newcurr,ipaddress),file=f)
rq = client.write_register(5014,0,unit=255)
setstat(ipaddress,0)
print('%s oldcurr %d, newcurr %d, ipadr %s disable station' % (
time_string, oldcurr, newcurr, ipaddress), file=f)
rq = client.write_register(5014, 0, unit=255)
setstat(ipaddress, 0)
else:
if (oldcurr == 0):
#enable station
print ('%s oldcurr %d, newcurr %d, ipadr %s enable station ' % (time_string,oldcurr,newcurr,ipaddress ),file=f)
rq = client.write_register(5014,1,unit=255)
setstat(ipaddress,1)
# setting new curr
print ('%s oldcurr %d, newcurr %d, hwlimit %d ipadr %s setting new curr' % (time_string,oldcurr,newcurr,supcur,ipaddress),file=f)
# enable station
print('%s oldcurr %d, newcurr %d, ipadr %s enable station ' % (
time_string, oldcurr, newcurr, ipaddress), file=f)
rq = client.write_register(5014, 1, unit=255)
setstat(ipaddress, 1)
# setting new current
print('%s oldcurr %d, newcurr %d, hwlimit %d ipadr %s setting new curr' % (
time_string, oldcurr, newcurr, supcur, ipaddress), file=f)
newcurrt = newcurr * 1000
rq = client.write_register(5004,newcurrt,unit=255)
rq = client.write_register(5004, newcurrt, unit=255)
else:
status = getstat(ipaddress)
if ((newcurr == 0) and (status != 0)) :
if ((newcurr == 0) and (status != 0)):
# disable station
print ('%s No car detected, ipadr %s disable station' % (time_string,ipaddress),file=f)
rq = client.write_register(5014,0,unit=255)
setstat(ipaddress,0)
print('%s No car detected, ipadr %s disable station' % (time_string, ipaddress), file=f)
rq = client.write_register(5014, 0, unit=255)
setstat(ipaddress, 0)
else:
if ((newcurr > 0) and (status != 1)):
#enable station
print ('%s No car detected, ipadr %s enable station ' % (time_string,ipaddress ),file=f)
rq = client.write_register(5014,1,unit=255)
setstat(ipaddress,1)
# enable station
print('%s No car detected, ipadr %s enable station ' % (time_string, ipaddress), file=f)
rq = client.write_register(5014, 1, unit=255)
setstat(ipaddress, 1)
f.close()
2 changes: 1 addition & 1 deletion packages/helpermodules/pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def pub_single(topic, payload, hostname="localhost", no_json=False):
hostname: str
IP des Hosts
no_json: bool
Kompabilität mit isss, die ramdisk verwenden.
Kompatibilität mit ISSS, die ramdisk verwenden.
"""
try:
if no_json:
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/common/component_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class SingleComponentUpdateContext:
""" Wenn die Werte der Komponenten nicht miteinander verrechnet werden, sollen, auch wenn bei einer Komponente ein
Fehler auftritt, alle anderen dennnoch ausgelesen werden. WR-Werte dienen nur statistisichen Zwecken, ohne
Fehler auftritt, alle anderen dennnoch ausgelesen werden. WR-Werte dienen nur statistischen Zwecken, ohne
EVU-Werte ist aber keine Regelung möglich. Ein nicht antwortender WR soll dann nicht die Regelung verhindern.
for component in self._components:
with SingleComponentUpdateContext(component):
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/common/modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def divide_rounding_up(numerator: int, denominator: int):
except pymodbus.exceptions.ConnectionException as e:
raise FaultState.error(
"TCP-Client konnte keine Verbindung zu " + str(self.address) + ":" + str(self.port) +
" aufbauen. Bitte Einstellungen (IP-Adresse, ..) und " + "Hardware-Anschluss pruefen.") from e
" aufbauen. Bitte Einstellungen (IP-Adresse, ..) und " + "Hardware-Anschluss prüfen.") from e
except pymodbus.exceptions.ModbusIOException as e:
raise FaultState.warning(
"TCP-Client " + str(self.address) + ":" + str(self.port) +
" konnte keinen Wert abfragen. Falls vorhanden, parallele Verbindungen, zB. node red," +
"beenden und bei anhaltender Fehlermeldung Zaehler neustarten.") from e
"beenden und bei anhaltender Fehlermeldung Zähler neustarten.") from e
except Exception as e:
raise FaultState.error(__name__+" "+str(type(e))+" " +
str(e)) from e
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/huawei/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def get_default_config() -> dict:
return {
"name": "Huawei",
"type": "hauwei",
"type": "huawei",
"id": 0,
"configuration":
{
Expand Down
71 changes: 35 additions & 36 deletions runs/dac.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,52 @@

# Setting the output voltage of the MCP4725 DAC.
# Read first value passed as the integer for DAC.
import time
import sys
# Import the MCP4725 module.
import Adafruit_MCP4725

# translation table current-to-voltage
voltage = {
0:0,
1:0,
2:0,
3:0,
4:0,
5:0,
6:790,
7:908,
8:1038,
9:1168,
10:1298,
11:1427,
12:1557,
13:1687,
14:1814,
15:1947,
16:2077,
17:2206,
18:2336,
19:2466,
20:2596,
21:2726,
22:2855,
23:2985,
24:3115,
25:3245,
26:3375,
27:3505,
28:3634,
29:3764,
30:3894,
31:4024,
32:4096
voltage = {
0: 0,
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 790,
7: 908,
8: 1038,
9: 1168,
10: 1298,
11: 1427,
12: 1557,
13: 1687,
14: 1814,
15: 1947,
16: 2077,
17: 2206,
18: 2336,
19: 2466,
20: 2596,
21: 2726,
22: 2855,
23: 2985,
24: 3115,
25: 3245,
26: 3375,
27: 3505,
28: 3634,
29: 3764,
30: 3894,
31: 4024,
32: 4096
}

# TODO: How precise need the values to be? Maybe the table could be replaced by volt=current*130

# Create a DAC instance.

#dac = Adafruit_MCP4725.MCP4725()
# dac = Adafruit_MCP4725.MCP4725()
address = int(sys.argv[2], 16)

# Note you can change the I2C address from its default (0x62), and/or the I2C
Expand Down
2 changes: 1 addition & 1 deletion runs/evsewritemodbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
evseid = int(sys.argv[2])
lla = int(sys.argv[3])

client = ModbusSerialClient(method = "rtu", port=seradd, baudrate=9600, stopbits=1, bytesize=8, timeout=1)
client = ModbusSerialClient(method="rtu", port=seradd, baudrate=9600, stopbits=1, bytesize=8, timeout=1)
rq = client.write_registers(1000, lla, unit=evseid)

0 comments on commit c9fb8f1

Please sign in to comment.