Skip to content

Commit 88c17c2

Browse files
committed
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
1 parent 643a39b commit 88c17c2

File tree

7 files changed

+74
-17
lines changed

7 files changed

+74
-17
lines changed

Documents/src/changes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changes to the Library {#changes}
22
\tableofcontents
33

4+
## 24.09.2024
5+
- Fixed UpdateHasPendingInformation() to use or (||) on test.
6+
- Fix no NAK for broadcast ISO Request
7+
- Fix do not call ISORqstHandler for specific messages, if request is broadcast
8+
- Added HandleCommand group function handler for heartbeat (PGN 126993)
9+
- Fixed 130316 temperature to unsigned by EricvanderVelde
10+
411
## 23.05.2024
512
- Fixed GetVarStr to handle invalid length, thanks to EricvanderVelde.
613
- Fixed PGN 129794 setter to set SID properly.

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"url": "http://www.kave.fi",
1414
"maintainer": true
1515
},
16-
"version": "4.21.5",
16+
"version": "4.22.0",
1717
"license": "MIT",
1818
"frameworks": "*",
1919
"platforms": "*"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=NMEA2000
2-
version=4.21.5
2+
version=4.22.0
33
author=Timo Lappalainen
44
maintainer=Kave Oy <www.kave.fi>
55
sentence=NMEA 2000 library for building compatible devices for NMEA 2000 bus.

src/N2kGroupFunctionDefaultHandlers.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,25 @@ bool tN2kGroupFunctionHandlerForPGN126993::HandleRequest(const tN2kMsg &N2kMsg,
535535
}
536536
return true;
537537
}
538+
539+
//*****************************************************************************
540+
bool tN2kGroupFunctionHandlerForPGN126993::HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev) {
541+
542+
// As default we respond with not supported.
543+
tN2kGroupFunctionPGNErrorCode PGNec=N2kgfPGNec_PGNNotSupported;
544+
tN2kGroupFunctionTransmissionOrPriorityErrorCode TORec=N2kgfTPec_Acknowledge;
545+
tN2kGroupFunctionParameterErrorCode PARec=N2kgfpec_Acknowledge;
546+
547+
if ( !(PrioritySetting == 0x08 || PrioritySetting == 0x0f || PrioritySetting == 0x09) ) TORec = N2kgfTPec_TransmitIntervalOrPriorityNotSupported;
548+
549+
SendAcknowledge(pNMEA2000,N2kMsg.Source,iDev,GetPGNForGroupFunction(N2kMsg),
550+
PGNec,
551+
TORec,
552+
NumberOfParameterPairs, PARec);
553+
554+
return true;
555+
}
556+
538557
#endif
539558

540559
#endif

src/N2kGroupFunctionDefaultHandlers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class tN2kGroupFunctionHandlerForPGN126993 : public tN2kGroupFunctionHandler {
120120
uint16_t TransmissionIntervalOffset,
121121
uint8_t NumberOfParameterPairs,
122122
int iDev);
123+
virtual bool HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev);
123124
public:
124125
tN2kGroupFunctionHandlerForPGN126993(tNMEA2000 *_pNMEA2000) : tN2kGroupFunctionHandler(_pNMEA2000,126993L) {}
125126
};

