CTRE Phoenix 6 C++ 25.0.0-beta-4
Loading...
Searching...
No Matches
ControlRequest.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
10#include <units/frequency.h>
11#include <map>
12#include <memory>
13#include <sstream>
14#include <string>
15
16namespace ctre {
17namespace phoenix6 {
18
19namespace hardware {
20 class ParentDevice;
21}
22
23namespace controls {
24
25 /**
26 * \brief Abstract Control Request class that other control requests extend for use.
27 */
29 {
31 virtual ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const = 0;
32
33 protected:
34 std::string name;
35
36 /* don't allow copy and move of the base class, only derived classes */
37 ControlRequest(ControlRequest const &) = default;
41
42 public:
43 /**
44 * \brief Constructs a new Control Request with the given name.
45 *
46 * \param name Name of the control request
47 */
48 ControlRequest(std::string name) : name{std::move(name)}
49 {
50 }
51
52 std::string const &GetName() const
53 {
54 return name;
55 }
56
57 /**
58 * \brief Gets information about this control request.
59 *
60 * \returns Map of control parameter names and corresponding applied values
61 */
62 virtual std::map<std::string, std::string> GetControlInfo() const = 0;
63
64 virtual ~ControlRequest() = default;
65 virtual std::string ToString() const = 0;
66 };
67
68 /**
69 * \brief Generic Empty Control class used to do nothing.
70 */
72 {
73 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
74 {
75 if (req.get() != this)
76 {
77 auto const reqCast = dynamic_cast<EmptyControl *>(req.get());
78 if (reqCast != nullptr)
79 {
80 *reqCast = *this;
81 }
82 else
83 {
84 req = std::make_shared<EmptyControl>(*this);
85 }
86 }
87
88 return c_ctre_phoenix6_RequestControlEmpty(network, deviceHash, 0);
89 }
90
91 public:
92 /**
93 * \brief Constructs an empty control request.
94 */
95 EmptyControl() : ControlRequest{"EmptyControl"}
96 {
97 }
98
99 /**
100 * \brief Gets information about this control request.
101 *
102 * \returns Map of control parameter names and corresponding applied values
103 */
104 std::map<std::string, std::string> GetControlInfo() const override
105 {
106 std::map<std::string, std::string> controlInfo;
107 controlInfo["Name"] = GetName();
108 return controlInfo;
109 }
110
111 std::string ToString() const override
112 {
113 std::stringstream ss;
114 ss << "class: EmptyControl" << std::endl;
115 return ss.str();
116 }
117
118 EmptyControl &WithUpdateFreqHz(units::frequency::hertz_t) { return *this; }
119 };
120
121}
122
123}
124}
CTREXPORT int c_ctre_phoenix6_RequestControlEmpty(const char *canbus, uint32_t ecuEncoding, double updateTime)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:29
ControlRequest & operator=(ControlRequest &&)=default
ControlRequest & operator=(ControlRequest const &)=default
std::string name
Definition ControlRequest.hpp:34
std::string const & GetName() const
Definition ControlRequest.hpp:52
ControlRequest(ControlRequest const &)=default
virtual std::map< std::string, std::string > GetControlInfo() const =0
Gets information about this control request.
ControlRequest(ControlRequest &&)=default
virtual std::string ToString() const =0
ControlRequest(std::string name)
Constructs a new Control Request with the given name.
Definition ControlRequest.hpp:48
Generic Empty Control class used to do nothing.
Definition ControlRequest.hpp:72
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition ControlRequest.hpp:104
EmptyControl & WithUpdateFreqHz(units::frequency::hertz_t)
Definition ControlRequest.hpp:118
EmptyControl()
Constructs an empty control request.
Definition ControlRequest.hpp:95
std::string ToString() const override
Definition ControlRequest.hpp:111
Parent class for all devices.
Definition ParentDevice.hpp:29
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition StatusCodes.h:18
Definition span.hpp:401