AD BasicOps
Edit this on GitLab
AD BasicOps
Explanation
About the Sample Application Code
This application example showcases how to use North Atlantic Industries' (NAI) Software Support Kit (SSK) to interact with Analog-Digital (AD) modules for basic operation. The application serves several purposes, including setting up configurations and reading channel data.
Definitions and Inclusions
-
Header Files: Various standard system headers (
stdint.h
,stdio.h
,stdlib.h
,string.h
,time.h
,ctype.h
) and NAI-specific headers (naiapp_boardaccess_menu.h
,naiapp_boardaccess_query.h
,naiapp_boardaccess_access.h
,naiapp_boardaccess_display.h
,naiapp_boardaccess_utils.h
,nai_ad_utils.h
,nai.h
,naibrd.h
,naibrd_ad.h
,nai_ether_adv.h
,naibrd_gen5.h
) are included.
Constants and Definitions
-
String Constants: Names are defined for program and configuration files (
SAMPLE_PGM_NAME
,CONFIG_FILE
, andSATURATION_MENU
). -
Version Constants: FPGA version constants indicating support for saturation commands for various AD modules.
-
Default Channel: Default communication channel is set to 1 (
DEFAULT_CHANNEL
).
Function Prototypes
Prototypes are specified for various functions facilitating the application’s logical flow, user command handling, and additional operations.
Main Function
The main()
function initializes the program, engages the menu for configuration, and loops until the user indicates to quit.
Key Steps in main()
:
-
Initialize and Run Board Menu:
-
naiapp_RunBoardMenu(CONFIG_FILE)
loads configuration.
-
-
User Input Loop:
-
naiapp_query_CardIndex()
andnaiapp_query_ModuleNumber()
gather user inputs for card index and module number. -
naibrd_GetModuleCount()
gets the module count. -
naibrd_GetModuleID()
gets the module ID. -
ADBasicOps_run()
handles the main operation execution loop.
-
-
Exit Program:
-
Prompts the user to press Enter to exit.
-
Closes all open card accesses using
naiapp_access_CloseAllOpenCards()
.
-
Key Functional Areas
Displaying Configurations
ADBasicOps_displayConfigurations()
displays the current configuration and status for each channel, including voltage, range, polarity, filter break frequency, latch status, and floating-point modes.
Command Functions
The sample makes use of several command functions, each handling a specific operation:
-
Range and Polarity (
ADBasicOps_setRangePolarity
): Set the range and polarity for the AD channel. -
Latch (
ADBasicOps_setLatch
): Latch or unlatch all channels. -
Mode (
ADBasicOps_setMode
): Set operational modes like voltage or current for AD4 module channels. -
Break Frequency (
ADBasicOps_setBreakFreq
): Set the filter break frequency. -
Active Channel (
ADBasicOps_setActiveChannel
): Activate or deactivate specific channels. -
D0 Test (
ADBasicOps_setD0TestEnable
): Enable or disable the D0 Test. -
Floating Point Mode (
ADBasicOps_FloatingPointMode
): Enable or disable hardware floating-point conversion.
Menu Handling
naiapp_cmdtbl_params_t
arrays (AD_BasicOpsCmds
and AD_BasicOps_SaturationCmds
) define available commands and their descriptions, associating them with corresponding handler functions.
Display and Interaction
The sample application leverages utility functions prefixed with naiapp_
and naibrd_
for querying user inputs, setting configurations, and displaying statuses.
Example Command Handling
When a user selects a command, the associated function is called with necessary parameters, obtained using naiapp_query_ChannelNumber
and other query utilities:
-
ADBasicOps_setRangePolarity:
-
Sets the range and polarity for a specified channel.
-
Prompts the user to select the channel, then sets the appropriate configuration using
naibrd_AD_SetRange
.
This clean structure allows for extensibility and ease of use when interacting with different modules and configurations supported by NAI.
Conclusion
This application code elegantly demonstrates the basic operations for NAI AD modules via user commands, providing a clear structure for initialization, configuration display, and command handling. It serves as a foundation for developing more complex interactions with NAI’s embedded function modules.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
#include "nai_ad_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ad.h"
#include "advanced/nai_ether_adv.h"
#include "boards/naibrd_gen5.h"
static const int8_t *SAMPLE_PGM_NAME = (const int8_t *)"AD Module Basic Operation Program";
static const int8_t *CONFIG_FILE = (const int8_t *)"default_AD_BasicOps.txt";
#define NAIAPPS_AD123_SATURATION_SUPPORT_FPGA_REV 0x00020001u
#define NAIAPPS_AD456_SATURATION_SUPPORT_FPGA_REV 0x0007000Cu
#define NAIAPPS_ADEFG_SATURATION_SUPPORT_FPGA_REV 0x00010007u
static const int8_t *SATURATION_MENU = (const int8_t *)"AD Module Saturation Menu";
#define DEFAULT_CHANNEL 1
/* Function prototypes */
static bool_t ADBasicOps_run(int32_t cardIndex, int32_t module, uint32_t modid);
static void ADBasicOps_displayConfigurations(int32_t cardIndex, int32_t module, uint32_t modId, int32_t maxChannels, bool_t displayHex);
static void ADBasicOps_displaySaturationConfig(int32_t cardIndex, int32_t module, uint32_t modId, int32_t maxChannels, bool_t displayHex);
/* AD Basic Ops Command Functions */
static nai_status_t ADBasicOps_setRangePolarity(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_setLatch(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_setMode(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_setBreakFreq(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_setActiveChannel(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_saturationMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_setD0TestEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_FloatingPointMode(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_FloatingPointOffset(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_FloatingPointScaleFactor(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_ChannelStatusEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_BITThresholds(int32_t paramCount, int32_t* p_paramas);
static nai_status_t ADBasicOps_toggleNumDisplay(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_setSaturationLow(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_setSaturationHigh(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_enableSaturationLow(int32_t paramCount, int32_t* p_params);
static nai_status_t ADBasicOps_enableSaturationHigh(int32_t paramCount, int32_t* p_params);
static bool_t ADBasicOps_SaturationAvailable(int32_t paramCount, int32_t* p_params);
/* Additional Helper Functions */
static void ADBasicOps_displayStatus(int cardIndex, int module, int channel);
/****** Command Table *******/
/* Invariant: enumeration of cmd table starts from 0 and increments by 1 */
enum ad_basicOps_commands
{
AD_BASICOPS_CMD_SET_POL_RNG,
AD_BASICOPS_CMD_SET_BREAK_FREQ,
AD_BASICOPS_CMD_SET_LATCH,
AD_BASICOPS_CMD_SET_MODE,
AD_BASICOPS_CMD_SET_CHANNEL_ACTIVE,
AD_BASICOPS_CMD_SATURATION_MENU,
AD_BASICOPS_CMD_SET_D0_TEST_ENABLE,
AD_BASICOPS_CMD_FLOATING_POINT_MODE,
AD_BASICOPS_CMD_FLOATING_POINT_OFFSET,
AD_BASICOPS_CMD_FLOATING_POINT_SCALE_FACTOR,
AD_BASICOPS_CMD_CHANNEL_STATUS_ENABLE,
AD_BASICOPS_CMD_PBIT,
AD_BASICOPS_CMD_BIT_THRESHOLD,
AD_BASICOPS_CMD_TOGGLE_NUMERIC_DISPLAY,
AD_BASICOPS_CMD_COUNT
};
enum ad_basicOps_Saturation_commands
{
AD_BASICOPS_SATURATION_CMD_SET_LOW,
AD_BASICOPS_SATURATION_CMD_SET_HIGH,
AD_BASICOPS_SATURATION_CMD_ENABLE_LOW,
AD_BASICOPS_SATURATION_CMD_ENABLE_HIGH,
AD_BASICOPS_SATURATION_CMD_COUNT
};
naiapp_cmdtbl_params_t AD_BasicOpsCmds[] =
{
{"PR", "Set AD Polarity and Range", AD_BASICOPS_CMD_SET_POL_RNG, ADBasicOps_setRangePolarity },
{"BRKFRQ", "Set AD Filter Break Frequency", AD_BASICOPS_CMD_SET_BREAK_FREQ, ADBasicOps_setBreakFreq },
{"M", "Set AD Voltage/Current Mode (AD4 ONLY)", AD_BASICOPS_CMD_SET_MODE, ADBasicOps_setMode },
{"L", "Set AD Latch/Unlatch Status", AD_BASICOPS_CMD_SET_LATCH, ADBasicOps_setLatch },
{"AC", "Set AD Channel Active/Inactive (AD4 ONLY)", AD_BASICOPS_CMD_SET_CHANNEL_ACTIVE, ADBasicOps_setActiveChannel },
{"SAT", "Saturation Menu", AD_BASICOPS_CMD_SATURATION_MENU, ADBasicOps_saturationMenu },
{"D0", "Enable/Configure/Disable D0 Test", AD_BASICOPS_CMD_SET_D0_TEST_ENABLE, ADBasicOps_setD0TestEnable },
{"FP_MODE", "Enable/Disable Hardware Floating-Point Conversion Mode", AD_BASICOPS_CMD_FLOATING_POINT_MODE, ADBasicOps_FloatingPointMode},
{"OFFSET", "Set Hardware Floating-Point Conversion Mode Offset", AD_BASICOPS_CMD_FLOATING_POINT_OFFSET, ADBasicOps_FloatingPointOffset},
{"SCALE", "Set Hardware Floating-Point Conversion Mode Scale Factor", AD_BASICOPS_CMD_FLOATING_POINT_SCALE_FACTOR, ADBasicOps_FloatingPointScaleFactor},
{"CHANSTAT","Channel Status Enable/Disable", AD_BASICOPS_CMD_CHANNEL_STATUS_ENABLE, ADBasicOps_ChannelStatusEnable},
{"PBIT", "Check Power-On BIT", AD_BASICOPS_CMD_PBIT, ADBasicOps_CheckPowerOnBIT },
{"THRESH", "Set BIT Error Threshold", AD_BASICOPS_CMD_BIT_THRESHOLD, ADBasicOps_BITThresholds },
{"TND", "Toggle Numeric Display", AD_BASICOPS_CMD_TOGGLE_NUMERIC_DISPLAY, ADBasicOps_toggleNumDisplay } };
naiapp_cmdtbl_params_t AD_BasicOps_SaturationCmds[] =
{
{"SL", "Set Saturation Low value", AD_BASICOPS_SATURATION_CMD_SET_LOW, ADBasicOps_setSaturationLow },
{"SH", "Set Saturation High value", AD_BASICOPS_SATURATION_CMD_SET_HIGH, ADBasicOps_setSaturationHigh },
{"EL", "Enable/Disable Saturation Low", AD_BASICOPS_SATURATION_CMD_ENABLE_LOW, ADBasicOps_enableSaturationLow },
{"EH", "Enable/Disable Saturation High", AD_BASICOPS_SATURATION_CMD_ENABLE_LOW, ADBasicOps_enableSaturationHigh },
};
/*****************************************************************************/
/**
* <summary>
* The purpose of the AD_BasicOps is to illustrate the methods to call in the
* naibrd library to perform basic operations with the AD modules for
* configuration setup and reading the channels.
*
* The following system configuration routines from the nai_sys_cfg.c file are
* called to assist with the configuration setup for this program prior to
* calling the naibrd AD routines.
* - ConfigDevice
* - DisplayDeviceCfg
* - GetBoardSNModCfg
* - CheckModule
* </summary>
*/
/*****************************************************************************/
#if defined (__VXWORKS__)
int32_t AD_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t bQuit = FALSE;
int32_t cardIndex = -1;
int32_t module = 0;
uint32_t modId = 0u;
int32_t moduleCount;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (!bQuit)
{
naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
naibrd_GetModuleCount(cardIndex, &moduleCount);
naiapp_query_ModuleNumber(moduleCount, 1, &module);
modId = naibrd_GetModuleID(cardIndex, module);
bQuit = ADBasicOps_run(cardIndex, module, modId);
}
printf("Type the Enter key to exit the program: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
naiapp_access_CloseAllOpenCards();
return 0;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_run illustrates the channel configuration and prepares the menu
* which will handle user command requests. Returns TRUE if the user enters
* the Quit Command at any point within its scope.
* </summary>
*/
/*****************************************************************************/
static bool_t ADBasicOps_run(int32_t cardIndex, int32_t module, uint32_t modId)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
naiapp_AppParameters_t ad_basicops_params;
p_naiapp_AppParameters_t ad_basicOps_params = &ad_basicops_params;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
ad_basicOps_params->cardIndex = cardIndex;
ad_basicOps_params->module = module;
ad_basicOps_params->channel = DEFAULT_CHANNEL;
ad_basicOps_params->maxChannels = naibrd_AD_GetChannelCount(modId);
ad_basicOps_params->modId = modId;
ad_basicOps_params->displayHex = FALSE;
do
{
naiapp_utils_LoadParamMenuCommands(AD_BASICOPS_CMD_COUNT, AD_BasicOpsCmds);
ADBasicOps_displayConfigurations(cardIndex, module, modId, ad_basicOps_params->maxChannels, ad_basicOps_params->displayHex);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_PGM_NAME);
printf("\n\nPlease enter a command or 'q' to quit:");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
AD_BasicOpsCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ad_basicOps_params);
}
else
{
printf("Invalid command entered\n");
}
}
}
} while (!bQuit);
return bQuit;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_displayConfigurations illustrates the methods to call in the naibrd library
* to retrieve the basic operation configuration states and status states
* as well as the current voltage reading for all channels.
* </summary>
*/
/*****************************************************************************/
static void ADBasicOps_displayConfigurations(int32_t cardIndex, int32_t module, uint32_t modId, int32_t maxChannels, bool_t displayHex)
{
int32_t channel;
float64_t data = 0;
float64_t range = 0;
uint32_t rawData = 0u;
nai_ad_range_mode_t polarity = NAI_AD_GEN5_D0_RANGE_MODE_UNIPOLAR;
nai_ad_mode_t data_mode = NAI_AD_MODE_VOLTAGE;
nai_ad_state_t channelActive = NAI_AD_STATE_INACTIVE;
char* sChannelState = "";
bool_t latched = FALSE;
bool_t d0TestEnable = FALSE;
nai_ad_range_mode_t d0Polarity = NAI_AD_GEN5_D0_RANGE_MODE_UNIPOLAR;
uint32_t filterBreakFreq = 0u;
float64_t d0Range = 0.0;
float64_t d0TestLevel = 0.0;
uint32_t rawD0TestEnable = 0u;
uint32_t rawD0Polarity = 0u;
uint32_t rawD0TestLevel = 0u;
float64_t offset = 0.0;
float64_t scale = 0.0;
bool_t fpCapable = FALSE;
bool_t floatMode = FALSE;
if (modId == NAI_MODULE_ID_AD4)
{
printf("\n\n =================================================================================================================================\n");
printf(" Chan Chan Mode Volt/Curr Range Polarity Break Chan BIT Status Open Status Summary Status FP FP\n");
printf(" State Freq Status (R/L) (R/L) (R/L) Offset Scale\n");
printf(" ---------------------------------------------------------------------------------------------------------------------------------\n");
}
else
{
printf("\n\n ====================================================================================================================\n");
printf(" Chan Voltage Range Polarity Break Chan BIT Status Open Status Summary Status FP FP\n");
printf(" Freq Status (R/L) (R/L) (R/L) Offset Scale\n");
printf(" ----------------------------------------------------------------------------------------------------------------------\n");
}
for (channel = 1; channel <= maxChannels; channel++)
{
/*** Acquire values stored in selected channel ***/
check_status(naibrd_AD_GetMode(cardIndex, module, channel, &data_mode));
printf(" %2d ", channel);
if (modId == NAI_MODULE_ID_AD4)
{
check_status(naibrd_AD_GetChannelState(cardIndex, module, channel, &channelActive));
if (FALSE == channelActive)
{
sChannelState = "INACTIVE";
}
else
{
sChannelState = " ACTIVE ";
}
printf("%8s ", sChannelState);
}
if (displayHex)
{
check_status(naibrd_AD_GetChannelRaw(cardIndex, module, channel, NAI_AD_CHAN_RAW_DATA, &rawData));
if (modId == NAI_MODULE_ID_AD4 && data_mode == NAI_AD_MODE_CURRENT)
{
printf("Current 0x%08X ", rawData);
}
else if (modId == NAI_MODULE_ID_AD4 && data_mode == NAI_AD_MODE_VOLTAGE)
{
printf("Voltage 0x%08X ", rawData);
}
else
{
printf("0x%08X ", rawData);
}
}
else
{
check_status(naibrd_AD_GetVoltage(cardIndex, module, channel, &data));
if (modId == NAI_MODULE_ID_AD4 && data_mode == NAI_AD_MODE_CURRENT)
{
printf("Current %10.6fA ", data);
}
else
{
if (modId == NAI_MODULE_ID_AD4 && data_mode == NAI_AD_MODE_VOLTAGE)
printf("Voltage %10.6fV ", data);
else
printf("%10.6fV ", data);
}
}
check_status(naibrd_AD_GetRange(cardIndex, module, channel, &polarity, &range));
printf("%6.2f ", range);
if (polarity == NAI_AD_RANGE_MODE_UNIPOLAR)
printf("UNIPOLAR");
else if (polarity == NAI_AD_RANGE_MODE_BIPOLAR)
printf("BIPOLAR ");
else
printf("ERROR ");
check_status(naibrd_AD_GetBreakFrequency(cardIndex, module, channel, &filterBreakFreq));
printf("%6u ", filterBreakFreq);
ADBasicOps_displayStatus(cardIndex, module, channel);
check_status(naibrd_GetFloatingPointModeCapability(cardIndex, module, &fpCapable));
if (fpCapable == TRUE)
{
check_status(naibrd_AD_GetFloatingPointOffset(cardIndex, module, channel, &offset));
check_status(naibrd_AD_GetFloatingPointScaleFactor(cardIndex, module, channel, &scale));
printf(" %7.3f %7.3f", offset, scale);
}
else
{
printf(" N/A N/A");
}
printf("\n");
}
printf("\n\nLatch Status (all channels): ");
check_status(naibrd_AD_GetLatch(cardIndex, module, &latched));
if (FALSE == latched)
{
printf("UNLATCHED\n");
}
else
{
printf("LATCHED\n");
}
if (fpCapable == TRUE)
{
check_status(naibrd_GetRunningInFloatingPointMode(cardIndex, module, &floatMode));
if (floatMode == TRUE)
{
printf("Floating-Point Mode: ENABLED\n");
}
else
{
printf("Floating-Point Mode: DISABLED\n");
}
}
if (displayHex)
{
printf("D0 Test (all channels): Internal Test Enable: ");
check_status(naibrd_AD_GetRaw(cardIndex, module, NAI_AD_RAW_TEST_ENABLE, &rawD0TestEnable));
check_status(naibrd_AD_GetRaw(cardIndex, module, NAI_AD_RAW_D0_RANGE_POLARITY, &rawD0Polarity));
check_status(naibrd_AD_GetRaw(cardIndex, module, NAI_AD_RAW_D0_TEST_VALUE, &rawD0TestLevel));
printf("0x%02X, Range/Polarity: 0x%02X, ", rawD0TestEnable, rawD0Polarity);
printf("Voltage Level: 0x%08X\n", rawD0TestLevel);
}
else
{
printf("D0 Test (all channels): ");
check_status(naibrd_AD_GetTestEnable(cardIndex, module, NAI_AD_D0_TEST, &d0TestEnable));
if (FALSE == d0TestEnable)
{
printf("DISABLED\n");
}
else
{
check_status(naibrd_AD_GetD0TestSettings(cardIndex, module, &d0Polarity, &d0Range, &d0TestLevel));
printf("ENABLED, Range:%6.2lfV, Mode: ", d0Range);
if (NAI_AD_GEN5_D0_RANGE_MODE_UNIPOLAR == d0Polarity)
{
printf("UNIPOLAR");
}
else
{
printf("BIPOLAR");
}
printf(", Voltage Level:%10.6lfV\n", d0TestLevel);
}
}
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_setRangePolarity handles the user request to set the configuration states
* of Range and Polarity for the selected channel.
* </summary>
*/
/*****************************************************************************/
static nai_status_t ADBasicOps_setRangePolarity(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
float64_t range = 0.0;
nai_ad_range_mode_t polarity = NAI_AD_GEN5_D0_RANGE_MODE_UNIPOLAR;
bool_t bQuit = FALSE;
nai_ad_mode_t mode = NAI_AD_MODE_VOLTAGE;
nai_status_t status = NAI_ERROR_UNKNOWN;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
naibrd_AD_GetMode(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, &mode);
if (FALSE == p_ad_params->displayHex)
{
ADUtils_GetPolarityRange(p_ad_params->cardIndex, p_ad_params->module, mode, &polarity, &range);
naibrd_AD_SetRange(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, polarity, range);
}
else
{
ADModule_GetHexPolarityRange(p_ad_params->cardIndex, p_ad_params->module, &mode, &range);
naibrd_AD_SetRange(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, polarity, range);
}
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_setLatch handles the user request to set the latch on all channel readings.
* </summary>
*/
/*****************************************************************************/
static nai_status_t ADBasicOps_setLatch(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t latched = FALSE;
bool_t bQuit = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
printf("Type 'L' to LATCH, or press any other key to UNLATCH all channels:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (toupper(inputBuffer[0]) == 'L')
latched = TRUE;
else
latched = FALSE;
check_status(naibrd_AD_SetLatch(p_ad_params->cardIndex, p_ad_params->module, latched));
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_setMode handles the user request to set the configuration states
* of Mode for the selected channel.
* </summary>
*/
/*****************************************************************************/
static nai_status_t ADBasicOps_setMode(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
int channel;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
if (p_ad_params->modId == NAI_MODULE_ID_AD4)
{
printf("\nType 'V' for voltage mode\n");
printf(" 'C' for current mode\n");
printf(" 'VA' to set all chan to voltage mode\n");
printf(" 'CA' to set all chan to current mode\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (toupper(inputBuffer[0]) == 'V')
{
if (toupper(inputBuffer[1]) == 'A')
{
for (channel = 1; channel <= p_ad_params->maxChannels; channel++)
status = naibrd_AD_SetMode(p_ad_params->cardIndex, p_ad_params->module, channel, NAI_AD_MODE_VOLTAGE);
}
else
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
status = naibrd_AD_SetMode(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, NAI_AD_MODE_VOLTAGE);
}
}
}
else if (toupper(inputBuffer[0]) == 'C')
{
if (toupper(inputBuffer[1]) == 'A')
{
for (channel = 1; channel <= p_ad_params->maxChannels; channel++)
status = naibrd_AD_SetMode(p_ad_params->cardIndex, p_ad_params->module, channel, NAI_AD_MODE_CURRENT);
}
else
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
status = naibrd_AD_SetMode(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, NAI_AD_MODE_CURRENT);
}
}
}
printf("Returned status %s\n", nai_GetStatusString(status));
}
}
else
{
printf("Mode selection only available for AD4\n");
status = NAI_ERROR_NOT_SUPPORTED;
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_setBreakFreq handles the user request to set the
* filter break frequency for the selected channel.
* </summary>
*/
/*****************************************************************************/
static nai_status_t ADBasicOps_setBreakFreq(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
uint32_t filterBreakFrequency = 0u;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
printf("Enter new Filter Break Frequency: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
sscanf((const char*)inputBuffer, "%u", &filterBreakFrequency);
check_status(naibrd_AD_SetBreakFrequency(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel,
filterBreakFrequency));
}
}
return NAI_SUCCESS;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_setActiveChannel handles the user request to set the
* active/inactive state for the selected channel.
* </summary>
*/
/*****************************************************************************/
static nai_status_t ADBasicOps_setActiveChannel(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
int32_t channel = 0;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
printf("\nType 'A' to set channel to ACTIVE\n");
printf("Type 'I' to set channel to INACTIVE\n");
printf("Type 'CA' to set all channels to ACTIVE\n");
printf("Type 'CI' to set all channels to INACTIVE\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if (toupper(inputBuffer[0]) == 'A')
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
status = naibrd_AD_SetChannelState(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, TRUE);
}
}
else if (toupper(inputBuffer[0]) == 'I')
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
status = naibrd_AD_SetChannelState(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, FALSE);
}
}
else if (toupper(inputBuffer[0]) == 'C')
{
if (toupper(inputBuffer[1]) == 'A')
{
for (channel = 1; channel <= p_ad_params->maxChannels; channel++)
{
if (status == NAI_SUCCESS)
{
status = naibrd_AD_SetChannelState(p_ad_params->cardIndex, p_ad_params->module, channel, TRUE);
}
else
{
naibrd_AD_SetChannelState(p_ad_params->cardIndex, p_ad_params->module, channel, TRUE);
}
}
}
else if (toupper(inputBuffer[1]) == 'I')
{
for (channel = 1; channel <= p_ad_params->maxChannels; channel++)
{
if (status == NAI_SUCCESS)
{
status = naibrd_AD_SetChannelState(p_ad_params->cardIndex, p_ad_params->module, channel, FALSE);
}
else
{
naibrd_AD_SetChannelState(p_ad_params->cardIndex, p_ad_params->module, channel, FALSE);
}
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
printf("Returned status %s\n", nai_GetStatusString(status));
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_setD0TestEnable handles the user request to set the D0 Test
* Enabled/Disabled State and configure the D0 Test Settings. The only range
* available is the 10V range. Valid range modes are unipolar and bipolar.
* The D0 Test Level can also be set.
* </summary>
*/
/*****************************************************************************/
static nai_status_t ADBasicOps_setD0TestEnable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
nai_ad_range_mode_t polarity = NAI_AD_RANGE_MODE_UNIPOLAR;
nai_ad_mode_t D0mode;
float64_t testLevel = 0.0;
float64_t D0Range = 0.0;
uint32_t rawD0RangePolarity = 0u;
uint32_t rawD0TestLevel = 0u;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
printf("Type 'D' to DISABLE the D0 Test, or press any other key to ENABLE the D0 Test:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if ((inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'D'))
{
check_status(naibrd_AD_SetTestEnable(p_ad_params->cardIndex, p_ad_params->module, NAI_AD_D0_TEST, FALSE));
}
else
{
check_status(naibrd_AD_SetTestEnable(p_ad_params->cardIndex, p_ad_params->module, NAI_AD_D0_TEST, TRUE));
printf("\n\nConfigure the D0 test Polarity and Voltage level.\n");
printf("**NOTE: Channels that are not set to the same Range and Polarity as D0 will not be scaled the same,\n");
printf(" and will show unexpected readings.\n");
printf("D0 range is always 10V, but the Polarity is configurable.\n");
if (p_ad_params->displayHex)
{
printf("\nType Raw D0 Test Range/Polarity Mode to set:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
sscanf((const char*)inputBuffer, "%X", &rawD0RangePolarity);
check_status(naibrd_AD_SetRaw(p_ad_params->cardIndex, p_ad_params->module, NAI_AD_RAW_D0_RANGE_POLARITY,
rawD0RangePolarity));
printf("\nType Raw D0 Test Voltage Level to set:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
sscanf((const char*)inputBuffer, "%X", &rawD0TestLevel);
check_status(naibrd_AD_SetRaw(p_ad_params->cardIndex, p_ad_params->module, NAI_AD_RAW_D0_TEST_VALUE,
rawD0TestLevel));
}
}
}
else
{
printf("Type 'U' to set the D0 Test Polarity to UNIPOLAR, or press any other key for BIPOLAR:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if ((inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'U'))
{
polarity = NAI_AD_RANGE_MODE_UNIPOLAR;
rawD0RangePolarity = (uint32_t)NAI_AD_GEN5_D0_RANGE_MODE_UNIPOLAR;
}
else
{
polarity = NAI_AD_RANGE_MODE_BIPOLAR;
rawD0RangePolarity = (uint32_t)NAI_AD_GEN5_D0_RANGE_MODE_BIPOLAR;
}
printf("Type the D0 Test Voltage Level you want to set:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
sscanf((const char*)inputBuffer, "%lf", &testLevel);
if ((p_ad_params->modId == NAI_MODULE_ID_AD3) || (p_ad_params->modId == NAI_MODULE_ID_ADG))
{
D0mode = NAI_AD_MODE_CURRENT;
}
else
{
D0mode = NAI_AD_MODE_VOLTAGE;
}
naibrd_AD_ConvertToVoltageRange(p_ad_params->modId, rawD0RangePolarity, &D0mode, &D0Range);
check_status(naibrd_AD_ConfigureD0Test(p_ad_params->cardIndex, p_ad_params->module, polarity, D0Range, testLevel));
}
}
}
}
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/*****************************************************************************/
/**
* <summary>
* ADBasicOps_displayStatus prints to stdin the range mode, BIT status, and Open Status in
* a format thats fits the table produced in displayChannelCfg.
* </summary>
*/
/*****************************************************************************/
static void ADBasicOps_displayStatus(int cardIndex, int module, int channel)
{
nai_status_bit_t bitStatusRT, bitStatusLT;
nai_status_bit_t openStatusRT, openStatusLT;
nai_status_bit_t summaryStatusRT, summaryStatusLT;
nai_status_bit_t chanStatusEnabled;
check_status(naibrd_AD_GetChanStatusEnable(cardIndex, module, channel, &chanStatusEnabled));
printf(" %s ", (chanStatusEnabled == FALSE) ? "NO " : "YES");
check_status(naibrd_AD_GetStatus(cardIndex, module, channel, NAI_AD_STATUS_BIT_REALTIME, &bitStatusRT));
check_status(naibrd_AD_GetStatus(cardIndex, module, channel, NAI_AD_STATUS_BIT_LATCHED, &bitStatusLT));
printf(" %d/%d", (bitStatusRT == NAI_STATUS_BIT_HI ? 1 : 0), (bitStatusLT == NAI_STATUS_BIT_HI ? 1 : 0));
check_status(naibrd_AD_GetStatus(cardIndex, module, channel, NAI_AD_STATUS_OPEN_OVERVOLT_REALTIME, &openStatusRT));
check_status(naibrd_AD_GetStatus(cardIndex, module, channel, NAI_AD_STATUS_OPEN_OVERVOLT_LATCHED, &openStatusLT));
printf(" %d/%d", (openStatusRT == NAI_STATUS_BIT_HI ? 1 : 0), (openStatusLT == NAI_STATUS_BIT_HI ? 1 : 0));
check_status(naibrd_AD_GetStatus(cardIndex, module, channel, NAI_AD_STATUS_SUMMARY_REALTIME, &summaryStatusRT));
check_status(naibrd_AD_GetStatus(cardIndex, module, channel, NAI_AD_STATUS_SUMMARY_LATCHED, &summaryStatusLT));
printf(" %d/%d", (summaryStatusRT == NAI_STATUS_BIT_HI ? 1 : 0), (summaryStatusLT == NAI_STATUS_BIT_HI ? 1 : 0));
}
static nai_status_t ADBasicOps_toggleNumDisplay(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
nai_status_t status = NAI_ERROR_UNKNOWN;
if (APP_PARAM_COUNT == paramCount)
{
if (FALSE == p_ad_params->displayHex)
{
p_ad_params->displayHex = TRUE;
}
else
{
p_ad_params->displayHex = FALSE;
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* ADBasicOps_CheckPowerOnBIT() Checks to see if the power-on BIT test
* has been run on the module. If the PBIT test has run, it checks the result
* of the test and reports it back.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t ADBasicOps_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t channelCount = 0, channel = 0;
bool_t pbitComplete;
nai_status_bit_t bitFailed;
if (APP_PARAM_COUNT == paramCount)
{
switch (p_ad_params->modId)
{
case NAI_MODULE_ID_AD1:
case NAI_MODULE_ID_AD2:
case NAI_MODULE_ID_AD3:
case NAI_MODULE_ID_AD4:
case NAI_MODULE_ID_AD5:
case NAI_MODULE_ID_AD6:
case NAI_MODULE_ID_ADE:
case NAI_MODULE_ID_ADF:
case NAI_MODULE_ID_ADG:
{
channelCount = naibrd_AD_GetChannelCount(p_ad_params->modId);
/* Check to see if PBIT ran for the module. */
printf("Checking if the Power-On BIT test has run...\n");
status = naibrd_GetModulePBITComplete(p_ad_params->cardIndex, p_ad_params->module,p_ad_params->channel, &pbitComplete);
printf("PBIT Complete: %s", (pbitComplete) ? "COMPLETED\n" : "NOT COMPLETED\n");
if (pbitComplete)
{
/* Read the BIT status */
printf("Checking the result of the Power-on BIT test...\n");
for (channel = 1; channel <= channelCount; channel++)
{
status = naibrd_AD_GetStatus(p_ad_params->cardIndex, p_ad_params->module, channel, NAI_AD_STATUS_BIT_LATCHED,
&bitFailed);
printf("Ch. %d: %s", channel, bitFailed ? "BIT FAILED\n" : "BIT Passed\n");
}
}
}
break;
default:
printf("\n\n****************************************************\n");
printf("*** This feature is not supported by this module.***\n");
printf("****************************************************\n");
status = NAI_ERROR_NOT_SUPPORTED;
break;
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* ADBasicOps_BITThresholds() allows the user to set and get the BIT error thresholds.
* This is an advanced feature.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t ADBasicOps_BITThresholds(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
uint32_t bitThreshold = 0u;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
switch (p_ad_params->modId)
{
case NAI_MODULE_ID_AD1:
case NAI_MODULE_ID_AD2:
case NAI_MODULE_ID_AD3:
case NAI_MODULE_ID_AD4:
case NAI_MODULE_ID_AD5:
case NAI_MODULE_ID_AD6:
case NAI_MODULE_ID_ADE:
case NAI_MODULE_ID_ADF:
case NAI_MODULE_ID_ADG:
{
printf("Set or Get BIT Error Threshold? ('S' = Set, 'G' = Get, 'C' = Clear BIT Counter): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit != FALSE)
{
if (inputBuffer[0] == 'S')
{
printf("\nType the desired BIT Error Threshold (Default = 5): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit != FALSE)
{
printf("\n");
bitThreshold = atoi((const char*)inputBuffer);
status = naibrd_SetModuleBITErrorThreshold(p_ad_params->cardIndex, p_ad_params->module, bitThreshold);
}
}
else if (inputBuffer[0] == 'G')
{
status = naibrd_GetModuleBITErrorThreshold(p_ad_params->cardIndex, p_ad_params->module, &bitThreshold);
printf("\nBIT Error threshold: %d", bitThreshold);
}
else if (inputBuffer[0] == 'C')
{
int32_t ch;
int32_t channels = naibrd_AD_GetChannelCount(p_ad_params->modId);
printf("\nClearing BIT counters on all channels.\n");
for (ch = 1; ch <= channels; ch++)
status = naibrd_ClearModuleBITLogic(p_ad_params->cardIndex, p_ad_params->module, ch);
}
else
{
printf("\nSelection not recognized.\n");
}
}
}
break;
default:
printf("\n\n****************************************************\n");
printf("*** This feature is not supported by this module.***\n");
printf("****************************************************\n");
status = NAI_ERROR_NOT_SUPPORTED;
break;
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function enables/disables the hardware floating-point conversion mode of the DA module, as specified
* by the user.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t ADBasicOps_FloatingPointMode(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
bool_t fpCapable = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
naibrd_GetFloatingPointModeCapability(p_ad_params->cardIndex, p_ad_params->module, &fpCapable);
if (fpCapable == TRUE)
{
printf("Select Floating-Point Mode to set ('0' for DISABLED, '1' for ENABLED)(default:DISABLED): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if (inputBuffer[0] == '0')
{
status = check_status(naibrd_SetFloatingPointModeEnable(p_ad_params->cardIndex, p_ad_params->module, 0x0));
}
else if (inputBuffer[0] == '1')
{
status = check_status(naibrd_SetFloatingPointModeEnable(p_ad_params->cardIndex, p_ad_params->module, 0x1));
}
}
}
else
{
printf("\n\n****************************************************\n");
printf("*** This feature is not supported by this module.***\n");
printf("****************************************************\n");
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function sets the hardware floating-point conversion mode offset for the DA channel specified by the
* user. This function is only applicable when the hardware floating-point conversion mode for the module is
* enabled.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t ADBasicOps_FloatingPointOffset(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
float64_t offset = 0.0;
bool_t fpCapable = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
naibrd_GetFloatingPointModeCapability(p_ad_params->cardIndex, p_ad_params->module, &fpCapable);
if (fpCapable == TRUE)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
printf("Type Hardware Floating-Point Conversion Mode Offset setting to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
sscanf((const char*)inputBuffer, "%lf", &offset);
status = check_status(naibrd_AD_SetFloatingPointOffset(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, offset));
}
}
}
else
{
printf("\n\n****************************************************\n");
printf("*** This feature is not supported by this module.***\n");
printf("****************************************************\n");
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function sets the hardware floating-point conversion mode scale factor for the DA channel specified by
* the user. This function is only applicable when the hardware floating-point conversion mode for the module
* is enabled.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t ADBasicOps_FloatingPointScaleFactor(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
float64_t scale = 0.0;
bool_t fpCapable = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
naibrd_GetFloatingPointModeCapability(p_ad_params->cardIndex, p_ad_params->module, &fpCapable);
if (fpCapable == TRUE)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
printf("Type Hardware Floating-Point Conversion Mode Scale Factor setting to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
sscanf((const char*)inputBuffer, "%lf", &scale);
status = check_status(naibrd_AD_SetFloatingPointScaleFactor(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, scale));
}
}
}
else
{
printf("\n\n****************************************************\n");
printf("*** This feature is not supported by this module.***\n");
printf("****************************************************\n");
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function Enables\Disables the reporting of the Channel Status. When enabled, the user will get status
* updates. When disabled, the statuses will not report and status-based interrupts will not assert.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t ADBasicOps_ChannelStatusEnable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(ad_params->maxChannels, ad_params->channel, &(ad_params->channel));
if (!bQuit)
{
printf("Enable Channel Status (Y = YES, [any other key] = NO: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
status = check_status(naibrd_AD_SetChanStatusEnable(ad_params->cardIndex, ad_params->module, ad_params->channel,
((inputResponseCnt > 0) && (inputBuffer[0] == 'Y' || inputBuffer[0] == 'y')) ? TRUE : FALSE));
}
}
}
return status;
}
static void ADBasicOps_displaySaturationConfig(int32_t cardIndex, int32_t module, uint32_t modId, int32_t maxChannels, bool_t displayHex)
{
int32_t channel;
float64_t satLowLevel = 0.0;
float64_t satHighLevel = 0.0;
bool_t satLowEnable = FALSE;
bool_t satHighEnable = FALSE;
char* sChannelState = "";
/* Unused params */
modId = 0;
displayHex = 0;
printf("\n\n ============================================================================\n");
printf(" Chan Saturation Low Low Enabled | Saturation High High Enabled\n");
printf(" --------------------------------------------------------------------------------\n");
for (channel = 1; channel <= maxChannels; channel++)
{
/*** Acquire values stored in selected channel ***/
check_status(naibrd_AD_GetSaturationLevel(cardIndex, module, channel, NAI_AD_SATURATION_CONTROL_LOW, &satLowLevel));
check_status(naibrd_AD_GetSaturationLevel(cardIndex, module, channel, NAI_AD_SATURATION_CONTROL_HIGH, &satHighLevel));
check_status(naibrd_AD_GetSaturationControl(cardIndex, module, channel, NAI_AD_SATURATION_CONTROL_LOW, &satLowEnable));
check_status(naibrd_AD_GetSaturationControl(cardIndex, module, channel, NAI_AD_SATURATION_CONTROL_HIGH, &satHighEnable));
printf(" %2d ", channel);
printf("%10.6fV ", satLowLevel);
if (FALSE == satLowEnable)
{
sChannelState = " INACTIVE ";
}
else
{
sChannelState = " ACTIVE ";
}
printf("%12s", sChannelState);
printf("| %10.6fV ", satHighLevel);
if (FALSE == satHighEnable)
{
sChannelState = " INACTIVE ";
}
else
{
sChannelState = " ACTIVE ";
}
printf("%12s\n", sChannelState);
}
}
static nai_status_t ADBasicOps_saturationMenu(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd = 0;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (TRUE == ADBasicOps_SaturationAvailable(paramCount, p_params))
{
if (APP_PARAM_COUNT == paramCount)
{
naiapp_utils_LoadParamMenuCommands(AD_BASICOPS_SATURATION_CMD_COUNT, AD_BasicOps_SaturationCmds);
do
{
ADBasicOps_displaySaturationConfig(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->modId, p_ad_params->maxChannels, p_ad_params->displayHex);
naiapp_display_ParamMenuCommands((int8_t*)SATURATION_MENU);
printf("\n\nPlease enter a command or 'q' to quit:");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
AD_BasicOps_SaturationCmds[cmd].func(APP_PARAM_COUNT, p_params);
}
else
{
printf("Invalid command entered\n");
}
}
}
} while (!bQuit);
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
}
else
{
printf("\n\n***Saturation is not supported by this module.***\n");
}
return status;
}
static nai_status_t ADBasicOps_setSaturationLow(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit;
int8_t userInput[15];
float64_t satLevel = 0.0;
nai_status_t status = NAI_ERROR_UNKNOWN;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
printf("Enter Saturation Low value:");
memset(userInput, 0x00, sizeof(userInput));
naiapp_fgets_stdin(userInput, sizeof(userInput));
sscanf((const char*)userInput, "%lf", &satLevel);
status = naibrd_AD_SetSaturationLevel(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, NAI_AD_SATURATION_CONTROL_LOW,
satLevel);
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t ADBasicOps_setSaturationHigh(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit;
int8_t userInput[15];
float64_t satLevel = 0.0;
nai_status_t status = NAI_ERROR_UNKNOWN;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
printf("Enter Saturation High value:");
memset(userInput, 0x00, sizeof(userInput));
naiapp_fgets_stdin(userInput, sizeof(userInput));
sscanf((const char*)userInput, "%lf", &satLevel);
status = naibrd_AD_SetSaturationLevel(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel, NAI_AD_SATURATION_CONTROL_HIGH,
satLevel);
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t ADBasicOps_enableSaturationLow(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
printf("Type 'E' to ENABLE Low-Level Saturation, or press any other key to DISABLE it:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if (toupper(inputBuffer[0]) == 'E')
{
check_status(naibrd_AD_SetSaturationControl(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel,
NAI_AD_SATURATION_CONTROL_LOW, TRUE));
}
else
{
check_status(naibrd_AD_SetSaturationControl(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel,
NAI_AD_SATURATION_CONTROL_LOW, FALSE));
}
}
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t ADBasicOps_enableSaturationHigh(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(p_ad_params->maxChannels, p_ad_params->channel, &(p_ad_params->channel));
if (!bQuit)
{
printf("Type 'E' to ENABLE High-Level Saturation, or press any other key to DISABLE it:\n>>");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if (toupper(inputBuffer[0]) == 'E')
{
check_status(naibrd_AD_SetSaturationControl(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel,
NAI_AD_SATURATION_CONTROL_HIGH, TRUE));
}
else
{
check_status(naibrd_AD_SetSaturationControl(p_ad_params->cardIndex, p_ad_params->module, p_ad_params->channel,
NAI_AD_SATURATION_CONTROL_HIGH, FALSE));
}
}
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static bool_t ADBasicOps_SaturationAvailable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
uint32_t fpgaRev = 0u;
uint32_t supportedRev = 0xFFFFFFFFu;
bool_t retVal = FALSE;
uint32_t modprocrev;
check_status(naibrd_GetModuleRev(p_ad_params->cardIndex, p_ad_params->module, &modprocrev, &fpgaRev));
/* Unused params */
paramCount = 0;
switch (p_ad_params->modId)
{
case NAI_MODULE_ID_AD1:
case NAI_MODULE_ID_AD2:
case NAI_MODULE_ID_AD3:
supportedRev = NAIAPPS_AD123_SATURATION_SUPPORT_FPGA_REV;
retVal = TRUE;
break;
case NAI_MODULE_ID_AD4:
case NAI_MODULE_ID_AD5:
case NAI_MODULE_ID_AD6:
supportedRev = NAIAPPS_AD456_SATURATION_SUPPORT_FPGA_REV;
retVal = TRUE;
break;
case NAI_MODULE_ID_ADE:
case NAI_MODULE_ID_ADF:
case NAI_MODULE_ID_ADG:
supportedRev = NAIAPPS_ADEFG_SATURATION_SUPPORT_FPGA_REV;
retVal = TRUE;
break;
default:
retVal = FALSE;
break;
}
if ((retVal == TRUE) && (fpgaRev < supportedRev))
{
retVal = FALSE;
}
return retVal;
}