src/NMEA2000.cpp

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ bool IsDefaultSingleFrameMessage(unsigned long PGN) {
282282
case 127245L: // Rudder, pri=2, period=100
283283
case 127250L: // Vessel Heading, pri=2, period=100
284284
case 127251L: // Rate of Turn, pri=2, period=100
285-
case 127252L: // Heave, pri=3, period=100
285+
case 127252L: // Heave, pri=3, period=100
286286
case 127257L: // Attitude, pri=3, period=1000
287287
case 127488L: // Engine parameters rapid, rapid Update, pri=2, period=100
288288
case 127493L: // Transmission parameters: dynamic, pri=2, period=100
289289
case 127501L: // Binary status report, pri=3, period=NA
290290
case 127505L: // Fluid level, pri=6, period=2500
291291
case 127508L: // Battery Status, pri=6, period=1500
292-
case 127750L: // Charger status new, pri=6, period=1500
292+
case 127750L: // Charger status new, pri=6, period=1500
293293
case 128259L: // Boat speed, pri=2, period=1000
294294
case 128267L: // Water depth, pri=3, period=1000
295295
case 129025L: // Lat/lon rapid, pri=2, period=100
@@ -405,6 +405,9 @@ bool IsMandatoryFastPacketMessage(unsigned long PGN) {
405405
* - 129811L: AIS Single Slot Binary Message, pri=5, period=NA
406406
* - 129812L: AIS Multi Slot Binary Message, pri=5, period=NA
407407
* - 129813L: AIS Long-Range Broadcast Message, pri=5, period=NA
408+
* - 129814L: AIS single slot binary message, pri=5, period=NA
409+
* - 129815L: AIS multi slot binary message, pri=5, period=NA
410+
* - 129816L: AIS acknowledge, pri=7, period=NA
408411
* - 130052L: Loran-C TD Data, pri=3, period=1000
409412
* - 130053L: Loran-C Range Data, pri=3, period=1000
410413
* - 130054L: Loran-C Signal Data, pri=3, period=1000
@@ -522,6 +525,9 @@ bool IsDefaultFastPacketMessage(unsigned long PGN) {
522525
case 129811L: // AIS Single Slot Binary Message, pri=5, period=NA
523526
case 129812L: // AIS Multi Slot Binary Message, pri=5, period=NA
524527
case 129813L: // AIS Long-Range Broadcast Message, pri=5, period=NA
528+
case 129814L: // AIS single slot binary message, pri=5, period=NA
529+
case 129815L: // AIS multi slot binary message, pri=5, period=NA
530+
case 129816L: // AIS acknowledge, pri=7, period=NA
525531
case 130052L: // Loran-C TD Data, pri=3, period=1000
526532
case 130053L: // Loran-C Range Data, pri=3, period=1000
527533
case 130054L: // Loran-C Signal Data, pri=3, period=1000
@@ -588,6 +594,24 @@ bool tNMEA2000::IsProprietaryMessage(unsigned long PGN) {
588594
return IsProprietaryFastPacketMessage(PGN) || ( PGN==61184L ) || ( 65280L<=PGN && PGN<=65535L );
589595
}
590596

597+
bool IgnoreBroadcastISORequest(unsigned long RequestedPGN) {
598+
switch (RequestedPGN) {
599+
case 127500L:
600+
case 130060L:
601+
case 130061L:
602+
case 130330L:
603+
case 130561L:
604+
case 130562L:
605+
case 130563L:
606+
case 130564L:
607+
case 130565L:
608+
case 130566L:
609+
return true;
610+
}
611+
612+
return false;
613+
}
614+
591615
/************************************************************************//**
592616
* \brief Default Product Information
593617
*
@@ -2298,7 +2322,7 @@ bool tNMEA2000::SendConfigurationInformation(int DeviceIndex) {
22982322
}
22992323

23002324
//*****************************************************************************
2301-
void tNMEA2000::RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev) {
2325+
void tNMEA2000::RespondISORequest(const tN2kMsg &N2kMsg, bool Addressed, unsigned long RequestedPGN, int iDev) {
23022326
if ( IsAddressClaimStarted(iDev) ) return; // We do not respond any queries during address claiming.
23032327

23042328
switch (RequestedPGN) {
@@ -2318,18 +2342,24 @@ void tNMEA2000::RespondISORequest(const tN2kMsg &N2kMsg, unsigned long Requested
23182342
default:
23192343
/* If user has established a handler */
23202344
if (ISORqstHandler!=0) {
2345+
// Do not respond to broadcast request for some messages
2346+
if ( !Addressed && IgnoreBroadcastISORequest(RequestedPGN) ) return;
2347+
23212348
/* and if it handled the request, we are done */
23222349
if (ISORqstHandler(RequestedPGN,N2kMsg.Source,iDev)) {
23232350
return;
23242351
}
23252352
}
23262353

2327-
tN2kMsg N2kMsgR;
2328-
// No user handler, or there was one and it returned FALSE. Send NAK
2329-
SetN2kPGNISOAcknowledgement(N2kMsgR,1,0xff,RequestedPGN);
2330-
// Direct the response to original requester.
2331-
N2kMsgR.Destination = N2kMsg.Source;
2332-
SendMsg(N2kMsgR,iDev);
2354+
// Respond NAK only for addressed messages
2355+
if ( Addressed ) {
2356+
tN2kMsg N2kMsgR;
2357+
// No user handler, or there was one and it retured FALSE. Send NAK
2358+
SetN2kPGNISOAcknowledgement(N2kMsgR,1,0xff,RequestedPGN);
2359+
// Direct the response to original requester.
2360+
N2kMsgR.Destination = N2kMsg.Source;
2361+
SendMsg(N2kMsgR,iDev);
2362+
}
23332363
}
23342364
}
23352365

@@ -2343,9 +2373,9 @@ void tNMEA2000::HandleISORequest(const tN2kMsg &N2kMsg) {
23432373
ParseN2kPGNISORequest(N2kMsg,RequestedPGN);
23442374
N2kMsgDbgStart("ISO request: "); N2kMsgDbgln(RequestedPGN);
23452375
if (tNMEA2000::IsBroadcast(N2kMsg.Destination)) { // broadcast -> respond from all devices
2346-
for (iDev=0; iDev<DeviceCount; iDev++) RespondISORequest(N2kMsg,RequestedPGN,iDev);
2376+
for (iDev=0; iDev<DeviceCount; iDev++) RespondISORequest(N2kMsg,false,RequestedPGN,iDev);
23472377
} else {
2348-
RespondISORequest(N2kMsg,RequestedPGN,iDev);
2378+
RespondISORequest(N2kMsg,true,RequestedPGN,iDev);
23492379
}
23502380
}
23512381

src/NMEA2000.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,10 @@ class tNMEA2000
921921
}
922922
void UpdateHasPendingInformation() {
923923
HasPendingInformation= PendingIsoAddressClaim.IsEnabled()
924-
| PendingProductInformation.IsEnabled()
925-
| PendingConfigurationInformation.IsEnabled()
924+
|| PendingProductInformation.IsEnabled()
925+
|| PendingConfigurationInformation.IsEnabled()
926926
#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
927-
| NextDTSendTime.IsEnabled()
927+
|| NextDTSendTime.IsEnabled()
928928
#endif
929929
;
930930
}
@@ -1381,7 +1381,7 @@ class tNMEA2000
13811381
* \param RequestedPGN Requested PGN
13821382
* \param iDev index of the device on \ref Devices
13831383
*/
1384-
void RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev);
1384+
void RespondISORequest(const tN2kMsg &N2kMsg, bool Addressed, unsigned long RequestedPGN, int iDev);
13851385

13861386
/*********************************************************************//**
13871387
* \brief Handles an ISO Request

0 commit comments

Comments
 (0)