Commit c58702a0 authored by Alessandro Rubini's avatar Alessandro Rubini

temperature: add a fake temperature-set to show how to use it

We have three temperatures, called "roof", "core", "case"
(yess rubi like word same lengt, s/he most love four).

There is a "faketemp" command that can set one two or all of them.
This allows to test negative temperatures in printouts (White Rabbit
in Siberia does it, but we southish can't test easily).

All temperatures are initialized to invalid. Example:

   wrc# faketemp -10 -2.5
   wrc# faketemp
   fff60000 fffd8003 80000000
   wrc# temp
   pcb:84.7500 roof:-10.0000 core:-2.4999 case:INVALID
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent a661eeed
......@@ -332,6 +332,13 @@ config WRC_VERBOSE
help
This enables some more diagnostic messages. Normally off.
config FAKE_TEMPERATURES
depends on DEVELOPER
boolean "Offer an array of 3 fake temperatures, for testing"
help
The option adds also a "faketemp" command, used to set
the fake temperatures: e.g. "faketemp 120 -10 50"
config VLAN
depends on DEVELOPER
boolean "Filter and rx/tx frames in a VLAN (as opposed to untagged)"
......
......@@ -22,6 +22,8 @@ obj-$(CONFIG_W1) += dev/temp-w1.o
obj-$(CONFIG_UART) += dev/uart.o
obj-$(CONFIG_UART_SW) += dev/uart-sw.o
obj-$(CONFIG_FAKE_TEMPERATURES) += dev/fake-temp.o
# Filter rules are selected according to configuration, but we may
# have more than one. Note: the filename is reflected in symbol names,
# so they are hardwired in ../Makefile (and ../tools/pfilter-builder too)
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2016 GSI (www.gsi.de)
* Author: Alessandro rubini
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <wrc.h>
#include <temperature.h>
#include <shell.h>
static struct wrc_onetemp temp_fake_data[] = {
{"roof", TEMP_INVALID},
{"core", TEMP_INVALID},
{"case", TEMP_INVALID},
{NULL,}
};
static int temp_fake_refresh(struct wrc_temp *t)
{
/* nothing to do */
return 0;
}
/* not static at this point, because it's the only one */
DEFINE_TEMPERATURE(w1) = {
.read = temp_fake_refresh,
.t = temp_fake_data,
};
static int cmd_faketemp(const char *args[])
{
int i;
const char *dot;
if (!args[0]) {
pp_printf("%08x %08x %08x\n", temp_fake_data[0].t,
temp_fake_data[1].t, temp_fake_data[2].t);
return 0;
}
for (i = 0; i < 3 && args[i]; i++) {
int sign = 1, val;
/* accept negative, and at most one decimal */
if (args[i][0] == '-')
sign = -1, args[i]++;
dot = fromdec(args[i], &val);
val <<= 16;
if (dot[0] == '.' && dot[1] >= '0' && dot[1] <= '9')
val += 0x10000 / 10 * (dot[1] - '0');
temp_fake_data[i].t = val * sign;
}
return 0;
}
DEFINE_WRC_COMMAND(faketemp) = {
.name = "faketemp",
.exec = cmd_faketemp,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment