Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 68766cdbed | |||
| 75178652e2 | |||
| ff3eeacaf7 | |||
| 80bd1c9f20 | |||
| f94cc160cf | |||
| 84cd73e503 | |||
| 6076497997 |
@@ -8,6 +8,7 @@
|
|||||||
#include <tactility/bindings/esp32_spi.h>
|
#include <tactility/bindings/esp32_spi.h>
|
||||||
#include <tactility/bindings/esp32_i2s.h>
|
#include <tactility/bindings/esp32_i2s.h>
|
||||||
#include <tactility/bindings/esp32_uart.h>
|
#include <tactility/bindings/esp32_uart.h>
|
||||||
|
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||||
#include <tactility/bindings/display_placeholder.h>
|
#include <tactility/bindings/display_placeholder.h>
|
||||||
|
|
||||||
/ {
|
/ {
|
||||||
@@ -69,6 +70,11 @@
|
|||||||
pullups;
|
pullups;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
wifi0 {
|
||||||
|
compatible = "espressif,esp32-wifi-pinned";
|
||||||
|
status = "disabled";
|
||||||
|
};
|
||||||
|
|
||||||
uart0 {
|
uart0 {
|
||||||
compatible = "espressif,esp32-uart";
|
compatible = "espressif,esp32-uart";
|
||||||
port = <UART_NUM_0>;
|
port = <UART_NUM_0>;
|
||||||
|
|||||||
@@ -84,5 +84,6 @@ dependencies:
|
|||||||
version: "1.1.4"
|
version: "1.1.4"
|
||||||
rules:
|
rules:
|
||||||
- if: "target in [esp32s3, esp32p4]"
|
- if: "target in [esp32s3, esp32p4]"
|
||||||
|
espressif/mdns: "1.3.2"
|
||||||
idf: '5.5.2'
|
idf: '5.5.2'
|
||||||
|
|
||||||
|
|||||||
@@ -199,12 +199,52 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
|
|||||||
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_set_button_width),
|
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_set_button_width),
|
||||||
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_set_selected_button),
|
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_set_selected_button),
|
||||||
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_clear_button_ctrl),
|
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_clear_button_ctrl),
|
||||||
// lv_canvas
|
// lv_canvas - full API for emulator framebuffer use-cases (GameBoy 160x144)
|
||||||
DEFINE_MODULE_SYMBOL(lv_canvas_create),
|
DEFINE_MODULE_SYMBOL(lv_canvas_create),
|
||||||
DEFINE_MODULE_SYMBOL(lv_canvas_fill_bg),
|
|
||||||
DEFINE_MODULE_SYMBOL(lv_canvas_set_draw_buf),
|
|
||||||
DEFINE_MODULE_SYMBOL(lv_canvas_set_buffer),
|
DEFINE_MODULE_SYMBOL(lv_canvas_set_buffer),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_set_draw_buf),
|
||||||
DEFINE_MODULE_SYMBOL(lv_canvas_set_px),
|
DEFINE_MODULE_SYMBOL(lv_canvas_set_px),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_set_palette),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_get_draw_buf),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_get_px),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_get_image),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_get_buf),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_copy_buf),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_fill_bg),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_init_layer),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_finish_layer),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_canvas_buf_size),
|
||||||
|
// lv_draw_buf - LVGL9 buffers (was lv_img_buf)
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_create),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_destroy),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_init),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_dup),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_copy),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_goto_xy),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_clear),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_width_to_stride),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_align),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_set_palette),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_from_image),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_to_image),
|
||||||
|
// LVGL cache invalidation - critical for raw framebuffer apps (GB emulator) where buffer mutated directly
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_invalidate_cache),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_buf_flush_cache),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_cache_drop),
|
||||||
|
// lv_draw layer helpers
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_layer_create),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_draw_layer_alloc_buf),
|
||||||
|
// lv_image transform/scale - critical for GB 2x/3x scaling (image as canvas)
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_set_scale),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_set_scale_x),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_set_scale_y),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_set_rotation),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_set_pivot),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_set_offset_x),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_image_set_offset_y),
|
||||||
|
// generic obj transform styles (fallback scaling path) - pivot_x/y already exported above, only add scale
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_obj_set_style_transform_scale_x),
|
||||||
|
DEFINE_MODULE_SYMBOL(lv_obj_set_style_transform_scale_y),
|
||||||
// lv_label
|
// lv_label
|
||||||
DEFINE_MODULE_SYMBOL(lv_label_create),
|
DEFINE_MODULE_SYMBOL(lv_label_create),
|
||||||
DEFINE_MODULE_SYMBOL(lv_label_cut_text),
|
DEFINE_MODULE_SYMBOL(lv_label_cut_text),
|
||||||
@@ -431,7 +471,7 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
|
|||||||
DEFINE_MODULE_SYMBOL(lv_draw_task_get_draw_dsc),
|
DEFINE_MODULE_SYMBOL(lv_draw_task_get_draw_dsc),
|
||||||
DEFINE_MODULE_SYMBOL(lv_draw_task_get_label_dsc),
|
DEFINE_MODULE_SYMBOL(lv_draw_task_get_label_dsc),
|
||||||
DEFINE_MODULE_SYMBOL(lv_draw_task_get_fill_dsc),
|
DEFINE_MODULE_SYMBOL(lv_draw_task_get_fill_dsc),
|
||||||
DEFINE_MODULE_SYMBOL(lv_draw_buf_create),
|
// lv_draw_buf_create moved to canvas block (duplicate removed)
|
||||||
// lv_image
|
// lv_image
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_create),
|
DEFINE_MODULE_SYMBOL(lv_image_create),
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_set_src),
|
DEFINE_MODULE_SYMBOL(lv_image_set_src),
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ idf_component_register(
|
|||||||
SRCS ${SOURCES}
|
SRCS ${SOURCES}
|
||||||
INCLUDE_DIRS "include/"
|
INCLUDE_DIRS "include/"
|
||||||
PRIV_INCLUDE_DIRS "private/"
|
PRIV_INCLUDE_DIRS "private/"
|
||||||
REQUIRES TactilityKernel driver esp_adc esp_driver_i2c esp_lcd vfs fatfs esp_wifi esp_netif esp_event
|
REQUIRES TactilityKernel driver esp_adc esp_driver_i2c esp_lcd vfs fatfs esp_wifi esp_netif esp_event mdns
|
||||||
)
|
)
|
||||||
|
|
||||||
if (DEFINED ENV{ESP_IDF_VERSION})
|
if (DEFINED ENV{ESP_IDF_VERSION})
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
#if defined(CONFIG_SOC_WIFI_SUPPORTED) || defined(CONFIG_SLAVE_SOC_WIFI_SUPPORTED)
|
#if defined(CONFIG_SOC_WIFI_SUPPORTED) || defined(CONFIG_SLAVE_SOC_WIFI_SUPPORTED)
|
||||||
|
|
||||||
#include <esp_event.h>
|
#include <esp_event.h>
|
||||||
|
#include <esp_mac.h>
|
||||||
#include <esp_netif.h>
|
#include <esp_netif.h>
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
#include <esp_wifi_default.h>
|
#include <esp_wifi_default.h>
|
||||||
|
#include <mdns.h>
|
||||||
|
|
||||||
#include <tactility/concurrent/mutex.h>
|
#include <tactility/concurrent/mutex.h>
|
||||||
#include <tactility/device.h>
|
#include <tactility/device.h>
|
||||||
@@ -151,6 +153,31 @@ error_t bring_up_wifi(Esp32WifiCtx* ctx) {
|
|||||||
return ERROR_RESOURCE;
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mDNS + hostname: kidsOS-XXXX from MAC, for Bonjour discovery
|
||||||
|
{
|
||||||
|
uint8_t mac[6];
|
||||||
|
char hostname[32];
|
||||||
|
if (esp_wifi_get_mac(WIFI_IF_STA, mac) == ESP_OK) {
|
||||||
|
snprintf(hostname, sizeof(hostname), "kidsOS-%02X%02X", mac[4], mac[5]);
|
||||||
|
} else {
|
||||||
|
strncpy(hostname, "kidsOS", sizeof(hostname));
|
||||||
|
}
|
||||||
|
LOG_I(TAG, "Setting DHCP hostname to '%s'", hostname);
|
||||||
|
esp_netif_set_hostname(ctx->netif, hostname);
|
||||||
|
|
||||||
|
esp_err_t mdns_err = mdns_init();
|
||||||
|
if (mdns_err == ESP_OK) {
|
||||||
|
LOG_I(TAG, "mDNS initialized, hostname '%s.local'", hostname);
|
||||||
|
mdns_hostname_set(hostname);
|
||||||
|
mdns_instance_name_set("kidsOS Tactility Device");
|
||||||
|
mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
|
||||||
|
mdns_service_add(NULL, "_tactility", "_tcp", 6666, NULL, 0);
|
||||||
|
} else {
|
||||||
|
LOG_W(TAG, "mDNS init failed: %s", esp_err_to_name(mdns_err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Warning: this is the memory-intensive operation. It uses over 100kB of
|
// Warning: this is the memory-intensive operation. It uses over 100kB of
|
||||||
// RAM with default settings.
|
// RAM with default settings.
|
||||||
wifi_init_config_t init_config = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t init_config = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
|||||||
vfs
|
vfs
|
||||||
fatfs
|
fatfs
|
||||||
lwip
|
lwip
|
||||||
|
mdns
|
||||||
spi_flash
|
spi_flash
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ struct PairedDevice {
|
|||||||
bool autoConnect = false;
|
bool autoConnect = false;
|
||||||
/** Profile used to pair (BtProfileId value). Defaults to BT_PROFILE_SPP=2. */
|
/** Profile used to pair (BtProfileId value). Defaults to BT_PROFILE_SPP=2. */
|
||||||
int profileId = 2;
|
int profileId = 2;
|
||||||
|
/** BLE address type (0=PUBLIC, 1=RANDOM, etc). Defaults to PUBLIC for backward compat. */
|
||||||
|
uint8_t addrType = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string addrToHex(const std::array<uint8_t, 6>& addr);
|
std::string addrToHex(const std::array<uint8_t, 6>& addr);
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace tt::network::mdns {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A discovered mDNS service instance.
|
||||||
|
* Example: instanceName="kidsOS-AB12", serviceType="_http", proto="_tcp",
|
||||||
|
* hostname="kidsOS-AB12", port=80, addresses=["192.168.1.42"]
|
||||||
|
*/
|
||||||
|
struct Service {
|
||||||
|
std::string instanceName; ///< Instance name (e.g. "ESP32-WebServer")
|
||||||
|
std::string serviceType; ///< Service type (e.g. "_http", "_tactility")
|
||||||
|
std::string proto; ///< Protocol (e.g. "_tcp", "_udp")
|
||||||
|
std::string hostname; ///< Hostname without .local (e.g. "kidsOS-AB12")
|
||||||
|
uint16_t port = 0; ///< Service port
|
||||||
|
std::vector<std::string> addresses; ///< All resolved IP addresses (v4 and v6)
|
||||||
|
std::string primaryAddress; ///< First IPv4 address, or first address if no v4
|
||||||
|
uint32_t ttl = 0; ///< Time to live
|
||||||
|
std::map<std::string, std::string> txtRecords; ///< TXT key-value pairs
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if mDNS subsystem is initialized and ready for queries.
|
||||||
|
* On simulator/POSIX it returns false until a platform implementation is present.
|
||||||
|
*/
|
||||||
|
bool isAvailable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse for mDNS services.
|
||||||
|
*
|
||||||
|
* This wraps `mdns_query_ptr(serviceType, proto, timeout, maxResults, ...)`.
|
||||||
|
* It blocks for up to timeoutMs while collecting results.
|
||||||
|
*
|
||||||
|
* @param serviceType e.g. "_http", "_tactility", "_arduino"
|
||||||
|
* @param proto e.g. "_tcp", "_udp" (include leading underscore)
|
||||||
|
* @param timeoutMs how long to wait for answers (e.g. 3000)
|
||||||
|
* @param maxResults maximum number of results to collect (e.g. 20)
|
||||||
|
* @param outResults filled with discovered services
|
||||||
|
* @return true on success (may still be 0 results), false if mDNS not running or error
|
||||||
|
*/
|
||||||
|
bool browse(const std::string& serviceType, const std::string& proto, uint32_t timeoutMs, size_t maxResults, std::vector<Service>& outResults);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse with sensible defaults: 3s timeout, 20 max results.
|
||||||
|
*/
|
||||||
|
inline bool browse(const std::string& serviceType, const std::string& proto, std::vector<Service>& outResults) {
|
||||||
|
return browse(serviceType, proto, 3000, 20, outResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a hostname (e.g. "kidsOS-AB12" or "kidsOS-AB12.local") to an IPv4 address string.
|
||||||
|
*
|
||||||
|
* @param hostname hostname to resolve, ".local" suffix is optional and stripped
|
||||||
|
* @param timeoutMs time to wait
|
||||||
|
* @param outIp resolved IP (e.g. "192.168.1.42")
|
||||||
|
* @return true if resolved
|
||||||
|
*/
|
||||||
|
bool resolveHostname(const std::string& hostname, uint32_t timeoutMs, std::string& outIp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve with 2s default timeout.
|
||||||
|
*/
|
||||||
|
inline bool resolveHostname(const std::string& hostname, std::string& outIp) {
|
||||||
|
return resolveHostname(hostname, 2000, outIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tt::network::mdns
|
||||||
@@ -14,6 +14,9 @@ bool isValidAppVersionName(const std::string& version);
|
|||||||
bool isValidAppVersionCode(const std::string& version);
|
bool isValidAppVersionCode(const std::string& version);
|
||||||
bool isValidName(const std::string& name);
|
bool isValidName(const std::string& name);
|
||||||
|
|
||||||
|
/** Parses a comma-separated flags string (e.g. "HideStatusBar,Hidden") into appFlags bitmask. */
|
||||||
|
uint16_t parseAppFlagsString(const std::string& raw);
|
||||||
|
|
||||||
/** Parses a V1 (sectioned INI, e.g. "[app]versionName=...") manifest map. */
|
/** Parses a V1 (sectioned INI, e.g. "[app]versionName=...") manifest map. */
|
||||||
bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest& manifest);
|
bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest& manifest);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
namespace tt::app::files { bool isSupportedAppFile(const std::string& filename); bool isSupportedImageFile(const std::string& filename); bool isSupportedTextFile(const std::string& filename); bool isSupportedAudioFile(const std::string& filename); } // namespace
|
namespace tt::app::files {
|
||||||
|
bool isSupportedAppFile(const std::string& filename);
|
||||||
|
bool isSupportedImageFile(const std::string& filename);
|
||||||
|
bool isSupportedTextFile(const std::string& filename);
|
||||||
|
bool isSupportedAudioFile(const std::string& filename);
|
||||||
|
bool isSupportedGameBoyFile(const std::string& filename);
|
||||||
|
} // namespace
|
||||||
|
|||||||
@@ -56,6 +56,34 @@ bool isValidName(const std::string& name) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t parseAppFlagsString(const std::string& raw) {
|
||||||
|
uint16_t flags = AppManifest::Flags::None;
|
||||||
|
if (raw.empty()) {
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto parts = string::split(raw, ",");
|
||||||
|
for (auto& part : parts) {
|
||||||
|
std::string trimmed = string::trim(part, " \t\r\n");
|
||||||
|
if (trimmed.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string lower = string::lowercase(trimmed);
|
||||||
|
|
||||||
|
if (lower == "hidestatusbar" || lower == "hide_statusbar" || lower == "hide-statusbar" || lower == "hide_status_bar") {
|
||||||
|
flags |= AppManifest::Flags::HideStatusBar;
|
||||||
|
} else if (lower == "hidden") {
|
||||||
|
flags |= AppManifest::Flags::Hidden;
|
||||||
|
} else if (lower == "none" || lower == "0" || lower == "") {
|
||||||
|
// keep as none, no additional flag
|
||||||
|
} else {
|
||||||
|
LOG_W(TAG, "Unknown app flag \"%s\" - ignoring", trimmed.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
/** The V1 format's first line is always the literal "[manifest]" section header; V2 files are flat from the first line onward. */
|
/** The V1 format's first line is always the literal "[manifest]" section header; V2 files are flat from the first line onward. */
|
||||||
static bool detectIsV1Format(const std::string& filePath) {
|
static bool detectIsV1Format(const std::string& filePath) {
|
||||||
std::string first_line;
|
std::string first_line;
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional: [app]flags - e.g. "HideStatusBar" or "HideStatusBar,Hidden"
|
||||||
|
auto flags_it = map.find("[app]flags");
|
||||||
|
if (flags_it != map.end()) {
|
||||||
|
manifest.appFlags = parseAppFlagsString(flags_it->second);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ bool parseManifestV2(const std::map<std::string, std::string>& map, AppManifest&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional: app.flags - e.g. "HideStatusBar" or "HideStatusBar,Hidden"
|
||||||
|
auto flags_it = map.find("app.flags");
|
||||||
|
if (flags_it != map.end()) {
|
||||||
|
manifest.appFlags = parseAppFlagsString(flags_it->second);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,24 @@
|
|||||||
#include <Tactility/StringUtils.h>
|
#include <Tactility/StringUtils.h>
|
||||||
#include <Tactility/TactilityCore.h>
|
#include <Tactility/TactilityCore.h>
|
||||||
namespace tt::app::files { constexpr auto* TAG = "Files"; bool isSupportedAppFile(const std::string& filename) { return filename.ends_with(".app"); } bool isSupportedImageFile(const std::string& filename) { return string::lowercase(filename).ends_with(".png"); } bool isSupportedTextFile(const std::string& filename) { std::string l=string::lowercase(filename); return l.ends_with(".txt")||l.ends_with(".ini")||l.ends_with(".json")||l.ends_with(".yaml")||l.ends_with(".yml")||l.ends_with(".lua")||l.ends_with(".js")||l.ends_with(".properties"); } bool isSupportedAudioFile(const std::string& filename) { std::string l=string::lowercase(filename); return l.ends_with(".mp3")||l.ends_with(".wav")||l.ends_with(".ogg")||l.ends_with(".flac"); } } // namespace
|
namespace tt::app::files {
|
||||||
|
constexpr auto* TAG = "Files";
|
||||||
|
bool isSupportedAppFile(const std::string& filename) {
|
||||||
|
return filename.ends_with(".app");
|
||||||
|
}
|
||||||
|
bool isSupportedImageFile(const std::string& filename) {
|
||||||
|
return string::lowercase(filename).ends_with(".png");
|
||||||
|
}
|
||||||
|
bool isSupportedTextFile(const std::string& filename) {
|
||||||
|
std::string l = string::lowercase(filename);
|
||||||
|
return l.ends_with(".txt") || l.ends_with(".ini") || l.ends_with(".json") || l.ends_with(".yaml") || l.ends_with(".yml") ||
|
||||||
|
l.ends_with(".lua") || l.ends_with(".js") || l.ends_with(".properties");
|
||||||
|
}
|
||||||
|
bool isSupportedAudioFile(const std::string& filename) {
|
||||||
|
std::string l = string::lowercase(filename);
|
||||||
|
return l.ends_with(".mp3") || l.ends_with(".wav") || l.ends_with(".ogg") || l.ends_with(".flac");
|
||||||
|
}
|
||||||
|
bool isSupportedGameBoyFile(const std::string& filename) {
|
||||||
|
std::string l = string::lowercase(filename);
|
||||||
|
return l.ends_with(".gb") || l.ends_with(".gbc") || l.ends_with(".sgb");
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|||||||
@@ -239,6 +239,15 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
|||||||
if (loader) {
|
if (loader) {
|
||||||
loader->start("one.tactility.mp3player", bundle);
|
loader->start("one.tactility.mp3player", bundle);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
} else if (isSupportedGameBoyFile(filename)) {
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
auto bundle = std::make_shared<Bundle>();
|
||||||
|
bundle->putString("file", processed_filepath);
|
||||||
|
auto loader = service::loader::findLoaderService();
|
||||||
|
if (loader) {
|
||||||
|
loader->start("one.tactility.gameboy", bundle);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
LOG_W(TAG, "Opening files of this type is not supported");
|
LOG_W(TAG, "Opening files of this type is not supported");
|
||||||
|
|||||||
@@ -115,6 +115,15 @@ static void bt_event_bridge(Device*, void* /*context*/, BtEvent event) {
|
|||||||
case BT_RADIO_STATE_ON:
|
case BT_RADIO_STATE_ON:
|
||||||
getMainDispatcher().dispatch([] {
|
getMainDispatcher().dispatch([] {
|
||||||
auto peers = settings::loadAll();
|
auto peers = settings::loadAll();
|
||||||
|
LOG_I(TAG, "RADIO ON: loaded %d paired peers", (int)peers.size());
|
||||||
|
for (const auto& p : peers) {
|
||||||
|
LOG_I(TAG, " - peer %s name='%s' profile=%d auto=%d type=%d",
|
||||||
|
settings::addrToHex(p.addr).c_str(),
|
||||||
|
p.name.c_str(),
|
||||||
|
p.profileId,
|
||||||
|
(int)p.autoConnect,
|
||||||
|
(int)p.addrType);
|
||||||
|
}
|
||||||
bool has_hid_host_auto = false;
|
bool has_hid_host_auto = false;
|
||||||
bool has_hid_device_auto = false;
|
bool has_hid_device_auto = false;
|
||||||
for (const auto& p : peers) {
|
for (const auto& p : peers) {
|
||||||
@@ -122,17 +131,26 @@ static void bt_event_bridge(Device*, void* /*context*/, BtEvent event) {
|
|||||||
if (p.profileId == BT_PROFILE_HID_HOST) has_hid_host_auto = true;
|
if (p.profileId == BT_PROFILE_HID_HOST) has_hid_host_auto = true;
|
||||||
if (p.profileId == BT_PROFILE_HID_DEVICE) has_hid_device_auto = true;
|
if (p.profileId == BT_PROFILE_HID_DEVICE) has_hid_device_auto = true;
|
||||||
}
|
}
|
||||||
|
LOG_I(TAG, "RADIO ON: has_hid_host_auto=%d has_hid_device_auto=%d spp=%d midi=%d",
|
||||||
|
(int)has_hid_host_auto, (int)has_hid_device_auto,
|
||||||
|
(int)settings::shouldSppAutoStart(), (int)settings::shouldMidiAutoStart());
|
||||||
|
// Start all auto-connect/auto-start roles that are configured.
|
||||||
|
// Scanning (central) and advertising (peripheral) can run concurrently
|
||||||
|
// on ESP32 NimBLE, so we no longer use exclusive else-if.
|
||||||
if (has_hid_host_auto) {
|
if (has_hid_host_auto) {
|
||||||
LOG_I(TAG, "HID host auto-connect peer found — starting scan");
|
LOG_I(TAG, "HID host auto-connect peer found — starting scan");
|
||||||
if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) {
|
if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) {
|
||||||
bluetooth_scan_start(dev);
|
bluetooth_scan_start(dev);
|
||||||
}
|
}
|
||||||
} else if (has_hid_device_auto) {
|
}
|
||||||
|
if (has_hid_device_auto) {
|
||||||
LOG_I(TAG, "HID device auto-start (bonded peer found)");
|
LOG_I(TAG, "HID device auto-start (bonded peer found)");
|
||||||
if (Device* dev = bluetooth_hid_device_get_device()) {
|
if (Device* dev = bluetooth_hid_device_get_device()) {
|
||||||
bluetooth_hid_device_start(dev, BT_HID_DEVICE_MODE_KEYBOARD);
|
bluetooth_hid_device_start(dev, BT_HID_DEVICE_MODE_KEYBOARD);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
// SPP and MIDI are peripheral servers; start them if their global
|
||||||
|
// auto-start flags are set, regardless of HID roles.
|
||||||
if (settings::shouldSppAutoStart()) {
|
if (settings::shouldSppAutoStart()) {
|
||||||
LOG_I(TAG, "Auto-starting SPP server");
|
LOG_I(TAG, "Auto-starting SPP server");
|
||||||
if (Device* dev = bluetooth_serial_get_device()) {
|
if (Device* dev = bluetooth_serial_get_device()) {
|
||||||
@@ -145,7 +163,6 @@ static void bt_event_bridge(Device*, void* /*context*/, BtEvent event) {
|
|||||||
bluetooth_midi_start(dev);
|
bluetooth_midi_start(dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -176,6 +193,9 @@ static void bt_event_bridge(Device*, void* /*context*/, BtEvent event) {
|
|||||||
int profile_copy = event.pair_result.profile;
|
int profile_copy = event.pair_result.profile;
|
||||||
memcpy(addr_buf, event.pair_result.addr, 6);
|
memcpy(addr_buf, event.pair_result.addr, 6);
|
||||||
getMainDispatcher().dispatch([addr_buf, profile_copy]() mutable {
|
getMainDispatcher().dispatch([addr_buf, profile_copy]() mutable {
|
||||||
|
// Ensure Bluetooth auto-enables on boot after successful pairing,
|
||||||
|
// so previously connected devices reconnect after a restart.
|
||||||
|
settings::setEnableOnBoot(true);
|
||||||
std::array<uint8_t, 6> peer_addr;
|
std::array<uint8_t, 6> peer_addr;
|
||||||
memcpy(peer_addr.data(), addr_buf, 6);
|
memcpy(peer_addr.data(), addr_buf, 6);
|
||||||
const auto hex = settings::addrToHex(peer_addr);
|
const auto hex = settings::addrToHex(peer_addr);
|
||||||
@@ -185,6 +205,13 @@ static void bt_event_bridge(Device*, void* /*context*/, BtEvent event) {
|
|||||||
dev.name = "";
|
dev.name = "";
|
||||||
dev.autoConnect = true;
|
dev.autoConnect = true;
|
||||||
dev.profileId = profile_copy;
|
dev.profileId = profile_copy;
|
||||||
|
// Try to preserve addrType from scan cache if available
|
||||||
|
uint8_t cached_type = 0;
|
||||||
|
if (getCachedScanAddrType(peer_addr.data(), &cached_type)) {
|
||||||
|
dev.addrType = cached_type;
|
||||||
|
} else {
|
||||||
|
dev.addrType = 0;
|
||||||
|
}
|
||||||
if (settings::save(dev)) {
|
if (settings::save(dev)) {
|
||||||
LOG_I(TAG, "Saved paired peer %s (profile=%d)", hex.c_str(), profile_copy);
|
LOG_I(TAG, "Saved paired peer %s (profile=%d)", hex.c_str(), profile_copy);
|
||||||
}
|
}
|
||||||
@@ -290,6 +317,11 @@ bool start(Device* dev) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Persist enable-on-boot so that paired devices auto-reconnect after a restart.
|
||||||
|
// The settings file is written from the main task to avoid blocking the NimBLE host
|
||||||
|
// task, but the dispatcher may run immediately, so we also set it here.
|
||||||
|
settings::setEnableOnBoot(true);
|
||||||
|
|
||||||
LOG_I(TAG, "BT enabled");
|
LOG_I(TAG, "BT enabled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -414,6 +446,9 @@ void unpair(const std::array<uint8_t, 6>& addr) {
|
|||||||
|
|
||||||
void connect(const std::array<uint8_t, 6>& addr, int profileId) {
|
void connect(const std::array<uint8_t, 6>& addr, int profileId) {
|
||||||
LOG_I(TAG, "connect(profile=%d)", profileId);
|
LOG_I(TAG, "connect(profile=%d)", profileId);
|
||||||
|
// Ensure BT restarts in the same mode after reboot, so previously connected
|
||||||
|
// devices can be re-found (scan) or reconnected to (advertising).
|
||||||
|
settings::setEnableOnBoot(true);
|
||||||
if (profileId == BT_PROFILE_HID_HOST) {
|
if (profileId == BT_PROFILE_HID_HOST) {
|
||||||
hidHostConnect(addr);
|
hidHostConnect(addr);
|
||||||
} else if (profileId == BT_PROFILE_HID_DEVICE) {
|
} else if (profileId == BT_PROFILE_HID_DEVICE) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <Tactility/bluetooth/Bluetooth.h>
|
#include <Tactility/bluetooth/Bluetooth.h>
|
||||||
#include <Tactility/bluetooth/BluetoothPairedDevice.h>
|
#include <Tactility/bluetooth/BluetoothPairedDevice.h>
|
||||||
#include <Tactility/bluetooth/BluetoothPrivate.h>
|
#include <Tactility/bluetooth/BluetoothPrivate.h>
|
||||||
|
#include <Tactility/bluetooth/BluetoothSettings.h>
|
||||||
|
|
||||||
#include <Tactility/Assets.h>
|
#include <Tactility/Assets.h>
|
||||||
#include <Tactility/Tactility.h>
|
#include <Tactility/Tactility.h>
|
||||||
@@ -480,6 +481,8 @@ static void hidHostSubscribeNext(HidHostCtx& ctx) {
|
|||||||
|
|
||||||
auto peer_addr = ctx.peerAddr;
|
auto peer_addr = ctx.peerAddr;
|
||||||
getMainDispatcher().dispatch([peer_addr] {
|
getMainDispatcher().dispatch([peer_addr] {
|
||||||
|
// Ensure BT stays on after reboot so this keyboard can be re-found.
|
||||||
|
settings::setEnableOnBoot(true);
|
||||||
// Find name from cached scan results
|
// Find name from cached scan results
|
||||||
std::string name;
|
std::string name;
|
||||||
{
|
{
|
||||||
@@ -488,17 +491,34 @@ static void hidHostSubscribeNext(HidHostCtx& ctx) {
|
|||||||
if (r.addr == peer_addr) { name = r.name; break; }
|
if (r.addr == peer_addr) { name = r.name; break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
uint8_t cached_type = 0;
|
||||||
|
bool has_cached_type = getCachedScanAddrType(peer_addr.data(), &cached_type);
|
||||||
settings::PairedDevice device;
|
settings::PairedDevice device;
|
||||||
device.addr = peer_addr;
|
device.addr = peer_addr;
|
||||||
device.profileId = BT_PROFILE_HID_HOST;
|
device.profileId = BT_PROFILE_HID_HOST;
|
||||||
device.autoConnect = true;
|
device.autoConnect = true;
|
||||||
|
device.addrType = has_cached_type ? cached_type : 0;
|
||||||
const auto addr_hex = settings::addrToHex(peer_addr);
|
const auto addr_hex = settings::addrToHex(peer_addr);
|
||||||
|
LOG_I(TAG, "HID host ready: saving device %s name='%s' cached_type=%d has_cached=%d",
|
||||||
|
addr_hex.c_str(), name.c_str(), (int)cached_type, (int)has_cached_type);
|
||||||
settings::PairedDevice existing;
|
settings::PairedDevice existing;
|
||||||
if (settings::load(addr_hex, existing)) {
|
if (settings::load(addr_hex, existing)) {
|
||||||
|
LOG_I(TAG, "Existing file found for %s, preserving autoConnect=%d", addr_hex.c_str(), (int)existing.autoConnect);
|
||||||
device.autoConnect = existing.autoConnect;
|
device.autoConnect = existing.autoConnect;
|
||||||
|
// Preserve existing addrType if we don't have a cached one
|
||||||
|
if (!has_cached_type) {
|
||||||
|
device.addrType = existing.addrType;
|
||||||
|
}
|
||||||
|
// Preserve stored name if scan didn't provide one
|
||||||
|
if (name.empty() && !existing.name.empty()) {
|
||||||
|
name = existing.name;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG_I(TAG, "No existing file for %s, creating new", addr_hex.c_str());
|
||||||
}
|
}
|
||||||
device.name = name;
|
device.name = name;
|
||||||
settings::save(device);
|
bool saved = settings::save(device);
|
||||||
|
LOG_I(TAG, "Save result for %s: %d", addr_hex.c_str(), (int)saved);
|
||||||
if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) {
|
if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) {
|
||||||
BtEvent e = {};
|
BtEvent e = {};
|
||||||
e.type = BT_EVENT_PROFILE_STATE_CHANGED;
|
e.type = BT_EVENT_PROFILE_STATE_CHANGED;
|
||||||
@@ -794,13 +814,22 @@ void hidHostConnect(const std::array<uint8_t, 6>& addr) {
|
|||||||
// Notify driver that a HID host central connection is starting.
|
// Notify driver that a HID host central connection is starting.
|
||||||
if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) bluetooth_set_hid_host_active(dev, true);
|
if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) bluetooth_set_hid_host_active(dev, true);
|
||||||
|
|
||||||
// Look up the addr_type from the cached scan results.
|
// Look up the addr_type from the cached scan results, or from persisted storage.
|
||||||
|
// For RPA devices we may have cached RPA type, but we want to connect using identity.
|
||||||
|
// Prefer cached scan type for direct scan-match, fallback to stored file's addrType.
|
||||||
ble_addr_t ble_addr = {};
|
ble_addr_t ble_addr = {};
|
||||||
ble_addr.type = BLE_ADDR_PUBLIC;
|
ble_addr.type = BLE_ADDR_PUBLIC;
|
||||||
std::memcpy(ble_addr.val, addr.data(), 6);
|
std::memcpy(ble_addr.val, addr.data(), 6);
|
||||||
uint8_t addr_type = 0;
|
uint8_t addr_type = 0;
|
||||||
if (getCachedScanAddrType(addr.data(), &addr_type)) {
|
if (getCachedScanAddrType(addr.data(), &addr_type)) {
|
||||||
ble_addr.type = addr_type;
|
ble_addr.type = addr_type;
|
||||||
|
} else {
|
||||||
|
// Try persisted addrType if available
|
||||||
|
const auto hex = settings::addrToHex(addr);
|
||||||
|
settings::PairedDevice stored;
|
||||||
|
if (settings::load(hex, stored)) {
|
||||||
|
ble_addr.type = stored.addrType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t own_addr_type;
|
uint8_t own_addr_type;
|
||||||
@@ -847,34 +876,58 @@ bool hidHostGetConnectedPeer(std::array<uint8_t, 6>& addr_out) {
|
|||||||
void autoConnectHidHost() {
|
void autoConnectHidHost() {
|
||||||
if (hidHostIsConnected()) return;
|
if (hidHostIsConnected()) return;
|
||||||
|
|
||||||
// Connect to the first saved HID host peer that appeared in the last scan.
|
// Gather all stored peers that want auto-connect as HID host (central).
|
||||||
// cacheScanAddr() is populated during scanning so addr_type is available for ble_gap_connect.
|
auto all_peers = settings::loadAll();
|
||||||
|
std::vector<settings::PairedDevice> auto_peers;
|
||||||
|
for (const auto& p : all_peers) {
|
||||||
|
if (p.autoConnect && p.profileId == BT_PROFILE_HID_HOST) {
|
||||||
|
auto_peers.push_back(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (auto_peers.empty()) return;
|
||||||
|
|
||||||
auto scan = getScanResults();
|
auto scan = getScanResults();
|
||||||
|
|
||||||
|
// 1. Direct address match (public address devices, most keyboards).
|
||||||
|
// cacheScanAddr() is populated during scanning so addr_type is available for ble_gap_connect.
|
||||||
for (const auto& r : scan) {
|
for (const auto& r : scan) {
|
||||||
settings::PairedDevice stored;
|
settings::PairedDevice stored;
|
||||||
if (settings::load(settings::addrToHex(r.addr), stored) &&
|
if (settings::load(settings::addrToHex(r.addr), stored) &&
|
||||||
stored.autoConnect &&
|
stored.autoConnect &&
|
||||||
stored.profileId == BT_PROFILE_HID_HOST) {
|
stored.profileId == BT_PROFILE_HID_HOST) {
|
||||||
LOG_I(TAG, "Auto-connecting HID host to %s", settings::addrToHex(r.addr).c_str());
|
LOG_I(TAG, "Auto-connecting HID host to %s (direct match)", settings::addrToHex(r.addr).c_str());
|
||||||
hidHostConnect(r.addr);
|
hidHostConnect(r.addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device not in the last scan. If we have an autoConnect HID host peer, restart
|
// 2. RPA / name fallback: some peripherals use Resolvable Private Addresses.
|
||||||
// scanning so we keep checking until the device powers back on.
|
// Their advertised address (RPA) does not equal the stored identity address,
|
||||||
auto peers = settings::loadAll();
|
// so hex-lookup fails. If we see a scan result whose name matches a stored
|
||||||
for (const auto& peer : peers) {
|
// auto-connect peer, attempt a direct connection to the stored identity address.
|
||||||
if (peer.autoConnect && peer.profileId == BT_PROFILE_HID_HOST) {
|
// The controller's resolving list (populated from NVS IRK) will resolve the RPA.
|
||||||
if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) {
|
for (const auto& r : scan) {
|
||||||
if (!bluetooth_is_scanning(dev)) {
|
if (r.name.empty()) continue;
|
||||||
LOG_I(TAG, "Auto-connect HID host: device not in scan, retrying scan");
|
for (const auto& stored : auto_peers) {
|
||||||
bluetooth_scan_start(dev);
|
if (!stored.name.empty() && stored.name == r.name) {
|
||||||
|
LOG_I(TAG, "Auto-connecting HID host to %s via name match '%s' (RPA handling: scan=%s stored=%s)",
|
||||||
|
settings::addrToHex(stored.addr).c_str(),
|
||||||
|
r.name.c_str(),
|
||||||
|
settings::addrToHex(r.addr).c_str(),
|
||||||
|
settings::addrToHex(stored.addr).c_str());
|
||||||
|
hidHostConnect(stored.addr);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Direct connect fallback: if device not in scan (or uses RPA without name in adv),
|
||||||
|
// try to connect directly to the first stored auto peer. ble_gap_connect() will
|
||||||
|
// internally scan and use the resolving list to match RPA to identity.
|
||||||
|
// This also covers the case where the keyboard is powered off and later on.
|
||||||
|
LOG_I(TAG, "Auto-connect HID host: %d auto peer(s) not in scan, trying direct connect to %s",
|
||||||
|
(int)auto_peers.size(), settings::addrToHex(auto_peers[0].addr).c_str());
|
||||||
|
hidHostConnect(auto_peers[0].addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tt::bluetooth
|
} // namespace tt::bluetooth
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ constexpr auto* KEY_NAME = "name";
|
|||||||
constexpr auto* KEY_ADDR = "addr";
|
constexpr auto* KEY_ADDR = "addr";
|
||||||
constexpr auto* KEY_AUTO_CONNECT = "autoConnect";
|
constexpr auto* KEY_AUTO_CONNECT = "autoConnect";
|
||||||
constexpr auto* KEY_PROFILE_ID = "profileId";
|
constexpr auto* KEY_PROFILE_ID = "profileId";
|
||||||
|
constexpr auto* KEY_ADDR_TYPE = "addrType";
|
||||||
|
|
||||||
static std::string getSettingsFilePath() {
|
static std::string getSettingsFilePath() {
|
||||||
return getUserDataPath() + "/service/bluetooth";
|
return getUserDataPath() + "/service/bluetooth";
|
||||||
@@ -78,8 +79,23 @@ bool load(const std::string& addr_hex, PairedDevice& device) {
|
|||||||
device.autoConnect = !map.contains(KEY_AUTO_CONNECT) || (map[KEY_AUTO_CONNECT] == "true");
|
device.autoConnect = !map.contains(KEY_AUTO_CONNECT) || (map[KEY_AUTO_CONNECT] == "true");
|
||||||
|
|
||||||
if (map.contains(KEY_PROFILE_ID)) {
|
if (map.contains(KEY_PROFILE_ID)) {
|
||||||
// TODO: Handle incorrect parsing input
|
char* endPtr = nullptr;
|
||||||
device.profileId = std::stoi(map[KEY_PROFILE_ID]);
|
long val = std::strtol(map[KEY_PROFILE_ID].c_str(), &endPtr, 10);
|
||||||
|
if (endPtr != map[KEY_PROFILE_ID].c_str()) {
|
||||||
|
device.profileId = static_cast<int>(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.contains(KEY_ADDR_TYPE)) {
|
||||||
|
char* endPtr = nullptr;
|
||||||
|
long val = std::strtol(map[KEY_ADDR_TYPE].c_str(), &endPtr, 10);
|
||||||
|
if (endPtr != map[KEY_ADDR_TYPE].c_str() && val >= 0 && val <= 255) {
|
||||||
|
device.addrType = static_cast<uint8_t>(val);
|
||||||
|
} else {
|
||||||
|
device.addrType = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
device.addrType = 0; // backward compat: assume PUBLIC
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -91,12 +107,17 @@ bool save(const PairedDevice& device) {
|
|||||||
map[KEY_ADDR] = addr_hex;
|
map[KEY_ADDR] = addr_hex;
|
||||||
map[KEY_AUTO_CONNECT] = device.autoConnect ? "true" : "false";
|
map[KEY_AUTO_CONNECT] = device.autoConnect ? "true" : "false";
|
||||||
map[KEY_PROFILE_ID] = std::to_string(device.profileId);
|
map[KEY_PROFILE_ID] = std::to_string(device.profileId);
|
||||||
|
map[KEY_ADDR_TYPE] = std::to_string(device.addrType);
|
||||||
auto file_path = getFilePath(addr_hex);
|
auto file_path = getFilePath(addr_hex);
|
||||||
|
LOG_I(TAG, "Saving device file %s profile=%d auto=%d type=%d",
|
||||||
|
file_path.c_str(), device.profileId, (int)device.autoConnect, (int)device.addrType);
|
||||||
if (!file::findOrCreateParentDirectory(file_path, 0755)) {
|
if (!file::findOrCreateParentDirectory(file_path, 0755)) {
|
||||||
LOG_E(TAG, "Failed to create parent dir for %s", file_path.c_str());
|
LOG_E(TAG, "Failed to create parent dir for %s", file_path.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return file::savePropertiesFile(file_path, map);
|
bool result = file::savePropertiesFile(file_path, map);
|
||||||
|
LOG_I(TAG, "SavePropertiesFile result for %s: %d", file_path.c_str(), (int)result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool remove(const std::string& addr_hex) {
|
bool remove(const std::string& addr_hex) {
|
||||||
@@ -108,6 +129,7 @@ bool remove(const std::string& addr_hex) {
|
|||||||
std::vector<PairedDevice> loadAll() {
|
std::vector<PairedDevice> loadAll() {
|
||||||
std::vector<dirent> entries;
|
std::vector<dirent> entries;
|
||||||
if (!file::isDirectory(getSettingsFilePath())) {
|
if (!file::isDirectory(getSettingsFilePath())) {
|
||||||
|
LOG_I(TAG, "loadAll: directory %s does not exist", getSettingsFilePath().c_str());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
file::scandir(getSettingsFilePath(), entries, [](const dirent* entry) -> int {
|
file::scandir(getSettingsFilePath(), entries, [](const dirent* entry) -> int {
|
||||||
@@ -116,6 +138,7 @@ std::vector<PairedDevice> loadAll() {
|
|||||||
return name.ends_with(".device.properties") ? 0 : -1;
|
return name.ends_with(".device.properties") ? 0 : -1;
|
||||||
}, nullptr);
|
}, nullptr);
|
||||||
|
|
||||||
|
LOG_I(TAG, "loadAll: found %d entries in %s", (int)entries.size(), getSettingsFilePath().c_str());
|
||||||
std::vector<PairedDevice> result;
|
std::vector<PairedDevice> result;
|
||||||
result.reserve(entries.size());
|
result.reserve(entries.size());
|
||||||
for (const auto& entry : entries) {
|
for (const auto& entry : entries) {
|
||||||
@@ -126,6 +149,8 @@ std::vector<PairedDevice> loadAll() {
|
|||||||
PairedDevice device;
|
PairedDevice device;
|
||||||
if (load(addr_hex, device)) {
|
if (load(addr_hex, device)) {
|
||||||
result.push_back(std::move(device));
|
result.push_back(std::move(device));
|
||||||
|
} else {
|
||||||
|
LOG_W(TAG, "loadAll: failed to load %s", filename.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -0,0 +1,172 @@
|
|||||||
|
#include <Tactility/network/Mdns.h>
|
||||||
|
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
|
||||||
|
#include <tactility/log.h>
|
||||||
|
#include <esp_wifi.h>
|
||||||
|
#include <esp_netif.h>
|
||||||
|
#include <lwip/ip4_addr.h>
|
||||||
|
#if CONFIG_LWIP_IPV6
|
||||||
|
#include <lwip/ip6_addr.h>
|
||||||
|
#endif
|
||||||
|
#include <mdns.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace tt::network::mdns {
|
||||||
|
|
||||||
|
constexpr auto* TAG = "Mdns";
|
||||||
|
|
||||||
|
static std::string ipAddrToString(const esp_ip_addr_t& ip) {
|
||||||
|
char buf[64];
|
||||||
|
if (ip.type == ESP_IPADDR_TYPE_V4) {
|
||||||
|
esp_ip4addr_ntoa(&ip.u_addr.ip4, buf, sizeof(buf));
|
||||||
|
} else {
|
||||||
|
#if CONFIG_LWIP_IPV6
|
||||||
|
ip6addr_ntoa_r(reinterpret_cast<const ip6_addr_t*>(&ip.u_addr.ip6), buf, sizeof(buf));
|
||||||
|
#else
|
||||||
|
snprintf(buf, sizeof(buf), "IPv6(not enabled)");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return std::string(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string normalizeHostname(std::string host) {
|
||||||
|
const std::string suffix = ".local";
|
||||||
|
if (host.size() > suffix.size() && host.compare(host.size() - suffix.size(), suffix.size(), suffix) == 0) {
|
||||||
|
host.erase(host.size() - suffix.size());
|
||||||
|
}
|
||||||
|
if (!host.empty() && host.back() == '.') {
|
||||||
|
host.pop_back();
|
||||||
|
}
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isAvailable() {
|
||||||
|
char buf[64];
|
||||||
|
return mdns_hostname_get(buf) == ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Service convertResult(const mdns_result_t* r) {
|
||||||
|
Service s;
|
||||||
|
if (r->instance_name) s.instanceName = r->instance_name;
|
||||||
|
if (r->service_type) s.serviceType = r->service_type;
|
||||||
|
if (r->proto) s.proto = r->proto;
|
||||||
|
if (r->hostname) s.hostname = r->hostname;
|
||||||
|
s.port = r->port;
|
||||||
|
s.ttl = r->ttl;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < r->txt_count; i++) {
|
||||||
|
if (r->txt[i].key) {
|
||||||
|
std::string key = r->txt[i].key;
|
||||||
|
std::string value;
|
||||||
|
if (r->txt[i].value && r->txt_value_len) {
|
||||||
|
value = std::string(r->txt[i].value, r->txt_value_len[i]);
|
||||||
|
} else if (r->txt[i].value) {
|
||||||
|
value = r->txt[i].value;
|
||||||
|
}
|
||||||
|
s.txtRecords[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string firstV4;
|
||||||
|
for (mdns_ip_addr_t* a = r->addr; a != nullptr; a = a->next) {
|
||||||
|
std::string ipStr = ipAddrToString(a->addr);
|
||||||
|
if (!ipStr.empty()) {
|
||||||
|
s.addresses.push_back(ipStr);
|
||||||
|
if (firstV4.empty() && a->addr.type == ESP_IPADDR_TYPE_V4) {
|
||||||
|
firstV4 = ipStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!firstV4.empty()) {
|
||||||
|
s.primaryAddress = firstV4;
|
||||||
|
} else if (!s.addresses.empty()) {
|
||||||
|
s.primaryAddress = s.addresses.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool browse(const std::string& serviceType, const std::string& proto, uint32_t timeoutMs, size_t maxResults, std::vector<Service>& outResults) {
|
||||||
|
if (serviceType.empty() || proto.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
outResults.clear();
|
||||||
|
|
||||||
|
mdns_result_t* results = nullptr;
|
||||||
|
esp_err_t err = mdns_query_ptr(serviceType.c_str(), proto.c_str(), timeoutMs, maxResults, &results);
|
||||||
|
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
if (err == ESP_ERR_INVALID_STATE) {
|
||||||
|
LOG_W(TAG, "browse: mDNS not running");
|
||||||
|
} else {
|
||||||
|
LOG_W(TAG, "browse %s.%s failed: %s", serviceType.c_str(), proto.c_str(), esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (mdns_result_t* r = results; r != nullptr; r = r->next) {
|
||||||
|
outResults.push_back(convertResult(r));
|
||||||
|
}
|
||||||
|
|
||||||
|
mdns_query_results_free(results);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool resolveHostname(const std::string& hostname, uint32_t timeoutMs, std::string& outIp) {
|
||||||
|
std::string normalized = normalizeHostname(hostname);
|
||||||
|
if (normalized.empty()) return false;
|
||||||
|
|
||||||
|
outIp.clear();
|
||||||
|
|
||||||
|
esp_ip4_addr_t addr;
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
|
||||||
|
esp_err_t err = mdns_query_a(normalized.c_str(), timeoutMs, &addr);
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
char buf[32];
|
||||||
|
esp_ip4addr_ntoa(&addr, buf, sizeof(buf));
|
||||||
|
outIp = buf;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if CONFIG_LWIP_IPV6
|
||||||
|
esp_ip6_addr_t addr6;
|
||||||
|
memset(&addr6, 0, sizeof(addr6));
|
||||||
|
err = mdns_query_aaaa(normalized.c_str(), timeoutMs, &addr6);
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
char buf[64];
|
||||||
|
ip6addr_ntoa_r(reinterpret_cast<const ip6_addr_t*>(&addr6), buf, sizeof(buf));
|
||||||
|
outIp = buf;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tt::network::mdns
|
||||||
|
|
||||||
|
#else // !ESP_PLATFORM — POSIX simulator stub
|
||||||
|
|
||||||
|
namespace tt::network::mdns {
|
||||||
|
|
||||||
|
bool isAvailable() { return false; }
|
||||||
|
|
||||||
|
bool browse(const std::string& serviceType, const std::string& proto, uint32_t timeoutMs, size_t maxResults, std::vector<Service>& outResults) {
|
||||||
|
(void)serviceType; (void)proto; (void)timeoutMs; (void)maxResults;
|
||||||
|
outResults.clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool resolveHostname(const std::string& hostname, uint32_t timeoutMs, std::string& outIp) {
|
||||||
|
(void)hostname; (void)timeoutMs;
|
||||||
|
outIp.clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tt::network::mdns
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -46,6 +46,8 @@
|
|||||||
#include <esp_system.h>
|
#include <esp_system.h>
|
||||||
#include <esp_vfs_fat.h>
|
#include <esp_vfs_fat.h>
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
|
#include <mdns.h>
|
||||||
|
#include <esp_mac.h>
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -392,6 +394,27 @@ bool WebServerService::startApMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_I(TAG, "WiFi AP started - SSID: '%s', Channel: %u, IP: 192.168.4.1", settings.apSsid.c_str(), (unsigned)settings.apChannel);
|
LOG_I(TAG, "WiFi AP started - SSID: '%s', Channel: %u, IP: 192.168.4.1", settings.apSsid.c_str(), (unsigned)settings.apChannel);
|
||||||
|
|
||||||
|
// mDNS for AP mode too - kidsOS-XXXX.local
|
||||||
|
{
|
||||||
|
uint8_t mac[6];
|
||||||
|
char hostname[32];
|
||||||
|
if (esp_wifi_get_mac(WIFI_IF_AP, mac) == ESP_OK) {
|
||||||
|
snprintf(hostname, sizeof(hostname), "kidsOS-%02X%02X", mac[4], mac[5]);
|
||||||
|
} else {
|
||||||
|
strncpy(hostname, "kidsOS", sizeof(hostname));
|
||||||
|
}
|
||||||
|
esp_netif_set_hostname(apNetif, hostname);
|
||||||
|
esp_err_t mdns_err = mdns_init();
|
||||||
|
if (mdns_err == ESP_OK) {
|
||||||
|
LOG_I(TAG, "mDNS AP initialized, hostname '%s.local'", hostname);
|
||||||
|
mdns_hostname_set(hostname);
|
||||||
|
mdns_instance_name_set("kidsOS Tactility Device");
|
||||||
|
mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
|
||||||
|
mdns_service_add(NULL, "_tactility", "_tcp", 6666, NULL, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TactilityC mDNS bindings — usable from external ELF apps.
|
||||||
|
*
|
||||||
|
* Provides synchronous mDNS browsing (PTR queries) and hostname resolution
|
||||||
|
* on top of the ESP-IDF mdns component. The API is intentionally C-only,
|
||||||
|
* string-copy based, to avoid complex lifetime issues across ELF boundaries.
|
||||||
|
*
|
||||||
|
* Implementation lives in Tactility (tt::network::mdns) and is exported via
|
||||||
|
* module symbols. TactilityC provides thin wrappers + symbol export.
|
||||||
|
*
|
||||||
|
* WiFi must be connected for mDNS queries to return results.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TT_MDNS_MAX_RESULTS 32
|
||||||
|
#define TT_MDNS_MAX_ADDRESSES 4
|
||||||
|
#define TT_MDNS_MAX_TXT_RECORDS 8
|
||||||
|
|
||||||
|
#define TT_MDNS_HOSTNAME_LEN 64
|
||||||
|
#define TT_MDNS_INSTANCE_LEN 64
|
||||||
|
#define TT_MDNS_SERVICE_TYPE_LEN 32
|
||||||
|
#define TT_MDNS_PROTO_LEN 16
|
||||||
|
#define TT_MDNS_IP_LEN 64
|
||||||
|
#define TT_MDNS_TXT_KEY_LEN 32
|
||||||
|
#define TT_MDNS_TXT_VALUE_LEN 64
|
||||||
|
|
||||||
|
/** One TXT key-value pair */
|
||||||
|
typedef struct {
|
||||||
|
char key[TT_MDNS_TXT_KEY_LEN];
|
||||||
|
char value[TT_MDNS_TXT_VALUE_LEN];
|
||||||
|
} TtMdnsTxtRecord;
|
||||||
|
|
||||||
|
/** One discovered service (copy-based, no pointers into mdns_result_t). */
|
||||||
|
typedef struct {
|
||||||
|
char instanceName[TT_MDNS_INSTANCE_LEN]; ///< e.g. "kidsOS-AB12"
|
||||||
|
char serviceType[TT_MDNS_SERVICE_TYPE_LEN];///< e.g. "_http"
|
||||||
|
char proto[TT_MDNS_PROTO_LEN]; ///< e.g. "_tcp"
|
||||||
|
char hostname[TT_MDNS_HOSTNAME_LEN]; ///< without .local
|
||||||
|
uint16_t port; ///< service port
|
||||||
|
char addresses[TT_MDNS_MAX_ADDRESSES][TT_MDNS_IP_LEN]; ///< resolved IPs
|
||||||
|
uint8_t addressCount;
|
||||||
|
char primaryAddress[TT_MDNS_IP_LEN]; ///< first IPv4 or first address
|
||||||
|
uint32_t ttl;
|
||||||
|
TtMdnsTxtRecord txtRecords[TT_MDNS_MAX_TXT_RECORDS];
|
||||||
|
uint8_t txtCount;
|
||||||
|
} TtMdnsService;
|
||||||
|
|
||||||
|
/** Result set returned by browse. */
|
||||||
|
typedef struct {
|
||||||
|
TtMdnsService services[TT_MDNS_MAX_RESULTS];
|
||||||
|
uint8_t count;
|
||||||
|
} TtMdnsBrowseResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if mDNS is initialized and running.
|
||||||
|
*/
|
||||||
|
bool tt_mdns_is_available();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse for mDNS service instances.
|
||||||
|
*
|
||||||
|
* Blocks for up to timeoutMs.
|
||||||
|
*
|
||||||
|
* @param serviceType e.g. "_http", "_tactility" (with or without leading underscore both accepted, but conventional is with)
|
||||||
|
* @param proto e.g. "_tcp", "_udp"
|
||||||
|
* @param timeoutMs how long to wait (e.g. 3000ms). 0 = use default 3000ms.
|
||||||
|
* @param maxResults clamp to TT_MDNS_MAX_RESULTS. 0 = default 20.
|
||||||
|
* @param outResult filled with 0..maxResults services. Caller provides storage.
|
||||||
|
* @return true on successful query (even 0 results is success). false if mDNS not running.
|
||||||
|
*/
|
||||||
|
bool tt_mdns_browse(const char* serviceType, const char* proto, uint32_t timeoutMs, size_t maxResults, TtMdnsBrowseResult* outResult);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a hostname like "kidsOS-AB12" or "kidsOS-AB12.local" to an IPv4 address string.
|
||||||
|
*
|
||||||
|
* @param hostname hostname (".local" suffix optional)
|
||||||
|
* @param timeoutMs wait time, 0 = 2000ms default
|
||||||
|
* @param outIp buffer of at least TT_MDNS_IP_LEN, filled with IP string e.g. "192.168.1.42"
|
||||||
|
* @return true if resolved.
|
||||||
|
*/
|
||||||
|
bool tt_mdns_resolve_hostname(const char* hostname, uint32_t timeoutMs, char* outIp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "tt_hal_display.h"
|
#include "tt_hal_display.h"
|
||||||
#include "tt_hal_touch.h"
|
#include "tt_hal_touch.h"
|
||||||
#include "tt_hal_uart.h"
|
#include "tt_hal_uart.h"
|
||||||
|
#include "tt_mdns.h"
|
||||||
#include <tt_lock.h>
|
#include <tt_lock.h>
|
||||||
#include "tt_lvgl.h"
|
#include "tt_lvgl.h"
|
||||||
#include "tt_lvgl_keyboard.h"
|
#include "tt_lvgl_keyboard.h"
|
||||||
@@ -361,6 +362,10 @@ const esp_elfsym main_symbols[] {
|
|||||||
ESP_ELFSYM_EXPORT(tt_timezone_set_format_24_hour),
|
ESP_ELFSYM_EXPORT(tt_timezone_set_format_24_hour),
|
||||||
// tt::lvgl
|
// tt::lvgl
|
||||||
ESP_ELFSYM_EXPORT(tt_lvgl_spinner_create),
|
ESP_ELFSYM_EXPORT(tt_lvgl_spinner_create),
|
||||||
|
// mDNS
|
||||||
|
ESP_ELFSYM_EXPORT(tt_mdns_is_available),
|
||||||
|
ESP_ELFSYM_EXPORT(tt_mdns_browse),
|
||||||
|
ESP_ELFSYM_EXPORT(tt_mdns_resolve_hostname),
|
||||||
|
|
||||||
// stdio.h
|
// stdio.h
|
||||||
ESP_ELFSYM_EXPORT(rename),
|
ESP_ELFSYM_EXPORT(rename),
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#include "tt_mdns.h"
|
||||||
|
|
||||||
|
#include <Tactility/network/Mdns.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
bool tt_mdns_is_available() {
|
||||||
|
return tt::network::mdns::isAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tt_mdns_browse(const char* serviceType, const char* proto, uint32_t timeoutMs, size_t maxResults, TtMdnsBrowseResult* outResult) {
|
||||||
|
if (outResult == nullptr) return false;
|
||||||
|
if (serviceType == nullptr || proto == nullptr) return false;
|
||||||
|
|
||||||
|
memset(outResult, 0, sizeof(TtMdnsBrowseResult));
|
||||||
|
|
||||||
|
uint32_t effectiveTimeout = timeoutMs == 0 ? 3000 : timeoutMs;
|
||||||
|
size_t effectiveMax = maxResults == 0 ? 20 : maxResults;
|
||||||
|
effectiveMax = std::min<size_t>(effectiveMax, TT_MDNS_MAX_RESULTS);
|
||||||
|
|
||||||
|
std::vector<tt::network::mdns::Service> services;
|
||||||
|
if (!tt::network::mdns::browse(serviceType, proto, effectiveTimeout, effectiveMax, services)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t toCopy = std::min(services.size(), static_cast<size_t>(TT_MDNS_MAX_RESULTS));
|
||||||
|
for (size_t i = 0; i < toCopy; i++) {
|
||||||
|
const auto& src = services[i];
|
||||||
|
auto& dst = outResult->services[i];
|
||||||
|
|
||||||
|
strncpy(dst.instanceName, src.instanceName.c_str(), TT_MDNS_INSTANCE_LEN - 1);
|
||||||
|
strncpy(dst.serviceType, src.serviceType.c_str(), TT_MDNS_SERVICE_TYPE_LEN - 1);
|
||||||
|
strncpy(dst.proto, src.proto.c_str(), TT_MDNS_PROTO_LEN - 1);
|
||||||
|
strncpy(dst.hostname, src.hostname.c_str(), TT_MDNS_HOSTNAME_LEN - 1);
|
||||||
|
dst.port = src.port;
|
||||||
|
dst.ttl = src.ttl;
|
||||||
|
strncpy(dst.primaryAddress, src.primaryAddress.c_str(), TT_MDNS_IP_LEN - 1);
|
||||||
|
|
||||||
|
size_t addrCount = std::min(src.addresses.size(), static_cast<size_t>(TT_MDNS_MAX_ADDRESSES));
|
||||||
|
dst.addressCount = static_cast<uint8_t>(addrCount);
|
||||||
|
for (size_t a = 0; a < addrCount; a++) {
|
||||||
|
strncpy(dst.addresses[a], src.addresses[a].c_str(), TT_MDNS_IP_LEN - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t txtCount = std::min(src.txtRecords.size(), static_cast<size_t>(TT_MDNS_MAX_TXT_RECORDS));
|
||||||
|
dst.txtCount = static_cast<uint8_t>(txtCount);
|
||||||
|
size_t idx = 0;
|
||||||
|
for (const auto& kv : src.txtRecords) {
|
||||||
|
if (idx >= txtCount) break;
|
||||||
|
strncpy(dst.txtRecords[idx].key, kv.first.c_str(), TT_MDNS_TXT_KEY_LEN - 1);
|
||||||
|
strncpy(dst.txtRecords[idx].value, kv.second.c_str(), TT_MDNS_TXT_VALUE_LEN - 1);
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outResult->count = static_cast<uint8_t>(toCopy);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tt_mdns_resolve_hostname(const char* hostname, uint32_t timeoutMs, char* outIp) {
|
||||||
|
if (hostname == nullptr || outIp == nullptr) return false;
|
||||||
|
memset(outIp, 0, TT_MDNS_IP_LEN);
|
||||||
|
|
||||||
|
uint32_t effectiveTimeout = timeoutMs == 0 ? 2000 : timeoutMs;
|
||||||
|
std::string ip;
|
||||||
|
if (!tt::network::mdns::resolveHostname(hostname, effectiveTimeout, ip)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(outIp, ip.c_str(), TT_MDNS_IP_LEN - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
@@ -81,3 +81,70 @@ TEST_CASE("parseManifestV2() should fail when the app id is invalid") {
|
|||||||
AppManifest manifest;
|
AppManifest manifest;
|
||||||
CHECK_EQ(parseManifestV2(properties, manifest), false);
|
CHECK_EQ(parseManifestV2(properties, manifest), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseAppFlagsString() should parse various flag combinations") {
|
||||||
|
CHECK_EQ(parseAppFlagsString(""), 0);
|
||||||
|
CHECK_EQ(parseAppFlagsString("None"), 0);
|
||||||
|
CHECK_EQ(parseAppFlagsString("HideStatusBar"), AppManifest::Flags::HideStatusBar);
|
||||||
|
CHECK_EQ(parseAppFlagsString("hidden"), AppManifest::Flags::Hidden);
|
||||||
|
CHECK_EQ(parseAppFlagsString("HideStatusBar,Hidden"), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
||||||
|
CHECK_EQ(parseAppFlagsString(" hidestatusbar , hidden "), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
||||||
|
CHECK_EQ(parseAppFlagsString("HideStatusBar, Hidden"), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseManifest() should parse V1 flags for fullscreen") {
|
||||||
|
TestFile file("test-manifest-v1-flags.properties");
|
||||||
|
file.writeData(
|
||||||
|
"[manifest]\n"
|
||||||
|
"version=0.1\n"
|
||||||
|
"[target]\n"
|
||||||
|
"sdk=0.0.0\n"
|
||||||
|
"platforms=esp32\n"
|
||||||
|
"[app]\n"
|
||||||
|
"id=one.tactility.sdktest\n"
|
||||||
|
"versionName=0.1.0\n"
|
||||||
|
"versionCode=1\n"
|
||||||
|
"name=SDK Test\n"
|
||||||
|
"flags=HideStatusBar\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
AppManifest manifest;
|
||||||
|
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
||||||
|
CHECK_EQ(manifest.appFlags & AppManifest::Flags::HideStatusBar, AppManifest::Flags::HideStatusBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseManifest() should parse V2 flags for fullscreen") {
|
||||||
|
TestFile file("test-manifest-v2-flags.properties");
|
||||||
|
file.writeData(
|
||||||
|
"manifest.version=0.1\n"
|
||||||
|
"target.sdk=0.0.0\n"
|
||||||
|
"target.platforms=esp32\n"
|
||||||
|
"app.id=one.tactility.sdktest\n"
|
||||||
|
"app.version.name=0.1.0\n"
|
||||||
|
"app.version.code=1\n"
|
||||||
|
"app.name=SDK Test\n"
|
||||||
|
"app.flags=HideStatusBar\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
AppManifest manifest;
|
||||||
|
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
||||||
|
CHECK_EQ(manifest.appFlags & AppManifest::Flags::HideStatusBar, AppManifest::Flags::HideStatusBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseManifest() should parse combined flags") {
|
||||||
|
TestFile file("test-manifest-v2-flags2.properties");
|
||||||
|
file.writeData(
|
||||||
|
"manifest.version=0.1\n"
|
||||||
|
"target.sdk=0.0.0\n"
|
||||||
|
"target.platforms=esp32\n"
|
||||||
|
"app.id=one.tactility.sdktest\n"
|
||||||
|
"app.version.name=0.1.0\n"
|
||||||
|
"app.version.code=1\n"
|
||||||
|
"app.name=SDK Test\n"
|
||||||
|
"app.flags=HideStatusBar,Hidden\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
AppManifest manifest;
|
||||||
|
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
||||||
|
CHECK_EQ(manifest.appFlags, (AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user