Beispiel #1
0
 /**
  * Beendet die Uebertragung und codiert alle noch unbehandelten bits.
  *
  * @return Die resultierende Signalfolge.
  */
 public String flush() {
   CharSequence tmp = zeroBuffer.read();
   zeroBuffer.clear();
   state = HDB3Sender.State.START;
   dc = 0;
   last = medium.minus();
   return tmp.toString();
 }
Beispiel #2
0
  /**
   * Codiert eine bit-Folge durch das AMI-Verfahren.
   *
   * @param toSend Die zu codierende bit-Folge, als boolesches Array.
   * @return Die resultierende Signalfolge.
   */
  public String send(boolean[] toSend) {
    StringBuilder output = new StringBuilder();

    for (int i = 0; i < toSend.length; i++) {
      boolean b = toSend[i];
      if (!b) {
        if (state != HDB3Sender.State.THREE_ZEROS) {
          state = state.next();
          zeroBuffer.buffer(medium.zero());

        } else {
          if (dc == 0 && last == medium.plus()) {
            output.append(zeroBuffer.read());
            output.append(medium.plus());
            dc += 1;
            last = medium.plus();

          } else if (dc == 0 && last == medium.minus()) {
            output.append(zeroBuffer.read());
            output.append(medium.minus());
            dc -= 1;
            last = medium.minus();

          } else if (dc == 1) {
            output.append("-==-");
            dc -= 2;
            last = medium.minus();

          } else if (dc == -1) {
            output.append("+==+");
            dc += 2;
            last = medium.plus();
          }

          state = HDB3Sender.State.START;
          zeroBuffer.clear();
        }

      } else {
        if (dc == 0 && last == medium.plus()) {
          output.append(zeroBuffer.read());
          output.append(medium.minus());
          dc -= 1;
          last = medium.minus();

        } else if (dc == 0 && last == medium.minus()) {
          output.append(zeroBuffer.read());
          output.append(medium.plus());
          dc += 1;
          last = medium.plus();

        } else if (dc == 1) {
          output.append(zeroBuffer.read());
          output.append(medium.minus());
          dc -= 1;
          last = medium.minus();

        } else if (dc == -1) {
          output.append(zeroBuffer.read());
          output.append(medium.plus());
          dc += 1;
          last = medium.plus();
        }

        state = HDB3Sender.State.START;
        zeroBuffer.clear();
      }
    }

    return output.toString();
  }