nim_duilib/examples/proto_debuger/tcp_client_form.cpp

84 lines
2.4 KiB
C++
Raw Normal View History

2021-10-11 00:00:10 +08:00
#include "tcp_client_form.h"
2021-11-21 13:47:19 +08:00
#include "utils.h"
2021-10-11 00:00:10 +08:00
2021-11-22 23:53:21 +08:00
TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, TcpClientLibevent* p):
m_connected(false),
mLua(nullptr)
2021-10-11 00:00:10 +08:00
{
mClient = p;
2021-11-22 23:53:21 +08:00
mClient->SetObserver(this);
2021-10-11 00:54:04 +08:00
if (nullptr != hwnd) {
this->SetWindow(hwnd, nullptr, false);
}
2021-11-21 13:47:19 +08:00
m_url = url;
m_port = port;
mLua = new LuaDelegate();
2021-10-11 00:00:10 +08:00
}
void TcpClientForm::Init()
{
2021-10-11 00:54:04 +08:00
ui::ChildBox::Init();
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"uart_info_label"));
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script"));
2021-11-22 23:53:21 +08:00
m_uart_send_edit = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
m_btn_send_data = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
2021-10-11 00:54:04 +08:00
m_check_box_1 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_new_line"));
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
m_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
2021-10-11 00:00:10 +08:00
2021-11-21 13:47:19 +08:00
wchar_t p[100] = { 0 };
2021-11-22 23:53:21 +08:00
wsprintf(p, L"<EFBFBD><EFBFBD>ַ%s,<2C>˿ں<CBBF>%d δ<><CEB4><EFBFBD><EFBFBD>", string2wstring(m_url).c_str(),m_port);
2021-11-21 13:47:19 +08:00
m_label_1->SetText(std::wstring(p));
2021-11-22 23:53:21 +08:00
m_btn_send_data->AttachAllEvents([this](ui::EventArgs* ev) {
if (ev->Type == ui::EventType::kEventClick) {
std::wcout << m_uart_send_edit->GetText() << std::endl;
auto data = wstring2string(m_uart_send_edit->GetText());
2021-11-24 00:37:05 +08:00
if (m_check_box_1->IsSelected()) {
data += std::string("\r\n");
}
2021-11-22 23:53:21 +08:00
this->ClientEvent()->SendDataAsync(data.c_str(), data.size());
}
return true;
});
}
TcpClientLibevent* TcpClientForm::ClientEvent()
{
return mClient;
}
void TcpClientForm::OnConnected()
{
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>\r\n"<<__FILE__<<" " << __LINE__ << std::endl;
wchar_t p[100] = { 0 };
wsprintf(p, L"<EFBFBD><EFBFBD>ַ%s,<2C>˿ں<CBBF>%d <20><><EFBFBD>ӳɹ<D3B3>", string2wstring(m_url).c_str(), m_port);
m_label_1->SetText(std::wstring(p));
}
void TcpClientForm::OnDisConnected(std::string reason)
{
wchar_t p[100] = { 0 };
wsprintf(p, L"<EFBFBD><EFBFBD>ַ%s,<2C>˿ں<CBBF>%d δ<><CEB4><EFBFBD><EFBFBD> " , string2wstring(m_url).c_str(), m_port);
m_label_1->SetText(std::wstring(p) + L" " + string2wstring(reason));
m_connected = false;
}
void TcpClientForm::OnData(uint8_t* dat, uint64_t len)
{
std::cout << (char*)dat << std::endl;
}
void TcpClientForm::OnClose()
{
2021-10-11 00:00:10 +08:00
}
2021-10-12 00:51:48 +08:00
2021-10-11 00:00:10 +08:00
void TcpClientForm::HandleMessage(ui::EventArgs& msg)
{
}