Exemplo n.º 1
0
            /// <summary>
            /// Function to read SCP statement from SCP statement.
            /// </summary>
            /// <param name="buffer">byte array</param>
            /// <param name="offset">position to start reading</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset)
            {
                if ((offset + Marshal.SizeOf(SequenceNr) + Marshal.SizeOf(Length)) > buffer.Length)
                {
                    return(0x1);
                }

                SequenceNr = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(SequenceNr), true);
                offset    += Marshal.SizeOf(SequenceNr);
                Length     = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Length), true);
                offset    += Marshal.SizeOf(Length);

                if (Length >= Marshal.SizeOf(TypeID))
                {
                    if ((offset + Length) > buffer.Length)
                    {
                        return(0x2);
                    }

                    TypeID  = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(TypeID), true);
                    offset += Marshal.SizeOf(TypeID);

                    if (Length > Marshal.SizeOf(TypeID))
                    {
                        Field   = new byte[Length - Marshal.SizeOf(TypeID)];
                        offset += BytesTool.copy(Field, 0, buffer, offset, Length - Marshal.SizeOf(TypeID));
                    }
                }

                return(0x0);
            }
Exemplo n.º 2
0
        public override bool CheckFormat(byte[] buffer, int offset)
        {
            if (buffer.Length >= HeaderSize)
            {
                // read in prefix part one.
                int    size      = PrefixOne.Length;
                String prefixOne = BytesTool.readString(buffer, offset, size);
                offset += size;

                // read in prefix part two.
                size = Marshal.SizeOf(PrefixTwo);
                Int16 prefixTwo = (Int16)BytesTool.readBytes(buffer, offset, size, LittleEndian);
                offset += size;

                if ((string.Compare(prefixOne, PrefixOne, false) == 0) &&
                    (prefixTwo == PrefixTwo))
                {
                    Int32 length = (Int32)BytesTool.readBytes(buffer, 0x0C, Marshal.SizeOf(NrOfSamples), LittleEndian);

                    if (length > 0)
                    {
                        // 12 bits per sample
                        length = length + (length >> 1);

                        return((offset + (HeaderSize - 6) + length) <= buffer.Length);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
            /// <summary>
            /// Function to write SCP statement.
            /// </summary>
            /// <param name="buffer">byte array to write into</param>
            /// <param name="offset">position to start writing</param>
            /// <returns>0 on success</returns>
            public int Write(byte[] buffer, int offset)
            {
                if (!Works())
                {
                    return(0x1);
                }

                if ((offset + getLength()) > buffer.Length)
                {
                    return(0x2);
                }

                int fieldSize = Marshal.SizeOf(_LeadId);

                BytesTool.writeBytes(_LeadId, buffer, offset, fieldSize, true);
                offset += fieldSize;

                fieldSize = Marshal.SizeOf(_LeadLength);
                BytesTool.writeBytes(_LeadLength, buffer, offset, fieldSize, true);
                offset += fieldSize;

                if (_LeadLength != 0)
                {
                    fieldSize = Marshal.SizeOf(typeof(short));

                    for (int i = 0; i < _Measurements.Length; i++)
                    {
                        BytesTool.writeBytes(_Measurements[i], buffer, offset, fieldSize, true);
                        offset += fieldSize;
                    }
                }

                return(0x0);
            }
Exemplo n.º 4
0
            /// <summary>
            /// Function to read SCP statement from SCP statement.
            /// </summary>
            /// <param name="buffer">byte array</param>
            /// <param name="offset">position to start reading</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset)
            {
                if ((offset + Marshal.SizeOf(_LeadId) + Marshal.SizeOf(_LeadLength)) > buffer.Length)
                {
                    return(0x1);
                }

                int fieldSize = Marshal.SizeOf(_LeadId);

                _LeadId = (ushort)BytesTool.readBytes(buffer, offset, fieldSize, true);
                offset += fieldSize;

                fieldSize   = Marshal.SizeOf(_LeadLength);
                _LeadLength = (ushort)BytesTool.readBytes(buffer, offset, fieldSize, true);
                offset     += fieldSize;

                if (_Measurements != null)
                {
                    if ((offset + _LeadLength) > buffer.Length)
                    {
                        return(0x2);
                    }

                    fieldSize = Marshal.SizeOf(typeof(short));

                    for (int i = 0; i < _Measurements.Length; i++)
                    {
                        _Measurements[i] = (short)BytesTool.readBytes(buffer, offset, fieldSize, true);
                        offset          += fieldSize;
                    }
                }

                return(0x0);
            }
Exemplo n.º 5
0
            /// <summary>
            /// Function to read an SCP huffman struct.
            /// </summary>
            /// <param name="buffer">byte array to read from</param>
            /// <param name="offset">position to start reading</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset)
            {
                if ((offset + Size) > buffer.Length)
                {
                    return(0x1);
                }

                prefix    = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(prefix), true);
                offset   += Marshal.SizeOf(prefix);
                entire    = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(entire), true);
                offset   += Marshal.SizeOf(entire);
                tablemode = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(tablemode), true);
                offset   += Marshal.SizeOf(tablemode);
                value     = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(value), true);
                offset   += Marshal.SizeOf(value);
                uint tempCode = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(code), true);

                offset += Marshal.SizeOf(code);

                // Have to reverse the code, because SCP stores it that way.
                code = 0;
                for (int loper = prefix; loper > 0; loper--)
                {
                    code     <<= 1;
                    code      |= (tempCode & 0x1);
                    tempCode >>= 1;
                }

                return(0x0);
            }
Exemplo n.º 6
0
            /// <summary>
            /// Function to read SCP extra measurements.
            /// </summary>
            /// <param name="buffer">byte array to read from</param>
            /// <param name="offset">position to start reading</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset)
            {
                Empty();
                int frontsize = Marshal.SizeOf(VentRate) + Marshal.SizeOf(AtrialRate) + Marshal.SizeOf(QTc) + Marshal.SizeOf(FormulaType) + Marshal.SizeOf(TaggedFieldSize);

                if ((offset + frontsize) > buffer.Length)
                {
                    return(0x1);
                }

                VentRate        = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(VentRate), true);
                offset         += Marshal.SizeOf(VentRate);
                AtrialRate      = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(AtrialRate), true);
                offset         += Marshal.SizeOf(AtrialRate);
                QTc             = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QTc), true);
                offset         += Marshal.SizeOf(QTc);
                FormulaType     = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(FormulaType), true);
                offset         += Marshal.SizeOf(FormulaType);
                TaggedFieldSize = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(TaggedFieldSize), true);
                offset         += Marshal.SizeOf(TaggedFieldSize);

                if (TaggedFieldSize > 0)
                {
                    if ((offset + TaggedFieldSize) > buffer.Length)
                    {
                        return(0x2);
                    }

                    TaggedFields = new byte[TaggedFieldSize];
                    offset      += BytesTool.copy(TaggedFields, 0, buffer, offset, TaggedFieldSize);
                }

                return(0x0);
            }
Exemplo n.º 7
0
            /// <summary>
            /// Function to write measurements.
            /// </summary>
            /// <param name="buffer">byte array to write into</param>
            /// <param name="offset">position to start writing</param>
            /// <returns>0 on success</returns>
            public int Write(byte[] buffer, int offset)
            {
                if ((offset + Size) > buffer.Length)
                {
                    return(0x1);
                }

                BytesTool.writeBytes(Ponset, buffer, offset, Marshal.SizeOf(Ponset), true);
                offset += Marshal.SizeOf(Ponset);
                BytesTool.writeBytes(Poffset, buffer, offset, Marshal.SizeOf(Poffset), true);
                offset += Marshal.SizeOf(Poffset);
                BytesTool.writeBytes(QRSonset, buffer, offset, Marshal.SizeOf(QRSonset), true);
                offset += Marshal.SizeOf(QRSonset);
                BytesTool.writeBytes(QRSoffset, buffer, offset, Marshal.SizeOf(QRSoffset), true);
                offset += Marshal.SizeOf(QRSoffset);
                BytesTool.writeBytes(Toffset, buffer, offset, Marshal.SizeOf(Toffset), true);
                offset += Marshal.SizeOf(Toffset);
                BytesTool.writeBytes(Paxis, buffer, offset, Marshal.SizeOf(Paxis), true);
                offset += Marshal.SizeOf(Paxis);
                BytesTool.writeBytes(QRSaxis, buffer, offset, Marshal.SizeOf(QRSaxis), true);
                offset += Marshal.SizeOf(QRSaxis);
                BytesTool.writeBytes(Taxis, buffer, offset, Marshal.SizeOf(Taxis), true);
                offset += Marshal.SizeOf(Taxis);

                return(0x0);
            }
