Esempio n. 1
0
bool PBBP::receiveAck() {
  bool first, second;
  if (!receiveBit(&first) || !receiveBit(&second))
    return false;

  // Acks are sent as 01, nacks as 10. Since the 0 is dominant during
  // a bus conflict, a receiveing of 00 means both an ack and a nack was
  // sent.
  if (!first && !second ) {
    this->last_error = ACK_AND_NACK;
    return false;
  } else if (!second ) {
    // Read error code from the slave
    if (receiveByte(&this->last_slave_error)) {
      this->last_error = NACK;
    } else {
      this->last_error = NACK_NO_SLAVE_CODE;
    }
    return false;
  } else if (first) {
    this->last_error = NO_ACK_OR_NACK;
    return false;
  } else {
    return true;
  }
}
Esempio n. 2
0
bool PBBP::receiveByte(uint8_t *b) {
  bool parity_val = 0;
  *b = 0;
  uint8_t next_bit = 0x80;
  bool value;
  // Receive data bits
  while (next_bit) {
    if (!receiveBit(&value))
      return false;

    if (value) {
      *b |= next_bit;
      parity_val ^= 1;
    }
    next_bit >>= 1;
  }
  // Receive parity bit
  if (!receiveBit(&value))
    return false;

  if (value == parity_val) {
    this->last_error = PARITY_ERROR;
    return false;
  }

  return receiveReady() && receiveAck();
}
Esempio n. 3
0
bool PBBP::receiveReady() {
  int timeout = this->max_stall_bits;
  while (timeout--) {
    bool value;
    if (!receiveBit(&value))
      return false;

    // Ready bit?
    if (value)
      return true;
  }
  this->last_error = STALL_TIMEOUT;
  return false;
}
// receiver: decode received bits.  Ns samples per bit.
Bits
BluetoothReceiver::receive(const Signal& input) {
    // Input length should be a multiple of Ns
    int nBits = input.size()/Ns;
    _ASSERTE((input.size()) % Ns == 0);
    Bits bitsOut(nBits);

    for (int i=0; i<nBits; ++i) {
        slice sl_i(i*Ns, Ns);
        bitsOut[i] = receiveBit(input[sl_i]);
    }

    return bitsOut;
}