controller-legacy/include/models/relay.h

64 lines
1.1 KiB
C

#ifndef CONTROLLER_RELAY_H
#define CONTROLLER_RELAY_H
#include <stdint.h>
#include <time.h>
#include <lmdb.h>
#include <constants.h>
#include <models/schedule.h>
typedef struct
{
uint8_t number;
char name[MAX_NAME_LENGTH + 1];
schedule_t *schedule;
} relay_t;
/**
* @brief Key to save relay information in database
*/
typedef enum
{
DB_KEY_RELAY_NAME = 0,
DB_KEY_RELAY_SCHEDULE_ID = 1,
DB_KEY_RELAY_SCHEDULE_PERIODS = 2,
} db_key_relay_e;
relay_t*
relay_create(uint8_t number);
void
relay_set_name(relay_t *relay, char *name);
/**
* @brief Load a relay for database or create a new one
*
* @param mdb_env An opened MDB_env to load from
*
* @return A loaded or new instance of relay
*/
relay_t*
relay_load(MDB_env *mdb_env, uint8_t num);
/**
* @brief Save a relay to the database
*
* @param relay Instance of a relay
* @param mdb_env Already created MDB_env
*
* @return Indicator to show success (0) or failure (!0)
*/
int
relay_save(relay_t *relay, MDB_env *mdb_env);
int
relay_is_active(relay_t *relay, time_t timestamp_now);
void
relay_free(relay_t *relay);
void
relay_debug(relay_t *relay);
#endif //CONTROLLER_RELAY_H