4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
41 std::string
get_next_param(const std::string
&cmd
, size_t &pos
, char sperate
= ' ');
47 CmdCtx(const CmdCtx
&) = delete;
48 CmdCtx
& operator=(const CmdCtx
&) = delete;
51 ConfigItem
*m_config_item
= nullptr;
52 void *m_dev
= nullptr;
56 class CmdUsbCtx
: public CmdCtx
59 ~CmdUsbCtx() override
;
60 int look_for_match_device(const char * procotol
);
74 const char * const key
;
75 const char * const Error
;
78 const bool ignore_case
;
79 Param(const char *ky
, void *pD
, Type tp
, bool ignore
= true, const char *error
= nullptr) :
80 key
{ky
}, Error
{error
}, pData
{pD
}, type
{tp
}, ignore_case
{ignore
}
89 CmdBase(char *p
) { if (p
) m_cmd
= p
; }
93 const std::string
& get_cmd() const noexcept
{ return m_cmd
; }
94 bool get_lastcmd() const noexcept
{ return m_lastcmd
; }
95 void insert_param_info(const char *key
, void *pD
, Param::Type tp
, bool ignore_case
= true, const char* err
= nullptr)
97 m_param
.emplace_back(Param
{key
, pD
, tp
, ignore_case
, err
});
99 virtual int parser_protocal(char *p
, size_t &pos
);
100 virtual int parser(char *p
= nullptr);
101 virtual int run(CmdCtx
*p
) = 0;
104 bool m_bCheckTotalParam
= false;
106 bool m_lastcmd
= false;
107 bool m_NoKeyParam
= false;
108 uint64_t m_timeout
= 2000;
111 std::vector
<Param
> m_param
;
114 using CreateCmdObj
= std::shared_ptr
<CmdBase
> (*) (char *);
116 class CmdObjCreateMap
:public std::map
<std::string
, CreateCmdObj
>
122 class CmdDone
:public CmdBase
125 CmdDone(char *p
) :CmdBase(p
) { m_lastcmd
= true; }
127 int run(CmdCtx
*p
) override
;
130 class CmdDelay
:public CmdBase
133 CmdDelay(char *p
) :CmdBase(p
) {}
135 int parser(char *p
= nullptr) override
;
136 int run(CmdCtx
*p
) override
;
142 class CmdError
: public CmdBase
145 CmdError(char *p
) :CmdBase(p
) {}
146 int parser(char *p
= nullptr) override
;
147 int run(CmdCtx
*p
) override
;
153 class CmdShell
: public CmdBase
156 CmdShell(char *p
) : CmdBase(p
) {}
158 int parser(char *p
= nullptr) override
;
159 int run(CmdCtx
*p
) override
;
163 std::string m_protocal
;
164 std::string m_shellcmd
;
167 class CmdIf
: public CmdBase
170 CmdIf(char *p
) : CmdBase(p
) {}
172 int parser(char *p
= nullptr) override
;
173 int run(CmdCtx
*p
) override
;
176 std::string m_condtion
;
177 std::string m_protocal
;
178 std::string m_true_cmd
;
179 std::map
<std::string
, std::string
> m_key_map
;
180 void build_map(CmdCtx
*p
);
183 class CmdEnv
: public CmdBase
186 using CmdBase::CmdBase
;
188 int parser(char *p
= nullptr) override
;
189 int run(CmdCtx
*p
) override
;
192 std::string m_unfold_cmd
;
195 class CmdList
: public std::vector
<std::shared_ptr
<CmdBase
>>
198 int run_all(CmdCtx
*p
, bool dry_run
= false);
201 class CmdMap
: public std::map
<std::string
, std::shared_ptr
<CmdList
>>
204 int run_all(const std::string
&protocal
, CmdCtx
*p
, bool dry_run
= false);
207 class CfgCmd
:public CmdBase
210 CfgCmd(char *cmd
) :CmdBase(cmd
) {}
212 int parser(char * /*p*/) override
{ return 0; }
213 int run(CmdCtx
*p
) override
;
216 int run_cmds(const char *procotal
, CmdCtx
*p
);
217 int run_cmd(CmdCtx
*pCtx
, const char * cmd
, int dry
);