Skip to content
Snippets Groups Projects
Commit 3d6792c0 authored by Daniel Agar's avatar Daniel Agar Committed by Lorenz Meier
Browse files

Block and SuperBlock minor cleanup

parent 1671c322
No related branches found
No related tags found
No related merge requests found
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
* Copyright (C) 2012-2017 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -37,25 +37,20 @@
* Controller library code
*/
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "Block.hpp"
#include "BlockParam.hpp"
#include <cstring>
#include <uORB/Subscription.hpp>
#include <uORB/Publication.hpp>
#include "Block.hpp"
#include "BlockParam.hpp"
namespace control
{
Block::Block(SuperBlock *parent, const char *name) :
_name(name),
_parent(parent),
_dt(0)
_parent(parent)
{
if (getParent() != nullptr) {
getParent()->getChildren().add(this);
......@@ -93,7 +88,7 @@ void Block::updateParams()
if (count++ > maxParamsPerBlock) {
char name[blockNameLengthMax];
getName(name, blockNameLengthMax);
printf("exceeded max params for block: %s\n", name);
PX4_ERR("exceeded max params for block: %s", name);
break;
}
......@@ -112,7 +107,7 @@ void Block::updateSubscriptions()
if (count++ > maxSubscriptionsPerBlock) {
char name[blockNameLengthMax];
getName(name, blockNameLengthMax);
printf("exceeded max subscriptions for block: %s\n", name);
PX4_ERR("exceeded max subscriptions for block: %s", name);
break;
}
......@@ -130,7 +125,7 @@ void Block::updatePublications()
if (count++ > maxPublicationsPerBlock) {
char name[blockNameLengthMax];
getName(name, blockNameLengthMax);
printf("exceeded max publications for block: %s\n", name);
PX4_ERR("exceeded max publications for block: %s", name);
break;
}
......@@ -149,7 +144,7 @@ void SuperBlock::setDt(float dt)
if (count++ > maxChildrenPerBlock) {
char name[blockNameLengthMax];
getName(name, blockNameLengthMax);
printf("exceeded max children for block: %s\n", name);
PX4_ERR("exceeded max children for block: %s", name);
break;
}
......@@ -167,7 +162,7 @@ void SuperBlock::updateChildParams()
if (count++ > maxChildrenPerBlock) {
char name[blockNameLengthMax];
getName(name, blockNameLengthMax);
printf("exceeded max children for block: %s\n", name);
PX4_ERR("exceeded max children for block: %s", name);
break;
}
......@@ -185,7 +180,7 @@ void SuperBlock::updateChildSubscriptions()
if (count++ > maxChildrenPerBlock) {
char name[blockNameLengthMax];
getName(name, blockNameLengthMax);
printf("exceeded max children for block: %s\n", name);
PX4_ERR("exceeded max children for block: %s", name);
break;
}
......@@ -203,7 +198,7 @@ void SuperBlock::updateChildPublications()
if (count++ > maxChildrenPerBlock) {
char name[blockNameLengthMax];
getName(name, blockNameLengthMax);
printf("exceeded max children for block: %s\n", name);
PX4_ERR("exceeded max children for block: %s", name);
break;
}
......@@ -212,7 +207,6 @@ void SuperBlock::updateChildPublications()
}
}
} // namespace control
template class List<uORB::SubscriptionNode *>;
......
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
* Copyright (C) 2012-2017 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -32,16 +32,13 @@
****************************************************************************/
/**
* @file Block.h
* @file Block.hpp
*
* Controller library code
*/
#pragma once
#include <stdint.h>
#include <inttypes.h>
#include <containers/List.hpp>
#include <uORB/Publication.hpp>
#include <uORB/Subscription.hpp>
......@@ -50,11 +47,11 @@
namespace control
{
static const uint16_t maxChildrenPerBlock = 100;
static const uint16_t maxParamsPerBlock = 100;
static const uint16_t maxSubscriptionsPerBlock = 100;
static const uint16_t maxPublicationsPerBlock = 100;
static const uint8_t blockNameLengthMax = 40;
static constexpr uint8_t maxChildrenPerBlock = 100;
static constexpr uint8_t maxParamsPerBlock = 100;
static constexpr uint8_t maxSubscriptionsPerBlock = 100;
static constexpr uint8_t maxPublicationsPerBlock = 100;
static constexpr uint8_t blockNameLengthMax = 40;
// forward declaration
class BlockParamBase;
......@@ -62,39 +59,43 @@ class SuperBlock;
/**
*/
class __EXPORT Block :
public ListNode<Block *>
class __EXPORT Block : public ListNode<Block *>
{
public:
friend class BlockParamBase;
// methods
Block(SuperBlock *parent, const char *name);
virtual ~Block() = default;
// no copy, assignment, move, move assignment
Block(const Block &) = delete;
Block &operator=(const Block &) = delete;
Block(Block &&) = delete;
Block &operator=(Block &&) = delete;
void getName(char *name, size_t n);
virtual ~Block() {};
virtual void updateParams();
virtual void updateSubscriptions();
virtual void updatePublications();
virtual void setDt(float dt) { _dt = dt; }
// accessors
float getDt() { return _dt; }
protected:
// accessors
SuperBlock *getParent() { return _parent; }
List<uORB::SubscriptionNode *> &getSubscriptions() { return _subscriptions; }
List<uORB::PublicationNode *> &getPublications() { return _publications; }
List<BlockParamBase *> &getParams() { return _params; }
// attributes
const char *_name;
SuperBlock *_parent;
float _dt;
float _dt{0.0f};
List<uORB::SubscriptionNode *> _subscriptions;
List<uORB::PublicationNode *> _publications;
List<BlockParamBase *> _params;
private:
/* this class has pointer data members and should not be copied (private constructor) */
Block(const control::Block &);
Block operator=(const control::Block &);
};
class __EXPORT SuperBlock :
......@@ -102,35 +103,44 @@ class __EXPORT SuperBlock :
{
public:
friend class Block;
// methods
SuperBlock(SuperBlock *parent, const char *name) : Block(parent, name) {}
virtual ~SuperBlock() {};
virtual void setDt(float dt);
virtual void updateParams()
SuperBlock(SuperBlock *parent, const char *name) : Block(parent, name) {};
~SuperBlock() = default;
// no copy, assignment, move, move assignment
SuperBlock(const SuperBlock &) = delete;
SuperBlock &operator=(const SuperBlock &) = delete;
SuperBlock(SuperBlock &&) = delete;
SuperBlock &operator=(SuperBlock &&) = delete;
void setDt(float dt) override;
void updateParams() override
{
Block::updateParams();
if (getChildren().getHead() != nullptr) { updateChildParams(); }
}
virtual void updateSubscriptions()
void updateSubscriptions() override
{
Block::updateSubscriptions();
if (getChildren().getHead() != nullptr) { updateChildSubscriptions(); }
}
virtual void updatePublications()
void updatePublications() override
{
Block::updatePublications();
if (getChildren().getHead() != nullptr) { updateChildPublications(); }
}
protected:
// methods
List<Block *> &getChildren() { return _children; }
void updateChildParams();
void updateChildSubscriptions();
void updateChildPublications();
// attributes
List<Block *> _children;
};
......
......@@ -77,7 +77,7 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref
_handle = param_find(fullname);
if (_handle == PARAM_INVALID) {
PX4_ERR("error finding param: %s\n", fullname);
PX4_ERR("error finding param: %s", fullname);
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment