237 lines
6.8 KiB
C++
237 lines
6.8 KiB
C++
#include "new_monitor_form.h"
|
||
|
||
#include <atlstr.h>
|
||
#include <setupapi.h>
|
||
#include <vector>
|
||
|
||
using namespace std;
|
||
|
||
const std::wstring NewMonitorForm::kClassName = L"Basic";
|
||
|
||
|
||
vector<wstring> EnumPortsWdm()
|
||
{
|
||
int i, dwDetDataSize;
|
||
vector<wstring> ret;
|
||
TCHAR fname[256], locinfo[256];
|
||
HDEVINFO hDevInfo;
|
||
SP_DEVICE_INTERFACE_DETAIL_DATA* pDetData;
|
||
SP_DEVICE_INTERFACE_DATA ifcData;
|
||
SP_DEVINFO_DATA devdata;
|
||
|
||
static const GUID ___GUID_CLASS_COMPORT = \
|
||
{ 0x86E0D1E0L, 0x8089, 0x11D0, { 0x9C, 0xE4, 0x08, 0x00, 0x3E, 0x30, 0x1F, 0x73 } };
|
||
/*static const GUID ___GUID_CLASS_COMPORT = \
|
||
{ 0xAD498944, 0x762F, 0x11D0, { 0x8D, 0xCB, 0x00, 0xC0, 0x4F, 0xC3, 0x35, 0x8C } };*/
|
||
|
||
|
||
hDevInfo = SetupDiGetClassDevs(&___GUID_CLASS_COMPORT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
|
||
if (hDevInfo == INVALID_HANDLE_VALUE)
|
||
{
|
||
return ret;
|
||
}
|
||
|
||
dwDetDataSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) + 256;
|
||
pDetData = (SP_DEVICE_INTERFACE_DETAIL_DATA*)calloc(1, dwDetDataSize);
|
||
if (!pDetData)
|
||
{
|
||
SetupDiDestroyDeviceInfoList(hDevInfo);
|
||
return ret;
|
||
}
|
||
|
||
ifcData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
||
pDetData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||
|
||
for (i = 0; SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &___GUID_CLASS_COMPORT, i, &ifcData); i++)
|
||
{
|
||
memset(&devdata, 0, sizeof(SP_DEVINFO_DATA));
|
||
devdata.cbSize = sizeof(SP_DEVINFO_DATA);
|
||
|
||
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, &ifcData, pDetData, dwDetDataSize, NULL, &devdata))
|
||
{
|
||
break;
|
||
}
|
||
|
||
if (SetupDiGetDeviceRegistryProperty(hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL, (PBYTE)fname, sizeof(fname), NULL))
|
||
{
|
||
ret.push_back(wstring(fname));
|
||
}
|
||
|
||
if (SetupDiGetDeviceRegistryProperty(hDevInfo, &devdata, SPDRP_LOCATION_INFORMATION, NULL, (PBYTE)locinfo, sizeof(locinfo), NULL))
|
||
{
|
||
if (StrCmpN(locinfo, TEXT("USB"), 3) == 0)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
|
||
free(pDetData);
|
||
SetupDiDestroyDeviceInfoList(hDevInfo);
|
||
return ret;
|
||
}
|
||
|
||
NewMonitorForm::NewMonitorForm()
|
||
{
|
||
|
||
}
|
||
|
||
NewMonitorForm::~NewMonitorForm()
|
||
{
|
||
}
|
||
|
||
std::wstring NewMonitorForm::GetSkinFolder()
|
||
{
|
||
return L"basic";
|
||
}
|
||
|
||
std::wstring NewMonitorForm::GetSkinFile()
|
||
{
|
||
return L"newmonitor.xml";
|
||
}
|
||
|
||
std::wstring NewMonitorForm::GetWindowClassName() const
|
||
{
|
||
return kClassName;
|
||
}
|
||
|
||
LRESULT NewMonitorForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||
{
|
||
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
|
||
}
|
||
|
||
void NewMonitorForm::InitWindow()
|
||
{
|
||
ui::Button* btn_add_new = dynamic_cast<ui::Button*>(FindControl(L"exit_button"));
|
||
if (nullptr != btn_add_new) {
|
||
btn_add_new->SetText(L"<EFBFBD>˳<EFBFBD>");
|
||
btn_add_new->AttachClick([this](ui::EventArgs*) {
|
||
this->Close();
|
||
return true;
|
||
});
|
||
}
|
||
m_combo_type = dynamic_cast<ui::Combo*>(FindControl(L"combo_type"));
|
||
if (NULL != m_combo_type) {
|
||
ui::ListContainerElement* element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L""));
|
||
|
||
m_combo_type->Add(element);
|
||
|
||
element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L"uart"));
|
||
|
||
m_combo_type->Add(element);
|
||
|
||
element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L"tcp client"));
|
||
m_combo_type->Add(element);
|
||
|
||
element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L"tcp server"));
|
||
m_combo_type->Add(element);
|
||
|
||
element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L"udp client"));
|
||
m_combo_type->Add(element);
|
||
|
||
element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L"udp server"));
|
||
m_combo_type->Add(element);
|
||
}
|
||
m_ip_config_vbox = dynamic_cast<ui::VBox*>(FindControl(L"ip_config"));
|
||
m_uart_config_vbox = dynamic_cast<ui::VBox*>(FindControl(L"uart_config"));
|
||
|
||
m_uart_select_combo = dynamic_cast<ui::Combo*>(FindControl(L"uart_type"));
|
||
m_uart_baurate_select = dynamic_cast<ui::Combo*>(FindControl(L"uart_baurate_select"));
|
||
|
||
m_combo_type->AttachAllEvents([this](ui::EventArgs* ev) {
|
||
if (nullptr != ev) {
|
||
auto p = static_cast<ui::Combo*>(ev->pSender);
|
||
if (ev->Type == 42) {
|
||
auto text = p->GetText();
|
||
wprintf(L"%s\r\n", text.c_str());
|
||
|
||
if (text == L"uart") {
|
||
this->m_ip_config_vbox->SetVisible(false);
|
||
this->m_uart_config_vbox->SetVisible(true);
|
||
auto ports = EnumPortsWdm();
|
||
this->m_uart_select_combo->RemoveAll();
|
||
for (auto x : ports) {
|
||
ui::ListContainerElement* element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L"%s", &x.c_str()[x.find(L"COM")]));
|
||
|
||
this->m_uart_select_combo->Add(element);
|
||
}
|
||
vector<wstring> baurate;
|
||
baurate.push_back(L"110");
|
||
baurate.push_back(L"300");
|
||
baurate.push_back(L"600");
|
||
baurate.push_back(L"1200");
|
||
baurate.push_back(L"2400");
|
||
baurate.push_back(L"4800");
|
||
baurate.push_back(L"9600");
|
||
baurate.push_back(L"14400");
|
||
baurate.push_back(L"19200");
|
||
baurate.push_back(L"38400");
|
||
baurate.push_back(L"56000");
|
||
baurate.push_back(L"57600");
|
||
baurate.push_back(L"115200");
|
||
|
||
baurate.push_back(L"128000");
|
||
baurate.push_back(L"256000");
|
||
|
||
m_uart_baurate_select->RemoveAll();
|
||
for (auto baus : baurate) {
|
||
ui::ListContainerElement* element = new ui::ListContainerElement;
|
||
element->SetClass(L"listitem");
|
||
element->SetFixedHeight(30);
|
||
element->SetBkColor(L"white");
|
||
element->SetTextPadding({ 6,0,6,0 });
|
||
element->SetText(nbase::StringPrintf(L"%s", baus.c_str()));
|
||
this->m_uart_baurate_select->Add(element);
|
||
}
|
||
|
||
}
|
||
if ((text == L"tcp client")|| (text == L"tcp server") ||
|
||
(text == L"udp client") || (text == L"udp server")) {
|
||
this->m_ip_config_vbox->SetVisible(true);
|
||
this->m_uart_config_vbox->SetVisible(false);
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
});
|
||
}
|
||
|
||
LRESULT NewMonitorForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||
{
|
||
return __super::OnClose(uMsg, wParam, lParam, bHandled);
|
||
}
|