From: Hans de Goede <j.w.r.degoede@hhs.nl>
To: lm-sensors@vger.kernel.org
Subject: [lm-sensors] Utility for creating computate sensors.conf lines for
Date: Wed, 31 Oct 2007 08:50:10 +0000 [thread overview]
Message-ID: <472841C2.5060701@hhs.nl> (raw)
[-- Attachment #1: Type: text/plain, Size: 252 bytes --]
Hi all,
As discussed here is an utility for creating computate sensors.conf lines for
fscher and newer from DMI tables.
I wrote it in C as I'm most fluent in that language. I've it attached, shall I
import it somewhere under progs?
Regards,
Hans
[-- Attachment #2: fscher-dmi2compute.c --]
[-- Type: text/x-csrc, Size: 3004 bytes --]
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
char buf[512];
unsigned int x;
FILE *f;
int i, count, entities_found;;
int in0_mult, in1_mult, in2_mult, in0_offset, in1_offset, in2_offset, vref;
if (getuid())
{
fprintf(stderr, "Error this program must be run as root because it "
"invokes / uses dmidecode which requires root rights\n");
return 1;
}
f = popen("/usr/sbin/dmidecode", "r");
if (!f)
{
perror("Error invoking dmidecode failed");
return 1;
}
while (fgets(buf, sizeof(buf), f))
{
if (strcmp(buf, "OEM-specific Type\n"))
continue;
if (!fgets(buf, sizeof(buf), f))
break;
if (strcmp(buf, "\tHeader and Data:\n"))
continue;
count = 0;
entities_found = 0;
while (fscanf(f, "%x", &x) == 1)
{
buf[count] = x;
count++;
}
/* we are looking for what Siemens calls "subtype" 19, the subtype
is stored in byte 5 of the dmi block */
if (buf[4] != 19)
continue;
/* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
consisting of what Siemens calls an "Entity" number, followed by
2 16 bit words in LSB first order */
for (i = 6; (i + 4) < count; i += 5)
{
if (buf[i] == 1) /* entity 1 5 volt / in1 multiplier and offset */
{
in1_mult = buf[i + 1] | (buf[i + 2] << 8);
in1_offset = buf[i + 3] | (buf[i + 4] << 8);
entities_found += 0x0001;
}
if (buf[i] == 2) /* entity 2 12 volt / in0 multiplier and offset */
{
in0_mult = buf[i + 1] | (buf[i + 2] << 8);
in0_offset = buf[i + 3] | (buf[i + 4] << 8);
entities_found += 0x0010;
}
if (buf[i] == 3) /* entity 3 vbat / in2 multiplier and offset */
{
in2_mult = buf[i + 1] | (buf[i + 2] << 8);
in2_offset = buf[i + 3] | (buf[i + 4] << 8);
entities_found += 0x0100;
}
if (buf[i] == 7) /* entity 7 reference voltage */
{
vref = buf[i + 1] | (buf[i + 2] << 8);
entities_found += 0x1000;
}
}
if (entities_found == 0x1111)
{
printf(" compute in0 (@ * (%d * %d) / 255) + (%d * 10), (@ - (%d * 10)) * 255 / (%d * %d)\n",
in0_mult, vref, in0_offset, in0_offset, in0_mult, vref);
printf(" compute in1 (@ * (%d * %d) / 255) + (%d * 10), (@ - (%d * 10)) * 255 / (%d * %d)\n",
in1_mult, vref, in1_offset, in1_offset, in1_mult, vref);
printf(" compute in2 (@ * (%d * %d) / 255) + (%d * 10), (@ - (%d * 10)) * 255 / (%d * %d)\n",
in2_mult, vref, in2_offset, in2_offset, in2_mult, vref);
fclose(f);
return 0;
}
}
fclose(f);
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 153 bytes --]
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next reply other threads:[~2007-10-31 8:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-31 8:50 Hans de Goede [this message]
2007-10-31 20:08 ` [lm-sensors] Utility for creating computate sensors.conf lines Jean Delvare
2007-10-31 20:38 ` Hans de Goede
2007-10-31 21:06 ` Jean Delvare
2007-11-02 7:46 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=472841C2.5060701@hhs.nl \
--to=j.w.r.degoede@hhs.nl \
--cc=lm-sensors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.