Skip to content

Commit 15e6758

Browse files
committed
Refactor and clean up code across multiple modules
- Removed unused function declarations and variables in http_server, bt_gatts, bt_spam, buzzer, id_open, id_open_esp32, odrone_id, spoofer, flash_fs, ieee_sniffer, ledc_controller, nmea_parser, sd_card, thread_broadcast, uart_sender, zigbee_light, and various command modules. - Updated logging macros to use consistent naming conventions in bt_gatts. - Fixed type casting issues for string parameters in various modules to ensure proper handling of character pointers. - Improved memory management by ensuring proper allocation and deallocation of dynamic memory in menus_module and gps modules. - Enhanced readability by adding const qualifiers where appropriate and removing redundant code. - Adjusted function signatures to include unused attribute where necessary to suppress compiler warnings.
1 parent 1f9b72b commit 15e6758

43 files changed

Lines changed: 57 additions & 104 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

firmware/components/OTA/modules/http_server/http_server.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ static esp_err_t http_server_app_js_handler(httpd_req_t* req);
6363
static esp_err_t http_server_favicon_handler(httpd_req_t* req);
6464
static esp_err_t http_server_ota_update_handler(httpd_req_t* req);
6565
static esp_err_t http_server_ota_status_handler(httpd_req_t* req);
66-
static esp_err_t http_server_sensor_value_handler(httpd_req_t* req);
6766
static void http_server_fw_update_reset_timer(void);
6867

6968
// Public Function Definition

firmware/components/bt_gatts/bt_gatts.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ void ble_server_write_event(esp_gatt_if_t gatts_if,
172172
void ble_server_exce_write_event(prepare_type_env_t* prepare_write_env,
173173
esp_ble_gatts_cb_param_t* param) {
174174
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
175-
esp_log_buffer_hex(TAG_BT_GATTS, prepare_write_env->prepare_buf,
175+
ESP_LOG_BUFFER_HEX(TAG_BT_GATTS, prepare_write_env->prepare_buf,
176176
prepare_write_env->prepare_len);
177-
esp_log_buffer_char(TAG_BT_GATTS, param->write.value, param->write.len);
177+
ESP_LOG_BUFFER_CHAR(TAG_BT_GATTS, param->write.value, param->write.len);
178178
} else {
179179
ESP_LOGI(TAG_BT_GATTS, "ESP_GATT_PREP_WRITE_CANCEL");
180180
}
@@ -290,8 +290,8 @@ void ble_server_gatt_profiles_event_handler(esp_gatts_cb_event_t event,
290290
if (!param->write.is_prep) {
291291
ESP_LOGI(TAG_BT_GATTS,
292292
"GATT_WRITE_EVT, value len %d, value :", param->write.len);
293-
esp_log_buffer_hex(TAG_BT_GATTS, param->write.value, param->write.len);
294-
esp_log_buffer_char(TAG_BT_GATTS, param->write.value, param->write.len);
293+
ESP_LOG_BUFFER_HEX(TAG_BT_GATTS, param->write.value, param->write.len);
294+
ESP_LOG_BUFFER_CHAR(TAG_BT_GATTS, param->write.value, param->write.len);
295295

296296
if (ble_server_gatt_profile_tab[DEVICE_PROFILE].descr_handle ==
297297
param->write.handle &&
@@ -319,7 +319,7 @@ void ble_server_gatt_profiles_event_handler(esp_gatts_cb_event_t event,
319319
ESP_LOGI(TAG_BT_GATTS, "notify/indicate disable ");
320320
} else {
321321
ESP_LOGE(TAG_BT_GATTS, "unknown descr value");
322-
esp_log_buffer_hex(TAG_BT_GATTS, param->write.value,
322+
ESP_LOG_BUFFER_HEX(TAG_BT_GATTS, param->write.value,
323323
param->write.len);
324324
}
325325
}
@@ -463,8 +463,8 @@ void ble_server_gatt_profiles_event_handler(esp_gatts_cb_event_t event,
463463
param->conf.status, param->conf.handle);
464464
if (param->conf.status != ESP_GATT_OK) {
465465
ESP_LOGW(TAG_BT_GATTS, "Confirm error, status %d", param->conf.status);
466-
esp_log_buffer_hex(TAG_BT_GATTS, param->conf.value, param->conf.len);
467-
esp_log_buffer_char(TAG_BT_GATTS, param->conf.value, param->conf.len);
466+
ESP_LOG_BUFFER_HEX(TAG_BT_GATTS, param->conf.value, param->conf.len);
467+
ESP_LOG_BUFFER_CHAR(TAG_BT_GATTS, param->conf.value, param->conf.len);
468468
}
469469
break;
470470
}

firmware/components/bt_spam/bt_spam.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
static const char* TAG = "bt_spam";
1010

1111
static bt_spam_cb_display display_records_cb = NULL;
12-
static TimerHandle_t adv_timer;
1312
static volatile bool running_task = false;
1413
static int adv_index = 0;
1514
static TaskHandle_t adv_task_handle = NULL;
@@ -142,7 +141,7 @@ static void start_adv_timer_callback() {
142141

143142
display_records_cb(long_names_devices[adv_index]);
144143
esp_err_t err = esp_ble_gap_config_adv_data_raw(
145-
long_devices_raw[adv_index], sizeof(long_devices_raw[adv_index]));
144+
(uint8_t*) long_devices_raw[adv_index], sizeof(long_devices_raw[adv_index]));
146145
if (err != ESP_OK) {
147146
ESP_LOGE(TAG, "Error setting adv data: %s", esp_err_to_name(err));
148147
return;

firmware/components/buzzer/buzzer.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#define BUZZER_DEFAULT_DUTTY (4096) // Set duty to 50%. (2 ** 13) * 50% = 4096
1313
#define BUZZER_DEFAULT_FREQUENCY_HZ (4000) // Set frequency at 4 kHz
1414

15-
static const char* TAG = "buzzer";
16-
1715
typedef struct {
1816
uint8_t pin;
1917
uint32_t freq;

firmware/components/drone_id/id_open/id_open.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ ID_OpenDrone::ID_OpenDrone() {
172172
void ID_OpenDrone::init(UTM_parameters* parameters, bool ble_drone) {
173173
bt_mode = ble_drone;
174174

175-
int status, i;
175+
int i;
176176
char text[128];
177177

178-
status = 0;
179178
text[0] = text[63] = 0;
180179

181180
#if DIAGNOSTICS
@@ -322,7 +321,6 @@ void ID_OpenDrone::set_auth(char* auth) {
322321

323322
void ID_OpenDrone::set_auth(uint8_t* auth, short int len, uint8_t type) {
324323
int i, j;
325-
char text[160];
326324
uint8_t check[32];
327325

328326
auth_page_count = 1;
@@ -403,14 +401,12 @@ void ID_OpenDrone::set_auth(uint8_t* auth, short int len, uint8_t type) {
403401

404402
int ID_OpenDrone::transmit(struct UTM_data* utm_data) {
405403
int i, status = 0;
406-
char text[128];
407404
time_t secs = 0;
408405
static int phase = 0;
409406

410407
//
411408

412409
i = 0;
413-
text[0] = 0;
414410
msecs = esp_timer_get_time() / 1000;
415411

416412
// For the ODID 2.0 and auth timestamps.
@@ -640,9 +636,6 @@ int ID_OpenDrone::transmit_wifi(struct UTM_data* utm_data, int prepacked) {
640636

641637
int length = 0, wifi_status = 0;
642638
uint64_t usecs = 0;
643-
char text[128];
644-
645-
text[0] = 0;
646639

647640
//
648641

@@ -781,10 +774,8 @@ int ID_OpenDrone::transmit_ble(uint8_t* odid_msg, int length) {
781774
// #if ID_OD_BT
782775

783776
int i, j, k, len, status;
784-
uint8_t* a;
785777

786-
i = j = k = len = 0;
787-
a = ble_message;
778+
i = j = k = len = status = 0;
788779

789780
memset(ble_message, 0, sizeof(ble_message));
790781

firmware/components/drone_id/id_open_esp32/id_open_esp32.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
#if ID_OD_WIFI
6363

6464
#include <esp_event.h>
65-
#include <esp_event_loop.h>
6665
#include <esp_system.h>
6766
#include <esp_wifi.h>
6867
#include <esp_wifi_types.h>
@@ -171,10 +170,8 @@ void init_w(char* ssid,
171170
int ssid_length,
172171
uint8_t* WiFi_mac_addr,
173172
uint8_t wifi_channel) {
174-
int status;
175173
char text[128];
176174

177-
status = 0;
178175
text[0] = text[63] = 0;
179176

180177
#if ID_OD_WIFI

firmware/components/drone_id/odrone_id.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void odrone_id_set_num_spoofers(uint8_t num_drones) {
3232
}
3333

3434
void odrone_id_set_wifi_ap(uint8_t channel) {
35-
set_wifi_ap("Mini Drone", channel);
35+
set_wifi_ap((char*)"Mini Drone", channel);
3636
}
3737

3838
void odrone_id_set_location(float latitude, float longitude) {

firmware/components/drone_id/spoofer/spoofer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void Spoofer::updateLocation(float latitude, float longitude) {
2727
double lat_d = utm_data.latitude_d = utm_data.base_latitude =
2828
latitude + (float) (rand() % 10 - 5) / 10000.0;
2929

30-
double long_d = utm_data.longitude_d = utm_data.base_longitude =
30+
[[maybe_unused]] double long_d = utm_data.longitude_d = utm_data.base_longitude =
3131
longitude + (float) (rand() % 10 - 5) / 10000.0;
3232

3333
utm_data.base_valid = 1;
@@ -79,7 +79,7 @@ void Spoofer::update() {
7979
y += speed_m_y * time_elapsed_secs;
8080

8181
// calculate new height
82-
float climbrate =
82+
[[maybe_unused]] float climbrate =
8383
float(rand() % int(2 * max_climbrate) - max_climbrate) / 1000.0;
8484
z = (z < -max_height) ? -max_height : (z > max_height ? max_height : z);
8585
utm_data.alt_msl_m = utm_data.base_alt_m + z;

firmware/components/flash_fs/flash_fs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
static size_t flash_fs_size, flash_fs_used;
1010

1111
static void (*flash_fs_show_event_cb)(flash_fs_events_t, void*) = NULL;
12-
static bool already_mounted = false;
1312

1413
void flash_fs_begin(void* screens_cb) {
1514
flash_fs_show_event_cb = screens_cb;

firmware/components/ieee_sniffer/ieee_sniffer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static ieee_sniffer_cb_t packet_callback = NULL;
1818
static int current_channel = IEEE_SNIFFER_CHANNEL_DEFAULT;
1919
static bool running = false;
2020

21-
static void debug_print_packet(uint8_t* packet, uint8_t packet_length);
21+
static void debug_print_packet(uint8_t* packet, uint8_t packet_length) __attribute__((unused));
2222
static void debug_handler_task(void* pvParameters);
2323

2424
static char addressing_mode[4][15] = {"None", "Reserved", "Short/16-bit",
@@ -291,7 +291,7 @@ static void debug_print_packet(uint8_t* packet, uint8_t packet_length) {
291291

292292
printf("Data length: %u\n", data_length);
293293
printf("Data: ==================================================\n");
294-
esp_log_buffer_hex(TAG_IEEE_SNIFFER, data, data_length);
294+
ESP_LOG_BUFFER_HEX(TAG_IEEE_SNIFFER, data, data_length);
295295

296296
uint16_t checksum = *((uint16_t*) &packet[position]);
297297

@@ -309,6 +309,6 @@ static void debug_print_packet(uint8_t* packet, uint8_t packet_length) {
309309
break;
310310
}
311311
}
312-
esp_log_buffer_hex(TAG_IEEE_SNIFFER, packet, packet_length);
312+
ESP_LOG_BUFFER_HEX(TAG_IEEE_SNIFFER, packet, packet_length);
313313
printf("-----------------------\n");
314314
}

0 commit comments

Comments
 (0)