NMEA2000 icon indicating copy to clipboard operation
NMEA2000 copied to clipboard

tN2kGroupFunctionHandler::HandleCommand error

Open evilruff opened this issue 1 year ago • 2 comments

Hi,

I think there is something wrong in this code:

bool tN2kGroupFunctionHandler::HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t  NumberOfParameterPairs, int iDev) {

    // As default we respond with not supported.
    bool IsTxPGN=pNMEA2000->IsTxPGN(GetPGNForGroupFunction(N2kMsg),iDev);
    tN2kGroupFunctionPGNErrorCode PGNec=(IsTxPGN?N2kgfPGNec_Acknowledge:N2kgfPGNec_PGNNotSupported);
    tN2kGroupFunctionTransmissionOrPriorityErrorCode TORec=N2kgfTPec_Acknowledge;
    tN2kGroupFunctionParameterErrorCode PARec=N2kgfpec_Acknowledge;

    if (PrioritySetting != 0x08 || PrioritySetting != 0x0f || PrioritySetting != 0x09) TORec = N2kgfTPec_TransmitIntervalOrPriorityNotSupported;

as IF(..) statement is always true, I think it should be && rather then ||

also here simular problem

void SetN2kPGN129540(tN2kMsg& N2kMsg, unsigned char SID, tN2kRangeResidualMode Mode) {
    N2kMsg.SetPGN(129540L);
    N2kMsg.Priority=6;
    N2kMsg.AddByte(SID);
    N2kMsg.AddByte(0xfc || Mode);
    N2kMsg.AddByte(0); // Init satellite count to 0
}

AddByte(0xfc || Mode); - this always evaluates to 1

evilruff avatar Jan 16 '24 13:01 evilruff

Should be if ( !(PrioritySetting == 0x08 || PrioritySetting == 0x0f || PrioritySetting == 0x09) ) Same error is also on some default handlers.

Should be AddByte(0xfc | (Mode & 0x03) );

I fix those after I have first done document update. I prefer to do document update as pure document update without any code update.

ttlappalainen avatar Jan 16 '24 13:01 ttlappalainen

Above has been fixed on 22.01.2024 update.

ttlappalainen avatar Jan 22 '24 14:01 ttlappalainen