Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
/debug_cli/doc/html
6 changes: 3 additions & 3 deletions debug_cli/DbgCliCommand.cpp → DbgCliCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* Author: niklausd
*/

#include <DbgCliCommand.h>
#include "DbgCliCommand.h"

#ifdef ARDUINO
#include <Arduino.h>
#else
#include <stdio.h>
#endif

DbgCli_Command::DbgCli_Command(const char* parentPath, const char* nodeName, const char* helpText)
: DbgCli_Node(parentPath, nodeName, helpText)
DbgCli_Command::DbgCli_Command(DbgCli_Node* parentNode, const char* nodeName, const char* helpText)
: DbgCli_Node(parentNode, nodeName, helpText)
{ }

DbgCli_Command::~DbgCli_Command()
Expand Down
10 changes: 5 additions & 5 deletions debug_cli/DbgCliCommand.h → DbgCliCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef PLAT_DEBUG_CLI_DBGCLICOMMAND_H_
#define PLAT_DEBUG_CLI_DBGCLICOMMAND_H_

#include <DbgCliNode.h>
#include "DbgCliNode.h"

/**
* Composite Pattern: Abstract Command Class, acts as the leaf node of the tree, has to be implemented by the client.
Expand All @@ -18,11 +18,11 @@ class DbgCli_Command: public DbgCli_Node
public: // abstract class - constructor must not be accessible
/**
* Constructor for a leaf node in the Command tree.
* @param parentPath Parent path string, each token is space separated.
* @param parentNode Pointer to the parent node, to add the newly created command.
* @param nodeName Name of this node (this becomes a part of the command path / tree).
* @param helpText Help and usage string.
*/
DbgCli_Command(const char* parentPath, const char* nodeName, const char* helpText);
DbgCli_Command(DbgCli_Node* parentNode, const char* nodeName, const char* helpText);

public:
/**
Expand All @@ -33,8 +33,8 @@ class DbgCli_Command: public DbgCli_Node
/**
* Execute the debug command.
* Pure virtual method, to be implemented by the client application.
* @param argc
* @param args
* @param argc number of elements in args
* @param args all arguments stored in an array
* @param idxToFirstArgToHandle Index to the first argument in args array to be handled as parameter (this is the first parameter to be passed to the method that gets called by this command)
*/
virtual void execute(unsigned int argc, const char** args, unsigned int idxToFirstArgToHandle);
Expand Down
127 changes: 127 additions & 0 deletions DbgCliNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* DbgCliNode.cpp
*
* Created on: 11.02.2015
* Author: niklausd
*/

#include "DbgCliTopic.h"
#include "DbgCliNode.h"
#include <string.h>

#define MAX_TREE_HEIGHT 7
#define MAX_PATH_LEGTH 50
#define MAX_NODE_NAME_LENGTH 15
#define PATH_DELIMITERS " /.-"

DbgCli_Node* DbgCli_Node::s_rootNode = 0;

void DbgCli_Node::AssignRootNode(DbgCli_Node* rootNode)
{
s_rootNode = rootNode;
}

DbgCli_Node* DbgCli_Node::RootNode()
{
return s_rootNode;
}

DbgCli_Node* DbgCli_Node::getNode(const char* parentPath, const char* nodeName)
{
char str[MAX_PATH_LEGTH];
char parentPathTokens[MAX_TREE_HEIGHT][MAX_NODE_NAME_LENGTH];
char* token;
unsigned int nbrOfTokens = 0;

// split parent path to its nodes
strncpy(str, parentPath, MAX_PATH_LEGTH);
token = strtok(str, PATH_DELIMITERS);
while (0 != token)
{
strncpy(parentPathTokens[nbrOfTokens], token, MAX_NODE_NAME_LENGTH);
nbrOfTokens++;
token = strtok(0, PATH_DELIMITERS);
}

if (0 != strncmp(nodeName,"\0",MAX_NODE_NAME_LENGTH))
{
// add nodeName to tokens, if parameter is used
strncpy(parentPathTokens[nbrOfTokens], nodeName, MAX_NODE_NAME_LENGTH);
nbrOfTokens++;
}

unsigned int tokenIterator = 0; // range: 0..nbrOfTokens-1
DbgCli_Node* tmpNode = DbgCli_Node::RootNode();

if ((0 != tmpNode) && (0 != strncmp(tmpNode->getNodeName(), parentPathTokens[tokenIterator], MAX_NODE_NAME_LENGTH)))
{
// Root node not found, brake!
return 0;
}
else
{
tokenIterator++;
DbgCli_Node* nextNode;
while (tokenIterator < nbrOfTokens)
{
// get next node
nextNode = tmpNode->getChildNode(parentPathTokens[tokenIterator]);
if (0 != nextNode)
{
tmpNode = nextNode;
tokenIterator++;
}
else
{
return 0;
}
}
return tmpNode;
}
}

