/* Реальное радио, запуск вручную: ble_probe [seconds]. Публикует только тестовое объявление. */ #include "ble_transport.h" #include "u_async.h" #include "debug_config.h" #include #include #include static int ready, failed; static struct ble_transport* transport; static void status(void* arg, enum ble_state state, const char* reason) { (void)arg; printf("BLE status=%d reason=%s\n", state, reason); fflush(stdout); if (state == BLE_READY) { ready = 1; if (ble_advertise(transport, "vibechat-probe", 14) != BLE_OK) failed = 1; } if (state == BLE_CLOSED && strcmp(reason, "stopped")) failed = 1; } static void broadcast(void* arg, const struct ble_endpoint* ep, const uint8_t* data, size_t len, int rssi) { (void)arg; (void)data; printf("BLE broadcast endpoint=%s bytes=%zu rssi=%d\n", ep->id, len, rssi); } int main(int argc, char** argv) { debug_config_init(); debug_set_level(DEBUG_LEVEL_INFO); debug_set_category_level(DEBUG_CATEGORY_DISCOVERY, DEBUG_LEVEL_DEBUG); int seconds = argc > 1 ? atoi(argv[1]) : 5; if (seconds < 1 || seconds > 60) return 2; struct UASYNC* ua = uasync_create(); struct ble_config cfg = {0}; cfg.node_id = 0x5643424c45544553ULL; cfg.company_id = 0xffff; cfg.callbacks.status = status; cfg.callbacks.broadcast = broadcast; transport = ble_create(ua, &cfg); if (!transport || ble_start(transport) != BLE_OK) failed = 1; uint64_t start = get_time_us(), end = start + (uint64_t)seconds * 1000000; int changed = 0; while (!failed && get_time_us() < end) { uasync_poll(ua, 100); if (ready && !changed && get_time_us() >= start + 1000000) { changed = 1; if (ble_advertise(transport, "vibechat-updated", 16) != BLE_OK) failed = 1; } } ble_destroy(transport); uasync_destroy(ua, 0); printf("BLE probe ready=%d failed=%d\n", ready, failed); return failed || !ready; }