diff --git a/firmware/main/ble.hpp b/firmware/main/ble.hpp index 36a884f..3e290a3 100644 --- a/firmware/main/ble.hpp +++ b/firmware/main/ble.hpp @@ -28,6 +28,7 @@ struct BleLocationData { uint32_t timestamp; uint8_t valid; }; +static_assert(sizeof(BleLocationData) == 17, "BleLocationData must be 17 bytes for BLE"); struct BleAlertData { uint8_t alert_type; @@ -37,6 +38,7 @@ struct BleAlertData { int32_t altitude; uint32_t timestamp; }; +static_assert(sizeof(BleAlertData) == 18, "BleAlertData must be 18 bytes for BLE"); #pragma pack(pop) class BleServer { @@ -44,12 +46,12 @@ class BleServer { BleServer (); ~BleServer (); - esp_err_t init (); - esp_err_t start (); - esp_err_t stop (); - esp_err_t update_location (const BleLocationData& location); - esp_err_t send_alert (const BleAlertData& alert); - esp_err_t set_device_name (const char* name); + [[nodiscard]] esp_err_t init (); + [[nodiscard]] esp_err_t start (); + [[nodiscard]] esp_err_t stop (); + [[nodiscard]] esp_err_t update_location (const BleLocationData& location); + [[nodiscard]] esp_err_t send_alert (const BleAlertData& alert); + [[nodiscard]] esp_err_t set_device_name (const char* name); bool is_connected () const; diff --git a/firmware/main/config.hpp b/firmware/main/config.hpp index 9baea98..72897ba 100644 --- a/firmware/main/config.hpp +++ b/firmware/main/config.hpp @@ -42,6 +42,15 @@ class Config { static esp_err_t get_spreading_factor (uint8_t& sf); static esp_err_t set_spreading_factor (uint8_t sf); + /** + * @brief Get device name from NVS + * @param name Buffer to store device name + * @param max_len Maximum buffer size + * @return ESP_OK on success, error code otherwise + * @note If key not found in NVS, returns default name "PetTracker" and ESP_OK. + * Callers who need to distinguish "stored value" vs "default" should use + * nvs_get_str() directly. + */ static esp_err_t get_device_name (char* name, size_t max_len); static esp_err_t set_device_name (const char* name); diff --git a/firmware/main/state_machine.cpp b/firmware/main/state_machine.cpp index 1a21152..0841cc7 100644 --- a/firmware/main/state_machine.cpp +++ b/firmware/main/state_machine.cpp @@ -221,7 +221,7 @@ TrackerStateMachine::check_geofence () { alert.longitude = (int32_t)(data.longitude * COORD_SCALE); alert.altitude = (int32_t)(data.altitude * 100); alert.timestamp = (uint32_t)(esp_timer_get_time () / 1000000); - ble_.send_alert (alert); + ESP_ERROR_CHECK (ble_.send_alert (alert)); break; } }