jgeisler0303 / CANFestivino

Arduino Library Version of CANFestival CANopen Stack
GNU Lesser General Public License v2.1
51 stars 17 forks source link

Problem with s_state_communication struct and StartOrStop macro #1

Open mmrohloff opened 9 years ago

mmrohloff commented 9 years ago

Hi Jens,

I was wondering why the CANFestivino project did't generate bootup-messages. I found out that the StartOrStop macro doesn't work with your memory reduced bitfield version of the s_state_communication struct in states.h so I replaced it with the default CANFestival version. Now everything with the state switch at states.cpp / switchCommunicationState works as expected.

CANFestivino:

typedef struct { INTEGER8 csBoot_Up :1;INTEGER8 csSDO :1;INTEGER8 csEmergency :1;INTEGER8 csSYNC :1;INTEGER8 csLifeGuard :1;INTEGER8 csPDO :1;INTEGER8 csLSS :1; } s_state_communication;

CANFestival:

typedef struct { INTEGER8 csBoot_Up; INTEGER8 csSDO; INTEGER8 csEmergency; INTEGER8 csSYNC; INTEGER8 csLifeGuard; INTEGER8 csPDO; INTEGER8 csLSS; } s_state_communication;

Kind regards Michael

jgeisler0303 commented 9 years ago

Hi Michael, thanks for noting. I don't really know why this happens. Maybe you could try to change the StartOrStop macro like this:

#define StartOrStop(CommType, FuncStart, FuncStop) \
    if(newCommunicationState->CommType && !ObjDict_Data.CurrentCommunicationState.CommType){\
        MSG_WAR(0x9999,#FuncStart, 9999);\
        ObjDict_Data.CurrentCommunicationState.CommType = 1;\
        FuncStart;\
    }else if(!newCommunicationState->CommType && ObjDict_Data.CurrentCommunicationState.CommType){\
        MSG_WAR(0x9999,#FuncStop, 9999);\
        ObjDict_Data.CurrentCommunicationState.CommType = 0;\
        FuncStop;\
    }

I don't have much time right now. Maybe I could try this tomorrow. Cheers

mmrohloff commented 9 years ago

Hi Jens,

it think you already did a great job in reducing the ram usage of canfestival so I don't worry about some more bytes with the default implementation at that part of the software. I didn't have in mind that bitfields of one bit size have in 0 or -1 as value so that was the problem.

Your code works for me and I checked it with many debug messages.

Thanks for the fast response Michael

jgeisler0303 commented 8 years ago

Hi Michael, I just found and fixed a pretty nasty bug in my Timer library that is used by CANFestivino: a stopped Timer would not be stopped immediately but be run one last time. This could lead to very hard to detect strange behaviour. Thought I'd tell you, since you seem to be really using CANFestivino. BTW, may I ask would you use it for?