耦合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);
|
mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node);
|
||||||
|
|
||||||
if (mUartForm.find(p->name) == mUartForm.end()) {
|
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);
|
p->data_bits, p->stop_bits, p->verify, p->flow_control);
|
||||||
form->SetChildLayoutXML(L"basic/uart_form.xml");
|
form->SetChildLayoutXML(L"basic/uart_form.xml");
|
||||||
form->SetName(p->name);
|
form->SetName(p->name);
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
//
|
//
|
||||||
#include "loger.h"
|
#include "loger.h"
|
||||||
using namespace Loger;
|
using namespace Loger;
|
||||||
string getTimeDate()
|
string getTimeDate() {
|
||||||
{
|
|
||||||
time_t timep;
|
time_t timep;
|
||||||
time (&timep);
|
time (&timep);
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
@ -12,8 +11,7 @@ string getTimeDate()
|
|||||||
return string(tmp);
|
return string(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
string getTime()
|
string getTime(){
|
||||||
{
|
|
||||||
time_t timep;
|
time_t timep;
|
||||||
time (&timep);
|
time (&timep);
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
@ -88,6 +86,7 @@ bool file_existed(string path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_C_Loger::_C_Loger(FILE *p) {
|
_C_Loger::_C_Loger(FILE *p) {
|
||||||
this->mFile = p;
|
this->mFile = p;
|
||||||
this->mCurrentDate = getTime();
|
this->mCurrentDate = getTime();
|
||||||
|
@ -115,6 +115,7 @@ void NewMonitorForm::InitWindow()
|
|||||||
// 打开成功
|
// 打开成功
|
||||||
MessageBox(0, L"打开成功", L"", 0);
|
MessageBox(0, L"打开成功", L"", 0);
|
||||||
UartInfo* p = new UartInfo;
|
UartInfo* p = new UartInfo;
|
||||||
|
p->port_num = PortNum;
|
||||||
p->name = m_uart_select_combo->GetText();
|
p->name = m_uart_select_combo->GetText();
|
||||||
p->baurate = 115200;
|
p->baurate = 115200;
|
||||||
p->data_bits = 8;
|
p->data_bits = 8;
|
||||||
@ -128,8 +129,7 @@ void NewMonitorForm::InitWindow()
|
|||||||
}
|
}
|
||||||
this->Close();
|
this->Close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}else {
|
||||||
else {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using namespace std;
|
|||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
wstring name;
|
wstring name;
|
||||||
|
UINT port_num;
|
||||||
uint32_t baurate;
|
uint32_t baurate;
|
||||||
uint8_t data_bits;
|
uint8_t data_bits;
|
||||||
uint8_t stop_bits;
|
uint8_t stop_bits;
|
||||||
|
@ -21,6 +21,19 @@ TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url,
|
|||||||
m_port = port;
|
m_port = port;
|
||||||
mFlagSelectClient = true;
|
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 );
|
TcpServerLibevent::OnAccept handler = std::bind(&TcpServerFrom::OnNewConnAccept, this,std::placeholders::_1 );
|
||||||
m_server->SetNewConnectionHandle(handler);
|
m_server->SetNewConnectionHandle(handler);
|
||||||
@ -41,7 +54,12 @@ void TcpServerFrom::Init()
|
|||||||
|
|
||||||
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"server_info"));
|
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_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_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_button_1 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
||||||
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
|
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include "lua_wraper.h"
|
#include "lua_wraper.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
class TcpServerFrom :
|
class TcpServerFrom :
|
||||||
public ui::ChildBox,
|
public ui::ChildBox,
|
||||||
@ -22,6 +23,7 @@ public:
|
|||||||
void OnDisConnected(ConnectionLibevent*);
|
void OnDisConnected(ConnectionLibevent*);
|
||||||
LuaDelegate* LuaVM();
|
LuaDelegate* LuaVM();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ShowDataInEdit(const char*) override;
|
void ShowDataInEdit(const char*) override;
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ private:
|
|||||||
uint32_t m_port;
|
uint32_t m_port;
|
||||||
ui::Label* m_label_1;
|
ui::Label* m_label_1;
|
||||||
ui::RichEdit* m_rich_edit_1;
|
ui::RichEdit* m_rich_edit_1;
|
||||||
ui::RichEdit* m_rich_edit_2;
|
ui::RichEdit* mEditLua;
|
||||||
ui::RichEdit* m_rich_edit_3;
|
ui::RichEdit* m_rich_edit_3;
|
||||||
ui::Button* m_button_1;
|
ui::Button* m_button_1;
|
||||||
ui::CheckBox* m_check_box_1;
|
ui::CheckBox* m_check_box_1;
|
||||||
@ -44,9 +46,10 @@ private:
|
|||||||
ui::Label* m_label_2;
|
ui::Label* m_label_2;
|
||||||
ui::Combo* m_combo_1;
|
ui::Combo* m_combo_1;
|
||||||
ui::Button* m_button_3;
|
ui::Button* m_button_3;
|
||||||
|
std::ifstream mLuaFile;
|
||||||
std::map<uint32_t, ConnectionLibevent*> mClients;
|
std::map<uint32_t, ConnectionLibevent*> mClients;
|
||||||
bool mFlagSelectClient;
|
bool mFlagSelectClient;
|
||||||
LuaDelegate *mLua;
|
LuaDelegate *mLua;
|
||||||
|
std::string mLuaScript;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,13 +6,14 @@
|
|||||||
#include "lua_bind.h"
|
#include "lua_bind.h"
|
||||||
|
|
||||||
UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
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 data_bits, uint8_t stop_bits,
|
||||||
uint8_t verify, uint8_t flow_control):
|
uint8_t verify, uint8_t flow_control):
|
||||||
m_thread_recv(nullptr),
|
m_thread_recv(nullptr),
|
||||||
mEditRecv(nullptr),
|
mEditRecv(nullptr),
|
||||||
mLua(nullptr)
|
mLua(nullptr)
|
||||||
{
|
{
|
||||||
|
m_portnum = portnum;
|
||||||
m_name = name;
|
m_name = name;
|
||||||
m_baurate = baurate;
|
m_baurate = baurate;
|
||||||
m_data_bits = data_bits;
|
m_data_bits = data_bits;
|
||||||
@ -65,6 +66,11 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
|||||||
this->mLua->BindFunction("showdata", LuaShowData);
|
this->mLua->BindFunction("showdata", LuaShowData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UartForm::~UartForm()
|
||||||
|
{
|
||||||
|
SerialPort::ClosePort(m_portnum);
|
||||||
|
}
|
||||||
|
|
||||||
void UartForm::ShowDataInEdit(const char*p) {
|
void UartForm::ShowDataInEdit(const char*p) {
|
||||||
if (nullptr == p) {
|
if (nullptr == p) {
|
||||||
std::cout << "ShowDataInEdit " << std::endl;
|
std::cout << "ShowDataInEdit " << std::endl;
|
||||||
|
@ -17,25 +17,26 @@
|
|||||||
#include "lua_wraper.h"
|
#include "lua_wraper.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
|
|
||||||
class UartForm :
|
class UartForm :
|
||||||
public ui::ChildBox,
|
public ui::ChildBox,
|
||||||
LuaBindInterface
|
LuaBindInterface
|
||||||
{
|
{
|
||||||
public:
|
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 data_bits,
|
||||||
uint8_t stop_bits,
|
uint8_t stop_bits,
|
||||||
uint8_t verify,
|
uint8_t verify,
|
||||||
uint8_t flow_control);
|
uint8_t flow_control);
|
||||||
|
~UartForm();
|
||||||
|
|
||||||
void ShowDataInEdit(const char*) override;
|
void ShowDataInEdit(const char*) override;
|
||||||
void OnUpdateUart();
|
void OnUpdateUart();
|
||||||
LuaDelegate* LuaVM();
|
LuaDelegate* LuaVM();
|
||||||
/// 重写父类方法,提供个性化功能,请参考父类声明
|
/// 重写父类方法,提供个性化功能,请参考父类声明
|
||||||
virtual void Init() override;
|
virtual void Init() override;
|
||||||
|
|
||||||
void UpdateRecvEdit();
|
void UpdateRecvEdit();
|
||||||
|
UINT m_portnum;
|
||||||
std::wstring m_name;
|
std::wstring m_name;
|
||||||
uint32_t m_baurate;
|
uint32_t m_baurate;
|
||||||
uint8_t m_data_bits;
|
uint8_t m_data_bits;
|
||||||
@ -49,7 +50,6 @@ public:
|
|||||||
ui::RichEdit* mEditSend;
|
ui::RichEdit* mEditSend;
|
||||||
ui::RichEdit* mEditRecv;
|
ui::RichEdit* mEditRecv;
|
||||||
ui::RichEdit* mEditLua;
|
ui::RichEdit* mEditLua;
|
||||||
|
|
||||||
|
|
||||||
HWND m_hwnd;
|
HWND m_hwnd;
|
||||||
LuaDelegate* mLua;
|
LuaDelegate* mLua;
|
||||||
|
Loading…
Reference in New Issue
Block a user