Exemplo n.º 1
0
int main(int argc, char const *argv[])
{
	double operating_time, operating_current;
	double discharge_time;
	//ask user for battery info
	printf("%s", "Enter battery voltage > ");
	scanf("%lf", &bat.voltage);
	printf("%s", "Enter power rating of the battery (in joules) > ");
	scanf("%lf", &bat.energy_limit);
	printf("%s", "What is battery’s available energy (in joules) > ");
	scanf("%lf", &bat.energy_available);
	printf("%s", "What is operating time (in seconds) > ");
	scanf("%lf", &operating_time);
	printf("%s", "What is operating current (int amps) > ");
	scanf("%lf", &operating_current);

	/****** start calculation *******/
	bat = power_device (bat, operating_time, operating_current);
	printf("\n\nthe outcome is %d\n",bat.dec);
	printf("the updated energy is %f\n\n\n",bat.energy_available);
	
	discharge_time = max_time(bat, operating_time, operating_current);
	printf("%s%f\n", "Discharge time with current load:\n", discharge_time);
	bat = recharge (bat);
	discharge_time = max_time(bat, operating_time, operating_current);
	printf("%s%f\n", "Discharge time after the battery is fully recharged:\n", 
		discharge_time);
	//debug
	//printf("%f %f %f\n", bat.voltage, bat.energy_limit, bat.energy_available);
	return 0;
}	
Exemplo n.º 2
0
	void connection_queue::on_timeout(error_code const& e)
	{
		mutex_t::scoped_lock l(m_mutex);

		INVARIANT_CHECK;
#ifdef TORRENT_DEBUG
		function_guard guard_(m_in_timeout_function);
#endif

		TORRENT_ASSERT(!e || e == asio::error::operation_aborted);
		if (e) return;

		ptime next_expire = max_time();
		ptime now = time_now_hires() + milliseconds(100);
		std::list<entry> timed_out;
		for (std::list<entry>::iterator i = m_queue.begin();
			!m_queue.empty() && i != m_queue.end();)
		{
			if (i->connecting && i->expires < now)
			{
				std::list<entry>::iterator j = i;
				++i;
				timed_out.splice(timed_out.end(), m_queue, j, i);
				--m_num_connecting;
				continue;
			}
			if (i->expires < next_expire)
				next_expire = i->expires;
			++i;
		}

		// we don't want to call the timeout callback while we're locked
		// since that is a recepie for dead-locks
		l.unlock();

		for (std::list<entry>::iterator i = timed_out.begin()
			, end(timed_out.end()); i != end; ++i)
		{
#ifndef BOOST_NO_EXCEPTIONS
			try {
#endif
				i->on_timeout();
#ifndef BOOST_NO_EXCEPTIONS
			} catch (std::exception&) {}
#endif
		}
		
		l.lock();
		
		if (next_expire < max_time())
		{
			error_code ec;
			m_timer.expires_at(next_expire, ec);
			m_timer.async_wait(boost::bind(&connection_queue::on_timeout, this, _1));
		}
		try_connect(l);
	}
