alarm wip

This commit is contained in:
2018-04-14 00:02:50 +02:00
parent 480c1a6002
commit 13dd7d432b
6 changed files with 88 additions and 31 deletions

View File

@@ -155,8 +155,6 @@ int main(int argc, char *argv[])
CapabilitiesShuttersModel the_cap_shutters(&the_devices_manager); CapabilitiesShuttersModel the_cap_shutters(&the_devices_manager);
CapabilitiesSprinklersModel the_cap_sprinklers(&the_devices_manager); CapabilitiesSprinklersModel the_cap_sprinklers(&the_devices_manager);
return 0;
/* Setup the Ubus context. */ /* Setup the Ubus context. */
the_ctx = setup_ubus(); the_ctx = setup_ubus();
if (the_ctx == NULL) if (the_ctx == NULL)

View File

@@ -48,39 +48,38 @@ Clock::~Clock(void)
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn isEqual * @fn set
* *
* @brief Set an Event to the Clock. * @brief Set a time (hour/minute) to the Clock.
*/ */
#if 0 int Clock::set(void)
int Clock::set(const Event &an_event)
{ {
m_event = an_event;
m_now = time(NULL); m_now = time(NULL);
return 0; return 0;
} }
#endif
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn is_equal_to_current_time * @fn is_equal_to_timer
* *
* @brief return true if the clock is equal to current time. * @brief return true if the clock is equal to current time.
*/ */
bool Clock::is_equal_to_current_time(void) bool Clock::is_equal_to_timer(const Timer &a_timer)
{ {
struct tm the_compared_time; struct tm the_compared_time;
double the_diff; double the_diff;
the_compared_time = *localtime(&m_now); the_compared_time = *localtime(&m_now);
#if 0 printf ("=>Hour: %.2d h %.2d\n", the_compared_time.tm_hour, the_compared_time.tm_min);
the_compared_time.tm_hour = m_event.get_hour();
the_compared_time.tm_min = m_event.get_minute(); the_compared_time.tm_hour = a_timer.get_hour();
#endif the_compared_time.tm_min = a_timer.get_minute();
the_diff = difftime(m_now, mktime(&the_compared_time)); the_diff = difftime(m_now, mktime(&the_compared_time));
//printf ("%.f seconds of diff between current time and Timer time.\n", theDiff); printf ("=>Timer: %.2d h %.2d\n", a_timer.get_hour(),a_timer.get_minute());
printf ("%.f seconds of diff between current time and Timer time.\n", the_diff);
if (the_diff == 0) if (the_diff == 0)
return true; return true;
@@ -93,19 +92,19 @@ bool Clock::is_equal_to_current_time(void)
* *
* @brief Return true if the curent time has expired. * @brief Return true if the curent time has expired.
*/ */
bool Clock::is_expired(void) bool Clock::is_expired(uint16_t a_duration)
{ {
time_t the_expired; time_t the_expired;
struct tm the_compared_time; struct tm the_compared_time;
double the_diff; double the_diff;
the_compared_time = *localtime(&m_now); the_compared_time = *localtime(&m_now);
#if 0
the_compared_time.tm_hour = m_event.get_hour();
the_compared_time.tm_min = m_event.get_minute();
the_expired = mktime(&the_compared_time) + (m_event.get_duration() * 60); // the_compared_time.tm_hour = m_hour;
#endif // the_compared_time.tm_min = m_minute;
the_expired = mktime(&the_compared_time) + (a_duration * 60);
the_diff = difftime(m_now, the_expired); the_diff = difftime(m_now, the_expired);
//printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired); //printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired);

View File

@@ -28,9 +28,11 @@
/*------------------------------- INCLUDES ----------------------------------*/ /*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <ctime> #include <ctime>
//#include "timers/event.h" #include "timer.h"
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
@@ -42,12 +44,12 @@ class Clock
Clock(void); Clock(void);
~Clock(void); ~Clock(void);
//int set(const Event &an_event); int set(void);
bool is_equal_to_current_time(void);
bool is_expired(void); bool is_equal_to_timer(const Timer &a_timer);
bool is_expired(uint16_t a_duration);
private: private:
//Event m_event;
time_t m_now; time_t m_now;
}; };

View File

@@ -36,7 +36,8 @@
* *
* @brief Constructor of the Sequence Object. * @brief Constructor of the Sequence Object.
*/ */
Sequence::Sequence(void) : m_id(0) Sequence::Sequence(void) : m_is_in_progress(false),
m_id(0)
{ {
} }
@@ -148,3 +149,34 @@ const std::string &Sequence::get_name(void) const
{ {
return m_name; return m_name;
} }
/*! ----------------------------------------------------------------------------
* @fn get_timer
*
* @brief return the timer of the Sequence.
*/
const Timer &Sequence::get_timer(void) const
{
return m_timer;
}
/*! ----------------------------------------------------------------------------
* @fn is_active
*
* @brief return true if the sequence has an active timer. false otherwise.
*/
bool Sequence::is_active(void)
{
return m_timer.is_active();
}
/*! ----------------------------------------------------------------------------
* @fn is_in_progress
*
* @brief return true if the sequence has been started..
*/
bool Sequence::is_in_progress(void)
{
return m_is_in_progress;
}

View File

@@ -52,8 +52,13 @@ public:
uint16_t get_id(void) const; uint16_t get_id(void) const;
const std::string &get_name(void) const; const std::string &get_name(void) const;
const Timer &get_timer(void) const;
bool is_active(void);
bool is_in_progress(void);
private: private:
bool m_is_in_progress;
uint16_t m_id; uint16_t m_id;
std::string m_name; std::string m_name;
Timer m_timer; Timer m_timer;

View File

@@ -41,7 +41,6 @@
//#define k60s 60000 //#define k60s 60000
#define k60s 2000 #define k60s 2000
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn SequencesManager * @fn SequencesManager
* *
@@ -96,6 +95,8 @@ int SequencesManager::load(void)
/* Clean the json object. */ /* Clean the json object. */
json_object_put(the_root_node); json_object_put(the_root_node);
tzset ();
start(k60s, true); start(k60s, true);
return 0; return 0;
@@ -114,7 +115,7 @@ int SequencesManager::save(void)
the_root_node = to_json(); the_root_node = to_json();
the_result = json_object_to_file(m_sequences_file_path.c_str(), the_root_node); the_result = json_object_to_file(m_sequences_file_path.c_str(), the_root_node);
/* Clean the json object. */ /* Clean the json object. */
json_object_put(the_root_node); json_object_put(the_root_node);
@@ -198,6 +199,26 @@ int SequencesManager::expire(void)
Clock the_clock; Clock the_clock;
fprintf(stderr, "**** >> Manage timers....\n"); fprintf(stderr, "**** >> Manage timers....\n");
for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++)
{
if ((*the_seq_it).is_active())
{
printf("sequence %d active.\n", (*the_seq_it).get_id());
if (!(*the_seq_it).is_in_progress())
{
if (the_clock.is_equal_to_timer((*the_seq_it).get_timer()))
{
// Action START.
fprintf(stdout, "Sequence Start\n");
//(*the_seq_it).start(m_devices_manager);
}
}
}
}
return 0;
}
#if 0 #if 0
for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++) for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++)
{ {
@@ -231,6 +252,6 @@ int SequencesManager::expire(void)
} }
} }
} }
#endif
return 0; return 0;
} }
#endif