remove: lmdb
add: sqlite add: new commands
This commit is contained in:
parent
a37bdc4870
commit
9602e6e937
33 changed files with 1403 additions and 752 deletions
|
@ -13,10 +13,12 @@
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
|
||||
/**
|
||||
* @brief A unique UUID for this controller
|
||||
*/
|
||||
uuid_t id;
|
||||
uuid_t uid;
|
||||
/**
|
||||
* @brief The name of this controller
|
||||
*
|
||||
|
@ -27,14 +29,7 @@ typedef struct
|
|||
* @brief The command port the controller was bound to
|
||||
*/
|
||||
uint16_t command_port;
|
||||
/**
|
||||
* @brief The discovery port the controller receives broadcasts on
|
||||
*/
|
||||
uint16_t discovery_port;
|
||||
/**
|
||||
* @brief Amount of relays available to this controller
|
||||
*/
|
||||
uint8_t relay_count;
|
||||
|
||||
relay_t **relays;
|
||||
|
||||
} controller_t;
|
||||
|
@ -71,7 +66,7 @@ controller_create(void);
|
|||
* @return A loaded or new instance of controller or NULL on database error
|
||||
*/
|
||||
controller_t*
|
||||
controller_load(MDB_env *mdb_env);
|
||||
controller_load();
|
||||
|
||||
/**
|
||||
* @brief Save a controller to the database
|
||||
|
@ -82,7 +77,7 @@ controller_load(MDB_env *mdb_env);
|
|||
* @return Indicator to show success (0) or failure (!0)
|
||||
*/
|
||||
int
|
||||
controller_save(controller_t *controller, MDB_env *mdb_env);
|
||||
controller_save();
|
||||
|
||||
/**
|
||||
* @brief Sets a name to a controller.
|
||||
|
|
13
include/models/junction_relay_schedule.h
Normal file
13
include/models/junction_relay_schedule.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef CONTROLLER_MODELS_JUNCTION_RELAY_SCHEDULE_H
|
||||
#define CONTROLLER_MODELS_JUNCTION_RELAY_SCHEDULE_H
|
||||
|
||||
int
|
||||
junction_relay_schedule_insert(uint8_t weekday, int relay_id, int schedule_id);
|
||||
|
||||
int
|
||||
junction_relay_schedule_remove_for_relay(int relay_id);
|
||||
|
||||
int
|
||||
junction_relay_schedule_insert_weekdays(int relay_id, int *schedule_ids);
|
||||
|
||||
#endif /* CONTROLLER_MODELS_JUNCTION_RELAY_SCHEDULE_H */
|
|
@ -10,10 +10,7 @@ typedef struct
|
|||
uint16_t end;
|
||||
} period_t;
|
||||
|
||||
period_t*
|
||||
period_create(uint16_t start, uint16_t end);
|
||||
|
||||
int
|
||||
period_includes_time(period_t *period, struct tm *time_struct);
|
||||
period_includes_time(period_t period, struct tm *time_struct);
|
||||
|
||||
#endif /* CONTROLLER_PERIOD_H */
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
uint8_t number;
|
||||
int is_on;
|
||||
int is_on_schedule;
|
||||
|
@ -33,26 +34,14 @@ 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);
|
||||
relay_load(uint8_t number);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
relay_save(relay_t *relay);
|
||||
|
||||
void
|
||||
relay_reload_schedules(relay_t *relay);
|
||||
|
||||
int
|
||||
relay_is_on_schedule(relay_t *relay, struct tm *time_struct);
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
uuid_t id;
|
||||
int id;
|
||||
uuid_t uid;
|
||||
uint8_t weekday;
|
||||
uint16_t length;
|
||||
period_t **periods;
|
||||
period_t *periods;
|
||||
} schedule_t;
|
||||
|
||||
/**
|
||||
|
@ -25,13 +26,16 @@ typedef enum
|
|||
} db_key_schedule_e;
|
||||
|
||||
schedule_t*
|
||||
schedule_create(uuid_t id, uint8_t weekday, uint16_t length, uint16_t *periods_blob);
|
||||
|
||||
schedule_t*
|
||||
schedule_load(MDB_env *mdb_env, uint8_t relay_num, uint8_t weekday);
|
||||
schedule_create(uuid_t uid, uint16_t length, uint16_t *periods_blob);
|
||||
|
||||
int
|
||||
schedule_save(schedule_t *schedule, uint8_t relay_num, MDB_env *mdb_env);
|
||||
schedule_save(schedule_t *schedule);
|
||||
|
||||
schedule_t*
|
||||
schedule_get_by_uid(uuid_t uid);
|
||||
|
||||
schedule_t**
|
||||
schedule_get_relay_weekdays(int relay_id);
|
||||
|
||||
uint16_t*
|
||||
schedule_periods_to_blob(schedule_t *schedule);
|
||||
|
@ -39,7 +43,16 @@ schedule_periods_to_blob(schedule_t *schedule);
|
|||
void
|
||||
schedule_free(schedule_t *schedule);
|
||||
|
||||
void
|
||||
schedule_free_list(schedule_t **schedules_list);
|
||||
|
||||
void
|
||||
schedule_debug(schedule_t *schedule);
|
||||
|
||||
int
|
||||
schedule_uid_parse(const char *uid_str, uuid_t result);
|
||||
|
||||
void
|
||||
schedule_uid_unparse(const uuid_t uid, char *result);
|
||||
|
||||
#endif /* CONTROLLER_SCHEDULE_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue