Merge remote-tracking branch 'origin/master' into pcap

This commit is contained in:
Paul Hollinsky
2019-05-06 13:16:29 -04:00
25 changed files with 2453 additions and 989 deletions
+1
View File
@@ -54,6 +54,7 @@ public:
FailedToWrite = 0x3001,
DriverFailedToOpen = 0x3002,
PacketChecksumError = 0x3003,
TransmitBufferFull = 0x3004,
PCAPCouldNotStart = 0x3102,
PCAPCouldNotFindDevices = 0x3103,
+16 -1
View File
@@ -5,12 +5,16 @@
#include <chrono>
#include <atomic>
#include <thread>
#include <mutex>
#include <condition_variable>
#include "icsneo/api/errormanager.h"
#include "icsneo/third-party/concurrentqueue/blockingconcurrentqueue.h"
namespace icsneo {
class ICommunication {
public:
ICommunication(const device_errorhandler_t& handler) : err(handler) {}
virtual ~ICommunication() {}
virtual bool open() = 0;
virtual bool isOpen() = 0;
@@ -18,12 +22,21 @@ public:
virtual bool read(std::vector<uint8_t>& bytes, size_t limit = 0);
virtual bool readWait(std::vector<uint8_t>& bytes, std::chrono::milliseconds timeout = std::chrono::milliseconds(100), size_t limit = 0);
virtual bool write(const std::vector<uint8_t>& bytes);
inline void onWrite() {
if(writeQueue.size_approx() < (writeQueueSize * 3/4))
writeCV.notify_one();
}
device_errorhandler_t err;
size_t writeQueueSize = 50;
bool writeBlocks = true; // Otherwise it just fails when the queue is full
protected:
class WriteOperation {
public:
WriteOperation() {}
WriteOperation(std::vector<uint8_t> b) { bytes = b; }
WriteOperation(const std::vector<uint8_t>& b) : bytes(b) {}
std::vector<uint8_t> bytes;
};
enum IOTaskState {
@@ -34,6 +47,8 @@ protected:
virtual void writeTask() = 0;
moodycamel::BlockingConcurrentQueue<uint8_t> readQueue;
moodycamel::BlockingConcurrentQueue<WriteOperation> writeQueue;
std::mutex writeMutex;
std::condition_variable writeCV;
std::thread readThread, writeThread;
std::atomic<bool> closing{false};
};
@@ -9,10 +9,11 @@ class CANMessage : public Message {
public:
uint32_t arbid;
uint8_t dlcOnWire;
bool isRemote = false;
bool isRemote = false; // Not allowed if CAN FD
bool isExtended = false;
bool isCANFD = false;
bool baudrateSwitch = false; // CAN FD only
bool errorStateIndicator = false; // CAN FD only
};
}
+2272 -943
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -16,7 +16,7 @@ class FTDI : public ICommunication {
public:
static std::vector<neodevice_t> FindByProduct(int product);
FTDI(device_errorhandler_t err, neodevice_t& forDevice);
FTDI(const device_errorhandler_t& err, neodevice_t& forDevice);
~FTDI() { close(); }
bool open();
bool close();
@@ -56,7 +56,6 @@ private:
bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices
neodevice_t& device;
device_errorhandler_t err;
};
}
+1 -2
View File
@@ -11,7 +11,7 @@ namespace icsneo {
class STM32 : public ICommunication {
public:
STM32(device_errorhandler_t err, neodevice_t& forDevice) : device(forDevice), err(err) {}
STM32(const device_errorhandler_t& err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product);
bool open();
@@ -20,7 +20,6 @@ public:
private:
neodevice_t& device;
device_errorhandler_t err;
int fd = -1;
static constexpr neodevice_handle_t HANDLE_OFFSET = 10;
+1 -1
View File
@@ -7,7 +7,7 @@ namespace icsneo {
class FTDI : public VCP {
public:
FTDI(device_errorhandler_t err, neodevice_t& forDevice) : VCP(err, forDevice) {}
FTDI(const device_errorhandler_t& err, neodevice_t& forDevice) : VCP(err, forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, { L"serenum" /*, L"ftdibus" */ }); }
};
+1 -1
View File
@@ -21,7 +21,7 @@ public:
static std::string GetEthDevSerialFromMacAddress(uint8_t product, uint16_t macSerial);
static bool IsHandleValid(neodevice_handle_t handle);
PCAP(device_errorhandler_t err, neodevice_t& forDevice);
PCAP(const device_errorhandler_t& err, neodevice_t& forDevice);
bool open();
bool isOpen();
bool close();
+1 -1
View File
@@ -7,7 +7,7 @@ namespace icsneo {
class STM32 : public VCP {
public:
STM32(device_errorhandler_t err, neodevice_t& forDevice) : VCP(err, forDevice) {}
STM32(const device_errorhandler_t& err, neodevice_t& forDevice) : VCP(err, forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, { L"usbser" }); }
};
+1 -1
View File
@@ -20,7 +20,7 @@ public:
static bool IsHandleValid(neodevice_handle_t handle);
typedef void(*fn_boolCallback)(bool success);
VCP(device_errorhandler_t err, neodevice_t& forDevice) : device(forDevice), err(err) {
VCP(const device_errorhandler_t& err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) {
overlappedRead.hEvent = INVALID_HANDLE_VALUE;
overlappedWrite.hEvent = INVALID_HANDLE_VALUE;
overlappedWait.hEvent = INVALID_HANDLE_VALUE;