robincornelius / libedssharp

A CanOpen EDS editor and library in C# with CanOpenNode export for Object Dictionary
GNU General Public License v3.0
227 stars 134 forks source link

CO_OD.c code including "CO_driver.h" #239

Closed JuPrgn closed 3 years ago

JuPrgn commented 3 years ago

I have an issue with CO_VERSION_MAJOR this is defined in CO_driver.h and also required to include CO_driver.h :

#if CO_VERSION_MAJOR < 2
 #include "CO_driver.h"
 #include "CO_OD.h"
 #include "CO_SDO.h"
#elif CO_VERSION_MAJOR < 4
 #include "301/CO_driver.h"
 #include "CO_OD.h"
 #include "301/CO_SDOserver.h"
#else
 #error This Object dictionary is not compatible with CANopenNode v4.0 and up!
#endif

MPLAB X IDE run the first part < 2 even if CO_VERSION_MAJOR is equal to 2.

Should we find another way to include CO_driver.h / 301/CO_driver.h here ?

CANopenNode commented 3 years ago

It seems, MPLAB really has a problem. It is strange. I just don't like complicate, if only MPLAB compiler has problems. I would make a hack in CO_driver.h for MPLAB and make a comment there. For example, define CO_VERSION_MAJOR as 1. It is not used anywhere else than in CO_OD.c, anyway.

JuPrgn commented 3 years ago

If /301 is added to compiler include path this is fine :

#include "CO_driver.h"
#if CO_VERSION_MAJOR < 2
 #include "CO_OD.h"
 #include "CO_SDO.h"
#elif CO_VERSION_MAJOR < 4
 #include "CO_OD.h"
 #include "301/CO_SDOserver.h"
#else
 #error This Object dictionary is not compatible with CANopenNode v4.0 and up!
#endif
CANopenNode commented 3 years ago

Of course ... my mistake CO_VERSION_MAJOR is defined in CO_driver.h, but #if is one line above the #include.

I think, we can't avoid using special compiler option or manual editing CO_OD.c.

I prefer second solution. However, this has to be used for all tools, not just MPLAB. libedssharo is then Ok as it is. If we use first solutuion, we have to change also all other include directives to make things clean.