Skip to content

Commit

Permalink
Mac PC-Host
Browse files Browse the repository at this point in the history
  • Loading branch information
GCY committed Mar 6, 2021
1 parent 171f7bf commit 9219d0e
Show file tree
Hide file tree
Showing 11 changed files with 6,864 additions and 0 deletions.
Binary file added Pulse Oximeter Monitor/Mac/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions Pulse Oximeter Monitor/Mac/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all:
g++ -o2 -o main.app main.cpp mathplot.cpp connectargsdlg.cpp serialport.cpp enumserial.cpp `wx-config --cxxflags --libs` --std=c++11 -m64 -D _MAC_
./main.app
87 changes: 87 additions & 0 deletions Pulse Oximeter Monitor/Mac/connectargsdlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "connectargsdlg.h"

IMPLEMENT_CLASS(ConnectArgsDialog,wxDialog)

ConnectArgsDialog::ConnectArgsDialog()
{
Init();
}

ConnectArgsDialog::ConnectArgsDialog(wxWindow *parent,wxWindowID id,const wxString &caption,const wxPoint &pos,const wxSize &size,long style)
{
Create(parent,id,caption,pos,size,style);
Init();
}

inline void ConnectArgsDialog::Init()
{
}

bool ConnectArgsDialog::Create(wxWindow *parent,wxWindowID id,const wxString &caption,const wxPoint &pos,const wxSize &size,long style)
{
SetExtraStyle(wxWS_EX_BLOCK_EVENTS | wxDIALOG_EX_CONTEXTHELP);

if(!wxDialog::Create(parent,id,caption,pos,size,style)){
return false;
}

CreateControls();

GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);

Center();

return true;
}

void ConnectArgsDialog::CreateControls()
{
wxBoxSizer *top = new wxBoxSizer(wxVERTICAL);
this->SetSizer(top);

wxBoxSizer *box = new wxBoxSizer(wxHORIZONTAL);
top->Add(box,0,wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL,5);

std::vector<std::string> vector_paths = enumserial.EnumSerialPort();
wxArrayString paths;
for(size_t i = 0;i < vector_paths.size();++i){
paths.Add(vector_paths[i]);
}

device_path = new wxChoice(this,wxID_ANY,wxDefaultPosition,wxDefaultSize,paths);
box->Add(device_path,0,wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL,5);

wxArrayString speed;
speed.Add(wxT("300"));
speed.Add(wxT("1200"));
speed.Add(wxT("2400"));
speed.Add(wxT("4800"));
speed.Add(wxT("9600"));
speed.Add(wxT("19200"));
speed.Add(wxT("38400"));
speed.Add(wxT("57600"));
speed.Add(wxT("115200"));

baud_rate = new wxChoice(this,wxID_ANY,wxDefaultPosition,wxDefaultSize,speed);
box->Add(baud_rate,0,wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL,5);

wxBoxSizer *ResetOkCancelBox = new wxBoxSizer(wxHORIZONTAL);
top->Add(ResetOkCancelBox,0,wxALIGN_CENTER_HORIZONTAL | wxALL,5);

wxButton *ok = new wxButton(this,wxID_OK,wxT("&Ok"),wxDefaultPosition,wxDefaultSize,0);
ResetOkCancelBox->Add(ok,0,wxALIGN_CENTER_VERTICAL | wxALL,5);

wxButton *cancel = new wxButton(this,wxID_CANCEL,wxT("&Cancel"),wxDefaultPosition,wxDefaultSize,0);
ResetOkCancelBox->Add(cancel,0,wxALIGN_CENTER_VERTICAL | wxALL,5);
}

bool ConnectArgsDialog::TransferDataToWindow()
{
return true;
}

bool ConnectArgsDialog::TransferDataFromWindow()
{
return true;
}
49 changes: 49 additions & 0 deletions Pulse Oximeter Monitor/Mac/connectargsdlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef __CONNECT_ARGS_DIALOG__
#define __CONNECT_ARGS_DIALOG__
#include <wx/wx.h>

#include "enumserial.h"

class ConnectArgsDialog:public wxDialog
{
public:
ConnectArgsDialog();

ConnectArgsDialog(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxString &caption = wxT("Connect Args"),
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU);

bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxString &caption = wxT("Connect Args"),
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU);

void Init();
void CreateControls();

bool TransferDataToWindow();
bool TransferDataFromWindow();

#ifdef _WIN_
wxString GetDevicePath() { return device_path->GetString(device_path->GetCurrentSelection()); }
#elif _MAC_
wxString GetDevicePath(){return enumserial.GetRoot() + device_path->GetString(device_path->GetCurrentSelection());}
#endif
wxString GetBaudRate(){return baud_rate->GetString(baud_rate->GetCurrentSelection());}

private:

EnumSerial enumserial;

wxChoice *device_path;
wxChoice *baud_rate;

DECLARE_CLASS(ConnectArgsDialog)
};

#endif
55 changes: 55 additions & 0 deletions Pulse Oximeter Monitor/Mac/enumserial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "enumserial.h"

EnumSerial::EnumSerial()
{
}

std::vector<std::string> EnumSerial::EnumSerialPort()
{
std::vector<std::string> paths;
#ifdef _WIN_
//search com

if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &hkey ))
{
unsigned long index = 0;
long return_value;

while ((return_value = RegEnumValue(hkey, index, key_valuename, &len_valuename, 0,
&key_type, (LPBYTE)key_valuedata,&len_valuedata)) == ERROR_SUCCESS)
{
if (key_type == REG_SZ)
{
std::wstring key_valuedata_ws(key_valuedata);
std::string key_valuedata_str(key_valuedata_ws.begin(), key_valuedata_ws.end());
paths.push_back(key_valuedata_str);
}
len_valuename = 1000;
len_valuedata = 1000;
index++;
}
}
// close key
RegCloseKey(hkey);
#elif _MAC_
root = std::string("/dev/");
DIR *dp;
struct dirent *dirp;
if((dp = opendir(root.c_str())) == NULL) {
}
while ((dirp = readdir(dp)) != NULL) {
std::string filename(dirp->d_name);
if(filename.find(std::string("cu.")) != std::string::npos){
paths.push_back(std::string(dirp->d_name));
continue;
}
if(filename.find(std::string("tty.")) != std::string::npos){
paths.push_back(std::string(dirp->d_name));
continue;
}
}
closedir(dp);
#endif

return paths;
}
44 changes: 44 additions & 0 deletions Pulse Oximeter Monitor/Mac/enumserial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef __ENUM_SERIAL__
#define __ENUM_SERIAL__

#include <iostream>
#include <string>
#include <vector>

#ifdef _WIN_
#include <atlbase.h>
#include <windows.h>
#include <tchar.h>
#include "dirent.h"

#elif _MAC_
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#endif

class EnumSerial
{
public:
EnumSerial();
std::vector<std::string> EnumSerialPort();
#ifdef _MAC_
std::string GetRoot(){return root;}
#endif

private:

#ifdef _WIN_
TCHAR key_valuename[1000];
unsigned long len_valuename = 1000;
wchar_t key_valuedata[1000];
unsigned long len_valuedata = 1000;
unsigned long key_type;
HKEY hkey = NULL;
#elif _MAC_
std::string root;
#endif

};

#endif
Loading

0 comments on commit 9219d0e

Please sign in to comment.