socketcan.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2016-2018 UAVCAN Team
  3. *
  4. * Distributed under the MIT License, available in the file LICENSE.
  5. *
  6. */
  7. #ifndef SOCKETCAN_H
  8. #define SOCKETCAN_H
  9. #include <canard.h>
  10. #ifdef __cplusplus
  11. extern "C"
  12. {
  13. #endif
  14. typedef struct
  15. {
  16. int fd;
  17. } SocketCANInstance;
  18. /**
  19. * Initializes the SocketCAN instance.
  20. * Returns 0 on success, negative on error.
  21. */
  22. int16_t socketcanInit(SocketCANInstance* out_ins, const char* can_iface_name);
  23. /**
  24. * Deinitializes the SocketCAN instance.
  25. * Returns 0 on success, negative on error.
  26. */
  27. int16_t socketcanClose(SocketCANInstance* ins);
  28. /**
  29. * Transmits a CanardCANFrame to the CAN socket.
  30. * Use negative timeout to block infinitely.
  31. * Returns 1 on successful transmission, 0 on timeout, negative on error.
  32. */
  33. int16_t socketcanTransmit(SocketCANInstance* ins, const CanardCANFrame* frame, int32_t timeout_msec);
  34. /**
  35. * Receives a CanardCANFrame from the CAN socket.
  36. * Use negative timeout to block infinitely.
  37. * Returns 1 on successful reception, 0 on timeout, negative on error.
  38. */
  39. int16_t socketcanReceive(SocketCANInstance* ins, CanardCANFrame* out_frame, int32_t timeout_msec);
  40. /**
  41. * Returns the file descriptor of the CAN socket.
  42. * Can be used for external IO multiplexing.
  43. */
  44. int socketcanGetSocketFileDescriptor(const SocketCANInstance* ins);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif