耦合lua层和tcp server
This commit is contained in:
parent
d25f4bf2b9
commit
9e0316c15a
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<ui::Label*>(FindSubControl(L"server_info"));
|
||||
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_recv_edit"));
|
||||
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script_edit"));
|
||||
mEditLua = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script_edit"));
|
||||
mEditLua->SetRich(true);
|
||||
mEditLua->SetReturnMsgWantCtrl(true);
|
||||
|
||||
mEditLua->SetText(string2wstring(mLuaScript));
|
||||
|
||||
m_rich_edit_3 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_send_edit"));
|
||||
m_button_1 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
||||
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <map>
|
||||
#include "lua_wraper.h"
|
||||
#include "global.h"
|
||||
#include <fstream>
|
||||
|
||||
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<uint32_t, ConnectionLibevent*> mClients;
|
||||
bool mFlagSelectClient;
|
||||
LuaDelegate *mLua;
|
||||
|
||||
std::string mLuaScript;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user