int main(void) { // Debug helper variables uint32_t length; // Data and acknowledgement payloads uint8_t payload[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH]; ///< Payload to send to Host. // Setup user interface (buttons and LEDs) ui_init(); // Initialize Gazell Link Layer (void)nrf_gzll_init(NRF_GZLL_MODE_HOST); (void)nrf_gzll_set_timeslot_period(NRF_GZLLDE_RXPERIOD_DIV_2); // Half RX period on nRF24Lxx device // Initialize Gazell Pairing Library gzp_init(); (void)nrf_gzll_set_rx_pipes_enabled(nrf_gzll_get_rx_pipes_enabled() | (1 << UNENCRYPTED_DATA_PIPE)); gzp_pairing_enable(true); (void)nrf_gzll_enable(); for(;;) { gzp_host_execute(); // If Host ID request received if(gzp_id_req_received()) { // Always grant request gzp_id_req_grant(); } length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH; if( nrf_gzll_get_rx_fifo_packet_count(UNENCRYPTED_DATA_PIPE) ) { if(nrf_gzll_fetch_packet_from_rx_fifo(UNENCRYPTED_DATA_PIPE, payload, &length)) { output_present(payload[0]); } } else if (gzp_crypt_user_data_received()) { if(gzp_crypt_user_data_read(payload, (uint8_t*)&length)) { output_present(payload[0]); } } } }
void main(void) { uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH]; mcu_init(); gzll_init(); gzp_init(); gzp_pairing_enable(true); // Open pipe 2. (Pipe 0 and 1 are reserved by pairing library). gzll_set_param(GZLL_PARAM_RX_PIPES, gzll_get_param(GZLL_PARAM_RX_PIPES) | (1 << 2)); // Set P0 as output P0DIR = 0; EA = 1; // Enter host mode (start monitoring for data) gzll_rx_start(); for(;;) { // If gzpair_host_execute() returns true, a pairing request has been received gzp_host_execute(); // If Host ID request received if(gzp_id_req_received()) { // Always grant request gzp_id_req_grant(); } // If any data received (plaintext on pipe 2 or encrypted through Gazell pairing library) if((gzll_get_rx_data_ready_pipe_number() == 2) || (gzp_crypt_user_data_received())) { // Plaintext data received? if(gzll_rx_fifo_read(payload, NULL, NULL)) { // Write received payload[0] to port 0 P0 = payload[0]; } else { // Read data from Gazell pairing library gzp_crypt_user_data_read(payload, NULL); // Write received payload[0] to port 0 P0 = payload[0]; } } } }