Exemplo n.º 8
0
            /// <summary>
            /// Function to read measurements.
            /// </summary>
            /// <param name="buffer">byte array to read from</param>
            /// <param name="offset">position to start reading</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset)
            {
                if ((offset + Size) > buffer.Length)
                {
                    return(0x1);
                }

                Ponset    = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Ponset), true);
                offset   += Marshal.SizeOf(Ponset);
                Poffset   = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Poffset), true);
                offset   += Marshal.SizeOf(Poffset);
                QRSonset  = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QRSonset), true);
                offset   += Marshal.SizeOf(QRSonset);
                QRSoffset = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QRSoffset), true);
                offset   += Marshal.SizeOf(QRSoffset);
                Toffset   = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Toffset), true);
                offset   += Marshal.SizeOf(Toffset);
                Paxis     = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Paxis), true);
                offset   += Marshal.SizeOf(Paxis);
                QRSaxis   = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QRSaxis), true);
                offset   += Marshal.SizeOf(QRSaxis);
                Taxis     = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Taxis), true);
                offset   += Marshal.SizeOf(Taxis);

                return(0x0);
            }
Exemplo n.º 9
0
        protected override int _Write(byte[] buffer, int offset)
        {
            BytesTool.writeBytes(_MedianDataLength, buffer, offset, Marshal.SizeOf(_MedianDataLength), true);
            offset += Marshal.SizeOf(_MedianDataLength);
            BytesTool.writeBytes(_FirstFiducial, buffer, offset, Marshal.SizeOf(_FirstFiducial), true);
            offset += Marshal.SizeOf(_FirstFiducial);
            BytesTool.writeBytes(_NrQRS, buffer, offset, Marshal.SizeOf(_NrQRS), true);
            offset += Marshal.SizeOf(_NrQRS);
            for (int loper = 0; loper < _NrQRS; loper++)
            {
                int err = _Subtraction[loper].Write(buffer, offset);
                if (err != 0)
                {
                    return(err << loper);
                }
                offset += SCPQRSSubtraction.Size;
            }

            if (_Protected != null)
            {
                for (int loper = 0; loper < _NrQRS; loper++)
                {
                    int err = _Protected[loper].Write(buffer, offset);
                    if (err != 0)
                    {
                        return(err << loper);
                    }
                    offset += SCPQRSProtected.Size;
                }
            }
            return(0x0);
        }
Exemplo n.º 10
0
        public override int Read(Stream input, int offset)
        {
            if ((input != null) &&
                (input.CanRead))
            {
                // Reading information from stream to byte array.
                input.Seek(offset, SeekOrigin.Begin);
                byte[] buffer1 = new byte[HeaderSize];
                BytesTool.readStream(input, buffer1, 0, buffer1.Length);
                Int32 length = (Int32)BytesTool.readBytes(buffer1, 0x0C, Marshal.SizeOf(NrOfSamples), LittleEndian);

                if (length > 0)
                {
                    // 12 bits per sample
                    length = length + (length >> 1);

                    if ((offset + buffer1.Length + length) <= input.Length)
                    {
                        byte[] buffer2 = new byte[buffer1.Length + length];
                        BytesTool.readStream(input, buffer2, buffer1.Length, buffer2.Length - buffer1.Length);
                        BytesTool.copy(buffer2, 0, buffer1, 0, buffer1.Length);
                        // Read using function for byte array.
                        return(Read(buffer2, 0) << 1);
                    }
                }
            }
            return(0x1);
        }
Exemplo n.º 11
0
        private static int _WriteSignal(ref byte[] data, Signals sigs, double[] avm)
        {
            if (sigs == null)
            {
                return(-1);
            }

            int rhythmStart, rhythmEnd;

            sigs.CalculateStartAndEnd(out rhythmStart, out rhythmEnd);

            int nrLeads   = sigs.NrLeads,
                sigs_size = rhythmEnd - rhythmStart,
                buff_size = sigs_size * nrLeads * SHORT_SIZE;

            if ((sigs_size <= 0) ||
                (avm == null) ||
                (avm.Length != nrLeads))
            {
                return(-1);
            }

            if ((data == null) ||
                (data.Length < buff_size))
            {
                data = new byte[buff_size];
            }

            for (int pos = 0; pos < buff_size; pos += SHORT_SIZE)
            {
                int pos2   = pos / SHORT_SIZE,
                    lead   = pos2 % nrLeads,
                    sample = (pos2 / nrLeads) + rhythmStart;

                short curr = LEAD_FAULT_VALUE;

                if ((sample >= sigs[lead].RhythmStart) &&
                    (sample < sigs[lead].RhythmEnd))
                {
                    sample -= sigs[lead].RhythmStart;

                    if ((sample >= 0) &&
                        (sample < sigs[lead].Rhythm.Length))
                    {
                        curr = sigs[lead].Rhythm[sample];
                    }
                }

                if (curr != LEAD_FAULT_VALUE)
                {
                    curr = (short)((curr * sigs.RhythmAVM) / avm[lead]);
                }

                BytesTool.writeBytes(curr, data, pos, SHORT_SIZE, true);
            }

            return(buff_size);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Function to read data segment from buffer.
        /// </summary>
        /// <param name="buffer">buffer to read from</param>
        /// <param name="offset">position to start reading</param>
        /// <param name="littleEndian">true if little endian used</param>
        /// <param name="nrleads">number of leads in section</param>
        /// <param name="nrsamples">number of samples for each lead</param>
        /// <returns>0 on success</returns>
        public int Read(byte[] buffer, int offset, bool littleEndian, int nrleads, uint nrsamples, bool bIsADCFormat)
        {
            if ((buffer == null) ||
                (nrleads <= 0))
            {
                return(1);
            }

            _Data = new short[nrleads][];
            for (int lead = 0; lead < nrleads; lead++)
            {
                _Data[lead] = new short[nrsamples];
            }

            if (bIsADCFormat)
            {
                for (int sample = 0; sample < nrsamples; sample++)
                {
                    if ((offset + Marshal.SizeOf(typeof(short))) > buffer.Length)
                    {
                        break;
                    }

                    for (int lead = 0; lead < nrleads; lead++)
                    {
                        if ((offset + Marshal.SizeOf(_Data[lead][sample])) > buffer.Length)
                        {
                            break;
                        }
                        _Data[lead][sample] = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_Data[lead][sample]), littleEndian);
                        offset += Marshal.SizeOf(_Data[lead][sample]);
                    }
                }
            }
            else
            {
                for (int lead = 0; lead < nrleads; lead++)
                {
                    if ((offset + Marshal.SizeOf(typeof(short))) > buffer.Length)
                    {
                        break;
                    }

                    for (int sample = 0; sample < nrsamples; sample++)
                    {
                        if ((offset + Marshal.SizeOf(_Data[lead][sample])) > buffer.Length)
                        {
                            break;
                        }
                        _Data[lead][sample] = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_Data[lead][sample]), littleEndian);
                        offset += Marshal.SizeOf(_Data[lead][sample]);
                    }
                }
            }
            return(0);
        }
Exemplo n.º 13
0
            /// <summary>
            /// Function to read GRI Setup from buffer.
            /// </summary>
            /// <param name="buffer">buffer to read from</param>
            /// <param name="offset">position to start reading</param>
            /// <param name="littleEndian">true if little endian is used</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset, bool littleEndian)
            {
                BradyLimit = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(BradyLimit), littleEndian);
                offset    += Marshal.SizeOf(BradyLimit);

                TachyLimit = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(TachyLimit), littleEndian);
                offset    += Marshal.SizeOf(TachyLimit);

                return(0);
            }
Exemplo n.º 14
0
            /// <summary>
            /// Function to write GRI Setup into a buffer.
            /// </summary>
            /// <param name="buffer">buffer to write in</param>
            /// <param name="offset">position to start writing</param>
            /// <param name="littleEndian">true if little endian is used</param>
            /// <returns>0 on success</returns>
            public int Write(byte[] buffer, int offset, bool littleEndian)
            {
                BytesTool.writeBytes(BradyLimit, buffer, offset, Marshal.SizeOf(BradyLimit), littleEndian);
                offset += Marshal.SizeOf(BradyLimit);

                BytesTool.writeBytes(TachyLimit, buffer, offset, Marshal.SizeOf(TachyLimit), littleEndian);
                offset += Marshal.SizeOf(TachyLimit);

                return(0);
            }
Exemplo n.º 15
0
 public override bool CheckFormat(byte[] buffer, int offset)
 {
     if ((offset + RawECGHeader.HeaderSize) <= buffer.Length)
     {
         return((buffer[offset] == RawECGHeader.ValueOfP) &&
                (buffer[offset + 1] == RawECGHeader.ValueOfK) &&
                ((((int)BytesTool.readBytes(buffer, 4, 2, true)) == RawECGHeader.HeaderSize) ||
                 (((int)BytesTool.readBytes(buffer, 4, 2, false)) == RawECGHeader.HeaderSize)));
     }
     return(false);
 }
Exemplo n.º 16
0
        public override int Read(Stream input, int offset)
        {
            byte[] buffer = new byte[input.Length - offset];
            input.Seek(offset, SeekOrigin.Begin);
            if (BytesTool.readStream(input, buffer, 0, buffer.Length) != buffer.Length)
            {
                return(0x1);
            }

            return(Read(buffer, 0) << 1);
        }
Exemplo n.º 17
0
        protected override int _Read(byte[] buffer, int offset)
        {
            int length = Length - Size;

            if (length <= 0)
            {
                return(0x1);
            }
            _Data   = new byte[length];
            offset += BytesTool.copy(_Data, 0, buffer, offset, length);
            return(0x00);
        }
Exemplo n.º 18
0
        public override bool CheckFormat(byte[] buffer, int offset)
        {
            ushort crc    = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_CRC), true);
            int    length = (int)BytesTool.readBytes(buffer, offset + Marshal.SizeOf(_CRC), Marshal.SizeOf(_Length), true);

            if (((offset + length) < buffer.Length) &&
                (length < _MinFileLength))
            {
                return(false);
            }
            return(CheckSCP(buffer, offset, crc, length));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Function to anonymous the header.
 /// </summary>
 /// <param name="type">character to use for anonymous</param>
 public void Anonymous(byte type)
 {
     // Empty id, lastname and firstname.
     BytesTool.emptyBuffer(_PatId.Id, 0, BytesTool.stringLength(_PatId.Id, 0, RawECGPatientId.MaxIdLen), type);
     BytesTool.emptyBuffer(_PatId.LastName, 0, BytesTool.stringLength(_PatId.LastName, 0, RawECGPatientId.MaxNameLen), type);
     BytesTool.emptyBuffer(_PatId.FirstName, 0, BytesTool.stringLength(_PatId.FirstName, 0, RawECGPatientId.MaxNameLen), type);
     // Setting date to first of january.
     _PatId.BirthDate[4] = (byte)'0';
     _PatId.BirthDate[5] = (byte)'1';
     _PatId.BirthDate[6] = (byte)'0';
     _PatId.BirthDate[7] = (byte)'1';
     _PatId.BirthDate[8] = 0;
 }
Exemplo n.º 20
0
            /// <summary>
            /// Function to write SCP spike.
            /// </summary>
            /// <param name="buffer">byte array to write into</param>
            /// <param name="offset">position to start writing</param>
            /// <returns>0 on success</returns>
            public int Write(byte[] buffer, int offset)
            {
                if ((offset + Size) > buffer.Length)
                {
                    return(0x1);
                }

                BytesTool.writeBytes(Time, buffer, offset, Marshal.SizeOf(Time), true);
                offset += Marshal.SizeOf(Time);
                BytesTool.writeBytes(Amplitude, buffer, offset, Marshal.SizeOf(Amplitude), true);
                offset += Marshal.SizeOf(Amplitude);

                return(0x0);
            }
Exemplo n.º 21
0
            /// <summary>
            /// Function to read QRS protected zone.
            /// </summary>
            /// <param name="buffer">byte array to read from</param>
            /// <param name="offset">position to start reading</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset)
            {
                if (offset + Size > buffer.Length)
                {
                    return(0x1);
                }

                Start   = (int)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Start), true);
                offset += Marshal.SizeOf(Start);
                End     = (int)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(End), true);
                offset += Marshal.SizeOf(End);

                return(0x0);
            }
Exemplo n.º 22
0
            /// <summary>
            /// Function to read a SCP spike.
            /// </summary>
            /// <param name="buffer">byte array to read from</param>
            /// <param name="offset">position to start reading</param>
            /// <returns>0 on success</returns>
            public int Read(byte[] buffer, int offset)
            {
                if ((offset + Size) > buffer.Length)
                {
                    return(0x1);
                }

                Time      = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Time), true);
                offset   += Marshal.SizeOf(Time);
                Amplitude = (short)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Amplitude), true);
                offset   += Marshal.SizeOf(Amplitude);

                return(0x0);
            }
Exemplo n.º 23
0
            /// <summary>
            /// Function to write QRS protected zone.
            /// </summary>
            /// <param name="buffer">byte array to write to</param>
            /// <param name="offset">position to start writing</param>
            /// <returns>0 on success</returns>
            public int Write(byte[] buffer, int offset)
            {
                if (offset + Size > buffer.Length)
                {
                    return(0x1);
                }

                BytesTool.writeBytes(Start, buffer, offset, Marshal.SizeOf(Start), true);
                offset += Marshal.SizeOf(Start);
                BytesTool.writeBytes(End, buffer, offset, Marshal.SizeOf(End), true);
                offset += Marshal.SizeOf(End);

                return(0x0);
            }
Exemplo n.º 24
0
        protected override int _Read(byte[] buffer, int offset)
        {
            int end = offset - Size + Length;

            if ((offset + Marshal.SizeOf(_MedianDataLength) + Marshal.SizeOf(_FirstFiducial) + Marshal.SizeOf(_NrQRS)) > end)
            {
                return(0x1);
            }
            _MedianDataLength = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_MedianDataLength), true);
            offset           += Marshal.SizeOf(_MedianDataLength);
            _FirstFiducial    = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_FirstFiducial), true);
            offset           += Marshal.SizeOf(_FirstFiducial);
            _NrQRS            = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_NrQRS), true);
            offset           += Marshal.SizeOf(_NrQRS);
            if ((offset + (_NrQRS * SCPQRSSubtraction.Size)) > end)
            {
                return(0x2);
            }
            _Subtraction = new SCPQRSSubtraction[_NrQRS];
            for (int loper = 0; loper < _NrQRS; loper++)
            {
                _Subtraction[loper] = new SCPQRSSubtraction();
                int err = _Subtraction[loper].Read(buffer, offset);
                if (err != 0)
                {
                    return(err << (2 + loper));
                }
                offset += SCPQRSSubtraction.Size;
            }

            if ((offset + (_NrQRS * SCPQRSProtected.Size)) > end)
            {
                return(0x0);
            }

            _Protected = new SCPQRSProtected[_NrQRS];
            for (int loper = 0; loper < _NrQRS; loper++)
            {
                _Protected[loper] = new SCPQRSProtected();
                int err = _Protected[loper].Read(buffer, offset);
                if (err != 0)
                {
                    return(err << (2 + loper));
                }
                offset += SCPQRSProtected.Size;
            }
            return(0x0);
        }
