controller-legacy/include/models/relay.h
2020-06-27 18:27:49 +02:00

66 lines
1.2 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;
int is_on;
int is_on_schedule;
int pulse_timer;
int sent_to_broker;
char name[MAX_NAME_LENGTH + 1];
schedule_t *schedules[7];
} relay_t;
/**
* @brief Key to save relay information in database
*/
typedef enum
{
DB_KEY_RELAY_NAME = 0,
} db_key_relay_e;
relay_t*
relay_create(uint8_t number);
void
relay_set_name(relay_t *relay, const 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_on_schedule(relay_t *relay, struct tm *time_struct);
void
relay_free(relay_t *relay);
void
relay_debug(relay_t *relay);
#endif //CONTROLLER_RELAY_H