# HG changeset patch # User Florian Pose # Date 1488545449 -3600 # Node ID 0d7936701e607d6d1689e056411f90ae6b1f7d5c # Parent d9e14a0ddbd6a666fa42771d8c4d04f89045ad5a crc reset command. diff -r d9e14a0ddbd6 -r 0d7936701e60 tool/CommandCrc.cpp --- a/tool/CommandCrc.cpp Fri Mar 03 13:33:17 2017 +0100 +++ b/tool/CommandCrc.cpp Fri Mar 03 13:50:49 2017 +0100 @@ -27,6 +27,7 @@ #include #include +#include using namespace std; #include "CommandCrc.h" @@ -45,8 +46,9 @@ { stringstream str; - str << binaryBaseName << " " << getName() - << " [OPTIONS]" << endl + str + << binaryBaseName << " " << getName() << endl + << binaryBaseName << " " << getName() << " reset" << endl << endl << getBriefDescription() << endl << endl @@ -66,16 +68,60 @@ /****************************************************************************/ #define NUM_PORTS (4) +#define REG_SIZE (20) void CommandCrc::execute(const StringVector &args) { + bool reset = false; + + if (args.size() > 1) { + stringstream err; + err << "'" << getName() << "' takes either no or 'reset' argument!"; + throwInvalidUsageException(err); + } + + if (args.size() == 1) { + string arg = args[0]; + transform(arg.begin(), arg.end(), + arg.begin(), (int (*) (int)) std::tolower); + if (arg != "reset") { + stringstream err; + err << "'" << getName() << "' takes either no or 'reset' argument!"; + throwInvalidUsageException(err); + } + + reset = true; + } MasterDevice m(getSingleMasterIndex()); - m.open(MasterDevice::Read); + m.open(reset ? MasterDevice::ReadWrite : MasterDevice::Read); ec_ioctl_master_t master; m.getMaster(&master); + uint8_t data[REG_SIZE]; + ec_ioctl_slave_reg_t io; + io.emergency = 0; + io.address = 0x0300; + io.size = REG_SIZE; + io.data = data; + + if (reset) { + for (int j = 0; j < REG_SIZE; j++) { + data[j] = 0x00; + } + + for (unsigned int i = 0; i < master.slave_count; i++) { + + io.slave_position = i; + try { + m.writeReg(&io); + } catch (MasterDeviceException &e) { + throw e; + } + } + return; + } cout << " |"; for (unsigned int port = 0; port < NUM_PORTS; port++) { @@ -89,19 +135,12 @@ } cout << endl; - ec_ioctl_slave_reg_t io; - io.emergency = 0; - io.address = 0x0300; - io.size = 20; - io.data = new uint8_t[20]; - for (unsigned int i = 0; i < master.slave_count; i++) { io.slave_position = i; try { m.readReg(&io); } catch (MasterDeviceException &e) { - delete [] io.data; throw e; } @@ -120,8 +159,6 @@ slaveName = slaveName.substr(0, 11); cout << slaveName << endl; } - - delete [] io.data; } /*****************************************************************************/