Exemplo n.º 3
0
Event count(const events_t & events) {

  if (events.empty()) {
    return {};
  }

  return events.front().copy().set_metric(events.size())
         .set_time(max_time(events));
}
Exemplo n.º 4
0
void connection_queue::check_invariant() const
{
    int num_connecting = 0;
    for (std::list<entry>::const_iterator i = m_queue.begin();
            i != m_queue.end(); ++i)
    {
        if (i->connecting) ++num_connecting;
        else TORRENT_ASSERT(i->expires == max_time());
    }
    TORRENT_ASSERT(num_connecting == m_num_connecting);
}
Exemplo n.º 5
0
Event mean(const events_t & events) {

  if (events.empty()) {
    return {};
  }

  Event e(events.front());
  e.set_metric_d(reduce(sum_fn, events) / events.size());
  e.set_time(max_time(events));

  return e;
}
Exemplo n.º 6
0
Event maximum(const events_t & events) {

  if (events.empty()) {
    return {};
  }

  double max = events[0].metric();

  for (const auto & e: events) {

    auto tmp = e.metric();
    if (tmp > max) {
      max = tmp;
    }
  }

  Event e(events.front());
  e.set_metric_d(max);
  e.set_time(max_time(events));

  return e;
}
Exemplo n.º 7
0
Event minimum(const events_t & events) {

  if (events.empty()) {
    return {};
  }

  double min = metric_to_double(events[0]);

  for (const auto & e: events) {

    auto tmp = metric_to_double(e);
    if (tmp < min) {
      min = tmp;
    }

  }

  Event e(events.front());
  e.set_metric_d(min);
  e.set_time(max_time(events));

  return e;
}
Exemplo n.º 8
0
void connection_queue::on_timeout(error_code const& e)
{
#if defined TORRENT_ASIO_DEBUGGING
    complete_async("connection_queue::on_timeout");
#endif
    mutex_t::scoped_lock l(m_mutex);
    --m_num_timers;

    INVARIANT_CHECK;
#ifdef TORRENT_DEBUG
    function_guard guard_(m_in_timeout_function);
#endif

    TORRENT_ASSERT(!e || e == error::operation_aborted);

    // if there was an error, it's most likely operation aborted,
    // we should just quit. However, in case there are still connections
    // in connecting state, and there are no other timer invocations
    // we need to stick around still.
    if (e && (m_num_connecting == 0 || m_num_timers > 0)) return;

    ptime next_expire = max_time();
    ptime now = time_now_hires() + milliseconds(100);
    std::list<entry> timed_out;
    for (std::list<entry>::iterator i = m_queue.begin();
            !m_queue.empty() && i != m_queue.end();)
    {
        if (i->connecting && i->expires < now)
        {
            std::list<entry>::iterator j = i;
            ++i;
            timed_out.splice(timed_out.end(), m_queue, j, i);
            --m_num_connecting;
            continue;
        }
        if (i->connecting && i->expires < next_expire)
            next_expire = i->expires;
        ++i;
    }

    // we don't want to call the timeout callback while we're locked
    // since that is a recepie for dead-locks
    l.unlock();

    for (std::list<entry>::iterator i = timed_out.begin()
                                        , end(timed_out.end()); i != end; ++i)
    {
        TORRENT_ASSERT(i->connecting);
        TORRENT_ASSERT(i->ticket != -1);
        TORRENT_TRY {
            i->on_timeout();
        } TORRENT_CATCH(std::exception&) {}
    }

    l.lock();

    if (next_expire < max_time())
    {
#if defined TORRENT_ASIO_DEBUGGING
        add_outstanding_async("connection_queue::on_timeout");
#endif
        error_code ec;
        m_timer.expires_at(next_expire, ec);
        m_timer.async_wait(boost::bind(&connection_queue::on_timeout, this, _1));
        ++m_num_timers;
    }
    try_connect(l);
}
Exemplo n.º 9
0
		entry(): connecting(false), ticket(0), expires(max_time()), priority(0) {}
