void Config::print(ostream &os)
{
	ConfigList children = getChildren();

	if (getLevel() == 0) {
		ConfigList::const_iterator iter = children.begin();
		for (; iter != children.end(); ++iter) (*iter)->print(os);
		os << endl;
	}
	else {
		if (children.size() == 0) {
			for (int i = 1; i < getLevel(); ++i) os << '\t';
			os << '<' << getName();
			printAttributes(os);
			os << '>';

			os << getValue("");
			os << "</" << getName() << '>' << endl;
		}
		else {
			os << '\n';
			for (int i = 1; i < getLevel(); ++i) os << '\t';
			os << '<' << getName();
			printAttributes(os);
			os << '>';
			os << '\n';

			ConfigList::const_iterator iter = children.begin();
			for (; iter != children.end(); ++iter) (*iter)->print(os);
			for (int i = 1; i < getLevel(); ++i) os << '\t';
			os << "</" << getName() << ">" << endl;
		}
	}
}
Example #2
0
/** Lists the bus configuration.
 */
void CommandConfig::listConfigs(
        MasterDevice &m,
        const ConfigList &configList,
        bool doIndent
        )
{
    ConfigList::const_iterator configIter;
    stringstream str;
    Info info;
    typedef list<Info> InfoList;
    InfoList list;
    InfoList::const_iterator iter;
    unsigned int maxAliasWidth = 0, maxPosWidth = 0,
                 maxSlavePosWidth = 0, maxStateWidth = 0;
    ec_ioctl_slave_t slave;
    string indent(doIndent ? "  " : "");

    for (configIter = configList.begin();
            configIter != configList.end();
            configIter++) {

        str << dec << configIter->alias;
        info.alias = str.str();
        str.clear();
        str.str("");

        str << configIter->position;
        info.pos = str.str();
        str.clear();
        str.str("");

        str << hex << setfill('0')
            << "0x" << setw(8) << configIter->vendor_id
            << "/0x" << setw(8) << configIter->product_code;
        info.ident = str.str();
        str.clear();
        str.str("");

        if (configIter->slave_position != -1) {
            m.getSlave(&slave, configIter->slave_position);

            str << dec << configIter->slave_position;
            info.slavePos = str.str();
            str.clear();
            str.str("");

            info.state = alStateString(slave.al_state);
        } else {
            str << "-";
            info.slavePos = str.str();
            str.clear();
            str.str("");

            str << "-";
            info.state = str.str();
            str.clear();
            str.str("");
        }

        list.push_back(info);

        if (info.alias.length() > maxAliasWidth)
            maxAliasWidth = info.alias.length();
        if (info.pos.length() > maxPosWidth)
            maxPosWidth = info.pos.length();
        if (info.slavePos.length() > maxSlavePosWidth)
            maxSlavePosWidth = info.slavePos.length();
        if (info.state.length() > maxStateWidth)
            maxStateWidth = info.state.length();
    }

    for (iter = list.begin(); iter != list.end(); iter++) {
        cout << indent << setfill(' ') << right
            << setw(maxAliasWidth) << iter->alias
            << ":" << left
            << setw(maxPosWidth) << iter->pos
            << "  "
            << iter->ident
            << "  "
            << setw(maxSlavePosWidth) << iter->slavePos << "  "
            << setw(maxStateWidth) << iter->state << "  "
            << endl;
    }
}
Example #3
0
/** Lists the complete bus configuration.
 */
