Resolve merge conflicts master into devicesettings

pull/4/head
Paul Hollinsky 2018-09-26 18:24:59 -04:00
commit 399c72e61d
40 changed files with 142 additions and 123 deletions

View File

@ -7,7 +7,9 @@
#include "device/include/device.h" #include "device/include/device.h"
namespace icsneo { namespace icsneo {
std::vector<std::shared_ptr<Device>> FindAllDevices();
}; std::vector<std::shared_ptr<Device>> FindAllDevices();
}
#endif #endif

View File

@ -58,6 +58,6 @@ private:
void readTask(); void readTask();
}; };
}; }
#endif #endif

View File

@ -38,6 +38,6 @@ protected:
std::atomic<bool> closing{false}; std::atomic<bool> closing{false};
}; };
}; }
#endif #endif

View File

@ -98,6 +98,6 @@ private:
void readTask(); void readTask();
}; };
}; }
#endif #endif

View File

@ -400,6 +400,6 @@ private:
} }
}; };
}; }
#endif #endif

View File

@ -1,37 +1,37 @@
#ifndef __MESSAGECALLBACK_H_ #ifndef __MESSAGECALLBACK_H_
#define __MESSAGECALLBACK_H_ #define __MESSAGECALLBACK_H_
#include "communication/message/include/message.h" #include "communication/message/include/message.h"
#include "communication/message/filter/include/messagefilter.h" #include "communication/message/filter/include/messagefilter.h"
#include <memory> #include <memory>
#include <functional> #include <functional>
namespace icsneo { namespace icsneo {
class MessageCallback { class MessageCallback {
public: public:
typedef std::function< void( std::shared_ptr<Message> ) > fn_messageCallback; typedef std::function< void( std::shared_ptr<Message> ) > fn_messageCallback;
MessageCallback(fn_messageCallback cb, std::shared_ptr<MessageFilter> f) : callback(cb), filter(f) {} MessageCallback(fn_messageCallback cb, std::shared_ptr<MessageFilter> f) : callback(cb), filter(f) {}
MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter()) : callback(cb), filter(std::make_shared<MessageFilter>(f)) {} MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter()) : callback(cb), filter(std::make_shared<MessageFilter>(f)) {}
// Allow the filter to be placed first if the user wants (maybe in the case of a lambda) // Allow the filter to be placed first if the user wants (maybe in the case of a lambda)
MessageCallback(MessageFilter f, fn_messageCallback cb) { MessageCallback(cb, f); } MessageCallback(MessageFilter f, fn_messageCallback cb) { MessageCallback(cb, f); }
virtual bool callIfMatch(const std::shared_ptr<Message>& message) const { virtual bool callIfMatch(const std::shared_ptr<Message>& message) const {
bool ret = filter->match(message); bool ret = filter->match(message);
if(ret) if(ret)
callback(message); callback(message);
return ret; return ret;
} }
const MessageFilter& getFilter() const { return *filter; } const MessageFilter& getFilter() const { return *filter; }
const fn_messageCallback& getCallback() const { return callback; } const fn_messageCallback& getCallback() const { return callback; }
protected: protected:
fn_messageCallback callback; fn_messageCallback callback;
std::shared_ptr<MessageFilter> filter; std::shared_ptr<MessageFilter> filter;
}; };
}; }
#endif #endif

View File

@ -1,47 +1,47 @@
#ifndef __MESSAGEFILTER_H_ #ifndef __MESSAGEFILTER_H_
#define __MESSAGEFILTER_H_ #define __MESSAGEFILTER_H_
#include "communication/include/network.h" #include "communication/include/network.h"
#include "communication/message/include/message.h" #include "communication/message/include/message.h"
#include <memory> #include <memory>
namespace icsneo { namespace icsneo {
class MessageFilter { class MessageFilter {
public: public:
MessageFilter() : matchAny(true) {} MessageFilter() : matchAny(true) {}
MessageFilter(Network::Type type) : type(type) {} MessageFilter(Network::Type type) : type(type) {}
MessageFilter(Network::NetID netid) : netid(netid) {} MessageFilter(Network::NetID netid) : netid(netid) {}
virtual ~MessageFilter() {} virtual ~MessageFilter() {}
virtual bool match(const std::shared_ptr<Message>& message) const { virtual bool match(const std::shared_ptr<Message>& message) const {
if(matchAny) if(matchAny)
return true; return true;
if(!matchType(message->network.getType())) if(!matchType(message->network.getType()))
return false; return false;
if(!matchNetID(message->network.getNetID())) if(!matchNetID(message->network.getNetID()))
return false; return false;
return true; return true;
} }
private: private:
bool matchAny = false; bool matchAny = false;
Network::Type type = Network::Type::Invalid; // Matching a type of invalid will match any Network::Type type = Network::Type::Invalid; // Matching a type of invalid will match any
bool matchType(Network::Type mtype) const { bool matchType(Network::Type mtype) const {
if(type == Network::Type::Invalid) if(type == Network::Type::Invalid)
return true; return true;
return type == mtype; return type == mtype;
} }
Network::NetID netid = Network::NetID::Invalid; // Matching a netid of invalid will match any Network::NetID netid = Network::NetID::Invalid; // Matching a netid of invalid will match any
bool matchNetID(Network::NetID mnetid) const { bool matchNetID(Network::NetID mnetid) const {
if(netid == Network::NetID::Invalid) if(netid == Network::NetID::Invalid)
return true; return true;
return netid == mnetid; return netid == mnetid;
} }
}; };
}; }
#endif #endif

View File

@ -10,6 +10,6 @@ public:
uint32_t arbid; uint32_t arbid;
}; };
}; }
#endif #endif

View File

@ -14,6 +14,6 @@ public:
uint64_t timestamp; uint64_t timestamp;
}; };
}; }
#endif #endif

View File

@ -32,8 +32,10 @@ typedef struct {
#include "communication/message/include/message.h" #include "communication/message/include/message.h"
namespace icsneo { namespace icsneo {
neomessage_t CreateNeoMessage(const Message& message);
}; neomessage_t CreateNeoMessage(const Message& message);
}
#endif #endif
#endif #endif

View File

@ -86,7 +86,7 @@ bool Packetizer::input(const std::vector<uint8_t>& inputBytes) {
break; break;
case ReadState::GetData: case ReadState::GetData:
// We do not include the checksum in packetLength so it doesn't get copied into the payload buffer // We do not include the checksum in packetLength so it doesn't get copied into the payload buffer
if(bytes.size() < packetLength + (checksum ? 1 : 0)) { // Read until we have the rest of the packet if(bytes.size() < (size_t)(packetLength + (checksum ? 1 : 0))) { // Read until we have the rest of the packet
haveEnoughData = false; haveEnoughData = false;
break; break;
} }

View File

@ -78,6 +78,6 @@ private:
void enforcePollingMessageLimit(); void enforcePollingMessageLimit();
}; };
}; }
#endif #endif

View File

@ -12,6 +12,6 @@ public:
static std::vector<std::shared_ptr<Device>> FindAll(); static std::vector<std::shared_ptr<Device>> FindAll();
}; };
}; }
#endif #endif

View File

@ -6,8 +6,10 @@
#ifdef __cplusplus #ifdef __cplusplus
// A forward declaration is needed as there is a circular dependency // A forward declaration is needed as there is a circular dependency
namespace icsneo { namespace icsneo {
class Device;
}; class Device;
}
typedef icsneo::Device* devicehandle_t; typedef icsneo::Device* devicehandle_t;
#else #else
typedef void* devicehandle_t; typedef void* devicehandle_t;

View File

@ -30,6 +30,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -30,6 +30,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -53,6 +53,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -14,6 +14,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -40,6 +40,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -29,6 +29,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -25,6 +25,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -25,6 +25,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -17,6 +17,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -44,6 +44,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -30,6 +30,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -33,6 +33,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -29,6 +29,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -30,6 +30,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -32,6 +32,6 @@ public:
} }
}; };
}; }
#endif #endif

View File

