2019-11-15 00:23:43 +00:00
|
|
|
#ifndef CONTROLLER_RELAY_H
|
|
|
|
#define CONTROLLER_RELAY_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2020-04-13 22:50:55 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <lmdb.h>
|
2019-11-15 00:23:43 +00:00
|
|
|
|
2020-04-16 23:38:25 +00:00
|
|
|
#include <constants.h>
|
2020-04-13 22:50:55 +00:00
|
|
|
#include <models/schedule.h>
|
2019-11-15 00:23:43 +00:00
|
|
|
|
2020-04-13 22:50:55 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t number;
|
2020-06-24 09:41:12 +00:00
|
|
|
int is_on;
|
2020-06-25 23:28:00 +00:00
|
|
|
int sent_to_broker;
|
2020-04-13 22:50:55 +00:00
|
|
|
char name[MAX_NAME_LENGTH + 1];
|
2020-04-24 22:48:59 +00:00
|
|
|
schedule_t *schedules[7];
|
2020-04-13 22:50:55 +00:00
|
|
|
} relay_t;
|
2019-11-15 00:23:43 +00:00
|
|
|
|
2020-04-13 22:50:55 +00:00
|
|
|
/**
|
|
|
|
* @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
|
2020-04-23 23:33:48 +00:00
|
|
|
relay_set_name(relay_t *relay, const char *name);
|
2020-04-13 22:50:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
2020-05-06 23:41:16 +00:00
|
|
|
relay_is_active(relay_t *relay, struct tm *time_struct);
|
2020-04-13 22:50:55 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
relay_free(relay_t *relay);
|
|
|
|
|
|
|
|
void
|
|
|
|
relay_debug(relay_t *relay);
|
2019-11-15 00:23:43 +00:00
|
|
|
|
|
|
|
#endif //CONTROLLER_RELAY_H
|