/** * Sets the (average) bit length for this data set. * * <p>A bit length is used to determine the baudrate of this data set. If there is already a bit * length available from an earlier call to this method, it will be used to average the resulting * bit length if both the current and the given bit length are "close". This allows you to use the * bit lengths of both the RxD- and TxD-lines to get a good approximation of the actual baudrate. * * @param aBitLength the bit length to set/add, should be >= 0. */ public void setSampledBitLength(final int aBitLength) { // If the given bit length is "much" smaller (smaller bit length means // higher baudrate) than the current one, switch to that one instead; this // way we can recover from bad values... if ((this.bitLength <= 0) || ((10.0 * aBitLength) < this.bitLength)) { // First time being called, take the given bit length as our "truth"... this.bitLength = aBitLength; } else { // Take the average as the current and the given bit lengths are "close" // to each other; ignore the given bit length otherwise, as it clobbers // our earlier results... final int diff = Math.abs(aBitLength - this.bitLength); if ((diff >= 0) && (diff < 50)) { this.bitLength = (int) ((aBitLength + this.bitLength) / 2.0); } else { LOG.log( Level.INFO, "Ignoring sampled bit length ({0}) as it deviates " + "too much from current bit length ({1}).", new Object[] {Integer.valueOf(aBitLength), Integer.valueOf(this.bitLength)}); } } }