void CommandConfig::showDetailedConfigs(
        MasterDevice &m,
        const ConfigList &configList,
        bool doIndent
        )
{
    ConfigList::const_iterator configIter;
    unsigned int i, j, k, l;
    ec_ioctl_slave_t slave;
    ec_ioctl_config_pdo_t pdo;
    ec_ioctl_config_pdo_entry_t entry;
    ec_ioctl_config_sdo_t sdo;
    ec_ioctl_config_idn_t idn;
    string indent(doIndent ? "  " : "");

    for (configIter = configList.begin();
            configIter != configList.end();
            configIter++) {

        cout << indent
            << "Alias: "
            << dec << configIter->alias << endl << indent
            << "Position: " << configIter->position << endl << indent
            << "Vendor Id: 0x"
            << hex << setfill('0')
            << setw(8) << configIter->vendor_id << endl << indent
            << "Product code: 0x"
            << setw(8) << configIter->product_code << endl << indent
            << "Attached slave: ";

        if (configIter->slave_position != -1) {
            m.getSlave(&slave, configIter->slave_position);
            cout << dec << configIter->slave_position
                << " (" << alStateString(slave.al_state) << ")" << endl;
        } else {
            cout << "none" << endl;
        }

        cout << indent << "Watchdog divider: ";
        if (configIter->watchdog_divider) {
            cout << dec << configIter->watchdog_divider;
        } else {
            cout << "(Default)";
        }
        cout << endl << indent
            << "Watchdog intervals: ";
        if (configIter->watchdog_intervals) {
            cout << dec << configIter->watchdog_intervals;
        } else {
            cout << "(Default)";
        }
        cout << endl;

        for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) {
            if (configIter->syncs[j].pdo_count) {
                cout << indent << "SM" << dec << j << ", Dir: "
                    << (configIter->syncs[j].dir == EC_DIR_INPUT
                            ? "Input" : "Output") << ", Watchdog: ";
                switch (configIter->syncs[j].watchdog_mode) {
                    case EC_WD_DEFAULT: cout << "Default"; break;
                    case EC_WD_ENABLE: cout << "Enable"; break;
                    case EC_WD_DISABLE: cout << "Disable"; break;
                    default: cout << "???"; break;
                }
                cout << endl;

                for (k = 0; k < configIter->syncs[j].pdo_count; k++) {
                    m.getConfigPdo(&pdo, configIter->config_index, j, k);

                    cout << indent << "  PDO 0x" << hex << setfill('0')
                        << setw(4) << pdo.index << endl;

                    for (l = 0; l < pdo.entry_count; l++) {
                        m.getConfigPdoEntry(&entry,
                                configIter->config_index, j, k, l);

                        cout << indent << "    PDO entry 0x"
                            << hex << setfill('0')
                            << setw(4) << entry.index << ":"
                            << setw(2) << (unsigned int) entry.subindex
                            << ", " << dec << setfill(' ')
                            << setw(2) << (unsigned int) entry.bit_length
                            << " bit" << endl;
                    }
                }
            }
        }

        cout << indent << "SDO configuration:" << endl;
        if (configIter->sdo_count) {
            for (j = 0; j < configIter->sdo_count; j++) {
                m.getConfigSdo(&sdo, configIter->config_index, j);

                cout << indent << "  0x"
                    << hex << setfill('0')
                    << setw(4) << sdo.index;
                if (sdo.complete_access) {
                    cout << " C";
                }
                else {
                    cout << ":" << setw(2) << (unsigned int) sdo.subindex;
                }
                cout << ", " << dec << sdo.size << " byte" << endl;

                cout << indent << "    " << hex;
                for (i = 0; i < min((uint32_t) sdo.size,
                            (uint32_t) EC_MAX_SDO_DATA_SIZE); i++) {
                    cout << setw(2) << (unsigned int) sdo.data[i];
                    if ((i + 1) % 16 == 0 && i < sdo.size - 1) {
                        cout << endl << indent << "    ";
                    } else {
                        cout << " ";
                    }
                }

                cout << endl;
                if (sdo.size > EC_MAX_SDO_DATA_SIZE) {
                    cout << indent << "    ..." << endl;
                }
            }
        } else {
            cout << indent << "  None." << endl;
        }

        cout << indent << "IDN configuration:" << endl;
        if (configIter->idn_count) {
            for (j = 0; j < configIter->idn_count; j++) {
                m.getConfigIdn(&idn, configIter->config_index, j);

                cout << indent << "  Drive " << (unsigned int) idn.drive_no
                    << ", " << outputIdn(idn.idn)
                    << ", " << dec << idn.size << " byte" << endl;

                cout << indent << "    " << hex << setfill('0');
                for (i = 0; i < min((uint32_t) idn.size,
                            (uint32_t) EC_MAX_IDN_DATA_SIZE); i++) {
                    cout << setw(2) << (unsigned int) idn.data[i];
                    if ((i + 1) % 16 == 0 && i < idn.size - 1) {
                        cout << endl << indent << "    ";
                    } else {
                        cout << " ";
                    }
                }

                cout << endl;
                if (idn.size > EC_MAX_IDN_DATA_SIZE) {
                    cout << indent << "    ..." << endl;
                }
            }
        } else {
            cout << indent << "  None." << endl;
        }
        if (configIter->dc_assign_activate) {
            int i;

            cout << indent << "DC configuration:" << endl
                << indent << "  AssignActivate: 0x" << hex << setfill('0')
                << setw(4) << configIter->dc_assign_activate << endl;

            cout << indent << "         Cycle [ns]   Shift [ns]" << endl;
            for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) {
                cout << indent << "  SYNC" << dec << i << "  "
                    << setfill(' ') << right
                    << setw(11) << configIter->dc_sync[i].cycle_time
                    << "  "
                    << setw(11) << configIter->dc_sync[i].shift_time
                    << endl;
            }
        }
        cout << endl;
    }
}
bool CompositeComponentProfile::doParse(Config *pcfg)
{
	if (pcfg == NULL) return false;

	try {
		Config *cfg = pcfg->getChild("name");
		if (cfg == NULL) throw IOException("There is no name");
		name = cfg->getValue();

		cfg = pcfg->getChild("description");
		if (cfg != NULL) description = cfg->getValue();

		appDomain.parse(pcfg->getChild("app_domain"));
		copyright.parse(pcfg->getChild("copyright"));
		execEnv.parse(pcfg->getChild("execution_environment"));

		cfg = pcfg->getChild("subcomponents");
		if (cfg == NULL) {
			log_error("<CompositeComponentProfile::parse> There is no subcomponents");
			return false;
		}
		else {
			ConfigList list = cfg->getChildren("subcomponent");
			ConfigList::iterator iter = list.begin();
			for (; iter != list.end(); ++iter) {
				ComponentInfo profile;
				profile.parse(*iter);
				componentList.push_back(profile);
			}
		}

		cfg = pcfg->getChild("export_ports");
		if (cfg == NULL) {
			log_error("<CompositeComponentProfile::parse> There is no export_ports");
			return false;
		}
		else {
			ConfigList list = cfg->getChildren("export_port");
			ConfigList::iterator iter = list.begin();
			for (; iter != list.end(); ++iter) {
				ExportPortInfo profile;
				profile.parse(*iter);
				exportPortList.push_back(profile);
			}
		}

		cfg = pcfg->getChild("port_connections");
		if (cfg == NULL) {
			log_error("<CompositeComponentProfile::parse> There is no port_connections");
			return false;
		}
		else {
			ConfigList list = cfg->getChildren("port_connection");
			ConfigList::iterator iter = list.begin();
			for (; iter != list.end(); ++iter) {
				PortConnectionInfo profile;
				profile.parse(*iter);
				portConnectionList.push_back(profile);
			}
		}

		cfg = pcfg->getChild("coordination");
		if (cfg != NULL) {
			ConfigList list = cfg->getChildren("depends");
			ConfigList::iterator iter = list.begin();
			for (; iter != list.end(); ++iter) {
				CoordinationInfo profile;
				profile.parse(*iter);
				coordinationInfoList.push_back(profile);
			}

		}
	}
	catch (Exception &e) {
		log_error("<CompositeComponentProfile::parse> Excepton Occurred <= " << e.getMessage());
		return false;
	}
	return true;
}
Example #5
0
bool ConfigArray::load(std::istream &sin, string &s)
{
    s.erase();
    for (;;){
        if (sin.eof() || sin.fail()){
            s = "";
            return true;
        }
        char buf[1024];
        sin.getline(buf, sizeof(buf));
        string line(buf);
        for (;line[0] == '[';){
            string name = line.c_str() + 1;
            char *p = strchr((char*)(name.c_str()), ']');
            if (p){
                *p = 0;
                list<ConfigValue*>::iterator it;
                for (it = values.begin(); it != values.end(); it++){
                    if (!(*it)->isList) continue;
                    if (strcmp(name.c_str(), (*it)->m_name.c_str())) continue;
                    ConfigList *list = static_cast<ConfigList*>(*it);
                    list->load(sin, line);
                    break;
                }
                if (it != values.end()){
                    if (line == "[]"){
                        if (sin.eof() || sin.fail()){
                            s = "";
                            return true;
                        }
                        sin.getline(buf, sizeof(buf));
                        line = buf;
                    }
                    continue;
                }
            }
            s = line;
            return true;
        }
        if (line.size() == 0) continue;
        char *p = strchr(line.c_str(), '=');
        if (p == NULL){
            log(L_WARN, "Bad string in config %s", line.c_str());
            continue;
        }
        *p = 0;
        p++;
        list<ConfigValue*>::iterator it;
        for (it = values.begin(); it != values.end(); it++){
            if (strcmp(line.c_str(), (*it)->m_name.c_str())) continue;
            string unquoted;
            for (; *p; p++){
                if (*p != '\\'){
                    unquoted += *p;
                    continue;
                }
                p++;
                if (*p == 0) break;
                switch (*p){
                case '\\':
                    unquoted += '\\';
                    break;
                case 'n':
                    unquoted += '\n';
                    break;
                case 't':
                    unquoted += '\t';
                    break;
                case 'x':
                    if (p[1] && p[2]){
                        char c = 0;
                        c = (fromHex(p[1]) << 4) + fromHex(p[2]);
                        unquoted += c;
                        p += 2;
                    }
                    break;
                default:
                    p--;
                }
            }
            (*it)->load(unquoted);
            break;
        }
        if (it == values.end())
            log(L_WARN, "Bad key %s in config", line.c_str());
    }
    return true;
}