fp@1126: /***************************************************************************** fp@1126: * fp@1126: * $Id$ fp@1126: * fp@1126: ****************************************************************************/ fp@1126: fp@1126: #include fp@1126: #include fp@1126: using namespace std; fp@1126: fp@1126: #include "globals.h" fp@1126: fp@1126: /****************************************************************************/ fp@1126: fp@1126: const char *help_sii_read = fp@1126: "[OPTIONS]\n" fp@1126: "\n" fp@1126: "\n" fp@1126: "Command-specific options:\n"; fp@1126: fp@1126: /****************************************************************************/ fp@1126: fp@1126: struct CategoryName { fp@1126: uint16_t type; fp@1126: const char *name; fp@1126: }; fp@1126: fp@1126: static const CategoryName categoryNames[] = { fp@1126: {0x000a, "STRINGS"}, fp@1126: {0x0014, "DataTypes"}, fp@1126: {0x001e, "General"}, fp@1126: {0x0028, "FMMU"}, fp@1126: {0x0029, "SyncM"}, fp@1126: {0x0032, "TXPDO"}, fp@1126: {0x0033, "RXPDO"}, fp@1126: {0x003c, "DC"}, fp@1126: {} fp@1126: }; fp@1126: fp@1126: /****************************************************************************/ fp@1126: fp@1126: const char *getCategoryName(uint16_t type) fp@1126: { fp@1126: const CategoryName *cn = categoryNames; fp@1126: fp@1126: while (cn->type) { fp@1126: if (cn->type == type) { fp@1126: return cn->name; fp@1126: } fp@1126: cn++; fp@1126: } fp@1126: fp@1126: return "unknown"; fp@1126: } fp@1126: fp@1126: /****************************************************************************/ fp@1126: fp@1126: void command_sii_read(void) fp@1126: { fp@1126: ec_ioctl_slave_sii_t data; fp@1126: ec_ioctl_slave_t slave; fp@1126: unsigned int i; fp@1126: const uint16_t *categoryHeader; fp@1126: uint16_t categoryType, categorySize; fp@1126: stringstream err; fp@1126: fp@1126: if (slavePosition < 0) { fp@1126: stringstream err; fp@1126: err << "'sii_read' requires a slave! Please specify --slave."; fp@1126: throw MasterDeviceException(err.str()); fp@1126: } fp@1126: data.slave_position = slavePosition; fp@1126: fp@1126: masterDev.open(MasterDevice::Read); fp@1126: fp@1126: masterDev.getSlave(&slave, slavePosition); fp@1126: fp@1126: if (!slave.sii_nwords) fp@1126: return; fp@1126: fp@1126: data.offset = 0; fp@1126: data.nwords = slave.sii_nwords; fp@1126: data.words = new uint16_t[data.nwords]; fp@1126: fp@1126: try { fp@1126: masterDev.readSii(&data); fp@1126: } catch (MasterDeviceException &e) { fp@1126: delete [] data.words; fp@1126: throw e; fp@1126: } fp@1126: fp@1126: if (verbosity == Verbose) { fp@1126: cout << "SII Area:" << hex << setfill('0'); fp@1126: for (i = 0; i < min(data.nwords, 0x0040U) * 2; i++) { fp@1126: if (i % BreakAfterBytes) { fp@1126: cout << " "; fp@1126: } else { fp@1126: cout << endl << " "; fp@1126: } fp@1126: cout << setw(2) << (unsigned int) *((uint8_t *) data.words + i); fp@1126: } fp@1126: cout << endl; fp@1126: fp@1126: if (data.nwords > 0x0040U) { fp@1126: // cycle through categories fp@1126: categoryHeader = data.words + 0x0040U; fp@1126: categoryType = le16tocpu(*categoryHeader); fp@1126: while (categoryType != 0xffff) { fp@1126: cout << "SII Category 0x" << hex fp@1126: << setw(4) << categoryType fp@1126: << " (" << getCategoryName(categoryType) << ")" << flush; fp@1126: fp@1126: if (categoryHeader + 1 > data.words + data.nwords) { fp@1126: err << "SII data seem to be corrupted!"; fp@1126: throw MasterDeviceException(err.str()); fp@1126: } fp@1126: categorySize = le16tocpu(*(categoryHeader + 1)); fp@1126: cout << ", " << dec << categorySize << " words" << flush; fp@1126: fp@1126: if (categoryHeader + 2 + categorySize fp@1126: > data.words + data.nwords) { fp@1126: err << "SII data seem to be corrupted!"; fp@1126: throw MasterDeviceException(err.str()); fp@1126: } fp@1126: fp@1126: cout << hex; fp@1126: for (i = 0; i < categorySize * 2U; i++) { fp@1126: if (i % BreakAfterBytes) { fp@1126: cout << " "; fp@1126: } else { fp@1126: cout << endl << " "; fp@1126: } fp@1126: cout << setw(2) << (unsigned int) fp@1126: *((uint8_t *) (categoryHeader + 2) + i); fp@1126: } fp@1126: cout << endl; fp@1126: fp@1126: if (categoryHeader + 2 + categorySize + 1 fp@1126: > data.words + data.nwords) { fp@1126: err << "SII data seem to be corrupted!"; fp@1126: throw MasterDeviceException(err.str()); fp@1126: } fp@1126: categoryHeader += 2 + categorySize; fp@1126: categoryType = le16tocpu(*categoryHeader); fp@1126: } fp@1126: } fp@1126: } else { fp@1126: for (i = 0; i < data.nwords; i++) { fp@1126: uint16_t *w = data.words + i; fp@1126: cout << *(uint8_t *) w << *((uint8_t *) w + 1); fp@1126: } fp@1126: } fp@1126: fp@1126: delete [] data.words; fp@1126: } fp@1126: fp@1126: /*****************************************************************************/