summaryrefslogtreecommitdiffstats
path: root/common/recipes-core/sensor-util
diff options
context:
space:
mode:
Diffstat (limited to 'common/recipes-core/sensor-util')
-rw-r--r--common/recipes-core/sensor-util/files/Makefile11
-rw-r--r--common/recipes-core/sensor-util/files/sensor-util.c173
-rw-r--r--common/recipes-core/sensor-util/sensor-util_0.1.bb34
3 files changed, 218 insertions, 0 deletions
diff --git a/common/recipes-core/sensor-util/files/Makefile b/common/recipes-core/sensor-util/files/Makefile
new file mode 100644
index 0000000..2d39a04
--- /dev/null
+++ b/common/recipes-core/sensor-util/files/Makefile
@@ -0,0 +1,11 @@
+# Copyright 2015-present Facebook. All Rights Reserved.
+all: sensor-util
+
+
+sensor-util: sensor-util.o
+ $(CC) $(CFLAGS) -lpal -lrt -lm -std=gnu99 -o $@ $^ $(LDFLAGS)
+
+.PHONY: clean
+
+clean:
+ rm -rf *.o sensor-util
diff --git a/common/recipes-core/sensor-util/files/sensor-util.c b/common/recipes-core/sensor-util/files/sensor-util.c
new file mode 100644
index 0000000..eb38d65
--- /dev/null
+++ b/common/recipes-core/sensor-util/files/sensor-util.c
@@ -0,0 +1,173 @@
+/*
+ * yosemite-sensors
+ *
+ * Copyright 2015-present Facebook. All Rights Reserved.
+ *
+ * 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 2 of the License, or
+ * (at your option) 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <openbmc/pal.h>
+
+static int
+print_usage() {
+ printf("Usage: sensor-util [ %s ] <sensor num>\n"
+ "sensor num is optional.", pal_fru_list);
+}
+
+static void
+print_single_sensor_reading(uint8_t fru, uint8_t *sensor_list, int sensor_cnt, uint8_t num) {
+
+ int i;
+ float fvalue;
+ char name[24];
+ char units[64];
+ int ret = 0;
+
+ for (i = 0; i < sensor_cnt; i++) {
+
+ if (sensor_list[i] == num) {
+ ret = 1;
+ pal_get_sensor_name(fru, sensor_list[i], name);
+ pal_get_sensor_units(fru, sensor_list[i], units);
+
+ if (pal_sensor_read(fru, sensor_list[i], &fvalue) < 0) {
+
+ printf("pal_sensor_read failed: fru: %d num: 0x%X name: %-23s\n",
+ fru, sensor_list[i], name);
+ } else {
+ printf("%-23s: %.2f %s\n", name, fvalue, units);
+ }
+
+ break;
+ }
+ }
+
+ if (!ret) {
+ printf("Wrong sensor number!\n");
+ print_usage();
+ exit(-1);
+ }
+}
+
+static void
+print_sensor_reading(uint8_t fru, uint8_t *sensor_list, int sensor_cnt) {
+
+ int i;
+ float fvalue;
+ char name[24];
+ char units[64];
+
+ for (i = 0; i < sensor_cnt; i++) {
+
+ /* Clear the variable */
+ sprintf(name, "");
+ sprintf(units, "");
+
+ pal_get_sensor_name(fru, sensor_list[i], name);
+ pal_get_sensor_units(fru, sensor_list[i], units);
+
+ if (pal_sensor_read(fru, sensor_list[i], &fvalue) < 0) {
+
+ printf("pal_sensor_read failed: fru: %d num: 0x%X name: %-23s\n",
+ fru, sensor_list[i], name);
+ } else {
+ printf("%-23s: %.2f %s\n", name, fvalue, units);
+ }
+ }
+}
+
+int
+main(int argc, char **argv) {
+
+ int ret;
+ int sensor_cnt;
+ uint8_t *sensor_list;
+ uint8_t fru;
+ uint8_t num;
+
+ if (argc < 2 || argc > 3) {
+ print_usage();
+ exit(-1);
+ }
+
+ if (argc == 3) {
+ errno = 0;
+ num = (uint8_t) strtol(argv[2], NULL, 0);
+ if (errno) {
+ printf("Sensor number format incorrect.\n");
+ print_usage();
+ exit(-1);
+ }
+ }
+
+
+ ret = pal_get_fru_id(argv[1], &fru);
+ if (ret < 0) {
+ print_usage();
+ return ret;
+ }
+
+ if (fru == 0) {
+ fru = 1;
+ while (fru <= MAX_NUM_FRUS) {
+
+ if (fru == FRU_NIC) {
+ printf("\nsensor-util does not support nic\n");
+ exit(-1);
+ }
+
+ ret = pal_get_fru_sensor_list(fru, &sensor_list, &sensor_cnt);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (num) {
+ print_single_sensor_reading(fru, sensor_list, sensor_cnt, num);
+ } else {
+ print_sensor_reading(fru, sensor_list, sensor_cnt);
+ }
+
+ fru++;
+ printf("\n");
+ }
+ } else {
+
+ if (fru == FRU_NIC) {
+ printf("\nsensor-util does not support nic\n");
+ //exit(-1);
+ }
+
+ ret = pal_get_fru_sensor_list(fru, &sensor_list, &sensor_cnt);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (num) {
+ print_single_sensor_reading(fru, sensor_list, sensor_cnt, num);
+ } else {
+ print_sensor_reading(fru, sensor_list, sensor_cnt);
+ }
+ }
+
+ return 0;
+}
diff --git a/common/recipes-core/sensor-util/sensor-util_0.1.bb b/common/recipes-core/sensor-util/sensor-util_0.1.bb
new file mode 100644
index 0000000..227ec53
--- /dev/null
+++ b/common/recipes-core/sensor-util/sensor-util_0.1.bb
@@ -0,0 +1,34 @@
+# Copyright 2015-present Facebook. All Rights Reserved.
+SUMMARY = "Sensor Utility"
+DESCRIPTION = "Util for reading various sensors"
+SECTION = "base"
+PR = "r1"
+LICENSE = "GPLv2"
+LIC_FILES_CHKSUM = "file://sensor-util.c;beginline=4;endline=16;md5=b395943ba8a0717a83e62ca123a8d238"
+
+SRC_URI = "file://Makefile \
+ file://sensor-util.c \
+ "
+S = "${WORKDIR}"
+
+binfiles = "sensor-util"
+
+DEPENDS =+ " libpal "
+
+pkgdir = "sensor-util"
+
+do_install() {
+ dst="${D}/usr/local/fbpackages/${pkgdir}"
+ bin="${D}/usr/local/bin"
+ install -d $dst
+ install -d $bin
+ install -m 755 sensor-util ${dst}/sensor-util
+ ln -snf ../fbpackages/${pkgdir}/sensor-util ${bin}/sensor-util
+}
+
+FBPACKAGEDIR = "${prefix}/local/fbpackages"
+
+FILES_${PN} = "${FBPACKAGEDIR}/sensor-util ${prefix}/local/bin"
+
+INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
+INHIBIT_PACKAGE_STRIP = "1"
OpenPOWER on IntegriCloud