Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <nuttx/net/usrsock.h>
#include <nuttx/mqueue.h>
#include <nuttx/net/net.h>
#include <nuttx/kstring.h>

#include <meadow/meadow_hw_version.h>
#include <meadow/hcom_shared_common.h>
Expand Down
119 changes: 86 additions & 33 deletions nuttx/configs/stm32f777zit6-meadow/src/espcp/espcp_event_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include <sys/types.h>

#include <nuttx/kstring.h>

#include <nuttx/kthread.h>
#include <nuttx/wqueue.h>
#include <meadow/hcom_shared_common.h>
Expand Down Expand Up @@ -78,6 +80,7 @@ static void espcp_network_got_ip_event_handler(espcp_message_t *);

static void espcp_system_get_configuration_event_handler(espcp_message_t *);
static void espcp_system_error_event_handler(espcp_message_t *);
static void espcp_send_logging_configuration(void);

/****************************************************************************
* Private Data
Expand Down Expand Up @@ -431,6 +434,87 @@ void espcp_dispatch_event(espcp_message_t *message)
}
}

/****************************************************************************
* Name: espcp_send_logging_configuration
*
* Description:
* Build the current logging configuration and send it to the ESP32.
*
* Input Parameters:
* None.
*
* Returned Value:
* None.
*
* Assumptions/Limitations:
* None.
*
****************************************************************************/
static void espcp_send_logging_configuration(void)
{
hcom_nx_config_lock();
meadow_configuration_t *config = hcom_nx_config_get_pointer();
espcp_logging_configuration_t logging_config;
logging_config.interface = config->esp_log_destination;
logging_config.udp_port = config->esp_log_udp_port;
//
// Note that we do not need to strdup the string as it will be copied
// when the payload is encoded. Also, the config is still locked at
// this point.
//
logging_config.components_to_log = config->esp_log_components;
int payload_length = espcp_encoded_logging_configuration_buffer_size(&logging_config);
uint8_t *payload = (uint8_t *) zalloc(payload_length);
if (payload != NULL)
{
espcp_encode_logging_configuration(&logging_config, payload);
}
hcom_nx_config_unlock();

if (payload != NULL)
{
espcp_message_t *logging_configuration_message = espcp_create_message_on_heap(espcp_message_types_header, espcp_esp32_interfaces_system,
espcp_system_function_logging_configuration, espcp_status_codes_completed_ok,
espcp_get_next_message_id(), payload, payload_length);
if (logging_configuration_message != NULL)
{
espcp_queue_message(logging_configuration_message, false);
}
else
{
free(payload);
}
}
}

/****************************************************************************
* Name: espcp_send_wifi_country_code
*
* Description:
* Send the WiFi country to the ESP in case it needs changing.
*
* Input Parameters:
* None.
*
****************************************************************************/
static void espcp_send_wifi_country_code(void)
{
char *country_code = NULL;

hcom_nx_config_lock();
meadow_configuration_t *config = hcom_nx_config_get_pointer();
if (config != NULL)
{
country_code = kmm_strdup(config->country_code);
}
hcom_nx_config_unlock();
if (country_code != NULL)
{
hcom_nx_config_set_esp_string_value(espcp_configuration_items_country_code, country_code);
kmm_free(country_code);
}
}

/****************************************************************************
* Name: espcp_system_get_configuration_event_handler
*
Expand Down Expand Up @@ -469,39 +553,8 @@ void espcp_system_get_configuration_event_handler(espcp_message_t *message)
//
// Send logging configuration to the ESP32.
//
hcom_nx_config_lock();
config = hcom_nx_config_get_pointer();
espcp_logging_configuration_t logging_config;
logging_config.interface = config->esp_log_destination;
logging_config.udp_port = config->esp_log_udp_port;
//
// Note that we do not need to strdup the string as it will be copied
// when the payload is encoded. Also, the config is still locked at
// this point.
//
logging_config.components_to_log = config->esp_log_components;
int payload_length = espcp_encoded_logging_configuration_buffer_size(&logging_config);
uint8_t *payload = (uint8_t *) zalloc(payload_length);
if (payload != NULL)
{
espcp_encode_logging_configuration(&logging_config, payload);
}
hcom_nx_config_unlock();

if (payload != NULL)
{
espcp_message_t *logging_configuration_message = espcp_create_message_on_heap(espcp_message_types_header, espcp_esp32_interfaces_system,
espcp_system_function_logging_configuration, espcp_status_codes_completed_ok,
espcp_get_next_message_id(), payload, payload_length);
if (logging_configuration_message != NULL)
{
espcp_queue_message(logging_configuration_message, false);
}
else
{
free(payload);
}
}
espcp_send_logging_configuration();
espcp_send_wifi_country_code();
}
}
espcp_delete_message_and_payload(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ enum espcp_status_codes
* @brief Invalid request.
*/
espcp_status_codes_invalid_request = 61,

/**
* @brief Invalid country code.
*/
espcp_status_codes_invalid_country_code = 62,
};
typedef enum espcp_status_codes espcp_status_codes_t;

Expand Down Expand Up @@ -343,6 +348,7 @@ enum espcp_configuration_items
espcp_configuration_items_soft_ap_mac_address = 14,
espcp_configuration_items_subnet_mask = 15,
espcp_configuration_items_bluetooth_mac_address = 16,
espcp_configuration_items_country_code = 17,
};
typedef enum espcp_configuration_items espcp_configuration_items_t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ static char *esp_log_component_names[] = {
"coredump", // Core dump information
};

/**
* @brief Default country code to use for WiFi if not specified in the config file.
*/
static char *default_country_code = "01";

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -1740,6 +1745,18 @@ static void hcom_nx_config_process_network_section(yaml_network_t *network_confi
}
}
}
config->country_code = default_country_code;
if ((network_config->country_code != NULL) && (strlen(network_config->country_code) > 0))
{
if (strlen(network_config->country_code) != 2)
{
meadow_os_raise_simple_exception(espcp_status_codes_invalid_country_code);
}
else
{
config->country_code = kmm_strdup(network_config->country_code);
}
}
if (create_default_dns_resolver_file)
{
hcom_nx_config_setup_default_dns_servers();
Expand Down Expand Up @@ -1767,7 +1784,22 @@ static void hcom_nx_config_process_network_section(yaml_network_t *network_confi
config->default_interface = hcom_nx_config_find_interface_by_name(MEADOW_IFT_ESP32_NAME);
}
config->default_interface->gateway_changed = false;
}
//
// Now check if the country code has been specified.
//
config->country_code = default_country_code;
if ((network_config->country_code != NULL) && (strlen(network_config->country_code) > 0))
{
if (strlen(network_config->country_code) != 2)
{
meadow_os_raise_simple_exception(espcp_status_codes_invalid_country_code);
}
else
{
config->country_code = kmm_strdup(network_config->country_code);
}
}
}
else
{
hcom_nx_config_setup_default_ntp_servers(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ void hcom_nx_config_process_cell_config_file(void);
void hcom_nx_config_turn_on_the_cell_module(void);
void hcom_nx_config_refresh_mono_version(meadow_configuration_t *);
int hcom_nx_config_set_esp_integer_value(espcp_configuration_items_t, uint32_t);
int hcom_nx_config_set_esp_string_value(espcp_configuration_items_t, const char *);
void hcom_nx_config_set_time_to_os_build_time(void);
void hcom_nx_config_add_default_gateway_dns_file(meadow_configuration_t *, uint32_t);
void hcom_nx_config_add_dns_address_into_file(uint32_t);
void hcom_nx_config_update_network_interface(meadow_configuration_t *, uint32_t, uint32_t, uint32_t);
void hcom_nx_config_update_dns_address(meadow_configuration_t *, uint32_t);
void hcom_nx_config_clear_network_interface(meadow_configuration_t *);
unit_tests_configuration_t *process_unit_tests_configuration_file(void);
int hcom_nx_config_set_esp_string_value(espcp_configuration_items_t, const char *);

#endif // __CONFIGS_MEADOW_SRC_HCOM_NX_CONFIG_MANAGER__H
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ struct yaml_network_s
*/
char *default_interface;

/**
* @brief Country code for WiFi configuration.
*/
char *country_code;

/**
* @brief Collection of network interfaces.
*/
Expand All @@ -274,6 +279,7 @@ static const cyaml_schema_field_t configuration_network_section_schema[] =
CYAML_FIELD_SEQUENCE("NtpServers", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, yaml_network_t, ntp_servers, &string_ptr_schema, 0, CYAML_UNLIMITED),
CYAML_FIELD_SEQUENCE("DnsServers", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, yaml_network_t, dns_servers, &string_ptr_schema, 0, CYAML_UNLIMITED),
CYAML_FIELD_STRING_PTR("DefaultInterface", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, yaml_network_t, default_interface, 0, CYAML_UNLIMITED),
CYAML_FIELD_STRING_PTR("CountryCode", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, yaml_network_t, country_code, 0, CYAML_UNLIMITED),
CYAML_FIELD_SEQUENCE("Interfaces", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, yaml_network_t, interfaces, &interface_schema_value, 0, CYAML_UNLIMITED),
CYAML_FIELD_END
};
Expand Down
5 changes: 5 additions & 0 deletions nuttx/include/meadow/hcom_shared_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,11 @@ struct meadow_configuration_s
* and returns an error code.
*/
uint32_t maximum_retry_count;

/**
* @brief Country code for the network interface.
*/
char *country_code;
};
typedef struct meadow_configuration_s meadow_configuration_t;

Expand Down
Loading