Firmware
Block.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2017 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
40 #pragma once
41 
42 #include <containers/List.hpp>
43 #include <uORB/Publication.hpp>
44 #include <uORB/Subscription.hpp>
46 
47 namespace control
48 {
49 
50 static constexpr uint8_t maxChildrenPerBlock = 100;
51 static constexpr uint8_t maxParamsPerBlock = 110;
52 static constexpr uint8_t maxSubscriptionsPerBlock = 100;
53 static constexpr uint8_t maxPublicationsPerBlock = 100;
54 static constexpr uint8_t blockNameLengthMax = 40;
55 
56 // forward declaration
57 class BlockParamBase;
58 class SuperBlock;
59 
62 class __EXPORT Block : public ListNode<Block *>
63 {
64 public:
65  friend class BlockParamBase;
66 
67  Block(SuperBlock *parent, const char *name);
68  virtual ~Block() = default;
69 
70  // no copy, assignment, move, move assignment
71  Block(const Block &) = delete;
72  Block &operator=(const Block &) = delete;
73  Block(Block &&) = delete;
74  Block &operator=(Block &&) = delete;
75 
76  void getName(char *name, size_t n);
77 
78  virtual void updateParams();
79  virtual void updateSubscriptions();
80  virtual void updatePublications();
81 
82  virtual void setDt(float dt) { _dt = dt; }
83  float getDt() { return _dt; }
84 
85 protected:
86 
87  virtual void updateParamsSubclass() {}
88 
89  SuperBlock *getParent() { return _parent; }
90  List<uORB::SubscriptionNode *> &getSubscriptions() { return _subscriptions; }
91  List<uORB::PublicationNode *> &getPublications() { return _publications; }
92  List<BlockParamBase *> &getParams() { return _params; }
93 
94  const char *_name;
95  SuperBlock *_parent;
96  float _dt{0.0f};
97 
98  List<uORB::SubscriptionNode *> _subscriptions;
99  List<uORB::PublicationNode *> _publications;
100  List<BlockParamBase *> _params;
101 };
102 
104  public Block
105 {
106 public:
107  friend class Block;
108 
109  SuperBlock(SuperBlock *parent, const char *name) : Block(parent, name) {}
110  ~SuperBlock() = default;
111 
112  // no copy, assignment, move, move assignment
113  SuperBlock(const SuperBlock &) = delete;
114  SuperBlock &operator=(const SuperBlock &) = delete;
115  SuperBlock(SuperBlock &&) = delete;
116  SuperBlock &operator=(SuperBlock &&) = delete;
117 
118  void setDt(float dt) override;
119 
120  void updateParams() override
121  {
122  Block::updateParams();
123 
124  if (getChildren().getHead() != nullptr) { updateChildParams(); }
125  }
126 
127  void updateSubscriptions() override
128  {
129  Block::updateSubscriptions();
130 
131  if (getChildren().getHead() != nullptr) { updateChildSubscriptions(); }
132  }
133  void updatePublications() override
134  {
135  Block::updatePublications();
136 
137  if (getChildren().getHead() != nullptr) { updateChildPublications(); }
138  }
139 
140 protected:
141  List<Block *> &getChildren() { return _children; }
142  void updateChildParams();
143  void updateChildSubscriptions();
144  void updateChildPublications();
145 
146  List<Block *> _children;
147 };
148 
149 
150 } // namespace control
Definition: BlockParam.hpp:54
An intrusive linked list.
Definition: List.hpp:45
Controller library code.
Definition: Block.hpp:62
Definition: Block.hpp:103
Definition: List.hpp:59
Definition: I2C.hpp:51
Definition: blocks.cpp:46