CAN attach in cpp

27 Jul 2011

I have found that the overloaded "attach" member function of mbed::CAN is not actually implemented in the library and reports...

Quote:

Undefined symbol mbed::CAN::attach<CAN_Interface>(T1*, void(T1::*)())

I am a C++ novice but i think this is a bug some where i have published an exampled project here http://mbed.org/users/chrispearce1972/programs/can_test/luz4y5 but basically looks like this...

class CAN_stack
{
    private:
    CAN* adapter;   
    void can_callback ( void );
    
    public:
    CAN_stack(CAN* can_int);  
    void poll (void);
    
}

CAN_stack::CAN_stack(CAN* can_int)
{
    adapter=can_int;
    adapter->attach(this, &CAN_stack::can_callback);
}

void CAN_stack::poll (void)
{
    /*
        pop fifo and do stuff        
    */ 
}

void CAN_stack::can_callback ( void )
{
    CANMessage msg;
    adapter->read(msg);
    /*
        push msg to fifo etc
    */
}

The error occurs on the

    adapter->attach(this, &CAN_stack::can_callback);

line, and im unsure as to why???

27 Jul 2011

Hi Chris,

Yep, that's a bug. Thanks for the great report; it has been ticketed, and tracked down. We'll get a fix release out in the next couple of days.

In the mean time, normal functions (vs member functions) will work, so I hope you can use that as a workaround while we fix it.

Thanks again!

Simon

28 Jul 2011

Great thanks, thats that mystery solved. I have a work around involving a global fifo and reference to the CAN adapter for the time being as im only using one adapter at the moment that allows me to continue the developemnt. I look forward to the update...

28 Jul 2011

Hi Chris,

There is now a beta library with this fix. If you delete the "mbed" library from your project, and then choose "Import Library..." and use the url:

  • http://mbed.org/projects/libraries-testing/svn/beta

Hopefully you should get the behaviour you were expecting.

Please report back!

Simon

02 Aug 2011

Yes thankyou Simon, I now get what i would expect and the call back fires correctly... ive published the revised SW here http://mbed.org/users/chrispearce1972/programs/can_test/lvaqkb with LED toggles round the received CAN message.... thanks again for your quick response...

09 Jan 2012

When will the CAN library go from beta to stable?

09 Jan 2012

Also,

I imported the new library ( I think ) and I'm still getting linking errors for my program:

"Undefined symbol mbed::CAN::attach(T1*,void(T1::*)()) (referred from SensorNode.cpp.cpp.LPC1768.o)."

If anyone could take a look at what I've got ( http://mbed.org/users/wsalis01/programs/ ) the extra eyes would help...the only difference I can see between Chris' and my code is that I'm using an initializer list where he passes in a 'new'd CAN object to his constructor...which I can't see as related...unless the objects haven't been instantiated in the body of the constructor.

10 Jan 2012

I was running library beta V29 (hvant touched my project for a while) which compiled ok, imported your project and confirmed your compile error. Upgraded my library file to V38 and i now get the same link error in my project using V38.... :-( so looks like a mistake in the library! Can you report it as an bug?! thanks in advance....

10 Jan 2012

Will Salisbury wrote:

When will the CAN library go from beta to stable?

Now: http://mbed.org/projects/libraries/svn/mbed/trunk?rev=35

Cheers, Emilio

10 Jan 2012

I presume this has does not have the bug Will identified yesterday ?

10 Jan 2012

Chris Pearce wrote:

I presume this has does not have the bug Will identified yesterday ?

The template is now defined in the header. This should have resolved the undefined symbol error.

10 Jan 2012

Just updated to main SVN trunk, compiled and it's linking correctly now. I'll update the software in my system and make sure it's working within the week.

Edit: Thanks!