WPILibC++  unspecified
CAN.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <HAL/CANAPI.h>
13 #include <wpi/ArrayRef.h>
14 
15 #include "ErrorBase.h"
16 
17 namespace frc {
18 struct CANData {
19  uint8_t data[8];
20  int32_t length;
21  uint64_t timestamp;
22 };
23 
34 class CAN : public ErrorBase {
35  public:
40  explicit CAN(int deviceId);
41 
45  ~CAN() override;
46 
54  void WritePacket(const uint8_t* data, int length, int apiId);
55 
66  void WritePacketRepeating(const uint8_t* data, int length, int apiId,
67  int repeatMs);
68 
74  void StopPacketRepeating(int apiId);
75 
85  bool ReadPacketNew(int apiId, CANData* data);
86 
95  bool ReadPacketLatest(int apiId, CANData* data);
96 
106  bool ReadPacketTimeout(int apiId, int timeoutMs, CANData* data);
107 
122  bool ReadPeriodicPacket(int apiId, int timeoutMs, int periodMs,
123  CANData* data);
124 
125  static constexpr HAL_CANManufacturer kTeamManufacturer = HAL_CAN_Man_kTeamUse;
126  static constexpr HAL_CANDeviceType kTeamDeviceType =
127  HAL_CAN_Dev_kMiscellaneous;
128 
129  private:
130  HAL_CANHandle m_handle{HAL_kInvalidHandle};
131 };
132 } // namespace frc
Definition: Utility.cpp:119
High level class for interfacing with CAN devices conforming to the standard CAN spec.
Definition: CAN.h:34
Base class for most objects.
Definition: ErrorBase.h:74
Definition: CAN.h:18