Skip to content

Commit

Permalink
Merge pull request #144 from asmithie13/finish_testbench_#107
Browse files Browse the repository at this point in the history
Finish testbench #107
  • Loading branch information
21AQN01 authored Mar 26, 2024
2 parents 7fcca1d + b1144cb commit 0503982
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
Binary file modified PLC_Files/__pycache__/Parser.cpython-312.pyc
Binary file not shown.
Binary file modified PLC_Files/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Track_Resources/Block.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, lineColor, blockSection, blockNum, hasLight, hasCrossing, has
self.occupied = False
self.ID = id
self.speedLimit = None
self.authority = None
self.authority = True
self.blockLength = None
self.Wayside = None

Binary file modified Track_Resources/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
56 changes: 45 additions & 11 deletions Wayside_SW/WaysideSWandTB.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class WaysideSW(QMainWindow):
sendOccupiedBlocks = pyqtSignal(list) #Send list of occupied blocks to CTC
sendTrainSpeedAuth = pyqtSignal(list) #Send commanded speed to track model

#signal to send all blocks to testbench
sendAllBlocks = pyqtSignal(list)

def __init__(self):
super().__init__()
uic.loadUi("Wayside_SW/Wayside_UI_Rough.ui",self)
Expand Down Expand Up @@ -98,7 +101,7 @@ def __init__(self):
for block in self.greenWayside2Blocks:
if block.LIGHT or block.CROSSING or block.SWITCH : self.specialGreenBlocksW2.append(block)
block.Wayside = "W2"

#2D array of blocks within 5 blocks of each other
self.green5blocks = []

Expand Down Expand Up @@ -297,6 +300,8 @@ def selectWayside(self):
self.blockMenu.addItems([block.ID])

self.FileParser = Parser(None,self.greenCrossingTriplesIDS,self.allGreenBlocks)
self.sendAllBlocks.emit(self.greenWayside2Blocks)


if selectedIndex == 0 and self.selectRedLine.isChecked():
self.currentBlocks = self.redWayside1Blocks
Expand All @@ -311,6 +316,7 @@ def selectWayside(self):
self.currentSwitchBlocksNums = self.redCrossingTriplesIDS

self.FileParser = Parser(None,self.redCrossingTriplesIDS,self.allRedBlocks)
self.sendAllBlocks.emit(self.redWayside1Blocks)

if selectedIndex == 1 and self.selectRedLine.isChecked():
self.currentBlocks = self.redWayside2Blocks
Expand All @@ -325,6 +331,7 @@ def selectWayside(self):
self.currentSwitchBlocksNums = self.redCrossingTriplesIDS

self.FileParser = Parser(None,self.redCrossingTriplesIDS,self.allRedBlocks)
self.sendAllBlocks.emit(self.redWayside2Blocks)

def blockActions(self):
selectedIndex = self.blockMenu.currentIndex()
Expand Down Expand Up @@ -485,7 +492,8 @@ def updateBlocks(self,new_data):
blockNum = int(block[1:])
for x in (self.green5blocks[blockNum - 1]):
if self.allGreenBlocks[x - 1].occupied:
self.sendTrainSpeedAuth.emit(0,0,0)
self.sendTrainSpeedAuth.emit([0,0,0])
self.allGreenBlocks[x - 1].authority = False

self.BlockOcc.setText(" ".join(sentBlocks))
if self.label_7.text() == "AUTOMATIC" : self.FileParser.parsePLC()
Expand All @@ -503,6 +511,7 @@ class TestBench(QMainWindow):
tbChangeMode = pyqtSignal() #Fliping mode
ctcSpeed = pyqtSignal(Block) #sending updated block with speed
ctcAuthority = pyqtSignal(Block) #sending updated block with authority
ctcIDSpeedAuthority = pyqtSignal(list)

def __init__(self):
super().__init__()
Expand All @@ -515,14 +524,20 @@ def __init__(self):
self.addBlock.returnPressed.connect(self.addBlockOcc)
self.removeBlock.returnPressed.connect(self.remBlockOcc)
self.tbBlockMenu.currentIndexChanged.connect(self.updateBlockStates)

#Menu
self.tbBlockMenu.addItems(['A1','A2','A3','A4','A5','B6','B7','B8','B9','B10','C11','C12','C13','C14','C15'])
self.lineEdit.returnPressed.connect(self.receiveInitialIDSpeedAuth)

#Backend vars
self.OccupiedBlocks = [] #Is sent to the UI
self.specialBlocks = [] #Is sent from the UI

#blocks per wayside
self.greenW2Blocks = []
self.redW1Blocks = []
self.redW2Blocks = []

#train id, speed, authority to send
self.idSpeedAuthority = []

def sendSpeed(self):
speed = self.speedInput.text()
self.comSpeed.setText(speed)
Expand Down Expand Up @@ -574,7 +589,7 @@ def updateBlockStates(self, arr):


else:
if arr > len(self.specialBlocks) - 1: return
if arr > len(self.specialBlocks) - 1 or arr == -1: return
selectedBlock = self.specialBlocks[arr]

self.comSpeed.setText(str(selectedBlock.speedLimit))
Expand Down Expand Up @@ -604,18 +619,37 @@ def updateBlockStates(self, arr):
if selectedBlock.switchState:
self.label_19.setText("")
self.label_22.setText("")
self.label_24.setText("B6")
self.label_24.setText("LEFT")
else:
self.label_19.setText("")
self.label_22.setText("")
self.label_24.setText("C11")
self.label_24.setText("RIGHT")

def receiveMode(self,mode):
if mode == True:
self.label_16.setText("MANUAL")
else:
self.label_16.setText("AUTOMATIC")


def receiveBlocks(self,blocks):
self.tbBlockMenu.clear()
if blocks[0].Wayside == "W2" and blocks[0].lineColor == "Green":
self.greenW2Blocks = blocks
for block in self.greenW2Blocks: self.tbBlockMenu.addItems([block.ID])
elif blocks[0].Wayside == "W1" and blocks[0].lineColor == "Red":
self.redW1Blocks = blocks
for block in self.redW1Blocks: self.tbBlockMenu.addItems([block.ID])
elif blocks[0].Wayside == "W2" and blocks[0].lineColor == "Red":
self.redW2Blocks = blocks
for block in self.redW2Blocks: self.tbBlockMenu.addItems([block.ID])

def receiveInitialIDSpeedAuth(self):
text = self.lineEdit.text()
splits = text.split(", ")
self.comSpeed.setText(splits[1])
self.authOut.setText(splits[2])
self.ctcIDSpeedAuthority.emit(splits)


if __name__ == "__main__":
app = QApplication(sys.argv)
Expand All @@ -625,12 +659,12 @@ def receiveMode(self,mode):
#Signal: Window
window.sendSpecialBlocks.connect(window2.updateBlockStates)
window.changeModeSend.connect(window2.receiveMode)
window.sendAllBlocks.connect(window2.receiveBlocks)

#Signal: Window 2
window2.OccBlocksChanged.connect(window.updateBlocks)
window2.tbChangeMode.connect(window.changeMode)
window2.ctcSpeed.connect(window.receiveSpeedAuth)
window2.ctcAuthority.connect(window.receiveSpeedAuth)
window2.ctcIDSpeedAuthority.connect(window.receiveSpeedAuth)

window.show()
window2.show()
Expand Down

0 comments on commit 0503982

Please sign in to comment.