Ejemplo n.º 1
0
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU((byte)0x07);

            pdu.Write("Reserved", (byte)0x00);
            pdu.Write("Reserved", (byte)0x00);
            pdu.Write("Source", (byte)_s);
            pdu.Write("Reason", (byte)_r);
            return(pdu);
        }
Ejemplo n.º 2
0
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU(0x04);

            foreach (PDV pdv in _pdvs)
            {
                pdv.Write(pdu);
            }
            return(pdu);
        }
Ejemplo n.º 3
0
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU((byte)0x03);

            pdu.Write("Reserved", (byte)0x00);
            pdu.Write("Result", (byte)_rt);
            pdu.Write("Source", (byte)_so);
            pdu.Write("Reason", (byte)_rn);
            return(pdu);
        }
Ejemplo n.º 4
0
        public void Write(RawPDU pdu)
        {
            byte mch = (byte)((_last ? 2 : 0) + (_command ? 1 : 0));

            pdu.MarkLength32("PDV-Length");
            pdu.Write("Presentation Context ID", _pcid);
            pdu.Write("Message Control Header", mch);
            pdu.Write("PDV Value", _value);
            pdu.WriteLength32();
        }
Ejemplo n.º 5
0
        public void Read(RawPDU raw)
        {
            uint len  = raw.Length;
            uint read = 0;

            while (read < len)
            {
                PDV pdv = new PDV();
                read += pdv.Read(raw);
                _pdvs.Add(pdv);
            }
        }
Ejemplo n.º 6
0
        public uint Read(RawPDU raw)
        {
            uint len = raw.ReadUInt32("PDV-Length");

            _pcid = raw.ReadByte("Presentation Context ID");
            byte mch = raw.ReadByte("Message Control Header");

            _value   = raw.ReadBytes("PDV Value", (int)len - 2);
            _command = (mch & 0x01) != 0;
            _last    = (mch & 0x02) != 0;
            return(len + 4);
        }
Ejemplo n.º 7
0
        private void WritePDU(bool last)
        {
            if (_pdu.PDVs.Count == 0 || ((CurrentPduSize() + 6) < _max && GetBufferLength() > 0))
            {
                CreatePDV(last);
            }
            if (_pdu.PDVs.Count > 0)
            {
                if (last)
                {
                    _pdu.PDVs[_pdu.PDVs.Count - 1].IsLastFragment = true;
                }
                RawPDU raw = _pdu.Write();

                _networkBase.EnqueuePdu(raw);
                if (OnTick != null)
                {
                    OnTick();
                }
                _pdu = new PDataTF();
            }
        }
Ejemplo n.º 8
0
 public void Read(RawPDU raw)
 {
     raw.ReadUInt32("Reserved");
 }
Ejemplo n.º 9
0
        public void Read(RawPDU raw)
        {
            uint l = raw.Length;

            raw.ReadUInt16("Version");
            raw.SkipBytes("Reserved", 2);
            raw.SkipBytes("Reserved", 16);
            raw.SkipBytes("Reserved", 16);
            raw.SkipBytes("Reserved", 32);
            l -= 68;

            while (l > 0)
            {
                byte type = raw.ReadByte("Item-Type");
                l -= 1;

                if (type == 0x10)
                {
                    // Application Context
                    raw.SkipBytes("Reserved", 1);
                    ushort c = raw.ReadUInt16("Item-Length");
                    raw.SkipBytes("Value", (int)c);
                    l -= 3 + (uint)c;
                }
                else

                if (type == 0x21)
                {
                    // Presentation Context
                    raw.ReadByte("Reserved");
                    ushort pl = raw.ReadUInt16("Presentation Context Item-Length");
                    byte   id = raw.ReadByte("Presentation Context ID");
                    raw.ReadByte("Reserved");
                    byte res = raw.ReadByte("Presentation Context Result/Reason");
                    raw.ReadByte("Reserved");
                    l  -= (uint)pl + 3;
                    pl -= 4;

                    // Presentation Context Transfer Syntax
                    raw.ReadByte("Presentation Context Item-Type (0x40)");
                    raw.ReadByte("Reserved");
                    ushort tl = raw.ReadUInt16("Presentation Context Item-Length");
                    string tx = raw.ReadString("Presentation Context Syntax UID", tl);
                    pl -= (ushort)(tl + 4);

                    _assoc.SetPresentationContextResult(id, (DicomPresContextResult)res);
                    TransferSyntax acceptedSyntax = TransferSyntax.GetTransferSyntax(tx);
                    if (acceptedSyntax != null)
                    {
                        _assoc.SetAcceptedTransferSyntax(id, acceptedSyntax);
                    }
                    else
                    {
                        _assoc.GetPresentationContext(id).ClearTransfers();
                    }
                }
                else

                if (type == 0x50)
                {
                    // User Information
                    raw.ReadByte("Reserved");
                    ushort il = raw.ReadUInt16("User Information Item-Length");
                    l -= (uint)(il + 3);
                    while (il > 0)
                    {
                        byte ut = raw.ReadByte("User Item-Type");
                        raw.ReadByte("Reserved");
                        ushort ul = raw.ReadUInt16("User Item-Length");
                        il -= (ushort)(ul + 4);
                        if (ut == 0x51)
                        {
                            _assoc.RemoteMaximumPduLength = raw.ReadUInt32("Max PDU Length");
                        }
                        else if (ut == 0x52)
                        {
                            _assoc.ImplementationClass = DicomUids.Lookup(raw.ReadString("Implementation Class UID", ul));
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.ImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else
                        {
                            raw.SkipBytes("User Item Value", (int)ul);
                        }
                    }
                }

                else
                {
                    raw.SkipBytes("Reserved", 1);
                    ushort il = raw.ReadUInt16("User Item-Length");
                    raw.SkipBytes("Unknown User Item", il);
                    l -= (uint)(il + 3);
                }
            }
        }
Ejemplo n.º 10
0
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU((byte)0x02);

            pdu.Write("Version", (ushort)0x0001);
            pdu.Write("Reserved", 0x00, 2);
            pdu.Write("Called AE", _assoc.CalledAE, 16, ' ');
            pdu.Write("Calling AE", _assoc.CallingAE, 16, ' ');
            pdu.Write("Reserved", 0x00, 32);

            // Application Context
            pdu.Write("Item-Type", (byte)0x10);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Application Context Name", DicomUids.DICOMApplicationContextName.UID);
            pdu.WriteLength16();

            foreach (DicomPresContext pc in _assoc.GetPresentationContexts())
            {
                // Presentation Context
                pdu.Write("Item-Type", (byte)0x21);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Presentation Context ID", (byte)pc.ID);
                pdu.Write("Reserved", (byte)0x00);
                pdu.Write("Result", (byte)pc.Result);
                pdu.Write("Reserved", (byte)0x00);

                // Transfer Syntax
                pdu.Write("Item-Type", (byte)0x40);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                if (pc.AcceptedTransferSyntax != null) //
                {
                    pdu.Write("Transfer Syntax UID", pc.AcceptedTransferSyntax.DicomUid.UID);
                }
                pdu.WriteLength16();

                pdu.WriteLength16();
            }

            // User Data Fields
            pdu.Write("Item-Type", (byte)0x50);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");

            // Maximum PDU
            pdu.Write("Item-Type", (byte)0x51);
            pdu.Write("Reserved", (byte)0x00);
            pdu.Write("Item-Length", (ushort)0x0004);
            pdu.Write("Max PDU Length", (uint)_assoc.LocalMaximumPduLength);

            // Implementation Class UID
            pdu.Write("Item-Type", (byte)0x52);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Class UID", DicomImplementation.ClassUID.UID);
            pdu.WriteLength16();

            // Implementation Version
            pdu.Write("Item-Type", (byte)0x55);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Version", DicomImplementation.Version);
            pdu.WriteLength16();

            pdu.WriteLength16();

            return(pdu);
        }
