mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28: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:
parent
5177908c02
commit
de5fc21ccc
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -14,3 +14,6 @@
|
|||
[submodule "Navigator/vendor/glm"]
|
||||
path = Navigator/vendor/glm
|
||||
url = https://github.com/g-truc/glm.git
|
||||
[submodule "Navigator\\vendor\\asio"]
|
||||
path = Navigator\\vendor\\asio
|
||||
url = https://github.com/chriskohlhoff/asio.git
|
||||
|
|
|
@ -23,19 +23,6 @@ namespace Navigator {
|
|||
PushLayer(new EditorLayer());
|
||||
m_imgui_layer = new ImGuiLayer();
|
||||
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()
|
||||
|
|
96
Navigator/src/Navigator/Physics/CompassOnlineSource.cpp
Normal file
96
Navigator/src/Navigator/Physics/CompassOnlineSource.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
34
Navigator/src/Navigator/Physics/CompassOnlineSource.h
Normal file
34
Navigator/src/Navigator/Physics/CompassOnlineSource.h
Normal 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
|
|
@ -114,12 +114,13 @@ namespace Navigator {
|
|||
return true;
|
||||
}
|
||||
|
||||
CompassHit CompassRun::GetData()
|
||||
const CompassHit& CompassRun::GetData()
|
||||
{
|
||||
if(!IsValid())
|
||||
{
|
||||
NAV_ERROR("Trying to access CompassRun data when invalid, bug detected!");
|
||||
return CompassHit();
|
||||
m_hit = CompassHit();
|
||||
return m_hit;
|
||||
}
|
||||
|
||||
if(GetHitsFromFiles())
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Navigator {
|
|||
CompassRun();
|
||||
CompassRun(const std::string& dir);
|
||||
virtual ~CompassRun();
|
||||
virtual CompassHit GetData() override;
|
||||
virtual const CompassHit& GetData() override;
|
||||
inline void SetDirectory(const std::string& dir) { m_directory = dir; CollectFiles(); }
|
||||
inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); }
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "DataSource.h"
|
||||
#include "CompassRun.h"
|
||||
#include "CompassOnlineSource.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
|
@ -8,7 +9,7 @@ namespace Navigator {
|
|||
switch(type)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Navigator {
|
|||
}
|
||||
|
||||
virtual ~DataSource() {};
|
||||
virtual CompassHit GetData() = 0;
|
||||
virtual const CompassHit& GetData() = 0;
|
||||
inline bool IsValid() { return m_validFlag; }
|
||||
|
||||
protected:
|
||||
|
|
1
Navigator/vendor/asio
vendored
Submodule
1
Navigator/vendor/asio
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit f70f65ae54351c209c3a24704624144bfe8e70a3
|
11
premake5.lua
11
premake5.lua
|
@ -16,6 +16,7 @@ IncludeDirs["ImGui"] = "Navigator/vendor/imgui"
|
|||
IncludeDirs["glad"] = "Navigator/vendor/glad/include"
|
||||
IncludeDirs["ImPlot"] = "Navigator/vendor/implot"
|
||||
IncludeDirs["glm"] = "Navigator/vendor/glm"
|
||||
IncludeDirs["asio"] = "Navigator/vendor/asio"
|
||||
|
||||
include "Navigator/vendor/glfw"
|
||||
include "Navigator/vendor/imgui"
|
||||
|
@ -44,7 +45,8 @@ project "Navigator"
|
|||
"%{IncludeDirs.ImGui}",
|
||||
"%{IncludeDirs.glad}",
|
||||
"%{IncludeDirs.ImPlot}",
|
||||
"%{IncludeDirs.glm}"
|
||||
"%{IncludeDirs.glm}",
|
||||
"%{IncludeDirs.asio}"
|
||||
}
|
||||
filter {}
|
||||
|
||||
|
@ -55,7 +57,8 @@ project "Navigator"
|
|||
"%{IncludeDirs.ImGui}",
|
||||
"%{IncludeDirs.glad}",
|
||||
"%{IncludeDirs.ImPlot}",
|
||||
"%{IncludeDirs.glm}"
|
||||
"%{IncludeDirs.glm}",
|
||||
"%{IncludeDirs.asio}"
|
||||
}
|
||||
|
||||
|
||||
|
@ -145,8 +148,8 @@ project "NavProject"
|
|||
"Navigator/vendor/spdlog/include/",
|
||||
"Navigator/vendor/implot/",
|
||||
"Navigator/vendor",
|
||||
"%{IncludeDirs.glm}"
|
||||
|
||||
"%{IncludeDirs.glm}",
|
||||
"%{IncludeDirs.asio}"
|
||||
}
|
||||
|
||||
links {
|
||||
|
|
57
spectra.nav
Normal file
57
spectra.nav
Normal 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
|
Loading…
Reference in New Issue
Block a user