Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break; missing in switch? #14

Open
ronzeiller opened this issue Nov 2, 2019 · 2 comments
Open

break; missing in switch? #14

ronzeiller opened this issue Nov 2, 2019 · 2 comments

Comments

@ronzeiller
Copy link

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 case line and now it works.

@ttlappalainen
Copy link
Owner

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants