示例#1
0
void HostUtility::create_junction_host(int aid)
{
    AimsunWorldUtility *world = NULL;
    world = FindModule<AimsunWorldUtility*>::findGlobalModule();
    if(!world)
    {
        throw cRuntimeError("Cannot get Aimsun World Utility!");
    }
    int vector_size = world->get_vehicles() + world->get_junctions();
    
    try
    {
        const unsigned short *attr_name = NULL;
        attr_name = AKIConvertFromAsciiString("GKNode:omnetpp_module");
        void *attr = ANGConnGetAttribute(attr_name);
        const unsigned short *name = NULL;
        name = ANGConnGetAttributeValueString(attr, aid);
        
        bool anyNonAsciiChar = false;
        std::string module_name = AKIConvertToAsciiString(name, false,
                                                          &anyNonAsciiChar);
        
        const unsigned short *attr_x_name = AKIConvertFromAsciiString("GKNode:x");
        void *attr_x = ANGConnGetAttribute(attr_x_name);
        double x = ANGConnGetAttributeValueDouble(attr_x, aid);
        
        const unsigned short *attr_y_name = AKIConvertFromAsciiString("GKNode:y");
        void *attr_y = ANGConnGetAttribute(attr_y_name);
        double y = ANGConnGetAttributeValueDouble(attr_y, aid);
        
        const unsigned short *attr_z_name = AKIConvertFromAsciiString("GKNode:z");
        void *attr_z = ANGConnGetAttribute(attr_z_name);
        double z = ANGConnGetAttributeValueDouble(attr_z, aid);

        if (module_name != "")
        { 
            cModuleType *moduleType = cModuleType::get(module_name.c_str());
            cModule *module = moduleType->create("hosts",
                                                 this->getParentModule(),
                                                 vector_size,
                                                 index);
            index++;
            // set up parameters and gate sizes before we set up itsubmodules
            module->par("aid") = aid;
            module->par("x") = x;
            module->par("y") = y;
            module->par("z") = z;
            module->finalizeParameters();
            // create internals, and schedule it
            module->buildInside();
            module->scheduleStart(simTime());
            module->callInitialize();
            junctions->insert(std::pair<int, cModule*>(aid, module));
        }
    }
    catch (std::exception& e)
    {
        AimsunPrint(std::string(e.what()));
    }
}
示例#2
0
void HostUtility::enter_vehicle(int aid, int sid)
{
    AimsunWorldUtility *world = NULL;
    int vector_size;
    const unsigned short *attr_name = NULL;
    const unsigned short *name = NULL;
    bool anyNonAsciiChar = false;
    int obj_id;
    std::string module_name = "";
    
    world = FindModule<AimsunWorldUtility*>::findGlobalModule();
    vector_size = world->get_vehicles() + world->get_junctions();
    
    try
    {
        StaticInfVeh info = AKIVehGetStaticInf(aid);
        name = AKIVehGetVehTypeName(info.type);
        obj_id = ANGConnGetObjectId(name, false);
        attr_name = AKIConvertFromAsciiString("GKVehicle::omnetpp_module");
        name = ANGConnGetAttributeValueString(ANGConnGetAttribute(attr_name),
                                              obj_id);
        if (name == NULL)
        {
            throw cRuntimeError("Cannot get ANG Object Attribute.");
        }

        module_name = AKIConvertToAsciiString(name, false,
                                              &anyNonAsciiChar);
        
        if (module_name != "")
        { 
            cModuleType *moduleType = cModuleType::get(module_name.c_str());
            cModule *module = moduleType->create("hosts",
                                                 this->getParentModule(),
                                                 vector_size,
                                                 index);
            index++;
            // set up parameters and gate sizes before we set up itsubmodules
            module->par("aid") = aid;
            module->par("section") = sid;
            module->finalizeParameters();
            // create internals, and schedule it
            module->buildInside();
            module->scheduleStart(simTime());
            module->callInitialize();
            vehicles->insert(std::pair<int, cModule*>(aid, module));
        }
    }
    catch (std::exception& e)
    {
        AimsunPrint(std::string(e.what()));
    }
}
std::string Tresenv::gets(const char *prompt, const char *defaultReply)
{
    if (!opt_interactive)
    {
        throw cRuntimeError("The simulation wanted to ask a question, set tresenv-interactive=true to allow it: \"%s\"", prompt);
    }
    else
    {
        ::fprintf(fout, "%s", prompt);
        if (!opp_isempty(defaultReply))
            ::fprintf(fout, "(default: %s) ", defaultReply);
        ::fflush(fout);
        
        ::fgets(buffer, 512, stdin);
        buffer[strlen(buffer)-1] = '\0'; // chop LF
        
        if (buffer[0]=='\x1b') // ESC?
            throw cRuntimeError(eCANCEL);
        
        return std::string(buffer);
    }
}
int Tresenv::run(int argc, char *argv[], cConfiguration *configobject)
{
    args = new ArgList();
    args->parse(argc, argv, "h?f:u:l:c:r:p:n:x:X:agGv");
    cfg = dynamic_cast<cConfigurationEx *>(configobject);
    if (!cfg)
        throw cRuntimeError("Cannot cast configuration object %s to cConfigurationEx", configobject->getClassName());
    if (simulationRequired())
    {
        if (setup())
            run();
    }
    return exitcode;
}
OMNETARA_NAMESPACE_BEGIN

