mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 07:27:41 -06:00
ENH: add keep alive logic
Change-Id: I6e6916d22e32983cc885586e2716b52b5ed1086f Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
parent
f525785338
commit
94c4ef6105
2 changed files with 25 additions and 0 deletions
|
@ -1505,6 +1505,8 @@ int MachineObject::command_request_push_all(bool request_now)
|
|||
json j;
|
||||
j["pushing"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
||||
j["pushing"]["command"] = "pushall";
|
||||
j["pushing"]["version"] = 1;
|
||||
j["pushing"]["push_target"] = 1;
|
||||
return this->publish_json(j.dump());
|
||||
}
|
||||
|
||||
|
@ -4348,8 +4350,27 @@ void DeviceManager::set_agent(NetworkAgent* agent)
|
|||
m_agent = agent;
|
||||
}
|
||||
|
||||
void DeviceManager::keep_alive()
|
||||
{
|
||||
MachineObject* obj = this->get_selected_machine();
|
||||
if (obj) {
|
||||
if (obj->keep_alive_count == 0) {
|
||||
obj->last_keep_alive = std::chrono::system_clock::now();
|
||||
}
|
||||
obj->keep_alive_count++;
|
||||
std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
|
||||
auto internal = std::chrono::duration_cast<std::chrono::milliseconds>(start - obj->last_keep_alive);
|
||||
if (internal.count() > TIMEOUT_FOR_KEEPALIVE && internal.count() < 1000 * 60 * 60 * 300) {
|
||||
BOOST_LOG_TRIVIAL(info) << "keep alive = " << internal.count() << ", count = " << obj->keep_alive_count;
|
||||
obj->command_request_push_all();
|
||||
obj->last_keep_alive = start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::check_pushing()
|
||||
{
|
||||
keep_alive();
|
||||
MachineObject* obj = this->get_selected_machine();
|
||||
if (obj && !obj->is_support_mqtt_alive) {
|
||||
std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define DISCONNECT_TIMEOUT 30000.f // milliseconds
|
||||
#define PUSHINFO_TIMEOUT 15000.f // milliseconds
|
||||
#define TIMEOUT_FOR_STRAT 20000.f // milliseconds
|
||||
#define TIMEOUT_FOR_KEEPALIVE 5* 60 * 1000.f // milliseconds
|
||||
#define REQUEST_PUSH_MIN_TIME 15000.f // milliseconds
|
||||
#define REQUEST_START_MIN_TIME 15000.f // milliseconds
|
||||
#define EXTRUSION_OMIT_TIME 20000.f // milliseconds
|
||||
|
@ -460,7 +461,9 @@ public:
|
|||
void set_lan_mode_connection_state(bool state) {m_lan_mode_connection_state = state;};
|
||||
bool get_lan_mode_connection_state() {return m_lan_mode_connection_state;};
|
||||
int parse_msg_count = 0;
|
||||
int keep_alive_count = 0;
|
||||
std::chrono::system_clock::time_point last_update_time; /* last received print data from machine */
|
||||
std::chrono::system_clock::time_point last_keep_alive; /* last received print data from machine */
|
||||
std::chrono::system_clock::time_point last_push_time; /* last received print push from machine */
|
||||
std::chrono::system_clock::time_point last_request_push; /* last received print push from machine */
|
||||
std::chrono::system_clock::time_point last_request_start; /* last received print push from machine */
|
||||
|
@ -895,6 +898,7 @@ public:
|
|||
std::map<std::string, MachineObject*> localMachineList; /* dev_id -> MachineObject*, localMachine SSDP */
|
||||
std::map<std::string, MachineObject*> userMachineList; /* dev_id -> MachineObject* cloudMachine of User */
|
||||
|
||||
void keep_alive();
|
||||
void check_pushing();
|
||||
|
||||
MachineObject* get_default_machine();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue