mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Refactor for a central include directory
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#ifndef __DEVICES_WINDOWS_H_
|
||||
#define __DEVICES_WINDOWS_H_
|
||||
|
||||
#include "icsneo/device/neoobd2pro/neoobd2pro.h"
|
||||
#include "icsneo/device/neoobd2sim/neoobd2sim.h"
|
||||
#include "icsneo/device/neovifire/neovifire.h"
|
||||
#include "icsneo/device/neovifire2/neovifire2eth.h"
|
||||
#include "icsneo/device/neovifire2/neovifire2usb.h"
|
||||
#include "icsneo/device/plasion/neoviion.h"
|
||||
#include "icsneo/device/plasion/neoviplasma.h"
|
||||
#include "icsneo/device/radgalaxy/radgalaxy.h"
|
||||
#include "icsneo/device/radstar2/radstar2eth.h"
|
||||
#include "icsneo/device/radstar2/radstar2usb.h"
|
||||
#include "icsneo/device/radsupermoon/radsupermoon.h"
|
||||
#include "icsneo/device/valuecan3/valuecan3.h"
|
||||
#include "icsneo/device/valuecan4/valuecan4-1.h"
|
||||
#include "icsneo/device/valuecan4/valuecan4-2.h"
|
||||
#include "icsneo/device/valuecan4/valuecan4-2el.h"
|
||||
#include "icsneo/device/valuecan4/valuecan4-4.h"
|
||||
#include "icsneo/device/vividcan/vividcan.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#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
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef __FTDI_WINDOWS_H_
|
||||
#define __FTDI_WINDOWS_H_
|
||||
|
||||
#include "icsneo/platform/windows/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
|
||||
@@ -0,0 +1,58 @@
|
||||
#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
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef __PCAP_WINDOWS_H_
|
||||
#define __PCAP_WINDOWS_H_
|
||||
|
||||
#include "icsneo/platform/windows/internal/pcapdll.h"
|
||||
#include "icsneo/device/neodevice.h"
|
||||
#include "icsneo/communication/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
|
||||
@@ -0,0 +1,33 @@
|
||||
#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
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef __STM32_WINDOWS_H_
|
||||
#define __STM32_WINDOWS_H_
|
||||
|
||||
#include "icsneo/platform/windows/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
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef __VCP_WINDOWS_H_
|
||||
#define __VCP_WINDOWS_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <Windows.h>
|
||||
#include "icsneo/device/neodevice.h"
|
||||
#include "icsneo/communication/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
|
||||
Reference in New Issue
Block a user