コード例 #1
0
void StanzaAckResponder::handleAckRequestReceived() {
	onAck(handledStanzasCount);
}
コード例 #2
0
ファイル: main.c プロジェクト: xiaokaisun90/Projects
void rx_task ()
{
	uint8_t pos,len,i,version;
	int8_t rssi;
  uint8_t *local_rx_buf;
  int16_t recipient,sender,dataseq;
	char type;
  if(log_g) printf ("log:rx_task PID=%d\r\n", nrk_get_pid ());
  // init bmac on channel 15 
  bmac_init (15);

  bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE);

  while (1) {
    // Wait until an RX packet is received
    bmac_wait_until_rx_pkt ();
    // Get the RX packet 
    nrk_led_set (ORANGE_LED);
    local_rx_buf = bmac_rx_pkt_get (&len, &rssi);
    //if(log_g) printf ("log:Packet recv\n");
    //if(log_g) printf ("log:");
    //for (i = 0; i < len; i++) {
    //  if(log_g) printf ("%c", rx_buf[i]);
		//}
    //if(log_g) printf ("\n");

		pos = 0; 
		recipient = get_next_int(local_rx_buf,&pos,len); 
		pos+=1;
		sender = get_next_int(local_rx_buf,&pos,len);
		pos+=1; 
		type = local_rx_buf[pos];
		pos+=2;

		if((recipient != 0 && recipient != MAC_ADDR) || sender == MAC_ADDR) {

			if(log_g) printf("log:Ignore\r\n");

		} else if(recipient == 0 && type == 'S') {

			version =get_next_int(local_rx_buf,&pos,len);
			on_discover_pkt(sender, version);
 
		} else if (recipient == 0 && type == 'B') {

			onBasketBallPkt();
		
		}	else if (type == 'C') {

			version =get_next_int(local_rx_buf,&pos,len);
			onConnectionReq(sender,version);

		} else if(type == 'D' ) {

			dataseq = get_next_int(local_rx_buf,&pos,len);	
			onData(sender,dataseq,local_rx_buf,len);

		}	else if(type == 'A') {

			dataseq = get_next_int(local_rx_buf,&pos,len);	
			onAck(sender, dataseq);

		} else if(type == 'M') {
			onContactShare(local_rx_buf,len); 
		}else {

			if(log_g) printf("log:Invalid MSG\r\n");

		}
    
		// Release the RX buffer so future packets can arrive 
    memset(local_rx_buf,0,len+1);
    bmac_rx_pkt_release ();
  	nrk_led_clr(ORANGE_LED);
		nrk_wait_until_next_period();
	}
}
コード例 #3
0
ファイル: test.c プロジェクト: GregoireDelannoy/TCPeP
int codingTest(){
    struct timeval startTime, endTime;
    encoderstate* encState = encoderStateInit();
    decoderstate* decState = decoderStateInit();
    uint8_t inputBuffer[INPUT_LENGTH], buf1[2 * PACKETSIZE], buf2[2 * PACKETSIZE], type;
    int totalBytesSent = 0, totalBytesReceived = 0, totalAckSent = 0, totalAckReceived = 0, totalDataPacketReceived = 0, totalDataPacketSent = 0, nDataPacketSent = 0;
    int i, j, buf1Len, buf2Len;
    muxstate mState;
    mState.sport = 10; mState.dport = 10; mState.remote_ip = 10;
    int nRounds = CLEAR_PACKETS, sendSize;
    float timeElapsed;
    
    matrix* randomMatrix = getRandomMatrix(1, INPUT_LENGTH);
    memcpy(inputBuffer, randomMatrix->data[0], INPUT_LENGTH);
    mFree(randomMatrix);
    
    gettimeofday(&startTime, NULL);
    for(i = 0; i<nRounds; i++){
        //if(regulator()){
            //printf("\n~~~~Starting round %d~~~~~\n", i);
            //encoderStatePrint(*encState);
            //decoderStatePrint(*decState);
            //printf("~~~~~~~~~\n");
        //}

        //sendSize = (int)(((0.8 + 0.2 *random())/RAND_MAX) * INPUT_LENGTH);
        sendSize = PACKETSIZE - 20;
        //printf("Adding %d to the encoder\n", sendSize);
        handleInClear(encState, inputBuffer, sendSize);
        totalBytesReceived += sendSize;

        // Send ACKs
        for(j = 0; j < decState->nAckToSend; j++){
            bufferToMuxed(decState->ackToSend[j], buf1, decState->ackToSendSize[j], &buf1Len, mState, TYPE_ACK);
            muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type);
            totalAckSent++;
            if(((1.0 * random())/RAND_MAX) > LOSS){
                onAck(encState, buf2, buf2Len);
                //printf("Sent an ACK\n");
                totalAckReceived++;
            } else {
                //printf("Lost an ACK\n");
            }
        }
        // Free
        for(j = 0; j< decState->nAckToSend;j++){
            free(decState->ackToSend[j]);
        }
        free(decState->ackToSend);
        decState->ackToSend = 0;
        free(decState->ackToSendSize);
        decState->ackToSendSize = 0;
        decState->nAckToSend = 0;

        // Send coded data packets from the encoder
        for(j = 0; j < encState->nDataToSend; j++){
            bufferToMuxed(encState->dataToSend[j], buf1, encState->dataToSendSize[j], &buf1Len, mState, TYPE_DATA);
            muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type);
            totalDataPacketSent += buf2Len;
            nDataPacketSent++;
            if(((1.0 * random())/RAND_MAX) > LOSS){
                handleInCoded(decState, buf2, buf2Len);
                //printf("Sent a DATA packet from buf1:%d to buf2:%d\n", buf1Len, buf2Len);
                totalDataPacketReceived += buf2Len;
            } else {
                //printf("Lost a data packet\n");
            }
            
        }
        // Free
        for(j = 0; j< encState->nDataToSend;j++){
            free(encState->dataToSend[j]);
        }
        free(encState->dataToSend);
        encState->dataToSend=0;
        free(encState->dataToSendSize);
        encState->dataToSendSize = 0;
        encState->nDataToSend = 0;
        
        if(decState->nDataToSend > 0){
            //printf("Sent %d decoded bytes to the application\n", decState->nDataToSend);
            totalBytesSent += decState->nDataToSend;
            free(decState->dataToSend);
            decState->dataToSend = 0;
            decState->nDataToSend = 0;
        }
        
        if(regulator()){
            printf("\n~~~~End of round %d~~~~~\n", i);
            encoderStatePrint(*encState);
            decoderStatePrint(*decState);
            printf("~~~~~~~~~\n");
        }
        
        //usleep(10000 + (1.0 * random() /RAND_MAX) * 1000);
    }
    gettimeofday(&endTime, NULL);
    timeElapsed = 1.0 * (endTime.tv_sec - startTime.tv_sec) + ((endTime.tv_usec - startTime.tv_usec) / 1000000.0);
    
    encoderStatePrint(*encState);
    decoderStatePrint(*decState);
    
    printf("During the %d rounds and %f s, %d bytes has been received by the encoder ; %d has been sent to the application.\n%d bytes of Data Packets has been sent, %d received.\n%d Ack has been sent, %d received.\n Simulated loss rate = %f %%. Transmission efficiency = %f %%. Transmission speed = %f MB/s. Data packet per Rounds = %f\n", nRounds, timeElapsed, totalBytesReceived, totalBytesSent, totalDataPacketSent, totalDataPacketReceived, totalAckSent, totalAckReceived, LOSS, 1.0 * totalBytesSent / totalDataPacketReceived, totalBytesSent / (1024 * 1024 * timeElapsed), 1.0 * nDataPacketSent / nRounds);
    
    encoderStateFree(encState);
    decoderStateFree(decState);
    return true;
}