Ethernet (DoIP) Activation Line support

This commit is contained in:
Paul Hollinsky
2021-04-06 22:50:25 -04:00
parent 4e245db94e
commit a6c8acd8e9
28 changed files with 613 additions and 15 deletions
+1
View File
@@ -46,6 +46,7 @@ public:
DeviceNotCurrentlyPolling = 0x1010,
UnsupportedTXNetwork = 0x1011,
MessageMaxLengthExceeded = 0x1012,
ValueNotYetPresent = 0x1013,
// Device Events
PollingMessageOverflow = 0x2000,
+2 -1
View File
@@ -12,10 +12,11 @@ enum class Command : uint8_t {
SetSettings = 0xA4, // Previously known as RED_CMD_SET_BAUD_REQ, follow up with SaveSettings to write to EEPROM
//GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ, now unused
SaveSettings = 0xA6,
UpdateLEDState = 0xA7,
SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM
RequestStatusUpdate = 0xBC,
ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX
UpdateLEDState = 0xA7,
MiscControl = 0xE7,
FlexRayControl = 0xF3
};
+30
View File
@@ -0,0 +1,30 @@
#ifndef __ICSNEO_IO_H_
#define __ICSNEO_IO_H_
#ifdef __cplusplus
namespace icsneo {
enum class IO {
EthernetActivation = 0, // The DoIP activation line, 0 is HiZ and 1 is pulled up to VBAT
USBHostPower = 1,
BackupPowerEnabled = 2, // The FIRE 2's backup super capacitor
BackupPowerGood = 3, // Whether or not the FIRE 2's backup super capacitor is charged (read only)
};
// Note that the C API does a static cast between this and neoio_t so keep them in sync!
}
#endif // __cplusplus
#ifdef __ICSNEOC_H_
typedef enum _neoio_t {
ICSNEO_IO_ETH_ACTIVATION = (0),
ICSNEO_IO_USB_HOST_POWER = (1),
ICSNEO_IO_BACKUP_POWER_EN = (2),
ICSNEO_IO_BACKUP_POWER_GOOD = (3),
} neoio_t;
#endif
#endif
+50
View File
@@ -18,10 +18,12 @@
#include "icsneo/communication/packetizer.h"
#include "icsneo/communication/encoder.h"
#include "icsneo/communication/decoder.h"
#include "icsneo/communication/io.h"
#include "icsneo/communication/message/resetstatusmessage.h"
#include "icsneo/device/extensions/flexray/controller.h"
#include "icsneo/communication/message/flexray/control/flexraycontrolmessage.h"
#include "icsneo/third-party/concurrentqueue/concurrentqueue.h"
#include "icsneo/platform/optional.h"
namespace icsneo {
@@ -86,6 +88,48 @@ public:
virtual size_t getNetworkCountByType(Network::Type) const;
virtual Network getNetworkByNumber(Network::Type, size_t) const;
/**
* Retrieve the number of Ethernet (DoIP) Activation lines present
* on this device.
*/
virtual size_t getEthernetActivationLineCount() const { return 0; }
/**
* Retrieve the number of power-controlled USB Host ports present
* on this device.
*/
virtual size_t getUSBHostPowerCount() const { return 0; }
/**
* Tell whether the current device supports controlling a backup
* power source through the API.
*/
virtual bool getBackupPowerSupported() const { return false; }
/**
* Get the value of a digital IO, returning an empty optional if the
* value is not present, the specified IO is not valid for this device,
* or if an error occurs.
*
* The index number starts counting at 1 to keep the numbers in sync
* with the numbering on the device, and is set to 1 by default.
*/
optional<bool> getDigitalIO(IO type, size_t number = 1);
/**
* Set a digital IO to either a 1, if value is true, or 0 otherwise.
*
* The index number starts counting at 1 to keep the numbers in sync
* with the numbering on the device.
*/
bool setDigitalIO(IO type, size_t number, bool value);
/**
* Set the first digital IO of a given type to either a 1, if value
* is true, or 0 otherwise.
*/
bool setDigitalIO(IO type, bool value) { return setDigitalIO(type, 1, value); }
virtual std::vector<std::shared_ptr<FlexRay::Controller>> getFlexRayControllers() const { return {}; }
const device_eventhandler_t& getEventHandler() const { return report; }
@@ -99,6 +143,10 @@ protected:
int messagePollingCallbackID = 0;
int internalHandlerCallbackID = 0;
device_eventhandler_t report;
optional<bool> ethActivationStatus;
optional<bool> usbHostPowerStatus;
optional<bool> backupPowerEnabled;
optional<bool> backupPowerGood;
// START Initialization Functions
Device(neodevice_t neodevice = { 0 }) {
@@ -185,6 +233,8 @@ protected:
void handleInternalMessage(std::shared_ptr<Message> message);
virtual void handleDeviceStatus(const std::shared_ptr<Message>& message) {}
neodevice_t& getWritableNeoDevice() { return data; }
private:
+29 -6
View File
@@ -47,11 +47,28 @@ enum
enum OPEthLinkMode
{
OPETH_LINK_INVALID = -1,
OPETH_LINK_AUTO = 0,
OPETH_LINK_MASTER,
OPETH_LINK_SLAVE
};
enum EthLinkSpeed
{
ETH_SPEED_10 = 0,
ETH_SPEED_100,
ETH_SPEED_1000,
};
typedef struct
{
uint16_t networkId;
uint8_t linkStatus;
uint8_t linkFullDuplex;
uint8_t linkSpeed; // see EthLinkSpeed
int8_t linkMode; // for automotive networks - see OPEthLinkMode
} EthernetNetworkStatus;
typedef struct
{
uint8_t Mode;
@@ -553,6 +570,12 @@ typedef struct _UART_SETTINGS
#define UART_SETTINGS_SIZE 16
static_assert(sizeof(UART_SETTINGS) == UART_SETTINGS_SIZE, "UART_SETTINGS is the wrong size!");
typedef struct {
uint8_t ethernetActivationLineEnabled;
EthernetNetworkStatus ethernetStatus;
uint8_t unused;
} fire2vnet_status_t, flexray_vnetz_status_t;
#pragma pack(pop)
#ifdef __cplusplus
@@ -592,7 +615,7 @@ public:
const uint8_t* offset = (const uint8_t*)getCANSettingsFor(net);
if(offset == nullptr)
return nullptr;
return static_cast<CAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
return reinterpret_cast<CAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
}
virtual const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const { (void)net; return nullptr; }
@@ -602,7 +625,7 @@ public:
const uint8_t* offset = (const uint8_t*)getCANFDSettingsFor(net);
if(offset == nullptr)
return nullptr;
return static_cast<CANFD_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
return reinterpret_cast<CANFD_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
}
virtual const CAN_SETTINGS* getLSFTCANSettingsFor(Network net) const { (void)net; return nullptr; }
@@ -612,7 +635,7 @@ public:
const uint8_t* offset = (const uint8_t*)getLSFTCANSettingsFor(net);
if(offset == nullptr)
return nullptr;
return static_cast<CAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
return reinterpret_cast<CAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
}
virtual const SWCAN_SETTINGS* getSWCANSettingsFor(Network net) const { (void)net; return nullptr; }
@@ -622,13 +645,13 @@ public:
const uint8_t* offset = (const uint8_t*)getSWCANSettingsFor(net);
if(offset == nullptr)
return nullptr;
return static_cast<SWCAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
return reinterpret_cast<SWCAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
}
const void* getRawStructurePointer() const { return settingsInDeviceRAM.data(); }
void* getMutableRawStructurePointer() { return settings.data(); }
template<typename T> const T* getStructurePointer() const { return static_cast<const T*>(getRawStructurePointer()); }
template<typename T> T* getMutableStructurePointer() { return static_cast<T*>(getMutableRawStructurePointer()); }
template<typename T> const T* getStructurePointer() const { return reinterpret_cast<const T*>(getRawStructurePointer()); }
template<typename T> T* getMutableStructurePointer() { return reinterpret_cast<T*>(getMutableRawStructurePointer()); }
template<typename T> T getStructure() const { return *getStructurePointer<T>(); }
template<typename T> bool applyStructure(const T& newStructure);
@@ -6,6 +6,7 @@
#include "icsneo/device/device.h"
#include "icsneo/device/devicetype.h"
#include "icsneo/platform/ftdi.h"
#include "icsneo/device/tree/neovifire2/neovifire2settings.h"
namespace icsneo {
@@ -46,6 +47,10 @@ public:
return supportedNetworks;
}
size_t getEthernetActivationLineCount() const override { return 1; }
size_t getUSBHostPowerCount() const override { return 1; }
bool getBackupPowerSupported() const override { return true; }
protected:
NeoVIFIRE2(neodevice_t neodevice) : Device(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
@@ -63,6 +68,16 @@ protected:
// 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); }
void handleDeviceStatus(const std::shared_ptr<Message>& message) override {
if(!message || message->data.size() < sizeof(neovifire2_status_t))
return;
const neovifire2_status_t* status = reinterpret_cast<const neovifire2_status_t*>(message->data.data());
backupPowerEnabled = status->backupPowerEnabled;
backupPowerGood = status->backupPowerGood;
ethActivationStatus = status->ethernetActivationLineEnabled;
usbHostPowerStatus = status->usbHostPowerEnabled;
}
};
}
@@ -5,7 +5,6 @@
#include "icsneo/device/tree/neovifire2/neovifire2.h"
#include "icsneo/platform/pcap.h"
#include "icsneo/device/tree/neovifire2/neovifire2settings.h"
#include <memory>
namespace icsneo {
@@ -106,6 +106,14 @@ typedef struct {
TIMESYNC_ICSHARDWARE_SETTINGS timeSync;
DISK_SETTINGS disk;
} neovifire2_settings_t;
typedef struct {
uint8_t backupPowerGood;
uint8_t backupPowerEnabled;
uint8_t usbHostPowerEnabled;
uint8_t ethernetActivationLineEnabled;
EthernetNetworkStatus ethernetStatus;
} neovifire2_status_t;
#pragma pack(pop)
#ifdef __cplusplus
@@ -5,7 +5,6 @@
#include "icsneo/device/tree/neovifire2/neovifire2.h"
#include "icsneo/platform/ftdi.h"
#include "icsneo/device/tree/neovifire2/neovifire2settings.h"
namespace icsneo {
@@ -41,6 +41,9 @@ public:
return supportedNetworks;
}
// Until VNET support is added, assume we have one FIRE 2 VNET or FlexRay VNETZ as the main
size_t getEthernetActivationLineCount() const override { return 1; }
protected:
virtual std::shared_ptr<Communication> makeCommunication(
std::unique_ptr<Driver> transport,
@@ -92,6 +95,13 @@ protected:
return ret;
}
void handleDeviceStatus(const std::shared_ptr<Message>& message) override {
if(!message || message->data.size() < sizeof(fire2vnet_status_t))
return;
const fire2vnet_status_t* status = reinterpret_cast<const fire2vnet_status_t*>(message->data.data());
ethActivationStatus = status->ethernetActivationLineEnabled;
}
public:
Plasion(neodevice_t neodevice) : Device(neodevice) {}
};
@@ -91,6 +91,8 @@ public:
productId = PRODUCT_ID;
}
size_t getEthernetActivationLineCount() const override { return 1; }
protected:
void setupPacketizer(Packetizer& packetizer) override {
Device::setupPacketizer(packetizer);
@@ -115,6 +117,13 @@ protected:
// The supported TX networks are the same as the supported RX networks for this device
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
void handleDeviceStatus(const std::shared_ptr<Message>& message) override {
if(!message || message->data.size() < sizeof(radgalaxy_status_t))
return;
const radgalaxy_status_t* status = reinterpret_cast<const radgalaxy_status_t*>(message->data.data());
ethActivationStatus = status->ethernetActivationLineEnabled;
}
};
}
@@ -87,6 +87,11 @@ typedef struct {
DISK_SETTINGS disk;
LOGGER_SETTINGS logger;
} radgalaxy_settings_t;
typedef struct {
uint8_t unused[3];
uint8_t ethernetActivationLineEnabled;
} radgalaxy_status_t;
#pragma pack(pop)
#ifdef __cplusplus
@@ -14,6 +14,8 @@ public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADGigalog;
static constexpr const char* SERIAL_START = "GL";
size_t getEthernetActivationLineCount() const override { return 1; }
protected:
RADGigalog(neodevice_t neodevice) : Device(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
@@ -74,6 +76,13 @@ protected:
};
txNetworks.insert(txNetworks.end(), supportedTxNetworks.begin(), supportedTxNetworks.end());
}
void handleDeviceStatus(const std::shared_ptr<Message>& message) override {
if(!message || message->data.size() < sizeof(radgigalog_status_t))
return;
const radgigalog_status_t* status = reinterpret_cast<const radgigalog_status_t*>(message->data.data());
ethActivationStatus = status->ethernetActivationLineEnabled;
}
};
}
@@ -86,6 +86,11 @@ typedef struct {
uint16_t network_enables_4;
RAD_REPORTING_SETTINGS reporting;
} radgigalog_settings_t;
typedef struct {
uint8_t unused[3];
uint8_t ethernetActivationLineEnabled;
} radgigalog_status_t;
#pragma pack(pop)
#ifdef __cplusplus
@@ -14,6 +14,8 @@ public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADGigastar;
static constexpr const char* SERIAL_START = "GS";
size_t getEthernetActivationLineCount() const override { return 1; }
protected:
RADGigastar(neodevice_t neodevice) : Device(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
@@ -78,6 +80,13 @@ protected:
};
txNetworks.insert(txNetworks.end(), supportedTxNetworks.begin(), supportedTxNetworks.end());
}
void handleDeviceStatus(const std::shared_ptr<Message>& message) override {
if(!message || message->data.size() < sizeof(radgigastar_status_t))
return;
const radgigastar_status_t* status = reinterpret_cast<const radgigastar_status_t*>(message->data.data());
ethActivationStatus = status->ethernetActivationLineEnabled;
}
};
}
@@ -135,6 +135,11 @@ public:
}
};
typedef struct {
uint8_t unused[3];
uint8_t ethernetActivationLineEnabled;
} radgigastar_status_t;
}
#endif // __cplusplus
@@ -76,6 +76,12 @@ typedef struct {
uint16_t pwr_man_timeout;
} valuecan4_4_2el_settings_t, valuecan4_4_settings_t, valuecan4_2el_settings_t;
typedef struct
{
uint8_t ethernetActivationLineEnabled;
uint8_t unused;
} valuecan4_4_2el_status_t, valuecan4_4_status_t, valuecan4_2el_status_t;
typedef struct {
CAN_SETTINGS can1;
CANFD_SETTINGS canfd1;
@@ -19,6 +19,15 @@ protected:
ValueCAN4_2EL(neodevice_t neodevice) : ValueCAN4(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
}
size_t getEthernetActivationLineCount() const override { return 1; }
void handleDeviceStatus(const std::shared_ptr<Message>& message) override {
if(!message || message->data.size() < sizeof(valuecan4_2el_status_t))
return;
const valuecan4_2el_status_t* status = reinterpret_cast<const valuecan4_2el_status_t*>(message->data.data());
ethActivationStatus = status->ethernetActivationLineEnabled;
}
};
}
+39 -1
View File
@@ -8,6 +8,7 @@
#include "icsneo/communication/message/neomessage.h" // For neomessage_t and friends
#include "icsneo/platform/dynamiclib.h" // Dynamic library loading and exporting
#include "icsneo/communication/network.h" // Network type and netID defines
#include "icsneo/communication/io.h" // IO enum defines
#include "icsneo/api/version.h" // For version info
#include "icsneo/api/event.h" // For event and error info
@@ -713,8 +714,29 @@ extern bool DLLExport icsneo_getSupportedDevices(devicetype_t* devices, size_t*
*/
extern bool DLLExport icsneo_getTimestampResolution(const neodevice_t* device, uint16_t* resolution);
/**
* \brief Get the value of a digital IO for the given device
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
* \param[in] type The IO type
* \param[in] number The index within the IO type, starting from 1
* \param[out] value A pointer to the uint8_t which will store the value of the IO port, if successful
* \returns True if the value is read successfully
*
* These values are often not populated if the device is not "online".
*/
extern bool DLLExport icsneo_getDigitalIO(const neodevice_t* device, neoio_t type, uint32_t number, uint8_t* value);
/**
* \brief Get the value of a digital IO for the given device
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
* \param[in] type The IO type
* \param[in] number The index within the IO type, starting from 1
* \param[in] value The value which will be written to the IO
* \returns True if the parameters and connection state are correct to submit the request to the device
*
* Note that this function is not synchronous with the device confirming the change.
*/
extern bool DLLExport icsneo_setDigitalIO(const neodevice_t* device, neoio_t type, uint32_t number, uint8_t value);
#ifdef __cplusplus
} // extern "C"
@@ -860,6 +882,18 @@ fn_icsneo_setEventLimit icsneo_setEventLimit;
typedef size_t(*fn_icsneo_getEventLimit)(void);
fn_icsneo_getEventLimit icsneo_getEventLimit;
typedef bool(*fn_icsneo_getSupportedDevices)(devicetype_t* devices, size_t* count);
fn_icsneo_getSupportedDevices icsneo_getSupportedDevices;
typedef bool(*fn_icsneo_getTimestampResolution)(const neodevice_t* device, uint16_t* resolution);
fn_icsneo_getTimestampResolution icsneo_getTimestampResolution;
typedef bool(*fn_icsneo_getDigitalIO)(const neodevice_t* device, neoio_t type, uint32_t number, uint8_t* value);
fn_icsneo_getDigitalIO icsneo_getDigitalIO;
typedef bool(*fn_icsneo_setDigitalIO)(const neodevice_t* device, neoio_t type, uint32_t number, uint8_t value);
fn_icsneo_setDigitalIO icsneo_setDigitalIO;
#define ICSNEO_IMPORT(func) func = (fn_##func)icsneo_dynamicLibraryGetFunction(icsneo_libraryHandle, #func)
#define ICSNEO_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3
void* icsneo_libraryHandle = NULL;
@@ -920,6 +954,10 @@ int icsneo_init() {
ICSNEO_IMPORTASSERT(icsneo_discardDeviceEvents);
ICSNEO_IMPORTASSERT(icsneo_setEventLimit);
ICSNEO_IMPORTASSERT(icsneo_getEventLimit);
ICSNEO_IMPORTASSERT(icsneo_getSupportedDevices);
ICSNEO_IMPORTASSERT(icsneo_getTimestampResolution);
ICSNEO_IMPORTASSERT(icsneo_getDigitalIO);
ICSNEO_IMPORTASSERT(icsneo_setDigitalIO);
icsneo_initialized = true;
return 0;