mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Drivers: Rename STM32 to CDC ACM
This is much more descriptive of what the driver actually is
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "icsneo/platform/stm32.h"
|
||||
#include "icsneo/platform/cdcacm.h"
|
||||
#include <dirent.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
STM32::~STM32() {
|
||||
CDCACM::~CDCACM() {
|
||||
awaitModeChangeComplete();
|
||||
if(isOpen())
|
||||
close();
|
||||
}
|
||||
|
||||
bool STM32::open() {
|
||||
bool CDCACM::open() {
|
||||
if(isOpen()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::Error);
|
||||
return false;
|
||||
@@ -101,17 +101,17 @@ bool STM32::open() {
|
||||
}
|
||||
|
||||
// Create threads
|
||||
readThread = std::thread(&STM32::readTask, this);
|
||||
writeThread = std::thread(&STM32::writeTask, this);
|
||||
readThread = std::thread(&CDCACM::readTask, this);
|
||||
writeThread = std::thread(&CDCACM::writeTask, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool STM32::isOpen() {
|
||||
bool CDCACM::isOpen() {
|
||||
return fd >= 0; // Negative fd indicates error or not opened yet
|
||||
}
|
||||
|
||||
bool STM32::close() {
|
||||
bool CDCACM::close() {
|
||||
if(!isOpen() && !isDisconnected()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||
return false;
|
||||
@@ -158,11 +158,11 @@ bool STM32::close() {
|
||||
}
|
||||
}
|
||||
|
||||
void STM32::modeChangeIncoming() {
|
||||
void CDCACM::modeChangeIncoming() {
|
||||
modeChanging = true;
|
||||
}
|
||||
|
||||
void STM32::awaitModeChangeComplete() {
|
||||
void CDCACM::awaitModeChangeComplete() {
|
||||
std::unique_lock<std::mutex> lk(modeChangeMutex);
|
||||
if(modeChanging && !modeChangeThread.joinable()) // Waiting for the thread to start
|
||||
modeChangeCV.wait_for(lk, std::chrono::seconds(1), [this] { return modeChangeThread.joinable(); });
|
||||
@@ -170,7 +170,7 @@ void STM32::awaitModeChangeComplete() {
|
||||
modeChangeThread.join();
|
||||
}
|
||||
|
||||
void STM32::readTask() {
|
||||
void CDCACM::readTask() {
|
||||
constexpr size_t READ_BUFFER_SIZE = 2048;
|
||||
uint8_t readbuf[READ_BUFFER_SIZE];
|
||||
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
@@ -209,7 +209,7 @@ void STM32::readTask() {
|
||||
}
|
||||
}
|
||||
|
||||
void STM32::writeTask() {
|
||||
void CDCACM::writeTask() {
|
||||
WriteOperation writeOp;
|
||||
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
while(!closing && !isDisconnected()) {
|
||||
@@ -260,7 +260,7 @@ void STM32::writeTask() {
|
||||
}
|
||||
}
|
||||
|
||||
bool STM32::fdIsValid() {
|
||||
bool CDCACM::fdIsValid() {
|
||||
struct termios tty = {};
|
||||
return tcgetattr(fd, &tty) == 0 ? true : false;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "icsneo/platform/stm32.h"
|
||||
#include "icsneo/platform/cdcacm.h"
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
io_object_t toRelease;
|
||||
};
|
||||
|
||||
std::vector<neodevice_t> STM32::FindByProduct(int product) {
|
||||
std::vector<neodevice_t> CDCACM::FindByProduct(int product) {
|
||||
std::vector<neodevice_t> found;
|
||||
|
||||
CFMutableDictionaryRef ref = IOServiceMatching(kIOSerialBSDServiceValue);
|
||||
@@ -179,10 +179,10 @@ std::vector<neodevice_t> STM32::FindByProduct(int product) {
|
||||
return found;
|
||||
}
|
||||
|
||||
std::string STM32::HandleToTTY(neodevice_handle_t handle) {
|
||||
std::string CDCACM::HandleToTTY(neodevice_handle_t handle) {
|
||||
std::lock_guard<std::mutex> lk(ttyTableMutex);
|
||||
const size_t index = size_t(handle - HANDLE_OFFSET);
|
||||
if(index >= ttyTable.size())
|
||||
return ""; // Not found, generic driver (stm32.cpp) will throw an error
|
||||
return ""; // Not found, generic driver (cdcacm.cpp) will throw an error
|
||||
return ttyTable[index];
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "icsneo/platform/stm32.h"
|
||||
#include "icsneo/platform/cdcacm.h"
|
||||
#include <dirent.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
@@ -80,16 +80,16 @@ private:
|
||||
std::string serial;
|
||||
};
|
||||
|
||||
std::vector<neodevice_t> STM32::FindByProduct(int product) {
|
||||
std::vector<neodevice_t> CDCACM::FindByProduct(int product) {
|
||||
std::vector<neodevice_t> found;
|
||||
|
||||
Directory directory("/sys/bus/usb/drivers/cdc_acm"); // Query the STM32 driver
|
||||
Directory directory("/sys/bus/usb/drivers/cdc_acm"); // Query the CDCACM driver
|
||||
if(!directory.openedSuccessfully())
|
||||
return found;
|
||||
|
||||
std::vector<std::string> foundusbs;
|
||||
for(auto& entry : directory.ls()) {
|
||||
/* This directory will have directories (links) for all devices using the cdc_acm driver (as STM32 devices do)
|
||||
/* This directory will have directories (links) for all devices using the cdc_acm driver (as CDCACM devices do)
|
||||
* There will also be other files and directories providing information about the driver in here. We want to ignore them.
|
||||
* Devices will be named like "7-2:1.0" where 7 is the enumeration for the USB controller, 2 is the device enumeration on
|
||||
* that specific controller (will change if the device is unplugged and replugged), 1 is the device itself and 0 is
|
||||
@@ -195,7 +195,7 @@ std::vector<neodevice_t> STM32::FindByProduct(int product) {
|
||||
return found;
|
||||
}
|
||||
|
||||
std::string STM32::HandleToTTY(neodevice_handle_t handle) {
|
||||
std::string CDCACM::HandleToTTY(neodevice_handle_t handle) {
|
||||
std::stringstream ss;
|
||||
ss << "/dev/ttyACM" << (int)(handle - HANDLE_OFFSET);
|
||||
return ss.str();
|
||||
Reference in New Issue
Block a user