summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d910699)
We still end up guessing based on magnitude of the value, though: it
might be 'bar' or 'mbar', we end up picking one or the other based on
just how big the value is.
I should make it look at any possible explicit units too, since at least
with good xml, they exist. Of course, the only good xml I've seen so
far is the one we generate ourselves ;)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
double fp;
};
enum number_type {
NEITHER,
double fp;
};
enum number_type {
NEITHER,
- res->i = val;
- return INTEGER;
+ res->fp = val;
+ return FLOAT;
}
static void pressure(char *buffer, void *_press)
{
}
static void pressure(char *buffer, void *_press)
{
pressure_t *pressure = _press;
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
case FLOAT:
pressure_t *pressure = _press;
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
case FLOAT:
- /* Maybe it's in Bar? */
- if (val.fp < 500.0) {
- pressure->mbar = val.fp * 1000 + 0.5;
+ switch (units.pressure) {
+ case BAR:
+ /* Assume mbar, but if it's really small, it's bar */
+ mbar = val.fp;
+ if (mbar < 5000)
+ mbar = mbar * 1000;
+ break;
+ case PSI:
+ mbar = val.fp * 68.95;
- printf("Unknown fractional pressure reading %s\n", buffer);
- break;
-
- case INTEGER:
- /*
- * Random integer? Maybe in PSI? Or millibar already?
- *
- * We assume that 5 bar is a ridiculous tank pressure,
- * so if it's smaller than 5000, it's in PSI..
- */
- if (val.i < 5000) {
- pressure->mbar = val.i * 68.95;
+ if (mbar > 5 && mbar < 500000) {
+ pressure->mbar = mbar + 0.5;
- pressure->mbar = val.i;
- break;
default:
printf("Strange pressure reading %s\n", buffer);
}
default:
printf("Strange pressure reading %s\n", buffer);
}
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
- /* All values are probably in meters */
- case INTEGER:
- val.fp = val.i;
- /* fallthrough */
- depth->mm = val.fp * 1000 + 0.5;
+ switch (units.length) {
+ case METERS:
+ depth->mm = val.fp * 1000 + 0.5;
+ break;
+ case FEET:
+ depth->mm = val.fp * 304.8 + 0.5;
+ break;
+ }
break;
default:
printf("Strange depth reading %s\n", buffer);
break;
default:
printf("Strange depth reading %s\n", buffer);
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
- /* C or F? Who knows? Let's default to Celsius */
- case INTEGER:
- val.fp = val.i;
- /* Fallthrough */
case FLOAT:
/* Ignore zero. It means "none" */
if (!val.fp)
break;
/* Celsius */
case FLOAT:
/* Ignore zero. It means "none" */
if (!val.fp)
break;
/* Celsius */
+ switch (units.temperature) {
+ case CELSIUS:
temperature->mkelvin = (val.fp + 273.15) * 1000 + 0.5;
break;
temperature->mkelvin = (val.fp + 273.15) * 1000 + 0.5;
break;
- }
- /* Fahrenheit */
- if (val.fp < 212.0) {
temperature->mkelvin = (val.fp + 459.67) * 5000/9;
break;
}
temperature->mkelvin = (val.fp + 459.67) * 5000/9;
break;
}
- /* Kelvin or already millikelvin */
- if (val.fp < 1000.0)
- val.fp *= 1000;
- temperature->mkelvin = val.fp;
break;
default:
printf("Strange temperature reading %s\n", buffer);
break;
default:
printf("Strange temperature reading %s\n", buffer);
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
- /* C or F? Who knows? Let's default to Celsius */
- case INTEGER:
- val.fp = val.i;
- /* Fallthrough */
case FLOAT:
if (val.fp <= 100.0)
fraction->permille = val.fp * 10 + 0.5;
case FLOAT:
if (val.fp <= 100.0)
fraction->permille = val.fp * 10 + 0.5;
float atm;
switch (integer_or_float(buffer, &val)) {
float atm;
switch (integer_or_float(buffer, &val)) {
- case INTEGER:
- val.fp = val.i;
- /* Fallthrough */
case FLOAT:
switch (units.pressure) {
case BAR:
case FLOAT:
switch (units.pressure) {
case BAR:
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
- case INTEGER:
- val.fp = val.i;
- /* Fallthrough */
case FLOAT:
*when = (val.fp - 40587.5) * 86400;
break;
case FLOAT:
*when = (val.fp - 40587.5) * 86400;
break;