Drivers: Rename STM32 to CDC ACM

This is much more descriptive of what the driver actually is
pull/35/head
Paul Hollinsky 2021-05-04 22:37:16 -04:00
parent 6d22b1e001
commit 78e3eb18df
20 changed files with 83 additions and 83 deletions

View File

@ -95,15 +95,15 @@ else() # Darwin or Linux
set(PLATFORM_SRC set(PLATFORM_SRC
platform/posix/ftdi.cpp platform/posix/ftdi.cpp
platform/posix/pcap.cpp platform/posix/pcap.cpp
platform/posix/stm32.cpp platform/posix/cdcacm.cpp
) )
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
list(APPEND PLATFORM_SRC list(APPEND PLATFORM_SRC
platform/posix/darwin/stm32darwin.cpp platform/posix/darwin/cdcacmdarwin.cpp
) )
else() # Linux or other else() # Linux or other
list(APPEND PLATFORM_SRC list(APPEND PLATFORM_SRC
platform/posix/linux/stm32linux.cpp platform/posix/linux/cdcacmlinux.cpp
) )
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
message(WARNING message(WARNING

View File

@ -7,7 +7,7 @@
#include "icsneo/device/devicetype.h" #include "icsneo/device/devicetype.h"
#include "icsneo/communication/packetizer.h" #include "icsneo/communication/packetizer.h"
#include "icsneo/communication/decoder.h" #include "icsneo/communication/decoder.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include "icsneo/device/tree/etherbadge/etherbadgesettings.h" #include "icsneo/device/tree/etherbadge/etherbadgesettings.h"
namespace icsneo { namespace icsneo {
@ -22,7 +22,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) for(auto neodevice : CDCACM::FindByProduct(PRODUCT_ID))
found.emplace_back(new EtherBADGE(neodevice)); found.emplace_back(new EtherBADGE(neodevice));
return found; return found;
@ -42,7 +42,7 @@ public:
EtherBADGE(neodevice_t neodevice) : Device(neodevice) { EtherBADGE(neodevice_t neodevice) : Device(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID; productId = PRODUCT_ID;
initialize<STM32, EtherBADGESettings>(); initialize<CDCACM, EtherBADGESettings>();
} }
protected: protected:

View File

@ -5,7 +5,7 @@
#include "icsneo/device/device.h" #include "icsneo/device/device.h"
#include "icsneo/device/devicetype.h" #include "icsneo/device/devicetype.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
namespace icsneo { namespace icsneo {
@ -17,7 +17,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) for(auto neodevice : CDCACM::FindByProduct(PRODUCT_ID))
found.emplace_back(new NeoOBD2PRO(neodevice)); found.emplace_back(new NeoOBD2PRO(neodevice));
return found; return found;
@ -33,7 +33,7 @@ public:
private: private:
NeoOBD2PRO(neodevice_t neodevice) : Device(neodevice) { NeoOBD2PRO(neodevice_t neodevice) : Device(neodevice) {
initialize<STM32>(); initialize<CDCACM>();
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID; productId = PRODUCT_ID;
} }

View File

@ -5,7 +5,7 @@
#include "icsneo/device/device.h" #include "icsneo/device/device.h"
#include "icsneo/device/devicetype.h" #include "icsneo/device/devicetype.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
namespace icsneo { namespace icsneo {
@ -17,7 +17,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) for(auto neodevice : CDCACM::FindByProduct(PRODUCT_ID))
found.emplace_back(new NeoOBD2SIM(neodevice)); found.emplace_back(new NeoOBD2SIM(neodevice));
return found; return found;
@ -33,7 +33,7 @@ public:
private: private:
NeoOBD2SIM(neodevice_t neodevice) : Device(neodevice) { NeoOBD2SIM(neodevice_t neodevice) : Device(neodevice) {
initialize<STM32>(); initialize<CDCACM>();
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID; productId = PRODUCT_ID;
} }

View File

@ -6,7 +6,7 @@
#include "icsneo/device/device.h" #include "icsneo/device/device.h"
#include "icsneo/device/devicetype.h" #include "icsneo/device/devicetype.h"
#include "icsneo/device/tree/radmoonduo/radmoonduosettings.h" #include "icsneo/device/tree/radmoonduo/radmoonduosettings.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
namespace icsneo { namespace icsneo {
@ -19,7 +19,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) for(auto neodevice : CDCACM::FindByProduct(PRODUCT_ID))
found.emplace_back(new RADMoonDuo(neodevice)); found.emplace_back(new RADMoonDuo(neodevice));
return found; return found;
@ -35,7 +35,7 @@ public:
protected: protected:
RADMoonDuo(neodevice_t neodevice) : Device(neodevice) { RADMoonDuo(neodevice_t neodevice) : Device(neodevice) {
initialize<STM32, RADMoonDuoSettings>(); initialize<CDCACM, RADMoonDuoSettings>();
productId = PRODUCT_ID; productId = PRODUCT_ID;
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
} }

View File

@ -4,7 +4,7 @@
#ifdef __cplusplus #ifdef __cplusplus
#include "icsneo/device/tree/radpluto/radpluto.h" #include "icsneo/device/tree/radpluto/radpluto.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
namespace icsneo { namespace icsneo {
@ -14,7 +14,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) for(auto neodevice : CDCACM::FindByProduct(PRODUCT_ID))
found.emplace_back(new RADPlutoUSB(neodevice)); found.emplace_back(new RADPlutoUSB(neodevice));
return found; return found;
@ -22,7 +22,7 @@ public:
private: private:
RADPlutoUSB(neodevice_t neodevice) : RADPluto(neodevice) { RADPlutoUSB(neodevice_t neodevice) : RADPluto(neodevice) {
initialize<STM32, RADPlutoSettings>(); initialize<CDCACM, RADPlutoSettings>();
} }
}; };

View File

@ -5,7 +5,7 @@
#include "icsneo/device/tree/valuecan4/valuecan4.h" #include "icsneo/device/tree/valuecan4/valuecan4.h"
#include "icsneo/device/tree/valuecan4/settings/valuecan4-1settings.h" #include "icsneo/device/tree/valuecan4/settings/valuecan4-1settings.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <string> #include <string>
namespace icsneo { namespace icsneo {
@ -19,7 +19,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(USB_PRODUCT_ID)) { for(auto neodevice : CDCACM::FindByProduct(USB_PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START) if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START)
found.emplace_back(new ValueCAN4_1(neodevice)); found.emplace_back(new ValueCAN4_1(neodevice));
} }
@ -50,7 +50,7 @@ protected:
private: private:
ValueCAN4_1(neodevice_t neodevice) : ValueCAN4(neodevice) { ValueCAN4_1(neodevice_t neodevice) : ValueCAN4(neodevice) {
initialize<STM32, ValueCAN4_1Settings>(); initialize<CDCACM, ValueCAN4_1Settings>();
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = USB_PRODUCT_ID; productId = USB_PRODUCT_ID;
} }

View File

@ -5,7 +5,7 @@
#include "icsneo/device/tree/valuecan4/valuecan4.h" #include "icsneo/device/tree/valuecan4/valuecan4.h"
#include "icsneo/device/tree/valuecan4/settings/valuecan4-2settings.h" #include "icsneo/device/tree/valuecan4/settings/valuecan4-2settings.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <string> #include <string>
namespace icsneo { namespace icsneo {
@ -24,7 +24,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(USB_PRODUCT_ID)) { for(auto neodevice : CDCACM::FindByProduct(USB_PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START) if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START)
found.emplace_back(new ValueCAN4_2(neodevice)); found.emplace_back(new ValueCAN4_2(neodevice));
} }
@ -70,7 +70,7 @@ protected:
private: private:
ValueCAN4_2(neodevice_t neodevice) : ValueCAN4(neodevice) { ValueCAN4_2(neodevice_t neodevice) : ValueCAN4(neodevice) {
initialize<STM32, ValueCAN4_2Settings>(); initialize<CDCACM, ValueCAN4_2Settings>();
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = USB_PRODUCT_ID; productId = USB_PRODUCT_ID;
} }

View File

@ -67,7 +67,7 @@ protected:
private: private:
ValueCAN4_2EL_ETH(neodevice_t neodevice) : ValueCAN4_2EL(neodevice) { ValueCAN4_2EL_ETH(neodevice_t neodevice) : ValueCAN4_2EL(neodevice) {
initialize<STM32, ValueCAN4_2ELSettings>(); initialize<CDCACM, ValueCAN4_2ELSettings>();
productId = ETH_PRODUCT_ID; productId = ETH_PRODUCT_ID;
} }
}; };

View File

@ -4,7 +4,7 @@
#ifdef __cplusplus #ifdef __cplusplus
#include "icsneo/device/tree/valuecan4/valuecan4-2el.h" #include "icsneo/device/tree/valuecan4/valuecan4-2el.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <string> #include <string>
namespace icsneo { namespace icsneo {
@ -14,7 +14,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(USB_PRODUCT_ID)) { for(auto neodevice : CDCACM::FindByProduct(USB_PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START) if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START)
found.emplace_back(new ValueCAN4_2EL_USB(neodevice)); found.emplace_back(new ValueCAN4_2EL_USB(neodevice));
} }
@ -43,7 +43,7 @@ protected:
private: private:
ValueCAN4_2EL_USB(neodevice_t neodevice) : ValueCAN4_2EL(neodevice) { ValueCAN4_2EL_USB(neodevice_t neodevice) : ValueCAN4_2EL(neodevice) {
initialize<STM32, ValueCAN4_2ELSettings>(); initialize<CDCACM, ValueCAN4_2ELSettings>();
productId = USB_PRODUCT_ID; productId = USB_PRODUCT_ID;
} }
}; };

View File

@ -5,7 +5,7 @@
#include "icsneo/device/tree/valuecan4/valuecan4.h" #include "icsneo/device/tree/valuecan4/valuecan4.h"
#include "icsneo/device/tree/valuecan4/settings/valuecan4-4settings.h" #include "icsneo/device/tree/valuecan4/settings/valuecan4-4settings.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <string> #include <string>
namespace icsneo { namespace icsneo {
@ -26,7 +26,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(USB_PRODUCT_ID)) { for(auto neodevice : CDCACM::FindByProduct(USB_PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START) if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START)
found.emplace_back(new ValueCAN4_4(neodevice)); found.emplace_back(new ValueCAN4_4(neodevice));
} }
@ -81,7 +81,7 @@ protected:
private: private:
ValueCAN4_4(neodevice_t neodevice) : ValueCAN4(neodevice) { ValueCAN4_4(neodevice_t neodevice) : ValueCAN4(neodevice) {
initialize<STM32, ValueCAN4_4Settings>(); initialize<CDCACM, ValueCAN4_4Settings>();
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = USB_PRODUCT_ID; productId = USB_PRODUCT_ID;
} }

View File

@ -4,7 +4,7 @@
#ifdef __cplusplus #ifdef __cplusplus
#include "icsneo/device/tree/valuecan4/valuecan4industrial.h" #include "icsneo/device/tree/valuecan4/valuecan4industrial.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <string> #include <string>
namespace icsneo { namespace icsneo {
@ -14,7 +14,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(USB_PRODUCT_ID)) { for(auto neodevice : CDCACM::FindByProduct(USB_PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START) if(std::string(neodevice.serial).substr(0, 2) == SERIAL_START)
found.emplace_back(new ValueCAN4IndustrialUSB(neodevice)); found.emplace_back(new ValueCAN4IndustrialUSB(neodevice));
} }
@ -43,7 +43,7 @@ protected:
private: private:
ValueCAN4IndustrialUSB(neodevice_t neodevice) : ValueCAN4Industrial(neodevice) { ValueCAN4IndustrialUSB(neodevice_t neodevice) : ValueCAN4Industrial(neodevice) {
initialize<STM32, ValueCAN4IndustrialSettings>(); initialize<CDCACM, ValueCAN4IndustrialSettings>();
} }
}; };

