This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GZLL Device Crypt, Host ??

We have a project for a sauna controllunit, A remotcontrolle and hostunit which controlles the sauna. The Device send comands to the host, the host sends Ack + Payload (the payload includes some informations that the remotconrolle needs to know). We could do that for some times and suddenly the payload includes the TX-Information from the device. When this happend we had an gzll errorcode 15. But we didn’t realy know how to handel that error. If we use the cryp methodes we could no get any respons form the host to the device.

The Ack +payload is about 11 Bytes long.

[b] Device:[/b]


/**
 * @brief Diese Funktion initialisiert die Kommunikation.
 */
void protocol_communication_init()
{
  nrf_gzll_init(NRF_GZLL_MODE_DEVICE);
  nrf_gzll_set_max_tx_attempts(100);
  nrf_gzll_set_timeslot_period(NRF_GZLLDE_RXPERIOD_DIV_2);  // Half RX period on nRF24Lxx device
  nrf_gzll_set_tx_power(NRF_GZLL_TX_POWER_4_DBM);
  
  gzp_init();
  nrf_gzll_enable();
  
  pairing_count = 0;
}


/**
 * @brief Erstellt ein Kommande, welches gesendet werden kann.
 */
static void send_command(uint8_t* send_array, uint8_t length)
{
  if(gzp_crypt_data_send(send_array, length))
  {
    protocol_ack_to_parameter();
  }
  
// Temporary outcommented...

//  nrf_gzp_reset_tx_complete();
//  nrf_gzp_reset_tx_success();

//  if(nrf_gzll_add_packet_to_tx_fifo(UNENCRYPTED_DATA_PIPE, send_array, length))
//  {
//    while(!nrf_gzp_tx_complete())
//    {
//        __WFI();
//    }
//  }
//  if(nrf_gzp_tx_success())
//  {
//    protocol_ack_to_parameter();
//  }
}

static void protocol_ack_to_parameter()
{
  uint16_t value = 0;
  
  parameter_setCurrentTemperature(rx_buffer[db_rec_curr_temp]);
  parameter_setCurrentHumidity(rx_buffer[db_rec_curr_humi]);
  
  parameter_setTemperature(rx_buffer[db_rec_target_temp]);
  parameter_setHumidity(rx_buffer[db_rec_target_humi]);

  value = ((uint16_t)rx_buffer[db_rec_duration_hb] << 8) + rx_buffer[db_rec_duration_lb];
  parameter_setStopwatchHour(value / 60);
  parameter_setStopwatchMinute(value % 60);
  
  parameter_setClockHour(rx_buffer[db_rec_clock_h]);
  parameter_setClockMinute(rx_buffer[db_rec_clock_min]);
  
  parameter_setError(rx_buffer[db_rec_error]);
  
  debug_print_values("\n\rACK: %d %d %d ", rx_buffer[0], rx_buffer[1], rx_buffer[2]);
  debug_print_values("%d %d %d ", rx_buffer[3], rx_buffer[4], rx_buffer[5]);
  debug_print_values("%d %d %d ", rx_buffer[6], rx_buffer[7], rx_buffer[8]);
  debug_print_values("%d %d %d ", rx_buffer[9], rx_buffer[10], rx_buffer[11]);
  debug_print_values("%d %d %d ", rx_buffer[12], rx_buffer[13], nrf_gzll_get_error_code());
}


/**
 * @brief Diese Funktion wartet so lange, bis ein Kommando empfangen wurde.
 * @retval 1 Ein Kommando wurde empfangen.
 * @retval 0 Es wurde kein Kommando innerhalb von 0.5s empfangen.
 */
uint8_t protocol_is_rec_ack()
{
  uint32_t ack_payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;

  if(nrf_gzll_get_rx_fifo_packet_count(UNENCRYPTED_DATA_PIPE) > 0)
  {
    nrf_gzll_fetch_packet_from_rx_fifo(UNENCRYPTED_DATA_PIPE, rx_buffer, &ack_payload_length);
  }
  
  return is_rec_command(CMD_ACK);
}

[b] Host:[/b]


void protocol_host_init(void)
{
  nrf_gzll_init(NRF_GZLL_MODE_HOST);
  nrf_gzll_set_rx_pipes_enabled(nrf_gzll_get_rx_pipes_enabled() | (1 << UNENCRYPTED_DATA_PIPE));
  nrf_gzll_set_timeslot_period(NRF_GZLLDE_RXPERIOD_DIV_2);
  
  gzp_init();
  gzp_pairing_enable(true);
  nrf_gzll_enable();
}


