def handleCommand(self, message): """handles received command""" #look inside base class if super().handleCommand(message): return True pcaId = None conf = None if len(message) > 1: pcaId = message[1].decode() if len(message) > 2: conf = configObject(json.loads(message[2].decode())) command = message[0].decode() if command == FLESTransitions.start: if pcaId and pcaId in self.PCAs: self.commandSocket.send(codes.ok) self.startRecording(pcaId) else: self.commandSocket.send(codes.error) elif command == FLESTransitions.stop: if pcaId and pcaId in self.PCAs: self.commandSocket.send(codes.ok) self.stopRecording(pcaId) else: self.commandSocket.send(codes.error) else: return False return True
def handleCommand(self, message): """handles commands for DetectorB returns False if command is unknown""" if not DetectorTransitions.isUserTransition(message[0].decode()): return super().handleCommand(message) #handle Transition if len(message) == 2: command, conf = message command = command.decode() conf = configObject(json.loads(conf.decode())) else: command = message[0].decode() conf = None if self.stateMachine.currentState not in { DetectorStatesB.Active, DetectorStatesB.Unconfigured } and command not in { DetectorTransitions.abort, DetectorTransitions.reset }: self.commandSocket.send(codes.busy) return True elif not self.stateMachine.checkIfPossible(command): self.commandSocket.send(codes.error) return True else: self.commandSocket.send(codes.ok) self.abort = False if command == DetectorTransitions.configure: self.transition(DetectorTransitions.configure, conf) self.inTransition = True workThread = threading.Thread(name="worker", target=self.configure, args=(conf, )) workThread.start() elif command == DetectorTransitions.abort: self.abortFunction() elif command == DetectorTransitions.reset: self.reset() elif command == DetectorTransitions.error: self.error() else: return False return True
def handleCommand(self, message): """handles command common for all Global Systems; returns False if command is unknown""" command = message[0] pcaId = None if len(message) > 1: pcaId = message[1].decode() if command == codes.ping: self.commandSocket.send(codes.ok) elif command == codes.pcaAsksForDetectorStatus: pcaId = message[1].decode() if pcaId and pcaId in self.PCAs: if pcaId in self.pcaConfigTag: self.commandSocket.send_multipart([ self.StateMachineForPca[pcaId].currentState.encode(), self.pcaConfigTag[pcaId].encode() ]) else: self.commandSocket.send_multipart( [self.StateMachineForPca[pcaId].currentState.encode()]) elif command == codes.addPartition: data = partitionDataObject(json.loads(message[1].decode())) self.addPartition(data) self.commandSocket.send(codes.ok) elif command == codes.deletePartition: pcaId = message[1].decode() self.deletePartition(pcaId) self.commandSocket.send(codes.ok) elif command == codes.remapDetector: detectorId = message[2].decode() if message[1] == codes.removed: self.abortFunction(self.detectorMapping[detectorId]) del self.detectorMapping[detectorId] else: pcaId = message[1].decode() self.abortFunction(pcaId) if detectorId in self.detectorMapping: self.abortFunction(self.detectorMapping[detectorId]) self.detectorMapping[detectorId] = pcaId self.commandSocket.send(codes.ok) #transitions elif command.decode() == GlobalSystemTransitions.configure: conf = None if len(message) > 2: conf = configObject(json.loads(message[2].decode())) if self.isPCAinTransition[pcaId]: self.commandSocket.send(codes.busy) elif not self.StateMachineForPca[pcaId].checkIfPossible( GlobalSystemTransitions.configure) or not conf: self.commandSocket.send(codes.error) print("error") else: self.commandSocket.send(codes.ok) self.isPCAinTransition[pcaId] = True workThread = threading.Thread(name="worker", target=self.configure, args=(pcaId, conf)) workThread.start() elif command.decode() == GlobalSystemTransitions.abort: if pcaId and pcaId in self.PCAs: self.abortFunction(pcaId) self.commandSocket.send(codes.ok) else: self.commandSocket.send(codes.error) elif command.decode() == GlobalSystemTransitions.reset: self.reset(pcaId) self.commandSocket.send(codes.ok) else: #command unknown return False return True