diff --git a/examples/proto_debuger/base_form.cpp b/examples/proto_debuger/base_form.cpp index d4b780b0..c2201ad3 100644 --- a/examples/proto_debuger/base_form.cpp +++ b/examples/proto_debuger/base_form.cpp @@ -187,7 +187,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node); if (mUartForm.find(p->name) == mUartForm.end()) { - auto form = new UartForm(this,p->name, p->baurate, + auto form = new UartForm(this,p->name, p->baurate,p->port_num, p->data_bits, p->stop_bits, p->verify, p->flow_control); form->SetChildLayoutXML(L"basic/uart_form.xml"); form->SetName(p->name); diff --git a/examples/proto_debuger/loger.cpp b/examples/proto_debuger/loger.cpp index a654368d..1fcc0925 100644 --- a/examples/proto_debuger/loger.cpp +++ b/examples/proto_debuger/loger.cpp @@ -3,8 +3,7 @@ // #include "loger.h" using namespace Loger; -string getTimeDate() -{ +string getTimeDate() { time_t timep; time (&timep); char tmp[64]; @@ -12,8 +11,7 @@ string getTimeDate() return string(tmp); } -string getTime() -{ +string getTime(){ time_t timep; time (&timep); char tmp[64]; @@ -88,6 +86,7 @@ bool file_existed(string path) { return true; } } + _C_Loger::_C_Loger(FILE *p) { this->mFile = p; this->mCurrentDate = getTime(); diff --git a/examples/proto_debuger/new_monitor_form.cpp b/examples/proto_debuger/new_monitor_form.cpp index 7fc98b02..1a1c070d 100644 --- a/examples/proto_debuger/new_monitor_form.cpp +++ b/examples/proto_debuger/new_monitor_form.cpp @@ -115,6 +115,7 @@ void NewMonitorForm::InitWindow() // 打开成功 MessageBox(0, L"打开成功", L"", 0); UartInfo* p = new UartInfo; + p->port_num = PortNum; p->name = m_uart_select_combo->GetText(); p->baurate = 115200; p->data_bits = 8; @@ -128,8 +129,7 @@ void NewMonitorForm::InitWindow() } this->Close(); return true; - } - else { + }else { } } diff --git a/examples/proto_debuger/serial_port.h b/examples/proto_debuger/serial_port.h index 0452924d..f7e0a0a9 100644 --- a/examples/proto_debuger/serial_port.h +++ b/examples/proto_debuger/serial_port.h @@ -8,6 +8,7 @@ using namespace std; typedef struct{ wstring name; + UINT port_num; uint32_t baurate; uint8_t data_bits; uint8_t stop_bits; diff --git a/examples/proto_debuger/tcp_server_form.cpp b/examples/proto_debuger/tcp_server_form.cpp index bfed29d8..9b2f9ac8 100644 --- a/examples/proto_debuger/tcp_server_form.cpp +++ b/examples/proto_debuger/tcp_server_form.cpp @@ -21,6 +21,19 @@ TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url, m_port = port; mFlagSelectClient = true; + mLua = new LuaDelegate; + mLuaFile.open("script.lua"); + std::string lua_script; + if (mLuaFile.is_open()) { + std::string s; + while (getline(mLuaFile, s)) { + lua_script += s + "\r\n"; + } + mLuaFile.close(); + } + mLuaScript = lua_script; + mLua->DoString(lua_script); + std::cout << "lua script is " << lua_script << std::endl; TcpServerLibevent::OnAccept handler = std::bind(&TcpServerFrom::OnNewConnAccept, this,std::placeholders::_1 ); m_server->SetNewConnectionHandle(handler); @@ -41,7 +54,12 @@ void TcpServerFrom::Init() m_label_1 = dynamic_cast(FindSubControl(L"server_info")); m_rich_edit_1 = dynamic_cast(FindSubControl(L"server_recv_edit")); - m_rich_edit_2 = dynamic_cast(FindSubControl(L"lua_script_edit")); + mEditLua = dynamic_cast(FindSubControl(L"lua_script_edit")); + mEditLua->SetRich(true); + mEditLua->SetReturnMsgWantCtrl(true); + + mEditLua->SetText(string2wstring(mLuaScript)); + m_rich_edit_3 = dynamic_cast(FindSubControl(L"server_send_edit")); m_button_1 = dynamic_cast(FindSubControl(L"btn_send_data")); m_check_box_2 = dynamic_cast(FindSubControl(L"check_time_send")); diff --git a/examples/proto_debuger/tcp_server_form.h b/examples/proto_debuger/tcp_server_form.h index bbc3a1ab..3f9f0020 100644 --- a/examples/proto_debuger/tcp_server_form.h +++ b/examples/proto_debuger/tcp_server_form.h @@ -9,6 +9,7 @@ #include #include "lua_wraper.h" #include "global.h" +#include class TcpServerFrom : public ui::ChildBox, @@ -22,6 +23,7 @@ public: void OnDisConnected(ConnectionLibevent*); LuaDelegate* LuaVM(); + protected: void ShowDataInEdit(const char*) override; @@ -32,7 +34,7 @@ private: uint32_t m_port; ui::Label* m_label_1; ui::RichEdit* m_rich_edit_1; - ui::RichEdit* m_rich_edit_2; + ui::RichEdit* mEditLua; ui::RichEdit* m_rich_edit_3; ui::Button* m_button_1; ui::CheckBox* m_check_box_1; @@ -44,9 +46,10 @@ private: ui::Label* m_label_2; ui::Combo* m_combo_1; ui::Button* m_button_3; + std::ifstream mLuaFile; std::map mClients; bool mFlagSelectClient; LuaDelegate *mLua; - + std::string mLuaScript; }; diff --git a/examples/proto_debuger/uart_form.cpp b/examples/proto_debuger/uart_form.cpp index 6fe46eb5..01f40f83 100644 --- a/examples/proto_debuger/uart_form.cpp +++ b/examples/proto_debuger/uart_form.cpp @@ -6,13 +6,14 @@ #include "lua_bind.h" UartForm::UartForm(ui::Window* hwnd,std::wstring name, - uint32_t baurate, + uint32_t baurate,UINT portnum, uint8_t data_bits, uint8_t stop_bits, uint8_t verify, uint8_t flow_control): m_thread_recv(nullptr), mEditRecv(nullptr), mLua(nullptr) { + m_portnum = portnum; m_name = name; m_baurate = baurate; m_data_bits = data_bits; @@ -65,6 +66,11 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name, this->mLua->BindFunction("showdata", LuaShowData); } +UartForm::~UartForm() +{ + SerialPort::ClosePort(m_portnum); +} + void UartForm::ShowDataInEdit(const char*p) { if (nullptr == p) { std::cout << "ShowDataInEdit " << std::endl; diff --git a/examples/proto_debuger/uart_process.h b/examples/proto_debuger/uart_process.h index c112ca84..edf0474f 100644 --- a/examples/proto_debuger/uart_process.h +++ b/examples/proto_debuger/uart_process.h @@ -17,25 +17,26 @@ #include "lua_wraper.h" #include "global.h" - class UartForm : public ui::ChildBox, LuaBindInterface { public: - UartForm(ui::Window* window,std::wstring name, uint32_t baurate, + UartForm(ui::Window* window,std::wstring name, + uint32_t baurate, UINT portnum, uint8_t data_bits, uint8_t stop_bits, uint8_t verify, uint8_t flow_control); + ~UartForm(); void ShowDataInEdit(const char*) override; void OnUpdateUart(); LuaDelegate* LuaVM(); /// 重写父类方法,提供个性化功能,请参考父类声明 virtual void Init() override; - void UpdateRecvEdit(); + UINT m_portnum; std::wstring m_name; uint32_t m_baurate; uint8_t m_data_bits; @@ -49,7 +50,6 @@ public: ui::RichEdit* mEditSend; ui::RichEdit* mEditRecv; ui::RichEdit* mEditLua; - HWND m_hwnd; LuaDelegate* mLua;