ttlappalainen / NMEA0183

Library for handling NMEA0183 messages
69 stars 44 forks source link

break; missing in switch? #14

Open ronzeiller opened 4 years ago

ronzeiller commented 4 years ago

Hi Timo,

in example NMEA0183/Examples/NMEA2000ToNMEA0183/

there is:

void tN2kDataToNMEA0183::HandleMsg(const tN2kMsg &N2kMsg) {
  switch (N2kMsg.PGN) {
    case 127250UL: HandleHeading(N2kMsg);
    case 127258UL: HandleVariation(N2kMsg);
    case 128259UL: HandleBoatSpeed(N2kMsg);
    case 128267UL: HandleDepth(N2kMsg);
    case 129025UL: HandlePosition(N2kMsg);
    case 129026UL: HandleCOGSOG(N2kMsg);
    case 129029UL: HandleGNSS(N2kMsg);
  }
}

I was adding case 129038UL: HandleAISClassAPosReport(N2kMsg); // AIS Class A Position Report

and got many false returns, because every PGN from all cases were sent to on ParseN2kPGN129038 function.

I added break; to each caseline and now it works.

ttlappalainen commented 4 years ago

I am shamed. Very basic error. Normally I handle those with dynamic lists, so this has not been on "production" use for me.

Will you pull fix, when you have added more sentences?

ronzeiller commented 4 years ago

Just saw, that you have quite often no break in switch/case functions. (All examples with those handles and a lot in your library code.

Normally I would say if it is let´s say the last case 129029UL, why should the missing breaks of the earlier case xxx: then harm?