2020-07-05 11:31:33 +02:00
|
|
|
/** Bare text values.
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2014-2019, 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/>.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
#include <villas/formats/value.hpp>
|
2020-07-05 11:31:33 +02:00
|
|
|
#include <villas/sample.h>
|
|
|
|
#include <villas/signal.h>
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
using namespace villas::node;
|
2020-07-05 11:31:33 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
int ValueFormat::sprint(char *buf, size_t len, size_t *wbytes, const struct sample * const smps[], unsigned cnt)
|
2020-07-05 11:31:33 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
size_t off = 0;
|
|
|
|
struct signal *sig;
|
2021-05-10 00:12:30 +02:00
|
|
|
const struct sample *smp = smps[0];
|
2020-07-05 11:31:33 +02:00
|
|
|
|
|
|
|
assert(cnt == 1);
|
|
|
|
assert(smp->length <= 1);
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
|
|
|
for (i = 0; i < smp->length; i++) {
|
|
|
|
sig = (struct signal *) vlist_at_safe(smp->signals, i);
|
|
|
|
if (!sig)
|
2020-07-06 15:07:05 +02:00
|
|
|
return -1;
|
2020-07-05 11:31:33 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
off += signal_data_print_str(&smp->data[i], sig->type, buf, len, real_precision);
|
2020-07-05 11:31:33 +02:00
|
|
|
off += snprintf(buf + off, len - off, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wbytes)
|
|
|
|
*wbytes = off;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
int ValueFormat::sscan(const char *buf, size_t len, size_t *rbytes, struct sample * const smps[], unsigned cnt)
|
2020-07-05 11:31:33 +02:00
|
|
|
{
|
|
|
|
unsigned i = 0, ret;
|
|
|
|
struct sample *smp = smps[0];
|
|
|
|
|
|
|
|
const char *ptr = buf;
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
assert(cnt == 1);
|
|
|
|
|
|
|
|
printf("Reading: %s", buf);
|
|
|
|
|
|
|
|
if (smp->capacity >= 1) {
|
2021-05-10 00:12:30 +02:00
|
|
|
struct signal *sig = (struct signal *) vlist_at_safe(signals, i);
|
2020-07-05 11:31:33 +02:00
|
|
|
if (!sig)
|
2020-07-06 15:07:05 +02:00
|
|
|
return -1;
|
2020-07-05 11:31:33 +02:00
|
|
|
|
2021-02-19 06:37:21 +01:00
|
|
|
ret = signal_data_parse_str(&smp->data[i], sig->type, ptr, &end);
|
2020-07-05 11:31:33 +02:00
|
|
|
if (ret || end == ptr) /* There are no valid values anymore. */
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
ptr = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
out: smp->flags = 0;
|
2021-05-10 00:12:30 +02:00
|
|
|
smp->signals = signals;
|
2020-07-05 11:31:33 +02:00
|
|
|
smp->length = i;
|
|
|
|
if (smp->length > 0)
|
|
|
|
smp->flags |= (int) SampleFlags::HAS_DATA;
|
|
|
|
|
|
|
|
if (rbytes)
|
|
|
|
*rbytes = ptr - buf;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
static char n[] = "value";
|
|
|
|
static char d[] = "A bare text value without any headers";
|
|
|
|
static FormatPlugin<ValueFormat, n, d, (int) SampleFlags::HAS_DATA> p;
|