WPILibC++ 2023.4.3
CANAPI.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include "hal/CANAPITypes.h"
10#include "hal/Types.h"
11
12/**
13 * @defgroup hal_canapi CAN API Functions
14 * @ingroup hal_capi
15 * @{
16 */
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/**
23 * Initializes a CAN device.
24 *
25 * These follow the FIRST standard CAN layout.
26 * https://docs.wpilib.org/en/stable/docs/software/can-devices/can-addressing.html
27 *
28 * @param[in] manufacturer the can manufacturer
29 * @param[in] deviceId the device ID (0-63)
30 * @param[in] deviceType the device type
31 * @param[out] status Error status variable. 0 on success.
32 * @return the created CAN handle
33 */
34HAL_CANHandle HAL_InitializeCAN(HAL_CANManufacturer manufacturer,
35 int32_t deviceId, HAL_CANDeviceType deviceType,
37
38/**
39 * Frees a CAN device
40 *
41 * @param handle the CAN handle
42 */
44
45/**
46 * Writes a packet to the CAN device with a specific ID.
47 *
48 * This ID is 10 bits.
49 *
50 * @param[in] handle the CAN handle
51 * @param[in] data the data to write (0-8 bytes)
52 * @param[in] length the length of data (0-8)
53 * @param[in] apiId the ID to write (0-1023 bits)
54 * @param[out] status Error status variable. 0 on success.
55 */
57 int32_t length, int32_t apiId, int32_t* status);
58
59/**
60 * Writes a repeating packet to the CAN device with a specific ID.
61 *
62 * This ID is 10 bits.
63 *
64 * The RoboRIO will automatically repeat the packet at the specified interval
65 *
66 * @param[in] handle the CAN handle
67 * @param[in] data the data to write (0-8 bytes)
68 * @param[in] length the length of data (0-8)
69 * @param[in] apiId the ID to write (0-1023)
70 * @param[in] repeatMs the period to repeat in ms
71 * @param[out] status Error status variable. 0 on success.
72 */
74 int32_t length, int32_t apiId,
75 int32_t repeatMs, int32_t* status);
76
77/**
78 * Writes an RTR frame of the specified length to the CAN device with the
79 * specific ID.
80 *
81 * By spec, the length must be equal to the length sent by the other device,
82 * otherwise behavior is unspecified.
83 *
84 * @param[in] handle the CAN handle
85 * @param[in] length the length of data to request (0-8)
86 * @param[in] apiId the ID to write (0-1023)
87 * @param[out] status Error status variable. 0 on success.
88 */
91
92/**
93 * Stops a repeating packet with a specific ID.
94 *
95 * This ID is 10 bits.
96 *
97 * @param[in] handle the CAN handle
98 * @param[in] apiId the ID to stop repeating (0-1023)
99 * @param[out] status Error status variable. 0 on success.
100 */
102 int32_t* status);
103
104/**
105 * Reads a new CAN packet.
106 *
107 * This will only return properly once per packet received. Multiple calls
108 * without receiving another packet will return an error code.
109 *
110 * @param[in] handle the CAN handle
111 * @param[in] apiId the ID to read (0-1023)
112 * @param[out] data the packet data (8 bytes)
113 * @param[out] length the received length (0-8 bytes)
114 * @param[out] receivedTimestamp the packet received timestamp (based off of
115 * CLOCK_MONOTONIC)
116 * @param[out] status Error status variable. 0 on success.
117 */
119 int32_t* length, uint64_t* receivedTimestamp,
120 int32_t* status);
121
122/**
123 * Reads a CAN packet. The will continuously return the last packet received,
124 * without accounting for packet age.
125 *
126 * @param[in] handle the CAN handle
127 * @param[in] apiId the ID to read (0-1023)
128 * @param[out] data the packet data (8 bytes)
129 * @param[out] length the received length (0-8 bytes)
130 * @param[out] receivedTimestamp the packet received timestamp (based off of
131 * CLOCK_MONOTONIC)
132 * @param[out] status Error status variable. 0 on success.
133 */
135 int32_t* length, uint64_t* receivedTimestamp,
136 int32_t* status);
137
138/**
139 * Reads a CAN packet. The will return the last packet received until the
140 * packet is older then the requested timeout. Then it will return an error
141 * code.
142 *
143 * @param[in] handle the CAN handle
144 * @param[in] apiId the ID to read (0-1023)
145 * @param[out] data the packet data (8 bytes)
146 * @param[out] length the received length (0-8 bytes)
147 * @param[out] receivedTimestamp the packet received timestamp (based off of
148 * CLOCK_MONOTONIC)
149 * @param[out] timeoutMs the timeout time for the packet
150 * @param[out] status Error status variable. 0 on success.
151 */
153 uint8_t* data, int32_t* length,
154 uint64_t* receivedTimestamp, int32_t timeoutMs,
155 int32_t* status);
156
157#ifdef __cplusplus
158} // extern "C"
159#endif
160/** @} */
HAL_CANHandle HAL_InitializeCAN(HAL_CANManufacturer manufacturer, int32_t deviceId, HAL_CANDeviceType deviceType, int32_t *status)
Initializes a CAN device.
void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId, uint8_t *data, int32_t *length, uint64_t *receivedTimestamp, int32_t timeoutMs, int32_t *status)
Reads a CAN packet.
void HAL_ReadCANPacketNew(HAL_CANHandle handle, int32_t apiId, uint8_t *data, int32_t *length, uint64_t *receivedTimestamp, int32_t *status)
Reads a new CAN packet.
void HAL_WriteCANPacket(HAL_CANHandle handle, const uint8_t *data, int32_t length, int32_t apiId, int32_t *status)
Writes a packet to the CAN device with a specific ID.
void HAL_CleanCAN(HAL_CANHandle handle)
Frees a CAN device.
void HAL_WriteCANPacketRepeating(HAL_CANHandle handle, const uint8_t *data, int32_t length, int32_t apiId, int32_t repeatMs, int32_t *status)
Writes a repeating packet to the CAN device with a specific ID.
void HAL_ReadCANPacketLatest(HAL_CANHandle handle, int32_t apiId, uint8_t *data, int32_t *length, uint64_t *receivedTimestamp, int32_t *status)
Reads a CAN packet.
void HAL_WriteCANRTRFrame(HAL_CANHandle handle, int32_t length, int32_t apiId, int32_t *status)
Writes an RTR frame of the specified length to the CAN device with the specific ID.
void HAL_StopCANPacketRepeating(HAL_CANHandle handle, int32_t apiId, int32_t *status)
Stops a repeating packet with a specific ID.
HAL_Handle HAL_CANHandle
Definition: Types.h:51
::uint64_t uint64_t
Definition: Meta.h:58
::int32_t int32_t
Definition: Meta.h:57
::uint8_t uint8_t
Definition: Meta.h:52
GHC_FS_API file_status status(const path &p, std::error_code &ec) noexcept
Definition: filesystem.hpp:4892
Definition: format.h:1544