Exemplo n.º 25
0
        protected override int _Read(byte[] buffer, int offset)
        {
            if (_NrLeads == 0)
            {
                return(0x1);
            }

            _DataLength = new ushort[_NrLeads];
            _Data       = new byte[_NrLeads][];

            int end      = offset - Size + Length;
            int startlen = (Marshal.SizeOf(_AVM) + Marshal.SizeOf(_TimeInterval) + Marshal.SizeOf(_Difference) + Marshal.SizeOf(_Bimodal));

            startlen += _DataLength.Length * Marshal.SizeOf(_DataLength[0]);
            if ((offset + startlen) > end)
            {
                return(0x2);
            }
            _AVM          = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_AVM), true);
            offset       += Marshal.SizeOf(_AVM);
            _TimeInterval = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_TimeInterval), true);
            offset       += Marshal.SizeOf(_TimeInterval);
            _Difference   = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_Difference), true);
            offset       += Marshal.SizeOf(_Difference);
            _Bimodal      = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_Bimodal), true);
            offset       += Marshal.SizeOf(_Bimodal);
            int sum = 0;

            for (int loper = 0; loper < _Data.Length; loper++)
            {
                sum    += (_DataLength[loper] = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_DataLength[loper]), true));
                offset += Marshal.SizeOf(_DataLength[loper]);
            }
            if ((offset + sum) > end)
            {
                return(0x4);
            }
            for (int loper = 0; loper < _Data.Length; loper++)
            {
                _Data[loper] = new byte[_DataLength[loper]];
                offset      += BytesTool.copy(_Data[loper], 0, buffer, offset, _DataLength[loper]);
                if ((_DataLength[loper] & 0x1) == 0x1)
                {
                    _DataLength[loper]++;
                }
            }
            return(0x00);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Function to write SCP time.
        /// </summary>
        /// <param name="buffer">byte array to write into</param>
        /// <param name="offset">position to start writing</param>
        /// <returns>0 on success</returns>
        public int Write(byte[] buffer, int offset)
        {
            if ((offset + Size) > buffer.Length)
            {
                return(0x1);
            }

            BytesTool.writeBytes(Hour, buffer, offset, Marshal.SizeOf(Hour), true);
            offset += Marshal.SizeOf(Hour);
            BytesTool.writeBytes(Min, buffer, offset, Marshal.SizeOf(Min), true);
            offset += Marshal.SizeOf(Min);
            BytesTool.writeBytes(Sec, buffer, offset, Marshal.SizeOf(Sec), true);
            offset += Marshal.SizeOf(Sec);

            return(0x0);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Function to read an SCP time.
        /// </summary>
        /// <param name="buffer">byte array to read from</param>
        /// <param name="offset">position to start reading</param>
        /// <returns>0 on success</returns>
        public int Read(byte[] buffer, int offset)
        {
            if ((offset + Size) > buffer.Length)
            {
                return(0x1);
            }

            Hour    = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Hour), true);
            offset += Marshal.SizeOf(Hour);
            Min     = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Min), true);
            offset += Marshal.SizeOf(Min);
            Sec     = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Sec), true);
            offset += Marshal.SizeOf(Sec);

            return(0x0);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Function to write an SCP date to a byte array.
        /// </summary>
        /// <param name="buffer">byte array to write in</param>
        /// <param name="offset">position to start writing</param>
        /// <returns></returns>
        public int Write(byte[] buffer, int offset)
        {
            if ((offset + Size) > buffer.Length)
            {
                return(0x1);
            }

            BytesTool.writeBytes(Year, buffer, offset, Marshal.SizeOf(Year), true);
            offset += Marshal.SizeOf(Year);
            BytesTool.writeBytes(Month, buffer, offset, Marshal.SizeOf(Month), true);
            offset += Marshal.SizeOf(Month);
            BytesTool.writeBytes(Day, buffer, offset, Marshal.SizeOf(Day), true);
            offset += Marshal.SizeOf(Day);

            return(0x0);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Function to read an SCP date from byte array.
        /// </summary>
        /// <param name="buffer">byte array to read from</param>
        /// <param name="offset">position to start reading</param>
        /// <returns>0 on success</returns>
        public int Read(byte[] buffer, int offset)
        {
            if ((offset + Size) > buffer.Length)
            {
                return(0x1);
            }

            Year    = (ushort)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Year), true);
            offset += Marshal.SizeOf(Year);
            Month   = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Month), true);
            offset += Marshal.SizeOf(Month);
            Day     = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Day), true);
            offset += Marshal.SizeOf(Day);

            return(0x0);
        }
Exemplo n.º 30
0
            /// <summary>
            /// Function to write SCP pointer.
            /// </summary>
            /// <param name="buffer">byte array to write section into</param>
            /// <param name="offset">position to start writing</param>
            /// <returns>0 on success</returns>
            public int Write(byte[] buffer, int offset)
            {
                if ((offset + Size) > buffer.Length)
                {
                    return(0x1);
                }

                BytesTool.writeBytes(Nr, buffer, offset, Marshal.SizeOf(Nr), true);
                offset += Marshal.SizeOf(Nr);
                BytesTool.writeBytes(Length, buffer, offset, Marshal.SizeOf(Length), true);
                offset += Marshal.SizeOf(Length);
                BytesTool.writeBytes(Index, buffer, offset, Marshal.SizeOf(Index), true);
                offset += Marshal.SizeOf(Index);

                return(0x0);
            }