CTRE Phoenix 6 C++ 24.3.0
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 <map>
11#include <memory>
12#include <sstream>
13#include <string>
14
15namespace ctre {
16namespace phoenix6 {
17
18namespace hardware {
19 class ParentDevice;
20}
21
22namespace controls {
23
24 /**
25 * \brief Abstract Control Request class that other control requests extend for use.
26 */
28 {
30 virtual ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) = 0;
31
32 protected:
33 std::string name;
34
35 /* don't allow copy and move of the base class, only derived classes */
36 ControlRequest(ControlRequest const &) = default;
40
41 public:
42 /**
43 * \brief Constructs a new Control Request with the given name.
44 *
45 * \param name Name of the control request
46 */
47 ControlRequest(std::string name) : name{std::move(name)}
48 {
49 }
50
51 std::string const &GetName() const
52 {
53 return name;
54 }
55
56 /**
57 * \brief Gets information about this control request.
58 *
59 * \returns Map of control parameter names and corresponding applied values
60 */
61 virtual std::map<std::string, std::string> GetControlInfo() const = 0;
62
63 virtual ~ControlRequest() = default;
64 virtual std::string ToString() const = 0;
65 };
66
67 /**
68 * \brief Generic Empty Control class used to do nothing.
69 */
71 {
72 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) override
73 {
74 if (req.get() != this)
75 {
76 auto const reqCast = dynamic_cast<EmptyControl *>(req.get());
77 if (reqCast != nullptr)
78 {
79 *reqCast = *this;
80 }
81 else
82 {
83 req = std::make_shared<EmptyControl>(*this);
84 }
85 }
86
87 return c_ctre_phoenix6_RequestControlEmpty(network, deviceHash, 0, cancelOtherRequests);
88 }
89
90 public:
91 /**
92 * \brief Constructs an empty control request.
93 */
94 EmptyControl() : ControlRequest{"EmptyControl"}
95 {
96 }
97
98 /**
99 * \brief Gets information about this control request.
100 *
101 * \returns Map of control parameter names and corresponding applied values
102 */
103 std::map<std::string, std::string> GetControlInfo() const override
104 {
105 std::map<std::string, std::string> controlInfo;
106 controlInfo["Name"] = GetName();
107 return controlInfo;
108 }
109
110 std::string ToString() const override
111 {
112 std::stringstream ss;
113 ss << "class: EmptyControl" << std::endl;
114 return ss.str();
115 }
116 };
117
118}
119
120}
121}
CTREXPORT int c_ctre_phoenix6_RequestControlEmpty(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests)
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
ControlRequest & operator=(ControlRequest &&)=default
ControlRequest & operator=(ControlRequest const &)=default
std::string name
Definition: ControlRequest.hpp:33
std::string const & GetName() const
Definition: ControlRequest.hpp:51
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:47
Generic Empty Control class used to do nothing.
Definition: ControlRequest.hpp:71
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: ControlRequest.hpp:103
EmptyControl()
Constructs an empty control request.
Definition: ControlRequest.hpp:94
std::string ToString() const override
Definition: ControlRequest.hpp:110
Parent class for all devices.
Definition: ParentDevice.hpp:29
Definition: string_util.hpp:15