init rewrite
This commit is contained in:
parent
9a44bc494e
commit
6d828fcffc
100 changed files with 50541 additions and 2707 deletions
45
include/models/controller.h
Normal file
45
include/models/controller.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef CORE_MODELS_CONTROLLER_H
|
||||
#define CORE_MODELS_CONTROLLER_H
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <helpers.h>
|
||||
#include <models/relay.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uuid_t id;
|
||||
char name[128];
|
||||
char ip[17];
|
||||
int active;
|
||||
int port;
|
||||
int relay_count;
|
||||
relay_t **relays;
|
||||
} controller_t;
|
||||
|
||||
void
|
||||
controller_free(controller_t* contoller);
|
||||
|
||||
int
|
||||
controller_save(controller_t* contoller);
|
||||
|
||||
int
|
||||
controller_remove(controller_t* contoller);
|
||||
|
||||
char*
|
||||
controller_to_json(controller_t* contoller);
|
||||
|
||||
controller_t**
|
||||
controller_get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param);
|
||||
|
||||
controller_t**
|
||||
controller_get_all();
|
||||
|
||||
int
|
||||
controller_command(int command_code, char *payload, uint32_t payload_size);
|
||||
|
||||
void
|
||||
controller_free_list(controller_t **controllers_list);
|
||||
|
||||
#endif /* CORE_MODELS_CONTROLLER_H */
|
19
include/models/junction_relay_schedule.h
Normal file
19
include/models/junction_relay_schedule.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef CORE_MODELS_JUNCTION_RELAY_SCHEDULE_H
|
||||
#define CORE_MODELS_JUNCTION_RELAY_SCHEDULE_H
|
||||
|
||||
int
|
||||
junction_relay_schedule_get_schedule_id(uint8_t weekday, int relay_id);
|
||||
|
||||
int
|
||||
junction_relay_schedule_insert(uint8_t weekday, int relay_id, int schedule_id);
|
||||
|
||||
int
|
||||
junction_relay_schedule_remove(uint8_t weekday, int relay_id, int schedule_id);
|
||||
|
||||
int
|
||||
junction_relay_schedule_remove_for_relay(int relay_id);
|
||||
|
||||
int
|
||||
junction_relay_schedule_remove_for_schedule(int schedule_id);
|
||||
|
||||
#endif /* CORE_MODELS_JUNCTION_RELAY_SCHEDULE_H */
|
32
include/models/junction_tag.h
Normal file
32
include/models/junction_tag.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef CORE_MODELS_JUNCTION_TAG_H
|
||||
#define CORE_MODELS_JUNCTION_TAG_H
|
||||
|
||||
int*
|
||||
junction_tag_get_relays_for_tag_id(int tag_id);
|
||||
|
||||
int*
|
||||
junction_tag_get_schedules_for_tag_id(int tag_id);
|
||||
|
||||
int*
|
||||
junction_tag_get_tags_for_relay_id(int relay_id);
|
||||
|
||||
int*
|
||||
junction_tag_get_tags_for_schedule_id(int schedule_id);
|
||||
|
||||
int
|
||||
junction_tag_insert(int tag_id, int relay_id, int schedule_id);
|
||||
|
||||
int
|
||||
junction_tag_remove(int tag_id, int relay_id, int schedule_id);
|
||||
|
||||
int
|
||||
junction_tag_remove_for_tag(int tag_id);
|
||||
|
||||
int
|
||||
junction_tag_remove_for_relay(int relay_id);
|
||||
|
||||
int
|
||||
junction_tag_remove_for_schedule(int schedule_id);
|
||||
|
||||
|
||||
#endif /* CORE_MODELS_JUNCTION_TAG_H */
|
21
include/models/period.h
Normal file
21
include/models/period.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef CORE_PERIOD_H
|
||||
#define CORE_PERIOD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t start;
|
||||
uint16_t end;
|
||||
} period_t;
|
||||
|
||||
period_t*
|
||||
period_create(uint16_t start, uint16_t end);
|
||||
|
||||
int
|
||||
period_includes_time(period_t *period, uint16_t timestamp);
|
||||
|
||||
int
|
||||
period_helper_parse_hhmm(const char *hhmm_str, uint16_t *hhmm);
|
||||
|
||||
#endif /* CORE_PERIOD_H */
|
49
include/models/relay.h
Normal file
49
include/models/relay.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef CORE_RELAY_H
|
||||
#define CORE_RELAY_H
|
||||
|
||||
#include <string.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <helpers.h>
|
||||
#include <database.h>
|
||||
#include <models/schedule.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
char name[128];
|
||||
int number;
|
||||
uuid_t controller_id;
|
||||
int active_schedule_id;
|
||||
schedule_t *active_schedule;
|
||||
schedule_t *schedules[7];
|
||||
} relay_t;
|
||||
|
||||
bool
|
||||
relay_save();
|
||||
|
||||
bool
|
||||
relay_remove();
|
||||
|
||||
char*
|
||||
relay_to_json();
|
||||
|
||||
void
|
||||
relay_free_list(relay_t **relays_list);
|
||||
|
||||
relay_t**
|
||||
relay_get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param);
|
||||
|
||||
relay_t*
|
||||
relay_get_by_id(int id);
|
||||
|
||||
relay_t*
|
||||
relay_get_relay_for_controller(uuid_t controller_id, int relay_num);
|
||||
|
||||
bool
|
||||
relay_valid_num_is_for_controller(uuid_t controller_id, int relay_num);
|
||||
|
||||
relay_t**
|
||||
relay_get_all();
|
||||
|
||||
#endif /* CORE_RELAY_H */
|
58
include/models/schedule.h
Normal file
58
include/models/schedule.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
#ifndef CORE_SCHEDULE_H
|
||||
#define CORE_SCHEDULE_H
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <cJSON.h>
|
||||
#include <constants.h>
|
||||
#include <models/period.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
uuid_t uid;
|
||||
char name[MAX_NAME_LENGTH + 1];
|
||||
uint16_t periods_count;
|
||||
period_t *periods;
|
||||
} schedule_t;
|
||||
|
||||
int
|
||||
schedule_save(schedule_t *schedule);
|
||||
|
||||
int
|
||||
schedule_remove(schedule_t *schedule);
|
||||
|
||||
void
|
||||
schedule_free(schedule_t *schedule);
|
||||
|
||||
void
|
||||
schedule_free_list(schedule_t **schedule);
|
||||
|
||||
cJSON*
|
||||
schedule_to_json(schedule_t *schedule);
|
||||
|
||||
void
|
||||
schedule_free_list(schedule_t **schedules_list);
|
||||
|
||||
uint16_t*
|
||||
schedule_periods_to_blob(schedule_t *schedule);
|
||||
|
||||
schedule_t**
|
||||
schedule_get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param);
|
||||
|
||||
schedule_t*
|
||||
schedule_get_by_id_or_off(int id);
|
||||
|
||||
schedule_t*
|
||||
schedule_get_by_id(int id);
|
||||
|
||||
schedule_t**
|
||||
schedule_get_all();
|
||||
|
||||
int
|
||||
schedule_uid_parse(const char *uid_str, uuid_t result);
|
||||
|
||||
void
|
||||
schedule_uid_unparse(const uuid_t uid, char *result);
|
||||
|
||||
#endif /* CORE_SCHEDULE_H */
|
17
include/models/tag.h
Normal file
17
include/models/tag.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef CORE_MODELS_TAG_H
|
||||
#define CORE_MODELS_TAG_H
|
||||
|
||||
int
|
||||
tag_save(int id, const char *tag);
|
||||
|
||||
int
|
||||
tag_remove(int id);
|
||||
|
||||
char*
|
||||
tag_get_tag(int id);
|
||||
|
||||
int
|
||||
tag_get_id(const char* tag);
|
||||
|
||||
|
||||
#endif /* CORE_MODELS_TAG_H */
|
Loading…
Add table
Add a link
Reference in a new issue