Example #1
0
void processData (rel_t *r, packet_t *pkt, int length){
	if ( r->beginTime.tv_sec == 0 && r->beginTime.tv_usec == 0 ) {
		gettimeofday(&r->beginTime, NULL);
	}
	if (ntohl(pkt->seqno) >= 1) {
		packetQueue* newPkt = new_packet();
		memcpy(newPkt->packet, pkt, length);
		if (ntohl(pkt->seqno) == r->seqIn) {
			r->seqIn = r->seqIn + 1;
		}
		ack(r, r->seqIn);
		processAck(r, (struct ack_packet*) pkt);
		orderlyInsert(&(r->receiverBuff), newPkt);
		if (length == 16) {
			fprintf(stderr, "GET EOF\n");
			r->pairEOFed = 1;
		}
		rel_output(r);
	}
	else{
		fprintf(stderr, " wrong seqno %d \n", ntohl(pkt->seqno));
		return;
	}
}
bufferStruct checkReceiveData(bufferStruct buffer){
	rfm12_tick();  //periodic tick function - call that one once in a while
	switch(state){
		case STATE_TIMEOUT:
			#if STATE_UART_DEBUG >= 2
				uart_putstr ("tiOu\r\n");
			#endif
			++timoutCounter;
			if(timoutCounter > 5){
				#if STATE_UART_DEBUG >= 2
					uart_putstr ("tiOuOverl\r\n");
				#endif
				state = STATE_FREE;
				stopTimer();
				timoutCounter = 0;
			} else {
				processNack();
			}			
			break;
		case STATE_SENDING_ACK:
			if(rfm12_tx_status() == STATUS_FREE){
				state = STATE_SENDING_DATA;
				#if STATE_UART_DEBUG >= 2
					uart_putstr ("finSeAck\r\n");
				#endif
				
				bufferStruct result;
				result.bufferLength = getPayloadLength(backupData.bufferLength, backupData.buffer);
				memcpy(result.buffer, getPayload(backupData.bufferLength, backupData.buffer), result.bufferLength);
				
				uart_putc('%');
				uart_putc(result.bufferLength);
				uart_putc('%');
				for(uint8_t i = 0; i < result.bufferLength; ++i){
					uart_putc(result.buffer[i]);
				}
				uart_putc('%');
				
				return result;
			}
		case STATE_SENDING_DATA:
			if(rfm12_tx_status() == STATUS_FREE){
				#if STATE_UART_DEBUG >= 2
					uart_putstr ("finSeData\r\n");
				#endif
				state = STATE_FREE;
			}				
			
	}
//uart_putstr (rfm12_rx_status());
	if (rfm12_rx_status() == STATUS_COMPLETE){
	
		bufferStruct tempBuffer;
		tempBuffer.bufferLength = rfm12_rx_len();
		memcpy(tempBuffer.buffer, rfm12_rx_buffer(), tempBuffer.bufferLength);
		
		if(validateCrc(tempBuffer)){
			#if STATE_UART_DEBUG >= 2
				uart_putstr ("crcAck\r\n");
			#endif
		} else {
			#if STATE_UART_DEBUG >= 2
				uart_putstr ("crcNack\r\n");
			#endif
			rfm12_rx_clear();
			sendNack(tempBuffer);
			return buffer;
		}

		if(state > STATE_FREE){
			if(getAck(tempBuffer.bufferLength, tempBuffer.buffer) & ACK){
				#if STATE_UART_DEBUG >= 2
				uart_putstr ("rxAck\r\n");
				#endif
				processAck();
			} else if(getType(tempBuffer.bufferLength, tempBuffer.buffer) & NACK){
				#if STATE_UART_DEBUG >= 2
				uart_putstr ("rxNack\r\n");
				#endif
				processNack();

			}				
		}		
		if(state == STATE_FREE){
			switch(getType(tempBuffer.bufferLength, tempBuffer.buffer)){
				case SEND_DATA:
					#if STATE_UART_DEBUG >= 2
						uart_putstr ("send\r\n");
					#endif
					buffer = receiveSendData(tempBuffer);
					break;
			// here we should implement the cases of repeating data therefore we would have to know all last data sent
			// here we should implement the get back to in -> timeframe not yet implemented		
			}
		}	
		// tell the implementation that the buffer
		// can be reused for the next data.
		rfm12_rx_clear();
	}
	return buffer;
}
void ReliabilitySystem::processAck( quint32 ack, quint32 ack_bits ) {
	processAck( ack, ack_bits, pendingAckQueue, ackedQueue, acked, acked_packets, rtt, max_sequence );
}
Example #4
0
static int fpReceiverTask(void* dummy)
{
  unsigned int  *ASC_3_INT_EN = (unsigned int*)(ASC3BaseAddress + ASC_INT_EN);
  unsigned char command[16];
  int		count = 0;
  
  daemonize("fp_rcv");

  allow_signal(SIGTERM);

  //we are on so enable the irq  
  *ASC_3_INT_EN = *ASC_3_INT_EN | 0x00000001;

  while(1)
  {
     if(down_interruptible (&rx_int_sem))
       break;
     
     if(leaving) {
	     leaving++;
	     break;
     }

     while (1)
     {	

     if(leaving)
	     break;

/* FIXME FIXME FIXME FIXME
-fixmefixmefixme
- sometime the state cStateWaitAck stalled
->must lock this if it happens again
->using the rc sometimes solves the problem
- all other things seems to work
*/

	/* since we process all data here it may be that there
	 * are more up's than we need so check _before_ processing
	 * anything if there is data. this is not the best but
	 * better than the fact of loosing interrupts ...
	 */
        if (readPosition == writePosition)
	{
		break;
	}
	
	/* process our state-machine */
	switch (state)
	{
     	   case cStateIdle: /* nothing do to, search for command start */
     		   if (detectEvent(receivedData[readPosition]))
     		   {
     			   count = 0;
        		   command[count++] = receivedData[readPosition];
			   state = cStateWaitEvent;
 			   readPosition = (readPosition + 1) % BUFFERSIZE;
	    		   dprintk("0. current readPos = %d\n", readPosition);
     		   } else
		   {
 			   readPosition = (readPosition + 1) % BUFFERSIZE;
	    		   dprintk("0.1 current readPos = %d\n", readPosition);
		   }
	   break;
     	   case cStateWaitAck: /* each setter */
     	   {
	       unsigned char c = receivedData[readPosition];	
	       int err = processAck(c);    

	       readPosition = (readPosition + 1) % BUFFERSIZE;

	       dprintk("1. current readPos = %d\n", readPosition);

	       if (err == 2)
	       {
	    	    /* an error is detected from fp requeue data ...
		     */
		    requeueData();

		    state = cStateIdle;	  
		    waitAckCounter = 0;
		    count = 0;
	       }
	       else
	       if (err == 1)
	       {
	    	      /* data is processed remove it from queue */

		      down_interruptible(&transmit_sem);

		      transmitCount--;

	              memmove(&transmit[0], &transmit[1], (cMaxTransQueue - 1) * sizeof(struct transmit_s));	

	              if (transmitCount != 0)		  
     	  		 dprintk("next command will be 0x%x\n", transmit[0].command);

		      up(&transmit_sem);

	 	      waitAckCounter = 0;
     	 	      dprintk("detect ACK %d\n", state);
		      state = cStateIdle;
		      count = 0;
	       }
	       else
	       if (err == 0)
	       {
	 	      udelay(1);
	              waitAckCounter--;

		      dprintk("1. %d, %d 0x%x\n", waitAckCounter, readPosition, c);

		      if (waitAckCounter <= 0)
		      {
			  dprintk("missing ACK from micom ->requeue data %d\n", state);

			  requeueData();

			  count = 0;
			  waitAckCounter = 0;
			  state = cStateIdle;
		      }
     	       }
	   }
	   break;
     	   case cStateWaitDataAck: /* each getter */
	   {
		   int err;

                   command[count++] = receivedData[readPosition];
	    	   readPosition = (readPosition + 1) % BUFFERSIZE;

	           dprintk("2. current readPos = %d\n", readPosition);

		   err = processDataAck(command, count);

		   if (err == 1)
		   {
	    	      /* data is processed remove it from queue */

		      down_interruptible(&transmit_sem);

		      transmitCount--;

	              memmove(&transmit[0], &transmit[1], (cMaxTransQueue - 1) * sizeof(struct transmit_s));	

	              if (transmitCount != 0)		  
     	  		 dprintk("next command will be 0x%x\n", transmit[0].command);

		      up(&transmit_sem);

	 	      waitAckCounter = 0;
     	 	      dprintk("detect ACK %d\n", state);
		      state = cStateIdle;
		      count = 0;
		   }
	   }
	   break;
     	   case cStateWaitEvent: /* key or button */
		   if (receiveCount < cMaxReceiveQueue)
		   {
                  	   command[count++] = receivedData[readPosition];
	    	  	   readPosition = (readPosition + 1) % BUFFERSIZE;
	    		   dprintk("3. current readPos = %d\n", readPosition);

			   if (processEvent(command, count))
			   {
			   	   /* command completed */
     	   			   count = 0;
				   state = cStateIdle;
			   }

		   } else
		   {
			   /* noop: wait that someone reads data */
		   	   dprintk("overflow, wait for readers\n");
		   }
	   break;
     	   case cStateWaitStartOfAnswer: /* each getter */
	   {
		   int err = searchAnswerStart(receivedData[readPosition]);
		   unsigned char c = receivedData[readPosition];

	    	   readPosition = (readPosition + 1) % BUFFERSIZE;
	           dprintk("4. current readPos = %d\n", readPosition);

		   if (err == 2) 
		   {
			/* error detected ->requeue data ... */

			requeueData();

			state = cStateIdle;	  
			waitAckCounter = 0;
			count = 0;
		   }
		   else
		   if (err == 1)
		   {
			/* answer start detected now process data */
        		count = 0;
			command[count++] = c;
			state = cStateWaitDataAck;
		   } else
		   {
			/* no answer start detected */
	 		 udelay(1);
	        	 waitAckCounter--;

			 dprintk("2. %d\n", waitAckCounter);

			 if (waitAckCounter <= 0)
			 {
			     dprintk("missing ACK from micom ->requeue data %d\n", state);
			     requeueData();

			     count = 0;
			     waitAckCounter = 0;
			     state = cStateIdle;
			 }
		   }
	   }
	   break;
	   case cStateTransmission:
		   /* we currently transmit data so ignore all */
	   break;
	}
     } /* while */
  }

  printk("FP: task %s stopped\n", __func__);

  return 0;
}
Example #5
0
void processAck2 (rel_t *r, packet_t *pkt){
	processAck(r, (struct ack_packet*) pkt);
	rel_read(r);
}