Refactor for a central include directory

This commit is contained in:
Paul Hollinsky
2018-10-22 11:52:34 -04:00
parent 12451def11
commit 8e6b0d0b0e
127 changed files with 263 additions and 265 deletions
-12
View File
@@ -1,12 +0,0 @@
#ifndef __DEVICES_H_
#define __DEVICES_H_
#if defined _WIN32
#include "platform/windows/include/devices.h"
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include "platform/posix/include/devices.h"
#else
#error "This platform is not supported by the devices driver, please add a definition!"
#endif
#endif
-12
View File
@@ -1,12 +0,0 @@
#ifndef __DYNAMICLIB_H_
#define __DYNAMICLIB_H_
#if defined _WIN32
#include "platform/windows/include/dynamiclib.h"
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include "platform/posix/include/dynamiclib.h"
#else
#warning "This platform is not supported by the dynamic library driver"
#endif
#endif
-14
View File
@@ -1,14 +0,0 @@
#ifndef __FTDI_H_
#define __FTDI_H_
#define INTREPID_USB_VENDOR_ID (0x093c)
#if defined _WIN32
#include "platform/windows/include/ftdi.h"
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include "platform/posix/include/ftdi.h"
#else
#warning "This platform is not supported by the FTDI driver"
#endif
#endif
-12
View File
@@ -1,12 +0,0 @@
#ifndef __PCAP_H_
#define __PCAP_H_
#if defined _WIN32
#include "platform/windows/include/pcap.h"
// #elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
// #include "platform/posix/include/ftdi.h"
#else
#warning "This platform is not supported by the PCAP driver"
#endif
#endif
-10
View File
@@ -1,10 +0,0 @@
#ifndef __REGISTRY_H_
#define __REGISTRY_H_
#if defined _WIN32
#include "platform/windows/include/registry.h"
#else
#warning "This platform is not supported by the registry driver"
#endif
#endif
-14
View File
@@ -1,14 +0,0 @@
#ifndef __STM32_H_
#define __STM32_H_
#define INTREPID_USB_VENDOR_ID (0x093c)
#if defined _WIN32
#include "platform/windows/include/stm32.h"
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include "platform/posix/include/stm32.h"
#else
#warning "This platform is not supported by the STM32 driver"
#endif
#endif
-12
View File
@@ -1,12 +0,0 @@
#ifndef __TCHAR_H_
#define __TCHAR_H_
#if defined _WIN32
// Windows does not need a TCHAR definition, as it is natively defined
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include "platform/posix/include/tchar.h"
#else
#warning "Please add a definition for this platform's equivalent to TCHAR"
#endif
#endif
@@ -1,6 +0,0 @@
#ifndef __DYNAMICLIB_DARWIN_H_
#define __DYNAMICLIB_DARWIN_H_
#define icsneo_dynamicLibraryLoad() dlopen("/Users/paulywog/Code/icsneonext/build/libicsneoc.dylib", RTLD_LAZY)
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
#include "platform/include/ftdi.h"
#include "icsneo/platform/ftdi.h"
#include <iostream>
#include <stdio.h>
#include <cstring>
-22
View File
@@ -1,22 +0,0 @@
#ifndef __DEVICES_POSIX_H_
#define __DEVICES_POSIX_H_
#include "device/neoobd2pro/include/neoobd2pro.h"
#include "device/neoobd2sim/include/neoobd2sim.h"
#include "device/neovifire/include/neovifire.h"
//#include "device/neovifire2/include/neovifire2eth.h" Ethernet not yet supported
#include "device/neovifire2/include/neovifire2usb.h"
#include "device/plasion/include/neoviion.h"
#include "device/plasion/include/neoviplasma.h"
//#include "device/radgalaxy/include/radgalaxy.h" Ethernet not yet supported
//#include "device/radstar2/include/radstar2eth.h" Ethernet not yet supported
#include "device/radstar2/include/radstar2usb.h"
#include "device/radsupermoon/include/radsupermoon.h"
#include "device/valuecan3/include/valuecan3.h"
#include "device/valuecan4/include/valuecan4-1.h"
#include "device/valuecan4/include/valuecan4-2.h"
#include "device/valuecan4/include/valuecan4-2el.h"
#include "device/valuecan4/include/valuecan4-4.h"
#include "device/vividcan/include/vividcan.h"
#endif
-24
View File
@@ -1,24 +0,0 @@
#ifndef __DYNAMICLIB_POSIX_H_
#define __DYNAMICLIB_POSIX_H_
#include <dlfcn.h>
#ifdef __APPLE__
#include "platform/posix/darwin/include/dynamiclib.h"
#else
#include "platform/posix/linux/include/dynamiclib.h"
#endif
// Nothing special is needed to export
#define DLLExport
// #ifndef ICSNEO_NO_AUTO_DESTRUCT
// #define ICSNEO_DESTRUCTOR __attribute__((destructor));
// #else
#define ICSNEO_DESTRUCTOR
// #endif
#define icsneo_dynamicLibraryGetFunction(handle, func) dlsym(handle, func)
#define icsneo_dynamicLibraryClose(handle) (dlclose(handle) == 0)
#endif
-51
View File
@@ -1,51 +0,0 @@
#ifndef __FTDI_POSIX_H_
#define __FTDI_POSIX_H_
#include <vector>
#include <memory>
#include <string>
#include <atomic>
#include <ftdi.hpp>
#include "device/include/neodevice.h"
#include "communication/include/icommunication.h"
#include "third-party/concurrentqueue/blockingconcurrentqueue.h"
namespace icsneo {
class FTDI : public ICommunication {
public:
static constexpr neodevice_handle_t INVALID_HANDLE = 0x7fffffff; // int32_t max value
static std::vector<neodevice_t> FindByProduct(int product);
static bool IsHandleValid(neodevice_handle_t handle);
FTDI(neodevice_t& forDevice);
~FTDI() { close(); }
bool open();
bool close();
bool isOpen() { return ftdiDevice.is_open(); }
private:
static Ftdi::Context context;
static neodevice_handle_t handleCounter;
class FTDIDevice : public Ftdi::Context {
public:
FTDIDevice() {}
FTDIDevice(const Ftdi::Context &x) : Ftdi::Context(x) {
handle = handleCounter++;
}
neodevice_handle_t handle = INVALID_HANDLE;
};
static std::vector<FTDIDevice> searchResultDevices;
static bool GetDeviceForHandle(neodevice_handle_t handle, FTDIDevice& device);
void readTask();
void writeTask();
bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices
neodevice_t& device;
FTDIDevice ftdiDevice;
};
}
#endif
-31
View File
@@ -1,31 +0,0 @@
#ifndef __STM32_POSIX_H_
#define __STM32_POSIX_H_
#include "communication/include/icommunication.h"
#include "device/include/neodevice.h"
#include <chrono>
#include <stdint.h>
namespace icsneo {
class STM32 : public ICommunication {
public:
STM32(neodevice_t& forDevice) : device(forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product);
bool open();
bool isOpen();
bool close();
private:
neodevice_t& device;
int fd = -1;
static constexpr neodevice_handle_t HANDLE_OFFSET = 10;
void readTask();
void writeTask();
};
}
#endif
-6
View File
@@ -1,6 +0,0 @@
#ifndef __TCHAR_POSIX_H_
#define __TCHAR_POSIX_H_
typedef char TCHAR;
#endif
@@ -1,6 +0,0 @@
#ifndef __DYNAMICLIB_LINUX_H_
#define __DYNAMICLIB_LINUX_H_
#define icsneo_dynamicLibraryLoad() dlopen("libicsneoc.so", RTLD_LAZY)
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
#include "platform/include/stm32.h"
#include "icsneo/platform/stm32.h"
#include <dirent.h>
#include <cstring>
#include <iostream>
-22
View File
@@ -1,22 +0,0 @@
#ifndef __DEVICES_WINDOWS_H_
#define __DEVICES_WINDOWS_H_
#include "device/neoobd2pro/include/neoobd2pro.h"
#include "device/neoobd2sim/include/neoobd2sim.h"
#include "device/neovifire/include/neovifire.h"
#include "device/neovifire2/include/neovifire2eth.h"
#include "device/neovifire2/include/neovifire2usb.h"
#include "device/plasion/include/neoviion.h"
#include "device/plasion/include/neoviplasma.h"
#include "device/radgalaxy/include/radgalaxy.h"
#include "device/radstar2/include/radstar2eth.h"
#include "device/radstar2/include/radstar2usb.h"
#include "device/radsupermoon/include/radsupermoon.h"
#include "device/valuecan3/include/valuecan3.h"
#include "device/valuecan4/include/valuecan4-1.h"
#include "device/valuecan4/include/valuecan4-2.h"
#include "device/valuecan4/include/valuecan4-2el.h"
#include "device/valuecan4/include/valuecan4-4.h"
#include "device/vividcan/include/vividcan.h"
#endif
-19
View File
@@ -1,19 +0,0 @@
#ifndef __DYNAMICLIB_WINDOWS_H_
#define __DYNAMICLIB_WINDOWS_H_
#include <Windows.h>
#ifdef ICSNEOC_MAKEDLL
#define DLLExport __declspec(dllexport)
#else
#define DLLExport __declspec(dllimport)
#endif
// MSVC does not have the ability to specify a destructor
#define ICSNEO_DESTRUCTOR
#define icsneo_dynamicLibraryLoad() LoadLibrary(L"C:\\Users\\Phollinsky\\Code\\icsneonext\\build\\icsneoc.dll")
#define icsneo_dynamicLibraryGetFunction(handle, func) GetProcAddress((HMODULE) handle, func)
#define icsneo_dynamicLibraryClose(handle) FreeLibrary((HMODULE) handle)
#endif
-16
View File
@@ -1,16 +0,0 @@
#ifndef __FTDI_WINDOWS_H_
#define __FTDI_WINDOWS_H_
#include "platform/windows/include/vcp.h"
namespace icsneo {
class FTDI : public VCP {
public:
FTDI(neodevice_t& forDevice) : VCP(forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"serenum"); }
};
}
#endif
-76
View File
@@ -1,76 +0,0 @@
#ifndef __PCAP_WINDOWS_H_
#define __PCAP_WINDOWS_H_
#include "platform/windows/internal/include/pcapdll.h"
#include "device/include/neodevice.h"
#include "communication/include/icommunication.h"
#include <string>
namespace icsneo {
class PCAP : public ICommunication {
public:
class PCAPFoundDevice {
public:
neodevice_t device;
std::vector<std::vector<uint8_t>> discoveryPackets;
};
static std::vector<PCAPFoundDevice> FindAll();
static std::string GetEthDevSerialFromMacAddress(uint8_t product, uint16_t macSerial);
static bool IsHandleValid(neodevice_handle_t handle);
PCAP(neodevice_t& forDevice);
bool open();
bool isOpen();
bool close();
private:
PCAPDLL pcap;
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
neodevice_t& device;
uint8_t deviceMAC[6];
bool openable = true;
void readTask();
void writeTask();
class NetworkInterface {
public:
uint8_t uuid;
uint8_t macAddress[8];
std::string nameFromWinPCAP;
std::string nameFromWin32API;
std::string descriptionFromWinPCAP;
std::string descriptionFromWin32API;
std::string friendlyNameFromWin32API;
std::string fullName;
pcap_t* fp = nullptr;
pcap_stat stats;
};
static std::vector<NetworkInterface> knownInterfaces;
NetworkInterface interface;
class EthernetPacket {
public: // Don't worry about endian when setting fields, this is all taken care of in getBytestream
EthernetPacket() {};
EthernetPacket(const std::vector<uint8_t>& bytestream);
EthernetPacket(const uint8_t* data, size_t size);
int loadBytestream(const std::vector<uint8_t>& bytestream);
std::vector<uint8_t> getBytestream() const;
uint8_t errorWhileDecodingFromBytestream = 0; // Not part of final bytestream, only for checking the result of the constructor
uint8_t destMAC[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
uint8_t srcMAC[6] = { 0x00, 0xFC, 0x70, 0xFF, 0xFF, 0xFF };
uint16_t etherType = 0xCAB1; // Big endian, Should be 0xCAB1 or 0xCAB2
uint32_t icsEthernetHeader = 0xAAAA5555; // Big endian, Should be 0xAAAA5555
// At this point in the packet, there is a 16-bit payload size, little endian
// This is calculated from payload size in getBytestream
uint16_t packetNumber = 0;
bool firstPiece = true; // These booleans make up a 16-bit bitfield, packetInfo
bool lastPiece = true;
bool bufferHalfFull = false;
std::vector<uint8_t> payload;
};
};
}
#endif
-33
View File
@@ -1,33 +0,0 @@
#ifndef __REGISTRY_WINDOWS_H_
#define __REGISTRY_WINDOWS_H_
#include <Windows.h>
#include <string>
namespace icsneo {
class Registry {
public:
// Get string value
static bool Get(std::wstring path, std::wstring key, std::wstring& value);
static bool Get(std::string path, std::string key, std::string& value);
// Get DWORD value
static bool Get(std::wstring path, std::wstring key, uint32_t& value);
static bool Get(std::string path, std::string key, uint32_t& value);
private:
class Key {
public:
Key(std::wstring path, bool readwrite = false);
~Key();
HKEY GetKey() { return key; }
bool IsOpen() { return key != nullptr; }
private:
HKEY key;
};
};
}
#endif
-16
View File
@@ -1,16 +0,0 @@
#ifndef __STM32_WINDOWS_H_
#define __STM32_WINDOWS_H_
#include "platform/windows/include/vcp.h"
namespace icsneo {
class STM32 : public VCP {
public:
STM32(neodevice_t& forDevice) : VCP(forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"usbser"); }
};
}
#endif
-48
View File
@@ -1,48 +0,0 @@
#ifndef __VCP_WINDOWS_H_
#define __VCP_WINDOWS_H_
#include <vector>
#include <string>
#include <thread>
#include <atomic>
#include <chrono>
#include <Windows.h>
#include "device/include/neodevice.h"
#include "communication/include/icommunication.h"
namespace icsneo {
// Virtual COM Port Communication
class VCP : public ICommunication {
public:
static std::vector<neodevice_t> FindByProduct(int product, wchar_t* driverName);
static bool IsHandleValid(neodevice_handle_t handle);
typedef void(*fn_boolCallback)(bool success);
VCP(neodevice_t& forDevice) : device(forDevice) {
overlappedRead.hEvent = INVALID_HANDLE_VALUE;
overlappedWrite.hEvent = INVALID_HANDLE_VALUE;
overlappedWait.hEvent = INVALID_HANDLE_VALUE;
}
~VCP() { close(); }
bool open() { return open(false); }
void openAsync(fn_boolCallback callback);
bool close();
bool isOpen() { return handle != INVALID_HANDLE_VALUE; }
private:
bool open(bool fromAsync);
bool opening = false;
neodevice_t& device;
HANDLE handle = INVALID_HANDLE_VALUE;
OVERLAPPED overlappedRead = {};
OVERLAPPED overlappedWrite = {};
OVERLAPPED overlappedWait = {};
std::vector<std::shared_ptr<std::thread>> threads;
void readTask();
void writeTask();
};
}
#endif
@@ -1,58 +0,0 @@
#ifndef __PCAPDLL_WINDOWS_H_
#define __PCAPDLL_WINDOWS_H_
#include <Windows.h>
#include <winsock2.h>
#include <pcap.h>
#include <memory>
namespace icsneo {
// Helper loader for the PCAP DLL
class PCAPDLL {
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
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 void(__cdecl* PCAPFREEDEVS)(pcap_if_t* alldevsp);
typedef void(__cdecl* PCAPCLOSE)(pcap_t* p);
typedef int(__cdecl* PCAPSTATS)(pcap_t* p, struct pcap_stat* ps);
typedef int(__cdecl* PCAPNEXTEX)(pcap_t* p, struct pcap_pkthdr** pkt_header, const u_char** pkt_data);
typedef int(__cdecl* PCAPSENDPACKET)(pcap_t* p, const u_char* buf, int size);
// typedef pcap_send_queue*(__cdecl* PCAPSENDQUEUEALLOC)(u_int memsize);
// typedef int(__cdecl* PCAPSENDQUEUEQUEUE)(pcap_send_queue* queue, const struct pcap_pkthdr* pkt_header, const u_char* pkt_data);
// typedef void(__cdecl* PCAPSENDQUEUEDESTROY)(pcap_send_queue* queue);
// typedef u_int(__cdecl* PCAPSENDQUEUETRANSMIT)(pcap_t* p, pcap_send_queue* queue, int sync);
typedef int(__cdecl* PCAPDATALINK)(pcap_t* p);
typedef int(__cdecl* PCAPCREATESRCSTR)(char* source, int type, const char* host, const char* port, const char* name, char* errbuf);
typedef int(__cdecl* PCAPSETBUFF)(pcap_t* p, int dim);
PCAPFINDDEVICE findalldevs_ex;
PCAPOPEN open;
PCAPFREEDEVS freealldevs;
PCAPCLOSE close;
PCAPSTATS stats;
PCAPNEXTEX next_ex;
PCAPSENDPACKET sendpacket;
// PCAPSENDQUEUEALLOC sendqueue_alloc;
// PCAPSENDQUEUEQUEUE sendqueue_queue;
// PCAPSENDQUEUEDESTROY sendqueue_destroy;
// PCAPSENDQUEUETRANSMIT sendqueue_transmit;
PCAPDATALINK datalink;
PCAPCREATESRCSTR createsrcstr;
PCAPSETBUFF setbuff;
PCAPDLL();
~PCAPDLL() { closeDLL(); }
bool ok() const { return dll != nullptr; }
private:
HINSTANCE dll;
void closeDLL();
};
}
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
#include "platform/windows/internal/include/pcapdll.h"
#include "icsneo/platform/windows/internal/pcapdll.h"
using namespace icsneo;
+4 -4
View File
@@ -1,7 +1,7 @@
#include "platform/windows/include/pcap.h"
#include "communication/include/network.h"
#include "communication/include/communication.h"
#include "communication/include/packetizer.h"
#include "icsneo/platform/windows/pcap.h"
#include "icsneo/communication/network.h"
#include "icsneo/communication/communication.h"
#include "icsneo/communication/packetizer.h"
#include <pcap.h>
#include <iphlpapi.h>
#pragma comment(lib, "IPHLPAPI.lib")
+1 -1
View File
@@ -1,4 +1,4 @@
#include "platform/windows/include/registry.h"
#include "icsneo/platform/windows/registry.h"
#include <codecvt>
#include <vector>
+3 -3
View File
@@ -1,6 +1,6 @@
#include "platform/windows/include/ftdi.h"
#include "platform/include/ftdi.h"
#include "platform/include/registry.h"
#include "icsneo/platform/windows/ftdi.h"
#include "icsneo/platform/ftdi.h"
#include "icsneo/platform/registry.h"
#include <iostream>
#include <iomanip>
#include <sstream>