mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
gtwif: started working on a parser for RSCAD .inf files
This commit is contained in:
parent
8f4ae1f16b
commit
1e0e44003e
3 changed files with 248 additions and 1 deletions
86
include/villas/rscad.h
Normal file
86
include/villas/rscad.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/** Parsers for RSCAD file formats
|
||||
*
|
||||
* @file
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @license GNU General Public License (version 3)
|
||||
*
|
||||
* VILLASnode
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "list.h"
|
||||
|
||||
struct rscad_inf_attribute {
|
||||
char *key;
|
||||
char *value;
|
||||
};
|
||||
|
||||
struct rscad_inf_timing_record {
|
||||
|
||||
};
|
||||
|
||||
struct rscad_inf_element {
|
||||
enum {
|
||||
RSCAD_INF_ELEMENT_STRING,
|
||||
RSCAD_INF_ELEMENT_OUTPUT,
|
||||
RSCAD_INF_ELEMENT_PUSHBUTTON,
|
||||
RSCAD_INF_ELEMENT_SLIDER
|
||||
} type;
|
||||
|
||||
enum {
|
||||
RSCAD_INF_DATATYPE_IEEE,
|
||||
RSCAD_INF_DATATYPE_INT
|
||||
} datatype;
|
||||
|
||||
union {
|
||||
float f;
|
||||
int i;
|
||||
} init_value, min, max;
|
||||
|
||||
int rack;
|
||||
uint32_t address;
|
||||
|
||||
char *group;
|
||||
char *description;
|
||||
char *units;
|
||||
};
|
||||
|
||||
struct rscad_inf {
|
||||
struct list elements; /**< List of struct rscad_inf_element */
|
||||
struct list attributes; /**< List of struct rscad_inf_attribute */
|
||||
struct list timing_records; /**< List of struct rscad_inf_timing_record */
|
||||
|
||||
int rack;
|
||||
char *name;
|
||||
double delta;
|
||||
|
||||
bool vsc;
|
||||
bool nrt;
|
||||
bool distribution;
|
||||
};
|
||||
|
||||
int rscad_inf_init(struct rscad_inf *i);
|
||||
|
||||
int rscad_inf_parse(struct rscad_inf *i, FILE *f);
|
||||
|
||||
int rscad_inf_destroy(struct rscad_inf *i);
|
||||
|
||||
struct rscad_inf_element * rscad_inf_lookup_element(struct rscad_inf *i, const char *name);
|
|
@ -31,7 +31,7 @@ LIB_SRCS += $(addprefix lib/nodes/, file.c cbuilder.c shmem.c) \
|
|||
log.c log_config.c utils.c super_node.c hist.c timing.c pool.c \
|
||||
list.c queue.c queue_signalled.c memory.c advio.c web.c api.c \
|
||||
plugin.c node_type.c stats.c mapping.c sample_io.c shmem.c \
|
||||
json.c crypt.c compat.c \
|
||||
json.c crypt.c compat.c rscad.c \
|
||||
)
|
||||
|
||||
LIB_LDFLAGS = -shared
|
||||
|
|
161
lib/rscad.c
Normal file
161
lib/rscad.c
Normal file
|
@ -0,0 +1,161 @@
|
|||
/** Parsers for RSCAD file formats
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @license GNU General Public License (version 3)
|
||||
*
|
||||
* VILLASnode
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "rscad.h"
|
||||
|
||||
static int rscad_inf_destroy_attribute(struct rscad_inf_attribute *a)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rscad_inf_destroy_element(struct rscad_inf_element *e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rscad_inf_destroy_timing_record(struct rscad_inf_timing_record *a)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rscad_inf_parse_attributes(struct list *l, FILE *f)
|
||||
{
|
||||
int ret = 0;
|
||||
char *line = NULL;
|
||||
size_t linelen = 0;
|
||||
|
||||
while (!feof(f)) {
|
||||
getline(&line, &linelen, f);
|
||||
|
||||
if (!strcmp(line, "\n")) {
|
||||
getline(&line, &linelen, f);
|
||||
ret = strcmp(line, "\n") == 0 ? 0 : -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
info("Parsing attribute: %s", line);
|
||||
}
|
||||
|
||||
out: free(line);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rscad_inf_parse_elements(struct list *l, FILE *f)
|
||||
{
|
||||
int ret = 0;
|
||||
char *line = NULL;
|
||||
size_t linelen = 0;
|
||||
|
||||
while (!feof(f)) {
|
||||
getline(&line, &linelen, f);
|
||||
|
||||
if (!strcmp(line, "\n")) {
|
||||
getline(&line, &linelen, f);
|
||||
ret = strcmp(line, "\n") == 0 ? 0 : -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
info("Parsing element: %s", line);
|
||||
}
|
||||
|
||||
out: free(line);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rscad_inf_parse_timing_records(struct list *l, FILE *f)
|
||||
{
|
||||
int ret = 0;
|
||||
char *line = NULL;
|
||||
size_t linelen = 0;
|
||||
|
||||
while (!feof(f)) {
|
||||
getline(&line, &linelen, f);
|
||||
|
||||
if (!strcmp(line, "\n")) {
|
||||
getline(&line, &linelen, f);
|
||||
ret = strcmp(line, "\n") == 0 ? 0 : -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
info("Parsing timing_record: %s", line);
|
||||
}
|
||||
|
||||
out: free(line);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int rscad_inf_init(struct rscad_inf *i)
|
||||
{
|
||||
list_init(&i->attributes);
|
||||
list_init(&i->elements);
|
||||
list_init(&i->timing_records);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rscad_inf_destroy(struct rscad_inf *i)
|
||||
{
|
||||
list_destroy(&i->attributes, (dtor_cb_t) rscad_inf_destroy_attribute, true);
|
||||
list_destroy(&i->elements, (dtor_cb_t) rscad_inf_destroy_element, true);
|
||||
list_destroy(&i->timing_records, (dtor_cb_t) rscad_inf_destroy_timing_record, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rscad_inf_parse(struct rscad_inf *i, FILE *f)
|
||||
{
|
||||
int ret;
|
||||
|
||||
rewind(f);
|
||||
|
||||
ret = rscad_inf_parse_attributes(&i->attributes, f);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = rscad_inf_parse_elements(&i->elements, f);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = rscad_inf_parse_timing_records(&i->timing_records, f);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct rscad_inf_element * rscad_inf_lookup_element(struct rscad_inf *i, const char *name)
|
||||
{
|
||||
for (size_t j = 0; j < list_length(&i->elements); j++) {
|
||||
struct rscad_inf_element *e __attribute__((unused)) = (struct rscad_inf_element *) list_at(&i->elements, j);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
Loading…
Add table
Reference in a new issue