Example #1
0
/*
* Return a string representation of the time
*/
std::string EAC_Time::as_string() const
   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::as_string: No time set");

   return std::to_string(year * 10000 + month * 100 + day);
   }
Example #2
0
/*
* Return a human readable string representation
*/
std::string EAC_Time::readable_string() const
   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::readable_string: No time set");

   // desired format: "%04d/%02d/%02d"
   std::stringstream output;
   output << std::setfill('0')
          << std::setw(4) << year << "/"
          << std::setw(2) << month << "/"
          << std::setw(2) << day;
   return output.str();
   }
Example #3
0
/*
* Compare this time against another
*/
s32bit EAC_Time::cmp(const EAC_Time& other) const
   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::cmp: No time set");

   const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0;

   if(year < other.year)     return EARLIER;
   if(year > other.year)     return LATER;
   if(month < other.month)   return EARLIER;
   if(month > other.month)   return LATER;
   if(day < other.day)       return EARLIER;
   if(day > other.day)       return LATER;

   return SAME_TIME;
   }
Example #4
0
std::string X509_Time::readable_string() const
   {
   if(time_is_set() == false)
      throw Invalid_State("X509_Time::readable_string: No time set");

   // desired format: "%04d/%02d/%02d %02d:%02d:%02d UTC"
   std::stringstream output;
   output << std::setfill('0')
          << std::setw(4) << m_year << "/"
          << std::setw(2) << m_month << "/"
          << std::setw(2) << m_day
          << " "
          << std::setw(2) << m_hour << ":"
          << std::setw(2) << m_minute << ":"
          << std::setw(2) << m_second
          << " UTC";

   return output.str();
   }
Example #5
0
std::string X509_Time::to_string() const
   {
   if(time_is_set() == false)
      throw Invalid_State("X509_Time::as_string: No time set");

   uint32_t full_year = m_year;

   if(m_tag == UTC_TIME)
      {
      if(m_year < 1950 || m_year >= 2050)
         throw Encoding_Error("X509_Time: The time " + readable_string() +
                              " cannot be encoded as a UTCTime");

      full_year = (m_year >= 2000) ? (m_year - 2000) : (m_year - 1900);
      }

   const uint64_t YEAR_FACTOR = 10000000000ULL;
   const uint64_t MON_FACTOR  = 100000000;
   const uint64_t DAY_FACTOR  = 1000000;
   const uint64_t HOUR_FACTOR = 10000;
   const uint64_t MIN_FACTOR  = 100;

   const uint64_t int_repr =
      YEAR_FACTOR * full_year +
      MON_FACTOR * m_month +
      DAY_FACTOR * m_day +
      HOUR_FACTOR * m_hour +
      MIN_FACTOR * m_minute +
      m_second;

   std::string repr = std::to_string(int_repr) + "Z";

   uint32_t desired_size = (m_tag == UTC_TIME) ? 13 : 15;

   while(repr.size() < desired_size)
      repr = "0" + repr;

   return repr;
   }
Example #6
0
int32_t X509_Time::cmp(const X509_Time& other) const
   {
   if(time_is_set() == false)
      throw Invalid_State("X509_Time::cmp: No time set");

   const int32_t EARLIER = -1, LATER = 1, SAME_TIME = 0;

   if(m_year < other.m_year)     return EARLIER;
   if(m_year > other.m_year)     return LATER;
   if(m_month < other.m_month)   return EARLIER;
   if(m_month > other.m_month)   return LATER;
   if(m_day < other.m_day)       return EARLIER;
   if(m_day > other.m_day)       return LATER;
   if(m_hour < other.m_hour)     return EARLIER;
   if(m_hour > other.m_hour)     return LATER;
   if(m_minute < other.m_minute) return EARLIER;
   if(m_minute > other.m_minute) return LATER;
   if(m_second < other.m_second) return EARLIER;
   if(m_second > other.m_second) return LATER;

   return SAME_TIME;
   }