/**
 * @brief Vergleicht die Kommando Id mit der empfangenen Id.
 */
static uint8_t is_rec_command(protocol_host_cmd_id_t cmd)
{
  return rx_buffer[db_rec_cmd] == cmd;
}

/**
 * @brief Diese Funktion setzt bereitet die ACK Antwort for
 */
static void protocol_host_prepair_response(void)
{
  uint16_t value = 0;
  uint32_t  length = (uint32_t)db_send_length;

  tx_buffer[db_send_cmd]         = (uint8_t)CMD_ACK;

  tx_buffer[db_send_clock_h]     = parameter_getClockHour();
  tx_buffer[db_send_clock_min]   = parameter_getClockMinute();
  
  tx_buffer[db_send_curr_humi]   = parameter_getCurrentHumidity();
  tx_buffer[db_send_curr_temp]   = parameter_getCurrentTemperature();
  
  value = ((uint16_t)parameter_getStopwatchHour() << 8) & 0xFF00 + parameter_getStopwatchMinute();
  tx_buffer[db_send_duration_hb] = (value >> 8) & 0x00FF;
  tx_buffer[db_send_duration_lb] = (value)      & 0x00FF;

  tx_buffer[db_send_error]       = parameter_getError();
  tx_buffer[db_send_state]       = 0;
  tx_buffer[db_send_target_humi] = parameter_getHumidity();
  tx_buffer[db_send_target_temp] = parameter_getTemperature();
  tx_buffer[db_send_used]        = 1;
  tx_buffer[db_send_bath_on]     = 1;

  if(nrf_gzll_ok_to_add_packet_to_tx_fifo(UNENCRYPTED_DATA_PIPE))
  {
    nrf_gzll_add_packet_to_tx_fifo(UNENCRYPTED_DATA_PIPE, tx_buffer, length);
  }
}

/**
 * @brief Diese muss im Host periodisch aufgerufen werden.
 */
void protocol_host_execute(void)
{
  gzp_host_execute();

  if(gzp_id_req_received())
  {
    gzp_id_req_grant();
  } 
  
  protocol_host_received_data();
}

/**
 * @brief Diese Funktion wird beim Empfang eines Kommandos aufgerufen.
 */
void protocol_host_received_data(void)
{
  if(gzp_crypt_user_data_received())
  {
    gzp_crypt_user_data_read(rx_buffer, &rx_length);
    
    protocol_host_set_parameter();
    protocol_host_prepair_response();
  }
// Temporary outcommented...
  
//  if(nrf_gzll_get_rx_fifo_packet_count(UNENCRYPTED_DATA_PIPE) > 0)
//  {
//    nrf_gzll_fetch_packet_from_rx_fifo(UNENCRYPTED_DATA_PIPE, rx_buffer, &rx_length);
//    protocol_host_set_parameter();
//    protocol_host_prepair_response();
//  }
}

  • We checked the exampels "gzll_device_ack_payload", "gzll_device_w_dynamic_pairing", "gzll_host_ack_payload" and "gzll_host_w_dynamic_pairing" but could not clearly find out where is the problem. We setting up the Device and the Host like the "Gazzel Link Layer User Guide" says.

    Device:

    
    
      nrf_gzll_init(NRF_GZLL_MODE_DEVICE);
      nrf_gzll_set_rx_pipes_enabled(nrf_gzll_get_rx_pipes_enabled() | (1 << UNENCRYPTED_DATA_PIPE));  //JSC Test
      nrf_gzll_set_max_tx_attempts(100);
      nrf_gzll_set_timeslot_period(NRF_GZLLDE_RXPERIOD_DIV_2);  // Half RX period on nRF24Lxx device
      nrf_gzll_set_tx_power(NRF_GZLL_TX_POWER_4_DBM);
      
      gzp_init();
      nrf_gzll_enable();
    
    
    

    Host:

    
    
      nrf_gzll_init(NRF_GZLL_MODE_HOST);
      nrf_gzll_set_rx_pipes_enabled(nrf_gzll_get_rx_pipes_enabled() | (1 << UNENCRYPTED_DATA_PIPE));
      nrf_gzll_set_timeslot_period(NRF_GZLLDE_RXPERIOD_DIV_2);
      
      gzp_init();
      gzp_pairing_enable(true);
      nrf_gzll_enable();
    
    
    

    Did we somethinge missed? We use the nrf51822

  • No one any ideas? Not even a correction of my bad englisch? :D or would help some more informations?

Related