IOControl/include/IO/RFSwitch/Request.h
Go to the documentation of this file.
1 
22 #pragma once
23 
24 #include <IO/Request.h>
25 #include "Device.h"
26 
27 namespace IO::RFSwitch
28 {
29 class Request : public IO::Request
30 {
31  friend Device;
32  friend Controller;
33 
34 public:
36  {
37  // Only one command applicable, may as well be the default
38  setCommand(Command::set);
39  }
40 
41  const Device& getDevice() const
42  {
43  return static_cast<const Device&>(device);
44  }
45 
46  ErrorCode parseJson(JsonObjectConst json) override;
47 
48  void getJson(JsonObject json) const override;
49 
50  /*
51  * We'll get called with NODES_ALL because no nodes are explicitly specified.
52  */
53  bool setNode(DevNode node) override
54  {
55  return node == DevNode_ALL;
56  }
57 
58  void send(uint32_t code, uint8_t repeats = 0);
59 
60  uint32_t getCode() const
61  {
62  return code;
63  }
64 
66  {
67  return repeats;
68  }
69 
70 protected:
71  void callback()
72  {
73  // No response to interpret here, so we're done
75  }
76 
77 private:
78  uint32_t code{0};
79  uint8_t repeats{0};
80 };
81 
82 } // namespace IO::RFSwitch
Controller for 433MHz transmitter.
Definition: IOControl/include/IO/RFSwitch/Controller.h:38
uint32_t getCode() const
Definition: IOControl/include/IO/RFSwitch/Request.h:60
Device & device
Definition: IOControl/include/IO/Request.h:280
@ success
Definition: Libraries/IOControl/include/IO/Error.h:71
ErrorCode parseJson(JsonObjectConst json) override
Fill this request from a JSON description.
Definition: Libraries/IOControl/include/IO/RFSwitch/Device.h:45
static constexpr DevNode DevNode_ALL
Definition: DevNode.h:53
int16_t ErrorCode
Definition: Libraries/IOControl/include/IO/Error.h:27
Definition: IOControl/include/IO/RFSwitch/Request.h:29
void send(uint32_t code, uint8_t repeats=0)
Request represents a single user request/response over a bus.
Definition: IOControl/include/IO/Request.h:79
Identifies a device node.
Definition: DevNode.h:30
Definition: IOControl/include/IO/Controller.h:25
Handles requests for a specific device; the requests are executed by the relevant controller.
Definition: Libraries/IOControl/include/IO/Device.h:35
Json json
void getJson(JsonObject json) const override
Get result of a completed request in JSON format.
void complete(ErrorCode err)
void setCommand(Command cmd)
Set the command code.
Definition: IOControl/include/IO/Request.h:167
const Device & getDevice() const
Definition: IOControl/include/IO/RFSwitch/Request.h:41
Definition: IOControl/include/IO/RFSwitch/Controller.h:25
void callback()
Definition: IOControl/include/IO/RFSwitch/Request.h:71
uint8_t getRepeats() const
Definition: IOControl/include/IO/RFSwitch/Request.h:65
bool setNode(DevNode node) override
If nodes are supported, implement this method.
Definition: IOControl/include/IO/RFSwitch/Request.h:53
Request(IO::Device &device)
Definition: IOControl/include/IO/RFSwitch/Request.h:35