Ejemplo n.º 1
0
/** 
 * Scan all the available channels for carrier/rpd
 * Results are stored in the sweeper struct 
 * 
 * @param s sweeper instance to work with
 * @param loops number of loops to perform the sweep
 */
void rf24_sweep(struct rf24_sweeper *s, int loops)
{
	while (loops--)
	{
		int i = RF24_NUM_CHANNELS;
		while (i--)
		{
			/* Select this channel */
			rf24_write_register(s->r, RF_CH, i);
			
			// Listen for a little
			rf24_start_listening(s->r);
			delay_us(128);
			rf24_stop_listening(s->r);
			
			/* Did we get a carrier? */
#ifdef CONFIG_LIB_RF24_SWEEP_RPD
			if ( rf24_test_rpd(s->r) )
#else
			if ( rf24_test_carrier(s->r) )
#endif
				s->values[i]++;
			
		}
	}
	
}
Ejemplo n.º 2
0
uchar   usbFunctionSetup(uchar data[8])
{
	usbRequest_t    *rq = (void *)data;
	switch (rq->bRequest) 
	{
	case RQ_SET_CONFIG:
		rf24_init(g_radio);
		rf24_enable_dynamic_payloads(g_radio);
		rf24_set_channel(g_radio,   rq->wValue.bytes[0]);
		rf24_set_data_rate(g_radio, rq->wValue.bytes[1]);
		rf24_set_pa_level(g_radio,  rq->wIndex.bytes[0]);
		break;
	case RQ_OPEN_PIPES:
		
		break;
	case RQ_LISTEN:
		if (rq->wValue.bytes[0]) {
			rf24_open_reading_pipe(g_radio, 1, local_addr);
			rf24_start_listening(g_radio);
		} else {
			rf24_stop_listening(g_radio);
			rf24_open_writing_pipe(g_radio, remote_addr);
		}
		break;
	case RQ_READ:
	{
		uint8_t pipe;
		uint8_t retries=50;
		uint8_t len =0; 
		do { 
			if (rf24_available(g_radio, &pipe)) {
				PORTC ^= 1<<2;
				len = rf24_get_dynamic_payload_size(g_radio);
				have_moar = !rf24_read(g_radio, msg, len);
				usbMsgPtr = msg;
				return len;
			}
			delay_ms(10);
		} while (retries--);
		
	}
		return 0;	
		break;
		
	case RQ_NOP:
		/* Shit out dbg buffer */
		usbMsgPtr = msg;
		return strlen(msg)+1;
		break;
	}
	last_rq = rq->bRequest;
	rq_len = rq->wLength.word;
	pos = 0;
	return USB_NO_MSG;		

}
Ejemplo n.º 3
0
int writeMessage(void* message, uint8_t address[5], uint16_t length) {
    transmitLedOn();
    _delay_ms(250);
    rf24_stop_listening(&r);
    rf24_open_writing_pipe(&r, address);    
    int writeReturn = rf24_write(&r, &message, length*sizeof(uint8_t));
    _delay_ms(250);
    rf24_start_listening(&r);
    transmitLedOff();
    return writeReturn
}
Ejemplo n.º 4
0
int sendConfigRequest(uint8_t address[5]) {
    message_type_t type = REQUESTCONFIG;
    ConfirmAddress msg;
    msg.messageId = type;
    msg.length = 3;
    PORTD ^= (1<<4);
    _delay_ms(250);
    rf24_stop_listening(&r);
    rf24_open_writing_pipe(&r, address);
    int writeReturn = rf24_write(&r, &msg, msg.length*sizeof(uint8_t));
    _delay_ms(250);
    rf24_start_listening(&r);
    PORTD ^= (1<<4);
    printk("sent config request message\n");
    return writeReturn;
}
Ejemplo n.º 5
0
uint8_t sendConfigResponse(uint8_t address[5]) {
    message_type_t type = RESPONDCONFIG;
    RespondConfig msg;
    msg.messageId = type;
    msg.length = 8;
    msg.numberOfSensors = 3;
    msg.sensorTypes = sensorIds; 
    PORTD ^= (1<<4);
    _delay_ms(250);
    rf24_stop_listening(&r);
    rf24_open_writing_pipe(&r, address);
    int writeReturn = rf24_write(&r, &msg, msg.length*sizeof(uint8_t));
    _delay_ms(250);
    rf24_start_listening(&r);
    PORTD ^= (1<<4);
    printk("sent config message\n");
    return writeReturn;
}