Ejemplo n.º 11
0
        public void Read(RawPDU raw)
        {
            uint l = raw.Length;

            raw.ReadUInt16("Version");
            raw.SkipBytes("Reserved", 2);
            _assoc.CalledAE  = raw.ReadString("Called AE", 16);
            _assoc.CallingAE = raw.ReadString("Calling AE", 16);
            raw.SkipBytes("Reserved", 32);
            l -= 2 + 2 + 16 + 16 + 32;

            while (l > 0)
            {
                byte type = raw.ReadByte("Item-Type");
                raw.SkipBytes("Reserved", 1);
                ushort il = raw.ReadUInt16("Item-Length");

                l -= 4 + (uint)il;

                if (type == 0x10)
                {
                    // Application Context
                    raw.SkipBytes("Application Context", il);
                }
                else

                if (type == 0x20)
                {
                    // Presentation Context
                    byte id = raw.ReadByte("Presentation Context ID");
                    raw.SkipBytes("Reserved", 3);
                    il -= 4;

                    while (il > 0)
                    {
                        byte pt = raw.ReadByte("Presentation Context Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        ushort pl = raw.ReadUInt16("Presentation Context Item-Length");
                        string sx = raw.ReadString("Presentation Context Syntax UID", pl);
                        if (pt == 0x30)
                        {
                            SopClass sopClass = SopClass.GetSopClass(sx);
                            if (sopClass == null)
                            {
                                sopClass = new SopClass("Private SOP Class", sx, false);
                            }
                            _assoc.AddPresentationContext(id, sopClass);
                        }
                        else if (pt == 0x40)
                        {
                            TransferSyntax transferSyntax = TransferSyntax.GetTransferSyntax(sx);
                            if (transferSyntax == null)
                            {
                                transferSyntax = new TransferSyntax("Private Syntax", sx, true, false, true, false, false, false);
                            }
                            _assoc.AddTransferSyntax(id, transferSyntax);
                        }
                        il -= (ushort)(4 + pl);
                    }
                }
                else

                if (type == 0x50)
                {
                    // User Information
                    while (il > 0)
                    {
                        byte ut = raw.ReadByte("User Information Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        ushort ul = raw.ReadUInt16("User Information Item-Length");
                        il -= (ushort)(4 + ul);
                        if (ut == 0x51)
                        {
                            _assoc.RemoteMaximumPduLength = raw.ReadUInt32("Max PDU Length");
                        }
                        else if (ut == 0x52)
                        {
                            _assoc.ImplementationClass = new DicomUid(raw.ReadString("Implementation Class UID", ul), "Implementation Class UID", UidType.Unknown);
                        }
                        else if (ut == 0x53)
                        {
                            _assoc.RemoteMaxOperationsInvoked   = raw.ReadUInt16("Max Operations Invoked");
                            _assoc.RemoteMaxOperationsPerformed = raw.ReadUInt16("Max Operations Performed");
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.ImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else if (ut == 0x54)
                        {
                            raw.SkipBytes("SCU/SCP Role Selection", ul);

                            /*
                             * ushort rsul = raw.ReadUInt16();
                             * if ((rsul + 4) != ul) {
                             *  throw new DicomNetworkException("SCU/SCP role selection length (" + ul + " bytes) does not match uid length (" + rsul + " + 4 bytes)");
                             * }
                             * raw.ReadChars(rsul);	// Abstract Syntax
                             * raw.ReadByte();		// SCU role
                             * raw.ReadByte();		// SCP role
                             */
                        }
                        else
                        {
                            LogAdapter.Logger.ErrorWithFormat("Unhandled user item: 0x{0:x2} ({1} + 4 bytes)", ut, ul);
                            raw.SkipBytes("Unhandled User Item", ul);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU(0x01);

            pdu.Write("Version", (ushort)0x0001);
            pdu.Write("Reserved", 0x00, 2);
            pdu.Write("Called AE", _assoc.CalledAE, 16, ' ');
            pdu.Write("Calling AE", _assoc.CallingAE, 16, ' ');
            pdu.Write("Reserved", 0x00, 32);

            // Application Context
            pdu.Write("Item-Type", (byte)0x10);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Application Context Name", DicomUids.DICOMApplicationContextName.UID);
            pdu.WriteLength16();

            if (_assoc.GetPresentationContexts().Count == 0)
            {
                throw new DicomException("No presentation contexts set for association");
            }

            foreach (DicomPresContext pc in _assoc.GetPresentationContexts())
            {
                // Presentation Context
                pdu.Write("Item-Type", (byte)0x20);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Presentation Context ID", (byte)pc.ID);
                pdu.Write("Reserved", (byte)0x00, 3);

                // Abstract Syntax
                pdu.Write("Item-Type", (byte)0x30);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Abstract Syntax UID", pc.AbstractSyntax.Uid);
                pdu.WriteLength16();

                if (pc.GetTransfers().Count == 0)
                {
                    throw new DicomException("No transfer syntaxes set for presentation context " + pc.AbstractSyntax.Name);
                }

                // Transfer Syntax
                foreach (TransferSyntax ts in pc.GetTransfers())
                {
                    pdu.Write("Item-Type", (byte)0x40);
                    pdu.Write("Reserved", (byte)0x00);
                    pdu.MarkLength16("Item-Length");
                    pdu.Write("Transfer Syntax UID", ts.DicomUid.UID);
                    pdu.WriteLength16();
                }

                pdu.WriteLength16();
            }

            // User Data Fields
            pdu.Write("Item-Type", 0x50);
            pdu.Write("Reserved", 0x00);
            pdu.MarkLength16("Item-Length");

            // Maximum PDU
            pdu.Write("Item-Type", 0x51);
            pdu.Write("Reserved", 0x00);
            pdu.Write("Item-Length", (ushort)0x0004);
            pdu.Write("Max PDU Length", _assoc.LocalMaximumPduLength);

            // Asychronous Window
            if (_assoc.LocalMaxOperationsInvoked != 1 || _assoc.LocalMaxOperationsPerformed != 1)
            {
                pdu.Write("Item-Type", (byte)0x53);
                pdu.Write("Reserved", (byte)0x00);
                pdu.Write("Item-Length", (ushort)0x0004);
                pdu.Write("Max Operations Invoked", (ushort)_assoc.LocalMaxOperationsInvoked);
                pdu.Write("Max Operations Invoked", (ushort)_assoc.LocalMaxOperationsPerformed);
            }

            // SCU / SCP Role Selection

            // Implementation Class UID
            pdu.Write("Item-Type", (byte)0x52);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Class UID", DicomImplementation.ClassUID.UID);
            pdu.WriteLength16();

            // Implementation Version
            pdu.Write("Item-Type", (byte)0x55);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Version", DicomImplementation.Version);
            pdu.WriteLength16();

            pdu.WriteLength16();

            return(pdu);
        }