fp@1200: /***************************************************************************** fp@1200: * fp@1200: * $Id$ fp@1200: * fp@1200: ****************************************************************************/ fp@1200: fp@1200: #include fp@1200: #include fp@1200: using namespace std; fp@1200: fp@1200: #include "CommandPhyRead.h" fp@1200: fp@1200: /*****************************************************************************/ fp@1200: fp@1200: CommandPhyRead::CommandPhyRead(): fp@1200: Command("phy_read", "Output a slave's physical memory contents.") fp@1200: { fp@1200: } fp@1200: fp@1200: /*****************************************************************************/ fp@1200: fp@1200: string CommandPhyRead::helpString() const fp@1200: { fp@1200: stringstream str; fp@1200: fp@1200: str << getName() << " [OPTIONS] " << endl fp@1200: << endl fp@1200: << getBriefDescription() << endl fp@1200: << endl fp@1200: << "This command requires a single slave to be selected." << endl fp@1200: << endl fp@1200: << "Arguments:" << endl fp@1200: << " OFFSET is the physical memory address. Must" << endl fp@1200: << " be an unsigned 16 bit number." << endl fp@1200: << " LENGTH is the number of bytes to read and must also be" << endl fp@1200: << " an unsigned 16 bit number. OFFSET plus LENGTH" << endl fp@1200: << " may not exceed 64k." << endl fp@1200: << endl fp@1200: << "Command-specific options:" << endl fp@1200: << " --alias -a " << endl fp@1200: << " --position -p Slave selection. See the help of" << endl fp@1200: << " the 'slaves' command." << endl fp@1200: << endl fp@1200: << numericInfo(); fp@1200: fp@1200: return str.str(); fp@1200: } fp@1200: fp@1200: /****************************************************************************/ fp@1200: fp@1200: void CommandPhyRead::execute(MasterDevice &m, const StringVector &args) fp@1200: { fp@1200: SlaveList slaves; fp@1200: ec_ioctl_slave_phy_t data; fp@1200: stringstream strOffset, strLength, err; fp@1200: uint16_t i; fp@1200: fp@1200: if (args.size() != 2) { fp@1200: err << "'" << getName() << "' takes two arguments!"; fp@1200: throwInvalidUsageException(err); fp@1200: } fp@1200: fp@1200: strOffset << args[0]; fp@1200: strOffset fp@1200: >> resetiosflags(ios::basefield) // guess base from prefix fp@1200: >> data.offset; fp@1200: if (strOffset.fail()) { fp@1200: err << "Invalid offset '" << args[0] << "'!"; fp@1200: throwInvalidUsageException(err); fp@1200: } fp@1200: fp@1200: strLength << args[1]; fp@1200: strLength fp@1200: >> resetiosflags(ios::basefield) // guess base from prefix fp@1200: >> data.length; fp@1200: if (strLength.fail()) { fp@1200: err << "Invalid length '" << args[1] << "'!"; fp@1200: throwInvalidUsageException(err); fp@1200: } fp@1200: fp@1200: if (!data.length) { fp@1200: return; fp@1200: } fp@1200: fp@1200: if ((uint32_t) data.offset + data.length > 0xffff) { fp@1200: err << "Offset and length exceeding 64k!"; fp@1200: throwInvalidUsageException(err); fp@1200: } fp@1200: fp@1200: m.open(MasterDevice::Read); fp@1200: slaves = selectedSlaves(m); fp@1200: fp@1200: if (slaves.size() != 1) { fp@1200: throwSingleSlaveRequired(slaves.size()); fp@1200: } fp@1200: data.slave_position = slaves.front().position; fp@1200: fp@1200: data.data = new uint8_t[data.length]; fp@1200: fp@1200: try { fp@1200: m.readPhy(&data); fp@1200: } catch (MasterDeviceException &e) { fp@1200: delete [] data.data; fp@1200: throw e; fp@1200: } fp@1200: fp@1200: for (i = 0; i < data.length; i++) { fp@1200: cout << data.data[i]; fp@1200: } fp@1200: fp@1200: delete [] data.data; fp@1200: } fp@1200: fp@1200: /*****************************************************************************/