diff --git a/README.md b/README.md index c6292c6..b05c6fc 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,14 @@ - udp #### 软件功能 -不仅仅能够显示收到的数据,还能基于自己编写脚本实现简单的协议。
-提供lua脚本功能钩子
+功能示意图如下:
+![image.png](https://www.testingcloud.club/sapi/api/image_download/000884f1-a057-11eb-a166-525400dc6cec.png) + +
+ +串口配置:
+![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png) + +lua脚本调试
+![image.png](https://www.testingcloud.club/sapi/api/image_download/36748542-a057-11eb-a166-525400dc6cec.png) \ No newline at end of file diff --git a/protoDebuger/ProtoDebug.qml b/protoDebuger/ProtoDebug.qml index 58f5889..4f60b5a 100644 --- a/protoDebuger/ProtoDebug.qml +++ b/protoDebuger/ProtoDebug.qml @@ -96,7 +96,8 @@ Item { Layout.bottomMargin: 10 onClicked: { - + lua_script_text = lua_script.text + DataWrap.SaveLuaScript(lua_script_text) } } } diff --git a/protoDebuger/lua_bind.cpp b/protoDebuger/lua_bind.cpp index a256deb..77fbb9f 100644 --- a/protoDebuger/lua_bind.cpp +++ b/protoDebuger/lua_bind.cpp @@ -1,6 +1,7 @@ #include "lua_bind.h" #include "sharedata.h" +// 在qml界面中显示lua层处理过的数据 int LuaShowData(lua_State *vm) { // 获取函数参数:从栈底取一个参数 @@ -12,3 +13,16 @@ int LuaShowData(lua_State *vm) return 0; } +// +int LuaWriteUart(lua_State *vm) +{ + // 获取函数参数:从栈底取一个参数 + const char *k = lua_tostring(vm, 1); + if (nullptr != k){ + //todo qml显示添加 + } + gGlobal.SendUartData(k); + qDebug()<<"send data "<< QString(k); + return 0; +} + diff --git a/protoDebuger/lua_bind.h b/protoDebuger/lua_bind.h index e326bf1..4d5a9bb 100644 --- a/protoDebuger/lua_bind.h +++ b/protoDebuger/lua_bind.h @@ -9,5 +9,6 @@ extern "C" { // 在界面中显示数据 int LuaShowData(lua_State *); +int LuaWriteUart(lua_State *vm); #endif // LUA_BIND_H diff --git a/protoDebuger/lua_wraper.cpp b/protoDebuger/lua_wraper.cpp index 6788c3f..134388e 100644 --- a/protoDebuger/lua_wraper.cpp +++ b/protoDebuger/lua_wraper.cpp @@ -24,6 +24,34 @@ void LuaDelegate::OnDataRecv(QString data){ lua_call(mVM,2,0); } +void LuaDelegate::DumpStack() +{ + static int count = 0; + printf("begin dump lua stack:%d\n", count); + int top = lua_gettop(mVM); + for (int i = top; i > 0; --i) + { + int t = lua_type(mVM, i); + switch (t) + { + case LUA_TSTRING: + qDebug()<<("%s\n", lua_tostring(mVM, i)); + break; + case LUA_TBOOLEAN: + qDebug()<<(lua_toboolean(mVM, i) ? "true\n" : "false\n"); + break; + case LUA_TNUMBER: + qDebug()<<("%g\n", lua_tonumber(mVM, i)); + break; + default: + qDebug()<<("%s\n", lua_typename(mVM, t)); + break; + } + } + ++count; +} + + LuaDelegate::~LuaDelegate() { if(nullptr != mVM){ @@ -40,6 +68,8 @@ LuaDelegate::LuaDelegate(): } luaL_openlibs(mVM); //打开标准库 lua_register(mVM, "showbuffer", LuaShowData); + lua_register(mVM, "resp", LuaWriteUart); + } int LuaDelegate::DoFile(QString path) @@ -55,11 +85,3 @@ int LuaDelegate::DoFile(QString path) return 0; } - -void TestLua() -{ - LuaDelegate v; - qDebug()<("test",13,(void *)"sds",false); -} diff --git a/protoDebuger/lua_wraper.h b/protoDebuger/lua_wraper.h index 4589d49..a8de13b 100644 --- a/protoDebuger/lua_wraper.h +++ b/protoDebuger/lua_wraper.h @@ -23,7 +23,6 @@ public: int DoFile(QString); void Stop(); int DoString(QString); - void pushstack() { // const std::type_info &t1 = std::bad_typeid(arg1); // std::cout << t1.name() << std::endl; @@ -45,7 +44,7 @@ public: } /* 收到数据发送给lua层进行处理*/ void OnDataRecv(QString); - + void DumpStack(); ~LuaDelegate(); private: diff --git a/protoDebuger/sharedata.cpp b/protoDebuger/sharedata.cpp index 6f2daa9..5c3ea9b 100644 --- a/protoDebuger/sharedata.cpp +++ b/protoDebuger/sharedata.cpp @@ -2,6 +2,7 @@ #include #include #include +#include ShareData::ShareData(QObject *parent) : QObject(parent), mView(nullptr) @@ -14,7 +15,10 @@ ShareData::ShareData(QObject *parent) : QObject(parent), QTextStream in(&file); mLuaScript = in.readAll(); qDebug()<< mLuaScript; - mLua.DoString(mLuaScript); + int ret = mLua.DoString(mLuaScript); + if(ret < 0){ + qDebug()<<"默认lua脚本加载错误"; + } } int ShareData::SetQuickView(QQuickView *view) @@ -41,10 +45,6 @@ int ShareData::SetQuickView(QQuickView *view) int ShareData::OnDataRecv(QByteArray arr) { -// qDebug()<mSerialController->SendData((uint8_t *)data,strlen(data)); + return 0; + } + return -1; +} + int ShareData::OpenUart(QString port, QString baudRate, QString dataBits, QString stopBits, QString flow) { qDebug()<