aboutsummaryrefslogtreecommitdiffstats
path: root/gui/stmdsp.hpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-06-18 20:40:37 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-06-18 20:40:37 -0400
commitda8d7ffe8a12c10f819f103de1194511bdb3776e (patch)
treefd7993f432cacfbb76c55604c20a88337eb87d33 /gui/stmdsp.hpp
parent6473b57cefe4c13cb262ed78bf0e49fe18a20267 (diff)
drafted device interface
Diffstat (limited to 'gui/stmdsp.hpp')
-rw-r--r--gui/stmdsp.hpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/gui/stmdsp.hpp b/gui/stmdsp.hpp
index 7695abe..030038d 100644
--- a/gui/stmdsp.hpp
+++ b/gui/stmdsp.hpp
@@ -1,8 +1,9 @@
#ifndef STMDSP_HPP_
#define STMDSP_HPP_
-#include <fstream>
+#include <cstdint>
#include <list>
+#include <serial/serial.h>
#include <string>
namespace stmdsp
@@ -15,11 +16,45 @@ namespace stmdsp
public:
std::list<std::string>& scan();
auto& devices() {
- return m_devices;
+ return m_available_devices;
}
private:
- std::list<std::string> m_devices;
+ std::list<std::string> m_available_devices;
+ };
+
+ using adcsample_t = uint16_t;
+
+ class device
+ {
+ public:
+ device(const std::string& file) :
+ m_serial(file, 115200, serial::Timeout::simpleTimeout(1000)) {}
+
+ ~device() {
+ m_serial.close();
+ }
+
+ bool connected() {
+ return m_serial.isOpen() && (m_serial.write("i"), m_serial.read(6) == "stmdsp");
+ }
+
+ std::vector<adcsample_t> sample(unsigned long int count = 1) {
+ if (connected()) {
+ m_serial.write(std::vector<uint8_t> {'r',
+ static_cast<uint8_t>(count),
+ static_cast<uint8_t>(count >> 8)});
+ std::vector<adcsample_t> data (count);
+ m_serial.read(reinterpret_cast<uint8_t *>(data.data()),
+ data.size() * sizeof(adcsample_t));
+ return data;
+ } else {
+ return {};
+ }
+ }
+
+ private:
+ serial::Serial m_serial;
};
}