Skip to content

Commit

Permalink
Merge pull request #92 from michallenc/python-refactor
Browse files Browse the repository at this point in the history
toolbox/supsisim: refactor SHV part of the code
  • Loading branch information
robertobucher authored Jan 5, 2025
2 parents c8b7382 + d04cbaf commit 60213a1
Show file tree
Hide file tree
Showing 8 changed files with 917 additions and 574 deletions.
18 changes: 6 additions & 12 deletions toolbox/supsisim/supsisim/RCPgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import copy
import sys
from supsisim.RCPblk import RCPblk
from supsisim.SHVgen import genSHVtree, genSHVcode, genSHVheader, genSHVend
from .shv import ShvTreeGenerator

def genCode(model, Tsamp, blocks, rkstep = 10):
"""Generate C-Code
Expand Down Expand Up @@ -68,7 +68,8 @@ def genCode(model, Tsamp, blocks, rkstep = 10):

N = size(Blocks)

genSHVheader(f, model, N)
shv_generator = ShvTreeGenerator(f, model, Blocks)
shv_generator.generate_header()

totContBlk = 0
for blk in Blocks:
Expand Down Expand Up @@ -160,15 +161,8 @@ def genCode(model, Tsamp, blocks, rkstep = 10):

f.write("\n\n")

Blks = []
for n in range(0,N):
Blks.append(Blocks[n].name)

BlksOrigin = copy.deepcopy(Blks)
Blks.sort()

if (environ["SHV_TREE_TYPE"] == "GSA_STATIC") and (environ["SHV_USED"] == "True"):
genSHVtree(f, Blocks, Blks)
shv_generator.generate_tree()

f.write("/* Initialization function */\n\n")
strLn = "void " + model + "_init(void)\n"
Expand Down Expand Up @@ -227,7 +221,7 @@ def genCode(model, Tsamp, blocks, rkstep = 10):
f.write("\n")

if environ["SHV_USED"] == "True":
genSHVcode(f, model, Blocks, Blks)
shv_generator.generate_code()

f.write("/* Set initial outputs */\n\n")

Expand Down Expand Up @@ -294,7 +288,7 @@ def genCode(model, Tsamp, blocks, rkstep = 10):
f.write(strLn)

if environ["SHV_USED"] == "True":
genSHVend(f, model)
shv_generator.generate_end()

for n in range(0,N):
blk = Blocks[n]
Expand Down
402 changes: 0 additions & 402 deletions toolbox/supsisim/supsisim/SHVgen.py

This file was deleted.

151 changes: 0 additions & 151 deletions toolbox/supsisim/supsisim/client.py

This file was deleted.

10 changes: 4 additions & 6 deletions toolbox/supsisim/supsisim/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import supsisim.RCPDlg as pDlg
from supsisim.const import GRID, DB, DP
from supsisim.node import Node
from supsisim.client import *
import numpy as np
import json
from shv import SHVDecimal, SHVFloat
from shv import SHVDecimal
from decimal import Decimal, ROUND_DOWN


Expand Down Expand Up @@ -233,7 +231,7 @@ def shvAction(self):

connection = self.scene.getBrokerConnection()

if not connection.isConnected():
if not connection.is_connected():
dlg = QMessageBox()
dlg.setWindowTitle("Warning!")
dlg.setText("No connection to broker")
Expand All @@ -255,7 +253,7 @@ def shvAction(self):
for i in range(1,len(items)):
par = items[i].split(':')
if par[2].replace(" ", "") == "double":
res = connection.getParameterValue(par[0], name)
res = connection.get_parameter_value(par[0], name)
par[1] = str(float(res))
items[i] = ':'.join(par)
name = item.name.replace(' ','_') + '_' + str(item.ident)
Expand Down Expand Up @@ -304,7 +302,7 @@ def shvAction(self):
print("Wrong data type")
else:
continue
connection.setPrameterValue(par[0], name, parameter)
connection.set_parameter_value(par[0], name, parameter)
else:
self.scene.clearLastUndo()

Expand Down
6 changes: 3 additions & 3 deletions toolbox/supsisim/supsisim/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from supsisim.connection import Connection
from supsisim.dialg import RTgenDlg, SHVDlg
from supsisim.const import VERSION, pyrun, TEMP, respath, BWmin
from supsisim.client import BrokerConnection
from .shv import ShvClient
from lxml import etree
import os
import subprocess
Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(self, main, parent=None):

self.SHV = SHVInstance(self.mainw.filename)

self.brokerConnection = BrokerConnection()
self.brokerConnection = ShvClient()

self.undoList = []

Expand Down Expand Up @@ -754,7 +754,7 @@ def debugInfo(self):
for item in dgmConnections:
print(item)

def getBrokerConnection(self) -> BrokerConnection:
def getBrokerConnection(self) -> ShvClient:

shv = self.SHV
self.brokerConnection.update_parameters_and_connect(shv.ip, shv.port, shv.user, shv.passw, shv.devid, shv.mount)
Expand Down
9 changes: 9 additions & 0 deletions toolbox/supsisim/supsisim/shv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Implementation of SHV tree generation and communication via pySHV."""

from .client import ShvClient
from .generator import ShvTreeGenerator

__all__ = [
"ShvClient",
"ShvTreeGenerator",
]
Loading

0 comments on commit 60213a1

Please sign in to comment.