From 0fcd1c6b183b880e0a1e2c1b74d11e70a828bd6a Mon Sep 17 00:00:00 2001 From: WangQiang <807319473@qq.com> Date: Mon, 5 Sep 2016 01:25:14 +0000 Subject: [PATCH] =?UTF-8?q?Sys.Reset()=20=20Sys.ResetAsync()=20=20=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=B8=BA=20=20Sys.Reboot(int=20Delayms=20=3D?= =?UTF-8?q?=200);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Button_GrayLevel.cpp | 2 +- Board/AP0104.cpp | 2 +- Board/AP0801.cpp | 6 +++--- Board/AP0802.cpp | 6 +++--- Board/IOK027X.cpp | 6 +++--- Board/IOK0612.cpp | 6 +++--- Board/Pandora.cpp | 4 ++-- Drivers/Esp8266/Esp8266.cpp | 2 +- Kernel/Sys.cpp | 4 +++- Kernel/Sys.h | 6 +++--- TinyNet/Tiny.cpp | 4 ++-- TinyNet/TinyClient.cpp | 8 ++++---- TokenNet/TokenClient.cpp | 13 ++++++++----- 13 files changed, 37 insertions(+), 32 deletions(-) diff --git a/App/Button_GrayLevel.cpp b/App/Button_GrayLevel.cpp index 7da75d46..38131121 100644 --- a/App/Button_GrayLevel.cpp +++ b/App/Button_GrayLevel.cpp @@ -306,7 +306,7 @@ void ACZeroReset(void *param) InputPort* port = Button_GrayLevel::ACZero; if (port) { - //Sys.Reset(); + //Sys.Reboot(); debug_printf("定时检查过零检测\r\n"); // 需要检测是否有交流电,否则关闭 diff --git a/Board/AP0104.cpp b/Board/AP0104.cpp index ceec6eed..b835ce85 100644 --- a/Board/AP0104.cpp +++ b/Board/AP0104.cpp @@ -177,7 +177,7 @@ void AP0104::InitClient() if (!client.Opened) { debug_printf("联网超时,准备重启系统!\r\n\r\n"); - Sys.Reset(); + Sys.Reboot(); } }, client, 8 * 60 * 1000, -1, "check connet net"); diff --git a/Board/AP0801.cpp b/Board/AP0801.cpp index e8f0bdd1..dcb9bb80 100644 --- a/Board/AP0801.cpp +++ b/Board/AP0801.cpp @@ -189,7 +189,7 @@ void AP0801::InitClient() if(!client.Opened) { debug_printf("联网超时,准备重启系统!\r\n\r\n"); - Sys.Reset(); + Sys.Reboot(); } }, client, 8 * 60 * 1000, -1, "联网检查"); @@ -510,7 +510,7 @@ void AP0801::Restore() { Config::Current->RemoveAll(); - Sys.Reset(); + Sys.Reboot(); } void AP0801::OnLongPress(InputPort* port, bool down) @@ -522,7 +522,7 @@ void AP0801::OnLongPress(InputPort* port, bool down) if (port->PressTime >= 5000) Restore(); else if (port->PressTime >= 1000) - Sys.Reset(); + Sys.Reboot(); } /* diff --git a/Board/AP0802.cpp b/Board/AP0802.cpp index 5a5afc11..62f07755 100644 --- a/Board/AP0802.cpp +++ b/Board/AP0802.cpp @@ -193,7 +193,7 @@ void AP0802::InitClient() if(!client.Opened) { debug_printf("联网超时,准备重启系统!\r\n\r\n"); - Sys.Reset(); + Sys.Reboot(); } }, client, 8 * 60 * 1000, -1, "联网检查"); @@ -458,7 +458,7 @@ void AP0802::Restore() { Config::Current->RemoveAll(); - Sys.Reset(); + Sys.Reboot(); } void AP0802::OnLongPress(InputPort* port, bool down) @@ -470,7 +470,7 @@ void AP0802::OnLongPress(InputPort* port, bool down) if (port->PressTime >= 5000) Restore(); else if (port->PressTime >= 1000) - Sys.Reset(); + Sys.Reboot(); } /* diff --git a/Board/IOK027X.cpp b/Board/IOK027X.cpp index 8326414d..e9aacbd4 100644 --- a/Board/IOK027X.cpp +++ b/Board/IOK027X.cpp @@ -148,7 +148,7 @@ void IOK027X::InitClient() if(!client.Opened) { debug_printf("联网超时,准备重启Esp!\r\n\r\n"); - // Sys.Reset(); + // Sys.Reboot(); auto port = dynamic_cast(bsp.Host); port->Close(); Sys.Sleep(1000); @@ -285,7 +285,7 @@ void IOK027X::Restore() { Config::Current->RemoveAll(); - Sys.Reset(); + Sys.Reboot(); } void IOK027X::FlushLed() @@ -342,7 +342,7 @@ void IOK027X::OnLongPress(InputPort* port, bool down) if (time >= 6500 && time < 10000) { Sys.Sleep(1000); - Sys.Reset(); + Sys.Reboot(); return; } diff --git a/Board/IOK0612.cpp b/Board/IOK0612.cpp index 99b9e987..18788859 100644 --- a/Board/IOK0612.cpp +++ b/Board/IOK0612.cpp @@ -171,7 +171,7 @@ void IOK0612::InitClient() if(!client.Opened) { debug_printf("联网超时,准备重启Esp!\r\n\r\n"); - // Sys.Reset(); + // Sys.Reboot(); auto port = dynamic_cast(bsp.Host); port->Close(); Sys.Sleep(1000); @@ -308,7 +308,7 @@ void IOK0612::Restore() { Config::Current->RemoveAll(); - Sys.Reset(); + Sys.Reboot(); } void IOK0612::FlushLed() @@ -365,7 +365,7 @@ void IOK0612::OnLongPress(InputPort* port, bool down) if (time >= 6500 && time < 10000) { Sys.Sleep(1000); - Sys.Reset(); + Sys.Reboot(); return; } if (time >= 5000) diff --git a/Board/Pandora.cpp b/Board/Pandora.cpp index 880e6790..40040832 100644 --- a/Board/Pandora.cpp +++ b/Board/Pandora.cpp @@ -116,7 +116,7 @@ void PA0903::InitClient() // 如果若干分钟后仍然没有打开令牌客户端,则重启系统 Sys.AddTask( [](void* p) { - if (!((TokenClient*)p)->Opened) Sys.Reset(); + if (!((TokenClient*)p)->Opened) Sys.Reboot(); }, client, 8 * 60 * 1000, -1, "CheckClient"); } @@ -258,7 +258,7 @@ void PA0903::Restore() { Config::Current->RemoveAll(); - Sys.Reset(); + Sys.Reboot(); } //auto host = (W5500*)Create5500(Spi1, PA8, PA0, led); diff --git a/Drivers/Esp8266/Esp8266.cpp b/Drivers/Esp8266/Esp8266.cpp index 0399a2d8..cd2c92a8 100644 --- a/Drivers/Esp8266/Esp8266.cpp +++ b/Drivers/Esp8266/Esp8266.cpp @@ -1087,7 +1087,7 @@ bool Esp8266::SetWiFi(const Pair& args, Stream& result) // 返回结果 result.Write((byte)true); // 延迟重启 - if(haveChang)Sys.ResetAsync(5000); + if(haveChang)Sys.Reboot(5000); return true; } diff --git a/Kernel/Sys.cpp b/Kernel/Sys.cpp index 5468ad26..e7d1beaa 100644 --- a/Kernel/Sys.cpp +++ b/Kernel/Sys.cpp @@ -157,8 +157,10 @@ void TSys::Start() } // 延迟异步重启 -void TSys::ResetAsync(int msDelay) const +void TSys::Reboot(int msDelay) const { + if (msDelay <= 0)Reset(); + auto func = &TSys::Reset; AddTask(*(Action*)&func, (void*)this, msDelay, -1, "延迟重启"); } diff --git a/Kernel/Sys.h b/Kernel/Sys.h index a4752e84..5ec7a082 100644 --- a/Kernel/Sys.h +++ b/Kernel/Sys.h @@ -94,16 +94,16 @@ public: bool CheckMemory() const; - // 重启系统 - void Reset() const; // 延迟异步重启 - void ResetAsync(int msDelay) const; + void Reboot(int msDelay = 0) const; // 系统跟踪 void InitTrace(void* port) const; void Trace(int times = 1) const; private: + // 重启系统 + void Reset() const; void OnInit(); void OnShowInfo() const; void OnStart(); diff --git a/TinyNet/Tiny.cpp b/TinyNet/Tiny.cpp index bcf16e45..1168b8f9 100644 --- a/TinyNet/Tiny.cpp +++ b/TinyNet/Tiny.cpp @@ -207,7 +207,7 @@ void ClearConfig() if(client) client->DisJoin(); Sys.Sleep(300); - Sys.Reset(); + Sys.Reboot(); } bool CheckUserPress(InputPort* port, bool down, void* param) @@ -226,7 +226,7 @@ bool CheckUserPress(InputPort* port, bool down, void* param) // 按下3秒,重启 else if(port->PressTime >= 3000) { - Sys.Reset(); + Sys.Reboot(); return true; } diff --git a/TinyNet/TinyClient.cpp b/TinyNet/TinyClient.cpp index a3e6ee66..87cb4b30 100644 --- a/TinyNet/TinyClient.cpp +++ b/TinyNet/TinyClient.cpp @@ -216,7 +216,7 @@ void TinyClient::OnWrite(const TinyMessage& msg) { debug_printf("\r\n 配置区被修改,200ms后重启\r\n"); Sys.Sleep(200); - Sys.Reset(); + Sys.Reboot(); } // 写入指令以后,为了避免写入响应丢失,缩短心跳间隔 @@ -391,7 +391,7 @@ bool TinyClient::OnJoin(const TinyMessage& msg) Cfg->Save(); // 组网以后重启一次 - Sys.Reset(); + Sys.Reboot(); return true; } @@ -429,7 +429,7 @@ bool TinyClient::OnDisjoin(const TinyMessage& msg) Cfg->Clear(); Sys.Sleep(3000); - Sys.Reset(); + Sys.Reboot(); return true; } @@ -461,7 +461,7 @@ void TinyClient::Ping() //Server = 0; - //Sys.Reset(); + //Sys.Reboot(); //Server = 0; //Password.SetLength(0); diff --git a/TokenNet/TokenClient.cpp b/TokenNet/TokenClient.cpp index 5c2dcf7a..08a9742f 100644 --- a/TokenNet/TokenClient.cpp +++ b/TokenNet/TokenClient.cpp @@ -343,7 +343,7 @@ void TokenClient::LoopTask() if (MaxNotActive != 0 && LastActive + MaxNotActive < Sys.Ms()) { Master->Close(); - // Sys.Reset(); + // Sys.Reboot(); } } @@ -894,7 +894,7 @@ void TokenClient::OnWrite(const TokenMessage& msg, TokenController* ctrl) { debug_printf("\r\n 配置区被修改,200ms后重启\r\n"); Sys.Sleep(200); - Sys.Reset(); + Sys.Reboot(); } LocalSend(0, Store.Data); } @@ -1010,7 +1010,8 @@ bool TokenClient::InvokeRestStart(void * param, const Pair& args, Stream& result res.Set("Restart", (byte)01); debug_printf("1000ms后重启\r\n"); - Sys.AddTask([](void * param) {Sys.Reset(); }, nullptr, 1000, 0, "Restart"); + // Sys.AddTask([](void * param) {Sys.Reboot(); }, nullptr, 1000, 0, "Restart"); + Sys.Reboot(1000); return true; } @@ -1023,8 +1024,10 @@ bool TokenClient::InvokeRestBoot(void * param, const Pair& args, Stream& result) debug_printf("1000ms后重置\r\n"); //Sys.Sleep(500); - //Sys.Reset(); - Sys.AddTask([](void * param) {Sys.Reset(); }, nullptr, 1000, 0, "RestBoot"); + //Sys.Reboot(); + //Sys.AddTask([](void * param) {Sys.Reset(); }, nullptr, 1000, 0, "RestBoot"); + + Sys.Reboot(1000); return true; }