Prepare go-rewrite
This commit is contained in:
parent
c49ada88c3
commit
c515f55b8b
57 changed files with 103 additions and 42639 deletions
|
|
@ -1,94 +0,0 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project(controller
|
||||
VERSION 0.4.0
|
||||
LANGUAGES C)
|
||||
|
||||
add_executable(controller src/main.c)
|
||||
|
||||
target_link_libraries(controller -lwiringPi)
|
||||
target_link_libraries(controller -lwiringPiDev)
|
||||
target_link_libraries(controller -lsqlite3)
|
||||
target_link_libraries(controller -luuid)
|
||||
|
||||
option(WIRING_PI_DEBUG "Use WiringPi Debugging Tool (OFF)" OFF)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D'__FILENAME__=\"$(subst $(realpath ${CMAKE_SOURCE_DIR}/src/)/,,$(abspath $<))\"'")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=gnu99 -Wpedantic -Werror -Wall -Wextra")
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage")
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
|
||||
file(GLOB_RECURSE ALL_SOURCE_FILES src/*.c)
|
||||
|
||||
if(WIRING_PI_DEBUG)
|
||||
message("Showing wiringPi calls as debug")
|
||||
add_definitions("-DWIRING_PI_DEBUG")
|
||||
endif(WIRING_PI_DEBUG)
|
||||
|
||||
aux_source_directory(src/ SRC_DIR)
|
||||
aux_source_directory(src/models MODELS_SRC)
|
||||
aux_source_directory(src/helpers HELPERS_SRC)
|
||||
aux_source_directory(src/handlers HANDLERS_SRC)
|
||||
aux_source_directory(src/drivers DRIVERS_SRC)
|
||||
aux_source_directory(src/runners RUNNERS_SRC)
|
||||
aux_source_directory(vendor VENDOR_SRC)
|
||||
|
||||
add_dependencies(controller sql)
|
||||
|
||||
configure_file("version.h.in" "version.h" @ONLY)
|
||||
|
||||
|
||||
target_sources(controller PRIVATE ${SRC_DIR} ${MODELS_SRC} ${HELPERS_SRC} ${HANDLERS_SRC} ${DRIVERS_SRC} ${RUNNERS_SRC} ${VENDOR_SRC})
|
||||
target_include_directories(controller PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_include_directories(controller PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor)
|
||||
target_include_directories(controller PRIVATE ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_custom_target(sql
|
||||
COMMAND ./compile_sql.sh
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(run
|
||||
COMMAND ${CMAKE_BINARY_DIR}/controller
|
||||
DEPENDS controller
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(docs
|
||||
COMMAND doxygen
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
||||
IF(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
message(STATUS "loading debug targets")
|
||||
add_custom_target(debug
|
||||
COMMAND gdb ${CMAKE_BINARY_DIR}/controller
|
||||
DEPENDS controller
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
add_custom_target(valgrind
|
||||
COMMAND valgrind -s ${CMAKE_BINARY_DIR}/controller
|
||||
DEPENDS controller
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
add_custom_target(valgrind-leak
|
||||
COMMAND valgrind --leak-check=full --show-leak-kinds=all ${CMAKE_BINARY_DIR}/controller
|
||||
DEPENDS controller
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(
|
||||
clang-tidy
|
||||
COMMAND /usr/bin/clang-tidy
|
||||
${ALL_SOURCE_FILES}
|
||||
--header-filter=${CMAKE_SOURCE_DIR}/include/*
|
||||
--
|
||||
-std=gnu99
|
||||
-I${CMAKE_SOURCE_DIR}/include
|
||||
-I${CMAKE_SOURCE_DIR}/vendor
|
||||
-I${CMAKE_BINARY_DIR}
|
||||
)
|
||||
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
3
go.mod
Normal file
3
go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module emgauwa.app/controller
|
||||
|
||||
go 1.15
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef CONTROLLER_CLI_H
|
||||
#define CONTROLLER_CLI_H
|
||||
|
||||
typedef struct cli
|
||||
{
|
||||
const char *config_file;
|
||||
int demo_mode;
|
||||
} cli_t;
|
||||
|
||||
void
|
||||
cli_parse(int argc, const char **argv, cli_t *cli);
|
||||
|
||||
#endif /* CONTROLLER_CLI_H */
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef CONTROLLER_COLORS_H
|
||||
#define CONTROLLER_COLORS_H
|
||||
|
||||
#define COLOR_RED "\033[0;31m"
|
||||
#define COLORB_RED "\033[1;31m"
|
||||
#define COLOR_GREEN "\033[0;32m"
|
||||
#define COLORB_GREEN "\033[1;32m"
|
||||
#define COLOR_YELLOW "\033[0;33m"
|
||||
#define COLORB_YELLOW "\033[1;33m"
|
||||
#define COLOR_BLUE "\033[0;34m"
|
||||
#define COLORB_BLUE "\033[1;34m"
|
||||
#define COLOR_MAGENTA "\033[0;35m"
|
||||
#define COLORB_MAGENTA "\033[1;35m"
|
||||
#define COLOR_CYAN "\033[0;36m"
|
||||
#define COLORB_CYAN "\033[1;36m"
|
||||
#define COLOR_NONE "\033[0m"
|
||||
|
||||
#endif //CONTROLLER_COLORS_H
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
#ifndef CONTROLLER_CONFIG_H
|
||||
#define CONTROLLER_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <toml.h>
|
||||
|
||||
#include <constants.h>
|
||||
#include <enums.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pin;
|
||||
int inverted;
|
||||
int init;
|
||||
relay_driver_t driver;
|
||||
uint8_t pulse_duration;
|
||||
} config_relay_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
char *database;
|
||||
char *user;
|
||||
char *group;
|
||||
char *mqtt_host;
|
||||
char *include;
|
||||
int relays_init;
|
||||
uint8_t relay_count;
|
||||
|
||||
struct
|
||||
{
|
||||
int level;
|
||||
FILE *file;
|
||||
} logging;
|
||||
|
||||
struct
|
||||
{
|
||||
uint16_t discovery;
|
||||
uint16_t mqtt;
|
||||
} ports;
|
||||
|
||||
config_relay_t *relay_configs;
|
||||
} config_t;
|
||||
|
||||
extern config_t *global_config;
|
||||
|
||||
void
|
||||
config_init();
|
||||
|
||||
void
|
||||
config_free();
|
||||
|
||||
void
|
||||
config_load_string(char **holder, const char *value);
|
||||
|
||||
void
|
||||
config_load(config_t *config, const char *cli_config_file);
|
||||
|
||||
void
|
||||
config_load_file(config_t *config, const char *file_name);
|
||||
|
||||
void
|
||||
config_load_directory(config_t *config, const char *directory_name);
|
||||
|
||||
#endif //CONTROLLER_CONFIG_H
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef CONTROLLER_CONNECTIONS_H
|
||||
#define CONTROLLER_CONNECTIONS_H
|
||||
|
||||
#include <mongoose.h>
|
||||
|
||||
struct mg_connection*
|
||||
connection_discovery_bind(struct mg_mgr *mgr);
|
||||
|
||||
struct mg_connection*
|
||||
connection_command_bind(struct mg_mgr *mgr);
|
||||
|
||||
struct mg_connection*
|
||||
connection_mqtt_connect(struct mg_mgr *mgr);
|
||||
|
||||
extern struct mg_connection *global_connection_mqtt;
|
||||
|
||||
#endif /* CONTROLLER_CONNECTIONS_H */
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef CONTROLLER_CONTANTS_H
|
||||
#define CONTROLLER_CONTANTS_H
|
||||
|
||||
#define SECONDS_PER_DAY 86400 // 60 * 60 * 24
|
||||
|
||||
#define SECONDS_PER_MINUTE 60
|
||||
|
||||
#define POLL_FDS_COUNT 2
|
||||
|
||||
/**
|
||||
* @brief Limit the maximum length of a controller/relay/etc name
|
||||
*
|
||||
* The NULL terminator is not included. Arrays of length #MAX_NAME_LENGTH + 1 are required.
|
||||
*/
|
||||
#define MAX_NAME_LENGTH 128
|
||||
|
||||
/**
|
||||
* @brief How many milli seconds to wait until poll timeout in main loop
|
||||
*/
|
||||
#define ACCEPT_TIMEOUT_MSECONDS 1000
|
||||
|
||||
#define PIFACE_GPIO_BASE 200
|
||||
|
||||
#define DEFAULT_CONTROLLER_NAME "emgauwa-controller"
|
||||
#define DEFAULT_CONFIG_PATH "emgauwa-controller.conf"
|
||||
#define DEFAULT_GLOBAL_CONFIG_PATH "/etc/emgauwa/controller.conf"
|
||||
#define DEFAULT_DATABASE_PATH "emgauwa-controller.sqlite"
|
||||
#define DEFAULT_DISCOVERY_PORT 4421
|
||||
#define DEFAULT_MQTT_PORT 1885
|
||||
#define DEFAULT_MQTT_HOST "127.0.0.1"
|
||||
|
||||
#endif /* CONTROLLER_CONTANTS_H */
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#ifndef CONTROLLER_DATABASE_H
|
||||
#define CONTROLLER_DATABASE_H
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
extern sqlite3 *global_database;
|
||||
|
||||
void
|
||||
database_init();
|
||||
|
||||
void
|
||||
database_free();
|
||||
|
||||
void
|
||||
database_migrate();
|
||||
|
||||
|
||||
int
|
||||
database_transaction_begin();
|
||||
|
||||
void
|
||||
database_transaction_commit();
|
||||
|
||||
void
|
||||
database_transaction_rollback();
|
||||
|
||||
|
||||
int
|
||||
database_helper_get_id(sqlite3_stmt *stmt);
|
||||
|
||||
int*
|
||||
database_helper_get_ids(sqlite3_stmt *stmt);
|
||||
|
||||
char*
|
||||
database_helper_get_string(sqlite3_stmt *stmt);
|
||||
|
||||
char**
|
||||
database_helper_get_strings(sqlite3_stmt *stmt);
|
||||
|
||||
#endif /* CONTROLLER_DATABASE_H */
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef CONTROLLER_DRIVERS_H
|
||||
#define CONTROLLER_DRIVERS_H
|
||||
|
||||
#include <models/relay.h>
|
||||
#include <enums.h>
|
||||
|
||||
void
|
||||
driver_piface_set(int pin, int value);
|
||||
|
||||
void
|
||||
driver_gpio_set(int pin, int value);
|
||||
|
||||
#endif /* CONTROLLER_DRIVERS_H */
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef CONTROLLER_ENUMS_H
|
||||
#define CONTROLLER_ENUMS_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
POLL_FDS_DISCOVERY,
|
||||
POLL_FDS_COMMAND
|
||||
} poll_fds_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DISCOVERY_MAPPING_ID = 0,
|
||||
DISCOVERY_MAPPING_NAME = 1,
|
||||
DISCOVERY_MAPPING_COMMAND_PORT = 2,
|
||||
DISCOVERY_MAPPING_RELAY_COUNT = 3,
|
||||
} discovery_mapping_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RELAY_DRIVER_NONE,
|
||||
RELAY_DRIVER_GPIO,
|
||||
RELAY_DRIVER_PIFACE,
|
||||
} relay_driver_t;
|
||||
|
||||
#endif /* CONTROLLER_ENUMS_H */
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef CONTROLLER_HANDLERS_H
|
||||
#define CONTROLLER_HANDLERS_H
|
||||
|
||||
#include <mongoose.h>
|
||||
|
||||
#include <models/controller.h>
|
||||
|
||||
/**
|
||||
* @brief Handle the command processing
|
||||
*
|
||||
* @param fd File descriptor to receive initial data from
|
||||
* @param controller Controller to use for answering command
|
||||
*/
|
||||
void
|
||||
handler_command(struct mg_connection *c, int ev, void *ev_data);
|
||||
|
||||
/**
|
||||
* @brief Handle the discovery processing
|
||||
*
|
||||
* @param fd File descriptor to receive initial data from
|
||||
* @param controller Controller to use for answering discovery
|
||||
*/
|
||||
void
|
||||
handler_discovery(struct mg_connection *c, int ev, void *ev_data);
|
||||
|
||||
void
|
||||
handler_mqtt(struct mg_connection *c, int ev, void *ev_data);
|
||||
|
||||
void
|
||||
handler_loop(struct mg_connection *c_mqtt);
|
||||
|
||||
#endif /* CONTROLLER_HANDLERS_H */
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef CONTROLLER_HELPERS_H
|
||||
#define CONTROLLER_HELPERS_H
|
||||
|
||||
#include <time.h>
|
||||
#include <config.h>
|
||||
|
||||
int
|
||||
helper_connect_tcp_server(char* host, uint16_t port);
|
||||
|
||||
int
|
||||
helper_bind_tcp_server(char* addr, uint16_t port, int max_client_backlog);
|
||||
|
||||
uint16_t
|
||||
helper_get_port(int sock);
|
||||
|
||||
/**
|
||||
* @brief Open socket for discovery
|
||||
*
|
||||
* Will exit program when unable to open socket.
|
||||
*
|
||||
* @param discovery_port Port number to listen on for discovery broadcasts
|
||||
*
|
||||
* @return Open socket to accept discovery broadcasts on
|
||||
*/
|
||||
int
|
||||
helper_open_discovery_socket(uint16_t discovery_port);
|
||||
|
||||
int
|
||||
helper_get_weekday(const struct tm *time_struct);
|
||||
|
||||
int
|
||||
helper_drop_privileges();
|
||||
|
||||
#endif /* CONTROLLER_HELPERS_H */
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef EMGAUWA_LOGGER_H
|
||||
#define EMGAUWA_LOGGER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <colors.h>
|
||||
#include <config.h>
|
||||
|
||||
void
|
||||
logger_log(int level, const char *filename, int line, const char *func, const char *msg, ...);
|
||||
|
||||
#define LOGGER_DEBUG(...) logger_log(LOG_DEBUG , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define LOGGER_INFO(...) logger_log(LOG_INFO , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define LOGGER_NOTICE(...) logger_log(LOG_NOTICE , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define LOGGER_WARNING(...) logger_log(LOG_WARNING, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define LOGGER_ERR(...) logger_log(LOG_ERR , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define LOGGER_CRIT(...) logger_log(LOG_CRIT , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define LOGGER_EMERG(...) logger_log(LOG_EMERG , __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
|
||||
#endif //EMGAUWA_LOGGER_H
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef CONTROLLER_MACROS_H
|
||||
#define CONTROLLER_MACROS_H
|
||||
|
||||
#define STRLEN(s) ((sizeof(s)/sizeof(s[0])) - sizeof(s[0]))
|
||||
|
||||
#endif /* CONTROLLER_MACROS_H */
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
#ifndef CONTROLLER_CONTROLLER_H
|
||||
#define CONTROLLER_CONTROLLER_H
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
#include <stdint.h>
|
||||
#include <lmdb.h>
|
||||
|
||||
#include <config.h>
|
||||
#include <models/relay.h>
|
||||
|
||||
/**
|
||||
* @brief Information about this controller
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
|
||||
/**
|
||||
* @brief A unique UUID for this controller
|
||||
*/
|
||||
uuid_t uid;
|
||||
/**
|
||||
* @brief The name of this controller
|
||||
*
|
||||
* Includes a \0 terminator.
|
||||
*/
|
||||
char name[MAX_NAME_LENGTH + 1];
|
||||
/**
|
||||
* @brief The command port the controller was bound to
|
||||
*/
|
||||
uint16_t command_port;
|
||||
|
||||
relay_t **relays;
|
||||
|
||||
} controller_t;
|
||||
|
||||
/**
|
||||
* @brief Key to save controller information in database
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
DB_KEY_CONTROLLER_ID = 0,
|
||||
DB_KEY_CONTROLLER_NAME = 1,
|
||||
DB_KEY_CONTROLLER_COMMAND_PORT = 2,
|
||||
DB_KEY_CONTROLLER_DISCOVERY_PORT = 3,
|
||||
} db_key_controller_e;
|
||||
|
||||
/**
|
||||
* @brief Create a new instance of controller
|
||||
*
|
||||
* This should not fail. The instance will be created with malloc and genric default values
|
||||
*
|
||||
* @return A new instance of #controller
|
||||
*/
|
||||
controller_t*
|
||||
controller_create(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Load a controller for database or create a new one
|
||||
*
|
||||
* Will return NULL when transaction can't start.
|
||||
*
|
||||
* @param mdb_env An opened MDB_env to load from
|
||||
*
|
||||
* @return A loaded or new instance of controller or NULL on database error
|
||||
*/
|
||||
controller_t*
|
||||
controller_load();
|
||||
|
||||
/**
|
||||
* @brief Save a controller to the database
|
||||
*
|
||||
* @param controller Instance of a controller
|
||||
* @param mdb_env Already created MDB_env
|
||||
*
|
||||
* @return Indicator to show success (0) or failure (!0)
|
||||
*/
|
||||
int
|
||||
controller_save();
|
||||
|
||||
/**
|
||||
* @brief Sets a name to a controller.
|
||||
* This function won't perform any checks (e.g. no NULL checks)
|
||||
*
|
||||
* @param controller Set the name to this controller
|
||||
* @param name Name to be set
|
||||
*/
|
||||
void
|
||||
controller_set_name(controller_t *controller, const char *name);
|
||||
|
||||
void
|
||||
controller_free(controller_t *controller);
|
||||
|
||||
/**
|
||||
* @brief Debug an instance of #controller
|
||||
*
|
||||
* Will use #LOG_DEBUG to log. So log will be depending on #LOG_LEVEL
|
||||
*
|
||||
* @param cntrlr #controller to debug
|
||||
*/
|
||||
void
|
||||
controller_debug(controller_t *controller);
|
||||
|
||||
extern controller_t *global_controller;
|
||||
|
||||
#endif //CONTROLLER_CONTROLLER_H
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#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);
|
||||
|
||||
int*
|
||||
junction_relay_schedule_get_relay_ids_with_schedule(int schedule_id);
|
||||
|
||||
#endif /* CONTROLLER_MODELS_JUNCTION_RELAY_SCHEDULE_H */
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef CONTROLLER_PERIOD_H
|
||||
#define CONTROLLER_PERIOD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t start;
|
||||
uint16_t end;
|
||||
} period_t;
|
||||
|
||||
int
|
||||
period_includes_time(period_t period, struct tm *time_struct);
|
||||
|
||||
#endif /* CONTROLLER_PERIOD_H */
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#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
|
||||
{
|
||||
int id;
|
||||
uint8_t number;
|
||||
int is_on;
|
||||
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);
|
||||
|
||||
relay_t*
|
||||
relay_load(uint8_t number);
|
||||
|
||||
int
|
||||
relay_save(relay_t *relay);
|
||||
|
||||
void
|
||||
relay_reload_schedules(relay_t *relay);
|
||||
|
||||
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
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
#ifndef CONTROLLER_SCHEDULE_H
|
||||
#define CONTROLLER_SCHEDULE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <lmdb.h>
|
||||
|
||||
#include <models/period.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
uuid_t uid;
|
||||
uint8_t weekday;
|
||||
uint16_t periods_count;
|
||||
period_t *periods;
|
||||
} schedule_t;
|
||||
|
||||
/**
|
||||
* @brief Key to save schedule information in database
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
DB_KEY_SCHEDULE_ID = 0,
|
||||
DB_KEY_SCHEDULE_PERIODS = 1,
|
||||
} db_key_schedule_e;
|
||||
|
||||
schedule_t*
|
||||
schedule_create(uuid_t uid, uint16_t length, uint16_t *periods_blob);
|
||||
|
||||
int
|
||||
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);
|
||||
|
||||
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 */
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef CONTROLLER_RUNNERS_H
|
||||
#define CONTROLLER_RUNNERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <models/controller.h>
|
||||
|
||||
void
|
||||
runner_test();
|
||||
|
||||
#endif /* CONTROLLER_RUNNERS_H */
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue