diff --git a/README.md b/README.md index 133faeb..c477c86 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,18 @@ std::this_thread::wait_for(std::chrono::seconds(5)); std::vector> 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(msg); - // canmsg->arbid is valid here - // canmsg->data is an std::vector, 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(msg); + // canmsg->arbid is valid here + // canmsg->data is an std::vector, 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(); diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index bd47ef2..61766dc 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -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: diff --git a/communication/decoder.cpp b/communication/decoder.cpp index d213a4a..863d2fa 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -30,7 +30,9 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptrtimestamp *= 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; diff --git a/communication/encoder.cpp b/communication/encoder.cpp index c5b9794..82805f4 100644 --- a/communication/encoder.cpp +++ b/communication/encoder.cpp @@ -22,7 +22,9 @@ bool Encoder::encode(std::vector& result, const std::shared_ptr(message); if(!canmsg) return false; // The message was not a properly formed CANMessage diff --git a/communication/message/neomessage.cpp b/communication/message/neomessage.cpp index f6dd2df..1774997 100644 --- a/communication/message/neomessage.cpp +++ b/communication/message/neomessage.cpp @@ -18,7 +18,9 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr 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(message); can.arbid = canmsg->arbid; @@ -52,7 +54,9 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr message) { std::shared_ptr 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(); canmsg->network = network; diff --git a/device/idevicesettings.cpp b/device/idevicesettings.cpp index 781dccc..b40bce3 100644 --- a/device/idevicesettings.cpp +++ b/device/idevicesettings.cpp @@ -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; } diff --git a/include/icsneo/device/idevicesettings.h b/include/icsneo/device/idevicesettings.h index 9febdae..d748175 100644 --- a/include/icsneo/device/idevicesettings.h +++ b/include/icsneo/device/idevicesettings.h @@ -370,6 +370,26 @@ public: return static_cast((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((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((void*)(settings.data() + (offset - settingsInDeviceRAM.data()))); + } + const void* getRawStructurePointer() const { return settingsInDeviceRAM.data(); } void* getMutableRawStructurePointer() { return settings.data(); } template const T* getStructurePointer() const { return static_cast(getRawStructurePointer()); } diff --git a/include/icsneo/device/neovifire/neovifire.h b/include/icsneo/device/neovifire/neovifire.h index 48ea25a..3d9da93 100644 --- a/include/icsneo/device/neovifire/neovifire.h +++ b/include/icsneo/device/neovifire/neovifire.h @@ -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, diff --git a/include/icsneo/device/neovifire/neovifiresettings.h b/include/icsneo/device/neovifire/neovifiresettings.h index 77aec68..71658fe 100644 --- a/include/icsneo/device/neovifire/neovifiresettings.h +++ b/include/icsneo/device/neovifire/neovifiresettings.h @@ -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(); + if(cfg == nullptr) + return nullptr; + switch(net.getNetID()) { + case Network::NetID::SWCAN: + return &(cfg->swcan); default: return nullptr; } diff --git a/include/icsneo/device/neovifire2/neovifire2settings.h b/include/icsneo/device/neovifire2/neovifire2settings.h index 8477814..d245042 100644 --- a/include/icsneo/device/neovifire2/neovifire2settings.h +++ b/include/icsneo/device/neovifire2/neovifire2settings.h @@ -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(); + 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; + } + } }; }