Skip to content

Commit

Permalink
Fix ISO request and 130316
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ttlappalainen committed Sep 24, 2024
1 parent 643a39b commit 88c17c2
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 17 deletions.
7 changes: 7 additions & 0 deletions Documents/src/changes.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "http://www.kave.fi",
"maintainer": true
},
"version": "4.21.5",
"version": "4.22.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NMEA2000
version=4.21.5
version=4.22.0
author=Timo Lappalainen
maintainer=Kave Oy <www.kave.fi>
sentence=NMEA 2000 library for building compatible devices for NMEA 2000 bus.
Expand Down
19 changes: 19 additions & 0 deletions src/N2kGroupFunctionDefaultHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/N2kGroupFunctionDefaultHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
};
Expand Down
52 changes: 41 additions & 11 deletions src/NMEA2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
}

Expand All @@ -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<DeviceCount; iDev++) RespondISORequest(N2kMsg,RequestedPGN,iDev);
for (iDev=0; iDev<DeviceCount; iDev++) RespondISORequest(N2kMsg,false,RequestedPGN,iDev);
} else {
RespondISORequest(N2kMsg,RequestedPGN,iDev);
RespondISORequest(N2kMsg,true,RequestedPGN,iDev);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/NMEA2000.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ class tNMEA2000
}
void UpdateHasPendingInformation() {
HasPendingInformation= PendingIsoAddressClaim.IsEnabled()
| PendingProductInformation.IsEnabled()
| PendingConfigurationInformation.IsEnabled()
|| PendingProductInformation.IsEnabled()
|| PendingConfigurationInformation.IsEnabled()
#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
| NextDTSendTime.IsEnabled()
|| NextDTSendTime.IsEnabled()
#endif
;
}
Expand Down Expand Up @@ -1381,7 +1381,7 @@ class tNMEA2000
* \param RequestedPGN Requested PGN
* \param iDev index of the device on \ref Devices
*/
void RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev);
void RespondISORequest(const tN2kMsg &N2kMsg, bool Addressed, unsigned long RequestedPGN, int iDev);

/*********************************************************************//**
* \brief Handles an ISO Request
Expand Down

0 comments on commit 88c17c2

Please sign in to comment.