View File

@ -5,7 +5,7 @@
#include "icsneo/device/device.h" #include "icsneo/device/device.h"
#include "icsneo/device/devicetype.h" #include "icsneo/device/devicetype.h"
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include "icsneo/device/tree/vividcan/vividcansettings.h" #include "icsneo/device/tree/vividcan/vividcansettings.h"
namespace icsneo { namespace icsneo {
@ -18,7 +18,7 @@ public:
static std::vector<std::shared_ptr<Device>> Find() { static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found; std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) for(auto neodevice : CDCACM::FindByProduct(PRODUCT_ID))
found.emplace_back(new VividCAN(neodevice)); found.emplace_back(new VividCAN(neodevice));
return found; return found;
@ -40,7 +40,7 @@ protected:
private: private:
VividCAN(neodevice_t neodevice) : Device(neodevice) { VividCAN(neodevice_t neodevice) : Device(neodevice) {
initialize<STM32, VividCANSettings>(); initialize<CDCACM, VividCANSettings>();
getWritableNeoDevice().type = DEVICE_TYPE; getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID; productId = PRODUCT_ID;
} }

View File

@ -0,0 +1,14 @@
#ifndef __CDCACM_H_
#define __CDCACM_H_
#define INTREPID_USB_VENDOR_ID (0x093c)
#if defined _WIN32
#include "icsneo/platform/windows/cdcacm.h"
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include "icsneo/platform/posix/cdcacm.h"
#else
#warning "This platform is not supported by the CDC ACM driver"
#endif
#endif

View File

@ -1,5 +1,5 @@
#ifndef __STM32_POSIX_H_ #ifndef __CDCACM_POSIX_H_
#define __STM32_POSIX_H_ #define __CDCACM_POSIX_H_
#ifdef __cplusplus #ifdef __cplusplus
@ -13,20 +13,20 @@
namespace icsneo { namespace icsneo {
class STM32 : public Driver { class CDCACM : public Driver {
public: public:
/* /**
* Note: This is a driver for all devices which use CDC_ACM * Note: This is a driver for all devices which use CDC_ACM
* Once we find the TTY we want it's a pretty generic POSIX TTY driver, but * Once we find the TTY we want it's a pretty generic POSIX TTY driver, but
* the method for finding the TTY we want varies by OS. * the method for finding the TTY we want varies by OS.
* On Linux, we read sysfs to find users of the CDC_ACM driver * On Linux, we read sysfs to find users of the CDC_ACM driver
* On macOS, we use IOKit to find the USB device we're looking for * On macOS, we use IOKit to find the USB device we're looking for
* As such platform specific FindByProduct & HandleToTTY code can be found * As such platform specific FindByProduct & HandleToTTY code can be found
* in stm32linux.cpp and stm32darwin.cpp respectively * in cdcacmlinux.cpp and cdcacmdarwin.cpp respectively
* Other POSIX systems (BSDs, QNX, etc) will need bespoke code written in the future * Other POSIX systems (BSDs, QNX, etc) will need bespoke code written in the future
*/ */
STM32(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) {} CDCACM(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) {}
~STM32(); ~CDCACM();
static std::vector<neodevice_t> FindByProduct(int product); static std::vector<neodevice_t> FindByProduct(int product);
bool open() override; bool open() override;

View File

@ -1,14 +0,0 @@
#ifndef __STM32_H_
#define __STM32_H_
#define INTREPID_USB_VENDOR_ID (0x093c)
#if defined _WIN32
#include "icsneo/platform/windows/stm32.h"
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include "icsneo/platform/posix/stm32.h"
#else
#warning "This platform is not supported by the STM32 driver"
#endif
#endif

View File

@ -1,5 +1,5 @@
#ifndef __STM32_WINDOWS_H_ #ifndef __CDCACM_WINDOWS_H_
#define __STM32_WINDOWS_H_ #define __CDCACM_WINDOWS_H_
#ifdef __cplusplus #ifdef __cplusplus
@ -7,9 +7,9 @@
namespace icsneo { namespace icsneo {
class STM32 : public VCP { class CDCACM : public VCP {
public: public:
STM32(const device_eventhandler_t& err, neodevice_t& forDevice) : VCP(err, forDevice) {} CDCACM(const device_eventhandler_t& err, neodevice_t& forDevice) : VCP(err, forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, { L"usbser" }); } static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, { L"usbser" }); }
}; };

View File

@ -1,4 +1,4 @@
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <dirent.h> #include <dirent.h>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
@ -14,13 +14,13 @@
using namespace icsneo; using namespace icsneo;
STM32::~STM32() { CDCACM::~CDCACM() {
awaitModeChangeComplete(); awaitModeChangeComplete();
if(isOpen()) if(isOpen())
close(); close();
} }
bool STM32::open() { bool CDCACM::open() {
if(isOpen()) { if(isOpen()) {
report(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::Error); report(APIEvent::Type::DeviceCurrentlyOpen, APIEvent::Severity::Error);
return false; return false;
@ -101,17 +101,17 @@ bool STM32::open() {
} }
// Create threads // Create threads
readThread = std::thread(&STM32::readTask, this); readThread = std::thread(&CDCACM::readTask, this);
writeThread = std::thread(&STM32::writeTask, this); writeThread = std::thread(&CDCACM::writeTask, this);
return true; return true;
} }
bool STM32::isOpen() { bool CDCACM::isOpen() {
return fd >= 0; // Negative fd indicates error or not opened yet return fd >= 0; // Negative fd indicates error or not opened yet
} }
bool STM32::close() { bool CDCACM::close() {
if(!isOpen() && !isDisconnected()) { if(!isOpen() && !isDisconnected()) {
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
return false; return false;
@ -158,11 +158,11 @@ bool STM32::close() {
} }
} }
void STM32::modeChangeIncoming() { void CDCACM::modeChangeIncoming() {
modeChanging = true; modeChanging = true;
} }
void STM32::awaitModeChangeComplete() { void CDCACM::awaitModeChangeComplete() {
std::unique_lock<std::mutex> lk(modeChangeMutex); std::unique_lock<std::mutex> lk(modeChangeMutex);
if(modeChanging && !modeChangeThread.joinable()) // Waiting for the thread to start if(modeChanging && !modeChangeThread.joinable()) // Waiting for the thread to start
modeChangeCV.wait_for(lk, std::chrono::seconds(1), [this] { return modeChangeThread.joinable(); }); modeChangeCV.wait_for(lk, std::chrono::seconds(1), [this] { return modeChangeThread.joinable(); });
@ -170,7 +170,7 @@ void STM32::awaitModeChangeComplete() {
modeChangeThread.join(); modeChangeThread.join();
} }
void STM32::readTask() { void CDCACM::readTask() {
constexpr size_t READ_BUFFER_SIZE = 2048; constexpr size_t READ_BUFFER_SIZE = 2048;
uint8_t readbuf[READ_BUFFER_SIZE]; uint8_t readbuf[READ_BUFFER_SIZE];
EventManager::GetInstance().downgradeErrorsOnCurrentThread(); EventManager::GetInstance().downgradeErrorsOnCurrentThread();
@ -209,7 +209,7 @@ void STM32::readTask() {
} }
} }
void STM32::writeTask() { void CDCACM::writeTask() {
WriteOperation writeOp; WriteOperation writeOp;
EventManager::GetInstance().downgradeErrorsOnCurrentThread(); EventManager::GetInstance().downgradeErrorsOnCurrentThread();
while(!closing && !isDisconnected()) { while(!closing && !isDisconnected()) {
@ -260,7 +260,7 @@ void STM32::writeTask() {
} }
} }
bool STM32::fdIsValid() { bool CDCACM::fdIsValid() {
struct termios tty = {}; struct termios tty = {};
return tcgetattr(fd, &tty) == 0 ? true : false; return tcgetattr(fd, &tty) == 0 ? true : false;
} }

View File

@ -1,4 +1,4 @@
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
@ -79,7 +79,7 @@ private:
io_object_t toRelease; 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; std::vector<neodevice_t> found;
CFMutableDictionaryRef ref = IOServiceMatching(kIOSerialBSDServiceValue); CFMutableDictionaryRef ref = IOServiceMatching(kIOSerialBSDServiceValue);
@ -179,10 +179,10 @@ std::vector<neodevice_t> STM32::FindByProduct(int product) {
return found; 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); std::lock_guard<std::mutex> lk(ttyTableMutex);
const size_t index = size_t(handle - HANDLE_OFFSET); const size_t index = size_t(handle - HANDLE_OFFSET);
if(index >= ttyTable.size()) 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]; return ttyTable[index];
} }

View File

@ -1,4 +1,4 @@
#include "icsneo/platform/stm32.h" #include "icsneo/platform/cdcacm.h"
#include <dirent.h> #include <dirent.h>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
@ -80,16 +80,16 @@ private:
std::string serial; std::string serial;
}; };
std::vector<neodevice_t> STM32::FindByProduct(int product) { std::vector<neodevice_t> CDCACM::FindByProduct(int product) {
std::vector<neodevice_t> found; 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()) if(!directory.openedSuccessfully())
return found; return found;
std::vector<std::string> foundusbs; std::vector<std::string> foundusbs;
for(auto& entry : directory.ls()) { 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. * 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 * 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 * 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; return found;
} }
std::string STM32::HandleToTTY(neodevice_handle_t handle) { std::string CDCACM::HandleToTTY(neodevice_handle_t handle) {
std::stringstream ss; std::stringstream ss;
ss << "/dev/ttyACM" << (int)(handle - HANDLE_OFFSET); ss << "/dev/ttyACM" << (int)(handle - HANDLE_OFFSET);
return ss.str(); return ss.str();