Skip to content
Open
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
22 changes: 22 additions & 0 deletions source/sampleapps/wifievents_consumer_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,25 @@ void client_csi_data_json_elem_add(cJSON *sta_obj, wifi_csi_data_t *csi,
json_add_wifi_csi_matrix_info(obj, csi);
}

int get_csi_data_interval(void)
{
if (g_csi_interval) {
return g_csi_interval;
} else {
return DEFAULT_CSI_INTERVAL;
}
}

void add_or_update_number(cJSON *obj, const char *key, double value)
{
cJSON *item = cJSON_GetObjectItem(obj, key);
if (item == NULL) {
cJSON_AddNumberToObject(obj, key, value);
} else {
item->valuedouble = value;
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The add_or_update_number function directly modifies the valuedouble field of a cJSON item. While this works, it's safer to use the standard cJSON API pattern. Consider using cJSON_ReplaceItemInObject to replace the existing item with a new number object, which is the pattern consistently used throughout the codebase (see source/dml/tr_181/sbapi/cosa_wifi_apis.c:1664 and source/platform/common/data_model/wifi_dml_api.c:1815). Alternatively, if using a modern version of cJSON, use cJSON_SetNumberValue. Also note that when directly modifying valuedouble, you should also update valueint for consistency.

Suggested change
item->valuedouble = value;
#ifdef cJSON_SetNumberValue
cJSON_SetNumberValue(item, value);
#else
cJSON *new_item = cJSON_CreateNumber(value);
if (new_item != NULL)
{
cJSON_ReplaceItemInObject(obj, key, new_item);
}
#endif

Copilot uses AI. Check for mistakes.
}
}

void csi_data_in_json_format(mac_address_t sta_mac, wifi_csi_data_t *csi)
{
if (g_num_of_samples == -1) {
Expand All @@ -465,6 +484,9 @@ void csi_data_in_json_format(mac_address_t sta_mac, wifi_csi_data_t *csi)
cJSON_AddItemToObject(p_csi_json_obj->main_json_obj, "CSI", p_csi_json_obj->json_csi_obj);
}

add_or_update_number(p_csi_json_obj->json_csi_obj, "csi_sampling_interval_ms",
get_csi_data_interval());

if (p_csi_json_obj->json_sounding_devices == NULL) {
p_csi_json_obj->json_sounding_devices = cJSON_CreateArray();
VERIFY_NULL_CHECK(p_csi_json_obj->json_sounding_devices);
Expand Down
Loading