PS BasicOps utils
Edit this on GitLab
PS BasicOps utils
Explanation
About This Code
The provided C code is a part of a sample application designed to work with North Atlantic Industries' (NAI) embedded function modules. This code particularly deals with printing and formatting the status and monitor information of a power supply (PS) system. Below you will find a detailed explanation of each section of the code and the purpose of the functions included.
Header Inclusions
#include <stdio.h> /* for printf(), getchar() */
#include "PS_BasicOps_utils.h"
/* naibrd include files */
#include "advanced/nai_ether_adv.h"
-
<stdio.h>
: This is a standard C library used for input and output functions such asprintf()
. -
PS_BasicOps_utils.h
: This is a custom utility header, likely containing auxiliary functions and definitions used in the application. -
advanced/nai_ether_adv.h
: This header from NAI is likely used for advanced Ethernet operations.
Function Definitions
-
print_ps_status_general_title()
-
Prints a title and headers for displaying general status information.
-
Makes use of
print_ps_short_horizontal_border()
to print horizontal borders.
-
-
print_ps_status_title()
-
Prints a title and headers for displaying non-general status information.
-
Uses
print_ps_long_horizontal_border()
to print horizontal borders.
-
-
print_ps_monitor_title()
-
Prints a title and headers for displaying monitoring information of voltage, current, and temperature.
-
Uses
print_ps_long_horizontal_border()
to print horizontal borders.
-
-
print_ps_status(uint32_t status)
-
Prints the status as either '1' or '0' based on whether the status value is non-zero or zero respectively.
-
-
print_ps_status_na()
-
Prints "N/A" (Not Available) status.
-
-
print_ps_voltage(float64_t* values, char sign)
-
Prints formatted voltage values for various metrics (Last, Average, Peak, Low).
-
-
print_ps_volt_na()
-
Prints "N/A" for voltage metrics.
-
-
print_ps_current(float64_t* values)
-
Prints formatted current values for various metrics (Last, Average, Peak).
-
-
print_ps_current_na()
-
Prints "N/A" for current metrics.
-
-
print_ps_temperature(float64_t* values)
-
Prints formatted temperature values for various metrics (Last, Average, Peak, Low).
-
-
print_ps_temperature_na()
-
Prints "N/A" for temperature metrics.
-
-
print_ps_long_horizontal_border()
-
Prints a long horizontal line (border) comprising dashes.
-
-
print_ps_short_horizontal_border()
-
Prints a short horizontal line (border) comprising dashes.
-
-
print_ps_column(int pad_tab_num, char *szText)
-
Prints text in a specified column format, padded by
pad_tab_num
times 4 spaces.
-
-
ps_convert_monitor_raw_to_value(uint32_t *values, uint8_t *raw)
-
Converts raw monitoring data into human-readable values and stores them in an array.
-
Presumably
LAST_MASK_INDEX
,AVE_MASK_INDEX
,PEAK_MASK_INDEX
, andLOW_MASK_INDEX
are macros defining indices for accessing elements in thevalues
andraw
arrays.
-
Key Constants and Macros
While the actual macro definitions aren’t provided in the snippet, we can infer their most likely purpose based on their usage:
- LAST_MASK_INDEX
: Index for the last recorded value.
- AVE_MASK_INDEX
: Index for the average value.
- PEAK_MASK_INDEX
: Index for the peak value.
- LOW_MASK_INDEX
: Index for the lowest value.
These constants help index into the arrays storing voltage, current, and temperature metrics.
Summary
This code is designed to produce formatted output for monitoring and status information of a power supply system. It includes functions for printing various statuses, voltage, current, and temperature data in a neatly formatted way, making use of standard I/O and utility functions specifically tailored for NAI embedded function modules.
#include <stdio.h> /* for printf(),getchar() */
#include "PS_BasicOps_utils.h"
/* naibrd include files */
#include "advanced/nai_ether_adv.h"
void print_ps_status_general_title()
{
print_ps_short_horizontal_border();
printf(" STATUS GENERAL\n");
print_ps_short_horizontal_border();
printf(" |General |General Latched\n");
print_ps_short_horizontal_border();
}
void print_ps_status_title()
{
printf("\n");
print_ps_long_horizontal_border();
printf(" NON-GENERAL STATUS\n");
print_ps_long_horizontal_border();
printf(" | | Under Volt| | Over Volt | | Over Curr | | Over Temp\n");
printf(" | Under Volt| Latched | Over Volt | Latched | Over Curr | Latched | Over Temp | Latched\n");
print_ps_long_horizontal_border();
}
void print_ps_monitor_title()
{
printf(" MONITOR\n");
print_ps_long_horizontal_border();
printf(" | Voltage(V) | Current(A) | Temperature(C)\n");
print_ps_long_horizontal_border();
printf(" |Last Avg Peak Low |Last Avg Peak |Last Avg Peak Low\n");
print_ps_long_horizontal_border();
}
void print_ps_status(uint32_t status)
{
if( status)
status = 1;
else
status = 0;
printf("|%u ", status);
}
void print_ps_status_na()
{
printf("|N/A ");
}
void print_ps_voltage(float64_t* values,char sign)
{
printf("|%c%7.3f ", sign, values[LAST_MASK_INDEX]);
printf("%c%7.3f ", sign, values[AVE_MASK_INDEX]);
printf("%c%7.3f ", sign, values[PEAK_MASK_INDEX]);
printf("%c%7.3f ", sign, values[LOW_MASK_INDEX]);
}
void print_ps_volt_na()
{
printf("|N/A N/A N/A N/A ");
}
void print_ps_current(float64_t* values)
{
printf("|%6.3f ", values[LAST_MASK_INDEX]);
printf("|%6.3f ", values[AVE_MASK_INDEX]);
printf("|%6.3f ", values[PEAK_MASK_INDEX]);
}
void print_ps_current_na()
{
printf("| N/A | N/A | N/A ");
}
void print_ps_temperature(float64_t* values)
{
printf("|%3d ", (int16_t)values[LAST_MASK_INDEX]);
printf("%3d ", (int16_t)values[AVE_MASK_INDEX]);
printf("%3d ", (int16_t)values[PEAK_MASK_INDEX]);
printf("%3d ", (int16_t)values[LOW_MASK_INDEX]);
}
void print_ps_temperature_na()
{
printf("| N/A N/A N/A N/A");
}
void print_ps_long_horizontal_border()
{
printf("-----------------------------------------------------------------------------------------------------------------------------------\n");
}
void print_ps_short_horizontal_border()
{
printf("-----------------------------------------------------------------\n");
}
void print_ps_column(int pad_tab_num, char *szText)
{
int spacecnt = pad_tab_num * 4;
int i;
for (i = 0; i < spacecnt; i++)
printf(" ");
printf("%s", szText);
}
void ps_convert_monitor_raw_to_value(uint32_t *values,uint8_t *raw)
{
values[LAST_MASK_INDEX]=0;
values[AVE_MASK_INDEX]=0;
values[PEAK_MASK_INDEX]=0;
values[LOW_MASK_INDEX]=0;
values[LAST_MASK_INDEX] = raw[LAST_MASK_INDEX*2+1]<<8 | raw[LAST_MASK_INDEX*2];
values[AVE_MASK_INDEX] = raw[AVE_MASK_INDEX*2+1]<<8 | raw[AVE_MASK_INDEX*2];
values[PEAK_MASK_INDEX] = raw[PEAK_MASK_INDEX*2+1]<<8 | raw[PEAK_MASK_INDEX*2];
values[LOW_MASK_INDEX] = raw[LOW_MASK_INDEX*2+1]<<8 | raw[LOW_MASK_INDEX*2];
}