Implemented 'ethercat debug' command.
--- a/master/cdev.c Thu Jun 05 12:39:46 2008 +0000
+++ b/master/cdev.c Thu Jun 05 14:33:36 2008 +0000
@@ -449,6 +449,12 @@
break;
}
+ case EC_IOCTL_DEBUG_LEVEL:
+ if (ec_master_debug_level(master, (unsigned int) arg)) {
+ retval = -EINVAL;
+ }
+ break;
+
default:
retval = -ENOIOCTLCMD;
}
--- a/master/ioctl.h Thu Jun 05 12:39:46 2008 +0000
+++ b/master/ioctl.h Thu Jun 05 14:33:36 2008 +0000
@@ -52,7 +52,8 @@
EC_IOCTL_DOMAIN_COUNT,
EC_IOCTL_DOMAIN,
EC_IOCTL_DOMAIN_FMMU,
- EC_IOCTL_DATA
+ EC_IOCTL_DATA,
+ EC_IOCTL_DEBUG_LEVEL,
};
/*****************************************************************************/
--- a/master/master.c Thu Jun 05 12:39:46 2008 +0000
+++ b/master/master.c Thu Jun 05 14:33:36 2008 +0000
@@ -65,25 +65,20 @@
void ec_master_eoe_run(unsigned long);
#endif
ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *);
-ssize_t ec_store_master_attribute(struct kobject *, struct attribute *,
- const char *, size_t);
/*****************************************************************************/
/** \cond */
EC_SYSFS_READ_ATTR(info);
-EC_SYSFS_READ_WRITE_ATTR(debug_level);
static struct attribute *ec_def_attrs[] = {
&attr_info,
- &attr_debug_level,
NULL,
};
static struct sysfs_ops ec_sysfs_ops = {
.show = &ec_show_master_attribute,
- .store = ec_store_master_attribute
};
static struct kobj_type ktype_ec_master = {
@@ -1085,52 +1080,12 @@
if (attr == &attr_info) {
return ec_master_info(master, buffer);
}
- else if (attr == &attr_debug_level) {
- return sprintf(buffer, "%i\n", master->debug_level);
- }
return 0;
}
/*****************************************************************************/
-/**
- Formats attribute data for SysFS write access.
- \return number of bytes processed, or negative error code
-*/
-
-ssize_t ec_store_master_attribute(struct kobject *kobj, /**< slave's kobject */
- struct attribute *attr, /**< attribute */
- const char *buffer, /**< memory with data */
- size_t size /**< size of data to store */
- )
-{
- ec_master_t *master = container_of(kobj, ec_master_t, kobj);
-
- if (attr == &attr_debug_level) {
- if (!strcmp(buffer, "0\n")) {
- master->debug_level = 0;
- }
- else if (!strcmp(buffer, "1\n")) {
- master->debug_level = 1;
- }
- else if (!strcmp(buffer, "2\n")) {
- master->debug_level = 2;
- }
- else {
- EC_ERR("Invalid debug level value!\n");
- return -EINVAL;
- }
-
- EC_INFO("Master debug level set to %i.\n", master->debug_level);
- return size;
- }
-
- return -EINVAL;
-}
-
-/*****************************************************************************/
-
#ifdef EC_EOE
/**
Starts Ethernet-over-EtherCAT processing on demand.
@@ -1339,6 +1294,26 @@
return NULL;
}
+/*****************************************************************************/
+
+int ec_master_debug_level(
+ ec_master_t *master,
+ int level
+ )
+{
+ if (level < 0 || level > 2) {
+ EC_ERR("Invalid debug level %i!\n", level);
+ return -1;
+ }
+
+ if (level != master->debug_level) {
+ master->debug_level = level;
+ EC_INFO("Master debug level set to %i.\n", master->debug_level);
+ }
+
+ return 0;
+}
+
/******************************************************************************
* Realtime interface
*****************************************************************************/
--- a/master/master.h Thu Jun 05 12:39:46 2008 +0000
+++ b/master/master.h Thu Jun 05 14:33:36 2008 +0000
@@ -126,7 +126,7 @@
struct list_head domains; /**< list of domains */
- int debug_level; /**< master debug level */
+ int debug_level; /**< Master debug level. */
ec_stats_t stats; /**< cyclic statistics */
unsigned int frames_timed_out; /**< there were frame timeouts in the last
call to ecrt_master_receive() */
@@ -200,6 +200,8 @@
unsigned int ec_master_domain_count(const ec_master_t *);
ec_domain_t *ec_master_find_domain(ec_master_t *, unsigned int);
-/*****************************************************************************/
-
-#endif
+int ec_master_debug_level(ec_master_t *, int);
+
+/*****************************************************************************/
+
+#endif
--- a/tools/Master.cpp Thu Jun 05 12:39:46 2008 +0000
+++ b/tools/Master.cpp Thu Jun 05 14:33:36 2008 +0000
@@ -77,6 +77,35 @@
/****************************************************************************/
+void Master::setDebug(const vector<string> &commandArgs)
+{
+ stringstream str;
+ int debugLevel;
+
+ if (commandArgs.size() != 1) {
+ stringstream err;
+ err << "'debug' takes exactly one argument!";
+ throw MasterException(err.str());
+ }
+
+ str << commandArgs[0];
+ str >> debugLevel;
+
+ if (str.fail()) {
+ stringstream err;
+ err << "Invalid debug level '" << commandArgs[0] << "'!";
+ throw MasterException(err.str());
+ }
+
+ if (ioctl(fd, EC_IOCTL_DEBUG_LEVEL, debugLevel) < 0) {
+ stringstream err;
+ err << "Failed to set debug level: " << strerror(errno);
+ throw MasterException(err.str());
+ }
+}
+
+/****************************************************************************/
+
void Master::showDomains(int domainIndex)
{
if (domainIndex == -1) {
--- a/tools/Master.h Thu Jun 05 12:39:46 2008 +0000
+++ b/tools/Master.h Thu Jun 05 14:33:36 2008 +0000
@@ -8,6 +8,8 @@
#define __EC_MASTER_H__
#include <stdexcept>
+#include <string>
+#include <vector>
using namespace std;
#include "../master/ioctl.h"
@@ -41,6 +43,7 @@
void close();
void outputData(int);
+ void setDebug(const vector<string> &);
void showDomains(int);
void listSlaves();
void listPdos(int);
--- a/tools/main.cpp Thu Jun 05 12:39:46 2008 +0000
+++ b/tools/main.cpp Thu Jun 05 14:33:36 2008 +0000
@@ -8,6 +8,7 @@
#include <iostream>
#include <string>
+#include <vector>
using namespace std;
#include "Master.h"
@@ -23,6 +24,7 @@
static int slavePosition = DEFAULT_SLAVEPOSITION;
static int domainIndex = DEFAULT_DOMAININDEX;
static string command = DEFAULT_COMMAND;
+vector<string> commandArgs;
/*****************************************************************************/
@@ -32,6 +34,7 @@
<< "Usage: ethercat <COMMAND> [OPTIONS]" << endl
<< "Commands:" << endl
<< " data Output binary domain process data." << endl
+ << " debug Set the master debug level." << endl
<< " domain Show domain information." << endl
<< " list (ls, slaves) List all slaves (former 'lsec')." << endl
<< " pdos List Pdo mapping of given slaves." << endl
@@ -131,6 +134,8 @@
}
command = argv[optind];
+ while (++optind < argc)
+ commandArgs.push_back(string(argv[optind]));
}
/****************************************************************************/
@@ -146,6 +151,8 @@
if (command == "data") {
master.outputData(domainIndex);
+ } else if (command == "debug") {
+ master.setDebug(commandArgs);
} else if (command == "domain") {
master.showDomains(domainIndex);
} else if (command == "list" || command == "ls" || command == "slaves") {