add: controller_info version reading

This commit is contained in:
Tobias Reisinger 2019-12-08 23:39:10 +01:00
parent d8ad2c205a
commit 270c87e0bc

View file

@ -4,7 +4,8 @@
#include <string.h>
#include <uuid/uuid.h>
#include "controller.h"
#include <models/controller.h>
#include <models/controller_file_reader.h>
#include <macros.h>
@ -32,7 +33,7 @@ controller*
controller_read(void)
{
FILE *fp;
controller *result;;
controller *result;
fp = fopen(CONTROLLER_FILE_NAME, "rb");
@ -50,6 +51,7 @@ controller_read(void)
read_size = fread(header, sizeof(*header), CONTROLLER_FILE_HEADER_SIZE, fp);
if(ferror(fp) || read_size != CONTROLLER_FILE_HEADER_SIZE)
{
fclose(fp);
LOG_ERROR("Error reading header");
result = controller_create();
@ -59,8 +61,17 @@ controller_read(void)
uint8_t version = header[0];
printf("%d\n", version);
switch(version)
{
case 1:
controller_file_reader_1(fp);
break;
default:
fclose(fp);
LOG_ERROR("Error unsupported version number");
// size_t fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file);
return NULL;
}
fclose(fp);