mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
[as5822-54x] simplify the code for onlp_file_read_int
This commit is contained in:
@@ -81,15 +81,12 @@ onlp_fan_info_t finfo[] = {
|
||||
static int
|
||||
_onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
|
||||
{
|
||||
int value;
|
||||
char path[64] = {0};
|
||||
int value, ret;
|
||||
|
||||
/* get fan present status
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_present", FAN_BOARD_PATH, fid);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -101,10 +98,8 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
|
||||
|
||||
/* get fan fault status (turn on when any one fails)
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_fault", FAN_BOARD_PATH, fid);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -115,10 +110,8 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
|
||||
|
||||
/* get fan direction (both : the same)
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_direction", FAN_BOARD_PATH, fid);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -127,20 +120,16 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
|
||||
|
||||
/* get front fan speed
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
info->rpm = value;
|
||||
|
||||
/* get rear fan speed
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -152,10 +141,8 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
|
||||
|
||||
/* get speed percentage from rpm
|
||||
*/
|
||||
sprintf(path, "%s""fan_max_speed_rpm", FAN_BOARD_PATH);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,9 +169,7 @@ onlp_ledi_init(void)
|
||||
int
|
||||
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
|
||||
{
|
||||
int lid, value;
|
||||
char path[64] = {0};
|
||||
|
||||
int lid, value;
|
||||
VALIDATE(id);
|
||||
|
||||
lid = ONLP_OID_ID_GET(id);
|
||||
@@ -180,10 +178,7 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
|
||||
*info = linfo[ONLP_OID_ID_GET(id)];
|
||||
|
||||
/* Get LED mode */
|
||||
sprintf(path, LED_FORMAT, leds[lid]);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
DEBUG_PRINT("Unable to read status from file (%s)", path);
|
||||
if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -166,19 +166,16 @@ psu_type_t get_psu_type(int id, char* modelname, int modelname_len)
|
||||
int psu_ym2401_pmbus_info_get(int id, char *node, int *value)
|
||||
{
|
||||
int ret = 0;
|
||||
char path[PSU_NODE_MAX_PATH_LEN] = {0};
|
||||
|
||||
*value = 0;
|
||||
|
||||
if (PSU1_ID == id) {
|
||||
sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
|
||||
ret = onlp_file_read_int(value, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
else {
|
||||
sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
|
||||
ret = onlp_file_read_int(value, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
|
||||
if (onlp_file_read_int(value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,19 +44,17 @@ static int
|
||||
psu_status_info_get(int id, char *node, int *value)
|
||||
{
|
||||
int ret = 0;
|
||||
char path[PSU_NODE_MAX_PATH_LEN] = {0};
|
||||
|
||||
*value = 0;
|
||||
|
||||
if (PSU1_ID == id) {
|
||||
sprintf(path, "%s%s", PSU1_AC_HWMON_PREFIX, node);
|
||||
ret = onlp_file_read_int(value, "%s%s", PSU1_AC_HWMON_PREFIX, node);
|
||||
}
|
||||
else if (PSU2_ID == id) {
|
||||
sprintf(path, "%s%s", PSU2_AC_HWMON_PREFIX, node);
|
||||
ret = onlp_file_read_int(value, "%s%s", PSU2_AC_HWMON_PREFIX, node);
|
||||
}
|
||||
|
||||
if (onlp_file_read_int(value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
|
||||
if (ret < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user