dsuarezv / mavlink.net

A better MavLink object generation for C#. Richer message classes are generated from the object definitions.
39 stars 35 forks source link

Generation breaks with multiple include files #11

Closed mthiffau closed 9 years ago

mthiffau commented 9 years ago

To be fair, the stock mavlink generator breaks on multiple include files unless you go into mavgen.py and change DEFAULT_VALIDATE to False.

This is what I get when I add a second include file: Error in [.\mavlink\message_definitions\v1.0.xml]: An item with the same key has already been added.

If there's an easy way to fix this I'd be super appreciative if you would. I'd take a look myself, but to be honest I don't have time. If you don't I can just go back to working with the normal generator, it will just be a pain in the ass to do everything else :P.

If you're interested. I'm working on a multispectral UAV camera which unfortunately has to run windows 8 embedded due to a lack of linux driver support for the individual camera modules we're putting together to make it (and they seem to be the best hardware available for what we're trying to do). The APM, the flight management computer and the camera computer will all speak mavlink, so ideally I'd like to have my dialect (with camera specific messages) include both ardupilotmega.xml and common.xml.

Thanks for writing this, it's really great despite the little problem I ran into.

dsuarezv commented 9 years ago

Looks a lot like there is a message definition that is duplicated in some of the files that you are including.

Can you provide a minimum sample of the files that reproduce the issue?

That or a stack trace would really help narrowing down the problem.

Cheers!

mthiffau commented 9 years ago

I've pasted the file I'm trying to use here: http://pastebin.com/CT3xmjZL

The stuff I added is pretty simple, I don't think it's the problem but if it is my apologies. The two files it's including are straight from the mavlink repository, and one typically includes the other (ardupilotmega includes common), so I don't know how it could be that.

The verification step in mavlink's generator seems to expect no more than two tag segments, which is violated if you declare messages and then include two files which do likewise. They made an assumption which is valid almost 100% of the time. I just had to go ruin it :P.

dsuarezv commented 9 years ago

I'm not on a computer now, but will take a look later.

dsuarezv commented 9 years ago

Can leave out common.XML from your file so it is included by ardupilptmega? Maybe that's the one being included twice

mthiffau commented 9 years ago

Did you write your parser to handle recursive includes? That would be sweet, but the stock generator definitely doesn't handle this (I've compared the generated output, for the python anyways). Worst case I can use different xml files on either end, one with recursive includes for mavlink.net and one with a double include for the linux/python side. Can you confirm that your code will do recursive includes? Don't worry if it doesn't detect cycles, I'll be careful not to make it blow up in my face.

dsuarezv commented 9 years ago

Just tested with our sample and get the exception. The offending message is heartbeat, and the cause is that common.xml is included twice, once from your file and again in ardupilotmega.xml.

Removing the include for common.xml in your file avoids the issue and everything is generated ok.

The generator could prevent cycles in recursive includes easily, just adding a list of "visited" includes and skipping if one is found that has been already processed.