timer-loop.h 1.63 KB

/**@file
 * @brief Declaration for the timing control functions
 * @author Ferràn Quer i Guerrero
 * @date 08/06/2014
 *
 * The functions declared in this file are used to synchronize the different actions taken by the device in a timely fashion.                                        
 */
#ifndef TIMER_LOOP_H
#define TIMER_LOOP_H

#include "libwismart.h"
#include "lwip/inet.h"

//! Half hour time definition
#define HALF_HOUR	    60*30 // time in seconds
//! Five minutes time definition
#define FIVE_MIN	    60*5  // time in seconds 
//#define LONG_PERIOD	HALF_HOUR //60*3 // for testing
//#define SHORT_PERIOD	FIVE_MIN  //60*1 // for testing
//! Long period time definition
/*! This defines how often will the device try to send data to the server. */
#define LONG_PERIOD		60*3 //60*3 // for testing
//! Short period time definition
/*! This defines how often will the device try to fetch data from the sensors. */
#define SHORT_PERIOD	60*1  //60*1 // for testing

//! Debug printing definition
/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */
#define DBG_TIMER(fmt,...)                printf("%c[1;35mtimer-loop.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
//#define DBG_TIMER(fmt,...)                printf("")

//! Returns elapsed time since device startup in seconds
unsigned long getSystemTime(void);

//! Returns elapsed time since the timestamp passed by argument
unsigned long getElapsedTime(unsigned long t /*! Time from which calculate the difference */); 

//! Sleep thread function
void sleep_thread(unsigned long seconds /*! Seconds to sleep */);

#endif