Issue #117
parent
237bed1b72
commit
41d6927496
|
|
@ -2,6 +2,7 @@
|
||||||
#define __NETWORKID_H_
|
#define __NETWORKID_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef uint16_t neonetid_t;
|
typedef uint16_t neonetid_t;
|
||||||
typedef uint8_t neonettype_t;
|
typedef uint8_t neonettype_t;
|
||||||
|
|
||||||
|
|
@ -12,8 +13,15 @@ typedef uint8_t neonettype_t;
|
||||||
|
|
||||||
namespace icsneo {
|
namespace icsneo {
|
||||||
|
|
||||||
class Network {
|
class Network {
|
||||||
public:
|
static constexpr uint16_t OFFSET_PLASMA_SLAVE1 = 100;
|
||||||
|
static constexpr uint16_t OFFSET_PLASMA_SLAVE2 = 200;
|
||||||
|
static constexpr uint16_t COUNT_PLASMA_SLAVE = 51;
|
||||||
|
static constexpr uint16_t OFFSET_PLASMA_SLAVE1_RANGE2 = 4608;
|
||||||
|
static constexpr uint16_t OFFSET_PLASMA_SLAVE2_RANGE2 = 8704;
|
||||||
|
static constexpr uint16_t OFFSET_PLASMA_SLAVE3_RANGE2 = 12800;
|
||||||
|
|
||||||
|
public:
|
||||||
enum class NetID : neonetid_t {
|
enum class NetID : neonetid_t {
|
||||||
Device = 0,
|
Device = 0,
|
||||||
HSCAN = 1,
|
HSCAN = 1,
|
||||||
|
|
@ -263,7 +271,7 @@ public:
|
||||||
MDIO8 = 82,
|
MDIO8 = 82,
|
||||||
};
|
};
|
||||||
static const char* GetTypeString(Type type) {
|
static const char* GetTypeString(Type type) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case Type::CAN:
|
case Type::CAN:
|
||||||
return "CAN";
|
return "CAN";
|
||||||
case Type::LIN:
|
case Type::LIN:
|
||||||
|
|
@ -297,8 +305,200 @@ public:
|
||||||
return "Invalid Type";
|
return "Invalid Type";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class VnetId : uint8_t {
|
||||||
|
None = 0,
|
||||||
|
VNET_A = 1,
|
||||||
|
VNET_B = 2,
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* So if you are passing in the offset from OFFSET_PLASMA_SLAVE1 or
|
||||||
|
* the offset from OFFSET_PLASMA_SLAVE2, return the vnet agnostic
|
||||||
|
* netid so caller can commonize handlers without caring about WHICH slave.
|
||||||
|
*/
|
||||||
|
static NetID OffsetToSimpleNetworkId(uint16_t offset)
|
||||||
|
{
|
||||||
|
switch (offset)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case 0:
|
||||||
|
return NetID::Device;
|
||||||
|
case 1:
|
||||||
|
return NetID::HSCAN;
|
||||||
|
case 2:
|
||||||
|
return NetID::MSCAN;
|
||||||
|
case 3:
|
||||||
|
return NetID::SWCAN;
|
||||||
|
case 4:
|
||||||
|
return NetID::LSFTCAN;
|
||||||
|
case 5:
|
||||||
|
return NetID::FordSCP;
|
||||||
|
case 6:
|
||||||
|
return NetID::J1708;
|
||||||
|
case 7:
|
||||||
|
return NetID::Aux;
|
||||||
|
case 8:
|
||||||
|
return NetID::J1850VPW;
|
||||||
|
case 9:
|
||||||
|
return NetID::ISO9141;
|
||||||
|
case 10:
|
||||||
|
return NetID::ISOPIC;
|
||||||
|
case 11:
|
||||||
|
return NetID::Main51;
|
||||||
|
case 12:
|
||||||
|
return NetID::RED;
|
||||||
|
case 13:
|
||||||
|
return NetID::SCI;
|
||||||
|
case 14:
|
||||||
|
return NetID::ISO9141_2;
|
||||||
|
case 15:
|
||||||
|
return NetID::ISO14230;
|
||||||
|
case 16:
|
||||||
|
return NetID::LIN;
|
||||||
|
case 17:
|
||||||
|
return NetID::ISO9141_3;
|
||||||
|
case 18:
|
||||||
|
return NetID::HSCAN2;
|
||||||
|
case 19:
|
||||||
|
return NetID::HSCAN3;
|
||||||
|
case 20:
|
||||||
|
return NetID::ISO9141_4;
|
||||||
|
case 21:
|
||||||
|
return NetID::LIN2;
|
||||||
|
case 22:
|
||||||
|
return NetID::LIN3;
|
||||||
|
case 23:
|
||||||
|
return NetID::LIN4;
|
||||||
|
//case 24:
|
||||||
|
// return NetID::MOST; // Deprecated
|
||||||
|
case 25:
|
||||||
|
return NetID::CGI;
|
||||||
|
case 26:
|
||||||
|
return NetID::I2C;
|
||||||
|
case 27:
|
||||||
|
return NetID::SPI1;
|
||||||
|
case 28:
|
||||||
|
return NetID::FlexRay1a;
|
||||||
|
case 29:
|
||||||
|
return NetID::MOST25;
|
||||||
|
case 30:
|
||||||
|
return NetID::MOST50;
|
||||||
|
case 31:
|
||||||
|
return NetID::MOST150;
|
||||||
|
case 32:
|
||||||
|
return NetID::HSCAN4;
|
||||||
|
case 33:
|
||||||
|
return NetID::HSCAN5;
|
||||||
|
case 34:
|
||||||
|
return NetID::RS232;
|
||||||
|
case 35:
|
||||||
|
return NetID::UART;
|
||||||
|
case 36:
|
||||||
|
return NetID::UART2;
|
||||||
|
case 37:
|
||||||
|
return NetID::UART3;
|
||||||
|
case 38:
|
||||||
|
return NetID::UART4;
|
||||||
|
case 39:
|
||||||
|
return NetID::SWCAN2;
|
||||||
|
case 40:
|
||||||
|
return NetID::FlexRay1b;
|
||||||
|
case 41:
|
||||||
|
return NetID::FlexRay2a;
|
||||||
|
case 42:
|
||||||
|
return NetID::FlexRay2b;
|
||||||
|
case 43:
|
||||||
|
return NetID::LIN5;
|
||||||
|
case 44:
|
||||||
|
return NetID::Ethernet;
|
||||||
|
case 45:
|
||||||
|
return NetID::Ethernet_DAQ;
|
||||||
|
case 46:
|
||||||
|
return NetID::RED_App_Error;
|
||||||
|
case 47:
|
||||||
|
return NetID::HSCAN6;
|
||||||
|
case 48:
|
||||||
|
return NetID::HSCAN7;
|
||||||
|
case 49:
|
||||||
|
return NetID::LIN6;
|
||||||
|
case 50:
|
||||||
|
return NetID::LSFTCAN2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static bool Within(neonetid_t value, neonetid_t min, neonetid_t max)
|
||||||
|
{
|
||||||
|
return ((min <= value) && (value < max));
|
||||||
|
}
|
||||||
|
static bool IdIsSlaveARange1(neonetid_t fullNetid)
|
||||||
|
{
|
||||||
|
return Within(fullNetid, OFFSET_PLASMA_SLAVE1, OFFSET_PLASMA_SLAVE1 + COUNT_PLASMA_SLAVE);
|
||||||
|
}
|
||||||
|
static bool IdIsSlaveARange2(neonetid_t fullNetid)
|
||||||
|
{
|
||||||
|
return Within(fullNetid, OFFSET_PLASMA_SLAVE1_RANGE2, OFFSET_PLASMA_SLAVE2_RANGE2);
|
||||||
|
}
|
||||||
|
static bool IdIsSlaveBRange1(neonetid_t fullNetid)
|
||||||
|
{
|
||||||
|
return Within(fullNetid, OFFSET_PLASMA_SLAVE2, OFFSET_PLASMA_SLAVE2 + COUNT_PLASMA_SLAVE);
|
||||||
|
}
|
||||||
|
static bool IdIsSlaveBRange2(neonetid_t fullNetid)
|
||||||
|
{
|
||||||
|
return Within(fullNetid, OFFSET_PLASMA_SLAVE2_RANGE2, OFFSET_PLASMA_SLAVE3_RANGE2);
|
||||||
|
}
|
||||||
|
static std::pair<VnetId, NetID> GetVnetAgnosticNetid(neonetid_t fullNetid)
|
||||||
|
{
|
||||||
|
VnetId vnetId = VnetId::None;
|
||||||
|
NetID netId;
|
||||||
|
|
||||||
|
if (fullNetid < OFFSET_PLASMA_SLAVE1)
|
||||||
|
{
|
||||||
|
netId = static_cast<NetID>(fullNetid);
|
||||||
|
}
|
||||||
|
else if (IdIsSlaveARange1(fullNetid))
|
||||||
|
{
|
||||||
|
netId = OffsetToSimpleNetworkId(fullNetid - OFFSET_PLASMA_SLAVE1);
|
||||||
|
vnetId = VnetId::VNET_A;
|
||||||
|
}
|
||||||
|
else if (IdIsSlaveARange2(fullNetid))
|
||||||
|
{
|
||||||
|
netId = static_cast<NetID>((fullNetid - OFFSET_PLASMA_SLAVE1_RANGE2));
|
||||||
|
vnetId = VnetId::VNET_A;
|
||||||
|
}
|
||||||
|
else if (IdIsSlaveBRange1(fullNetid))
|
||||||
|
{
|
||||||
|
netId = OffsetToSimpleNetworkId(fullNetid - OFFSET_PLASMA_SLAVE2);
|
||||||
|
vnetId = VnetId::VNET_B;
|
||||||
|
}
|
||||||
|
else if (IdIsSlaveBRange2(fullNetid))
|
||||||
|
{
|
||||||
|
netId = static_cast<NetID>((fullNetid - OFFSET_PLASMA_SLAVE2_RANGE2));
|
||||||
|
vnetId = VnetId::VNET_B;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
netId = static_cast<NetID>(fullNetid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_pair(vnetId, netId);
|
||||||
|
}
|
||||||
|
static const char* GetVnetIdString(VnetId vnetId)
|
||||||
|
{
|
||||||
|
switch (vnetId)
|
||||||
|
{
|
||||||
|
case VnetId::None:
|
||||||
|
return "None";
|
||||||
|
case VnetId::VNET_A:
|
||||||
|
return "VNET A";
|
||||||
|
case VnetId::VNET_B:
|
||||||
|
return "VNET B";
|
||||||
|
}
|
||||||
|
return "Invalid VNET ID";
|
||||||
|
}
|
||||||
static Type GetTypeOfNetID(NetID netid) {
|
static Type GetTypeOfNetID(NetID netid) {
|
||||||
switch(netid) {
|
const auto [vnetId, commonNetId] = GetVnetAgnosticNetid((neonetid_t)netid);
|
||||||
|
(void)vnetId;
|
||||||
|
|
||||||
|
switch (commonNetId) {
|
||||||
case NetID::HSCAN:
|
case NetID::HSCAN:
|
||||||
case NetID::MSCAN:
|
case NetID::MSCAN:
|
||||||
case NetID::HSCAN2:
|
case NetID::HSCAN2:
|
||||||
|
|
@ -411,7 +611,10 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static const char* GetNetIDString(NetID netid) {
|
static const char* GetNetIDString(NetID netid) {
|
||||||
switch(netid) {
|
const auto [vnetId, commonNetId] = GetVnetAgnosticNetid((neonetid_t)netid);
|
||||||
|
(void)vnetId;
|
||||||
|
|
||||||
|
switch (commonNetId) {
|
||||||
case NetID::Device:
|
case NetID::Device:
|
||||||
return "neoVI";
|
return "neoVI";
|
||||||
case NetID::HSCAN:
|
case NetID::HSCAN:
|
||||||
|
|
@ -691,7 +894,7 @@ public:
|
||||||
return "Invalid Network";
|
return "Invalid Network";
|
||||||
}
|
}
|
||||||
static std::optional<CoreMini> GetCoreMiniNetworkFromNetID(NetID netid) {
|
static std::optional<CoreMini> GetCoreMiniNetworkFromNetID(NetID netid) {
|
||||||
switch(netid) {
|
switch (netid) {
|
||||||
case NetID::HSCAN:
|
case NetID::HSCAN:
|
||||||
return CoreMini::HSCAN;
|
return CoreMini::HSCAN;
|
||||||
case NetID::MSCAN:
|
case NetID::MSCAN:
|
||||||
|
|
@ -861,7 +1064,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static NetID GetNetIDFromCoreMiniNetwork(CoreMini cm) {
|
static NetID GetNetIDFromCoreMiniNetwork(CoreMini cm) {
|
||||||
switch(cm) {
|
switch (cm) {
|
||||||
case CoreMini::HSCAN:
|
case CoreMini::HSCAN:
|
||||||
return NetID::HSCAN;
|
return NetID::HSCAN;
|
||||||
case CoreMini::MSCAN:
|
case CoreMini::MSCAN:
|
||||||
|
|
@ -1032,11 +1235,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Network() { setValue(NetID::Invalid); }
|
Network() { setValue(NetID::Invalid); }
|
||||||
Network(neonetid_t netid) { setValue((NetID)netid); }
|
Network(neonetid_t netid) { setValue(static_cast<NetID>(netid)); }
|
||||||
Network(NetID netid) { setValue(netid); }
|
Network(NetID netid) { setValue(netid); }
|
||||||
Network(CoreMini cm) { setValue(GetNetIDFromCoreMiniNetwork(cm)); }
|
Network(CoreMini cm) { setValue(GetNetIDFromCoreMiniNetwork(cm)); }
|
||||||
NetID getNetID() const { return value; }
|
NetID getNetID() const { return value; }
|
||||||
Type getType() const { return type; }
|
Type getType() const { return type; }
|
||||||
|
VnetId getVnetId() const { return vnetId; }
|
||||||
std::optional<CoreMini> getCoreMini() const { return GetCoreMiniNetworkFromNetID(getNetID()); }
|
std::optional<CoreMini> getCoreMini() const { return GetCoreMiniNetworkFromNetID(getNetID()); }
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Network& network) {
|
friend std::ostream& operator<<(std::ostream& os, const Network& network) {
|
||||||
os << GetNetIDString(network.getNetID());
|
os << GetNetIDString(network.getNetID());
|
||||||
|
|
@ -1045,14 +1249,19 @@ public:
|
||||||
friend bool operator==(const Network& net1, const Network& net2) { return net1.getNetID() == net2.getNetID(); }
|
friend bool operator==(const Network& net1, const Network& net2) { return net1.getNetID() == net2.getNetID(); }
|
||||||
friend bool operator!=(const Network& net1, const Network& net2) { return !(net1 == net2); }
|
friend bool operator!=(const Network& net1, const Network& net2) { return !(net1 == net2); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetID value; // Always use setValue so that value and type stay in sync
|
NetID value; // Always use setValue so that value and type stay in sync
|
||||||
Type type;
|
Type type;
|
||||||
|
NetID commonNetId;
|
||||||
|
VnetId vnetId;
|
||||||
void setValue(NetID id) {
|
void setValue(NetID id) {
|
||||||
value = id;
|
value = id;
|
||||||
type = GetTypeOfNetID(value);
|
type = GetTypeOfNetID(value);
|
||||||
|
const auto vnetIdInfo = GetVnetAgnosticNetid((neonetid_t)id);
|
||||||
|
vnetId = vnetIdInfo.first;
|
||||||
|
commonNetId = vnetIdInfo.second;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue