diff --git a/CMakeLists.txt b/CMakeLists.txt index dbf558ce..89391fa7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) -set(PROJECT_VER "0.6.2") +set(PROJECT_VER "0.6.3") include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(xiaozhi) diff --git a/flash.sh b/flash.sh new file mode 100755 index 00000000..2b4c2098 --- /dev/null +++ b/flash.sh @@ -0,0 +1,2 @@ +#!/bin/sh +esptool.py -p /dev/ttyACM0 -b 2000000 write_flash 0 releases/v0.6.2_ML307/merged-binary.bin diff --git a/main/Application.cc b/main/Application.cc index e8377a80..b75f02ea 100644 --- a/main/Application.cc +++ b/main/Application.cc @@ -70,7 +70,6 @@ Application::~Application() { void Application::CheckNewVersion() { // Check if there is a new firmware version available - firmware_upgrade_.SetBoardJson(Board::GetInstance().GetJson()); firmware_upgrade_.CheckVersion(); if (firmware_upgrade_.HasNewVersion()) { // Wait for the chat state to be idle @@ -196,6 +195,7 @@ void Application::Start() { }, "play_audio", 4096 * 4, this, 4, NULL); board.StartNetwork(); + firmware_upgrade_.SetPostData(board.GetJson()); // Blink the LED to indicate the device is running builtin_led.SetGreen(); builtin_led.BlinkOnce(); @@ -445,6 +445,7 @@ void Application::SetChatState(ChatState state) { BinaryProtocol3* Application::AllocateBinaryProtocol3(const uint8_t* payload, size_t payload_size) { auto protocol = (BinaryProtocol3*)heap_caps_malloc(sizeof(BinaryProtocol3) + payload_size, MALLOC_CAP_SPIRAM); + assert(protocol != nullptr); protocol->type = 0; protocol->reserved = 0; protocol->payload_size = htons(payload_size); diff --git a/main/Board.cc b/main/Board.cc index d0b643ce..42139dff 100644 --- a/main/Board.cc +++ b/main/Board.cc @@ -1,8 +1,104 @@ #include "Board.h" +#include "SystemInfo.h" + #include +#include +#include // static const char *TAG = "Board"; bool Board::GetBatteryVoltage(int &voltage, bool& charging) { return false; } + +std::string Board::GetJson() { + /* + { + "flash_size": 4194304, + "psram_size": 0, + "minimum_free_heap_size": 123456, + "mac_address": "00:00:00:00:00:00", + "chip_model_name": "esp32s3", + "chip_info": { + "model": 1, + "cores": 2, + "revision": 0, + "features": 0 + }, + "application": { + "name": "my-app", + "version": "1.0.0", + "compile_time": "2021-01-01T00:00:00Z" + "idf_version": "4.2-dev" + "elf_sha256": "" + }, + "partition_table": [ + "app": { + "label": "app", + "type": 1, + "subtype": 2, + "address": 0x10000, + "size": 0x100000 + } + ], + "ota": { + "label": "ota_0" + } + } + */ + std::string json = "{"; + json += "\"flash_size\":" + std::to_string(SystemInfo::GetFlashSize()) + ","; + json += "\"minimum_free_heap_size\":" + std::to_string(SystemInfo::GetMinimumFreeHeapSize()) + ","; + json += "\"mac_address\":\"" + SystemInfo::GetMacAddress() + "\","; + json += "\"chip_model_name\":\"" + SystemInfo::GetChipModelName() + "\","; + json += "\"chip_info\":{"; + + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + json += "\"model\":" + std::to_string(chip_info.model) + ","; + json += "\"cores\":" + std::to_string(chip_info.cores) + ","; + json += "\"revision\":" + std::to_string(chip_info.revision) + ","; + json += "\"features\":" + std::to_string(chip_info.features); + json += "},"; + + json += "\"application\":{"; + auto app_desc = esp_app_get_description(); + json += "\"name\":\"" + std::string(app_desc->project_name) + "\","; + json += "\"version\":\"" + std::string(app_desc->version) + "\","; + json += "\"compile_time\":\"" + std::string(app_desc->date) + "T" + std::string(app_desc->time) + "Z\","; + json += "\"idf_version\":\"" + std::string(app_desc->idf_ver) + "\","; + + char sha256_str[65]; + for (int i = 0; i < 32; i++) { + snprintf(sha256_str + i * 2, sizeof(sha256_str) - i * 2, "%02x", app_desc->app_elf_sha256[i]); + } + json += "\"elf_sha256\":\"" + std::string(sha256_str) + "\""; + json += "},"; + + json += "\"partition_table\": ["; + esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL); + while (it) { + const esp_partition_t *partition = esp_partition_get(it); + json += "{"; + json += "\"label\":\"" + std::string(partition->label) + "\","; + json += "\"type\":" + std::to_string(partition->type) + ","; + json += "\"subtype\":" + std::to_string(partition->subtype) + ","; + json += "\"address\":" + std::to_string(partition->address) + ","; + json += "\"size\":" + std::to_string(partition->size); + json += "},"; + it = esp_partition_next(it); + } + json.pop_back(); // Remove the last comma + json += "],"; + + json += "\"ota\":{"; + auto ota_partition = esp_ota_get_running_partition(); + json += "\"label\":\"" + std::string(ota_partition->label) + "\""; + json += "},"; + + json += "\"board\":" + GetBoardJson(); + + // Close the JSON object + json += "}"; + return json; +} diff --git a/main/Board.h b/main/Board.h index 006331b9..197e94db 100644 --- a/main/Board.h +++ b/main/Board.h @@ -27,7 +27,7 @@ public: virtual WebSocket* CreateWebSocket() = 0; virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) = 0; virtual bool GetBatteryVoltage(int &voltage, bool& charging); - virtual std::string GetJson() = 0; + virtual std::string GetJson(); protected: Board() = default; @@ -35,6 +35,7 @@ protected: private: Board(const Board&) = delete; // 禁用拷贝构造函数 Board& operator=(const Board&) = delete; // 禁用赋值操作 + virtual std::string GetBoardJson() = 0; }; #define DECLARE_BOARD(BOARD_CLASS_NAME) \ diff --git a/main/BoxAudioDevice.cc b/main/BoxAudioDevice.cc index 6296c604..5ee4eb38 100644 --- a/main/BoxAudioDevice.cc +++ b/main/BoxAudioDevice.cc @@ -40,7 +40,7 @@ void BoxAudioDevice::Initialize() { .intr_priority = 0, .trans_queue_depth = 0, .flags = { - .enable_internal_pullup = 1, + .enable_internal_pullup = 0, }, }; ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_master_handle_)); diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index b6e0479e..93e435d6 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -64,4 +64,6 @@ idf_component_register(SRCS ${SOURCES} ) # 使用 target_compile_definitions 来定义 BOARD_TYPE -target_compile_definitions(${COMPONENT_LIB} PRIVATE BOARD_TYPE=\"${BOARD_TYPE}\") \ No newline at end of file +target_compile_definitions(${COMPONENT_LIB} + PRIVATE BOARD_TYPE=\"${BOARD_TYPE}\" + ) diff --git a/main/Display.cc b/main/Display.cc index 3137a52b..35904834 100644 --- a/main/Display.cc +++ b/main/Display.cc @@ -27,7 +27,7 @@ Display::Display(int sda_pin, int scl_pin) : sda_pin_(sda_pin), scl_pin_(scl_pin .intr_priority = 0, .trans_queue_depth = 0, .flags = { - .enable_internal_pullup = 1, + .enable_internal_pullup = 0, }, }; diff --git a/main/FirmwareUpgrade.cc b/main/FirmwareUpgrade.cc index 4b29b6bc..396b69cc 100644 --- a/main/FirmwareUpgrade.cc +++ b/main/FirmwareUpgrade.cc @@ -5,11 +5,10 @@ #include #include #include -#include #include #include -#include +#include #include #include #include @@ -31,6 +30,10 @@ void FirmwareUpgrade::SetHeader(const std::string& key, const std::string& value headers_[key] = value; } +void FirmwareUpgrade::SetPostData(const std::string& post_data) { + post_data_ = post_data; +} + void FirmwareUpgrade::CheckVersion() { std::string current_version = esp_app_get_description()->version; ESP_LOGI(TAG, "Current version: %s", current_version.c_str()); @@ -46,8 +49,12 @@ void FirmwareUpgrade::CheckVersion() { } http->SetHeader("Content-Type", "application/json"); - http->SetContent(GetPostData()); - http->Open("POST", check_version_url_); + if (post_data_.length() > 0) { + http->SetContent(post_data_); + http->Open("POST", check_version_url_); + } else { + http->Open("GET", check_version_url_); + } auto response = http->GetBody(); http->Close(); @@ -256,99 +263,3 @@ bool FirmwareUpgrade::IsNewVersionAvailable(const std::string& currentVersion, c return newer.size() > current.size(); } - -void FirmwareUpgrade::SetBoardJson(const std::string& board_json) { - board_json_ = board_json; -} - -std::string FirmwareUpgrade::GetPostData() { - /* - { - "flash_size": 4194304, - "psram_size": 0, - "minimum_free_heap_size": 123456, - "mac_address": "00:00:00:00:00:00", - "chip_model_name": "esp32s3", - "chip_info": { - "model": 1, - "cores": 2, - "revision": 0, - "features": 0 - }, - "application": { - "name": "my-app", - "version": "1.0.0", - "compile_time": "2021-01-01T00:00:00Z" - "idf_version": "4.2-dev" - "elf_sha256": "" - }, - "partition_table": [ - "app": { - "label": "app", - "type": 1, - "subtype": 2, - "address": 0x10000, - "size": 0x100000 - } - ], - "ota": { - "label": "ota_0" - } - } - */ - std::string json = "{"; - json += "\"flash_size\":" + std::to_string(SystemInfo::GetFlashSize()) + ","; - json += "\"minimum_free_heap_size\":" + std::to_string(SystemInfo::GetMinimumFreeHeapSize()) + ","; - json += "\"mac_address\":\"" + SystemInfo::GetMacAddress() + "\","; - json += "\"chip_model_name\":\"" + SystemInfo::GetChipModelName() + "\","; - json += "\"chip_info\":{"; - - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); - json += "\"model\":" + std::to_string(chip_info.model) + ","; - json += "\"cores\":" + std::to_string(chip_info.cores) + ","; - json += "\"revision\":" + std::to_string(chip_info.revision) + ","; - json += "\"features\":" + std::to_string(chip_info.features); - json += "},"; - - json += "\"application\":{"; - auto app_desc = esp_app_get_description(); - json += "\"name\":\"" + std::string(app_desc->project_name) + "\","; - json += "\"version\":\"" + std::string(app_desc->version) + "\","; - json += "\"compile_time\":\"" + std::string(app_desc->date) + "T" + std::string(app_desc->time) + "Z\","; - json += "\"idf_version\":\"" + std::string(app_desc->idf_ver) + "\","; - - char sha256_str[65]; - for (int i = 0; i < 32; i++) { - snprintf(sha256_str + i * 2, sizeof(sha256_str) - i * 2, "%02x", app_desc->app_elf_sha256[i]); - } - json += "\"elf_sha256\":\"" + std::string(sha256_str) + "\""; - json += "},"; - - json += "\"partition_table\": ["; - esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL); - while (it) { - const esp_partition_t *partition = esp_partition_get(it); - json += "{"; - json += "\"label\":\"" + std::string(partition->label) + "\","; - json += "\"type\":" + std::to_string(partition->type) + ","; - json += "\"subtype\":" + std::to_string(partition->subtype) + ","; - json += "\"address\":" + std::to_string(partition->address) + ","; - json += "\"size\":" + std::to_string(partition->size); - json += "},"; - it = esp_partition_next(it); - } - json.pop_back(); // Remove the last comma - json += "],"; - - json += "\"ota\":{"; - auto ota_partition = esp_ota_get_running_partition(); - json += "\"label\":\"" + std::string(ota_partition->label) + "\""; - json += "},"; - - json += "\"board\":" + board_json_; - - // Close the JSON object - json += "}"; - return json; -} diff --git a/main/FirmwareUpgrade.h b/main/FirmwareUpgrade.h index c160830e..1d9487fb 100644 --- a/main/FirmwareUpgrade.h +++ b/main/FirmwareUpgrade.h @@ -10,9 +10,9 @@ public: FirmwareUpgrade(); ~FirmwareUpgrade(); - void SetBoardJson(const std::string& board_json); void SetCheckVersionUrl(std::string check_version_url); void SetHeader(const std::string& key, const std::string& value); + void SetPostData(const std::string& post_data); void CheckVersion(); bool HasNewVersion() { return has_new_version_; } void StartUpgrade(std::function callback); @@ -23,14 +23,13 @@ private: bool has_new_version_ = false; std::string firmware_version_; std::string firmware_url_; - std::string board_json_; + std::string post_data_; std::map headers_; void Upgrade(const std::string& firmware_url); std::function upgrade_callback_; std::vector ParseVersion(const std::string& version); bool IsNewVersionAvailable(const std::string& currentVersion, const std::string& newVersion); - std::string GetPostData(); }; #endif // _FIRMWARE_UPGRADE_H diff --git a/main/Ml307Board.cc b/main/Ml307Board.cc index ea7c9604..5d210668 100644 --- a/main/Ml307Board.cc +++ b/main/Ml307Board.cc @@ -94,7 +94,7 @@ bool Ml307Board::GetNetworkState(std::string& network_name, int& signal_quality, return signal_quality != -1; } -std::string Ml307Board::GetJson() { +std::string Ml307Board::GetBoardJson() { // Set the board type for OTA std::string board_type = BOARD_TYPE; std::string module_name = modem_.GetModuleName(); diff --git a/main/Ml307Board.h b/main/Ml307Board.h index 9b196e08..0ad71983 100644 --- a/main/Ml307Board.h +++ b/main/Ml307Board.h @@ -8,6 +8,7 @@ class Ml307Board : public Board { protected: Ml307AtModem modem_; + virtual std::string GetBoardJson() override; void StartModem(); public: @@ -18,7 +19,6 @@ public: virtual Http* CreateHttp() override; virtual WebSocket* CreateWebSocket() override; virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override; - virtual std::string GetJson() override; }; #endif // ML307_BOARD_H diff --git a/main/WifiBoard.cc b/main/WifiBoard.cc index 5b505e7e..b990c773 100644 --- a/main/WifiBoard.cc +++ b/main/WifiBoard.cc @@ -87,7 +87,7 @@ bool WifiBoard::GetNetworkState(std::string& network_name, int& signal_quality, return signal_quality != -1; } -std::string WifiBoard::GetJson() { +std::string WifiBoard::GetBoardJson() { // Set the board type for OTA auto& wifi_station = WifiStation::GetInstance(); std::string board_type = BOARD_TYPE; diff --git a/main/WifiBoard.h b/main/WifiBoard.h index 7a717931..f6641095 100644 --- a/main/WifiBoard.h +++ b/main/WifiBoard.h @@ -7,13 +7,14 @@ class WifiBoard : public Board { protected: bool wifi_config_mode_ = false; + virtual std::string GetBoardJson() override; + public: virtual void Initialize() override; virtual void StartNetwork() override; virtual Http* CreateHttp() override; virtual WebSocket* CreateWebSocket() override; virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override; - virtual std::string GetJson() override; }; #endif // WIFI_BOARD_H diff --git a/main/boards/kevin-box-1/KevinBoxBoard.cc b/main/boards/kevin-box-1/KevinBoxBoard.cc index ba49e363..127baa52 100644 --- a/main/boards/kevin-box-1/KevinBoxBoard.cc +++ b/main/boards/kevin-box-1/KevinBoxBoard.cc @@ -29,7 +29,7 @@ private: void Enable4GModule() { // Make GPIO15 HIGH to enable the 4G module gpio_config_t ml307_enable_config = { - .pin_bit_mask = (1ULL << 15), + .pin_bit_mask = (1ULL << 15) | (1ULL << 18), .mode = GPIO_MODE_OUTPUT, .pull_up_en = GPIO_PULLUP_DISABLE, .pull_down_en = GPIO_PULLDOWN_DISABLE, @@ -37,6 +37,7 @@ private: }; gpio_config(&ml307_enable_config); gpio_set_level(GPIO_NUM_15, 1); + gpio_set_level(GPIO_NUM_18, 1); } virtual void InitializeADC() { diff --git a/versions.py b/versions.py index e1a9eb00..ff8cd474 100644 --- a/versions.py +++ b/versions.py @@ -60,8 +60,10 @@ def get_board_name(folder): if basename.startswith("v0.3") or basename.startswith("v0.4") or basename.startswith("v0.5") or basename.startswith("v0.6"): if "ML307" in basename: return "bread-compact-ml307" - else: + elif "WiFi" in basename: return "bread-compact-wifi" + elif "KevinBox1" in basename: + return "kevin-box-1" raise Exception(f"Unknown board name: {basename}") def read_binary(dir_path):