KimBP / AIS

An Arduino library able to decode AIS messages
Other
30 stars 9 forks source link

unsupported message error #2

Closed kimphg closed 6 years ago

kimphg commented 7 years ago

This library doesn't handle AIS messages other than type 1 2 3 18 24, if a message of other types come, there will be error. Because by default msgType=AIS_MSG_MAX and there is no definittion on AIS_MSG_MAX.

KimBP commented 7 years ago

I agree it doesn't handle other than 1 2 3 18 24 (and 4 and 5), but I don't see how you think any other message will cause an error. Can you explain that?

In the constructor of the class the private method numericToMessage() is called. This method traverses the AisMsgTypes[] array and in case an unsupported message is found, the function returns AIS_MSG_MAX (which is defined as last entry of enum Nmea0183AisMessages.

I've use the library with live data (though I can't guarantee having received any messages but the supported) for several months now without any problems.

In my VhfToN2k-blue repository you can see in src/nmea0183Handler.cpp how I use the AIS library:


AIS ais_msg(buf, fillBits);

// Convert to N2k message.
// See relation between AIS messages and PGN at
// http://www.panbo.com/Panbo%20AIS%20over%20NMEA%202000%20Info%20Sheet.pdf
enum AIS::Nmea0183AisMessages msgType = ais_msg.get_type();
tN2kMsg N2kMsg;

switch(msgType) {
case AIS::AIS_MSG_1_2_3_POS_REPORT_CLASS_A:
{
: 
// lines deleted
: 
}
default:
    break;
}
kimphg commented 7 years ago

I tested the code on my data, when the message is not supported, numericToMessage() return AIS_MSG_MAX but doesnt yield anything about that, then when you try to get data, for example, calling AIS::get_shipname(), it will trigger refference to null pointer exception as long as the AIS_MSG_MAX doesnt reffer to anything in struct AIS::AisParamPosPair* . I added this line when decode and it work fine: if(msgType==AIS_MSG_MAX)return false;// message not supported BTW the message that was not supported in my test data is 19, which is similar to 18, so i will add definenition of message 19 and public the code soon. Anyway, nice work of yours, compact and easy to modify.

KimBP commented 6 years ago

Yes you are absolutely right. I didn't expect anyone to request anything while not knowing the message type. Feel free to make a pull request with your fix and I'll add to the repository. You are of course also welcome to add support for more message types.

kimphg commented 6 years ago

this is the modified code: https://github.com/kimphg/Arduino-AIS

KimBP commented 6 years ago

Well - if you had just chosen to fork my repository you could have made me a pull-request. Instead you have chosen to 're-commit' my work (which I guess in this case is fully valid because I haven't even added a copyright notice) making future synchronization between the two repositories a bit more difficult. I don't have the time right now to isolate your changes but will have it in mind next time I'll work on this project. You are still welcome to generate a pull-reqest if you want to keep the credit for the change(s)

kimphg commented 6 years ago

I was trying to make a pull request but it said i dont have permission. I will delete my repos when i figure out how to do that.

KimBP commented 6 years ago

You fork my repository (fork button) Commit your change, say e.g. the test for Max something. Then you ought be able to make the pull request. Let me know if that fails /Kim Sendt fra min Mobil-------- Oprindelig meddelelse --------Emne: Re: [KimBP/AIS] unsupported message error (#2)Fra: Phuong Phung Til: KimBP/AIS CC: KimBP ,State change I was trying to make a pull request but it said i dont have permission. I will delete my repos when i figure out how to do that.

—You are receiving this because you modified the open/close state.Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/KimBP/AIS","title":"KimBP/AIS","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/KimBP/AIS"}},"updates":{"snippets":[{"icon":"PERSON","message":"@kimphg in #2: I was trying to make a pull request but it said i dont have permission. I will delete my repos when i figure out how to do that."}],"action":{"name":"View Issue","url":"https://github.com/KimBP/AIS/issues/2#issuecomment-337763133"}}}