#ifndef VOICELINK_BLE_NAME_H #define VOICELINK_BLE_NAME_H #include #include // Legacy scan response: 31 bytes minus AD length/type = 29 name bytes. // "vl-" (3) + model (<=17 UTF-8 bytes) + "-" (1) + ID (8). #define VOICELINK_BLE_NAME_CAPACITY 30 static inline void voicelink_ble_name(char out[VOICELINK_BLE_NAME_CAPACITY], const char *model, const char *factory_id) { size_t model_len = strlen(model); if (model_len > 17) { model_len = 17; // Do not truncate inside a UTF-8 code point. while (model_len && ((unsigned char)model[model_len] & 0xc0) == 0x80) model_len--; } size_t id_len = strlen(factory_id); const char *suffix = id_len >= 8 ? factory_id + id_len - 8 : factory_id; snprintf(out, VOICELINK_BLE_NAME_CAPACITY, "vl-%.*s-%s", (int)model_len, model, suffix); } #endif