1
0
Fork 0
CANopenNode/stack/neuberger-socketCAN/CO_notify_pipe.c
Martin Wagner c46a2edd57 Add Linux socketCAN driver for CANopen manager application
This driver is more sophisticated than the normal socketCAN driver. Compared
to the normal socketCAN driver, this one contains the linking exception license.

Changes compared to normal socketCAN driver:
- Re-implementation based on driver template
- Error detection works
- Setting up filters works properly
- Optional Support for socketCAN error frames. This currently handles bus-off
  and no-ack condition by setting driver into listen-only mode. If you decide
  to use this feature have a close look at your own requirements and fit
  error handling functions to that.
- Optional support for CAN interface combining (not redundancy!). With this
  feature enabled you can have multiple CAN interface represented as one within
  CANopenNode stack. By default, all TX messages are sent on all used CAN
  interfaces, but the user can change this behaviour inside own app (e.g. check
  on wich bus rx-sdo is received and set-up tx-sdo accordingly).
  Be aware that no bridging between the interfaces is done!
2019-05-10 09:52:11 +02:00

60 lines
1,005 B
C

/* Snipped from https://stackoverflow.com/a/2486353 */
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
#include "CO_notify_pipe.h"
struct CO_NotifyPipe {
int m_receiveFd;
int m_sendFd;
};
CO_NotifyPipe_t *CO_NotifyPipeCreate(void)
{
int pipefd[2];
CO_NotifyPipe_t *p;
int ret = pipe(pipefd);
if (ret < 0) {
return NULL;
}
p = calloc(1, sizeof(CO_NotifyPipe_t));
if (p == NULL) {
return NULL;
}
p->m_receiveFd = pipefd[0];
p->m_sendFd = pipefd[1];
fcntl(p->m_sendFd,F_SETFL,O_NONBLOCK);
return p;
}
void CO_NotifyPipeFree(CO_NotifyPipe_t *p)
{
if (p == NULL) {
return;
}
close(p->m_sendFd);
close(p->m_receiveFd);
free(p);
}
int CO_NotifyPipeGetFd(CO_NotifyPipe_t *p)
{
if (p == NULL) {
return -1;
}
return p->m_receiveFd;
}
void CO_NotifyPipeSend(CO_NotifyPipe_t *p)
{
if (p == NULL) {
return;
}
write(p->m_sendFd,"1",1);
}