Exemplo n.º 1
0
void writeNetworksSection(std::ostream& out, NodeSet& ns)
{
    out << "# Networks" << std::endl;
    NetworkSet& nets = ns.networksUsed();
    NetworkSet::iterator it = nets.begin();
    while (it != nets.end())
    {
        Network* n = *it;
        out << "SUBNET " << n->address;
        out << " { ";
        std::set<Node*>::iterator nit = n->nodes.begin();
        double lat = 0.0;
        double lon = 0.0;
        double alt = 0.0;
        while (nit != n->nodes.end())
        {
            out << (*nit)->NodeId << " ";
            lat += (*nit)->entity->worldLocation.lat;
            lon += (*nit)->entity->worldLocation.lon;
            alt += (*nit)->entity->worldLocation.alt;
            nit++;
        }
        lat = lat / (1.0*n->nodes.size());
        lon = lon / (1.0*n->nodes.size());
        alt = alt / (1.0*n->nodes.size());
        out << "} " << lat << " " << lon << " " << alt << std::endl;
        std::stringstream mask;
        ChannelSet::iterator cit = ns.channelsUsed().begin();
        while (cit != ns.channelsUsed().end())
        {
            if (*cit == n->channel)
            {
                mask << "1";
            }
            else
            {
                mask << "0";
            }
            cit++;
        }
        out << "[ " << n->address << "] PHY-LISTENABLE-CHANNEL-MASK "
            << mask.str() << std::endl;
        out << "[ " << n->address << "] PHY-LISTENING-CHANNEL-MASK "
            << mask.str() << std::endl;
        out << std::endl;
        it++;
    }
}
Exemplo n.º 2
0
void ConfigFileWriter::writeConfigFile(std::string filename, NodeSet& ns)
{
    std::fstream out;
    out.open(filename.c_str(), std::fstream::out | std::fstream::trunc);

    writeGeneralSection(out, Config::instance());
    writeTerrainSection(out, Config::instance());

    writePositionSection(out, Config::instance());
    writeMobilitySection(out, Config::instance());
    writeProgagationSection(out, Config::instance(), ns.channelsUsed());

    writeNetworksSection(out, ns);
    writePhysicalSection(out, Config::instance(), ns);

    writeStatisticsSection(out, Config::instance());
    writeHostnameSection(out, ns);
    writeNodeIconSection(out, ns, Config::instance());
    writeSlotsFile(out, Config::instance(), ns);

    if (Config::instance().externalInterfaceType == "HLA13"
        || Config::instance().externalInterfaceType == "HLA1516")
    {
        writeHLASection(out, Config::instance());
    }
    else if (Config::instance().externalInterfaceType == "DIS")
    {
        writeDISSection(out, Config::instance());
    }
    writeComponentSection(out, ns);

    out.close();
}