コード例 #1
0
ファイル: PBBP.cpp プロジェクト: AdamMagaluk/library-pinoccio
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();
}
コード例 #2
0
ファイル: Transport.cpp プロジェクト: KennEskildsen/I4IKN
	/// <summary>
	/// Send the specified buffer and size.
	/// </summary>
	/// <param name='buffer'>
	/// Buffer.
	/// </param>
	/// <param name='size'>
	/// Size.
	/// </param>
	void Transport::send(char buf[], short size)
	{

		memcpy(this->buffer+ACKSIZE, buf, size);

		buffer[SEQNO]=seqNo;
		buffer[TYPE]=DATA;//type = data
		checksum->calcChecksum(buffer,size+ACKSIZE);

		// Fremprovokeret fejl 
		errorCount++;
		if(errorCount == 5)
			buffer[0]++;

		link->send(this->buffer,size+ACKSIZE);//header + data

		if(errorCount==5)
			buffer[0]--;


		while(!receiveAck())
		{
			std::cout<<"Error did not receive ACK in transportlayer\r\n";
			link->send(this->buffer,size+ACKSIZE);//header + data
		}
			
		std::cout<<"ACK receieved in transportlayer\r\n";

		return;
	}
コード例 #3
0
void ElevatorController::sendRegistration() {
	rt_printf("EC%d: Sending EC->GD registration...", (unsigned int)this->getID());
	sendMessage(RegisterWithGDMessage(this->getID()));

	rt_printf("done.\n");

	receiveAck();
}
コード例 #4
0
ファイル: PBBP.cpp プロジェクト: AdamMagaluk/library-pinoccio
bool PBBP::sendByte(uint8_t b) {
  bool parity_val = 0;
  bool ok = true;
  uint8_t next_bit = 0x80;
  while (next_bit && ok) {
    if (b & next_bit)
      parity_val ^= 1;
    if (!sendBit(b & next_bit))
      return false;
    next_bit >>= 1;
  }

  return sendBit(!parity_val) && receiveReady() && receiveAck();
}
コード例 #5
0
ファイル: solitaire_c.c プロジェクト: gchronis/groupitaire
int main(int argc, char **argv) {

  char buffer[MAXLINE];
  
  //
  // Check for host name and port number.
  //
  if (argc != 3) {
    fprintf(stderr,"usage: %s <host> <port>\n", argv[0]);
    exit(0);
  }

  //
  // Connect to the server.
  //
  int server = connectToServer(argv[1],atoi(argv[2]));

  printf("Welcome to the remote SOLITAIRE game for MATH 442.\n\n");
  printf("Here is a key of possible card plays you can make:\n");
  printf("\tplay <face><suit> - throw a card onto an arena pile in the center.\n");
  printf("\tmove k<suit> - move a king onto an empty pile.\n");
  printf("\tmove <face><suit> <face><suit>- move a card, putting it on top of another card.\n");
  printf("\tdraw - draw and overturn the next card, placing it on the discard pile.\n");
  printf("where <face> is one of a,2,3,...,9,t,j,q,k and <suit> is one of d,c,s,h.\n");

  //
  // Send a series of solitaire play commands.
  //
  while (1) {
    printf("\nEnter a card play: ");
    
    fgets(buffer,MAXLINE,stdin);
    write(server,buffer,strlen(buffer)+1);
    if (receiveAck(server)) {
      printf("Done!\n");
    } else {
      printf("That play wasn't made.\n");
    } 
  }

}