Example #7
0
void fc_step()
{
    //using fake data
#ifdef FAKE_ENABLE
    return;
#endif


    gps_step();

    bt_step();

    protocol_step();

    logger_step();

    wind_step();

    //logger always enabled
    if (config.autostart.flags & AUTOSTART_ALWAYS_ENABLED)
    {
        if (fc.vario.valid && fc.flight.state == FLIGHT_WAIT)
        {
            fc_takeoff();
        }
    }
    else
    {
        //auto start
        // baro valid, waiting to take off or landed, and enabled auto start
        if (fc.vario.valid && (fc.flight.state == FLIGHT_WAIT || fc.flight.state == FLIGHT_LAND) && config.autostart.start_sensititvity > 0)
        {
            if (abs(fc.altitude1 - fc.flight.autostart_altitude) > config.autostart.start_sensititvity)
            {
                fc_takeoff();
            }
            else
            {
                uint32_t t = task_get_ms_tick();

                if(t < fc.flight.autostart_timer)
                {
                    assert(0);
                    DEBUG("old %lu\n", fc.flight.autostart_timer);
                    DEBUG("act %lu\n", t);
                }

                //reset wait timer
                if (t - fc.flight.autostart_timer > (uint32_t)config.autostart.timeout * 1000ul)
                {
                    fc.flight.autostart_timer = t;
                    fc.flight.autostart_altitude = fc.altitude1;
                }
            }
        }

        //auto land
        // flying and auto land enabled
        if (fc.flight.state == FLIGHT_FLIGHT && config.autostart.land_sensititvity > 0)
        {
            if (abs(fc.altitude1 - fc.flight.autostart_altitude) < config.autostart.land_sensititvity)
            {
                uint32_t tick = task_get_ms_tick();

                if (tick < fc.flight.autostart_timer)
                {
                    assert(0);
                    DEBUG("TT %lu\n", tick);
                    DEBUG("AT %lu\n", fc.flight.autostart_timer);
                }
                else if (tick - fc.flight.autostart_timer > (uint32_t)config.autostart.timeout * 1000ul)
                {
                    //reduce timeout from flight time
                    fc.flight.timer += (uint32_t)config.autostart.timeout * 1000ul;

                    gui_reset_timeout();
                    fc_landing();
                }
            }
            else
            {
                fc.flight.autostart_altitude = fc.altitude1;
                fc.flight.autostart_timer = task_get_ms_tick();
            }
        }
    }


    //gps time sync
    if ((config.system.time_flags & TIME_SYNC) && fc.gps_data.fix_cnt == GPS_FIX_TIME_SYNC)
    {
        if (config.gui.menu_audio_flags & CFG_AUDIO_MENU_GPS)
            seq_start(&gps_ready, config.gui.alert_volume);

        fc_sync_gps_time();
        fc.gps_data.fix_cnt++;
    }

    //glide ratio
    //when you have GPS, baro and speed is higher than 2km/h and you are sinking <= -0.01
    if (fc.gps_data.valid && fc.vario.valid && fc.gps_data.groud_speed > FC_GLIDE_MIN_KNOTS && fc.vario.avg <= FC_GLIDE_MIN_SINK)
    {
        float spd_m = fc.gps_data.groud_speed * FC_KNOTS_TO_MPS;
        fc.glide_ratio = spd_m / abs(fc.vario.avg);

        fc.glide_ratio_valid = true;
    }
    else
    {
        fc.glide_ratio_valid = false;
    }

    //flight logger
    if (config.logger.enabled)
    {
        if (fc.flight.state == FLIGHT_FLIGHT && !logger_active() && time_is_set() && !logger_error())
        {
            logger_start();
        }
    }

    //flight statistic
    if (fc.flight.state == FLIGHT_FLIGHT)
    {
        int16_t t_vario = fc.vario.avg * 100;

        if (fc.altitude1 > fc.flight.stats.max_alt)
            fc.flight.stats.max_alt = fc.altitude1;
        if (fc.altitude1 < fc.flight.stats.min_alt)
            fc.flight.stats.min_alt = fc.altitude1;

        if (t_vario > fc.flight.stats.max_climb)
            fc.flight.stats.max_climb = t_vario;
        if (t_vario < fc.flight.stats.max_sink)
            fc.flight.stats.max_sink = t_vario;
    }
}
Example #8
0
// Botan is released under the Simplified BSD License (see license.txt)

#include "catch.hpp"
#include <botan/build.h>

#if defined(BOTAN_HAS_CVC)

#include <botan/eac_asn_obj.h>

TEST_CASE("human readable time", "[EAC_Time]")
   {
   auto time1 = Botan::EAC_Time("2008-02-01");
   auto time2 = Botan::EAC_Time("2008/02/28");
   auto time3 = Botan::EAC_Time("2004-06-14");

   CHECK(( time1.time_is_set() == true ));
   CHECK(( time2.time_is_set() == true ));
   CHECK(( time3.time_is_set() == true ));

   CHECK(( time1.readable_string() == "2008/02/01" ));
   CHECK(( time2.readable_string() == "2008/02/28" ));
   CHECK(( time3.readable_string() == "2004/06/14" ));
   }

TEST_CASE("no time", "[EAC_Time]")
   {
   auto time = Botan::EAC_Time("");
   CHECK(( time.time_is_set() == false ));
   }

TEST_CASE("invalis time", "[EAC_Time]")