add: much

This commit is contained in:
Tobias Reisinger 2020-02-10 00:58:17 +01:00
parent 7b6ee283c6
commit cbb4ac7a86
15 changed files with 159 additions and 56 deletions

View file

@ -3,17 +3,25 @@
#include <log_levels.h>
#define CONTROLLER_FILE_NAME "emgauwa-controller.dat"
#define CONTROLLER_FILE_VERSION 1
#define CONTROLLER_FILE_HEADER_SIZE 4
/**
* @brief Limit the maximum length of a controller name
*
* The NULL terminator is not included. Arrays of length #CONTROLLER_NAME_LENGTH + 1 are required.
*/
#define CONTROLLER_NAME_LENGTH 128
/**
* @brief Maximum number of dbs for the databases for the MDB_env
*
* Used when calling mdb_env_set_maxdbs() in database_setup()
*/
#define MDB_MAXDBS 8
#define TEST_KEY "blubb"
#define TEST_VALUE "bla bla bla"
/**
* @brief Indicates to which level to log
*
* @see include/log_levels.h
*/
#define LOG_LEVEL LOG_LEVEL_TRACE
#endif //CONTROLLER_CONFIG_H

17
include/database.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef CONTROLLER_DATABASE_H
#define CONTROLLER_DATABASE_H
#include <lmdb.h>
/**
* @brief Setup lmdb database enviroment
*
* Creates, sets max dbs and opens an MDB_env instance.
* Will return on success, but exit program on failure.
*
* @param mdb_env Source variable will be set to new MDB_env
*/
void
database_setup(MDB_env **mdb_env);
#endif /* CONTROLLER_DATABASE_H */

4
include/discovery.h Normal file
View file

@ -0,0 +1,4 @@
#ifndef CONTROLLER_DISCOVERY_H
#define CONTROLLER_DISCOVERY_H
#endif /* CONTROLLER_DISCOVERY_H */

View file

@ -1,4 +0,0 @@
#include <stdint.h>
void
display_setup(void);

View file

@ -1,5 +1,5 @@
#ifndef CONTROLLER_LOG_LEVEL_H
#define CONTROLLER_LOG_LEVEL_H
#ifndef CONTROLLER_LOG_LEVELS_H
#define CONTROLLER_LOG_LEVELS_H
#define LOG_LEVEL_TRACE 5
#define LOG_LEVEL_DEBUG 4
@ -8,4 +8,4 @@
#define LOG_LEVEL_ERROR 1
#define LOG_LEVEL_FATAL 0
#endif //CONTROLLER_LOG_LEVEL_H
#endif //CONTROLLER_LOG_LEVELS_H

View file

@ -1,6 +1,7 @@
#ifndef CONTROLLER_LOGGER_H
#define CONTROLLER_LOGGER_H
#include <stdio.h>
#include <colors.h>
#include <config.h>
#include <macros.h>

View file

@ -23,24 +23,55 @@ typedef struct controller
* Includes a \0 terminator.
*/
char name[CONTROLLER_NAME_LENGTH + 1];
uint16_t port;
/**
* @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 **relays;
} controller;
/**
* @brief Key to save controller information in database
*/
typedef enum controller_db_key
{
KEY_META_UUID,
KEY_META_NAME,
KEY_META_PORT,
KEY_META_RELAY_COUNT,
KEY_META_RELAYS
KEY_META_UUID = 0,
KEY_META_NAME = 1,
KEY_META_COMMAND_PORT = 2,
KEY_META_DISCOVERY_PORT = 3,
KEY_META_RELAY_COUNT = 4,
KEY_META_RELAYS = 5,
} controller_db_key;
/**
* @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*
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*
controller_load(MDB_env *mdb_env);
@ -55,6 +86,14 @@ controller_load(MDB_env *mdb_env);
int
controller_save(controller *cntrlr, MDB_env *mdb_env);
/**
* @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 *cntrlr);

View file

@ -1,7 +1,10 @@
#ifndef CONTROLLER_WIRING_DEBUG_H
#define CONTROLLER_WIRING_DEBUG_H
#ifdef WIRING_PI_DEBUG
#define wiringPiSetup() printf("Setting up wiringPi....\n")
#define pinMode(x,y) printf("pinMode(%d, %d)\n",x,y)
#define digitalWrite(x,y) printf("digitalWrite(%d, %d)\n",x,y)
#define wiringPiSetup() LOG_INFO("wiringP wiringPiSetup()")
#define pinMode(x,y) LOG_INFO("wiringPi pinMode(%d, %d)", x, y)
#define digitalWrite(x,y) LOG_INFO("wiringPi digitalWrite(%d, %d)", x, y)
#endif
#endif /* CONTROLLER_WIRING_DEBUG_H */