Skip to content
Advertisement

Can-Bus Communication – MSG-Structure (WinUser.h) Linux equivalent

Hello StackOverflow Community

I’ve searched for quite a while now but I don’t find a solution for my problem. I’m working on a project right now, where I have to port a Windows tool on to a Linux operating system (Ubuntu 12.04LTS to be specific). The Windows-based tool is written in C++ and therefore I’m trying to rewrite the Tool in C++ on Linux. The problem I’m facing at the moment is, that in the Windows Solution there is a part where it uses ‘MSG’. Here the Code Snippet from the Windows Solution:

/** Callback to send CAN message */
#define CB_SEND_MSG( MSG )          CanWriteCB( MSG )

I already have implemented the CanWriteCB Method but I did not find a Linux equivalent to ‘MSG’. I found the declaration of MSG in the Windows tool in the include file ‘WinUser.h’. This looks as follows:

/*
 * Message structure
 */
typedef struct tagMSG {
    HWND        hwnd;
    UINT        message;
    WPARAM      wParam;
    LPARAM      lParam;
    DWORD       time;
    POINT       pt;
#ifdef _MAC
    DWORD       lPrivate;
#endif
} MSG, *PMSG, NEAR *NPMSG, FAR *LPMSG;

I do not know if it helps you but here is also the implementation of the ‘CanWriteCB’ method:

boolean_t CanWriteCB( Can_Msg *msg )
{
    return (CanDispatcher_SendMsgByCanBus( msg ) == CanDisp_Err_Ok ) ? TRUE : FALSE;
}

const Det_Config detCfg = 
{
WriteDebugErrorData
};

Has anybody an idea about how to achieve this structure on a Linux platform? The only thing I found was how to create a Message Queue but I don’t know how this will help me at all?

Thank you for your time

Best regards Alex

Advertisement

Answer

The MSG you mentioned is a macro argument, and is unrelated to struct tagMSG at all.

Linux has CAN support using SocketCAN which implement socket interface for the CAN bus, and supports various HW devices. The closest thing to CAN message structure there is struct can_frame.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement