mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-09-20 16:08:37 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a47b6f179 | ||
|
|
ff1a78c4eb | ||
|
|
6bae630463 | ||
|
|
4530bd14c0 | ||
|
|
8833617fe5 | ||
|
|
3621184696 | ||
|
|
d49fba7d81 | ||
|
|
ba7228d4ba | ||
|
|
9175a7bacf | ||
|
|
56d191b438 | ||
|
|
a465d5d6c6 | ||
|
|
e081724da6 | ||
|
|
0dae7d4354 | ||
|
|
288ff3565e | ||
|
|
f3cd9ac94b |
@@ -6,3 +6,4 @@ Thumbs.db
|
|||||||
third-party/concurrentqueue/benchmarks
|
third-party/concurrentqueue/benchmarks
|
||||||
third-party/concurrentqueue/tests
|
third-party/concurrentqueue/tests
|
||||||
*.bak
|
*.bak
|
||||||
|
.vs
|
||||||
+14
-2
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
project(libicsneo VERSION 0.1.0)
|
project(libicsneo VERSION 0.1.2)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
@@ -116,7 +116,19 @@ execute_process(
|
|||||||
ERROR_VARIABLE GIT_DESCRIBE
|
ERROR_VARIABLE GIT_DESCRIBE
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
)
|
)
|
||||||
|
if(${BUILD_METADATA})
|
||||||
|
set(BUILD_METADATA_PLUS +${BUILD_METADATA})
|
||||||
|
endif()
|
||||||
|
if(NOT ${GIT_BRANCH} STREQUAL "master")
|
||||||
|
set(BUILD_GIT_INFO "${GIT_BRANCH} @ ")
|
||||||
|
endif()
|
||||||
|
string(SUBSTRING GIT_DESCRIBE 0 1 GIT_DESCRIBE_FIRST)
|
||||||
|
if(NOT ${GIT_DESCRIBE_FIRST} STREQUAL "v")
|
||||||
|
string(APPEND BUILD_GIT_INFO "${GIT_DESCRIBE}")
|
||||||
|
endif()
|
||||||
|
|
||||||
configure_file(api/icsneocpp/buildinfo.h.template ${CMAKE_CURRENT_BINARY_DIR}/generated/buildinfo.h)
|
configure_file(api/icsneocpp/buildinfo.h.template ${CMAKE_CURRENT_BINARY_DIR}/generated/buildinfo.h)
|
||||||
|
configure_file(api/icsneoc/version.rc.template ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc/version.rc)
|
||||||
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
add_library(icsneocpp
|
add_library(icsneocpp
|
||||||
@@ -154,7 +166,7 @@ if(WIN32)
|
|||||||
add_definitions(-DWPCAP -DHAVE_REMOTE -DWIN32_LEAN_AND_MEAN)
|
add_definitions(-DWPCAP -DHAVE_REMOTE -DWIN32_LEAN_AND_MEAN)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
add_library(icsneoc SHARED api/icsneoc/icsneoc.cpp)
|
add_library(icsneoc SHARED api/icsneoc/icsneoc.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc/version.rc)
|
||||||
target_include_directories(icsneoc
|
target_include_directories(icsneoc
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@
|
||||||
|
#define VER_FILEVERSION_STR "v@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@@BUILD_METADATA_PLUS@ @BUILD_GIT_INFO@"
|
||||||
|
|
||||||
|
#define VER_PRODUCTVERSION VER_FILEVERSION
|
||||||
|
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
|
||||||
|
|
||||||
|
#ifndef DEBUG
|
||||||
|
#define VER_DEBUG 0
|
||||||
|
#else
|
||||||
|
#define VER_DEBUG VS_FF_DEBUG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
VS_VERSION_INFO VERSIONINFO
|
||||||
|
FILEVERSION VER_FILEVERSION
|
||||||
|
PRODUCTVERSION VER_PRODUCTVERSION
|
||||||
|
FILEFLAGSMASK (VS_FF_DEBUG)
|
||||||
|
FILEFLAGS (VER_DEBUG)
|
||||||
|
FILEOS VOS__WINDOWS32
|
||||||
|
FILETYPE VFT_DLL
|
||||||
|
FILESUBTYPE VFT2_UNKNOWN
|
||||||
|
BEGIN
|
||||||
|
BLOCK "StringFileInfo"
|
||||||
|
BEGIN
|
||||||
|
BLOCK "040904E4"
|
||||||
|
BEGIN
|
||||||
|
VALUE "CompanyName", "Intrepid Control Systems, Inc."
|
||||||
|
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
|
||||||
|
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||||
|
VALUE "InternalName", "icsneoc.dll"
|
||||||
|
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2019"
|
||||||
|
VALUE "OriginalFilename", "icsneoc.dll"
|
||||||
|
VALUE "ProductName", "libicsneo"
|
||||||
|
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||||
|
END
|
||||||
|
END
|
||||||
|
|
||||||
|
BLOCK "VarFileInfo"
|
||||||
|
BEGIN
|
||||||
|
/* The following line should only be modified for localized versions. */
|
||||||
|
/* It consists of any number of WORD,WORD pairs, with each pair */
|
||||||
|
/* describing a language,codepage combination supported by the file. */
|
||||||
|
/* */
|
||||||
|
/* For example, a file might have values "0x409,1252" indicating that it */
|
||||||
|
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
|
||||||
|
|
||||||
|
VALUE "Translation", 0x409, 1252
|
||||||
|
|
||||||
|
END
|
||||||
|
END
|
||||||
+9
-2
@@ -151,13 +151,15 @@ bool Device::open() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!serial) {
|
if(!serial) {
|
||||||
err(APIError::NoSerialNumber);
|
err(APIError::NoSerialNumber); // Communication could not be established with the device. Perhaps it is not powered with 12 volts?
|
||||||
|
com->close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string currentSerial = getNeoDevice().serial;
|
std::string currentSerial = getNeoDevice().serial;
|
||||||
if(currentSerial != serial->deviceSerial) {
|
if(currentSerial != serial->deviceSerial) {
|
||||||
err(APIError::IncorrectSerialNumber);
|
err(APIError::IncorrectSerialNumber);
|
||||||
|
com->close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,5 +267,10 @@ void Device::updateLEDState() {
|
|||||||
auto msg = std::make_shared<Message>();
|
auto msg = std::make_shared<Message>();
|
||||||
msg->network = Network::NetID::Device;
|
msg->network = Network::NetID::Device;
|
||||||
msg->data = {0x00, 0x06, uint8_t(ledState)};
|
msg->data = {0x00, 0x06, uint8_t(ledState)};
|
||||||
transmit(msg);
|
|
||||||
|
std::vector<uint8_t> packet;
|
||||||
|
if(!com->encoder->encode(packet, msg))
|
||||||
|
return;
|
||||||
|
|
||||||
|
com->sendPacket(packet);
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,10 @@ static std::vector<DeviceType> supportedDevices = {
|
|||||||
RADGalaxy::DEVICE_TYPE,
|
RADGalaxy::DEVICE_TYPE,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __RADPLUTOUSB_H_
|
||||||
|
RADPlutoUSB::DEVICE_TYPE,
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __RADSTAR2ETH_H_
|
#ifdef __RADSTAR2ETH_H_
|
||||||
RADStar2ETH::DEVICE_TYPE,
|
RADStar2ETH::DEVICE_TYPE,
|
||||||
#endif
|
#endif
|
||||||
@@ -112,6 +116,10 @@ std::vector<std::shared_ptr<Device>> DeviceFinder::FindAll() {
|
|||||||
findResults.push_back(RADGalaxy::Find());
|
findResults.push_back(RADGalaxy::Find());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __RADPLUTOUSB_H_
|
||||||
|
findResults.push_back(RADPlutoUSB::Find());
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __RADSTAR2ETH_H_
|
#ifdef __RADSTAR2ETH_H_
|
||||||
findResults.push_back(RADStar2ETH::Find());
|
findResults.push_back(RADStar2ETH::Find());
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ private:
|
|||||||
productId = PRODUCT_ID;
|
productId = PRODUCT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ private:
|
|||||||
productId = PRODUCT_ID;
|
productId = PRODUCT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,13 +77,13 @@ private:
|
|||||||
productId = PRODUCT_ID;
|
productId = PRODUCT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupSettings(IDeviceSettings& ssettings) override {
|
virtual void setupSettings(IDeviceSettings* ssettings) {
|
||||||
// TODO Check firmware version, old firmwares will reset Ethernet settings on settings send
|
// TODO Check firmware version, old firmwares will reset Ethernet settings on settings send
|
||||||
ssettings.readonly = true;
|
ssettings->readonly = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -102,13 +102,13 @@ protected:
|
|||||||
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,39 +13,8 @@ class RADPluto : public Device {
|
|||||||
public:
|
public:
|
||||||
// Serial numbers start with PL
|
// Serial numbers start with PL
|
||||||
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADPluto;
|
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADPluto;
|
||||||
static constexpr const uint16_t PRODUCT_ID = 0xffff; // Not yet set
|
static constexpr const uint16_t PRODUCT_ID = 0x1104;
|
||||||
static constexpr const char* SERIAL_START = "PL";
|
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 const std::vector<Network>& GetSupportedNetworks() {
|
||||||
static std::vector<Network> supportedNetworks = {
|
static std::vector<Network> supportedNetworks = {
|
||||||
@@ -65,18 +34,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
RADPluto(neodevice_t neodevice) : Device(neodevice) {
|
RADPluto(neodevice_t neodevice) : Device(neodevice) {
|
||||||
initialize<PCAP>();
|
|
||||||
getWritableNeoDevice().type = DEVICE_TYPE;
|
getWritableNeoDevice().type = DEVICE_TYPE;
|
||||||
productId = PRODUCT_ID;
|
productId = PRODUCT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupPacketizer(Packetizer& packetizer) override {
|
|
||||||
Device::setupPacketizer(packetizer);
|
|
||||||
packetizer.disableChecksum = true;
|
|
||||||
packetizer.align16bit = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setupEncoder(Encoder& encoder) override {
|
virtual void setupEncoder(Encoder& encoder) override {
|
||||||
Device::setupEncoder(encoder);
|
Device::setupEncoder(encoder);
|
||||||
encoder.supportCANFD = true;
|
encoder.supportCANFD = true;
|
||||||
@@ -87,13 +49,13 @@ protected:
|
|||||||
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef __RADPLUTOUSB_H_
|
||||||
|
#define __RADPLUTOUSB_H_
|
||||||
|
|
||||||
|
#include "icsneo/device/radpluto/radpluto.h"
|
||||||
|
#include "icsneo/platform/stm32.h"
|
||||||
|
|
||||||
|
namespace icsneo {
|
||||||
|
|
||||||
|
class RADPlutoUSB : public RADPluto {
|
||||||
|
public:
|
||||||
|
// Serial numbers start with RP
|
||||||
|
static std::vector<std::shared_ptr<Device>> Find() {
|
||||||
|
std::vector<std::shared_ptr<Device>> found;
|
||||||
|
|
||||||
|
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID))
|
||||||
|
found.emplace_back(new RADPlutoUSB(neodevice));
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
RADPlutoUSB(neodevice_t neodevice) : RADPluto(neodevice) {
|
||||||
|
initialize<STM32>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -44,13 +44,13 @@ protected:
|
|||||||
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
|
|
||||||
RADStar2(neodevice_t neodevice) : Device(neodevice) {
|
RADStar2(neodevice_t neodevice) : Device(neodevice) {
|
||||||
getWritableNeoDevice().type = DEVICE_TYPE;
|
getWritableNeoDevice().type = DEVICE_TYPE;
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ private:
|
|||||||
productId = PRODUCT_ID;
|
productId = PRODUCT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ protected:
|
|||||||
encoder.supportCANFD = false; // VCAN 4-1 does not support CAN FD
|
encoder.supportCANFD = false; // VCAN 4-1 does not support CAN FD
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueCAN4_1(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
ValueCAN4_1(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueCAN4_2(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
ValueCAN4_2(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueCAN4_2EL(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
ValueCAN4_2EL(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
for(auto& netid : GetSupportedNetworks())
|
for(auto& netid : GetSupportedNetworks())
|
||||||
rxNetworks.emplace_back(netid);
|
rxNetworks.emplace_back(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The supported TX networks are the same as the supported RX networks for this device
|
// The supported TX networks are the same as the supported RX networks for this device
|
||||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueCAN4_4(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
ValueCAN4_4(neodevice_t neodevice) : ValueCAN4(neodevice) {
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#ifndef __MACADDR_DARWIN_H_
|
|
||||||
#define __MACADDR_DARWIN_H_
|
|
||||||
|
|
||||||
#include <net/if_dl.h>
|
|
||||||
|
|
||||||
#define ICSNEO_AF_MACADDR (AF_LINK)
|
|
||||||
|
|
||||||
// Points towards the first byte of the MAC address, given a sockaddr*
|
|
||||||
#define PLATFORM_MAC_FROM_SOCKADDR(SADDR) (((struct sockaddr_dl*)SADDR)->sdl_data + ((struct sockaddr_dl*)SADDR)->sdl_nlen)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -4,13 +4,13 @@
|
|||||||
#include "icsneo/device/neoobd2pro/neoobd2pro.h"
|
#include "icsneo/device/neoobd2pro/neoobd2pro.h"
|
||||||
#include "icsneo/device/neoobd2sim/neoobd2sim.h"
|
#include "icsneo/device/neoobd2sim/neoobd2sim.h"
|
||||||
#include "icsneo/device/neovifire/neovifire.h"
|
#include "icsneo/device/neovifire/neovifire.h"
|
||||||
#include "icsneo/device/neovifire2/neovifire2eth.h"
|
//#include "icsneo/device/neovifire2/neovifire2eth.h"
|
||||||
#include "icsneo/device/neovifire2/neovifire2usb.h"
|
#include "icsneo/device/neovifire2/neovifire2usb.h"
|
||||||
#include "icsneo/device/plasion/neoviion.h"
|
#include "icsneo/device/plasion/neoviion.h"
|
||||||
#include "icsneo/device/plasion/neoviplasma.h"
|
#include "icsneo/device/plasion/neoviplasma.h"
|
||||||
#include "icsneo/device/radgalaxy/radgalaxy.h"
|
//#include "icsneo/device/radgalaxy/radgalaxy.h"
|
||||||
#include "icsneo/device/radpluto/radpluto.h"
|
#include "icsneo/device/radpluto/radplutousb.h"
|
||||||
#include "icsneo/device/radstar2/radstar2eth.h"
|
//#include "icsneo/device/radstar2/radstar2eth.h"
|
||||||
#include "icsneo/device/radstar2/radstar2usb.h"
|
#include "icsneo/device/radstar2/radstar2usb.h"
|
||||||
#include "icsneo/device/radsupermoon/radsupermoon.h"
|
#include "icsneo/device/radsupermoon/radsupermoon.h"
|
||||||
#include "icsneo/device/valuecan3/valuecan3.h"
|
#include "icsneo/device/valuecan3/valuecan3.h"
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#ifndef __MACADDR_LINUX_H_
|
|
||||||
#define __MACADDR_LINUX_H_
|
|
||||||
|
|
||||||
#include <netpacket/packet.h>
|
|
||||||
|
|
||||||
#define ICSNEO_AF_MACADDR (AF_PACKET)
|
|
||||||
|
|
||||||
// Points towards the first byte of the MAC address, given a sockaddr*
|
|
||||||
#define PLATFORM_MAC_FROM_SOCKADDR(SADDR) (((struct sockaddr_ll*)SADDR)->sll_addr)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef __MACADDR_POSIX_H_
|
|
||||||
#define __MACADDR_POSIX_H_
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include "icsneo/platform/posix/darwin/macaddr.h"
|
|
||||||
#else
|
|
||||||
#include "icsneo/platform/posix/linux/macaddr.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -37,8 +37,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
uint8_t uuid;
|
uint8_t uuid;
|
||||||
uint8_t macAddress[8];
|
uint8_t macAddress[8];
|
||||||
std::string nameFromPCAP;
|
std::string nameFromWinPCAP;
|
||||||
std::string descriptionFromPCAP;
|
std::string descriptionFromWinPCAP;
|
||||||
std::string fullName;
|
std::string fullName;
|
||||||
pcap_t* fp = nullptr;
|
pcap_t* fp = nullptr;
|
||||||
pcap_stat stats;
|
pcap_stat stats;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "icsneo/device/plasion/neoviion.h"
|
#include "icsneo/device/plasion/neoviion.h"
|
||||||
#include "icsneo/device/plasion/neoviplasma.h"
|
#include "icsneo/device/plasion/neoviplasma.h"
|
||||||
#include "icsneo/device/radgalaxy/radgalaxy.h"
|
#include "icsneo/device/radgalaxy/radgalaxy.h"
|
||||||
#include "icsneo/device/radgalaxy/radpluto.h"
|
#include "icsneo/device/radpluto/radplutousb.h"
|
||||||
#include "icsneo/device/radstar2/radstar2eth.h"
|
#include "icsneo/device/radstar2/radstar2eth.h"
|
||||||
#include "icsneo/device/radstar2/radstar2usb.h"
|
#include "icsneo/device/radstar2/radstar2usb.h"
|
||||||
#include "icsneo/device/radsupermoon/radsupermoon.h"
|
#include "icsneo/device/radsupermoon/radsupermoon.h"
|
||||||
|
|||||||
@@ -30,9 +30,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4127) // ICS: Warnings generated by this file
|
#pragma warning(disable:4127) // ICS: Warnings generated by this file
|
||||||
#pragma warning(disable:4706)
|
#pragma warning(disable:4706)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
// Disable -Wconversion warnings (spuriously triggered when Traits::size_t and
|
// Disable -Wconversion warnings (spuriously triggered when Traits::size_t and
|
||||||
@@ -3638,4 +3640,6 @@ inline void swap(typename ConcurrentQueue<T, Traits>::ImplicitProducerKVP& a, ty
|
|||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma warning(pop)
|
#if defined(_MSC_VAR)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
+22
-28
@@ -2,13 +2,13 @@
|
|||||||
#include "icsneo/communication/network.h"
|
#include "icsneo/communication/network.h"
|
||||||
#include "icsneo/communication/communication.h"
|
#include "icsneo/communication/communication.h"
|
||||||
#include "icsneo/communication/packetizer.h"
|
#include "icsneo/communication/packetizer.h"
|
||||||
#include "icsneo/platform/posix/macaddr.h"
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <netpacket/packet.h>
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
||||||
@@ -19,12 +19,12 @@ std::vector<PCAP::NetworkInterface> PCAP::knownInterfaces;
|
|||||||
std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
||||||
std::vector<PCAPFoundDevice> foundDevices;
|
std::vector<PCAPFoundDevice> foundDevices;
|
||||||
|
|
||||||
// First we ask libpcap to give us all of the devices
|
// First we ask WinPCAP to give us all of the devices
|
||||||
pcap_if_t* alldevs;
|
pcap_if_t* alldevs;
|
||||||
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
|
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
|
||||||
bool success = false;
|
bool success = false;
|
||||||
// Calling pcap_findalldevs too quickly can cause various errors. Retry a few times in this case.
|
// Calling pcap_findalldevs too quickly can cause various errors. Retry a few times in this case.
|
||||||
for(auto retry = 0; retry < 3; retry++) {
|
for(auto retry = 0; retry < 10; retry++) {
|
||||||
auto ret = pcap_findalldevs(&alldevs, errbuf);
|
auto ret = pcap_findalldevs(&alldevs, errbuf);
|
||||||
if(ret == 0) {
|
if(ret == 0) {
|
||||||
success = true;
|
success = true;
|
||||||
@@ -46,14 +46,15 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
NetworkInterface netif;
|
NetworkInterface netif;
|
||||||
netif.nameFromPCAP = dev->name;
|
netif.nameFromWinPCAP = dev->name;
|
||||||
if(dev->description)
|
if(dev->description)
|
||||||
netif.descriptionFromPCAP = dev->description;
|
netif.descriptionFromWinPCAP = dev->description;
|
||||||
pcap_addr* currentAddress = dev->addresses;
|
pcap_addr* currentAddress = dev->addresses;
|
||||||
bool hasAddress = false;
|
bool hasAddress = false;
|
||||||
while(!hasAddress && currentAddress != nullptr) {
|
while(!hasAddress && currentAddress != nullptr) {
|
||||||
if(currentAddress->addr && currentAddress->addr->sa_family == ICSNEO_AF_MACADDR) {
|
if(currentAddress->addr && currentAddress->addr->sa_family == AF_PACKET) {
|
||||||
memcpy(netif.macAddress, PLATFORM_MAC_FROM_SOCKADDR(currentAddress->addr), sizeof(netif.macAddress));
|
struct sockaddr_ll* s = (struct sockaddr_ll*)currentAddress->addr;
|
||||||
|
memcpy(netif.macAddress, s->sll_addr, sizeof(netif.macAddress));
|
||||||
hasAddress = true;
|
hasAddress = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -79,28 +80,21 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
|||||||
|
|
||||||
for(size_t i = 0; i < knownInterfaces.size(); i++) {
|
for(size_t i = 0; i < knownInterfaces.size(); i++) {
|
||||||
auto& interface = knownInterfaces[i];
|
auto& interface = knownInterfaces[i];
|
||||||
|
// if(interface.fullName.length() == 0)
|
||||||
|
// continue; // Win32 did not find this interface in the previous step
|
||||||
|
|
||||||
errbuf[0] = '\0';
|
errbuf[0] = '\0';
|
||||||
interface.fp = pcap_create(interface.nameFromPCAP.c_str(), errbuf);
|
interface.fp = pcap_open_live(interface.nameFromWinPCAP.c_str(), UINT16_MAX, 1, 0, errbuf);
|
||||||
if(interface.fp == nullptr) {
|
if(strlen(errbuf) != 0) { // This means a warning
|
||||||
// TODO Flag error that interface could not be opened?
|
std::cout << "Warning for " << interface.nameFromWinPCAP << " " << errbuf << std::endl;
|
||||||
// This can happen if, on Linux, you are not running as root
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
pcap_set_snaplen(interface.fp, UINT16_MAX);
|
|
||||||
pcap_set_timeout(interface.fp, 1);
|
|
||||||
pcap_set_immediate_mode(interface.fp, 1);
|
|
||||||
pcap_setnonblock(interface.fp, 1, errbuf);
|
|
||||||
if(pcap_activate(interface.fp)) {
|
|
||||||
// TODO Flag error that interface could not be opened?
|
|
||||||
// This can happen if, on Linux, you are not running as root
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Propagate this up
|
if(interface.fp == nullptr) {
|
||||||
// if(strlen(errbuf) != 0) { // The open succeeded but we got a warning
|
std::cout << "pcap_open_live failed for " << interface.nameFromWinPCAP << " with " << errbuf << std::endl;
|
||||||
// std::cout << "Warning for " << interface.nameFromPCAP << " " << errbuf << std::endl;
|
continue; // Could not open the interface
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
pcap_setnonblock(interface.fp, 1, errbuf);
|
||||||
|
|
||||||
EthernetPacket requestPacket;
|
EthernetPacket requestPacket;
|
||||||
requestPacket.payload.reserve(4);
|
requestPacket.payload.reserve(4);
|
||||||
@@ -114,7 +108,7 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
|||||||
auto bs = requestPacket.getBytestream();
|
auto bs = requestPacket.getBytestream();
|
||||||
pcap_sendpacket(interface.fp, bs.data(), (int)bs.size());
|
pcap_sendpacket(interface.fp, bs.data(), (int)bs.size());
|
||||||
|
|
||||||
auto timeout = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(5);
|
auto timeout = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(50);
|
||||||
while(std::chrono::high_resolution_clock::now() <= timeout) { // Wait up to 5ms for the response
|
while(std::chrono::high_resolution_clock::now() <= timeout) { // Wait up to 5ms for the response
|
||||||
struct pcap_pkthdr* header;
|
struct pcap_pkthdr* header;
|
||||||
const uint8_t* data;
|
const uint8_t* data;
|
||||||
@@ -164,6 +158,7 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
|||||||
pcap_close(interface.fp);
|
pcap_close(interface.fp);
|
||||||
interface.fp = nullptr;
|
interface.fp = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundDevices;
|
return foundDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +191,7 @@ bool PCAP::open() {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Open the interface
|
// Open the interface
|
||||||
interface.fp = pcap_open_live(interface.nameFromPCAP.c_str(), INT16_MAX, 1, 0, errbuf);
|
interface.fp = pcap_open_live(interface.nameFromWinPCAP.c_str(), INT16_MAX, 1, 0, errbuf);
|
||||||
if(interface.fp == nullptr) {
|
if(interface.fp == nullptr) {
|
||||||
err(APIError::DriverFailedToOpen);
|
err(APIError::DriverFailedToOpen);
|
||||||
return false;
|
return false;
|
||||||
@@ -282,7 +277,6 @@ void PCAP::writeTask() {
|
|||||||
if(!closing)
|
if(!closing)
|
||||||
pcap_sendpacket(interface.fp, bs.data(), (int)bs.size());
|
pcap_sendpacket(interface.fp, bs.data(), (int)bs.size());
|
||||||
// TODO Handle packet send errors
|
// TODO Handle packet send errors
|
||||||
onWrite();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,9 +200,10 @@ bool STM32::open() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct termios tty;
|
struct termios tty = {};
|
||||||
|
struct termios compare = {};
|
||||||
|
|
||||||
if(tcgetattr(fd, &tty) < 0) {
|
if(tcgetattr(fd, &tty) != 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -229,6 +230,11 @@ bool STM32::open() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(tcgetattr(fd, &compare) != 0 || memcmp(&tty, &compare, sizeof(struct termios)) != 0) {
|
||||||
|
close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Create threads
|
// Create threads
|
||||||
readThread = std::thread(&STM32::readTask, this);
|
readThread = std::thread(&STM32::readTask, this);
|
||||||
writeThread = std::thread(&STM32::writeTask, this);
|
writeThread = std::thread(&STM32::writeTask, this);
|
||||||
|
|||||||
Reference in New Issue
Block a user