Skip to content

Commit

Permalink
update the code document.
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYuancheng committed Aug 8, 2023
1 parent 2712478 commit a38065e
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 267 deletions.
247 changes: 118 additions & 129 deletions src/scadaEmuUI/hmiEmuRun.py

Large diffs are not rendered by default.

121 changes: 64 additions & 57 deletions src/scadaEmuUI/hmiMgr.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
#!/usr/bin/python
#-----------------------------------------------------------------------------
# Name: railwayMgr.py
# Name: hmiMgr.py
#
# Purpose: The management module to control all the components on the map
# and update the components state.
#
# Author: Yuancheng Liu
#
# Version: v0.1
# Version: v0.1.3
# Created: 2023/05/29
# Copyright:
# License:
# Copyright: Copyright (c) 2023 LiuYuancheng
# License: MIT License
#-----------------------------------------------------------------------------

import scadaGobal as gv
from collections import OrderedDict

#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------

class AgentSensors(object):
""" The sensors set to show the sensors detection state."""
def __init__(self, parent, id, posList=None):
self.parent = parent
self.id = id
self.sensorsCount = 0 if posList is None else len(posList)
self.sensorsPosList = [] if posList is None else posList
self.sensorsStateList = [0]*self.sensorsCount
self.sensorsStateList = [0]*self.sensorsCount

def addOneSensor(self, pos):
self.sensorsPosList.append(pos)
Expand All @@ -38,10 +39,11 @@ def updateSensorState(self, idx, state):

def updateSensorsState(self, statList):
if statList is None: return
print("update sensor: %s, in: %s, %s " % (str( self.id), str(self.sensorsCount), str(len(statList)) ))
print("update sensor: %s, in: %s, %s " %(str(self.id), str(self.sensorsCount), str(len(statList))))
if len(statList) == self.sensorsCount:
self.sensorsStateList = statList

#-----------------------------------------------------------------------------
# Init all the get() function here:
def getID(self):
return self.id

Expand All @@ -57,7 +59,7 @@ def getSensorsState(self):
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
class AgentSignal(object):

""" The signal agent."""
def __init__(self, parent, id, pos) -> None:
self.parent = parent
self.id = id
Expand All @@ -72,6 +74,8 @@ def addTGonPos(self, pos):
def addTFoffPos(self, pos):
self.triggerOffPosList.append(pos)

#-----------------------------------------------------------------------------
# Init all the get() function here:
def getID(self):
return self.id

Expand All @@ -93,7 +97,7 @@ def setState(self, state):
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
class AgentStation(object):

""" The station agent."""
def __init__(self, parent, id, pos, labelLayout=gv.LAY_D) -> None:
self.parent = parent
self.id = id
Expand All @@ -102,6 +106,8 @@ def __init__(self, parent, id, pos, labelLayout=gv.LAY_D) -> None:
self.signalState = False # station singal state.
self.labelLayout = labelLayout

#-----------------------------------------------------------------------------
# Init all the get() function here:
def getID(self):
return self.id

Expand All @@ -117,6 +123,8 @@ def getSignalState(self):
def getlabelLayout(self):
return self.labelLayout

#-----------------------------------------------------------------------------
# Init all the set() function here:
def setSensorState(self, state):
self.sensorState = state

Expand All @@ -138,50 +146,59 @@ def __init__(self, parent):
self._initSignals()
self._initStations()

#-----------------------------------------------------------------------------
def _initSensors(self):

""" Init all the sensors location on track."""
# weline (top)
y = 100
sensorPos_we = [(80+100*i, y) for i in range(17) ]
sensorPos_we = [(80+100*i, y) for i in range(17)]
self.sensors['weline'] = AgentSensors(self, 'we')
for pos in sensorPos_we:
self.sensors['weline'].addOneSensor(pos)

# ccline (mid)
y += 160
sensorPos_cc = [(80+120*i, y) for i in range(14)]
self.sensors['ccline'] = AgentSensors(self, 'cc')
for pos in sensorPos_cc:
self.sensors['ccline'].addOneSensor(pos)

# nsline (btm)
y+= 160
sensorPos_ns = [(80+210*i, y) for i in range(8)]
sensorPos_ns = [(80+210*i, y) for i in range(8)]
self.sensors['nsline'] = AgentSensors(self, 'ns')
for pos in sensorPos_ns:
self.sensors['nsline'].addOneSensor(pos)