@ -1,6 +1,6 @@
#ifndef __DYNAMICLIB_DARWIN_H_ #ifndef __DYNAMICLIB_DARWIN_H_
#define __DYNAMICLIB_DARWIN_H_ #define __DYNAMICLIB_DARWIN_H_
#define icsneo_dynamicLibraryLoad() dlopen("/home/paulywog/Code/icsneonext/build/libicsneoc.dylib", RTLD_LAZY) #define icsneo_dynamicLibraryLoad() dlopen("/Users/paulywog/Code/icsneonext/build/libicsneoc.dylib", RTLD_LAZY)
#endif #endif

View File

@ -46,6 +46,6 @@ private:
FTDIDevice ftdiDevice; FTDIDevice ftdiDevice;
}; };
}; }
#endif #endif

View File

@ -26,6 +26,6 @@ private:
void writeTask(); void writeTask();
}; };
}; }
#endif #endif

View File

@ -273,8 +273,8 @@ void STM32::writeTask() {
if(!writeQueue.wait_dequeue_timed(writeOp, std::chrono::milliseconds(100))) if(!writeQueue.wait_dequeue_timed(writeOp, std::chrono::milliseconds(100)))
continue; continue;
const auto writeSize = writeOp.bytes.size(); const ssize_t writeSize = (ssize_t)writeOp.bytes.size();
int actualWritten = ::write(fd, writeOp.bytes.data(), writeSize); ssize_t actualWritten = ::write(fd, writeOp.bytes.data(), writeSize);
if(actualWritten != writeSize) if(actualWritten != writeSize)
std::cout << "Failure to write " << writeSize << " bytes, wrote " << actualWritten << std::endl; std::cout << "Failure to write " << writeSize << " bytes, wrote " << actualWritten << std::endl;
} }

View File

@ -11,6 +11,6 @@ public:
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"serenum"); } static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"serenum"); }
}; };
}; }
#endif #endif

View File

@ -65,6 +65,6 @@ private:
}; };
}; };
}; }
#endif #endif

View File

@ -28,6 +28,6 @@ private:
}; };
}; };
}; }
#endif #endif

View File

@ -11,6 +11,6 @@ public:
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"); }
}; };
}; }
#endif #endif

View File

@ -43,6 +43,6 @@ private:
void writeTask(); void writeTask();
}; };
}; }
#endif #endif

View File

@ -4,12 +4,17 @@
#include <Windows.h> #include <Windows.h>
#include <winsock2.h> #include <winsock2.h>
#include <pcap.h> #include <pcap.h>
#include <memory>
namespace icsneo { namespace icsneo {
// Helper loader for the PCAP DLL // Helper loader for the PCAP DLL
class PCAPDLL { class PCAPDLL {
public: public:
// The first time we use the DLL we keep it in here and it won't get freed until the user unloads us (for speed reasons)
static std::shared_ptr<PCAPDLL> lazyLoadHolder;
static bool lazyLoaded;
// Functions // Functions
typedef int(__cdecl* PCAPFINDDEVICE)(char* source, struct pcap_rmtauth* auth, pcap_if_t** alldevs, char* errbuf); typedef int(__cdecl* PCAPFINDDEVICE)(char* source, struct pcap_rmtauth* auth, pcap_if_t** alldevs, char* errbuf);
typedef pcap_t*(__cdecl* PCAPOPEN)(const char* source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth* auth, char* errbuf); typedef pcap_t*(__cdecl* PCAPOPEN)(const char* source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth* auth, char* errbuf);
@ -48,6 +53,6 @@ private:
void closeDLL(); void closeDLL();
}; };
}; }
#endif #endif

View File

@ -2,7 +2,15 @@
using namespace icsneo; using namespace icsneo;
std::shared_ptr<PCAPDLL> PCAPDLL::lazyLoadHolder;
bool PCAPDLL::lazyLoaded = false;
PCAPDLL::PCAPDLL() { PCAPDLL::PCAPDLL() {
if(!lazyLoaded) {
lazyLoaded = true;
lazyLoadHolder = std::make_shared<PCAPDLL>();
}
dll = LoadLibrary("wpcap.dll"); dll = LoadLibrary("wpcap.dll");
if(dll == NULL) { if(dll == NULL) {