Esempio n. 1
0
/*
 * Reads the input file and sends packets to the decoder.
 * When the file is at its end it sends a empty frame to the framelist.
 * We use this as a notification of EOF.
 */
static void *
decodethread(void *arg)
{
	AVPacket packet;
	int nr;

	while (!abortflag) {
		nr = av_read_frame(avfmt, &packet);
		if (nr < 0) {
			xprintf("(%s:%d) av_read_frame, error: %s",
			    __FILE__, __LINE__, avstrerror(nr));
			break;
		}

		/* discard unwanted packets */
		if (packet.stream_index != sti) {
			av_free_packet(&packet);
			continue;
		}
		decodepacket(&packet);
		av_free_packet(&packet);
	}
	flpush(NULL);
	pthread_exit(NULL);
}
Esempio n. 2
0
int _readrx(void) {
	for (int i=0;i<21;i++) packet[i]=0;
	channel=tx_channels[chanrow][chancol]-1-chanoffset;
	A7105_Strobe(A7105_STANDBY);
	A7105_Strobe(A7105_RST_RDPTR);
	A7105_WriteRegister(0x0F, channel);
	A7105_Strobe(A7105_RX);
	chancol = (chancol + 1) % 16;
	unsigned long pause;
	uint8_t x;
	pause=lib_timers_starttimer();
	while(1){
		if (lib_timers_gettimermicroseconds(pause) > 2000) {
//			Red_LED_OFF;
			chancol = (chancol + 1) % 16;
			channel=tx_channels[chanrow][chancol]-1-chanoffset;
			break;
		}
		if(A7105_ReadRegister(A7105_00_MODE) & A7105_MODE_TRER_MASK){
			continue;
		}
		x=A7105_ReadRegister(0x00);
		if (!(bitRead(x,5)==0)&& !(bitRead(x,6)==0)){
			continue;
		}
		Read_Packet();
		if (convert2id(packet[1],packet[2],packet[3],packet[4])!=usersettings.flysky_id) {
//			Serial.println("bad id");
			continue;
		}


		decodepacket();

		// reset the failsafe timer
		global.failsafetimer = lib_timers_starttimer();
		return 1;
	}
	return 0;
}
Esempio n. 3
0
void checkrx( void)
{
	int packetreceived =	checkpacket();
	int pass = 0;
		if ( packetreceived ) 
		{ 
			if ( rxmode == 0)
			{	// rx startup , bind mode
				xn_readpayload( rxdata , 15);
		
				if ( rxdata[0] == 164 ) 
				{// bind packet
					rfchannel[0] = rxdata[6];
					rfchannel[1] = rxdata[7];
					rfchannel[2] = rxdata[8];
					rfchannel[3] = rxdata[9];		
					
					rxaddress[0] = rxdata[1];
					rxaddress[1] = rxdata[2];
					rxaddress[2] = rxdata[3];
					rxaddress[3] = rxdata[4];
					rxaddress[4] = rxdata[5];
					rxmode = 123;				
					xn_writerxaddress( rxaddress );
				  xn_writereg(0x25, rfchannel[chan] ); // Set channel frequency	
				
					#ifdef SERIAL_INFO	
					printf( " BIND \n");
					#endif
				}
			}
			else
			{	// normal mode	
				#ifdef RXDEBUG	
				rxdebug.channelcount[chan]++;	
				rxdebug.packettime = gettime() - lastrxtime;
				#endif
				
				// for longer loop times than 3ms it was skipping 2 channels
				//chan++;
				//if (chan > 3 ) chan = 0;
				nextchannel();
				
				lastrxtime = gettime();				
				xn_readpayload( rxdata , 15);
				pass = decodepacket();
				 
				if (pass)
				{ 
					#ifdef RXDEBUG	
					packetrx++;
					#endif
					failsafetime = lastrxtime; 
					failsafe = 0;
				}	
				else
				{
				#ifdef RXDEBUG	
				rxdebug.failcount++;
				#endif	
				}
			
			}// end normal rx mode
				
		}// end packet received

		unsigned long time = gettime();
		
    // sequence period 12000
		if( time - lastrxtime > 9000 && rxmode != 0)
		{//  channel with no reception	 
		 lastrxtime = time;
		 nextchannel();	
		}
		if( time - failsafetime > FAILSAFETIME )
		{//  failsafe
		  failsafe = 1;
			rx[0] = 0;
			rx[1] = 0;
			rx[2] = 0;
			rx[3] = 0;
		}
#ifdef RXDEBUG	
			if ( gettime() - secondtimer  > 1000000)
			{
				rxdebug.packetpersecond = packetrx;
				packetrx = 0;
				secondtimer = gettime();
			}
#endif

}
Esempio n. 4
0
void checkrx(void)
{
	int packetreceived = checkpacket();
	int pass = 0;
	if (packetreceived)
	  {
		  if (rxmode == RXMODE_BIND)
		    {		// rx startup , bind mode
			    xn_readpayload(rxdata, 15);

			    if (rxdata[0] == 164)
			      {	// bind packet
				      rfchannel[0] = rxdata[6];
				      rfchannel[1] = rxdata[7];
				      rfchannel[2] = rxdata[8];
				      rfchannel[3] = rxdata[9];
							
							int rxaddress[5];
				      rxaddress[0] = rxdata[1];
				      rxaddress[1] = rxdata[2];
				      rxaddress[2] = rxdata[3];
				      rxaddress[3] = rxdata[4];
				      rxaddress[4] = rxdata[5];
				      
				      xn_writerxaddress(rxaddress);
				      xn_writereg(0x25, rfchannel[chan]);	// Set channel frequency 
							rxmode = RXMODE_NORMAL;

#ifdef SERIAL
				      printf(" BIND \n");
#endif
			      }
		    }
		  else
		    {		// normal mode  
#ifdef RXDEBUG
			    rxdebug.channelcount[chan]++;
			    rxdebug.packettime = gettime() - lastrxtime;
					
					if ( skipchannel&& !timingfail ) afterskip[skipchannel]++;
					if ( timingfail ) afterskip[0]++;

#endif

unsigned long temptime = gettime();
	
			    nextchannel();

			    xn_readpayload(rxdata, 15);
			    pass = decodepacket();

			    if (pass)
			      {
#ifdef RXDEBUG
				      packetrx++;
#endif
							skipchannel = 0;
							timingfail = 0;
							lastrxchan = chan;
							lastrxtime = temptime;
				      failsafetime = temptime;
				      failsafe = 0;
			      }
			    else
			      {
#ifdef RXDEBUG
				      rxdebug.failcount++;
#endif
			      }

		    }		// end normal rx mode

	  }			// end packet received

		
	unsigned long time = gettime();

		

	// sequence period 12000
	if (time - lastrxtime > (HOPPING_NUMBER*PACKET_PERIOD + 1000) && rxmode != RXMODE_BIND)
	  {			
			//  channel with no reception   
		  lastrxtime = time;
			// set channel to last with reception
			if (!timingfail) chan = lastrxchan;
			// advance to next channel
		  nextchannel();
			// set flag to discard packet timing
			timingfail = 1;
	  }
		
	if ( !timingfail && skipchannel < HOPPING_NUMBER+1 && rxmode != RXMODE_BIND)
		{
			unsigned int temp = time - lastrxtime ;

			if ( temp > 1000 && ( temp + (PACKET_OFFSET) )/((int) PACKET_PERIOD) >= (skipchannel + 1) ) 
			{
				nextchannel();
#ifdef RXDEBUG				
				skipstats[skipchannel]++;
#endif				
				skipchannel++;
			}
		}	
	
	if (time - failsafetime > FAILSAFETIME)
	  {	//  failsafe
		  failsafe = 1;
		  rx[0] = 0;
		  rx[1] = 0;
		  rx[2] = 0;
		  rx[3] = 0;
	  }
#ifdef RXDEBUG
	if (gettime() - secondtimer > 1000000)
	  {
		  rxdebug.packetpersecond = packetrx;
		  packetrx = 0;
		  secondtimer = gettime();
	  }
#endif

}