From 7caa12233a7610ee3aa489a521d1a552b04273a4 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Wed, 11 Jul 2018 15:41:54 -0500 Subject: [PATCH] add delay command Signed-off-by: Frank Li --- libuuu/cmd.cpp | 37 ++++++++++++++++++++++++++++++++++++- libuuu/cmd.h | 10 ++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/libuuu/cmd.cpp b/libuuu/cmd.cpp index 22c87837..354866c8 100644 --- a/libuuu/cmd.cpp +++ b/libuuu/cmd.cpp @@ -42,7 +42,7 @@ #include "sdp.h" #include "fastboot.h" #include - +#include static CmdMap g_cmd_map; static CmdObjCreateMap g_cmd_create_map; @@ -211,6 +211,7 @@ CmdObjCreateMap::CmdObjCreateMap() (*this)["SDPS:BOOT"] = new_cmd_obj; (*this)["SDPS:DONE"] = new_cmd_obj; + (*this)["SDPS:DELAY"] = new_cmd_obj; (*this)["SDP:DCD"] = new_cmd_obj; (*this)["SDP:JUMP"] = new_cmd_obj; @@ -218,9 +219,12 @@ CmdObjCreateMap::CmdObjCreateMap() (*this)["SDP:STATUS"] = new_cmd_obj; (*this)["SDP:BOOT"] = new_cmd_obj; (*this)["SDP:DONE"] = new_cmd_obj; + (*this)["SDP:DELAY"] = new_cmd_obj; + (*this)["SDPU:JUMP"] = new_cmd_obj; (*this)["SDPU:WRITE"] = new_cmd_obj; (*this)["SDPU:DONE"] = new_cmd_obj; + (*this)["SDPU:DELAY"] = new_cmd_obj; (*this)["FB:GETVAR"] = new_cmd_obj; (*this)["FASTBOOT:GETVAR"] = new_cmd_obj; @@ -236,12 +240,16 @@ CmdObjCreateMap::CmdObjCreateMap() (*this)["FASTBOOT:ERASE"] = new_cmd_obj; (*this)["FB:DONE"] = new_cmd_obj; (*this)["FASTBOOT:DONE"] = new_cmd_obj; + (*this)["FB:DELAY"] = new_cmd_obj; + (*this)["FASTBOOT:DELAY"] = new_cmd_obj; (*this)["FBK:UCMD"] = new_cmd_obj; (*this)["FBK:ACMD"] = new_cmd_obj; (*this)["FBK:SYNC"] = new_cmd_obj; (*this)["FBK:UCP"] = new_cmd_obj; (*this)["FBK:DONE"] = new_cmd_obj; + (*this)["FBK:DELAY"] = new_cmd_obj; + } shared_ptr create_cmd_obj(string cmd) @@ -325,6 +333,33 @@ int CmdDone::run(CmdCtx *) return 0; } +int CmdDelay::parser(char *p) +{ + size_t pos = 0; + string param = get_next_param(m_cmd, pos); + + if (param.find(':') != string::npos) + param = get_next_param(m_cmd, pos); + + if (str_to_upper(param) != "DELAY") + { + string err = "Uknown Commnd:"; + err += param; + set_last_err_string(err); + return -1; + } + + string ms = get_next_param(m_cmd, pos); + m_ms = str_to_uint(ms); + return 0; +} + +int CmdDelay::run(CmdCtx *) +{ + std::this_thread::sleep_for(std::chrono::milliseconds(m_ms)); + return 0; +} + int run_cmds(const char *procotal, CmdCtx *p) { CmdMap cmdmap, *pCmdMap; diff --git a/libuuu/cmd.h b/libuuu/cmd.h index f977eef4..fe11ae17 100644 --- a/libuuu/cmd.h +++ b/libuuu/cmd.h @@ -112,6 +112,16 @@ class CmdDone :public CmdBase int run(CmdCtx *p); }; +class CmdDelay :public CmdBase +{ +public: + int m_ms; + virtual int parser(char *p = NULL); + CmdDelay(char *p) :CmdBase(p) { m_ms = 0; }; + int run(CmdCtx *p); +}; + + class CmdList : public std::vector> { public: