mirror of
https://github.com/HEYAHONG/SimpleBLETool.git
synced 2025-05-08 05:26:40 +08:00
添加RSSI查看
This commit is contained in:
parent
ae1612379c
commit
bfb406350f
83
BLERSSIDialog.cpp
Normal file
83
BLERSSIDialog.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#include "BLERSSIDialog.h"
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include "time.h"
|
||||
|
||||
|
||||
BLERSSIDialog::BLERSSIDialog( wxWindow* parent):GUIBLERSSIDialog(parent)
|
||||
{
|
||||
//ctor
|
||||
mainwindow=dynamic_cast<SimpleBLEToolFrame *>(parent);
|
||||
if(mainwindow==NULL)
|
||||
{
|
||||
wxLogMessage(_T("此窗口必须由主窗口调用"));
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
auto cb=[&](SimpleBLE::Peripheral perh)
|
||||
{
|
||||
if(!Perh.initialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(Perh.address()==perh.address())
|
||||
{
|
||||
int rssi=perh.rssi();
|
||||
auto uicb=[=]()
|
||||
{
|
||||
wxDataViewListStore *store=m_dataViewListCtrl->GetStore();
|
||||
wxVector< wxVariant > data;
|
||||
data.push_back(wxString(std::to_string(rssi)));
|
||||
wxString time_stamp;
|
||||
{
|
||||
std::stringstream out;
|
||||
using namespace std::chrono;
|
||||
std::chrono::system_clock::time_point t = std::chrono::system_clock::now();
|
||||
time_t c = std::chrono::system_clock::to_time_t(t);
|
||||
struct tm m_tm;
|
||||
#ifdef WIN32
|
||||
localtime_s(&m_tm,&c);
|
||||
#else
|
||||
localtime_r(&c,&m_tm);
|
||||
#endif // WIN32
|
||||
|
||||
out<<std::put_time(&m_tm, "%F %T ") <<std::setfill('0')<<std::setw(3)<<(std::chrono::duration_cast<std::chrono::milliseconds>(t.time_since_epoch()) % 1000).count();
|
||||
time_stamp=out.str();
|
||||
}
|
||||
data.push_back(time_stamp);
|
||||
store->InsertItem(0,data);
|
||||
};
|
||||
mainwindow->AddUpdateUIFuncitonByOther(uicb);
|
||||
}
|
||||
};
|
||||
mainwindow->RegisterScanUpdateCallback(this,cb);
|
||||
}
|
||||
|
||||
BLERSSIDialog::~BLERSSIDialog()
|
||||
{
|
||||
//dtor
|
||||
mainwindow->UnRegistterScanUpdateCallback(this);
|
||||
if(OnCloseCb!=NULL)
|
||||
{
|
||||
OnCloseCb();
|
||||
}
|
||||
}
|
||||
|
||||
void BLERSSIDialog::SetBLEPerh(SimpleBLE::Peripheral _Perh)
|
||||
{
|
||||
SetTitle(wxString(_Perh.identifier()) + " [" << _Perh.address() + "] ");
|
||||
Perh=_Perh;
|
||||
}
|
||||
|
||||
void BLERSSIDialog::SetOnClose(std::function<void(void)> OnClose)
|
||||
{
|
||||
OnCloseCb=OnClose;
|
||||
}
|
||||
|
||||
void BLERSSIDialog::OnClose( wxCloseEvent& event )
|
||||
{
|
||||
Destroy();
|
||||
}
|
28
BLERSSIDialog.h
Normal file
28
BLERSSIDialog.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef BLERSSIDIALOG_H
|
||||
#define BLERSSIDIALOG_H
|
||||
|
||||
#include "SimpleBLEToolMain.h"
|
||||
#include "wx/log.h"
|
||||
|
||||
class BLERSSIDialog:public GUIBLERSSIDialog
|
||||
{
|
||||
|
||||
public:
|
||||
BLERSSIDialog( wxWindow* parent);
|
||||
virtual ~BLERSSIDialog();
|
||||
|
||||
void SetBLEPerh(SimpleBLE::Peripheral _Perh);
|
||||
|
||||
void SetOnClose(std::function<void(void)> OnClose);
|
||||
|
||||
protected:
|
||||
virtual void OnClose( wxCloseEvent& event );
|
||||
|
||||
private:
|
||||
SimpleBLEToolFrame *mainwindow;
|
||||
SimpleBLE::Peripheral Perh;
|
||||
|
||||
std::function<void(void)> OnCloseCb;
|
||||
};
|
||||
|
||||
#endif // BLERSSIDIALOG_H
|
29
GUIFrame.cpp
29
GUIFrame.cpp
@ -164,3 +164,32 @@ GUIAboutDialog::GUIAboutDialog( wxWindow* parent, wxWindowID id, const wxString&
|
||||
GUIAboutDialog::~GUIAboutDialog()
|
||||
{
|
||||
}
|
||||
|
||||
GUIBLERSSIDialog::GUIBLERSSIDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
|
||||
{
|
||||
this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize );
|
||||
|
||||
wxBoxSizer* bSizer5;
|
||||
bSizer5 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_dataViewListCtrl = new wxDataViewListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_dataViewListColumn_RSSI = m_dataViewListCtrl->AppendTextColumn( wxT("RSSI(dbm)"), wxDATAVIEW_CELL_INERT, -1, static_cast<wxAlignment>(wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL), wxDATAVIEW_COL_RESIZABLE );
|
||||
m_dataViewListColumn_Time = m_dataViewListCtrl->AppendTextColumn( wxT("时间"), wxDATAVIEW_CELL_INERT, -1, static_cast<wxAlignment>(wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL), wxDATAVIEW_COL_RESIZABLE );
|
||||
bSizer5->Add( m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5 );
|
||||
|
||||
|
||||
this->SetSizer( bSizer5 );
|
||||
this->Layout();
|
||||
|
||||
this->Centre( wxBOTH );
|
||||
|
||||
// Connect Events
|
||||
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( GUIBLERSSIDialog::OnClose ) );
|
||||
}
|
||||
|
||||
GUIBLERSSIDialog::~GUIBLERSSIDialog()
|
||||
{
|
||||
// Disconnect Events
|
||||
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( GUIBLERSSIDialog::OnClose ) );
|
||||
|
||||
}
|
||||
|
25
GUIFrame.h
25
GUIFrame.h
@ -29,6 +29,7 @@
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/hyperlink.h>
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/dataview.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -95,3 +96,27 @@ class GUIAboutDialog : public wxDialog
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// Class GUIBLERSSIDialog
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class GUIBLERSSIDialog : public wxDialog
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
wxDataViewListCtrl* m_dataViewListCtrl;
|
||||
wxDataViewColumn* m_dataViewListColumn_RSSI;
|
||||
wxDataViewColumn* m_dataViewListColumn_Time;
|
||||
|
||||
// Virtual event handlers, override them in your derived class
|
||||
virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
GUIBLERSSIDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 400,600 ), long style = wxDEFAULT_DIALOG_STYLE );
|
||||
|
||||
~GUIBLERSSIDialog();
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,30 +1,30 @@
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif //__BORLANDC__
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif //WX_PRECOMP
|
||||
#include "SimpleBLEToolGUIFrame.h"
|
||||
|
||||
SimpleBLEToolGUIFrame::SimpleBLEToolGUIFrame( wxWindow* parent )
|
||||
:
|
||||
GUIFrame( parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleBLEToolGUIFrame::OnClose( wxCloseEvent& event )
|
||||
{
|
||||
// TODO: Implement OnClose
|
||||
}
|
||||
|
||||
void SimpleBLEToolGUIFrame::OnAbout( wxCommandEvent& event )
|
||||
{
|
||||
// TODO: Implement OnAbout
|
||||
}
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif //__BORLANDC__
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif //WX_PRECOMP
|
||||
#include "SimpleBLEToolGUIFrame.h"
|
||||
|
||||
SimpleBLEToolGUIFrame::SimpleBLEToolGUIFrame( wxWindow* parent )
|
||||
:
|
||||
GUIFrame( parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleBLEToolGUIFrame::OnClose( wxCloseEvent& event )
|
||||
{
|
||||
// TODO: Implement OnClose
|
||||
}
|
||||
|
||||
void SimpleBLEToolGUIFrame::OnAbout( wxCommandEvent& event )
|
||||
{
|
||||
// TODO: Implement OnAbout
|
||||
}
|
||||
|
||||
SimpleBLEToolGUIFrame::~SimpleBLEToolGUIFrame()
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "simpleble/Utils.h"
|
||||
#include "simpleble/Logging.h"
|
||||
#include <wx/treectrl.h>
|
||||
|
||||
#include "BLERSSIDialog.h"
|
||||
/*
|
||||
wxTreeCtrl的item
|
||||
*/
|
||||
@ -37,18 +37,21 @@ public:
|
||||
adapter.set_callback_on_scan_found([](SimpleBLE::Peripheral) {});
|
||||
}
|
||||
};
|
||||
|
||||
class wxTreeCtrlAdapterPerhItemData:public wxTreeItemData
|
||||
{
|
||||
public:
|
||||
SimpleBLE::Peripheral Perh;
|
||||
BLERSSIDialog *rssi_dlg;
|
||||
wxTreeCtrlAdapterPerhItemData(SimpleBLE::Peripheral _Perh):Perh(_Perh)
|
||||
{
|
||||
|
||||
rssi_dlg=NULL;
|
||||
}
|
||||
virtual ~wxTreeCtrlAdapterPerhItemData()
|
||||
{
|
||||
|
||||
if(rssi_dlg!=NULL)
|
||||
{
|
||||
rssi_dlg->Close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -104,8 +107,8 @@ SimpleBLEToolFrame::SimpleBLEToolFrame(wxFrame *frame)
|
||||
|
||||
SimpleBLEToolFrame::~SimpleBLEToolFrame()
|
||||
{
|
||||
m_treeCtrl_adapter->DeleteAllItems();
|
||||
wxLog::EnableLogging(false);
|
||||
m_treeCtrl_adapter->DeleteAllItems();
|
||||
wxLog::EnableLogging(false);
|
||||
}
|
||||
|
||||
void SimpleBLEToolFrame::OnClose(wxCloseEvent &event)
|
||||
@ -187,6 +190,29 @@ void SimpleBLEToolFrame::OnTreeAdapterRightClick( wxTreeEvent& event )
|
||||
PopupMenu(&menu);
|
||||
}
|
||||
}
|
||||
{
|
||||
wxTreeCtrlAdapterPerhItemData * _Data=dynamic_cast<wxTreeCtrlAdapterPerhItemData *>(data);
|
||||
if(_Data!=NULL)
|
||||
{
|
||||
wxMenu menu;
|
||||
{
|
||||
auto menufunc=[&]( wxCommandEvent& event )
|
||||
{
|
||||
if(_Data->rssi_dlg==NULL)
|
||||
{
|
||||
_Data->rssi_dlg=new BLERSSIDialog(this);
|
||||
_Data->rssi_dlg->SetBLEPerh(_Data->Perh);
|
||||
_Data->rssi_dlg->SetOnClose([=](){_Data->rssi_dlg=NULL;});
|
||||
}
|
||||
_Data->rssi_dlg->Show();
|
||||
};
|
||||
wxMenuItem *item=menu.Append(1000,_T("实时RSSI数据"));
|
||||
menu.Bind(wxEVT_COMMAND_MENU_SELECTED,menufunc,item->GetId(),item->GetId());
|
||||
}
|
||||
menu.AppendSeparator();
|
||||
PopupMenu(&menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,6 +309,17 @@ void SimpleBLEToolFrame::UpdateBLEAdapterList()
|
||||
wxString adapter_addr=adapter.address();
|
||||
auto cb=[=](SimpleBLE::Peripheral perh)
|
||||
{
|
||||
{
|
||||
//调用回调函数
|
||||
std::lock_guard<std::mutex> lock(ScanUpdateMapLock);
|
||||
for(auto pair:ScanUpdateMap)
|
||||
{
|
||||
if(pair.second!=NULL)
|
||||
{
|
||||
pair.second(perh);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(PerhList_Lock);
|
||||
std::map<wxString,std::map<wxString,wxTreeCtrlAdapterPerhID>> &PerhList=this->PerhList;
|
||||
wxTreeCtrlAdapterPerhID ID;
|
||||
@ -327,3 +364,27 @@ void SimpleBLEToolFrame::UpdateBLEAdapterList()
|
||||
|
||||
AddUpdateUIFunciton(cb);
|
||||
}
|
||||
|
||||
|
||||
void SimpleBLEToolFrame::RegisterScanUpdateCallback(void * owner,std::function<void (SimpleBLE::Peripheral)>cb)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(ScanUpdateMapLock);
|
||||
if(owner!=NULL)
|
||||
{
|
||||
ScanUpdateMap[owner]=cb;
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleBLEToolFrame::UnRegistterScanUpdateCallback(void *owner)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(ScanUpdateMapLock);
|
||||
if(ScanUpdateMap.find(owner)!=ScanUpdateMap.end())
|
||||
{
|
||||
ScanUpdateMap.erase(owner);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleBLEToolFrame::AddUpdateUIFuncitonByOther(std::function<void(void)> func)
|
||||
{
|
||||
AddUpdateUIFunciton(func);
|
||||
}
|
||||
|
@ -10,8 +10,9 @@
|
||||
#ifndef SIMPLEBLETOOLMAIN_H
|
||||
#define SIMPLEBLETOOLMAIN_H
|
||||
|
||||
|
||||
|
||||
#include "simpleble/Adapter.h"
|
||||
#include "simpleble/PeripheralSafe.h"
|
||||
#include "simpleble/Utils.h"
|
||||
#include "SimpleBLEToolApp.h"
|
||||
|
||||
|
||||
@ -39,6 +40,20 @@ public:
|
||||
std::map<wxString,std::map<wxString,wxTreeCtrlAdapterPerhID>> PerhList;
|
||||
std::mutex PerhList_Lock;
|
||||
|
||||
/*
|
||||
注册扫描更新回调函数
|
||||
*/
|
||||
void RegisterScanUpdateCallback(void * owner,std::function<void (SimpleBLE::Peripheral)>cb);
|
||||
/*
|
||||
取消注册扫描更新函数
|
||||
*/
|
||||
void UnRegistterScanUpdateCallback(void *owner);
|
||||
|
||||
/*
|
||||
添加更新UI操作
|
||||
*/
|
||||
void AddUpdateUIFuncitonByOther(std::function<void(void)> func);
|
||||
|
||||
private:
|
||||
virtual void OnClose(wxCloseEvent& event);
|
||||
virtual void OnQuit(wxCommandEvent& event);
|
||||
@ -87,7 +102,11 @@ private:
|
||||
|
||||
void UpdateBLEAdapterList();
|
||||
|
||||
|
||||
/*
|
||||
扫描更新相关数据
|
||||
*/
|
||||
std::map<void *,std::function<void (SimpleBLE::Peripheral)>> ScanUpdateMap;
|
||||
std::mutex ScanUpdateMapLock;
|
||||
};
|
||||
|
||||
#endif // SIMPLEBLETOOLMAIN_H
|
||||
|
@ -647,5 +647,89 @@
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="Dialog" expanded="0">
|
||||
<property name="aui_managed">0</property>
|
||||
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
|
||||
<property name="bg"></property>
|
||||
<property name="center">wxBOTH</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="event_handler">impl_virtual</property>
|
||||
<property name="extra_style"></property>
|
||||
<property name="fg"></property>
|
||||
<property name="font"></property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="minimum_size">-1,-1</property>
|
||||
<property name="name">GUIBLERSSIDialog</property>
|
||||
<property name="pos"></property>
|
||||
<property name="size">400,600</property>
|
||||
<property name="style">wxDEFAULT_DIALOG_STYLE</property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="title"></property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="two_step_creation">0</property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnClose">OnClose</event>
|
||||
<object class="wxBoxSizer" expanded="0">
|
||||
<property name="minimum_size"></property>
|
||||
<property name="name">bSizer5</property>
|
||||
<property name="orient">wxVERTICAL</property>
|
||||
<property name="permission">none</property>
|
||||
<object class="sizeritem" expanded="0">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL|wxEXPAND</property>
|
||||
<property name="proportion">1</property>
|
||||
<object class="wxDataViewListCtrl" expanded="0">
|
||||
<property name="bg"></property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="font"></property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="name">m_dataViewListCtrl</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="pos"></property>
|
||||
<property name="size"></property>
|
||||
<property name="style"></property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<object class="dataViewListColumn" expanded="0">
|
||||
<property name="align">wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</property>
|
||||
<property name="ellipsize"></property>
|
||||
<property name="flags">wxDATAVIEW_COL_RESIZABLE</property>
|
||||
<property name="label">RSSI(dbm)</property>
|
||||
<property name="mode">wxDATAVIEW_CELL_INERT</property>
|
||||
<property name="name">m_dataViewListColumn_RSSI</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="type">Text</property>
|
||||
<property name="width">-1</property>
|
||||
</object>
|
||||
<object class="dataViewListColumn" expanded="0">
|
||||
<property name="align">wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</property>
|
||||
<property name="ellipsize"></property>
|
||||
<property name="flags">wxDATAVIEW_COL_RESIZABLE</property>
|
||||
<property name="label">时间</property>
|
||||
<property name="mode">wxDATAVIEW_CELL_INERT</property>
|
||||
<property name="name">m_dataViewListColumn_Time</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="type">Text</property>
|
||||
<property name="width">-1</property>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</wxFormBuilder_Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user