1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-23 02:38:52 -05:00

Added asio submodule for socket and created CompassOnlineSource. Needs testing. Some refinement to come for the source classes I think

This commit is contained in:
Gordon McCann 2022-01-23 13:48:14 -05:00
parent 5177908c02
commit de5fc21ccc
11 changed files with 205 additions and 22 deletions

3
.gitmodules vendored
View File

@ -14,3 +14,6 @@
[submodule "Navigator/vendor/glm"] [submodule "Navigator/vendor/glm"]
path = Navigator/vendor/glm path = Navigator/vendor/glm
url = https://github.com/g-truc/glm.git url = https://github.com/g-truc/glm.git
[submodule "Navigator\\vendor\\asio"]
path = Navigator\\vendor\\asio
url = https://github.com/chriskohlhoff/asio.git

View File

@ -23,19 +23,6 @@ namespace Navigator {
PushLayer(new EditorLayer()); PushLayer(new EditorLayer());
m_imgui_layer = new ImGuiLayer(); m_imgui_layer = new ImGuiLayer();
PushOverlay(m_imgui_layer); PushOverlay(m_imgui_layer);
/*
HistogramMap& histMap = HistogramMap::GetInstance();
histMap.AddHistogram(HistogramParameters("myHisto", "joseph", 100, 0, 10));
histMap.AddHistogram(HistogramParameters("myHisto2D", "joseph", "joseph", 100, 0, 10, 100, 0, 10));
CutMap::GetInstance().AddCut(CutParams("joe_cut","joseph"),0.0, 7.0);
CutMap::GetInstance().AddCut(CutParams("joe2D_cut", "joseph", "joseph"), { 1.0, 3.0, 3.0, 1.0, 1.0}, { 1.0, 1.0, 3.0, 3.0, 1.0});
histMap.AddCutToHistogramDraw("joe_cut", "myHisto");
histMap.AddCutToHistogramDraw("joe2D_cut", "myHisto2D");
*/
} }
Application::~Application() Application::~Application()

View File

@ -0,0 +1,96 @@
#include "CompassOnlineSource.h"
namespace Navigator {
CompassOnlineSource::CompassOnlineSource(const std::string& hostname, const std::string& port) :
DataSource(), m_bufferIter(nullptr), m_bufferEnd(nullptr), m_socket(m_socketContext)
{
m_buffer.resize(m_bufferSize);
InitSocket(hostname, port);
}
CompassOnlineSource::~CompassOnlineSource() {}
void CompassOnlineSource::InitSocket(const std::string& hostname, const std::string& port)
{
m_validFlag = false;
try
{
asio::ip::tcp::resolver resolver(m_socketContext);
auto end_points = resolver.resolve(hostname, port);
asio::connect(m_socket, end_points);
}
catch (asio::system_error& error)
{
NAV_ERROR("Unable to connect to remote port for CompassOnlineSource! Error Code: {0}", error.what());
return;
}
NAV_INFO("Successfully connected to host {0} on port {1}", hostname, port);
m_validFlag = true;
}
const CompassHit& CompassOnlineSource::GetData()
{
if (!IsValid())
{
NAV_ERROR("Attempting to access invalid source at CompassOnlineSource!");
m_currentHit = CompassHit();
return m_currentHit;
}
else if (m_bufferIter == nullptr || m_bufferIter == m_bufferEnd)
{
FillBuffer();
}
if (m_bufferIter != m_bufferEnd)
{
GetHit();
return m_currentHit;
}
else
{
m_currentHit = CompassHit();
return m_currentHit;
}
}
void CompassOnlineSource::FillBuffer()
{
asio::error_code code;
size_t length = m_socket.read_some(asio::buffer(m_buffer), code);
m_bufferEnd = m_buffer.data() + length;
m_bufferIter = m_buffer.data();
if (code == asio::error::eof)
{
NAV_WARN("CompassOnlineSource invalidated by host. Invalidating and detaching source.");
m_validFlag = false;
}
else if (code)
{
NAV_ERROR("CompassOnlineSource recieved unexpected error from host. Error message: {0}", code.message());
NAV_WARN("Invalidating and detaching source.");
m_validFlag = false;
}
}
void CompassOnlineSource::GetHit()
{
m_currentHit.board = *((uint16_t*)m_bufferIter);
m_bufferIter += 2;
m_currentHit.channel = *((uint16_t*)m_bufferIter);
m_bufferIter += 2;
m_currentHit.timestamp = *((uint64_t*)m_bufferIter);
m_bufferIter += 8;
m_currentHit.lgate = *((uint16_t*)m_bufferIter);
m_bufferIter += 2;
m_currentHit.sgate = *((uint16_t*)m_bufferIter);
m_bufferIter += 2;
m_currentHit.flags = *((uint32_t*)m_bufferIter);
m_bufferIter += 4;
m_currentHit.Ns = *((uint32_t*)m_bufferIter);
m_bufferIter += 4;
}
}

View File

@ -0,0 +1,34 @@
#ifndef COMPASS_ONLINE_SOURCE_H
#define COMPASS_ONLINE_SOURCE_H
#include "DataSource.h"
#include "asio/include/asio.hpp"
namespace Navigator {
class CompassOnlineSource : public DataSource
{
public:
CompassOnlineSource(const std::string& hostname, const std::string& port);
virtual ~CompassOnlineSource() override;
virtual const CompassHit& GetData() override;
private:
void InitSocket(const std::string& hostname, const std::string& port);
void FillBuffer();
void GetHit();
std::vector<char> m_buffer;
static constexpr size_t m_bufferSize = 1000000;
char* m_bufferIter;
char* m_bufferEnd;
CompassHit m_currentHit;
asio::io_context m_socketContext;
asio::ip::tcp::socket m_socket;
};
}
#endif

View File

@ -114,12 +114,13 @@ namespace Navigator {
return true; return true;
} }
CompassHit CompassRun::GetData() const CompassHit& CompassRun::GetData()
{ {
if(!IsValid()) if(!IsValid())
{ {
NAV_ERROR("Trying to access CompassRun data when invalid, bug detected!"); NAV_ERROR("Trying to access CompassRun data when invalid, bug detected!");
return CompassHit(); m_hit = CompassHit();
return m_hit;
} }
if(GetHitsFromFiles()) if(GetHitsFromFiles())

View File

@ -25,7 +25,7 @@ namespace Navigator {
CompassRun(); CompassRun();
CompassRun(const std::string& dir); CompassRun(const std::string& dir);
virtual ~CompassRun(); virtual ~CompassRun();
virtual CompassHit GetData() override; virtual const CompassHit& GetData() override;
inline void SetDirectory(const std::string& dir) { m_directory = dir; CollectFiles(); } inline void SetDirectory(const std::string& dir) { m_directory = dir; CollectFiles(); }
inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); } inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); }

View File

@ -1,5 +1,6 @@
#include "DataSource.h" #include "DataSource.h"
#include "CompassRun.h" #include "CompassRun.h"
#include "CompassOnlineSource.h"
namespace Navigator { namespace Navigator {
@ -8,7 +9,7 @@ namespace Navigator {
switch(type) switch(type)
{ {
case DataSource::SourceType::CompassOffline : return new CompassRun(loc); case DataSource::SourceType::CompassOffline : return new CompassRun(loc);
case DataSource::SourceType::CompassOnline : return nullptr; case DataSource::SourceType::CompassOnline : return new CompassOnlineSource(loc, "5346");
case DataSource::SourceType::None : return nullptr; case DataSource::SourceType::None : return nullptr;
} }
} }

View File

@ -22,7 +22,7 @@ namespace Navigator {
} }
virtual ~DataSource() {}; virtual ~DataSource() {};
virtual CompassHit GetData() = 0; virtual const CompassHit& GetData() = 0;
inline bool IsValid() { return m_validFlag; } inline bool IsValid() { return m_validFlag; }
protected: protected:

1
Navigator/vendor/asio vendored Submodule

@ -0,0 +1 @@
Subproject commit f70f65ae54351c209c3a24704624144bfe8e70a3

View File

@ -16,6 +16,7 @@ IncludeDirs["ImGui"] = "Navigator/vendor/imgui"
IncludeDirs["glad"] = "Navigator/vendor/glad/include" IncludeDirs["glad"] = "Navigator/vendor/glad/include"
IncludeDirs["ImPlot"] = "Navigator/vendor/implot" IncludeDirs["ImPlot"] = "Navigator/vendor/implot"
IncludeDirs["glm"] = "Navigator/vendor/glm" IncludeDirs["glm"] = "Navigator/vendor/glm"
IncludeDirs["asio"] = "Navigator/vendor/asio"
include "Navigator/vendor/glfw" include "Navigator/vendor/glfw"
include "Navigator/vendor/imgui" include "Navigator/vendor/imgui"
@ -44,7 +45,8 @@ project "Navigator"
"%{IncludeDirs.ImGui}", "%{IncludeDirs.ImGui}",
"%{IncludeDirs.glad}", "%{IncludeDirs.glad}",
"%{IncludeDirs.ImPlot}", "%{IncludeDirs.ImPlot}",
"%{IncludeDirs.glm}" "%{IncludeDirs.glm}",
"%{IncludeDirs.asio}"
} }
filter {} filter {}
@ -55,7 +57,8 @@ project "Navigator"
"%{IncludeDirs.ImGui}", "%{IncludeDirs.ImGui}",
"%{IncludeDirs.glad}", "%{IncludeDirs.glad}",
"%{IncludeDirs.ImPlot}", "%{IncludeDirs.ImPlot}",
"%{IncludeDirs.glm}" "%{IncludeDirs.glm}",
"%{IncludeDirs.asio}"
} }
@ -145,8 +148,8 @@ project "NavProject"
"Navigator/vendor/spdlog/include/", "Navigator/vendor/spdlog/include/",
"Navigator/vendor/implot/", "Navigator/vendor/implot/",
"Navigator/vendor", "Navigator/vendor",
"%{IncludeDirs.glm}" "%{IncludeDirs.glm}",
"%{IncludeDirs.asio}"
} }
links { links {

57
spectra.nav Normal file
View File

@ -0,0 +1,57 @@
begin_cuts
begin_cut1D
name: joe_cut
xparam: joseph
minValue: 0
maxValue: 7
end_cut1D
begin_cut2D
name: joe2D_cut
xparam: joseph
yparam: joseph
begin_xvalues
1
3
3
1
1
end_xvalues
begin_yvalues
1
1
3
3
1
end_yvalues
end_cut2D
end_cuts
begin_histograms
begin_histogram1D
name: myHisto
xparam: joseph
Nxbins: 100
XMin: 0
XMax: 10
begin_cutsdrawn
joe_cut
end_cutsdrawn
begin_cutsapplied
end_cutsapplied
end_histogram1D
begin_histogram2D
name: myHisto2D
xparam: joseph
yparam: joseph
Nxbins: 100
XMin: 0
XMax: 10
Nybins: 100
YMin: 0
YMax: 10
begin_cutsdrawn
joe2D_cut
end_cutsdrawn
begin_cutsapplied
end_cutsapplied
end_histogram2D
end_histograms