|
Packit |
534379 |
// Copyright(c) 2018-2020, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifndef _WIN32
|
|
Packit |
534379 |
#include <unistd.h>
|
|
Packit |
534379 |
#include <uuid/uuid.h>
|
|
Packit |
534379 |
#else
|
|
Packit |
534379 |
#include <io.h>
|
|
Packit |
534379 |
#endif
|
|
Packit |
534379 |
#include <fcntl.h>
|
|
Packit |
534379 |
#include <sys/types.h>
|
|
Packit |
534379 |
#include <stdlib.h>
|
|
Packit |
534379 |
#include <string.h>
|
|
Packit |
534379 |
#include <getopt.h>
|
|
Packit |
534379 |
#include <wchar.h>
|
|
Packit |
534379 |
#include "bmcinfo.h"
|
|
Packit |
534379 |
#include "bmcdata.h"
|
|
Packit |
534379 |
#include <opae/fpga.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
static wchar_t *base_units[] = {L"unspecified",
|
|
Packit |
534379 |
L"\x00b0\x0043", // degrees C
|
|
Packit |
534379 |
L"\x00b0\x0046", // degrees F
|
|
Packit |
534379 |
L"\x00b0\x004b", // degrees K
|
|
Packit |
534379 |
L"Volts",
|
|
Packit |
534379 |
L"Amps",
|
|
Packit |
534379 |
L"Watts",
|
|
Packit |
534379 |
L"Joules",
|
|
Packit |
534379 |
L"Coulombs",
|
|
Packit |
534379 |
L"VA",
|
|
Packit |
534379 |
L"Nits",
|
|
Packit |
534379 |
L"limen",
|
|
Packit |
534379 |
L"lux",
|
|
Packit |
534379 |
L"Candela",
|
|
Packit |
534379 |
L"kPa",
|
|
Packit |
534379 |
L"PSI",
|
|
Packit |
534379 |
L"Newton",
|
|
Packit |
534379 |
L"CFM",
|
|
Packit |
534379 |
L"RPM",
|
|
Packit |
534379 |
L"Hz",
|
|
Packit |
534379 |
L"microsecond",
|
|
Packit |
534379 |
L"millisecond",
|
|
Packit |
534379 |
L"second",
|
|
Packit |
534379 |
L"minute",
|
|
Packit |
534379 |
L"hour",
|
|
Packit |
534379 |
L"day",
|
|
Packit |
534379 |
L"week",
|
|
Packit |
534379 |
L"mil",
|
|
Packit |
534379 |
L"inches",
|
|
Packit |
534379 |
L"feet",
|
|
Packit |
534379 |
L"in\x00b3",
|
|
Packit |
534379 |
L"ft\x00b3",
|
|
Packit |
534379 |
L"mm",
|
|
Packit |
534379 |
L"cm",
|
|
Packit |
534379 |
L"m",
|
|
Packit |
534379 |
L"cm\x00b3",
|
|
Packit |
534379 |
L"m\x00b3",
|
|
Packit |
534379 |
L"liters",
|
|
Packit |
534379 |
L"fluid ounce",
|
|
Packit |
534379 |
L"radians",
|
|
Packit |
534379 |
L"steradians",
|
|
Packit |
534379 |
L"revolutions",
|
|
Packit |
534379 |
L"cycles",
|
|
Packit |
534379 |
L"gravities",
|
|
Packit |
534379 |
L"ounce",
|
|
Packit |
534379 |
L"pound",
|
|
Packit |
534379 |
L"ft-lb",
|
|
Packit |
534379 |
L"oz-in",
|
|
Packit |
534379 |
L"gauss",
|
|
Packit |
534379 |
L"gilberts",
|
|
Packit |
534379 |
L"henry",
|
|
Packit |
534379 |
L"millihenry",
|
|
Packit |
534379 |
L"farad",
|
|
Packit |
534379 |
L"microfarad",
|
|
Packit |
534379 |
L"ohms",
|
|
Packit |
534379 |
L"siemens",
|
|
Packit |
534379 |
L"mole",
|
|
Packit |
534379 |
L"becquerel",
|
|
Packit |
534379 |
L"PPM",
|
|
Packit |
534379 |
L"reserved",
|
|
Packit |
534379 |
L"Decibels",
|
|
Packit |
534379 |
L"DbA",
|
|
Packit |
534379 |
L"DbC",
|
|
Packit |
534379 |
L"gray",
|
|
Packit |
534379 |
L"sievert",
|
|
Packit |
534379 |
L"color temp \x00b0\x004b", // degrees K
|
|
Packit |
534379 |
L"bit",
|
|
Packit |
534379 |
L"kilobit",
|
|
Packit |
534379 |
L"megabit",
|
|
Packit |
534379 |
L"gigabit",
|
|
Packit |
534379 |
L"byte",
|
|
Packit |
534379 |
L"kilobyte",
|
|
Packit |
534379 |
L"megabyte",
|
|
Packit |
534379 |
L"gigabyte",
|
|
Packit |
534379 |
L"word",
|
|
Packit |
534379 |
L"dword",
|
|
Packit |
534379 |
L"qword",
|
|
Packit |
534379 |
L"line",
|
|
Packit |
534379 |
L"hit",
|
|
Packit |
534379 |
L"miss",
|
|
Packit |
534379 |
L"retry",
|
|
Packit |
534379 |
L"reset",
|
|
Packit |
534379 |
L"overrun / overflow",
|
|
Packit |
534379 |
L"underrun",
|
|
Packit |
534379 |
L"collision",
|
|
Packit |
534379 |
L"packets",
|
|
Packit |
534379 |
L"messages",
|
|
Packit |
534379 |
L"characters",
|
|
Packit |
534379 |
L"error",
|
|
Packit |
534379 |
L"correctable error",
|
|
Packit |
534379 |
L"uncorrectable error",
|
|
Packit |
534379 |
L"fatal error",
|
|
Packit |
534379 |
L"grams"};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
static size_t max_base_units = (sizeof(base_units) / sizeof(base_units[0]));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Values *bmc_build_values(sensor_reading *reading, sdr_header *header,
|
|
Packit |
534379 |
sdr_key *key, sdr_body *body)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
Values *val = (Values *)calloc(1, sizeof(Values));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
(void)header;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (NULL == val)
|
|
Packit |
534379 |
return NULL;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
val->is_valid = true;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (!reading->sensor_validity.sensor_state.sensor_scanning_disabled) {
|
|
Packit |
534379 |
val->annotation_1 = "scanning enabled";
|
|
Packit |
534379 |
// val->is_valid = false;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (reading->sensor_validity.sensor_state.reading_state_unavailable) {
|
|
Packit |
534379 |
val->annotation_2 = "reading state unavailable";
|
|
Packit |
534379 |
val->is_valid = false;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (!reading->sensor_validity.sensor_state.event_messages_disabled) {
|
|
Packit |
534379 |
val->annotation_3 = "event messages enabled";
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (body->id_string_type_length_code.bits.format == ASCII_8) {
|
|
Packit |
534379 |
uint8_t len =
|
|
Packit |
534379 |
body->id_string_type_length_code.bits.len_in_characters;
|
|
Packit |
534379 |
if ((len == 0x1f) || (len == 0)) {
|
|
Packit |
534379 |
val->name = strdup("**INVALID**");
|
|
Packit |
534379 |
val->is_valid = false;
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
val->name = strdup((char *)&body->string_bytes[0]);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
val->name = strdup("**String type unimplemented**");
|
|
Packit |
534379 |
DBG_PRINT("String type other than ASCII8\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
val->sensor_number = key->sensor_number;
|
|
Packit |
534379 |
val->sensor_type =
|
|
Packit |
534379 |
SDR_SENSOR_IS_TEMP(body)
|
|
Packit |
534379 |
? BMC_THERMAL
|
|
Packit |
534379 |
: SDR_SENSOR_IS_POWER(body) ? BMC_POWER : BMC_ALL;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
switch (body->sensor_units_1.bits.analog_data_format) {
|
|
Packit |
534379 |
case 0x0: // unsigned
|
|
Packit |
534379 |
case 0x1: // 1's compliment (signed)
|
|
Packit |
534379 |
case 0x2: // 2's complement (signed)
|
|
Packit |
534379 |
break;
|
|
Packit |
534379 |
case 0x3: // Does not return a reading
|
|
Packit |
534379 |
val->is_valid = false;
|
|
Packit |
534379 |
break;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (body->sensor_units_2 < max_base_units) {
|
|
Packit |
534379 |
val->units = base_units[body->sensor_units_2];
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
val->units = L"*OUT OF RANGE*";
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
calc_params(body, val);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
val->raw_value = (uint64_t)reading->sens_reading;
|
|
Packit |
534379 |
val->val_type = SENSOR_FLOAT;
|
|
Packit |
534379 |
val->value.f_val = getvalue(val, val->raw_value);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return val;
|
|
Packit |
534379 |
}
|