Example #1
0
            private void CreatePDV(bool last)
            {
                try {
                    if (_bytes == null)
                    {
                        _bytes = new byte[0];
                    }

                    if (_length < _bytes.Length)
                    {
                        Array.Resize(ref _bytes, _length);
                    }

                    PDV pdv = new PDV(_pcid, _bytes, _command, last);
                    _pdu.PDVs.Add(pdv);

                    //_service.Logger.Info(pdv);

                    // reset length in case we recurse into WritePDU()
                    _length = 0;
                    // is the current PDU at its maximum size or do we have room for another PDV?
                    if ((CurrentPduSize() + 6) >= _max || (!_command && last))
                    {
                        WritePDU(last);
                    }

                    // Max PDU Size - Current Size - Size of PDV header
                    uint max = _max - CurrentPduSize() - 6;
                    _bytes = last ? null : new byte[max];
                } catch (Exception e) {
                    _service.Logger.Error("Exception creating PDV: " + e.ToString());
                    throw;
                }
            }
Example #2
0
        public void Constructor_OddLengthValue_PaddedToEvenLength()
        {
            var bytes = new byte[] { 1, 2, 3, 4, 5 };
            var expected = new byte[6];
            Array.Copy(bytes, expected, bytes.Length);

            var pdv = new PDV(1, bytes, true, true);
            var actual = pdv.Value;

            Assert.Equal(expected, actual);
        }
Example #3
0
        /// <summary>
        /// Reads P-DATA-TF from PDU buffer
        /// </summary>
        /// <param name="raw">PDU buffer</param>
        public void Read(RawPDU raw)
        {
            uint len  = raw.Length - 6;
            uint read = 0;

            while (read < len)
            {
                PDV pdv = new PDV();
                read += pdv.Read(raw);
                _pdvs.Add(pdv);
            }
        }
Example #4
0
        public void Constructor_OddLengthValue_PaddedToEvenLength()
        {
            var bytes    = new byte[] { 1, 2, 3, 4, 5 };
            var expected = new byte[6];

            Array.Copy(bytes, expected, bytes.Length);

            var pdv    = new PDV(1, bytes, true, true);
            var actual = pdv.Value;

            Assert.Equal(expected, actual);
        }
Example #5
0
            private bool CreatePDV()
            {
                int len = Math.Min(GetBufferLength(), _max - CurrentPduSize() - 6);

                if (_bytes == null || _bytes.Length != len || _pdu.PDVs.Count > 0)
                {
                    _bytes = new byte[len];
                }
                _sent = _buffer.Read(_bytes, 0, len);

                PDV pdv = new PDV(_pcid, _bytes, _command, false);

                _pdu.PDVs.Add(pdv);

                return(pdv.IsLastFragment);
            }
Example #6
0
            private async Task CreatePDV(bool last)
            {
                try
                {
                    if (_bytes == null) _bytes = new byte[0];

                    if (_length < _bytes.Length) Array.Resize(ref _bytes, _length);

                    PDV pdv = new PDV(_pcid, _bytes, _command, last);
                    _pdu.PDVs.Add(pdv);

                    //_service.Logger.Info(pdv);

                    // reset length in case we recurse into WritePDU()
                    _length = 0;
                    // is the current PDU at its maximum size or do we have room for another PDV?
                    if ((CurrentPduSize() + 6) >= _max || (!_command && last)) await this.WritePDUAsync(last).ConfigureAwait(false);

                    // Max PDU Size - Current Size - Size of PDV header
                    uint max = _max - CurrentPduSize() - 6;
                    _bytes = last ? null : new byte[max];
                }
                catch (Exception e)
                {
                    _service.Logger.Error("Exception creating PDV: {@error}", e);
                    throw;
                }
            }
Example #7
0
		/// <summary>
		/// Reads P-DATA-TF from PDU buffer
		/// </summary>
		/// <param name="raw">PDU buffer</param>
		public void Read(RawPDU raw) {
			uint len = raw.Length - 6;
			uint read = 0;
			while (read < len) {
				PDV pdv = new PDV();
				read += pdv.Read(raw);
				_pdvs.Add(pdv);
			}
		}
Example #8
0
			private void CreatePDV(bool last) {
				try {
					if (_bytes == null)
						_bytes = new byte[0];

					if (_length < _bytes.Length)
						Array.Resize(ref _bytes, _length);

					PDV pdv = new PDV(_pcid, _bytes, _command, last);
					_pdu.PDVs.Add(pdv);

					//_service.Logger.Info(pdv);

					// reset length in case we recurse into WritePDU()
					_length = 0;
					// is the current PDU at its maximum size or do we have room for another PDV?
					if (_service.Options.OnePDVPerPDU || (CurrentPduSize() + 6) >= _max || (!_command && last))
						WritePDU(last);

					// Max PDU Size - Current Size - Size of PDV header
					uint max = _max - CurrentPduSize() - 6;
				  _bytes = last ? null : new byte[max];
				} catch (Exception e) {
					_service.Logger.Error("Exception creating PDV: " + e.ToString());
					throw;
				}
			}
Example #9
0
        private bool CreatePDV()
        {
            int len = Math.Min(GetBufferLength(), _max - CurrentPduSize() - 6);

            if (_bytes == null || _bytes.Length != len || _pdu.PDVs.Count > 0)
            {
                _bytes = new byte[len];
            }
            _sent = _buffer.Read(_bytes, 0, len);

            PDV pdv = new PDV(_pcid, _bytes, _command, false);
            _pdu.PDVs.Add(pdv);

            return pdv.IsLastFragment;
        }