Adds more functionality to the simulation
This commit is contained in:
@ -16,6 +16,7 @@ class CounterBox:
|
|||||||
def __init__(self, total_channels):
|
def __init__(self, total_channels):
|
||||||
self.total_channels = total_channels
|
self.total_channels = total_channels
|
||||||
self.counts = [0] * self.total_channels
|
self.counts = [0] * self.total_channels
|
||||||
|
self.rates = [randrange(5) for i in range(self.total_channels)]
|
||||||
|
|
||||||
self.status = 0
|
self.status = 0
|
||||||
self.countmode = 'time'
|
self.countmode = 'time'
|
||||||
@ -41,7 +42,8 @@ class CounterBox:
|
|||||||
|
|
||||||
def updateCounts(self):
|
def updateCounts(self):
|
||||||
for i in range(self.total_channels):
|
for i in range(self.total_channels):
|
||||||
self.counts[i] += randrange(5)
|
self.rates[i] = randrange(5)
|
||||||
|
self.counts[i] += self.rates[i]
|
||||||
|
|
||||||
def getRunTime(self):
|
def getRunTime(self):
|
||||||
elapsed = round(time.time() - self.starttime, 3)
|
elapsed = round(time.time() - self.starttime, 3)
|
||||||
@ -68,6 +70,10 @@ class CounterBox:
|
|||||||
|
|
||||||
return self.elapsed
|
return self.elapsed
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.getRunTime()
|
||||||
|
self.status = 0
|
||||||
|
|
||||||
def startTimePreset(self, presettime):
|
def startTimePreset(self, presettime):
|
||||||
self.countmode = 'time'
|
self.countmode = 'time'
|
||||||
self.status = 1
|
self.status = 1
|
||||||
@ -80,6 +86,15 @@ class CounterBox:
|
|||||||
self.presetcount = presetcount
|
self.presetcount = presetcount
|
||||||
self.resetCounts()
|
self.resetCounts()
|
||||||
|
|
||||||
|
def setMonitorChannel(self, channel):
|
||||||
|
self.monitor = channel - 1
|
||||||
|
|
||||||
|
def getMonitorChannel(self):
|
||||||
|
return self.monitor + 1
|
||||||
|
|
||||||
|
def getRate(self, channel):
|
||||||
|
return float(self.rates[channel - 1])
|
||||||
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
|
|
||||||
s.bind((HOST, PORT))
|
s.bind((HOST, PORT))
|
||||||
@ -129,6 +144,9 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|||||||
elif data == 'RS':
|
elif data == 'RS':
|
||||||
send(str(counterbox.getStatus()))
|
send(str(counterbox.getStatus()))
|
||||||
|
|
||||||
|
elif data == 'S':
|
||||||
|
counterbox.stop()
|
||||||
|
|
||||||
elif re.fullmatch(r'TP (\d+(\.\d+)?)', data):
|
elif re.fullmatch(r'TP (\d+(\.\d+)?)', data):
|
||||||
presettime = float(re.fullmatch(r'TP (\d+(\.\d+)?)', data).group(1))
|
presettime = float(re.fullmatch(r'TP (\d+(\.\d+)?)', data).group(1))
|
||||||
counterbox.startTimePreset(presettime)
|
counterbox.startTimePreset(presettime)
|
||||||
@ -139,6 +157,17 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|||||||
counterbox.startCountPreset(counts)
|
counterbox.startCountPreset(counts)
|
||||||
send('')
|
send('')
|
||||||
|
|
||||||
|
elif data == 'PC':
|
||||||
|
send(str(counterbox.getMonitorChannel()))
|
||||||
|
|
||||||
|
elif re.fullmatch(r'PC (\d+)', data):
|
||||||
|
channel = int(re.fullmatch(r'PC (\d+)', data).group(1))
|
||||||
|
counterbox.setMonitorChannel(channel)
|
||||||
|
|
||||||
|
elif re.fullmatch(r'RR (\d+)', data):
|
||||||
|
channel = int(re.fullmatch(r'RR (\d+)', data).group(1))
|
||||||
|
send(counterbox.getRate(channel))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send('?2') # Bad command
|
send('?2') # Bad command
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user