MySensors Library & Examples  2.3.2-62-ge298769
Any.h
1 
2 /* Any strategy
3  This strategy includes virtual inheritance and let a PJON object switch
4  from a strategy to another when required or a collection of PJON objects
5  with different strategies to be treated dynamically.
6 
7  Proposed and developed by Fred Larsen
8  ___________________________________________________________________________
9 
10  Copyright 2010-2020 Giovanni Blu Mitolo [email protected]
11 
12  Licensed under the Apache License, Version 2.0 (the "License");
13  you may not use this file except in compliance with the License.
14  You may obtain a copy of the License at
15 
16  http://www.apache.org/licenses/LICENSE-2.0
17 
18  Unless required by applicable law or agreed to in writing, software
19  distributed under the License is distributed on an "AS IS" BASIS,
20  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  See the License for the specific language governing permissions and
22  limitations under the License. */
23 
24 #pragma once
25 
26 #include "StrategyLinkBase.h"
27 #include "StrategyLink.h"
28 
29 class Any
30 {
31 public:
32  StrategyLinkBase *s = NULL;
33 
34  /* Set a pointer to the StrategyLink to be used.
35  It will not be freed by this class: */
36 
37  void set_link(StrategyLinkBase *strategy_link)
38  {
39  s = strategy_link;
40  }
41 
42 
43  /* Returns delay related to the attempts passed as parameter: */
44 
45  uint32_t back_off(uint8_t attempts)
46  {
47  return s->back_off(attempts);
48  }
49 
50 
51  /* Begin method, to be called on initialization: */
52 
53  bool begin(uint8_t did = 0)
54  {
55  return s->begin(did);
56  }
57 
58 
59  /* Check if the channel is free for transmission */
60 
61  bool can_start()
62  {
63  return s->can_start();
64  };
65 
66 
67  /* Returns the maximum number of attempts for each transmission: */
68 
69  uint8_t get_max_attempts()
70  {
71  return s->get_max_attempts();
72  }
73 
74 
75  /* Returns the recommended receive time for this strategy: */
76 
77  uint16_t get_receive_time()
78  {
79  return s->get_receive_time();
80  }
81 
82 
83  /* Handle a collision: */
84 
85  void handle_collision()
86  {
87  s->handle_collision();
88  };
89 
90 
91  /* Receive a frame: */
92 
93  uint16_t receive_frame(uint8_t *data, uint16_t max_length)
94  {
95  return s->receive_frame(data, max_length);
96  }
97 
98 
99  /* Receive byte response: */
100 
101  uint16_t receive_response()
102  {
103  return s->receive_response();
104  }
105 
106 
107  /* Send byte response to package transmitter: */
108 
109  void send_response(uint8_t response)
110  {
111  s->send_response(response);
112  }
113 
114 
115  /* Send a frame: */
116 
117  void send_frame(uint8_t *data, uint16_t length)
118  {
119  s->send_frame(data, length);
120  }
121 };
data
char data[MAX_PAYLOAD_SIZE+1]
Buffer for raw payload data.
Definition: MyMessage.h:654
StrategyLinkBase
Definition: StrategyLinkBase.h:23
Any
Definition: Any.h:29