mirror of
https://github.com/galera951/experiment-automation.git
synced 2024-11-25 07:05:52 +03:00
Clean structure
This commit is contained in:
parent
20d17edaf8
commit
1be63c1793
@ -1,7 +1,44 @@
|
||||
#include "Device.hpp"
|
||||
|
||||
void Generator::update() {
|
||||
std::string response = query(m_channel + ":BSWV?");
|
||||
|
||||
Device::Device(std::string path_name) : root_path("/dev/" + path_name)
|
||||
{
|
||||
std::string response = query("*IDN?");
|
||||
response.erase(0, response.find(',') + 1);
|
||||
response.erase(response.find(','));
|
||||
|
||||
name = response;
|
||||
}
|
||||
|
||||
void Device::command(std::string comm)
|
||||
{
|
||||
std::ofstream out;
|
||||
out.open(root_path);
|
||||
|
||||
if (!out.is_open())
|
||||
std::cerr << "**ERROR** file is not open to output." << std::endl;
|
||||
else
|
||||
{
|
||||
out << comm;
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
std::string Device::query(std::string comm)
|
||||
{
|
||||
command(comm);
|
||||
|
||||
std::string buffer;
|
||||
std::ifstream in;
|
||||
in.open(root_path);
|
||||
|
||||
if (!in.is_open())
|
||||
std::cerr << "**ERROR** file is not open to input." << std::endl;
|
||||
else
|
||||
{
|
||||
std::getline(in, buffer);
|
||||
in.close();
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
@ -1,114 +1,25 @@
|
||||
#pragma once
|
||||
#include<fstream>
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
|
||||
class Device {
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
Device(std::string path_name): root_path("/dev/" + path_name) {
|
||||
std::string idn = query("*IDN?");
|
||||
idn.erase(0, idn.find(',') + 1);
|
||||
idn.erase(idn.find(','));
|
||||
Device(std::string path_name);
|
||||
|
||||
name = idn;
|
||||
std::string get_name()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
protected:
|
||||
void command(std::string comm) {
|
||||
std::ofstream out;
|
||||
out.open(root_path);
|
||||
void command(std::string comm);
|
||||
std::string query(std::string comm);
|
||||
|
||||
if(!out.is_open())
|
||||
std::cerr << "**ERROR** file is not open to output." << std::endl;
|
||||
else {
|
||||
out << comm;
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
std::string query(std::string comm) {
|
||||
command(comm);
|
||||
|
||||
std::string buffer;
|
||||
std::ifstream in;
|
||||
in.open(root_path);
|
||||
|
||||
if(!in.is_open())
|
||||
std::cerr << "**ERROR** file is not open to input." << std::endl;
|
||||
else {
|
||||
std::getline(in, buffer);
|
||||
in.close();
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
std::string root_path;
|
||||
};
|
||||
|
||||
|
||||
class Generator: public Device {
|
||||
public:
|
||||
Generator(std::string path_name): Device(path_name), m_channel("C1") { }
|
||||
|
||||
void set_channel(size_t channel) {
|
||||
if (channel == 1 || channel == 2) m_channel = "C" + std::to_string(channel);
|
||||
else std::cerr << "Invalid channel" << std::endl;
|
||||
}
|
||||
|
||||
void buzz() {
|
||||
command("BUZZ ON");
|
||||
}
|
||||
|
||||
void set_waveform(std::string waveform) {
|
||||
m_waveform = waveform;
|
||||
command(m_channel + ":BSWV WVTP," + waveform);
|
||||
}
|
||||
|
||||
void set_frequency(double frequency) {
|
||||
m_frequency = frequency;
|
||||
command(m_channel + ":BSWV FRQ," + std::to_string(frequency));
|
||||
}
|
||||
|
||||
void set_period(double period) {
|
||||
command(m_channel + ":BSWV PERI," + std::to_string(period));
|
||||
}
|
||||
|
||||
void set_amplitude(double amplitude) {
|
||||
command(m_channel + ":BSWV AMP," + std::to_string(amplitude));
|
||||
}
|
||||
|
||||
void set_offset(double offset) {
|
||||
command(m_channel + ":BSWV OFST," + std::to_string(offset));
|
||||
}
|
||||
|
||||
void set_phase(double phase) {
|
||||
command(m_channel + ":BSWV PHSE," + std::to_string(phase));
|
||||
}
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
std::string m_channel;
|
||||
std::string m_waveform;
|
||||
double m_frequency;
|
||||
double m_period;
|
||||
double m_amplitude;
|
||||
double m_offset;
|
||||
double m_phase;
|
||||
};
|
||||
|
||||
|
||||
class Oscilloscope: public Device {
|
||||
public:
|
||||
Oscilloscope(std::string path_name): Device(path_name) { }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
project/Generator.cpp
Normal file
2
project/Generator.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "Generator.hpp"
|
||||
|
54
project/Generator.hpp
Normal file
54
project/Generator.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
#include "Device.hpp"
|
||||
|
||||
class Generator : public Device
|
||||
{
|
||||
public:
|
||||
Generator(std::string path_name) : Device(path_name), m_channel("C1") {}
|
||||
|
||||
void set_channel(size_t channel)
|
||||
{
|
||||
if (channel == 1 || channel == 2)
|
||||
m_channel = "C" + std::to_string(channel);
|
||||
else
|
||||
std::cerr << "Invalid channel" << std::endl;
|
||||
}
|
||||
|
||||
void buzz()
|
||||
{
|
||||
command("BUZZ ON");
|
||||
}
|
||||
|
||||
void set_waveform(std::string waveform)
|
||||
{
|
||||
command(m_channel + ":BSWV WVTP," + waveform);
|
||||
}
|
||||
|
||||
void set_frequency(double frequency)
|
||||
{
|
||||
command(m_channel + ":BSWV FRQ," + std::to_string(frequency));
|
||||
}
|
||||
|
||||
void set_period(double period)
|
||||
{
|
||||
command(m_channel + ":BSWV PERI," + std::to_string(period));
|
||||
}
|
||||
|
||||
void set_amplitude(double amplitude)
|
||||
{
|
||||
command(m_channel + ":BSWV AMP," + std::to_string(amplitude));
|
||||
}
|
||||
|
||||
void set_offset(double offset)
|
||||
{
|
||||
command(m_channel + ":BSWV OFST," + std::to_string(offset));
|
||||
}
|
||||
|
||||
void set_phase(double phase)
|
||||
{
|
||||
command(m_channel + ":BSWV PHSE," + std::to_string(phase));
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_channel;
|
||||
};
|
@ -1,10 +1,23 @@
|
||||
all: main
|
||||
CC=g++
|
||||
CFLAGS=-c
|
||||
EXECUTABLE=start
|
||||
|
||||
main: main.o
|
||||
g++ main.o -o main
|
||||
all: $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): main.o Device.o Generator.o Oscilloscope.o
|
||||
$(CC) main.o Device.o Generator.o Oscilloscope.o -o main
|
||||
|
||||
main.o: main.cpp
|
||||
g++ -c main.cpp -o main.o
|
||||
$(CC) $(CFLAGS) main.cpp
|
||||
|
||||
Device.o: Device.cpp
|
||||
$(CC) $(CFLAGS) Device.cpp
|
||||
|
||||
Generator.o: Generator.cpp
|
||||
$(CC) $(CFLAGS) Generator.cpp
|
||||
|
||||
Oscilloscope.o: Oscilloscope.cpp
|
||||
$(CC) $(CFLAGS) Oscilloscope.cpp
|
||||
|
||||
clean:
|
||||
rm -f main
|
||||
|
1
project/Oscilloscope.cpp
Normal file
1
project/Oscilloscope.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "Oscilloscope.hpp"
|
8
project/Oscilloscope.hpp
Normal file
8
project/Oscilloscope.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "Device.hpp"
|
||||
|
||||
class Oscilloscope : public Device
|
||||
{
|
||||
public:
|
||||
Oscilloscope(std::string path_name) : Device(path_name) {}
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
#include "Device.hpp"
|
||||
#include "Generator.hpp"
|
||||
#include "Oscilloscope.hpp"
|
||||
#include <vector>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -13,8 +14,10 @@ int main() {
|
||||
auto path = "usbtmc" + std::to_string(i);
|
||||
Device device(path);
|
||||
|
||||
if (device.name == "AKIP-3409-4") generator_path = path;
|
||||
else if (device.name == "AKIP-4131/1") oscilloscope_path = path;
|
||||
if (device.get_name() == "AKIP-3409-4")
|
||||
generator_path = path;
|
||||
else if (device.get_name() == "AKIP-4131/1")
|
||||
oscilloscope_path = path;
|
||||
else {
|
||||
std::cerr << "Devices not available!" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
|
Loading…
Reference in New Issue
Block a user