def SCP(self, msg): ds = dsutils.decode(msg.Identifier, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # make response rsp = C_FIND_ServiceParameters() rsp.MessageIDBeingRespondedTo = msg.MessageID rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID gen = self.AE.OnReceiveFind(self, ds) try: while 1: time.sleep(0.001) IdentifierDS, status = gen.next() rsp.Status = int(status) rsp.Identifier = dsutils.encode( IdentifierDS, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send response self.DIMSE.Send(rsp, self.pcid, self.ACSE.MaxPDULength) except StopIteration: # send final response rsp = C_FIND_ServiceParameters() rsp.MessageIDBeingRespondedTo = msg.MessageID rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID rsp.Status = int(self.Success) self.DIMSE.Send(rsp, self.pcid, self.ACSE.MaxPDULength)
def SCU(self, ds, msgid): # build C-FIND primitive cfind = C_FIND_ServiceParameters() cfind.MessageID = msgid cfind.AffectedSOPClassUID = self.UID cfind.Priority = 0x0002 cfind.Identifier = dsutils.encode(ds, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send c-find request self.DIMSE.Send(cfind, self.pcid, self.maxpdulength) while 1: time.sleep(0.001) # wait for c-find responses ans, id = self.DIMSE.Receive(Wait=False) if not ans: continue d = dsutils.decode(ans.Identifier, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) try: status = self.Code2Status(ans.Status.value) except: status = None if status and status.Type != 'Pending': break yield status, d yield status, d
def SCU(self, ds, msgid): # build C-FIND primitive cfind = C_FIND_ServiceParameters() cfind.MessageID = msgid cfind.AffectedSOPClassUID = self.UID cfind.Priority = 0x0002 cfind.Identifier = dsutils.encode(ds, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send c-find request self.DIMSE.Send(cfind, self.pcid, self.maxpdulength) while 1: time.sleep(0.001) # wait for c-find responses ans, id = self.DIMSE.Receive(Wait=False) if not ans: continue d = dsutils.decode( ans.Identifier, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) try: status = self.Code2Status(ans.Status.value).Type except: status = None if status != 'Pending': break yield status, d yield status, d
def SCU(self, ds, destaet, msgid): # build C-FIND primitive cmove = C_MOVE_ServiceParameters() cmove.MessageID = msgid cmove.AffectedSOPClassUID = self.UID cmove.MoveDestination = destaet cmove.Priority = 0x0002 cmove.Identifier = dsutils.encode( ds, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send c-find request self.DIMSE.Send(cmove, self.pcid, self.maxpdulength) while 1: # wait for c-move responses time.sleep(0.001) ans, id = self.DIMSE.Receive(Wait=False) if not ans: yield None,None continue status = self.Code2Status(ans.Status.value) yield status,ans if status and status.Type != 'Pending': break # last answer
def SCU(self, ds, destaet, msgid): # build C-FIND primitive cmove = C_MOVE_ServiceParameters() cmove.MessageID = msgid cmove.AffectedSOPClassUID = self.UID cmove.MoveDestination = destaet cmove.Priority = 0x0002 cmove.Identifier = dsutils.encode(ds, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send c-find request self.DIMSE.Send(cmove, self.pcid, self.maxpdulength) while 1: # wait for c-move responses time.sleep(0.001) ans, id = self.DIMSE.Receive(Wait=False) if not ans: continue status = self.Code2Status(ans.Status.value) yield status, ans if status and status.Type != 'Pending': break # last answer
def SCU(self, dataset, msgid): # build C-STORE primitive csto = C_STORE_ServiceParameters() csto.MessageID = msgid csto.AffectedSOPClassUID = dataset.SOPClassUID csto.AffectedSOPInstanceUID = dataset.SOPInstanceUID csto.Priority = 0x0002 csto.DataSet = dsutils.encode(dataset, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send cstore request self.DIMSE.Send(csto, self.pcid, self.maxpdulength) # wait for c-store response ans, id = self.DIMSE.Receive(Wait=True) return self.Code2Status(ans.Status.value)
def SCU(self, ds, msgid): # build C-GET primitive cget = C_GET_ServiceParameters() cget.MessageID = msgid cget.AffectedSOPClassUID = self.UID cget.Priority = 0x0002 cget.Identifier = dsutils.encode(ds, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send c-get primitive self.DIMSE.Send(cget, self.pcid, self.maxpdulength) while 1: # receive c-store msg, id = self.DIMSE.Receive(Wait=True) if msg.__class__ == C_GET_ServiceParameters: status = self.Code2Status(msg.Status.value) yield status, msg if status.Type != 'Pending': break # last answer elif msg.__class__ == C_STORE_ServiceParameters: # send c-store response rsp = C_STORE_ServiceParameters() rsp.MessageIDBeingRespondedTo = msg.MessageID rsp.AffectedSOPInstanceUID = msg.AffectedSOPInstanceUID rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID try: d = dsutils.decode(msg.DataSet, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) SOPClass = UID2SOPClass(d.SOPClassUID) SOPClass.transfersyntax = self.transfersyntax status = self.AE.OnReceiveStore(SOPClass, d) except: # cannot understand status = self.CannotUnderstand rsp.Status = int(status) self.DIMSE.Send(rsp, id, self.maxpdulength)
def SCU(self, ds, msgid): # build C-GET primitive cget = C_GET_ServiceParameters() cget.MessageID = msgid cget.AffectedSOPClassUID = self.UID cget.Priority = 0x0002 cget.Identifier = dsutils.encode(ds, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send c-get primitive self.DIMSE.Send(cget, self.pcid, self.maxpdulength) while 1: # receive c-store msg, id = self.DIMSE.Receive(Wait=True) if msg.__class__ == C_GET_ServiceParameters: status = self.Code2Status(msg.Status.value) yield status,msg if status.Type != 'Pending': break # last answer elif msg.__class__ == C_STORE_ServiceParameters: # send c-store response rsp = C_STORE_ServiceParameters() rsp.MessageIDBeingRespondedTo = msg.MessageID rsp.AffectedSOPInstanceUID = msg.AffectedSOPInstanceUID rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID try: d = dsutils.decode( msg.DataSet, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) SOPClass = UID2SOPClass(d.SOPClassUID) SOPClass.transfersyntax = self.transfersyntax status = self.AE.OnReceiveStore(SOPClass, d) except: # cannot understand status = self.CannotUnderstand rsp.Status = int(status) self.DIMSE.Send(rsp, id, self.maxpdulength)
def Encode(self, id, maxpdulength): """Returns the encoded message as a series of P-DATA service parameter objects""" self.ID = id pdatas = [] encoded_command_set = dsutils.encode(self.CommandSet, self.ts.is_implicit_VR, self.ts.is_little_endian) # fragment command set pdvs = fragment(maxpdulength, encoded_command_set) assert ''.join(pdvs) == encoded_command_set for ii in pdvs[:-1]: # send only one pdv per pdata primitive pdata = P_DATA_ServiceParameters() # not last command fragment pdata.PresentationDataValueList = [[self.ID, pack('b', 1) + ii]] pdatas.append(pdata) # last command fragment pdata = P_DATA_ServiceParameters() # last command fragment pdata.PresentationDataValueList = [[self.ID, pack('b', 3) + pdvs[-1]]] pdatas.append(pdata) # fragment data set #if self.__dict__.has_key('DataSet') and self.DataSet: if 'DataSet' in self.__dict__ and self.DataSet is not None: pdvs = fragment(maxpdulength, self.DataSet) assert ''.join(pdvs) == self.DataSet for ii in pdvs[:-1]: pdata = P_DATA_ServiceParameters() # not last data fragment pdata.PresentationDataValueList = [[ self.ID, pack('b', 0) + ii ]] pdatas.append(pdata) pdata = P_DATA_ServiceParameters() # last data fragment pdata.PresentationDataValueList = [[ self.ID, pack('b', 2) + pdvs[-1] ]] pdatas.append(pdata) return pdatas
def Encode(self, id, maxpdulength): """Returns the encoded message as a series of P-DATA service parameter objects""" self.ID = id pdatas = [] encoded_command_set = dsutils.encode( self.CommandSet, self.ts.is_implicit_VR, self.ts.is_little_endian) # fragment command set pdvs = fragment(maxpdulength, encoded_command_set) assert ''.join(pdvs) == encoded_command_set for ii in pdvs[:-1]: # send only one pdv per pdata primitive pdata = P_DATA_ServiceParameters() # not last command fragment pdata.PresentationDataValueList = [[self.ID, pack('b', 1) + ii]] pdatas.append(pdata) # last command fragment pdata = P_DATA_ServiceParameters() # last command fragment pdata.PresentationDataValueList = [[self.ID, pack('b', 3) + pdvs[-1]]] pdatas.append(pdata) # fragment data set #if self.__dict__.has_key('DataSet') and self.DataSet: if 'DataSet' in self.__dict__ and self.DataSet is not None: pdvs = fragment(maxpdulength, self.DataSet) assert ''.join(pdvs) == self.DataSet for ii in pdvs[:-1]: pdata = P_DATA_ServiceParameters() # not last data fragment pdata.PresentationDataValueList = [ [self.ID, pack('b', 0) + ii]] pdatas.append(pdata) pdata = P_DATA_ServiceParameters() # last data fragment pdata.PresentationDataValueList = [ [self.ID, pack('b', 2) + pdvs[-1]]] pdatas.append(pdata) return pdatas
def SCP(self, msg): ds = dsutils.decode(msg.Identifier, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # make response rsp = C_GET_ServiceParameters() rsp.MessageIDBeingRespondedTo = msg.MessageID.value rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID.value rsp.Status = int(self.Pending) rsp.NumberOfRemainingSubOperations = 0 rsp.NumberOfCompletedSubOperations = 0 rsp.NumberOfFailedSubOperations = 0 rsp.NumberOfWarningSubOperations = 0 self.DIMSE.Send(rsp, self.pcid, self.maxpdulength) gen = self.AE.OnReceiveGet(self, ds) # # build C-STORE primitive csto = C_STORE_ServiceParameters() csto.MessageID = 0 for ds in gen: csto.AffectedSOPClassUID = ds.SOPClassUID csto.AffectedSOPInstanceUID = ds.SOPInstanceUID csto.Priority = 0x0002 csto.DataSet = dsutils.encode(ds, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian) # send cstore request self.DIMSE.Send(csto, self.pcid, self.maxpdulength) # wait for c-store response ans, id = self.DIMSE.Receive(Wait=True) # TODO: Handle the answers coming back if self.Code2Status(ans.Status.value).Type != 'Success': pass # TODO: Set various values on the rsp here rsp.Status = int(self.Success) self.DIMSE.Send(rsp, self.pcid, self.maxpdulength)