diff --git a/Cpp/CMakeLists.txt b/Cpp/CMakeLists.txt index 0f2c19a370bbcf64c3f8426a923866953edbb086..e50f5fbebe4fbc376833ab37a000b54a2f28190c 100644 --- a/Cpp/CMakeLists.txt +++ b/Cpp/CMakeLists.txt @@ -15,13 +15,11 @@ set(CMAKE_CXX_STANDARD 20) add_library(wfmLib "") add_library(AWGLib "") add_subdirectory(lib) -include_directories(lib/driver_header) +# include_directories(lib/driver_header) -find_package(Eigen3 3.4 REQUIRED NO_MODULE) set(LIBS wfmLib AWGLib - Eigen3::Eigen ) # main.exe diff --git a/Cpp/lib/AWG.cpp b/Cpp/lib/AWG.cpp index d0379eca97310cf5780a80a1a4a7ce2b5cd25d55..2e9803431650ba0f399dc0c61c441949bbd8b8b3 100644 --- a/Cpp/lib/AWG.cpp +++ b/Cpp/lib/AWG.cpp @@ -13,7 +13,6 @@ AWG::AWG() noexcept { } AWG::~AWG() { - // TODO: do this if (this->isOpen()) { this->close(); } this->pCardHandle = nullptr; return; @@ -21,7 +20,7 @@ AWG::~AWG() { void AWG::checkError() { /** - * printout error if detected. + * throw error if detected. * */ if (this->pCardHandle == nullptr) { return; } diff --git a/Cpp/lib/CMakeLists.txt b/Cpp/lib/CMakeLists.txt index 67b4031458bfad9ee27f4da85555377c8329c1db..aae29277679448632457e9b4846905260191ec97 100644 --- a/Cpp/lib/CMakeLists.txt +++ b/Cpp/lib/CMakeLists.txt @@ -1,10 +1,13 @@ +find_package(Eigen3 3.4 REQUIRED NO_MODULE) + target_sources(wfmLib PRIVATE waveform.cpp PUBLIC waveform.h ) -target_include_directories(wfmLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +# target_include_directories(wfmLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +target_link_libraries(wfmLib Eigen3::Eigen) target_sources(AWGLib PRIVATE @@ -18,5 +21,6 @@ set_target_properties(driverLib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/driver_header" ) target_link_libraries(AWGLib PUBLIC driverLib) -target_include_directories(AWGLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +# target_include_directories(AWGLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}) + diff --git a/Cpp/lib/Waveform.cpp b/Cpp/lib/Waveform.cpp index c246c141f9c5c480816a54cb69c950e7eaf9c4ed..5bf7c07ffe68a1a3b63f5684213a55a04194a35c 100644 --- a/Cpp/lib/Waveform.cpp +++ b/Cpp/lib/Waveform.cpp @@ -1,6 +1,48 @@ -#include "Waveform.h" +#include "waveform.h" +Waveform::WaveformParam::WaveformParam() { + this->samplingRate = 0; + this->freqResolution = 0; +} + +Waveform::WaveformParam::WaveformParam( + const WaveformParam& other +) { + this->samplingRate = other.samplingRate; + this->freqResolution = other.freqResolution; + this->freqTones = other.freqTones; + this->phases = other.phases; + this->amplitudes = other.amplitudes; +} + +void Waveform::WaveformParam::setFreqTone( + int centerFreq, + int freqSpacing, + int numTones +) { + int freqStart = centerFreq - + freqSpacing * int(std::floor(numTones / 2)); + this->freqTones.setLinSpaced( + numTones, + freqStart, + freqStart + freqSpacing * (numTones-1) + ); +} + +void Waveform::WaveformParam::setFreqTone( + const Eigen::VectorXi otherTones +) { + this->freqTones = otherTones; +} + +void Waveform::WaveformParam::setPhase( + const Eigen::VectorXd otherPhase +) { + this->phases = otherPhase; +} -Waveform::Waveform() { - +void Waveform::WaveformParam::setAmplitude( + const Eigen::VectorXd otherAmp +) { + this->amplitudes = otherAmp; } diff --git a/Cpp/lib/Waveform.h b/Cpp/lib/Waveform.h index eb351928a4832f0b151c7fdefe0843875750c5e6..3cf23f4f71d566be8eb8256be9d8d253b1bd4d8b 100644 --- a/Cpp/lib/Waveform.h +++ b/Cpp/lib/Waveform.h @@ -1,9 +1,27 @@ #pragma once -class Waveform { - public: - int freqRes; // frequency resolution - int samplingRate; // sampling rate +#include <Eigen/Dense> +namespace Waveform { + class WaveformParam { + public: + unsigned long samplingRate; + unsigned long freqResolution; + Eigen::VectorXi freqTones; + Eigen::VectorXd phases; + Eigen::VectorXd amplitudes; + + WaveformParam(); + WaveformParam(const WaveformParam& other); + void setFreqTone( + int centerFreq, + int freqSpacing, + int numTones + ); + void setFreqTone(const Eigen::VectorXi otherTone); + void setPhase(const Eigen::VectorXd otherPhase); + void setAmplitude(const Eigen::VectorXd otherAmp); + + }; + - Waveform(); }; diff --git a/Cpp/run.cpp b/Cpp/run.cpp index ae75247cdce6008ad50cc7cd7d7e95deb5131873..a4704bb07bf415d23b582ae86d8e3aad629488eb 100644 --- a/Cpp/run.cpp +++ b/Cpp/run.cpp @@ -1,12 +1,22 @@ #include <iostream> #include "lib/AWG.h" #include "lib/waveform.h" -#include <Eigen/Dense> int main() { - auto wfm = Waveform::Waveform(); - auto awg = AWG::AWG(); - awg.open(0); - std::cout << wfm.freqRes << std::endl; + // auto t = 2e-3; + // auto sr = 614.4e6; + // auto sample = int(t * sr); + // Eigen::ArrayXd signal = Eigen::ArrayXd::Zero(sample); + // void* ptr = signal.data(); + // size_t space = sample * 2; + // size_t size_remain = 0; + // void* res = std::align(4096, space, ptr, size_remain); + // std::cout << ptr << "\n" << res << "\n" << size_remain << std::endl; + // auto wfm = Waveform::WaveformParam(); + // wfm.setFreqTone(int(105e6), int(1e6), 5); + // std::cout << wfm.freqTones << std::endl; + Eigen::Vector3i a {1, 2, 3}; + Eigen::Vector4i b = Eigen::VectorXi::LinSpaced(4, 1, 5); + std::cout << a; return 0; }