Exemplo n.º 10
0
    std::unique_ptr<intermediate> run(
            const std::atomic_bool& keep_going) const {
        //  RAYTRACER  /////////////////////////////////////////////////////////

        const auto rays_to_visualise = std::min(32ul, raytracer_.rays);

        engine_state_changed_(state::starting_raytracer, 1.0);

        auto raytracer_output = raytracer::canonical(
                compute_context_,
                voxels_and_mesh_.voxels,
                source_,
                receiver_,
                environment_,
                raytracer_,
                rays_to_visualise,
                keep_going,
                [&](auto step, auto total_steps) {
                    engine_state_changed_(state::running_raytracer,
                                          step / (total_steps - 1.0));
                });

        if (!(keep_going && raytracer_output)) {
            return nullptr;
        }

        engine_state_changed_(state::finishing_raytracer, 1.0);

        raytracer_reflections_generated_(std::move(raytracer_output->visual),
                                         source_);

        //  look for the max time of an impulse
        const auto max_stochastic_time =
                max_time(raytracer_output->aural.stochastic);

        //  WAVEGUIDE  /////////////////////////////////////////////////////////
        engine_state_changed_(state::starting_waveguide, 1.0);

        auto waveguide_output = waveguide_->run(
                compute_context_,
                voxels_and_mesh_,
                source_,
                receiver_,
                environment_,
                max_stochastic_time,
                keep_going,
                [&](auto& queue, const auto& buffer, auto step, auto steps) {
                    //  If there are node pressure listeners.
                    if (!waveguide_node_pressures_changed_.empty()) {
                        auto pressures =
                                core::read_from_buffer<float>(queue, buffer);
                        const auto time =
                                step / waveguide_->compute_sampling_frequency();
                        const auto distance =
                                time * environment_.speed_of_sound;
                        waveguide_node_pressures_changed_(std::move(pressures),
                                                          distance);
                    }

                    engine_state_changed_(state::running_waveguide,
                                          step / (steps - 1.0));
                });

        if (!(keep_going && waveguide_output)) {
            return nullptr;
        }

        engine_state_changed_(state::finishing_waveguide, 1.0);

        return make_intermediate_impl_ptr(
                make_combined_results(std::move(raytracer_output->aural),
                                      std::move(*waveguide_output)),
                source_,
                receiver_,
                room_volume_,
                environment_);
    }
int main(int argc, char **argv){
     if(argc<2){
        printf("Usage: ./trace domain \n for example: ./trace www.utdallas.edu\n");
        exit(0);
     }
	char command[200];
	strcpy(command, "traceroute ");
	strcat(command, argv[1]);
	strcat(command, " > output.txt");

       system(command);
       
       FILE * fp;
       char * line = NULL;
       size_t len = 0;
       ssize_t read;
       char *token;
       char delimiter[5] = " (),";
       char* strArray[12];
       
       fp = fopen("output.txt", "r"); // open file
       if (fp == NULL)
           exit(EXIT_FAILURE);
       int line_number = 0;
       int currentLine = 0;
       int tokenNumber = 0;
       float time[3];
       float min, max, avg;

       while ((read = getline(&line, &len, fp)) != -1) { //while line present do following

            printf("%s", line);
            tokenNumber = 0;
            token = strtok(line, delimiter); // token separated
            if(currentLine == 0)
            {
              //code for fist line
              while(token != NULL)
              {
                strArray[tokenNumber] = (char*)malloc(strlen(token) + 1);
                strcpy(strArray[tokenNumber], token); //token copy
                
                tokenNumber++;
                token = strtok(NULL, delimiter);
              }
              printf("DNS = %s\nIP = %s\n\n",strArray[2],strArray[3]);
              currentLine++;
            }
            else
            {
              //code for other lines
              while(token != NULL)
              {
                strArray[tokenNumber] = (char*)malloc(strlen(token) + 1);
                strcpy(strArray[tokenNumber], token);
                
                if(tokenNumber == 3)
                {
                  time[0] = atof(strArray[tokenNumber]); //time token saved by converting it to float
                }
                if(tokenNumber == 5)
                {
                  time[1] = strtod(strArray[tokenNumber],NULL); //time token saved by converting it to float
                }
                if(tokenNumber == 7)
                {
                  time[2] = strtod(strArray[tokenNumber],NULL); //time token saved by converting it to float
                }
                tokenNumber++;
                token = strtok(NULL, delimiter);
              }
               min = min_time(time, 3); //find min
               max = max_time(time, 3); // find max
               avg = avg_time(time, 3);  // find avg
               printf("DNS = %s\nIP = %s\n",strArray[1],strArray[2]);
               printf( "time 1 = %f,  time 2 = %f,  time 3 = %f\n",time[0], time[1], time[2]);
               printf( "min time = %f\nmax time = %f\navg time = %f\n\n",min, max, avg);
            }
            
       }

       fclose(fp); //close file

       printf(" ** end of mytrace program ** \n");          
}