Implemented 'ethercat debug' command.
This commit is contained in:
parent
b5111a255b
commit
7194a43da1
|
|
@ -449,6 +449,12 @@ long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|||
break;
|
||||
}
|
||||
|
||||
case EC_IOCTL_DEBUG_LEVEL:
|
||||
if (ec_master_debug_level(master, (unsigned int) arg)) {
|
||||
retval = -EINVAL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
retval = -ENOIOCTLCMD;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ enum {
|
|||
EC_IOCTL_DOMAIN_COUNT,
|
||||
EC_IOCTL_DOMAIN,
|
||||
EC_IOCTL_DOMAIN_FMMU,
|
||||
EC_IOCTL_DATA
|
||||
EC_IOCTL_DATA,
|
||||
EC_IOCTL_DEBUG_LEVEL,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -65,25 +65,20 @@ static int ec_master_operation_thread(ec_master_t *);
|
|||
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 @@ ssize_t ec_show_master_attribute(struct kobject *kobj, /**< kobject */
|
|||
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 @@ ec_domain_t *ec_master_find_domain(
|
|||
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
|
||||
*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ struct ec_master {
|
|||
|
||||
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 @@ void ec_master_destroy_slaves(ec_master_t *);
|
|||
unsigned int ec_master_domain_count(const ec_master_t *);
|
||||
ec_domain_t *ec_master_find_domain(ec_master_t *, unsigned int);
|
||||
|
||||
int ec_master_debug_level(ec_master_t *, int);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -77,6 +77,35 @@ void Master::outputData(int domainIndex)
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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 @@ class Master
|
|||
void close();
|
||||
|
||||
void outputData(int);
|
||||
void setDebug(const vector<string> &);
|
||||
void showDomains(int);
|
||||
void listSlaves();
|
||||
void listPdos(int);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#include "Master.h"
|
||||
|
|
@ -23,6 +24,7 @@ static unsigned int masterIndex = DEFAULT_MASTER;
|
|||
static int slavePosition = DEFAULT_SLAVEPOSITION;
|
||||
static int domainIndex = DEFAULT_DOMAININDEX;
|
||||
static string command = DEFAULT_COMMAND;
|
||||
vector<string> commandArgs;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ void printUsage()
|
|||
<< "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 @@ void getOptions(int argc, char **argv)
|
|||
}
|
||||
|
||||
command = argv[optind];
|
||||
while (++optind < argc)
|
||||
commandArgs.push_back(string(argv[optind]));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
|
@ -146,6 +151,8 @@ int main(int argc, char **argv)
|
|||
|
||||
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") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue