void  NRF905::RX(char *TxRxBuffer)
{
    set_rx();			// Set nRF905 in Rx mode
    while (check_ready()==0);
    delay(1);
    RxPacket(TxRxBuffer);
    delay(1);
}
示例#2
0
/**
 * @param none
 */
void nRF905_rxData(void)
{
    /* Set nRF905 in Rx mode */
    set_rx();
    while (check_ready()==0);
    nrf_delay_ms(10);
    RxPacket();
    nrf_delay_ms(10);
}
void NRF905::TX(char *TxRxBuf)
{

    set_tx();
    delay(1);
    // Send data by nRF905
    TxPacket(config_info_buf+5, TxRxBuf);
	set_rx(); //switch back to receiving mode to set DR low

}
void NRF905::TX(char *TxRxBuf, char *TxAddress)
{

    set_tx();
    delay(1);
    // Send data by nRF905
    TxPacket(TxAddress, TxRxBuf);
	set_rx();

}
void NRF905::RX(char *TxRxBuf, char *RxAddress) //receive and change own address
{
    if(config_info_buf[5] != RxAddress[0] ||\
       config_info_buf[6] != RxAddress[1] ||\
       config_info_buf[7] != RxAddress[2] ||\
       config_info_buf[8] != RxAddress[3]){

        config_info_buf[5] = RxAddress[0];
        config_info_buf[6] = RxAddress[1];
        config_info_buf[7] = RxAddress[2];
        config_info_buf[8] = RxAddress[3];

        write_config(config_info_buf);
    }

    set_rx();			// Set nRF905 in Rx mode
    while (check_ready()==0);
    delay(1);
    RxPacket(TxRxBuf);
    delay(1);
}
示例#6
0
文件: tdma_c.c 项目: EDAyele/wsn430
static uint16_t slot_control(void) {
    uint8_t len, src;

    // test bytes in FIFO
    len = cc1101_status_rxbytes();

    // check fifo length
    if (len==0) {
        // empty packet
        //~ printf("empty");
        return 0;
    } else if (len>64) {
        // overflow, flush
        //~ printf("over");
        set_rx();
        return 0;
    }

    // get length, and check
    cc1101_fifo_get(&control_msg.hdr.length, 1);
    if (control_msg.hdr.length<(CONTROL_LENGTH-1)) {
        // length too small, download packet and return
        cc1101_fifo_get((uint8_t*)&control_msg+1, control_msg.hdr.length);
        cc1101_fifo_get((uint8_t*)&footer, FOOTER_LENGTH);
        //~ printf("small");
        return 0;
    } else if (control_msg.hdr.length>(CONTROL_LENGTH-1)) {
        // length too big, can't empty, flush
        //~ printf("big");
        set_rx();
        return 0;
    }

    // length is good
    // get data+status
    cc1101_fifo_get((uint8_t*)&control_msg+1, CONTROL_LENGTH-1);
    cc1101_fifo_get((uint8_t*)&footer, FOOTER_LENGTH);

    // check CRC
    if ( (footer.crc&0x80)==0 ) {
        // bad crc, exit
        //~ printf("crc");
        return 0;
    }

    src = HEADER_GET_ADDR(control_msg.hdr);
    // it's valid data for me, check content
    if (CONTROL_GET_TYPE(control_msg) == CONTROL_ATTACH_REQ) {
        int16_t slot;
        slot = tdma_mgt_attach(src);
        if (slot>0) {
            CONTROL_SET_TYPE(beacon_msg, CONTROL_ATTACH_OK);
            CONTROL_SET_ADDR(beacon_msg, src);
            beacon_msg.data = (uint8_t)slot;
            mac_slots[slot-1].addr = src;
        } else {
            CONTROL_SET_TYPE(beacon_msg, CONTROL_ATTACH_ERR);
            CONTROL_SET_ADDR(beacon_msg, src);
            beacon_msg.data = 0xFF;
        }
    }
    return 0;
}
示例#7
0
文件: tdma_c.c 项目: EDAyele/wsn430
static uint16_t slot_data(void) {
    uint8_t len, src;
    uint16_t now;
    now = timerB_time();

    // test CRC and bytes in FIFO
    len = cc1101_status_rxbytes();

    // check fifo length
    if (len==0) {
        // empty packet
        //~ printf("empty");
        return 0;
    } else if (len>64) {
        // overflow, flush
        //~ printf("over");
        set_rx();
        return 0;
    }

    // get length, and check
    cc1101_fifo_get(&data_msg.hdr.length, 1);
    if (data_msg.hdr.length>(DATA_LENGTH-1)) {
        // length too big, can't empty, flush
        //~ printf("big");
        set_rx();
        return 0;
    }
    // length is good
    // get data
    cc1101_fifo_get((uint8_t*)&data_msg+1, data_msg.hdr.length);
    // get status
    cc1101_fifo_get((uint8_t*)&footer, FOOTER_LENGTH);

    // check CRC
    if ( (footer.crc&0x80)==0 ) {
        // bad crc, exit
        //~ printf("crc");
        return 0;
    }

    // check type, destination
    if (HEADER_GET_TYPE(data_msg.hdr) != DATA_TYPE) {
        //~ printf("not_data");
        return 0;
    }

    // check source corresponds to timeslot
    src = HEADER_GET_ADDR(data_msg.hdr);

    if (tdma_mgt_getaddr(slot_count)!=src) {
        // src doesn't match slot
        return 0;
    }

    // check data has been read
    if (mac_slots[slot_count-1].ready==0) {
        memcpy(mac_slots[slot_count-1].data, data_msg.payload, MAC_PAYLOAD_SIZE);
        mac_slots[slot_count-1].ready = 1;

        // wake the CPU up by returning 1
        return 1;
    }
    return 0;
}