mirror of
https://github.com/ClusterM/open-bamboo-networking.git
synced 2026-10-21 18:42:21 -05:00
Studio's main loop polls is_user_login (~5 ms apart), install_device_cert (~1 Hz), and the logout/build_logout_cmd pair (~2 s) regardless of whether anything actually changed. At the default debug level these three call sites buried real activity in ~150 identical lines per 20 s of idle. Keep them at TRACE so they only show up under OBN_LOG_LEVEL=trace, when you really want to see every ABI tick. Made-with: Cursor
86 lines
3.2 KiB
C++
86 lines
3.2 KiB
C++
#include <string>
|
|
|
|
#include "obn/abi_export.hpp"
|
|
#include "obn/agent.hpp"
|
|
#include "obn/bambu_networking.hpp"
|
|
#include "obn/log.hpp"
|
|
|
|
using obn::as_agent;
|
|
|
|
OBN_ABI int bambu_network_connect_printer(void* agent,
|
|
std::string dev_id,
|
|
std::string dev_ip,
|
|
std::string username,
|
|
std::string password,
|
|
bool use_ssl)
|
|
{
|
|
OBN_INFO("connect_printer dev=%s ip=%s user=%s pwd.len=%zu ssl=%d",
|
|
dev_id.c_str(), dev_ip.c_str(), username.c_str(),
|
|
password.size(), use_ssl);
|
|
auto* a = as_agent(agent);
|
|
if (!a) {
|
|
OBN_ERROR("connect_printer: null agent handle");
|
|
return BAMBU_NETWORK_ERR_INVALID_HANDLE;
|
|
}
|
|
int rc = a->connect_printer(std::move(dev_id),
|
|
std::move(dev_ip),
|
|
std::move(username),
|
|
std::move(password),
|
|
use_ssl);
|
|
OBN_INFO("connect_printer -> rc=%d", rc);
|
|
return rc;
|
|
}
|
|
|
|
OBN_ABI int bambu_network_disconnect_printer(void* agent)
|
|
{
|
|
OBN_INFO("disconnect_printer");
|
|
auto* a = as_agent(agent);
|
|
if (!a) return BAMBU_NETWORK_ERR_INVALID_HANDLE;
|
|
return a->disconnect_printer();
|
|
}
|
|
|
|
OBN_ABI int bambu_network_send_message_to_printer(void* agent,
|
|
std::string dev_id,
|
|
std::string json_str,
|
|
int qos,
|
|
int flag)
|
|
{
|
|
OBN_DEBUG("send_message_to_printer dev=%s qos=%d flag=%d payload=%s",
|
|
dev_id.c_str(), qos, flag,
|
|
obn::log::redact(json_str, 200).c_str());
|
|
auto* a = as_agent(agent);
|
|
if (!a) return BAMBU_NETWORK_ERR_INVALID_HANDLE;
|
|
int rc = a->send_message_to_printer(dev_id, json_str, qos);
|
|
if (rc != BAMBU_NETWORK_SUCCESS)
|
|
OBN_WARN("send_message_to_printer dev=%s -> rc=%d", dev_id.c_str(), rc);
|
|
return rc;
|
|
}
|
|
|
|
OBN_ABI int bambu_network_update_cert(void* /*agent*/)
|
|
{
|
|
OBN_DEBUG("update_cert");
|
|
return BAMBU_NETWORK_SUCCESS;
|
|
}
|
|
|
|
OBN_ABI void bambu_network_install_device_cert(void* agent,
|
|
std::string dev_id,
|
|
bool lan_only)
|
|
{
|
|
// Studio calls this ~1 Hz from its refresh timer; the agent
|
|
// internally dedups so real work only happens once per session
|
|
// (logged there at INFO level). Keep the per-tick trace at TRACE
|
|
// so the default log isn't drowned in identical lines.
|
|
OBN_TRACE("install_device_cert dev=%s lan_only=%d", dev_id.c_str(), lan_only);
|
|
auto* a = as_agent(agent);
|
|
if (!a) return;
|
|
a->install_device_cert(dev_id, lan_only);
|
|
}
|
|
|
|
OBN_ABI bool bambu_network_start_discovery(void* agent, bool start, bool sending)
|
|
{
|
|
OBN_DEBUG("bambu_network_start_discovery start=%d sending=%d", start, sending);
|
|
auto* a = as_agent(agent);
|
|
if (!a) return false;
|
|
return a->start_discovery(start, sending);
|
|
}
|