PX4 Firmware
PX4 Autopilot Software http://px4.io
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 
34 /**
35  * @file Block.hpp
36  *
37  * Controller library code
38  */
39 
40 #pragma once
41 
42 #include <containers/List.hpp>
44 #include <cstdint>
45 
46 namespace control
47 {
48 
49 static constexpr uint8_t maxChildrenPerBlock = 100;
50 static constexpr uint8_t maxParamsPerBlock = 110;
51 static constexpr uint8_t blockNameLengthMax = 40;
52 
53 // forward declaration
54 class BlockParamBase;
55 class SuperBlock;
56 
57 /**
58  */
59 class __EXPORT Block : public ListNode<Block *>
60 {
61 public:
62  friend class BlockParamBase;
63 
64  Block(SuperBlock *parent, const char *name);
65  virtual ~Block() = default;
66 
67  // no copy, assignment, move, move assignment
68  Block(const Block &) = delete;
69  Block &operator=(const Block &) = delete;
70  Block(Block &&) = delete;
71  Block &operator=(Block &&) = delete;
72 
73  void getName(char *name, size_t n);
74 
75  virtual void updateParams();
76 
77  virtual void setDt(float dt) { _dt = dt; }
78  float getDt() { return _dt; }
79 
80 protected:
81 
82  virtual void updateParamsSubclass() {}
83 
84  SuperBlock *getParent() { return _parent; }
85  List<BlockParamBase *> &getParams() { return _params; }
86 
87  const char *_name;
89  float _dt{0.0f};
90 
92 };
93 
95  public Block
96 {
97 public:
98  friend class Block;
99 
100  SuperBlock(SuperBlock *parent, const char *name) : Block(parent, name) {}
101  ~SuperBlock() = default;
102 
103  // no copy, assignment, move, move assignment
104  SuperBlock(const SuperBlock &) = delete;
105  SuperBlock &operator=(const SuperBlock &) = delete;
106  SuperBlock(SuperBlock &&) = delete;
107  SuperBlock &operator=(SuperBlock &&) = delete;
108 
109  void setDt(float dt) override;
110 
111  void updateParams() override
112  {
114 
115  if (getChildren().getHead() != nullptr) { updateChildParams(); }
116  }
117 
118 protected:
119  List<Block *> &getChildren() { return _children; }
120  void updateChildParams();
121 
123 };
124 
125 
126 } // namespace control
const char * _name
Definition: Block.hpp:87
virtual void updateParamsSubclass()
Definition: Block.hpp:82
static constexpr uint8_t maxParamsPerBlock
Definition: Block.hpp:50
float getDt()
Definition: Block.hpp:78
List< BlockParamBase * > _params
Definition: Block.hpp:91
void updateParams() override
Definition: Block.hpp:111
Definition: I2C.hpp:51
An intrusive linked list.
List< Block * > _children
Definition: Block.hpp:122
virtual void setDt(float dt)
Definition: Block.hpp:77
Definition: List.hpp:59
static constexpr uint8_t maxChildrenPerBlock
Definition: Block.hpp:49
List< Block * > & getChildren()
Definition: Block.hpp:119
static constexpr uint8_t blockNameLengthMax
Definition: Block.hpp:51
Controller library code.
const char * name
Definition: tests_main.c:58
SuperBlock * _parent
Definition: Block.hpp:88
SuperBlock(SuperBlock *parent, const char *name)
Definition: Block.hpp:100
float dt
Definition: px4io.c:73
virtual void updateParams()
Definition: Block.cpp:79
SuperBlock * getParent()
Definition: Block.hpp:84
List< BlockParamBase * > & getParams()
Definition: Block.hpp:85