Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a6866d906196
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 00cf5a9c4f80
Choose a head ref
  • 11 commits
  • 9 files changed
  • 2 contributors

Commits on Jun 21, 2020

  1. Modified CMake project file to include GLEW as well as needed Windows…

    … libraries
    nshcat committed Jun 21, 2020
    Copy the full SHA
    4ec53d8 View commit details
  2. Copy the full SHA
    8bfb9c4 View commit details
  3. Fixed YAML deserialization code using longs, which are only 4 byte on…

    … windows
    nshcat committed Jun 21, 2020
    Copy the full SHA
    048dcde View commit details
  4. Replaced long literal with long long literal

    nshcat committed Jun 21, 2020
    Copy the full SHA
    f64e4f6 View commit details
  5. Added GLEW OpenGL extension loader

    nshcat committed Jun 21, 2020
    Copy the full SHA
    811d6e9 View commit details
  6. Copy the full SHA
    85e439a View commit details
  7. Added OpenGL headers for windows

    nshcat committed Jun 21, 2020
    Copy the full SHA
    9b14e30 View commit details
  8. Implemented CWD switching for windows

    nshcat committed Jun 21, 2020
    Copy the full SHA
    4e02834 View commit details
  9. Fixed wrong cast

    nshcat committed Jun 21, 2020
    Copy the full SHA
    df73939 View commit details
  10. Renamed glew initialization flag

    nshcat committed Jun 21, 2020
    Copy the full SHA
    33ad0c7 View commit details
  11. Merge pull request #114 from nshcat/win32-fixes

    Allow compilation and offline execution of glscopeclient on Windows
    azonenberg authored Jun 21, 2020
    Copy the full SHA
    00cf5a9 View commit details
18 changes: 16 additions & 2 deletions glscopeclient/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# GLEW and OpenGL are required
find_package(GLEW REQUIRED)
find_package(OpenGL REQUIRED)

# Additional libraries on Windows
if(WIN32)
set(WIN_LIBS shlwapi)

# For some reason, find_package does not manage to find glew32 on Windows. Hardcoding for now.
set(GLEW_LIBRARIES "glew32")
endif()

#Set up include paths
include_directories(${GTKMM_INCLUDE_DIRS} ${SIGCXX_INCLUDE_DIRS})
include_directories(${GTKMM_INCLUDE_DIRS} ${SIGCXX_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS} ${SIGCXX_LIBRARY_DIRS})

###############################################################################
@@ -39,7 +51,9 @@ target_link_libraries(glscopeclient
scopeprotocols
${GTKMM_LIBRARIES}
${SIGCXX_LIBRARIES}
GL
${OPENGL_LIBRARY}
${WIN_LIBS}
${GLEW_LIBRARIES}
yaml-cpp
)

20 changes: 19 additions & 1 deletion glscopeclient/HistoryWindow.cpp
Original file line number Diff line number Diff line change
@@ -142,7 +142,13 @@ void HistoryWindow::OnWaveformDataReady()
//Format timestamp
char tmp[128];
struct tm ltime;

#ifdef _WIN32
localtime_s(&ltime, &data->m_startTimestamp);
#else
localtime_r(&data->m_startTimestamp, &ltime);
#endif

strftime(tmp, sizeof(tmp), "%H:%M:%S.", &ltime);
string stime = tmp;
snprintf(tmp, sizeof(tmp), "%010zu", data->m_startPicoseconds / 100); //round to nearest 100ps for display
@@ -314,7 +320,13 @@ void HistoryWindow::SerializeWaveforms(string dir, IDTable& table)
snprintf(tmp, sizeof(tmp), "%s/scope_%d_metadata.yml", dir.c_str(), table[m_scope]);
string fname = tmp;
snprintf(tmp, sizeof(tmp), "%s/scope_%d_waveforms", dir.c_str(), table[m_scope]);

#ifdef _WIN32
mkdir(tmp);
#else
mkdir(tmp, 0755);
#endif

string dname = tmp;

