static bool gzp_tx_packet(const uint8_t* tx_packet, uint8_t length, uint8_t pipe) { if(gzll_tx_data(tx_packet, length, pipe)) { while(gzll_get_state() != GZLL_IDLE) ; return gzll_tx_success(); } return false; }
void main(void) { bool send_crypt_data = false; bool tx_success = false; gzp_id_req_res_t id_req_status; uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH]; mcu_init(); // Initialize Gazell Link Layer gzll_init(); // Initialize Gazell Pairing Library gzp_init(); EA = 1; while(true) { payload[0] = ~P0; // Send every other packet as encrypted data if(send_crypt_data) { // Send encrypted packet using the Gazell pairing library tx_success = gzp_crypt_data_send(payload, GZP_ENCRYPTED_USER_DATA_MAX_LENGTH); } else { // Send packet as plaintext on pipe 2 gzll_tx_data(payload, GZLL_MAX_FW_PAYLOAD_LENGTH, 2); while(gzll_get_state() != GZLL_IDLE) ; tx_success = gzll_tx_success(); } send_crypt_data = !send_crypt_data; // If data transfer failed if(!tx_success) { // Send "system address request". Needed for sending any user data to Host. gzp_address_req_send(); // Send "Host ID request". Needed for sending encrypted user data to host. id_req_status = gzp_id_req_send(); } // If waiting for Host to grant or reject ID request if(id_req_status == GZP_ID_RESP_PENDING) { // Send new ID request for fetching response id_req_status = gzp_id_req_send(); } } }
bool com_execute() { xdata bool retval = false; xdata uint8_t user_data[32]; xdata uint16_t temp; xdata uint8_t t_length, t_pipe, curr_gzll_state; static xdata uint8_t prev_gzll_state = 0xff; // If Device operation if(device_mode) { // Get Gazell state curr_gzll_state = gzll_get_state(); if(curr_gzll_state == GZLL_IDLE) { // If state transition from TRANSMIT to IDLE if(prev_gzll_state == GZLL_DEVICE_ACTIVE) { retval = true; if(gzll_tx_success()) { statistics[TX_PL_CNT]++; statistics[TX_BYTE_CNT] += app_setup[TX_PL_LENGTH]; temp = gzll_get_tx_attempts(); statistics[TX_TRY_CNT] += temp; statistics[AVG_TX_TRIES] = (uint16_t)(((float)statistics[TX_TRY_CNT] * 100) / statistics[TX_PL_CNT] ); if(statistics[MAX_TX_TRIES] < temp) { statistics[MAX_TX_TRIES] = temp; } statistics[TX_CH_SWITCHES] += gzll_get_tx_channel_switches(); } if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe)) { statistics[RX_PL_CNT]++; statistics[RX_BYTE_CNT] += t_length; } } if(radio_run) { EA = 0; if(cnt_1ms >= app_setup[TX_PACKET_INTERVAL] ) { gzll_timer_tick = false; cnt_1ms = 0; EA = 1; while(!gzll_timer_tick) // Improves synchronization to start in synch with protocol timer ; gzll_tx_data(user_data, app_setup[TX_PL_LENGTH], app_setup[TX_PIPE]); curr_gzll_state = GZLL_DEVICE_ACTIVE; } EA = 1; } prev_gzll_state = curr_gzll_state; } } // Host operation else { if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe)) { retval = true; statistics[RX_PL_CNT]++; statistics[RX_BYTE_CNT] += t_length; t_length = app_setup[ACK_PL_LENGTH]; if(t_length) { if(gzll_ack_payload_write(user_data, t_length, t_pipe)) { statistics[TX_PL_CNT]++; statistics[TX_BYTE_CNT] += t_length; } } } } return retval; }