OMNeTEARAConfiguration::OMNeTEARAConfiguration(cModule* module, EnergyAwareRoutingTable* routingTable, EARAPacketFactory* packetFactory) : OMNeTConfiguration(module, routingTable, packetFactory) {
    OMNeTBattery* battery = ModuleAccess<OMNeTBattery>("battery").get();
    this->routingTable = routingTable;
    this->packetFactory = packetFactory;

    //TODO this maximumEnergyValue seems very redundant to the OMNeTConfiguration (check this)
    maximumEnergyValue = battery->getCapacity();

    ARANetworkConfigurator* networkConfig = check_and_cast<ARANetworkConfigurator*>(simulation.getModuleByPath("networkConfigurator"));
    maximumBatteryCapacityInNetwork = networkConfig->getMaximumBatteryCapacityInNetwork();

    influenceOfMinimumEnergyValue = module->par("influenceOfMinimumEnergyValue").longValue();
    routeDiscoveryDelayInMilliSeconds = module->par("routeDiscoveryDelay").longValue();
    peantEnergyThreshold = module->par("peantEnergyThreshold").doubleValue();

    if (influenceOfMinimumEnergyValue < 1) {
        throw cRuntimeError("EARA parameter influenceOfMinimumEnergyValue needs to be >= 1");
    }
    if (peantEnergyThreshold > 1 || (peantEnergyThreshold < 0 && peantEnergyThreshold != -1)) {
        throw cRuntimeError("EARA parameter peantEnergyThreshold needs to be between 0 and 1 (or -1 to be disabled)");
    }
}
bool Tresenv::askyesno(const char *question)
{
    if (!opt_interactive)
    {
        throw cRuntimeError("Simulation needs user input in non-interactive mode (prompt text: \"%s (y/n)\")", question);
    }
    else
    {
        // should also return -1 (==CANCEL)
        for(;;)
        {
            ::fprintf(fout, "%s (y/n) ", question);
            ::fflush(fout);
            ::fgets(buffer, 512, stdin);
            buffer[strlen(buffer)-1] = '\0'; // chop LF
            if (opp_toupper(buffer[0])=='Y' && !buffer[1])
                return true;
            else if (opp_toupper(buffer[0])=='N' && !buffer[1])
                return false;
            else
                putsmsg("Please type 'y' or 'n'!\n");
        }
    }
}
void Tresenv::readOptions()
{
    EnvirBase::readOptions();
    
    cConfiguration *cfg = getConfig();
    
    // note: configname and runstoexec will possibly be overwritten
    // with the -c, -r command-line options in our setup() method
    opt_configname = cfg->getAsString(CFGID_CONFIG_NAME);
    opt_runstoexec = cfg->getAsString(CFGID_RUNS_TO_EXECUTE);
    
    opt_extrastack = (size_t) cfg->getAsDouble(CFGID_TRESENV_EXTRA_STACK);
    opt_outputfile = cfg->getAsFilename(CFGID_OUTPUT_FILE).c_str();
    
    if (!opt_outputfile.empty())
    {
        processFileName(opt_outputfile);
        ::printf("Tresenv: redirecting output to file `%s'...\n",opt_outputfile.c_str());
        FILE *out = fopen(opt_outputfile.c_str(), "w");
        if (!out)
            throw cRuntimeError("Cannot open output redirection file `%s'",opt_outputfile.c_str());
        fout = out;
    }
}
示例#8
0
void doUnpacking(cCommBuffer *, T& t) {
    throw cRuntimeError("Parsim error: no doUnpacking() function for type %s or its base class (check .msg and _m.cc/h files!)",opp_typename(typeid(t)));
}