//Serialize waveforms
@@ -337,7 +349,13 @@ void HistoryWindow::SerializeWaveforms(string dir, IDTable& table)

//Format directory for this waveform
snprintf(tmp, sizeof(tmp), "%s/waveform_%d", dname.c_str(), id);
mkdir(tmp, 0755);

#ifdef _WIN32
mkdir(tmp);
#else
mkdir(tmp, 0755);
#endif

string wname = tmp;

//Save waveform data
15 changes: 12 additions & 3 deletions glscopeclient/OscilloscopeWindow.cpp
Original file line number Diff line number Diff line change
@@ -642,8 +642,8 @@ void OscilloscopeWindow::LoadWaveformDataForScope(
{
//Top level metadata
auto wfm = it.second;
time.first = wfm["timestamp"].as<long>();
time.second = wfm["time_psec"].as<long>();
time.first = wfm["timestamp"].as<long long>();
time.second = wfm["time_psec"].as<long long>();
int waveform_id = wfm["id"].as<int>();

//Detach old waveforms from our channels (if any)
@@ -1101,6 +1101,7 @@ void OscilloscopeWindow::OnFileSave(bool saveToCurrentFile, bool saveLayout, boo
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FIXME: a fair bit of the code below is POSIX specific and will need to be fixed for portability eventually

#ifndef _WIN32
//See if the directory exists
bool dir_exists = false;
int hfile = open(m_currentDataDirName.c_str(), O_RDONLY);
@@ -1152,7 +1153,13 @@ void OscilloscopeWindow::OnFileSave(bool saveToCurrentFile, bool saveLayout, boo
//Create the directory we're saving to (if needed)
if(!dir_exists)
{
if(0 != mkdir(m_currentDataDirName.c_str(), 0755))
#ifdef _WIN32
auto result = mkdir(m_currentDataDirName.c_str());
#else
auto result = mkdir(m_currentDataDirName.c_str(), 0755);
#endif

if(0 != result)
{
string msg = string("The data directory ") + m_currentDataDirName + " could not be created!";
Gtk::MessageDialog errdlg(msg, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
@@ -1186,6 +1193,8 @@ void OscilloscopeWindow::OnFileSave(bool saveToCurrentFile, bool saveLayout, boo
//Serialize waveform data if needed
if(saveWaveforms)
SerializeWaveforms(table);

#endif
}

string OscilloscopeWindow::SerializeConfiguration(bool saveLayout, IDTable& table)
4 changes: 3 additions & 1 deletion glscopeclient/ScopeSyncWizard.cpp
Original file line number Diff line number Diff line change
@@ -336,7 +336,9 @@ void ScopeSyncWizard::OnWaveformDataReady()
At 10 Gsps this is a whopping 1000 ns, typical values are in the low tens of ns.
*/
m_maxSkewSamples = static_cast<int64_t>(pw->m_offsets.size() / 2);
m_maxSkewSamples = min(m_maxSkewSamples, 10000L);

m_maxSkewSamples = min(m_maxSkewSamples, static_cast<int64_t>(10000LL));

m_delta = - m_maxSkewSamples;

//Set the timer
15 changes: 15 additions & 0 deletions glscopeclient/WaveformArea.cpp
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@
using namespace std;
using namespace glm;

bool WaveformArea::m_isGlewInitialized = false;

WaveformArea::WaveformArea(
OscilloscopeChannel* channel,
OscilloscopeWindow* parent
@@ -455,6 +457,19 @@ void WaveformArea::on_realize()
//Let the base class create the GL context, then select it
Gtk::GLArea::on_realize();
make_current();

// Initialize GLEW
if(!m_isGlewInitialized)
{
GLenum glewResult = glewInit();
if (glewResult != GLEW_OK)
{
LogError("Error: Failed to initialize GLEW");
return;
}

m_isGlewInitialized = true;
}

//We're about to draw the first frame after realization.
//This means we need to save some configuration (like the current FBO) that GTK doesn't tell us directly
3 changes: 3 additions & 0 deletions glscopeclient/WaveformArea.h
Original file line number Diff line number Diff line change
@@ -277,6 +277,9 @@ class WaveformArea : public Gtk::GLArea
//Display options
bool m_persistence;
bool m_persistenceClear;

// Whether GLEW is already initialized
static bool m_isGlewInitialized;

Framebuffer m_windowFramebuffer;

5 changes: 5 additions & 0 deletions glscopeclient/WaveformArea_cairo.cpp
Original file line number Diff line number Diff line change
@@ -33,6 +33,11 @@
@brief Cairo rendering code for WaveformArea
*/

#ifdef _WIN32
#define _USE_MATH_DEFINES
#include <cmath>
#endif

#include "glscopeclient.h"
#include "WaveformArea.h"
#include "OscilloscopeWindow.h"
8 changes: 8 additions & 0 deletions glscopeclient/glscopeclient.h
Original file line number Diff line number Diff line change
@@ -49,7 +49,15 @@
#include <giomm.h>
#include <gtkmm.h>

#include <GL/glew.h>
#include <GL/gl.h>

#ifdef _WIN32
#include <GL/glcorearb.h>
#include <GL/glext.h>
#endif


#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
42 changes: 38 additions & 4 deletions glscopeclient/main.cpp
Original file line number Diff line number Diff line change
@@ -32,6 +32,11 @@
@author Andrew D. Zonenberg
@brief Program entry point
*/

#ifdef _WIN32
#include <windows.h>
#include <shlwapi.h>
#endif

#include "glscopeclient.h"
#include "../scopeprotocols/scopeprotocols.h"
@@ -44,6 +49,9 @@
#include "InstrumentConnectionDialog.h"
#include <libgen.h>
#include <omp.h>
#include <chrono>
#include <iostream>
#include <thread>

using namespace std;

@@ -159,6 +167,31 @@ int main(int argc, char* argv[])

//Change to the binary's directory so we can use relative paths for external resources
//FIXME: portability warning: this only works on Linux
#ifdef _WIN32
// Retrieve the file name of the current process image
TCHAR binPath[MAX_PATH];

if( GetModuleFileName(NULL, binPath, MAX_PATH) == 0 )
{
LogError("Error: GetModuleFileName() failed.\n");
return 1;
}

// Remove file name from path
if( !PathRemoveFileSpec(binPath) )
{
LogError("Error: PathRemoveFileSpec() failed.\n");
return 1;
}

// Set it as current working directory
if( SetCurrentDirectory(binPath) == 0 )
{
LogError("Error: SetCurrentDirectory() failed.\n");
return 1;
}

#else
char binDir[1024];
ssize_t readlinkReturn = readlink("/proc/self/exe", binDir, (sizeof(binDir) - 1) );
if ( readlinkReturn < 0 )
@@ -190,6 +223,7 @@ int main(int argc, char* argv[])
return 1;
}
}
#endif

g_app = new ScopeApp;

@@ -298,7 +332,7 @@ void ScopeThread(Oscilloscope* scope)
if(npending > 100)
{
LogTrace("Queue is too big, sleeping\n");
usleep(50 * 1000);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
tlast = GetTime();
continue;
}
@@ -308,7 +342,7 @@ void ScopeThread(Oscilloscope* scope)
if(npending*dt > 5)
{
LogTrace("Capture thread got 5 sec ahead of UI, sleeping\n");
usleep(50 * 1000);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
tlast = GetTime();
continue;
}
@@ -317,7 +351,7 @@ void ScopeThread(Oscilloscope* scope)
if(!scope->IsTriggerArmed())
{
LogTrace("Scope isn't armed, sleeping\n");
usleep(5 * 1000);
std::this_thread::sleep_for(std::chrono::milliseconds(5));
tlast = GetTime();
continue;
}
@@ -347,7 +381,7 @@ void ScopeThread(Oscilloscope* scope)

//Wait 1ms before polling again, so the UI thread has a chance to grab the mutex
else
usleep(1*1000);
std::this_thread::sleep_for(std::chrono::milliseconds(1));

npolls ++;
}