Class StopAndWaitPacketInputStream

java.lang.Object
java.io.InputStream
org.refcodes.serial.PacketInputStream
org.refcodes.serial.StopAndWaitPacketInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, org.refcodes.mixin.BlockSizeAccessor, org.refcodes.mixin.PacketSizeAccessor, org.refcodes.numerical.EndianessAccessor, AcknowledgeMagicBytesAccessor, AcknowledgeRetryNumberAccessor, AcknowledgeSegmentPackagerAccessor, AcknowledgeTimeoutInMsAccessor, PacketLengthWidthAccessor, PacketMagicBytesAccessor, PacketSegmentPackagerAccessor, SequenceNumberAccessor, SequenceNumberConcatenateModeAccessor, SequenceNumberInitValueAccessor, SequenceNumberWidthAccessor

The StopAndWaitPacketInputStream wraps an InputStream and chunks any data to be written into packets with a sequence number and a block of data. An according StopAndWaitPacketInputStream then reverts the packetised data stream while performing sequence number validation. A SegmentPackager can be used to add functionality such as CRC checksum support.
  • Constructor Details

    • StopAndWaitPacketInputStream

      public StopAndWaitPacketInputStream(InputStream aInputStream, OutputStream aReturnStream, TransmissionMetrics aTransmissionMetrics)
      Constructs an according StopAndWaitPacketInputStream instance wrapping the given OutputStream. The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
      Parameters:
      aInputStream - The InputStream to be wrapped.
      aReturnStream - The OutputStream for establishing a return channel (handshake with the communication partner).
      aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
    • StopAndWaitPacketInputStream

      public StopAndWaitPacketInputStream(InputStream aInputStream, int aBlockSize, int aPacketLengthWidth, byte[] aPacketMagicBytes, int aSequenceNumberInitValue, int aSequenceNumberWidth, org.refcodes.mixin.ConcatenateMode aSequenceNumberConcatenateMode, SegmentPackager aPacketSegmentPackager, OutputStream aReturnStream, byte[] aAcknowledgeMagicBytes, int aAcknowledgeRetryNumber, long aAcknowledgeTimeoutInMs, SegmentPackager aAckSegmentPackager, org.refcodes.numerical.Endianess aEndianess)
      Constructs an according StopAndWaitPacketInputStream instance wrapping the given OutputStream.
      Parameters:
      aInputStream - The InputStream to be wrapped.
      aBlockSize - The block size of a data block for each packet.
      aPacketLengthWidth - The width (bytes) for declaring the (max) length of a package.
      aPacketMagicBytes - The magic bytes identifying a packet and distinguishing a packet from a last package.
      aSequenceNumberInitValue - The initial sequence number from where to start counting the blocks.
      aSequenceNumberWidth - The width (in bytes) to be used for sequence number values.
      aSequenceNumberConcatenateMode - The mode of concatenation to use when creating a Sequence from this Transmission and the decorated Transmission.
      aPacketSegmentPackager - An (optional) SegmentPackager used to modify a packet's data e.g. with a CRC checksum.
      aReturnStream - The OutputStream for establishing a return channel (handshake with the communication partner).
      aAcknowledgeMagicBytes - The ACK character(s) to be used by the return channel to transmit an ACK (acknowledge) response after successful receiving a transmission.
      aAcknowledgeRetryNumber - The number of retries waiting for an ACK from the return channel.
      aAcknowledgeTimeoutInMs - The timeout in milliseconds to pend till the next retry.
      aAckSegmentPackager - An (optional) SegmentPackager used to modify a ACK response data e.g. with a CRC checksum.
      aEndianess - The Endianess to use for integer (double) numbers and the like.
  • Method Details