mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Merge branch 'pcap'
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#ifndef __RADPLUTO_H_
|
||||
#define __RADPLUTO_H_
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/devicetype.h"
|
||||
#include "icsneo/platform/pcap.h"
|
||||
#include "icsneo/communication/packetizer.h"
|
||||
#include "icsneo/communication/decoder.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class RADPluto : public Device {
|
||||
public:
|
||||
// Serial numbers start with PL
|
||||
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADPluto;
|
||||
static constexpr const uint16_t PRODUCT_ID = 0xffff; // Not yet set
|
||||
static constexpr const char* SERIAL_START = "PL";
|
||||
static std::vector<std::shared_ptr<Device>> Find() {
|
||||
std::vector<std::shared_ptr<Device>> found;
|
||||
|
||||
for(auto& foundDev : PCAP::FindAll()) {
|
||||
auto fakedev = std::shared_ptr<RADPluto>(new RADPluto({}));
|
||||
for(auto& payload : foundDev.discoveryPackets)
|
||||
fakedev->com->packetizer->input(payload);
|
||||
for(auto& packet : fakedev->com->packetizer->output()) {
|
||||
std::shared_ptr<Message> msg;
|
||||
if(!fakedev->com->decoder->decode(msg, packet))
|
||||
continue; // We failed to decode this packet
|
||||
|
||||
if(!msg || msg->network.getNetID() != Network::NetID::Main51)
|
||||
continue; // Not a message we care about
|
||||
auto sn = std::dynamic_pointer_cast<SerialNumberMessage>(msg);
|
||||
if(!sn)
|
||||
continue; // Not a serial number message
|
||||
|
||||
if(sn->deviceSerial.length() < 2)
|
||||
continue;
|
||||
if(sn->deviceSerial.substr(0, 2) != SERIAL_START)
|
||||
continue; // Not a RADPluto
|
||||
|
||||
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
|
||||
found.emplace_back(new RADPluto(foundDev.device));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
static const std::vector<Network>& GetSupportedNetworks() {
|
||||
static std::vector<Network> supportedNetworks = {
|
||||
Network::NetID::HSCAN,
|
||||
Network::NetID::HSCAN2,
|
||||
|
||||
Network::NetID::LIN,
|
||||
|
||||
Network::NetID::Ethernet,
|
||||
|
||||
Network::NetID::OP_Ethernet1,
|
||||
Network::NetID::OP_Ethernet2,
|
||||
Network::NetID::OP_Ethernet3,
|
||||
Network::NetID::OP_Ethernet4
|
||||
};
|
||||
return supportedNetworks;
|
||||
}
|
||||
|
||||
RADPluto(neodevice_t neodevice) : Device(neodevice) {
|
||||
initialize<PCAP>();
|
||||
getWritableNeoDevice().type = DEVICE_TYPE;
|
||||
productId = PRODUCT_ID;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setupPacketizer(Packetizer& packetizer) override {
|
||||
Device::setupPacketizer(packetizer);
|
||||
packetizer.disableChecksum = true;
|
||||
packetizer.align16bit = false;
|
||||
}
|
||||
|
||||
virtual void setupEncoder(Encoder& encoder) override {
|
||||
Device::setupEncoder(encoder);
|
||||
encoder.supportCANFD = true;
|
||||
}
|
||||
|
||||
virtual void setupDecoder(Decoder& decoder) override {
|
||||
Device::setupDecoder(decoder);
|
||||
decoder.timestampMultiplier = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
||||
}
|
||||
|
||||
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||
for(auto& netid : GetSupportedNetworks())
|
||||
rxNetworks.emplace_back(netid);
|
||||
}
|
||||
|
||||
// The supported TX networks are the same as the supported RX networks for this device
|
||||
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#if defined _WIN32
|
||||
#include "icsneo/platform/windows/pcap.h"
|
||||
// #elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||
// #include "icsneo/platform/posix/ftdi.h"
|
||||
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||
#include "icsneo/platform/posix/pcap.h"
|
||||
#else
|
||||
#warning "This platform is not supported by the PCAP driver"
|
||||
#endif
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
#include "icsneo/device/neoobd2pro/neoobd2pro.h"
|
||||
#include "icsneo/device/neoobd2sim/neoobd2sim.h"
|
||||
#include "icsneo/device/neovifire/neovifire.h"
|
||||
//#include "icsneo/device/neovifire2/neovifire2eth.h" Ethernet not yet supported
|
||||
#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" Ethernet not yet supported
|
||||
//#include "icsneo/device/radstar2/radstar2eth.h" Ethernet not yet supported
|
||||
#include "icsneo/device/radgalaxy/radgalaxy.h"
|
||||
#include "icsneo/device/radpluto/radpluto.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"
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#ifndef __PCAP_POSIX_H_
|
||||
#define __PCAP_POSIX_H_
|
||||
|
||||
#include "icsneo/device/neodevice.h"
|
||||
#include "icsneo/communication/icommunication.h"
|
||||
#include "icsneo/api/errormanager.h"
|
||||
#include <string>
|
||||
#include <pcap.h>
|
||||
|
||||
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(device_errorhandler_t err, neodevice_t& forDevice);
|
||||
bool open();
|
||||
bool isOpen();
|
||||
bool close();
|
||||
private:
|
||||
device_errorhandler_t err;
|
||||
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 descriptionFromWinPCAP;
|
||||
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
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "icsneo/device/plasion/neoviion.h"
|
||||
#include "icsneo/device/plasion/neoviplasma.h"
|
||||
#include "icsneo/device/radgalaxy/radgalaxy.h"
|
||||
#include "icsneo/device/radgalaxy/radpluto.h"
|
||||
#include "icsneo/device/radstar2/radstar2eth.h"
|
||||
#include "icsneo/device/radstar2/radstar2usb.h"
|
||||
#include "icsneo/device/radsupermoon/radsupermoon.h"
|
||||
|
||||
Reference in New Issue
Block a user