DbgCli_Node::DbgCli_Node(DbgCli_Node* parentNode, const char* nodeName, const char* helpText)
: m_parentNode(parentNode)
, m_nodeName(nodeName)
, m_helpText(helpText)
, m_sibling(0)
{
DbgCli_Node* rootNode = DbgCli_Node::RootNode();
if (0 != rootNode) // not possible to add nodes, without root node
{
if (0 != m_parentNode)
{
DbgCli_Topic* parentTopic = static_cast<DbgCli_Topic*>(m_parentNode);
parentTopic->addChildNode(this);
}
}
}

DbgCli_Node::~DbgCli_Node()
{
if (0 != m_parentNode)
{
DbgCli_Topic* parentTopic = static_cast<DbgCli_Topic*>(m_parentNode);
parentTopic->removeChildNode(this);
}
}

const char* DbgCli_Node::getNodeName()
{
return m_nodeName;
}

const char* DbgCli_Node::getHelpText()
{
return m_helpText;
}

DbgCli_Node* DbgCli_Node::getNextSibling()
{
return m_sibling;
}

void DbgCli_Node::setNextSibling(DbgCli_Node* nextSibling)
{
m_sibling = nextSibling;
}
45 changes: 34 additions & 11 deletions debug_cli/DbgCliNode.h → DbgCliNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
#ifndef PLAT_DEBUG_CLI_DBGCLINODE_H_
#define PLAT_DEBUG_CLI_DBGCLINODE_H_


/**
* Composite Pattern: Abstract Node Class, acts as the Interface to the object tree.
*/
class DbgCli_Node
{
protected: // abstract class - constructor must not be accessible
DbgCli_Node(const char* parentPath, const char* nodeName, const char* helpText);
protected: /// abstract class - constructor must not be accessible
DbgCli_Node(DbgCli_Node* parentNode, const char* nodeName, const char* helpText);

public:
virtual ~DbgCli_Node();

public:
/**
* Add a node to the tree.
* Location is given by the parentPath set for the node.
* @param node Pointer to the node to be added.
* print all child nodes to console output
*/
virtual void addNode(DbgCli_Node* node) { }
virtual void printAllChildNodes() { }

protected:
/**
Expand All @@ -34,26 +33,43 @@ class DbgCli_Node
*/
virtual void addChildNode(DbgCli_Node* childNode) { }

/**
* Remove a particular node from the children.
* @param node Pointer to the DbgCli_Node to be removed.
*/
virtual void removeChildNode(DbgCli_Node* childNode) { }

public:
/**
* Get parent node.
* @return DbgCli_Node Pointer to the parent node object.
*/
virtual DbgCli_Node* getParentNode() { return m_parentNode; }

/**
* Get a child node by name (no grandchildren).
* Command nodes return always null, since these objects don't have any children.
* @param nodeName Child node object name.
* @return DbgCli_Node Pointer to the object found, null pointer otherwise.
*/
virtual DbgCli_Node* getNode(const char* nodeName) { return 0; }
virtual DbgCli_Node* getChildNode(const char* nodeName) { return 0; }

/**
* Get first child node.
* @return DbgCli_Node Pointer to the firstchild object, null pointer if none is available.
*/
virtual DbgCli_Node* getFirstChild() {return 0;}

public:
/**
* Execute the debug command.
* Pure virtual method, to be implemented for leaf nodes (i.e. commands) by the application.
* @param argc
* @param args
* @param argc number of elements in args
* @param args all arguments stored in an array
* @param idxToFirstArgToHandle Index to the first argument in args array to be handled as parameter (this is the first parameter to be passed to the method that gets called by this command)
*/
virtual void execute(unsigned int argc, const char** args, unsigned int idxToFirstArgToHandle) = 0;

const char* getParentPath();
const char* getNodeName();
const char* getHelpText();

Expand All @@ -72,12 +88,19 @@ class DbgCli_Node
public:
static void AssignRootNode(DbgCli_Node* rootNode);
static DbgCli_Node* RootNode();
/**
* Get a pointer to a node
* @param parentPath parentPath of the searched node
* @param nodeName (optional) nodeName of the searched node
* @return DbgCli_Node Pointer to searched node, to parent node if nodeName is empty or null if (parent)node not found.
*/
static DbgCli_Node* getNode(const char* parentPath, const char* nodeName = "\0");

private:
static DbgCli_Node* s_rootNode;
DbgCli_Node* m_parentNode;

private:
const char* m_parentPath;
const char* m_nodeName;
const char* m_helpText;

Expand Down
Loading