fix: rename uuid property to id

add: WIP discovery stuff
This commit is contained in:
Tobias Reisinger 2020-02-29 10:23:44 +01:00
parent 074c5c5750
commit d679d99a92
6 changed files with 23 additions and 67 deletions

View file

@ -15,6 +15,14 @@
#include <helper.h> #include <helper.h>
#include <binn.h> #include <binn.h>
enum DISCOVERY_MAPPING
{
DISCOVERY_MAPPING_ID = 0,
DISCOVERY_MAPPING_NAME = 1,
DISCOVERY_MAPPING_COMMAND_PORT = 2,
DISCOVERY_MAPPING_RELAY_COUNT = 3,
};
int int
discovery_socket_open(uint16_t discovery_port) discovery_socket_open(uint16_t discovery_port)
{ {
@ -84,20 +92,12 @@ discovery_handle_discover(int fd, controller *cntrlr)
return; return;
} }
binn *obj; binn *map = binn_map();
// create a new object binn_map_set_blob(map, DISCOVERY_MAPPING_ID, &cntrlr->id, sizeof(uuid_t));
obj = binn_object();
// add values to it void *payload = binn_ptr(map);
binn_object_set_blob(obj, "uuid", &cntrlr->uuid, sizeof(uuid_t)); size_t payload_size = binn_size(map);
// send over the network or save to a file...
void *payload = binn_ptr(obj);
size_t payload_size = binn_size(obj);
// release the buffer
char discover_answer_port_str[6]; char discover_answer_port_str[6];
sprintf(discover_answer_port_str, "%d", discovery_answer_port); sprintf(discover_answer_port_str, "%d", discovery_answer_port);
@ -108,13 +108,13 @@ discovery_handle_discover(int fd, controller *cntrlr)
if((bytes_transferred = send(fd_answer, &payload_size, sizeof(payload_size), 0)) <= 0) if((bytes_transferred = send(fd_answer, &payload_size, sizeof(payload_size), 0)) <= 0)
{ {
LOG_ERROR("error during sending"); LOG_ERROR("error during sending");
binn_free(obj); binn_free(map);
return; return;
} }
if((bytes_transferred = send(fd_answer, payload, payload_size, 0)) <= 0) if((bytes_transferred = send(fd_answer, payload, payload_size, 0)) <= 0)
{ {
LOG_ERROR("error during sending"); LOG_ERROR("error during sending");
binn_free(obj); binn_free(map);
return; return;
} }

View file

@ -1,44 +0,0 @@
#include <stdio.h>
#include <stdint.h>
#include <wiringPi.h>
#ifdef WIRING_PI_DEBUG
#include "wiring_debug.h"
#endif
#include "display.h"
#define INPUT_A 22
#define INPUT_B 23
#define LOAD 24
#define CLOCK 25
#define PAUSE 1
#define BOARD_SIZE_X 64
#define BOARD_SIZE_Y 40
#define BOARD_PIXEL_COUNT BOARD_SIZE_X * BOARD_SIZE_Y
#define BLOCK_SIZE_X 4
#define BLOCK_SIZE_Y 8
#define BLOCK_PIXEL_COUNT BLOCK_SIZE_X * BLOCK_SIZE_Y
#define BOARD_BLOCK_COUNT 80
uint32_t display_block_array[BOARD_BLOCK_COUNT];
void
display_setup(void)
{
wiringPiSetup();
pinMode(INPUT_A, OUTPUT);
digitalWrite(INPUT_A, LOW);
pinMode(INPUT_B, OUTPUT);
digitalWrite(INPUT_B, LOW);
pinMode(LOAD, OUTPUT);
digitalWrite(LOAD, LOW);
pinMode(CLOCK, OUTPUT);
digitalWrite(CLOCK, LOW);
}

View file

@ -16,7 +16,7 @@ typedef struct controller
/** /**
* @brief A unique UUID for this controller * @brief A unique UUID for this controller
*/ */
uuid_t uuid; uuid_t id;
/** /**
* @brief The name of this controller * @brief The name of this controller
* *
@ -44,7 +44,7 @@ typedef struct controller
*/ */
typedef enum controller_db_key typedef enum controller_db_key
{ {
KEY_META_UUID = 0, KEY_META_ID = 0,
KEY_META_NAME = 1, KEY_META_NAME = 1,
KEY_META_COMMAND_PORT = 2, KEY_META_COMMAND_PORT = 2,
KEY_META_DISCOVERY_PORT = 3, KEY_META_DISCOVERY_PORT = 3,

View file

@ -11,7 +11,7 @@ controller*
controller_create(void) controller_create(void)
{ {
controller *result = malloc(sizeof(*result)); controller *result = malloc(sizeof(*result));
uuid_generate(result->uuid); uuid_generate(result->id);
strcpy(result->name, "new emgauwa device"); strcpy(result->name, "new emgauwa device");
result->command_port = 0; result->command_port = 0;
@ -36,7 +36,7 @@ controller_debug(controller *cntrlr)
LOG_DEBUG("controller is NULL"); LOG_DEBUG("controller is NULL");
} }
char uuid_str[37]; char uuid_str[37];
uuid_unparse(cntrlr->uuid, uuid_str); uuid_unparse(cntrlr->id, uuid_str);
LOG_DEBUG("(1/4) %s @ %p", uuid_str, cntrlr); LOG_DEBUG("(1/4) %s @ %p", uuid_str, cntrlr);
LOG_DEBUG("(2/4) name: %s", cntrlr->name); LOG_DEBUG("(2/4) name: %s", cntrlr->name);
LOG_DEBUG("(3/4) relays: %3d", cntrlr->relay_count); LOG_DEBUG("(3/4) relays: %3d", cntrlr->relay_count);

View file

@ -56,8 +56,8 @@ controller_load(MDB_env *mdb_env)
MDB_val value; MDB_val value;
controller_load_single(mdb_txn, mdb_dbi, KEY_META_UUID, &value); controller_load_single(mdb_txn, mdb_dbi, KEY_META_ID, &value);
memmove(new_controller->uuid, (uuid_t*)value.mv_data, sizeof(uuid_t)); memmove(new_controller->id, (uuid_t*)value.mv_data, sizeof(uuid_t));
controller_load_single(mdb_txn, mdb_dbi, KEY_META_NAME, &value); controller_load_single(mdb_txn, mdb_dbi, KEY_META_NAME, &value);
strncpy(new_controller->name, (char*)value.mv_data, CONTROLLER_NAME_LENGTH); strncpy(new_controller->name, (char*)value.mv_data, CONTROLLER_NAME_LENGTH);

View file

@ -48,9 +48,9 @@ controller_save(controller *cntrlr, MDB_env *mdb_env)
exit(1); exit(1);
} }
value.mv_size = sizeof(cntrlr->uuid); value.mv_size = sizeof(cntrlr->id);
value.mv_data = cntrlr->uuid; value.mv_data = cntrlr->id;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_UUID, value)) if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_ID, value))
{ {
return 1; return 1;
} }