def _initSignals(self):
y = 100
trackSignalConfig_we = [
{'id': 'we-0', 'pos':(80+100*1+30, y), 'tiggerS': 'ccline', 'onIdx':(12,), 'offIdx':(13,) },
{'id': 'we-2', 'pos':(80+100*3+30, y), 'tiggerS': 'ccline', 'onIdx':(10,), 'offIdx':(11,) },
{'id': 'we-4', 'pos':(80+100*5+30, y), 'tiggerS': 'ccline', 'onIdx':(8,), 'offIdx':(9,) },
{'id': 'we-6', 'pos':(80+100*7+30, y), 'tiggerS': 'ccline', 'onIdx':(6,), 'offIdx':(7,) },
{'id': 'we-7', 'pos':(80+100*9+30, y), 'tiggerS': 'ccline', 'onIdx':(6,), 'offIdx':(7,) },
{'id': 'we-5', 'pos':(80+100*11+30, y), 'tiggerS': 'ccline', 'onIdx':(8,), 'offIdx':(9,) },
{'id': 'we-3', 'pos':(80+100*13+30, y), 'tiggerS': 'ccline', 'onIdx':(10,), 'offIdx':(11,) },
{'id': 'we-1', 'pos':(80+100*15+30, y), 'tiggerS': 'ccline', 'onIdx':(12,), 'offIdx':(13,) },
]
key = 'weline'
self.signals[key] = []

for signalInfo in trackSignalConfig_we:
#-----------------------------------------------------------------------------
def _builSignalList(self, configDict):
signals = []
for signalInfo in configDict:
signal = AgentSignal(self, signalInfo['id'], signalInfo['pos'])
sPosList = self.getSensors(trackID=signalInfo['tiggerS']).getSensorPos()
for idx in signalInfo['onIdx']:
signal.addTGonPos(sPosList[idx])
for idx in signalInfo['offIdx']:
signal.addTFoffPos(sPosList[idx])
self.signals[key].append(signal)
signals.append(signal)
return signals

#-----------------------------------------------------------------------------
def _initSignals(self):
""" Init all the signals location on track."""
# weline (top)
y = 100
key = 'weline'
trackSignalConfig_we = [
{'id': 'we-0', 'pos':(80+100*1+30, y), 'tiggerS': 'ccline', 'onIdx':(12,), 'offIdx':(13,) },
{'id': 'we-2', 'pos':(80+100*3+30, y), 'tiggerS': 'ccline', 'onIdx':(10,), 'offIdx':(11,) },
{'id': 'we-4', 'pos':(80+100*5+30, y), 'tiggerS': 'ccline', 'onIdx':(8,), 'offIdx':(9,) },
{'id': 'we-6', 'pos':(80+100*7+30, y), 'tiggerS': 'ccline', 'onIdx':(6,), 'offIdx':(7,) },
{'id': 'we-7', 'pos':(80+100*9+30, y), 'tiggerS': 'ccline', 'onIdx':(6,), 'offIdx':(7,) },
{'id': 'we-5', 'pos':(80+100*11+30, y), 'tiggerS': 'ccline', 'onIdx':(8,), 'offIdx':(9,) },
{'id': 'we-3', 'pos':(80+100*13+30, y), 'tiggerS': 'ccline', 'onIdx':(10,), 'offIdx':(11,) },
{'id': 'we-1', 'pos':(80+100*15+30, y), 'tiggerS': 'ccline', 'onIdx':(12,), 'offIdx':(13,) },
]
self.signals[key] = self._builSignalList(trackSignalConfig_we)
# ccline (mid)
y += 160
trackSignalConfig_cc = [
{'id': 'cc-0', 'pos':(80+120*0+40, y), 'tiggerS': 'nsline', 'onIdx':(0, 6), 'offIdx':(1, 7) },
Expand All @@ -193,16 +210,8 @@ def _initSignals(self):
{'id': 'cc-6', 'pos':(80+120*12+40, y), 'tiggerS': 'weline', 'onIdx':(1, 15), 'offIdx':(2,16) },
]
key = 'ccline'
self.signals[key] = []
for signalInfo in trackSignalConfig_cc:
signal = AgentSignal(self, signalInfo['id'], signalInfo['pos'])
sPosList = self.getSensors(trackID=signalInfo['tiggerS']).getSensorPos()
for idx in signalInfo['onIdx']:
signal.addTGonPos(sPosList[idx])
for idx in signalInfo['offIdx']:
signal.addTFoffPos(sPosList[idx])
self.signals[key].append(signal)

self.signals[key] = self._builSignalList(trackSignalConfig_cc)
# nsline (btm)
y += 160
trackSignalConfig_ns = [
{'id': 'ns-0', 'pos':(80+210*0+70, y), 'tiggerS': 'ccline', 'onIdx':(0,), 'offIdx':(1,) },
Expand All @@ -211,18 +220,14 @@ def _initSignals(self):
{'id': 'ns-3', 'pos':(80+210*6+70, y), 'tiggerS': 'ccline', 'onIdx':(4,), 'offIdx':(5,) },
]
key = 'nsline'
self.signals[key] = []
for signalInfo in trackSignalConfig_ns:
signal = AgentSignal(self, signalInfo['id'], signalInfo['pos'])
sPosList = self.getSensors(trackID=signalInfo['tiggerS']).getSensorPos()
for idx in signalInfo['onIdx']:
signal.addTGonPos(sPosList[idx])
for idx in signalInfo['offIdx']:
signal.addTFoffPos(sPosList[idx])
self.signals[key].append(signal)
self.signals[key] = self._builSignalList(trackSignalConfig_ns)

#-----------------------------------------------------------------------------
def _initStations(self):
""" Init all the station location on track."""
# weline (top)
y = 100
key = 'weline'
trackStation_we = [{'id': 'Tuas_Link', 'pos': (80+100*0+60, y), 'layout': gv.LAY_D},
{'id': 'Jurong_East', 'pos': (80+100*2+60, y), 'layout': gv.LAY_U},
{'id': 'Outram_Park', 'pos': (80+100*4+60, y), 'layout': gv.LAY_U},
Expand All @@ -233,40 +238,40 @@ def _initStations(self):
{'id': 'Raffles_Place', 'pos': (80+100*12+60, y), 'layout': gv.LAY_U},
{'id': 'Clementi', 'pos': (80+100*14+60, y), 'layout': gv.LAY_U},
{'id': 'Boon_Lay', 'pos': (80+100*15+60, y), 'layout': gv.LAY_D}]
key = 'weline'
self.stations[key] = []
for stationInfo in trackStation_we:
station = AgentStation(self, stationInfo['id'], stationInfo['pos'], labelLayout=stationInfo['layout'])
self.stations[key].append(station)

# ccline (mid)
y += 160
key = 'ccline'
trackStation_cc = [
{'id': 'Buona_Vista', 'pos': (80+120*11+40, y), 'layout': gv.LAY_D},
{'id': 'Farrer_Road', 'pos': (80+120*12+80, y), 'layout': gv.LAY_D},
{'id': 'Serangoon', 'pos': (80+120*3+80, y), 'layout': gv.LAY_U},
{'id': 'Nicoll_Highway', 'pos': (80+120*7+40, y), 'layout': gv.LAY_U},
{'id': 'Bayfront', 'pos': (80+120*7+80, y),'layout': gv.LAY_D},
{'id': 'Harbourfront', 'pos': (80+120*9+80, y),'layout': gv.LAY_D}]
key = 'ccline'
self.stations[key] = []
for stationInfo in trackStation_cc:
station = AgentStation(self, stationInfo['id'], stationInfo['pos'], labelLayout=stationInfo['layout'])
self.stations[key].append(station)

# nsline (btm)
y += 160
key = 'nsline'
trackStation_ns = [{'id': 'Jurong_East', 'pos': (80+210*6+140, y), 'layout': gv.LAY_D},
{'id': 'Woodlands', 'pos': (80+210*1+70, y), 'layout': gv.LAY_U},
{'id': 'Yishun', 'pos': (80+210*1+140, y), 'layout': gv.LAY_D},
{'id': 'Orchard', 'pos': (80+210*3+70, y), 'layout': gv.LAY_U},
{'id': 'City_Hall', 'pos': (80+210*3+140, y), 'layout': gv.LAY_D},
{'id': 'Bishan', 'pos': (80+210*5+140, y), 'layout': gv.LAY_D}]
key = 'nsline'
self.stations[key] = []
for stationInfo in trackStation_ns:
station = AgentStation(self, stationInfo['id'], stationInfo['pos'], labelLayout=stationInfo['layout'])
self.stations[key].append(station)


#-----------------------------------------------------------------------------
# Init all the get() function here:
def getSensors(self, trackID=None):
if trackID and trackID in self.sensors.keys(): return self.sensors[trackID]
return self.sensors
Expand All @@ -279,6 +284,8 @@ def getStations(self, trackID=None):
if trackID and trackID in self.stations.keys(): return self.stations[trackID]
return self.stations

#-----------------------------------------------------------------------------
# Init all the set() function here:
def setSensors(self, trackID, stateList):
self.sensors[trackID].updateSensorsState(stateList)

Expand All @@ -298,4 +305,4 @@ def setStationsSignals(self, trackID, stateList):
if trackID is None or stateList is None: return
if trackID in self.stations.keys() and len(stateList) <= len(self.stations[trackID]):
for i, state in enumerate(stateList):
self.stations[trackID][i].setSignalState(state)
self.stations[trackID][i].setSignalState(state)
5 changes: 2 additions & 3 deletions src/scadaEmuUI/hmiPanel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/python
#-----------------------------------------------------------------------------
# Name: uiPanel.py
# Name: hmiPanel.py
#
# Purpose: This module is used to create different function panels.
#
# Author: Yuancheng Liu
#
# Version: v0.1.2
# Version: v0.1.3
# Created: 2023/07/12
# Copyright: Copyright (c) 2023 Singapore National Cybersecurity R&D Lab LiuYuancheng
# License: MIT License
Expand All @@ -17,7 +17,6 @@

import scadaGobal as gv


#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
class PanelPLC(wx.Panel):
Expand Down
Loading

0 comments on commit a38065e

Please sign in to comment.