From 88c17c29f6de680d10f6b1a8d375ece74d6ac9c3 Mon Sep 17 00:00:00 2001 From: Timo Lappalainen Date: Tue, 24 Sep 2024 14:48:20 +0300 Subject: [PATCH] Fix ISO request and 130316 - Fixed UpdateHasPendingInformation() to use or (||) on test. - Fix no NAK for broadcast ISO Request - Fix do not call ISORqstHandler for specific messages, if request is broadcast - Added HandleCommand group function handler for heartbeat (PGN 126993) - Fixed 130316 temperature to unsigned by EricvanderVelde --- Documents/src/changes.md | 7 ++++ library.json | 2 +- library.properties | 2 +- src/N2kGroupFunctionDefaultHandlers.cpp | 19 +++++++++ src/N2kGroupFunctionDefaultHandlers.h | 1 + src/NMEA2000.cpp | 52 +++++++++++++++++++------ src/NMEA2000.h | 8 ++-- 7 files changed, 74 insertions(+), 17 deletions(-) diff --git a/Documents/src/changes.md b/Documents/src/changes.md index 6d2a52f7..06ed5213 100644 --- a/Documents/src/changes.md +++ b/Documents/src/changes.md @@ -1,6 +1,13 @@ # Changes to the Library {#changes} \tableofcontents +## 24.09.2024 +- Fixed UpdateHasPendingInformation() to use or (||) on test. +- Fix no NAK for broadcast ISO Request +- Fix do not call ISORqstHandler for specific messages, if request is broadcast +- Added HandleCommand group function handler for heartbeat (PGN 126993) +- Fixed 130316 temperature to unsigned by EricvanderVelde + ## 23.05.2024 - Fixed GetVarStr to handle invalid length, thanks to EricvanderVelde. - Fixed PGN 129794 setter to set SID properly. diff --git a/library.json b/library.json index 8cf2e407..bde26a75 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "url": "http://www.kave.fi", "maintainer": true }, - "version": "4.21.5", + "version": "4.22.0", "license": "MIT", "frameworks": "*", "platforms": "*" diff --git a/library.properties b/library.properties index 9f80e72e..9b50446b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=NMEA2000 -version=4.21.5 +version=4.22.0 author=Timo Lappalainen maintainer=Kave Oy sentence=NMEA 2000 library for building compatible devices for NMEA 2000 bus. diff --git a/src/N2kGroupFunctionDefaultHandlers.cpp b/src/N2kGroupFunctionDefaultHandlers.cpp index 05ff127b..aeac3bab 100644 --- a/src/N2kGroupFunctionDefaultHandlers.cpp +++ b/src/N2kGroupFunctionDefaultHandlers.cpp @@ -535,6 +535,25 @@ bool tN2kGroupFunctionHandlerForPGN126993::HandleRequest(const tN2kMsg &N2kMsg, } return true; } + +//***************************************************************************** +bool tN2kGroupFunctionHandlerForPGN126993::HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev) { + + // As default we respond with not supported. + tN2kGroupFunctionPGNErrorCode PGNec=N2kgfPGNec_PGNNotSupported; + tN2kGroupFunctionTransmissionOrPriorityErrorCode TORec=N2kgfTPec_Acknowledge; + tN2kGroupFunctionParameterErrorCode PARec=N2kgfpec_Acknowledge; + + if ( !(PrioritySetting == 0x08 || PrioritySetting == 0x0f || PrioritySetting == 0x09) ) TORec = N2kgfTPec_TransmitIntervalOrPriorityNotSupported; + + SendAcknowledge(pNMEA2000,N2kMsg.Source,iDev,GetPGNForGroupFunction(N2kMsg), + PGNec, + TORec, + NumberOfParameterPairs, PARec); + + return true; +} + #endif #endif diff --git a/src/N2kGroupFunctionDefaultHandlers.h b/src/N2kGroupFunctionDefaultHandlers.h index 5f3b6543..c44b8770 100644 --- a/src/N2kGroupFunctionDefaultHandlers.h +++ b/src/N2kGroupFunctionDefaultHandlers.h @@ -120,6 +120,7 @@ class tN2kGroupFunctionHandlerForPGN126993 : public tN2kGroupFunctionHandler { uint16_t TransmissionIntervalOffset, uint8_t NumberOfParameterPairs, int iDev); + virtual bool HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev); public: tN2kGroupFunctionHandlerForPGN126993(tNMEA2000 *_pNMEA2000) : tN2kGroupFunctionHandler(_pNMEA2000,126993L) {} }; diff --git a/src/NMEA2000.cpp b/src/NMEA2000.cpp index 0424b880..6ae4a136 100644 --- a/src/NMEA2000.cpp +++ b/src/NMEA2000.cpp @@ -282,14 +282,14 @@ bool IsDefaultSingleFrameMessage(unsigned long PGN) { case 127245L: // Rudder, pri=2, period=100 case 127250L: // Vessel Heading, pri=2, period=100 case 127251L: // Rate of Turn, pri=2, period=100 - case 127252L: // Heave, pri=3, period=100 + case 127252L: // Heave, pri=3, period=100 case 127257L: // Attitude, pri=3, period=1000 case 127488L: // Engine parameters rapid, rapid Update, pri=2, period=100 case 127493L: // Transmission parameters: dynamic, pri=2, period=100 case 127501L: // Binary status report, pri=3, period=NA case 127505L: // Fluid level, pri=6, period=2500 case 127508L: // Battery Status, pri=6, period=1500 - case 127750L: // Charger status new, pri=6, period=1500 + case 127750L: // Charger status new, pri=6, period=1500 case 128259L: // Boat speed, pri=2, period=1000 case 128267L: // Water depth, pri=3, period=1000 case 129025L: // Lat/lon rapid, pri=2, period=100 @@ -405,6 +405,9 @@ bool IsMandatoryFastPacketMessage(unsigned long PGN) { * - 129811L: AIS Single Slot Binary Message, pri=5, period=NA * - 129812L: AIS Multi Slot Binary Message, pri=5, period=NA * - 129813L: AIS Long-Range Broadcast Message, pri=5, period=NA + * - 129814L: AIS single slot binary message, pri=5, period=NA + * - 129815L: AIS multi slot binary message, pri=5, period=NA + * - 129816L: AIS acknowledge, pri=7, period=NA * - 130052L: Loran-C TD Data, pri=3, period=1000 * - 130053L: Loran-C Range Data, pri=3, period=1000 * - 130054L: Loran-C Signal Data, pri=3, period=1000 @@ -522,6 +525,9 @@ bool IsDefaultFastPacketMessage(unsigned long PGN) { case 129811L: // AIS Single Slot Binary Message, pri=5, period=NA case 129812L: // AIS Multi Slot Binary Message, pri=5, period=NA case 129813L: // AIS Long-Range Broadcast Message, pri=5, period=NA + case 129814L: // AIS single slot binary message, pri=5, period=NA + case 129815L: // AIS multi slot binary message, pri=5, period=NA + case 129816L: // AIS acknowledge, pri=7, period=NA case 130052L: // Loran-C TD Data, pri=3, period=1000 case 130053L: // Loran-C Range Data, pri=3, period=1000 case 130054L: // Loran-C Signal Data, pri=3, period=1000 @@ -588,6 +594,24 @@ bool tNMEA2000::IsProprietaryMessage(unsigned long PGN) { return IsProprietaryFastPacketMessage(PGN) || ( PGN==61184L ) || ( 65280L<=PGN && PGN<=65535L ); } +bool IgnoreBroadcastISORequest(unsigned long RequestedPGN) { + switch (RequestedPGN) { + case 127500L: + case 130060L: + case 130061L: + case 130330L: + case 130561L: + case 130562L: + case 130563L: + case 130564L: + case 130565L: + case 130566L: + return true; + } + + return false; +} + /************************************************************************//** * \brief Default Product Information * @@ -2298,7 +2322,7 @@ bool tNMEA2000::SendConfigurationInformation(int DeviceIndex) { } //***************************************************************************** -void tNMEA2000::RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev) { +void tNMEA2000::RespondISORequest(const tN2kMsg &N2kMsg, bool Addressed, unsigned long RequestedPGN, int iDev) { if ( IsAddressClaimStarted(iDev) ) return; // We do not respond any queries during address claiming. switch (RequestedPGN) { @@ -2318,18 +2342,24 @@ void tNMEA2000::RespondISORequest(const tN2kMsg &N2kMsg, unsigned long Requested default: /* If user has established a handler */ if (ISORqstHandler!=0) { + // Do not respond to broadcast request for some messages + if ( !Addressed && IgnoreBroadcastISORequest(RequestedPGN) ) return; + /* and if it handled the request, we are done */ if (ISORqstHandler(RequestedPGN,N2kMsg.Source,iDev)) { return; } } - tN2kMsg N2kMsgR; - // No user handler, or there was one and it returned FALSE. Send NAK - SetN2kPGNISOAcknowledgement(N2kMsgR,1,0xff,RequestedPGN); - // Direct the response to original requester. - N2kMsgR.Destination = N2kMsg.Source; - SendMsg(N2kMsgR,iDev); + // Respond NAK only for addressed messages + if ( Addressed ) { + tN2kMsg N2kMsgR; + // No user handler, or there was one and it retured FALSE. Send NAK + SetN2kPGNISOAcknowledgement(N2kMsgR,1,0xff,RequestedPGN); + // Direct the response to original requester. + N2kMsgR.Destination = N2kMsg.Source; + SendMsg(N2kMsgR,iDev); + } } } @@ -2343,9 +2373,9 @@ void tNMEA2000::HandleISORequest(const tN2kMsg &N2kMsg) { ParseN2kPGNISORequest(N2kMsg,RequestedPGN); N2kMsgDbgStart("ISO request: "); N2kMsgDbgln(RequestedPGN); if (tNMEA2000::IsBroadcast(N2kMsg.Destination)) { // broadcast -> respond from all devices - for (iDev=0; iDev