Add LSFTCAN and SWCAN support
parent
c313801a21
commit
ae78122cbe
18
README.md
18
README.md
|
|
@ -50,12 +50,18 @@ std::this_thread::wait_for(std::chrono::seconds(5));
|
|||
std::vector<std::shared_ptr<icsneo::Message>> messages = myDevice->getMessages();
|
||||
std::cout << "We got " << messages.size() << " messages!" << std::endl;
|
||||
for(auto& msg : messages) {
|
||||
if(msg->network.getType() == icsneo::Network::Type::CAN) {
|
||||
// A message of type CAN is guaranteed to be a CANMessage, so we can static cast safely
|
||||
auto canmsg = std::static_pointer_cast<icsneo::CANMessage>(msg);
|
||||
// canmsg->arbid is valid here
|
||||
// canmsg->data is an std::vector<uint8_t>, you can check .size() for the DLC of the message
|
||||
// canmsg->timestamp is the time recorded by the hardware in nanoseconds since (1/1/2007 12:00:00 GMT)
|
||||
switch(msg->network.getType()) {
|
||||
case icsneo::Network::Type::CAN:
|
||||
case icsneo::Network::Type::SWCAN:
|
||||
case icsneo::Network::Type::LSFTCAN: {
|
||||
// A message of type CAN is guaranteed to be a CANMessage, so we can static cast safely
|
||||
auto canmsg = std::static_pointer_cast<icsneo::CANMessage>(msg);
|
||||
// canmsg->arbid is valid here
|
||||
// canmsg->data is an std::vector<uint8_t>, you can check .size() for the DLC of the message
|
||||
// canmsg->timestamp is the time recorded by the hardware in nanoseconds since (1/1/2007 12:00:00 GMT)
|
||||
}
|
||||
default:
|
||||
// Handle others
|
||||
}
|
||||
}
|
||||
myDevice->close();
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ static void NeoMessageToSpyMessage(const neomessage_t& newmsg, icsSpyMessage& ol
|
|||
oldmsg.StatusBitField4 = newmsg.status.statusBitfield[3];
|
||||
switch(Network::Type(newmsg.type)) {
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN:
|
||||
oldmsg.Protocol = newmsg.status.canfdFDF ? SPY_PROTOCOL_CANFD : SPY_PROTOCOL_CAN;
|
||||
break;
|
||||
case Network::Type::Ethernet:
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
|||
result->timestamp *= timestampMultiplier;
|
||||
result->network = packet->network;
|
||||
return true;
|
||||
case Network::Type::CAN: {
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN: {
|
||||
if(packet->data.size() < 24)
|
||||
return false;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ bool Encoder::encode(std::vector<uint8_t>& result, const std::shared_ptr<Message
|
|||
|
||||
break;
|
||||
} // End of Network::Type::Ethernet
|
||||
case Network::Type::CAN: {
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN: {
|
||||
auto canmsg = std::dynamic_pointer_cast<CANMessage>(message);
|
||||
if(!canmsg)
|
||||
return false; // The message was not a properly formed CANMessage
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
|||
neomsg.status.transmitMessage = message->transmitted;
|
||||
|
||||
switch(type) {
|
||||
case Network::Type::CAN: {
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN: {
|
||||
neomessage_can_t& can = *(neomessage_can_t*)&neomsg;
|
||||
auto canmsg = std::static_pointer_cast<CANMessage>(message);
|
||||
can.arbid = canmsg->arbid;
|
||||
|
|
@ -52,7 +54,9 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
|||
std::shared_ptr<Message> icsneo::CreateMessageFromNeoMessage(const neomessage_t* neomessage) {
|
||||
const Network network = neomessage->netid;
|
||||
switch(network.getType()) {
|
||||
case Network::Type::CAN: {
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN: {
|
||||
neomessage_can_t& can = *(neomessage_can_t*)neomessage;
|
||||
auto canmsg = std::make_shared<CANMessage>();
|
||||
canmsg->network = network;
|
||||
|
|
|
|||
|
|
@ -242,6 +242,9 @@ bool IDeviceSettings::applyDefaults(bool temporary) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// This short wait helps on FIRE devices, otherwise the checksum might be wrong!
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(3));
|
||||
|
||||
refresh(true); // Refresh ignoring checksum
|
||||
// The device might modify the settings once they are applied, however in this case it does not update the checksum
|
||||
// We refresh to get these updates, update the checksum, and send it back so it's all in sync
|
||||
|
|
@ -315,6 +318,32 @@ bool IDeviceSettings::setBaudrateFor(Network net, int64_t baudrate) {
|
|||
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
|
||||
return true;
|
||||
}
|
||||
case Network::Type::LSFTCAN: {
|
||||
CAN_SETTINGS* cfg = getMutableLSFTCANSettingsFor(net);
|
||||
if(cfg == nullptr)
|
||||
return false;
|
||||
|
||||
CANBaudrate newBaud = GetEnumValueForBaudrate(baudrate);
|
||||
if(newBaud == (CANBaudrate)-1)
|
||||
return false;
|
||||
cfg->Baudrate = (uint8_t)newBaud;
|
||||
cfg->auto_baud = false;
|
||||
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
|
||||
return true;
|
||||
}
|
||||
case Network::Type::SWCAN: {
|
||||
SWCAN_SETTINGS* cfg = getMutableSWCANSettingsFor(net);
|
||||
if(cfg == nullptr)
|
||||
return false;
|
||||
|
||||
CANBaudrate newBaud = GetEnumValueForBaudrate(baudrate);
|
||||
if(newBaud == (CANBaudrate)-1)
|
||||
return false;
|
||||
cfg->Baudrate = (uint8_t)newBaud;
|
||||
cfg->auto_baud = false;
|
||||
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,6 +370,26 @@ public:
|
|||
return static_cast<CANFD_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
|
||||
}
|
||||
|
||||
virtual const CAN_SETTINGS* getLSFTCANSettingsFor(Network net) const { (void)net; return nullptr; }
|
||||
CAN_SETTINGS* getMutableLSFTCANSettingsFor(Network net) {
|
||||
if(disabled || readonly)
|
||||
return nullptr;
|
||||
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())));
|
||||
}
|
||||
|
||||
virtual const SWCAN_SETTINGS* getSWCANSettingsFor(Network net) const { (void)net; return nullptr; }
|
||||
SWCAN_SETTINGS* getMutableSWCANSettingsFor(Network net) {
|
||||
if(disabled || readonly)
|
||||
return nullptr;
|
||||
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())));
|
||||
}
|
||||
|
||||
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()); }
|
||||
|
|
|
|||
|
|
@ -27,14 +27,10 @@ public:
|
|||
Network::NetID::MSCAN,
|
||||
Network::NetID::HSCAN2,
|
||||
Network::NetID::HSCAN3,
|
||||
Network::NetID::HSCAN4,
|
||||
Network::NetID::HSCAN5,
|
||||
|
||||
Network::NetID::LSFTCAN,
|
||||
Network::NetID::LSFTCAN2,
|
||||
|
||||
Network::NetID::SWCAN,
|
||||
Network::NetID::SWCAN2,
|
||||
|
||||
Network::NetID::LIN,
|
||||
Network::NetID::LIN2,
|
||||
|
|
|
|||
|
|
@ -113,6 +113,20 @@ public:
|
|||
return &(cfg->can3);
|
||||
case Network::NetID::HSCAN3:
|
||||
return &(cfg->can4);
|
||||
case Network::NetID::LSFTCAN:
|
||||
return &(cfg->lsftcan);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
const CAN_SETTINGS* getLSFTCANSettingsFor(Network net) const override { return getCANSettingsFor(net); }
|
||||
const SWCAN_SETTINGS* getSWCANSettingsFor(Network net) const override {
|
||||
auto cfg = getStructurePointer<neovifire_settings_t>();
|
||||
if(cfg == nullptr)
|
||||
return nullptr;
|
||||
switch(net.getNetID()) {
|
||||
case Network::NetID::SWCAN:
|
||||
return &(cfg->swcan);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,10 @@ public:
|
|||
return &(cfg->can7);
|
||||
case Network::NetID::HSCAN7:
|
||||
return &(cfg->can8);
|
||||
case Network::NetID::LSFTCAN:
|
||||
return &(cfg->lsftcan1);
|
||||
case Network::NetID::LSFTCAN2:
|
||||
return &(cfg->lsftcan2);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -164,6 +168,20 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
const CAN_SETTINGS* getLSFTCANSettingsFor(Network net) const override { return getCANSettingsFor(net); }
|
||||
const SWCAN_SETTINGS* getSWCANSettingsFor(Network net) const override {
|
||||
auto cfg = getStructurePointer<neovifire2_settings_t>();
|
||||
if(cfg == nullptr)
|
||||
return nullptr;
|
||||
switch(net.getNetID()) {
|
||||
case Network::NetID::SWCAN:
|
||||
return &(cfg->swcan1);
|
||||
case Network::NetID::SWCAN2:
|
||||
return &(cfg->swcan2);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue