Пример #1
0
void beacon_sequence()
{
static int beacon_seq_state = 0;
	
 switch ( beacon_seq_state )
 {
	 case 0:
		 // send data if enough time passed since last send
	   if ( gettime() - ble_txtime > BLE_INTERVAL )
		 {
		 ble_send = 1;
		 oldchan = rf_chan;
		 send_beacon();
	   beacon_seq_state++;
		 }
	 break;
	 
	 case 1:
		 // wait for data to finish transmitting
			if( (xn_readreg(0x17)&B00010000)  ) 
			{
				xn_writereg( 0 , XN_TO_RX ); 
				xn_writereg(0x25, rfchannel[oldchan]);
			 beacon_seq_state++;
			 goto next;
			}
			else
			{// if it takes too long we get rid of it
				if ( gettime() - ble_txtime > BLE_TX_TIMEOUT )
				{
				 xn_command( FLUSH_TX);
					xn_writereg( 0 , XN_TO_RX ); 
				 beacon_seq_state++;
				 ble_send = 0;
				}
			}
	 break;
	 
		
	 case 2:
		 next:
		 // restore radio settings to protocol compatible
	   // mainly channel here if bind
		 ble_send = 0;	
		if ( rxmode == 0 )
		{
			xn_writereg(0x25, 0 ); // Set channel frequency	, bind
		}
		 beacon_seq_state++;
	 break;
	 
	 default:
		 beacon_seq_state = 0;		 
	 break;
	
 
	 
 }

}
Пример #2
0
void rx_init()
{


uint8_t bbcal[6] = { 0x3f , 0x4c , 0x84 , 0x6F , 0x9c , 0x20  };
writeregs( bbcal , sizeof(bbcal) );


uint8_t rfcal[8] = { 0x3e , 0xc9 , 0x9a , 0x80 , 0x61 , 0xbb , 0xab , 0x9c  };
writeregs( rfcal , sizeof(rfcal) );


uint8_t demodcal[6] = { 0x39 , 0x0b , 0xdf , 0xc4 , 0xa7 , 0x03};
writeregs( demodcal , sizeof(demodcal) );


int rxaddress[5] = { 0 , 0 , 0 , 0 , 0  };
xn_writerxaddress( rxaddress);

	xn_writereg( EN_AA , 0 );	// aa disabled
	xn_writereg( EN_RXADDR , 1 ); // pipe 0 only
	xn_writereg( RF_SETUP , B00000001);  // lna high current on ( better performance )
	xn_writereg( RX_PW_P0 , 15 ); // payload size
	xn_writereg( SETUP_RETR , 0 ); // no retransmissions ( redundant?)
	xn_writereg( SETUP_AW , 3 ); // address size (5 bits)
	xn_command( FLUSH_RX);
  xn_writereg( RF_CH , 0 );  // bind on channel 0
  xn_writereg( 0 , B00001111 ); // power up, crc enabled

#ifdef RADIO_CHECK
void check_radio(void);
 check_radio();
#endif	
}
Пример #3
0
void rx_init()
{	

writeregs( bbcal , sizeof(bbcal) );
writeregs( rfcal , sizeof(rfcal) );
writeregs( demodcal , sizeof(demodcal) );

int rxaddress[5] =  {0xCC,0xCC,0xCC,0xCC,0xCC};

xn_writerxaddress( rxaddress);

xn_writetxaddress( rxaddress);	

	xn_writereg( EN_AA , 0 );	// aa disabled
	xn_writereg( EN_RXADDR , 1 ); // pipe 0 only
//	xn_writereg( RF_SETUP , B00000001);  // lna high current on ( better performance )
	xn_writereg( RF_SETUP , B00000111);
	xn_writereg( RX_PW_P0 , PAYLOAD_LENGHT ); // payload size
	xn_writereg( SETUP_RETR , 0 ); // no retransmissions ( redundant?)
	xn_writereg( SETUP_AW , 3 ); // address size (5 bits)
	xn_command( FLUSH_RX);
  xn_writereg( RF_CH , 2 );  // bind  channel 
  xn_writereg( 0 , B00001111 ); // power up, crc enabled


	
}
void checkrx( void)
{
		if ( checkpacket() ) 
		{ 
			xn_readpayload( rxdata , 15);
			if ( rxmode == RXMODE_BIND)
			{	// rx startup , bind mode		
				if ( rxdata[0] == 0xAA ) 
				{// bind packet received
		
					txid[0] = rxdata[1];
					txid[1] = rxdata[2];
					
					rxmode = RXMODE_NORMAL;				

				  xn_writereg(0x25, (uint8_t)(rxdata[1] - 0x7D) ); // Set channel frequency	
								
				}
			}
			else
			{	// normal mode	
				#ifdef RXDEBUG	
				rxdebug.packettime = gettime() - lastrxtime;
				lastrxtime = gettime();
				#endif
				
				int pass = decode_cg023();
			 
				if ( pass )
				{ 	
					failsafetime = gettime(); 
					failsafe = 0;
					
				}	
				else
				{
				#ifdef RXDEBUG	
				rxdebug.failcount++;
				#endif	
				}
			
			}// end normal rx mode
				
		}// end packet received

		unsigned long time = gettime();
		
		if( time - failsafetime > FAILSAFETIME )
		{//  failsafe
		  failsafe = 1;
			rx[0] = 0;
			rx[1] = 0;
			rx[2] = 0;
			rx[3] = 0;
		}
#ifdef RXDEBUG	
		// packets per second counter
			if ( time - secondtimer  > 1000000)
			{
				rxdebug.packetpersecond = packetrx;
				packetrx = 0;
				secondtimer = gettime();
			}
#endif

}
Пример #5
0
void send_beacon()
{
	
// Channel hopping
ch++;
if (ch>2 ) 
{
  ch = 0;
}
// sending on channel 37 only to use whitening array
if (ONE_CHANNEL) ch = 0;


xn_writereg(RF_CH, chRf[ch]);

uint8_t L=0;



#ifdef USE_IBEACON
L=0;
// ibeacon packet structure
buf[L++] = B00100010; //PDU type, given address is random; 0x42 for Android and 0x40 for iPhone
buf[L++] = 36; // length of payload
buf[L++] = MY_MAC_0;
buf[L++] = MY_MAC_1;
buf[L++] = MY_MAC_2;
buf[L++] = MY_MAC_3;
buf[L++] = MY_MAC_4;
buf[L++] = MY_MAC_5;

// packet data unit
buf[L++] = 2; //flags (LE-only, limited discovery mode)
buf[L++] = 0x01;
buf[L++] = 0x06;
buf[L++] = 0x1A; // length of the name, including type byte
buf[L++] = 0xff;
buf[L++] = 0x4c;
buf[L++] = 0x00;
buf[L++] = 0x02;
buf[L++] = 0x15;
buf[L++] = 0x58;
buf[L++] = 0x5c;
buf[L++] = 0xde;
buf[L++] = 0x93;
buf[L++] = 0x1b;
buf[L++] = 0x01;
buf[L++] = 0x42;
buf[L++] = 0xcc;
buf[L++] = 0x9a;
buf[L++] = 0x13;
buf[L++] = 0x25;
buf[L++] = 0x00;
buf[L++] = 0x9b;
buf[L++] = 0xed;
buf[L++] = 0xc6;
buf[L++] = 0xe5;
buf[L++] = 0x00;
buf[L++] = 0x00;
buf[L++] = 0x00;
buf[L++] = 0x00;
buf[L++] = 0xCA; // tx power
#else


extern float vbattfilt;
int vbatt = vbattfilt *1000.0f;

unsigned int time = gettime();

time = time>>20; // divide by 1024*1024, no time for accuracy here
time = time * 10;

L=0;
buf[L++] = B00100010; //PDU type, given address is random; 0x42 for Android and 0x40 for iPhone
//buf[L++] = 0x42; //PDU type, given address is random; 0x42 for Android and 0x40 for iPhone

// max len 27 with 5 byte address = 37 total payload bytes
buf[L++] = 10+ 21; // length of payload
buf[L++] = MY_MAC_0;
buf[L++] = MY_MAC_1;
buf[L++] = MY_MAC_2;
buf[L++] = MY_MAC_3;
buf[L++] = MY_MAC_4;
buf[L++] = MY_MAC_5;

// packet data unit
buf[L++] = 2; //flags lenght(LE-only, limited discovery mode)
buf[L++] = 0x01; // compulsory flags
buf[L++] = 0x06; // flag value
buf[L++] =  0x03;  // Length of next block
buf[L++] =  0x03;  // Param: Service List
buf[L++] =  0xAA;  // Eddystone ID - 16 bit 0xFEAA
buf[L++] =  0xFE;  // Eddystone ID
buf[L++] =  0x11;  // Length of next block
buf[L++] =  0x16;  // Service Data
buf[L++] =  0xAA;  // Eddystone ID
buf[L++] =  0xFE;  // Eddystone ID
buf[L++] =  0x20;  // TLM flag
buf[L++] =  0x00;  // TLM version
buf[L++] =  vbatt>>8;  // Battery voltage
buf[L++] =  vbatt;  // Battery voltage
buf[L++] =  0x80;  // temperature 8.8 fixed point
buf[L++] =  0x00;  // temperature 8.8 fixed point
buf[L++] =  0x00;  // advertisment count 0
buf[L++] =  0x00;  // advertisment count 1
buf[L++] =  packetpersecond>>8&0xff;  // advertisment count 2
buf[L++] =  packetpersecond&0xff;  // advertisment count 3
buf[L++] =  time>>24;  // powerup time 0 
buf[L++] =  time>>16;  // powerup time 1
buf[L++] =  time>>8;  // powerup time 2
buf[L++] =  time;  // powerup time 3 in seconds times 10.
#endif
L=L+3; //crc


btLePacketEncode(buf, L, ch );

// undo xn297 data whitening
for (uint8_t i = 0; i < L; ++i) 
{
buf[i] = buf[i] ^ xn297_scramble_rev[i+ XN297_ADDRESS_SIZE_BLE] ;
}
 

for( int i = 0 ; i < L ; i++) buffint[i] = buf[i];


xn_command( FLUSH_TX);

xn_writereg( 0 , XN_TO_TX );

payloadsize = L;
xn_writepayload( buffint , L );

ble_txtime = gettime();

return;	
}
Пример #6
0
void rx_init()
{

	
// always on (CH_ON) channel set 1
aux[AUXNUMBER - 2] = 1;
// always off (CH_OFF) channel set 0
aux[AUXNUMBER - 1] = 0;
#ifdef AUX1_START_ON
aux[CH_AUX1] = 1;
#endif

	
#ifdef RADIO_XN297L
	
#define XN_TO_RX B10001111
#define XN_TO_TX B10000010
#define XN_POWER B00111111
	
#endif


	
#ifdef RADIO_XN297
static uint8_t bbcal[6] = { 0x3f , 0x4c , 0x84 , 0x6F , 0x9c , 0x20  };
writeregs( bbcal , sizeof(bbcal) );
// new values
static uint8_t rfcal[8] = { 0x3e , 0xc9 , 0x9a , 0xA0 , 0x61 , 0xbb , 0xab , 0x9c  };
writeregs( rfcal , sizeof(rfcal) );

static uint8_t demodcal[6] = { 0x39 , 0x0b , 0xdf , 0xc4 , 0xa7 , 0x03};
writeregs( demodcal , sizeof(demodcal) );


#define XN_TO_RX B00001111
#define XN_TO_TX B00000010
#define XN_POWER B00000111
#endif



bleinit();

delay(100);


int rxaddress[5] = { 0 , 0 , 0 , 0 , 0  };
xn_writerxaddress( rxaddress);

	xn_writereg( EN_AA , 0 );	// aa disabled
	xn_writereg( EN_RXADDR , 1 ); // pipe 0 only
	xn_writereg( RF_SETUP , XN_POWER);  // lna high current on ( better performance )
	xn_writereg( RX_PW_P0 , 15 ); // payload size
	xn_writereg( SETUP_RETR , 0 ); // no retransmissions ( redundant?)
	xn_writereg( SETUP_AW , 3 ); // address size (5 bits)
	xn_command( FLUSH_RX);
  xn_writereg( RF_CH , 0 );  // bind on channel 0

// set above
//	xn_writereg( 29 , 32); // feture reg , CE mode (software controlled)

#ifdef RADIO_XN297L
xn_writereg( 0x1d, B00111000 ); // 64 bit payload , software ce
spi_cson();
spi_sendbyte( 0xFD); // internal CE high command
spi_sendbyte( 0); // required for above
spi_csoff();
#endif

#ifdef RADIO_XN297
  xn_writereg( 0x1d, B00011000 ); // 64 bit payload , software ce
#endif

  xn_writereg( 0 , XN_TO_RX ); // power up, crc enabled, rx mode


#ifdef RADIO_CHECK
void check_radio(void);
 check_radio();
#endif	
}
Пример #7
0
void nextchannel()
{
	chan++;
	if (chan > 3 ) chan = 0;
	xn_writereg(0x25, rfchannel[chan] );
}
Пример #8
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

}
Пример #9
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

}
Пример #10
0
void send_beacon()
{
	
// Channel hopping
ch++;
if (ch>2 ) 
{
  ch = 0;
}
// sending on channel 37 only to use whitening array
if (ONE_CHANNEL) ch = 0;


xn_writereg(RF_CH, chRf[ch]);

uint8_t L=0;

extern int random_seed;

//extern int random_seed; //SilverVISE
//SilverVISE - start
#ifdef MY_QUAD_ID
random_seed = MY_QUAD_ID;
#else
#warning WARNING!!! USING RANDOM MAC ADDRESS! PLEASE READ COMMENT INSIDE rx_bayang_ble_app.c REGARDING POSSIBLE PROBLEMS WITH BLUETOOTH DUE TO ANDROID BUG!
#endif
// SilverVISE - end



extern float vbatt_comp;
int vbatt_comp_int = vbatt_comp *1000.0f;
extern int onground;

unsigned int time = gettime();

time = time>>20; // divide by 1024*1024, no time for accuracy here
time = time * 10;


//int acro_or_level_mode;
	
//if ( aux[LEVELMODE] ) acro_or_level_mode = 1;
//else acro_or_level_mode = 0;

extern unsigned int total_time_in_air;
extern unsigned int time_throttle_on;
unsigned int uptime = gettime();


int TLMorPID = 0; // 0 = TLM, 1 = PID+TLM

#ifdef PID_GESTURE_TUNING
TLMorPID = 1; // 0 = TLM, 1 = PID+TLM
#endif

if (onground ==1)
{
	time_throttle_on = uptime;
}
else
{
	total_time_in_air += (uptime - time_throttle_on);
	time_throttle_on = uptime;
}
unsigned int total_time_in_air_time = total_time_in_air>>20;
total_time_in_air_time = total_time_in_air_time *10;

int rate_and_mode_value = (aux[RATES]<<1) + !!(aux[LEVELMODE]);

extern int bound_for_BLE_packet;
extern int failsafe;
int onground_and_bind = (failsafe<<2)+(onground<<1)+(bound_for_BLE_packet);

#ifdef USE_STOCK_TX
	//nothing to do - already prepared (4. bit flag is 0 for stock TX)
#else
	onground_and_bind = 8+onground_and_bind;
#endif


int packetpersecond_short = packetpersecond/2;
if (packetpersecond_short>0xff) packetpersecond=0xff;


buf[L++] = B00100010; //PDU type, given address is random; 0x42 for Android and 0x40 for iPhone
//buf[L++] = 0x42; //PDU type, given address is random; 0x42 for Android and 0x40 for iPhone

// max len 27 with 5 byte address = 37 total payload bytes
buf[L++] = 10+ 21; // length of payload
buf[L++] = random_seed; //SilverVISE
buf[L++] = MY_MAC_1;
buf[L++] = MY_MAC_2;
buf[L++] = MY_MAC_3;
buf[L++] = MY_MAC_4;
buf[L++] = MY_MAC_5;

// packet data unit
buf[L++] = 2; //flags lenght(LE-only, limited discovery mode)
buf[L++] = 0x01; // compulsory flags
buf[L++] = 0x06; // flag value
buf[L++] =  0x15;  // Length of next block
buf[L++] =  0x16;  // Service Data


// ------------------------- TLM+PID
if (TLMorPID == 1)
{
buf[L++] =  0x2F; //PID+TLM datatype_and_packetID;  // xxxxyyyy -> yyyy = 1111 packet type ID (custom BLE type), xxxx = type of data in packet: 0001 -> telemetry, 0002->PID

#ifdef MY_QUAD_MODEL
	buf[L++] =  MY_QUAD_MODEL;
#else
	buf[L++] =  0x20;  // quad model (00 - unknown, 01- H8 mini green board, 20 - H101... check comments at start of this file for details)
#endif

buf[L++] = random_seed; //already custom entry - need to be randomized
#ifdef MY_QUAD_NAME
//fill with characters from MY_QUAD_NAME (just first 6 chars)
int string_len = 0;
while (string_len< 6)
	  {
			if (MY_QUAD_NAME[string_len]=='\0') break;
			buf[L++] = (char) MY_QUAD_NAME[string_len];
			string_len++;
		}

//fill the rest (up to 6 bytes) with blanks
for ( int i = string_len ; i < 6; i++)
	{
	buf[L++] = ' '; //blank
	}
#else


buf[L++]=(char)'N';
buf[L++]=(char)'O';
buf[L++]=(char)'N';
buf[L++]=(char)'A';
buf[L++]=(char)'M';
buf[L++]=(char)'E';
#endif
	
extern int current_pid_term; //0 = pidkp, 1 = pidki, 2 = pidkd
extern int current_pid_axis; //0 = roll, 1 = pitch, 2 = yaw

//int selectedPID = 0; //inxed of selected PID for changing
	
int selectedPID = ((current_pid_term)*3)+(current_pid_axis);
	
buf[L++] =  (current_PID_for_display<<4)+selectedPID; // xy => x=current PID for display 0 - 14 (cycling...), y = selected PID for changing 0 - 14
	
buf[L++] = packetpersecond_short;
	
/*
buf[L++] =  onground_and_bind; //binary xxxxabcd - xxxx = error code or warning, a -> 0 = stock TX, 1= other TX, b -> 0 = not failsafe, 1 = failsafe, c = 0 -> not bound, 1 -> bound, d = 0 -> in the air, 1 = on the ground;
*/

	
#ifdef COMBINE_PITCH_ROLL_PID_TUNING
	buf[L++] =  B01000000+((rate_and_mode_value<<4)+onground_and_bind); //binary xxRMabcd - x = error code or warning, 1 = combined roll+pitch tuning, R = rate (0 - normal, 1 - fast) , M = mode (1 - level, 0 - acro); a -> 0 = stock TX, 1= other TX, b -> 0 = not failsafe, 1 = failsafe, c = 0 -> not bound, 1 -> bound, d = 0 -> in the air, 1 = on the ground;
	int PID_pause = 8;
#else
	buf[L++] =  (rate_and_mode_value<<4)+onground_and_bind; //binary x0RMabcd - x = error code or warning, 0 = no combined roll+pitch tuning, R = rate (0 - normal, 1 - fast) , M = mode (1 - level, 0 - acro); a -> 0 = stock TX, 1= other TX, b -> 0 = not failsafe, 1 = failsafe, c = 0 -> not bound, 1 -> bound, d = 0 -> in the air, 1 = on the ground;
	int PID_pause = 12;
#endif
	
buf[L++] =  vbatt_comp_int>>8;  // Battery voltage compensated
buf[L++] =  vbatt_comp_int;  // Battery voltage compensated


extern float pidkp[]; // current_PID_for_display = 0, 1, 2
extern float pidki[]; // current_PID_for_display = 3, 4, 5
extern float pidkd[]; // current_PID_for_display = 6, 7, 8
extern float apidkp[]; // current_PID_for_display = 9, 10
extern float apidki[]; //  current_PID_for_display = 11, 12
extern float apidkd[]; //  current_PID_for_display = 13, 14
	
unsigned long pid_for_display = 0;

switch ( current_PID_for_display )
 {
	 case 0:pid_for_display =(uint16_t)(pidkp[0]*10000.0f);break;
	 case 1:pid_for_display =(uint16_t)(pidkp[1]*10000.0f);break;
	 case 2:pid_for_display =(uint16_t)(pidkp[2]*10000.0f);break;
	 case 3:pid_for_display =(uint16_t)(pidki[0]*10000.0f);break;
	 case 4:pid_for_display =(uint16_t)(pidki[1]*10000.0f);break;
	 case 5:pid_for_display =(uint16_t)(pidki[2]*10000.0f);break;
	 case 6:pid_for_display =(uint16_t)(pidkd[0]*10000.0f);break;
	 case 7:pid_for_display =(uint16_t)(pidkd[1]*10000.0f);break;
	 case 8:pid_for_display =(uint16_t)(pidkd[2]*10000.0f);break;
/*
	 //level mode PIDs - disabled for now...
	 case 9:pid_for_display =(uint16_t)(apidkp[0]*10000.0f);break;
	 case 10:pid_for_display =(uint16_t)(apidkp[1]*10000.0f);break;
	 case 11:pid_for_display =(uint16_t)(apidki[0]*10000.0f);break;
	 case 12:pid_for_display =(uint16_t)(apidki[1]*10000.0f);break;
	 case 13:pid_for_display =(uint16_t)(apidkd[0]*10000.0f);break;
	 case 14:pid_for_display =(uint16_t)(apidkd[1]*10000.0f);break;
*/
	 }

/*buf[L++] =  total_time_in_air_time>>8;  // total time in air
buf[L++] =  total_time_in_air_time;  // total time in air
buf[L++] =  time>>8;
buf[L++] =  time;
*/	

buf[L++] =  total_time_in_air_time>>8;  // total time in air
buf[L++] =  total_time_in_air_time;  // total time in air	 
buf[L++] =  time>>8;
buf[L++] =  time;

buf[L++] =  pid_for_display>>8;
buf[L++] =  pid_for_display;
	 
L=L+3; //crc

PID_index_delay++;
int PID_index_limit = 8; // number of PIDs to display for acro mode tuning
//if ((rate_and_mode_value&1) == 1) PID_index_limit = 14; // number of PIDs to display for level mode tuning
if (PID_index_delay > PID_pause) {
	PID_index_delay = 0;
	current_PID_for_display++;
	
#ifdef COMBINE_PITCH_ROLL_PID_TUNING
 if (current_PID_for_display == 1)	current_PID_for_display =2;
 if (current_PID_for_display == 4)	current_PID_for_display =5;
 if (current_PID_for_display == 7)	current_PID_for_display =8;
#endif
	
	if (current_PID_for_display > PID_index_limit) current_PID_for_display = 0;
}

}
Пример #11
0
void rx_init()
{

	
// always on (CH_ON) channel set 1
aux[AUXNUMBER - 2] = 1;
// always off (CH_OFF) channel set 0
aux[AUXNUMBER - 1] = 0;
#ifdef AUX1_START_ON
aux[CH_AUX1] = 1;
#endif


#ifdef AUX4_START_ON
    aux[CH_AUX4] = 1;
#endif

	
#ifdef RADIO_XN297L
	
#define XN_TO_RX B10001111
#define XN_TO_TX B10000010
#define XN_POWER B00111111
	
#endif


	
#ifdef RADIO_XN297
static uint8_t bbcal[6] = { 0x3f , 0x4c , 0x84 , 0x6F , 0x9c , 0x20  };
writeregs( bbcal , sizeof(bbcal) );
// new values
static uint8_t rfcal[8] = { 0x3e , 0xc9 , 0x9a , 0xA0 , 0x61 , 0xbb , 0xab , 0x9c  };
writeregs( rfcal , sizeof(rfcal) );

static uint8_t demodcal[6] = { 0x39 , 0x0b , 0xdf , 0xc4 , 0xa7 , 0x03};
//static uint8_t demodcal[6] = { 0x39 , 0x0b , 0xdf , 0xc4 , B00100111 , B00000000};
writeregs( demodcal , sizeof(demodcal) );


#define XN_TO_RX B00001111
#define XN_TO_TX B00000010
//#define XN_POWER B00000111 // disabled by silverAG for SilverVISE - value is added from config.h
// SilverVISE - start:
#ifdef TX_POWER_GENERAL
// use value from config.h
#define XN_POWER TX_POWER_GENERAL
#else
#define XN_POWER B00000111
#endif
// SilverVISE - end

#endif



bleinit();

delay(100);


int rxaddress[5] = { 0 , 0 , 0 , 0 , 0  };
xn_writerxaddress( rxaddress);

	xn_writereg( EN_AA , 0 );	// aa disabled
	xn_writereg( EN_RXADDR , 1 ); // pipe 0 only
	xn_writereg( RF_SETUP , XN_POWER);  // lna high current on ( better performance )
	xn_writereg( RX_PW_P0 , 15 ); // payload size
	xn_writereg( SETUP_RETR , 0 ); // no retransmissions ( redundant?)
	xn_writereg( SETUP_AW , 3 ); // address size (5 bits)
	xn_command( FLUSH_RX);
  xn_writereg( RF_CH , 0 );  // bind on channel 0


#ifdef RADIO_XN297L
xn_writereg( 0x1d, B00111000 ); // 64 bit payload , software ce
spi_cson();
spi_sendbyte( 0xFD); // internal CE high command
spi_sendbyte( 0); // required for above
spi_csoff();
#endif

#ifdef RADIO_XN297
  xn_writereg( 0x1d, B00011000 ); // 64 bit payload , software ce
#endif

  xn_writereg( 0 , XN_TO_RX ); // power up, crc enabled, rx mode


#ifdef RADIO_CHECK
int	rxcheck = xn_readreg( 0x0f); // rx address pipe 5	
	// should be 0xc6
	extern void failloop( int);
	if ( rxcheck != 0xc6) failloop(3);
#endif	
}