diff -r 7ffbca63fc72 -r 59be91dfcbe1 tool/CommandData.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool/CommandData.cpp Thu Jul 24 13:27:06 2008 +0000 @@ -0,0 +1,90 @@ +/***************************************************************************** + * + * $Id$ + * + ****************************************************************************/ + +#include +using namespace std; + +#include "CommandData.h" + +/*****************************************************************************/ + +CommandData::CommandData(): + Command("data", "Output binary domain process data.") +{ +} + +/*****************************************************************************/ + +string CommandData::helpString() const +{ + stringstream str; + + str << getName() << " [OPTIONS]" << endl + << endl + << getBriefDescription() << endl + << endl + << "Command-specific options:" << endl + << " --domain -d Positive numerical domain index, or" << endl + << " 'all' for all domains (default). In" << endl + << " this case, data of all domains are" << endl + << " concatenated." << endl + << endl + << numericInfo(); + + return str.str(); +} + +/****************************************************************************/ + +void CommandData::execute(MasterDevice &m, const StringVector &args) +{ + m.open(MasterDevice::Read); + + if (domainIndex == -1) { + unsigned int i; + ec_ioctl_master_t master; + + m.getMaster(&master); + + for (i = 0; i < master.domain_count; i++) { + outputDomainData(m, i); + } + } else { + outputDomainData(m, domainIndex); + } +} + +/****************************************************************************/ + +void CommandData::outputDomainData(MasterDevice &m, unsigned int domainIndex) +{ + ec_ioctl_domain_t domain; + ec_ioctl_domain_data_t data; + unsigned char *processData; + unsigned int i; + + m.getDomain(&domain, domainIndex); + + if (!domain.data_size) + return; + + processData = new unsigned char[domain.data_size]; + + try { + m.getData(&data, domainIndex, domain.data_size, processData); + } catch (MasterDeviceException &e) { + delete [] processData; + throw e; + } + + for (i = 0; i < data.data_size; i++) + cout << processData[i]; + cout.flush(); + + delete [] processData; +} + +/****************************************************************************/