Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

SD BasicOpsMenu

SD BasicOpsMenu

Explanation

About the Sample Application Code for NAI Embedded Function Modules

Overview This C code sample demonstrates how to interface with North Atlantic Industries (NAI) Synchronous Data (SD) embedded function modules using their Software Support Kit (SSK). It includes functions for configuring the modules, reading data, and performing various operations using the NAI library functions.

Key Components

Headers - Standard Headers: #include <stdio.h>, #include <stdlib.h>, #include <string.h>, #include <time.h>, #include <ctype.h> - NAI Application Headers: These headers include application-specific functions for board access, querying, display, and utility operations. - #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" - NAI Board Library Headers: These provide the core definitions and functions required for board interaction. - #include "nai.h" - #include "naibrd.h" - #include "functions/naibrd_sd.h" - #include "advanced/nai_ether_adv.h"

Constants and Types - File Constants: static const int8_t *CONFIG_FILE = (const int8_t *)"default_SD_BasicOps.txt"; - Function Prototypes: Declares the prototype functions used within the application, such as SDBasicMenu_Run(), SDBasicMenu_displayMeasurements(), and command functions like SDBasicMenu_SetMode().

Enumerations - Command Enumeration: Enumerates the commands available in the SD basic operations and SD test menus.

enum sd_basicOpsMenu_commands {
    SD_BASICMENU_CMD_SET_MODE, // Other commands follow...
};
enum sd_basicOpsMenu_test_commands {
    SD_TESTMENU_CMD_CLEAR_BIT_STATUS, // Other commands follow...
};

Command Tables naiapp_cmdtbl_params_t SD_BasicOpMenuCmds[] and naiapp_cmdtbl_params_t SD_TestMenuCmds[]: Arrays holding the command descriptions and associated functions for the SD Basic and Test operations, respectively.

Main Function The main() function (or SD_BasicOpsMenu() for VXWORKS) starts the application and manages the interaction with the NAI board, including querying user input, running the SD basic menu, and handling quit responses.

SD Basic Menu Run Function The SDBasicMenu_Run() function processes user commands, displays menu options, and handles individual command execution.

Display Functions - SDBasicMenu_displayMeasurements(): Retrieves and displays the configuration states and measurement results for all SD channels. - SDBasicMenu_displayMode(): Outputs the mode of a specific channel (e.g., Resolver or Synchro). - SDBasicMenu_displayStatus(): Prints the detailed status of the SD channel, including fault statuses, lock statuses, and summary statuses.

Command Functions This section details the specific command processing functions: - Setting Modes and Statuses: - SDBasicMenu_SetMode(): Sets the SD channel mode. - SDBasicMenu_SetChanStatusEnable(): Enables or disables channel status reporting. - SDBasicMenu_ClearStatus(): Clears latched status bits. - Setting Thresholds: - SDBasicMenu_SetSigLossThreshold(), SDBasicMenu_SetRefLossThreshold() - SDBasicMenu_SetSigFaultHiThreshold(), SDBasicMenu_SetRefFaultHiThreshold() - SDBasicMenu_SetOpenThreshold(), SDBasicMenu_SetShortThreshold(): These functions set various fault thresholds. - Handling Angle Data: - SDBasicMenu_SetDeltaAngle(), SDBasicMenu_InitDeltaAngle(): Set and initialize delta angle values. - Test Menu Functions: - SDTestMenu_ClearBITStatus(), SDTestMenu_SetBITErrorLimit() - SDTestMenu_SetTestAngle(), SDTestMenu_SetD0TestEnable() - SDTestMenu_CheckPowerOnBIT(): These functions handle Built-In Test (BIT) status, error limits, and test configurations.

Register Read/Write Functions - Read Register: SDBasicMenu_ReadReg(): Reads a 32-bit value from a specified register address. - Write Register: SDBasicMenu_WriteReg(): Writes a 32-bit value to a specified register address.

Usage To run the sample application, load the configuration file (default_SD_BasicOps.txt), follow the prompts to select a card and module, and use the menu options to perform operations. The application is designed to be quit using the 'Q' key, as prompted.


This code exemplifies modular interaction with NAI embedded function modules using their board support libraries, offering a groundwork for more complex application developments.

#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"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_sd.h"
#include "advanced/nai_ether_adv.h"

static const int8_t *CONFIG_FILE = (const int8_t *)"default_SD_BasicOps.txt";

/* Function prototypes */
static bool_t SDBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modid);
static void SDBasicMenu_displayMeasurements(int32_t cardIndex, int32_t module, uint32_t modid);
static void SDBasicMenu_displayMode(nai_sd_format_t mode);
static void SDBasicMenu_displayStatus(nai_status_bit_t BitStatus, nai_status_bit_t SigLoss, nai_status_bit_t RefLoss,
                                      nai_status_bit_t LockLossStat, nai_status_bit_t DeltaAngleStat, nai_status_bit_t OpenStat,
                                      nai_status_bit_t ShortStat, nai_status_bit_t RefHiStat, nai_status_bit_t SigHiStat,
                                      nai_status_bit_t SummaryStatus);

/* SD Basic Ops Command Functions */
static nai_status_t SDBasicMenu_SetMode(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetChanStatusEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_ClearStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetSigLossThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetRefLossThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetSigFaultHiThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetRefFaultHiThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetOpenThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetShortThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_SetDeltaAngle(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_InitDeltaAngle(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_FloatingPointMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_TestMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_ReadReg(int32_t paramCount, int32_t* p_params);
static nai_status_t SDBasicMenu_WriteReg(int32_t paramCount, int32_t* p_params);

static nai_status_t SDTestMenu_ClearBITStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t SDTestMenu_SetBITErrorLimit(int32_t paramCount, int32_t* p_params);
static nai_status_t SDTestMenu_SetTestAngle(int32_t paramCount, int32_t* p_params);
static nai_status_t SDTestMenu_SetD0TestEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t SDTestMenu_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params);

static nai_status_t DisplayAsHex = FALSE;
static uint32_t g_modId = 0u;

/****** Command Table *******/
enum sd_basicOpsMenu_commands
{
   SD_BASICMENU_CMD_SET_MODE,
   SD_BASICMENU_CMD_SET_CHAN_STATUS_ENABLE,
   SD_BASICMENU_CMD_CLEAR_STATUS,
   SD_BASICMENU_CMD_SET_SIGLOSS_THRESHOLD,
   SD_BASICMENU_CMD_SET_REFLOSS_THRESHOLD,
   SD_BASICMENU_CMD_SET_SIG_HI_THRESHOLD,
   SD_BASICMENU_CMD_SET_REF_HI_THRESHOLD,
   SD_BASICMENU_CMD_SET_OPEN_THRESHOLD,
   SD_BASICMENU_CMD_SET_SHORT_THRESHOLD,
   SD_BASICMENU_CMD_SET_DELTA_ANGLE,
   SD_BASICMENU_CMD_INIT_DELTA_ANGLE,
   SD_BASICMENU_CMD_FLOATING_POINT,
   SD_BASICMENU_CMD_TEST,
   SD_BASICMENU_CMD_DISPLAY_CONVERTED,
   SD_BASICMENU_CMD_DISPLAY_HEX,
   SD_BASICMENU_CMD_READ_REG,
   SD_BASICMENU_CMD_WRITE_REG,
   SD_BASICMENU_CMD_COUNT
};

enum sd_basicOpsMenu_test_commands
{
   SD_TESTMENU_CMD_CLEAR_BIT_STATUS,
   SD_TESTMENU_CMD_SET_BIT_ERROR_LIMIT,
   SD_TESTMENU_CMD_SET_TEST_ANGLE,
   SD_TESTMENU_CMD_ENABLE_D0_TEST,
   SD_TESTMENU_CMD_CHECK_PBIT,
   SD_TESTMENU_CMD_DISPLAY_CONVERTED,
   SD_TESTMENU_CMD_DISPLAY_HEX,
   SD_TESTMENU_CMD_COUNT
};

naiapp_cmdtbl_params_t SD_BasicOpMenuCmds[] = {
   {"Mode",        "Set SD Mode",                             SD_BASICMENU_CMD_SET_MODE,               SDBasicMenu_SetMode},
   {"Enable",      "Enable/Disable Channel Status Reporting", SD_BASICMENU_CMD_SET_CHAN_STATUS_ENABLE, SDBasicMenu_SetChanStatusEnable},
   {"Clear",       "Clear Latched Status",                    SD_BASICMENU_CMD_CLEAR_STATUS,           SDBasicMenu_ClearStatus},
   {"LoSig",       "Set SD Signal Fault Low Threshold",       SD_BASICMENU_CMD_SET_SIGLOSS_THRESHOLD,  SDBasicMenu_SetSigLossThreshold},
   {"LoRef",       "Set SD Reference Fault Low Threshold",    SD_BASICMENU_CMD_SET_REFLOSS_THRESHOLD,  SDBasicMenu_SetRefLossThreshold},
   {"HiSig",       "Set SD Signal Fault High Threshold",      SD_BASICMENU_CMD_SET_SIG_HI_THRESHOLD,   SDBasicMenu_SetSigFaultHiThreshold},
   {"HiRef",       "Set SD Reference Fault High Threshold",   SD_BASICMENU_CMD_SET_REF_HI_THRESHOLD,   SDBasicMenu_SetRefFaultHiThreshold},
   {"Open",        "Set SD Open Threshold",                   SD_BASICMENU_CMD_SET_OPEN_THRESHOLD,     SDBasicMenu_SetOpenThreshold},
   {"Short",       "Set SD Short Threshold",                  SD_BASICMENU_CMD_SET_SHORT_THRESHOLD,    SDBasicMenu_SetShortThreshold},
   {"Delta",       "Set SD Delta Angle Value",                SD_BASICMENU_CMD_SET_DELTA_ANGLE,        SDBasicMenu_SetDeltaAngle},
   {"Init",        "Initialize Delta Angle Status Reporting", SD_BASICMENU_CMD_INIT_DELTA_ANGLE,       SDBasicMenu_InitDeltaAngle},
   {"Float",       "SD Floating-Point Menu",                  SD_BASICMENU_CMD_FLOATING_POINT,         SDBasicMenu_FloatingPointMenu},
   {"Test",        "SD BIT Test Menu",                        SD_BASICMENU_CMD_TEST,                   SDBasicMenu_TestMenu},
   {"Converted",   "Display Values with Conversion",          SD_BASICMENU_CMD_DISPLAY_CONVERTED,      NULL},
   {"Hex Display", "Display Value as Hex",                    SD_BASICMENU_CMD_DISPLAY_HEX,            NULL},
   {"Read",        "Read Register",                           SD_BASICMENU_CMD_READ_REG,               SDBasicMenu_ReadReg},
   {"Write",       "Write Register",                          SD_BASICMENU_CMD_WRITE_REG,              SDBasicMenu_WriteReg}
};

naiapp_cmdtbl_params_t SD_TestMenuCmds[] = {
   {"Status",      "Clear BIT Latched Status",                SD_TESTMENU_CMD_CLEAR_BIT_STATUS,        SDTestMenu_ClearBITStatus},
   {"Limit",       "Set BIT Error Limit",                     SD_TESTMENU_CMD_SET_BIT_ERROR_LIMIT,     SDTestMenu_SetBITErrorLimit},
   {"Angle",       "Set SD Test Angle",                       SD_TESTMENU_CMD_SET_TEST_ANGLE,          SDTestMenu_SetTestAngle},
   {"Enable",      "Enable or Disable D0 Test",               SD_TESTMENU_CMD_ENABLE_D0_TEST,          SDTestMenu_SetD0TestEnable},
   {"Power On",    "Check Power-On BIT",                      SD_TESTMENU_CMD_CHECK_PBIT,              SDTestMenu_CheckPowerOnBIT},
   {"Converted",   "Display Values with Conversion",          SD_TESTMENU_CMD_DISPLAY_CONVERTED,       NULL},
   {"Hex",         "Display Values as Hex",                   SD_TESTMENU_CMD_DISPLAY_HEX,             NULL}
};
/*****************************************************************************/
/**
<summary>
The purpose of the SD_BasicOpsMenu is to illustrate the methods to call in the
naibrd library to perform basic operations with the SD 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 SD_BasicOpsMenu(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               g_modId = moduleID;
               if ((moduleID != 0))
               {
                  SDBasicMenu_Run(cardIndex, module, moduleID);
               }
            }
         }

         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   printf("\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}
/*****************************************************************************/
/**
<summary>
SDBasicMenu_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 SDBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = FALSE, bCmdFound = FALSE;
   int32_t MAX_CHANNELS = naibrd_SD_GetChannelCount(modid);
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  sd_basicops_params;
   p_naiapp_AppParameters_t sd_basicOps_params = &sd_basicops_params;
   sd_basicOps_params->cardIndex = cardIndex;
   sd_basicOps_params->module = module;
   sd_basicOps_params->maxChannels = naibrd_SD_GetChannelCount(modid);
   sd_basicOps_params->modId = modid;
   sd_basicOps_params->displayHex = FALSE;

   naiapp_utils_LoadParamMenuCommands(SD_BASICMENU_CMD_COUNT, SD_BasicOpMenuCmds);
   do
   {
      naiapp_utils_LoadParamMenuCommands(SD_BASICMENU_CMD_COUNT, SD_BasicOpMenuCmds);
      SDBasicMenu_displayMeasurements(cardIndex, module, modid);
      naiapp_display_ParamMenuCommands((int8_t*)"MENU_TITLE");
      printf("\n Type command or %c to quit : ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit && inputResponseCnt > 0)
      {
         naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
         if((cmd >= 0) && (cmd < SD_BASICMENU_CMD_COUNT))
         {
            if (cmd == SD_BASICMENU_CMD_DISPLAY_CONVERTED)
               DisplayAsHex = FALSE;
            else if (cmd == SD_BASICMENU_CMD_DISPLAY_HEX)
               DisplayAsHex = TRUE;
            else
            {
               if ((cmd == SD_BASICMENU_CMD_SET_MODE) || (cmd == SD_BASICMENU_CMD_SET_CHAN_STATUS_ENABLE) ||
                   (cmd == SD_BASICMENU_CMD_SET_SIGLOSS_THRESHOLD) || (cmd == SD_BASICMENU_CMD_SET_REFLOSS_THRESHOLD) ||
                   (cmd == SD_BASICMENU_CMD_CLEAR_STATUS) || (cmd == SD_BASICMENU_CMD_FLOATING_POINT) ||
                   (cmd == SD_BASICMENU_CMD_SET_DELTA_ANGLE) || (cmd == SD_BASICMENU_CMD_INIT_DELTA_ANGLE) ||
                   (cmd == SD_BASICMENU_CMD_SET_SIG_HI_THRESHOLD) || (cmd == SD_BASICMENU_CMD_SET_REF_HI_THRESHOLD) ||
                   (cmd == SD_BASICMENU_CMD_SET_OPEN_THRESHOLD) || (cmd == SD_BASICMENU_CMD_SET_SHORT_THRESHOLD))
                  naiapp_query_ChannelNumber(MAX_CHANNELS, 1, &sd_basicOps_params->channel);
               else
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  SD_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)sd_basicOps_params);
               }
            }
         }
         else
            printf(" Invalid command entered\n");
      }
   } while (!bQuit);
   return bQuit;
}
/*****************************************************************************/
/**
<summary>
SDBasicMenu_displayMeasurements illustrates the methods to call in the naibrd library
to retrieve the basic operation configuration states and status states
as well as the current SD reading for all channels.
</summary>
*/
/*****************************************************************************/
static void SDBasicMenu_displayMeasurements(int32_t cardIndex, int32_t module, uint32_t modid)
{
   uint32_t chanStatusEnable = 0u;
   int32_t channel = 0, MAX_CHANNEL = naibrd_SD_GetChannelCount(modid);
   nai_sd_format_t mode = 0u;
   float64_t angle = 0.0, frequency = 0.0, sigvolt = 0.0, refvolt = 0.0, minsigvolt = 0.0, minrefvolt = 0.0;
   float64_t maxsigvolt = 0.0, maxrefvolt = 0.0, openThres = 0.0, shortThres = 0.0, deltaAngle = 0.0;
   uint32_t BitStatus = NAI_STATUS_BIT_LO, SigLoss = NAI_STATUS_BIT_LO, RefLoss = NAI_STATUS_BIT_LO, SummaryStatus = NAI_STATUS_BIT_LO;
   uint32_t SigHiStat = NAI_STATUS_BIT_LO, RefHiStat = NAI_STATUS_BIT_LO, OpenStat = NAI_STATUS_BIT_LO, ShortStat = NAI_STATUS_BIT_LO;
   uint32_t DeltaAngleStat = NAI_STATUS_BIT_LO, LockLossStat = NAI_STATUS_BIT_LO;
   uint32_t rawangle = 0u, rawfreq = 0u, rawsigvolt = 0u, rawrefvolt = 0u, rawminsigvolt = 0u, rawminrefvolt = 0u;
   uint32_t rawmaxsigvolt = 0u, rawmaxrefvolt = 0u, rawOpenThres = 0u, rawShortThres = 0u, rawDeltaAngle = 0u;
   char strChanStatusEnable[10] = "";

   printf("\n\n =================================================================================================================================================== \n");
   printf(" channel  Mode          Angle    Frequency     Signal      Ref          Min       Min           Max       Max          Open        Short       Delta\n");
   printf("                                             Voltage    Voltage     Signal    Reference     Signal    Reference    Threshold   Threshold     Angle\n");
   printf(" ---------------------------------------------------------------------------------------------------------------------------------------------------\n");
   for( channel = 1; channel <= MAX_CHANNEL; channel++)
   {
      printf("  %2d    ", channel);
      check_status(naibrd_SD_GetChanMode(cardIndex, module, channel, &mode));
      SDBasicMenu_displayMode(mode);
      if (DisplayAsHex)
      {
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_ANGLE, &rawangle));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_FREQUENCY, &rawfreq));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SIGNAL_VOLTAGE, &rawsigvolt));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_REF_VOLTAGE, &rawrefvolt));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SIG_LOSS_THRESHOLD, &rawminsigvolt));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_REF_LOSS_THRESHOLD, &rawminrefvolt));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SIG_FAULT_HI_THRESHOLD, &rawmaxsigvolt));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_REF_FAULT_HI_THRESHOLD, &rawmaxrefvolt));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_OPEN_THRESHOLD, &rawOpenThres));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SHORT_THRESHOLD, &rawShortThres));
         check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_ANGLE_DELTA, &rawDeltaAngle));
         printf("0x%08X  0x%08X  0x%08X  0x%08X 0x%08X  0x%08X  0x%08X  0x%08X  0x%08X  0x%08X  0x%08X\n", rawangle, rawfreq, rawsigvolt,
                rawrefvolt, rawminsigvolt, rawminrefvolt, rawmaxsigvolt, rawmaxrefvolt, rawOpenThres, rawShortThres, rawDeltaAngle);
      }
      else
      {
         check_status(naibrd_SD_GetAngle(cardIndex, module, channel, &angle));
         check_status(naibrd_SD_GetFrequency(cardIndex, module, channel, &frequency));
         check_status(naibrd_SD_GetSignalVoltage(cardIndex, module, channel, &sigvolt));
         check_status(naibrd_SD_GetRefVoltage(cardIndex, module, channel, &refvolt));
         check_status(naibrd_SD_GetSigLossThreshold(cardIndex, module, channel, &minsigvolt));
         check_status(naibrd_SD_GetRefLossThreshold(cardIndex, module, channel, &minrefvolt));
         check_status(naibrd_SD_GetThreshold(cardIndex, module, channel, NAIBRD_SD_SIG_FAULT_HI_THRESHOLD, &maxsigvolt));
         check_status(naibrd_SD_GetThreshold(cardIndex, module, channel, NAIBRD_SD_REF_FAULT_HI_THRESHOLD, &maxrefvolt));
         check_status(naibrd_SD_GetThreshold(cardIndex, module, channel, NAIBRD_SD_OPEN_THRESHOLD, &openThres));
         check_status(naibrd_SD_GetThreshold(cardIndex, module, channel, NAIBRD_SD_SHORT_THRESHOLD, &shortThres));
         check_status(naibrd_SD_GetAngleDelta(cardIndex, module, channel, &deltaAngle));
         printf("%9.4f      %6.2f      %6.2f     %6.2f     %6.2f       %6.2f     %6.2f       %6.2f       %6.2f      %6.2f   %9.4f\n", angle,
                frequency, sigvolt, refvolt, minsigvolt, minrefvolt, maxsigvolt, maxrefvolt, openThres, shortThres, deltaAngle);
      }
   }

   printf("\n\n ============================================================================================================================== \n");
   printf(" channel  channelStat     BIT     Sig Fault   Ref Fault   Sig Fault   Ref Fault   Lock Loss    Open    Short   Delta Angle  Summary\n");
   printf("         Enable      Status   Lo Status   Lo Status   Hi Status   Hi Status    Status     Status   Status    Status     Status\n");
   printf(" ------------------------------------------------------------------------------------------------------------------------------\n");
   for( channel = 1; channel <= MAX_CHANNEL; channel++)
   {
      printf("  %2d    ", channel);
      check_status(naibrd_SD_GetChanStatusEnable(cardIndex, module, channel, &chanStatusEnable));
      switch (chanStatusEnable)
      {
         case TRUE:
            sprintf(strChanStatusEnable, "Enabled ");
         break;
         case FALSE:
            sprintf(strChanStatusEnable, "Disabled");
         break;
         default:
            sprintf(strChanStatusEnable, "Unknown ");
         break;
      }
      printf("%8s  ", strChanStatusEnable);
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_BIT_LATCHED, &BitStatus));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_SIGNAL_LATCHED, &SigLoss));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_REF_LATCHED, &RefLoss));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_2SPDLOCKLOSS_LATCHED, &LockLossStat));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_ANGLEDELTA_LATCHED, &DeltaAngleStat));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_OPEN_LATCHED, &OpenStat));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_SHORT_LATCHED, &ShortStat));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_REF_FAULT_HIGH_LATCHED, &RefHiStat));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_SIG_FAULT_HIGH_LATCHED, &SigHiStat));
      check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_SUMMARY_LATCHED, &SummaryStatus));
      SDBasicMenu_displayStatus((nai_status_bit_t)BitStatus, (nai_status_bit_t)SigLoss, (nai_status_bit_t)RefLoss,
                                (nai_status_bit_t)LockLossStat, (nai_status_bit_t)DeltaAngleStat, (nai_status_bit_t)OpenStat,
                                (nai_status_bit_t)ShortStat, (nai_status_bit_t)RefHiStat, (nai_status_bit_t)SigHiStat, (nai_status_bit_t)SummaryStatus);
   }
}
/*****************************************************************************/
/**
<summary>
SDBasicMenu_displayMode prints mode value.
</summary>
*/
/*****************************************************************************/
static void SDBasicMenu_displayMode(nai_sd_format_t mode)
{
   if (mode == NAI_SD_RESOLVER)
      printf("RSL(%d)     ", mode);
   else if (mode == NAI_SD_SYNCHRO)
      printf("SYN(%d)     ", mode);
   else
      printf("UNKNOWN(%d) ", mode);
}
/*****************************************************************************/
/**
<summary>
SDBasicMenu_displayStatus prints to stdin the BIT Status,
Signal Fault Low Status, Reference Fault Low Status,
Signal Fault High Status, Reference Fault High Status,
Two Speed Lock Loss Status, Open Status, Short Status, Delta Angle Status,
and Summary Status.
</summary>
*/
/*****************************************************************************/
static void SDBasicMenu_displayStatus(nai_status_bit_t BitStatus, nai_status_bit_t SigLoss, nai_status_bit_t RefLoss,
                                      nai_status_bit_t LockLossStat, nai_status_bit_t DeltaAngleStat, nai_status_bit_t OpenStat,
                                      nai_status_bit_t ShortStat, nai_status_bit_t RefHiStat, nai_status_bit_t SigHiStat,
                                      nai_status_bit_t SummaryStatus)
{
   if (BitStatus == NAI_STATUS_BIT_HI)
      printf("   FAILED  ");
   else if (BitStatus == NAI_STATUS_BIT_LO)
      printf("   Normal  ");
   else
      printf("   Error   ");

   if (SigLoss == NAI_STATUS_BIT_HI)
      printf("  FAILED     ");
   else if (SigLoss == NAI_STATUS_BIT_LO)
      printf("  Normal     ");
   else
      printf("  Error      ");

   if (RefLoss == NAI_STATUS_BIT_HI)
      printf(" FAILED   ");
   else if (RefLoss == NAI_STATUS_BIT_LO)
      printf(" Normal   ");
   else
      printf("  Error   ");

   if (SigHiStat == NAI_STATUS_BIT_HI)
      printf("   FAILED   ");
   else if (SigHiStat == NAI_STATUS_BIT_LO)
      printf("   Normal   ");
   else
      printf("    Error   ");

   if (RefHiStat == NAI_STATUS_BIT_HI)
      printf("   FAILED   ");
   else if (RefHiStat == NAI_STATUS_BIT_LO)
      printf("   Normal   ");
   else
      printf("    Error   ");

   if (LockLossStat == NAI_STATUS_BIT_HI)
      printf("   FAILED   ");
   else if (LockLossStat == NAI_STATUS_BIT_LO)
      printf("   Normal   ");
   else
      printf("    Error   ");

   if (OpenStat == NAI_STATUS_BIT_HI)
      printf("  FAILED  ");
   else if (OpenStat == NAI_STATUS_BIT_LO)
      printf("  Normal  ");
   else
      printf("   Error  ");

   if (ShortStat == NAI_STATUS_BIT_HI)
      printf(" FAILED   ");
   else if (ShortStat == NAI_STATUS_BIT_LO)
      printf(" Normal   ");
   else
      printf("  Error   ");

   if (DeltaAngleStat == NAI_STATUS_BIT_HI)
      printf(" FAILED   ");
   else if (DeltaAngleStat == NAI_STATUS_BIT_LO)
      printf(" Normal   ");
   else
      printf("  Error   ");

   if (SummaryStatus == NAI_STATUS_BIT_HI)
      printf("  FAILED\n");
   else if (SummaryStatus == NAI_STATUS_BIT_LO)
      printf("  Normal\n");
   else
      printf("   Error\n");
}

static nai_status_t SDBasicMenu_SetMode(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sd_format_t mode;
   p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ad_params->cardIndex;
   int32_t module = p_ad_params->module;
   int32_t channel = p_ad_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Select SD Mode to set: [0 (RSL) or 1 (SYN)]: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if ((inputBuffer[0] == '0') || (inputBuffer[0] == '1'))
      {
         if (inputBuffer[0] == '0')
            mode = NAI_SD_RESOLVER;
         else
            mode = NAI_SD_SYNCHRO;
         check_status(naibrd_SD_SetChanMode(cardIndex, module, channel, mode));
      }
      else
         printf("\nInvalid SD Mode Entered\n");
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetChanStatusEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t enable = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Select Channel Status Enabled/Disabled Setting to set (0 for Disabled, 1 for Enabled): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      if ((inputBuffer[0] == '0') || (inputBuffer[0] == '1'))
      {
         if (inputBuffer[0] == '1')
         {
            enable = 1u;
         }
         check_status(naibrd_SD_SetChanStatusEnable(cardIndex, module, channel, enable));
      }
      else
      {
         printf("\nInvalid setting entered\n");
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_ClearStatus(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sd_status_type_t statusTypeToClear = 0u;
   char statusTypeStr[18] = "";
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Select Latched Status Type to clear: (0 for BIT, 1 for Signal Fault Low, 2 for Ref Fault Low, 3 for Signal Fault High, ");
   printf("4 for Ref Fault High, 5 for Lock Loss, 6 for Open, 7 for Short, 8 for Delta Angle, 9 for Summary, q for quit): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      switch (inputBuffer[0])
      {
         case '0':
            statusTypeToClear = NAI_SD_STATUS_BIT_LATCHED;
            sprintf(statusTypeStr, "BIT");
         break;
         case '1':
            statusTypeToClear = NAI_SD_STATUS_SIGNAL_LATCHED;
            sprintf(statusTypeStr, "Signal Fault Low");
         break;
         case '2':
            statusTypeToClear = NAI_SD_STATUS_REF_LATCHED;
            sprintf(statusTypeStr, "Ref Fault Low");
         break;
         case '3':
            statusTypeToClear = NAI_SD_STATUS_SIG_FAULT_HIGH_LATCHED;
            sprintf(statusTypeStr, "Signal Fault High");
         break;
         case '4':
            statusTypeToClear = NAI_SD_STATUS_REF_FAULT_HIGH_LATCHED;
            sprintf(statusTypeStr, "Ref Fault High");
         break;
         case '5':
            statusTypeToClear = NAI_SD_STATUS_2SPDLOCKLOSS_LATCHED;
            sprintf(statusTypeStr, "Lock Loss");
         break;
         case '6':
            statusTypeToClear = NAI_SD_STATUS_OPEN_LATCHED;
            sprintf(statusTypeStr, "Open");
         break;
         case '7':
            statusTypeToClear = NAI_SD_STATUS_SHORT_LATCHED;
            sprintf(statusTypeStr, "Short");
         break;
         case '8':
            statusTypeToClear = NAI_SD_STATUS_ANGLEDELTA_LATCHED;
            sprintf(statusTypeStr, "Delta Angle");
         break;
         case '9':
            statusTypeToClear = NAI_SD_STATUS_SUMMARY_LATCHED;
            sprintf(statusTypeStr, "Summary");
         break;
         case 'q':
         case 'Q':
            bQuit = TRUE;
         break;
         default:
            bQuit = TRUE;
            printf("\nInvalid status type entered\n");
         break;
      }

      if (!bQuit)
      {
         printf("\nAre you sure you want to clear the %s status? (Y for Yes or N for No): ", statusTypeStr);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if ((!bQuit) && (inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'Y'))
         {
            check_status(naibrd_SD_ClearStatus(cardIndex, module, channel, statusTypeToClear));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetSigLossThreshold(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t threshold = 0.0;
   uint32_t thresholdRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Enter the minimum signal voltage to allow before raising an alert: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      printf("Type Raw Hex Signal Low Threshold Value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         thresholdRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (thresholdRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SIG_LOSS_THRESHOLD, thresholdRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SIG_LOSS_THRESHOLD, thresholdRaw));
         }
      }
   }
   else
   {
      printf("Enter the minimum signal voltage to allow before raising an alert: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         threshold = atof((const char*)inputBuffer);
         if (threshold == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetSigLossThreshold(cardIndex, module, channel, threshold));
            }
            else
            {
               printf("\nInvalid Signal Threshold Entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetSigLossThreshold(cardIndex, module, channel, threshold));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetRefLossThreshold(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t threshold = 0.0;
   uint32_t thresholdRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Enter the minimum reference voltage to allow before raising an alert: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      printf("Type Raw Hex Reference Low Threshold Value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         thresholdRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (thresholdRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_REF_LOSS_THRESHOLD, thresholdRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_REF_LOSS_THRESHOLD, thresholdRaw));
         }
      }
   }
   else
   {
      printf("Enter the minimum reference voltage to allow before raising an alert: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         threshold = atof((const char*)inputBuffer);
         if (threshold == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetRefLossThreshold(cardIndex, module, channel, threshold));
            }
            else
            {
               printf("\nInvalid Reference Threshold Entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetRefLossThreshold(cardIndex, module, channel, threshold));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetSigFaultHiThreshold(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t threshold = 0.0;
   uint32_t thresholdRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   if (DisplayAsHex)
   {
      printf("Type Raw Hex Signal High Threshold Value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         thresholdRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (thresholdRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SIG_FAULT_HI_THRESHOLD, thresholdRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SIG_FAULT_HI_THRESHOLD, thresholdRaw));
         }
      }
   }
   else
   {
      printf("Enter the maximum signal voltage to allow before raising an alert: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         threshold = atof((const char*)inputBuffer);
         if (threshold == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_SIG_FAULT_HI_THRESHOLD, threshold));
            }
            else
            {
               printf("\nInvalid Signal Threshold Entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_SIG_FAULT_HI_THRESHOLD, threshold));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetRefFaultHiThreshold(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t threshold = 0.0;
   uint32_t thresholdRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   if (DisplayAsHex)
   {
      printf("Type Raw Hex Reference High Threshold Value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         thresholdRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (thresholdRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_REF_FAULT_HI_THRESHOLD, thresholdRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_REF_FAULT_HI_THRESHOLD, thresholdRaw));
         }
      }
   }
   else
   {
      printf("Enter the maximum reference voltage to allow before raising an alert: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         threshold = atof((const char*)inputBuffer);
         if (threshold == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_REF_FAULT_HI_THRESHOLD, threshold));
            }
            else
            {
               printf("\nInvalid Reference Threshold Entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_REF_FAULT_HI_THRESHOLD, threshold));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetOpenThreshold(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t threshold = 0.0;
   uint32_t thresholdRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   if (DisplayAsHex)
   {
      printf("Type Raw Hex Open Threshold Value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         thresholdRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (thresholdRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_OPEN_THRESHOLD, thresholdRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_OPEN_THRESHOLD, thresholdRaw));
         }
      }
   }
   else
   {
      printf("Enter Open Threshold value to set: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         threshold = atof((const char*)inputBuffer);
         if (threshold == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_OPEN_THRESHOLD, threshold));
            }
            else
            {
               printf("\nInvalid Open Threshold Entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_OPEN_THRESHOLD, threshold));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetShortThreshold(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t threshold = 0.0;
   uint32_t thresholdRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   if (DisplayAsHex)
   {
      printf("Type Raw Hex Short Threshold Value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         thresholdRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (thresholdRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SHORT_THRESHOLD, thresholdRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_SHORT_THRESHOLD, thresholdRaw));
         }
      }
   }
   else
   {
      printf("Enter Short Threshold value to set: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         threshold = atof((const char*)inputBuffer);
         if (threshold == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_SHORT_THRESHOLD, threshold));
            }
            else
            {
               printf("\nInvalid Short Threshold Entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetThreshold(cardIndex, module, channel, NAIBRD_SD_SHORT_THRESHOLD, threshold));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_SetDeltaAngle(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t deltaAngle = 0.0;
   uint32_t deltaAngleRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   if (DisplayAsHex)
   {
      printf("Type Raw Hex Delta Angle Value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         deltaAngleRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (deltaAngleRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_ANGLE_DELTA, deltaAngleRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_ANGLE_DELTA, deltaAngleRaw));
         }
      }
   }
   else
   {
      printf("Type Delta Angle Value to set: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         deltaAngle = atof((const char*)inputBuffer);
         if (deltaAngle == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetAngleDelta(cardIndex, module, channel, deltaAngle));
            }
            else
            {
               printf("\nInvalid Delta Angle value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetAngleDelta(cardIndex, module, channel, deltaAngle));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_InitDeltaAngle(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_status_t status = NAI_ERROR_UNKNOWN;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Do you want to enable or disable Delta Angle Status reporting for channel %d? (1 for Enable, 0 for Disable): ", channel);
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      if (inputBuffer[0] == '0')
      {
         status = check_status(naibrd_SD_SetAngleDataInit(cardIndex, module, channel, (bool_t)0x0u));
         if (status == NAI_SUCCESS)
         {
            printf("\nDelta Angle Status reporting has been disabled for channel %d.\n", channel);
         }
      }
      else if (inputBuffer[0] == '1')
      {
         status = check_status(naibrd_SD_SetAngleDataInit(cardIndex, module, channel, (bool_t)0x1u));
         if (status == NAI_SUCCESS)
         {
            printf("\nDelta Angle Status reporting has been enabled for channel %d.\n", channel);
         }
      }
      else
      {
         printf("\nInvalid selection entered\n");
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_FloatingPointMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t floatModeEnabled = FALSE;
   int32_t channel= 0;
   int32_t maxChannel = 0;
   float64_t angleOffset = 0.0, angleScale = 0.0, velocityOffset = 0.0, velocityScale = 0.0;
   uint32_t attributeTypeToSet = 0u;
   bool_t bQuit = FALSE;
   bool_t bExit = FALSE;
   float64_t valueToSet = 0.0;
   char strFloatModeEnabled[10] = "";
   char strAttributeType[20] = "";
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t chan= p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   maxChannel = naibrd_SD_GetChannelCount(g_modId);

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   while (bQuit == FALSE)
   {
      printf("====================================================\n");
      printf("%4s%12s%11s%13s%12s\n", "Chan", "Angle", "Angle", "Velocity", "Velocity");
      printf("%4s%12s%12s%10s%13s\n", "", "Scale", "Offset", "Scale", "Offset");
      printf("----------------------------------------------------\n");
      for (channel= 1; channel<= maxChannel; chan++)
      {
         check_status(naibrd_SD_GetFloatingPointAngleScale(cardIndex, module, chan, &angleScale));
         check_status(naibrd_SD_GetFloatingPointAngleOffset(cardIndex, module, chan, &angleOffset));
         check_status(naibrd_SD_GetFloatingPointVelocityScale(cardIndex, module, chan, &velocityScale));
         check_status(naibrd_SD_GetFloatingPointVelocityOffset(cardIndex, module, chan, &velocityOffset));

         printf("%2d", chan);
         printf("%14.4f%12.4f%12.4f%12.4f\n", angleScale, angleOffset, velocityScale, velocityOffset);
      }
      check_status(naibrd_GetFloatingPointModeEnable(cardIndex, module, &floatModeEnabled));
      switch (floatModeEnabled)
      {
         case FALSE:
            sprintf(strFloatModeEnabled, "DISABLED");
         break;
         case TRUE:
            sprintf(strFloatModeEnabled, "ENABLED ");
         break;
         default:
            sprintf(strFloatModeEnabled, "UNKNOWN ");
         break;
      }
      printf("Floating-Point Mode: %s\n\n", strFloatModeEnabled);
      printf("\nDo you want to enable/disable floating-point mode, set floating-point attributes, or refresh the display? (0 for mode, 1 for attributes, q for quit, anything else to refresh the display): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0) && ((inputBuffer[0] == '0') || (inputBuffer[0] == '1')))
      {
         if (inputBuffer[0] == '1')
         {
            printf("\nSet Floating-Point Attributes (0 for Angle Scale, 1 for Angle Offset, 2 for Velocity Scale, 3 for Velocity Offset, anything else to refresh the display): ");
            bExit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
            if ((!bExit) && (inputResponseCnt > 0))
            {
               switch (inputBuffer[0])
               {
                  case '0':
                     attributeTypeToSet = 0u;
                     sprintf(strAttributeType, "Angle Scale");
                  break;
                  case '1':
                     attributeTypeToSet = 1u;
                     sprintf(strAttributeType, "Angle Offset");
                  break;
                  case '2':
                     attributeTypeToSet = 2u;
                     sprintf(strAttributeType, "Velocity Scale");
                  break;
                  case '3':
                     attributeTypeToSet = 3u;
                     sprintf(strAttributeType, "Velocity Offset");
                  break;
                  default:
                     bExit = TRUE;
                  break;
               }

               if (!bExit)
               {
                  printf("\nEnter %s value to set: ", strAttributeType);
                  bExit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
                  if ((!bExit) && (inputResponseCnt > 0))
                  {
                     valueToSet = atof((const char*)inputBuffer);
                     if (valueToSet == 0.0)
                     {
                        if (inputBuffer[0] == '0')
                        {
                           switch (attributeTypeToSet)
                           {
                              case 0u:
                                 check_status(naibrd_SD_SetFloatingPointAngleScale(cardIndex, module, channel, valueToSet));
                              break;
                              case 1u:
                                 check_status(naibrd_SD_SetFloatingPointAngleOffset(cardIndex, module, channel, valueToSet));
                              break;
                              case 2u:
                                 check_status(naibrd_SD_SetFloatingPointVelocityScale(cardIndex, module, channel, valueToSet));
                              break;
                              case 3u:
                                 check_status(naibrd_SD_SetFloatingPointVelocityOffset(cardIndex, module, channel, valueToSet));
                              break;
                           }
                        }
                        else
                        {
                           printf("\nInvalid value entered\n");
                        }
                     }
                     else
                     {
                        switch (attributeTypeToSet)
                        {
                           case 0u:
                              check_status(naibrd_SD_SetFloatingPointAngleScale(cardIndex, module, channel, valueToSet));
                           break;
                           case 1u:
                              check_status(naibrd_SD_SetFloatingPointAngleOffset(cardIndex, module, channel, valueToSet));
                           break;
                           case 2u:
                              check_status(naibrd_SD_SetFloatingPointVelocityScale(cardIndex, module, channel, valueToSet));
                           break;
                           case 3u:
                              check_status(naibrd_SD_SetFloatingPointVelocityOffset(cardIndex, module, channel, valueToSet));
                           break;
                        }
                     }
                  }
               }
            }
         }
         else
         {
            printf("\nEnable or Disable floating-point mode? (0 to disable, 1 to enable, anything else to refresh the display): ");
            bExit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
            if ((!bExit) && (inputResponseCnt > 0))
            {
               switch (inputBuffer[0])
               {
                  case '0':
                     check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, FALSE));
                  break;
                  case '1':
                     check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, TRUE));
                  break;
               }
            }
         }
      }
   }

   return NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_TestMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   int32_t cmd = 0;
   float64_t testAngle = 0.0;
   uint32_t testAngleRaw = 0u;
   bool_t d0TestEnabled = FALSE;
   bool_t pBitComplete = 0u;
   uint32_t bitStatus = 0u;
   float64_t bitErrorLimit = 0.0;
   uint32_t bitErrorLimitRaw = 0u;
   int32_t channelCount = 0;
   char strBITStatus[7] = "";
   char strD0TestEnabled[10] = "";
   char strPBITComplete[15] = "";
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel = p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   channelCount = naibrd_SD_GetChannelCount(g_modId);
   naiapp_utils_LoadParamMenuCommands(SD_TESTMENU_CMD_COUNT, SD_TestMenuCmds);
   do
   {
      printf("\n\n ============================= \n");
      printf(" channel    BIT        BIT Error\n");
      printf("         Status        Limit\n");
      printf(" -----------------------------\n");
      for (channel = 1; channel <= channelCount; channel++)
      {
         check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_BIT_LATCHED, &bitStatus));
         switch (bitStatus)
         {
            case (uint32_t)NAI_STATUS_BIT_LO:
               sprintf(strBITStatus, "Normal");
            break;
            case (uint32_t)NAI_STATUS_BIT_HI:
               sprintf(strBITStatus, "FAILED");
            break;
            default:
               sprintf(strBITStatus, "Error ");
            break;
         }
         if (DisplayAsHex)
         {
            check_status(naibrd_SD_GetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_BIT_ERROR_LIMIT, &bitErrorLimitRaw));
            printf("  %2d     %s     0x%08X\n", channel, strBITStatus, bitErrorLimitRaw);
         }
         else
         {
            check_status(naibrd_SD_GetBITErrorLimit(cardIndex, module, channel, &bitErrorLimit));
            printf("  %2d     %s   %12.4f\n", channel, strBITStatus, bitErrorLimit);
         }
      }
      if (DisplayAsHex)
      {
         check_status(naibrd_SD_GetRaw(cardIndex, module, NAI_SD_RAW_TEST_ANGLE, &testAngleRaw));
      }
      else
      {
         check_status(naibrd_SD_GetTestAngle(cardIndex, module, &testAngle));
      }
      check_status(naibrd_SD_GetModuleBITEnable(cardIndex, module, NAI_SD_TEST_ENABLE_D0, &d0TestEnabled));
      switch (d0TestEnabled)
      {
         case TRUE:
            sprintf(strD0TestEnabled, "ENABLED ");
         break;
         case FALSE:
            sprintf(strD0TestEnabled, "DISABLED");
         break;
         default:
            sprintf(strD0TestEnabled, "UNKNOWN ");
         break;
      }
      check_status(naibrd_SD_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
      switch (pBitComplete)
      {
         case TRUE:
            sprintf(strPBITComplete, "COMPLETED");
         break;
         case FALSE:
            sprintf(strPBITComplete, "NOT COMPLETED");
         break;
         default:
            sprintf(strPBITComplete, "UNKNOWN");
         break;
      }
      if (DisplayAsHex)
      {
         printf("\nTest Angle Raw Hex Value: 0x%08X\n", testAngleRaw);
      }
      else
      {
         printf("\nTest Angle: %-16.8f\n", testAngle);
      }
      printf("D0 Test Enabled/Disabled: %s\n", strD0TestEnabled);
      printf("Power-On BIT Complete: %s\n", strPBITComplete);
      naiapp_display_ParamMenuCommands((int8_t*)"SD Test Menu");
      printf("\n Type command or %c to quit : ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
         if ((cmd >= 0) && (cmd < SD_TESTMENU_CMD_COUNT))
         {
            if (cmd == SD_TESTMENU_CMD_DISPLAY_CONVERTED)
            {
               DisplayAsHex = FALSE;
            }
            else if (cmd == SD_TESTMENU_CMD_DISPLAY_HEX)
            {
               DisplayAsHex = TRUE;
            }
            else if ((cmd == SD_TESTMENU_CMD_CLEAR_BIT_STATUS) || (cmd == SD_TESTMENU_CMD_SET_BIT_ERROR_LIMIT))
            {
               naiapp_query_ChannelNumber(channelCount, 1, &p_sd_params->channel);
               SD_TestMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_params);
            }
            else
            {
               SD_TestMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_params);
            }
         }
         else
         {
            printf(" Invalid command entered\n");
         }
      }
   } while (!bQuit);

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDBasicMenu_ReadReg(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t Addr = 0;
   uint32_t data = 0;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   uint32_t dataCount;
   uint32_t idx = 0;
   uint32_t rowAddr = 0;
   uint32_t addrOffset = 0;
   int8_t  buffer[500];

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the Address(relative to the MB) to read from: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
        Addr = strtol(((const char *)inputBuffer), NULL, 16);
        check_status(naibrd_ReadReg32(cardIndex, 0, Addr, &data));
        printf("Read Register: 0x%x\n", Addr);
        printf("Read value: 0x%x\n", data);
      }
   }
   do
   {
      printf("\nEnter the Address(relative to the MB) to read from: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         addrOffset = strtol ((const char *)inputBuffer, NULL, 16);
         printf("Enter Number of data to retrieve: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            memset(buffer, 0, sizeof(buffer));
            sprintf((char *)buffer, "\n            0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x0x%-10x\n",
                                         0x0, 0x4, 0x8, 0xc, 0x10, 0x14, 0x18, 0x1c, 0x20, 0x24, 0x28, 0x2c, 0x30, 0x34, 0x38, 0x3c);
            printf("%s", buffer);
            dataCount = strtol ((const char *)inputBuffer, NULL, 10);
            for(idx=0; idx < dataCount; idx++)
            {
               naibrd_ReadReg32(cardIndex, 0, addrOffset+idx*4, &data);
               if( (idx % 16) == 0)
               {
                  rowAddr = 4*idx + addrOffset;
                  printf("            \n0x%-10x0x%-10x", rowAddr,data);
               }
               else
                  printf("0x%-10x", data);
            }
         }
      }
      printf("\nType %c to exit: ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   }while(!bQuit);
   return bQuit;
}
static nai_status_t SDBasicMenu_WriteReg(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t Addr = 0;
   uint32_t data = 0;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the Address(relative to the MB) to write to: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         Addr = strtol(((const char *)inputBuffer), NULL, 16);
         printf("\nEnter the value to write: 0x");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               data = strtol(((const char *)inputBuffer), NULL, 16);
               check_status(naibrd_WriteReg32(cardIndex, 0, Addr, data));
               printf("Write Register: 0x%x\n", Addr);
               printf("Write value: 0x%x\n", data);
            }
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDTestMenu_ClearBITStatus(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel = p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Are you sure you want to clear the Latched BIT status? (Y for Yes or N for No): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'Y'))
   {
      check_status(naibrd_SD_ClearStatus(cardIndex, module, channel, NAI_SD_STATUS_BIT_LATCHED));
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDTestMenu_SetBITErrorLimit(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t bitErrorLimit = 0.0;
   uint32_t bitErrorLimitRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel = p_sd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   if (DisplayAsHex)
   {
      printf("Type BIT Error Limit Raw Hex value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         bitErrorLimitRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (bitErrorLimitRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_BIT_ERROR_LIMIT, bitErrorLimitRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetChannelRaw(cardIndex, module, channel, NAI_SD_CHAN_RAW_BIT_ERROR_LIMIT, bitErrorLimitRaw));
         }
      }
   }
   else
   {
      printf("Type BIT Error Limit value to set: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         bitErrorLimit = atof((const char*)inputBuffer);
         if (bitErrorLimit == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetBITErrorLimit(cardIndex, module, channel, bitErrorLimit));
            }
            else
            {
               printf("\nInvalid BIT Error Limit entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetBITErrorLimit(cardIndex, module, channel, bitErrorLimit));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDTestMenu_SetTestAngle(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t testAngle = 0.0;
   uint32_t testAngleRaw = 0u;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   if (DisplayAsHex)
   {
      printf("Type Test Angle Raw Hex value to set: 0x");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         testAngleRaw = (uint32_t)strtoul((const char*)inputBuffer, NULL, 16);
         if (testAngleRaw == 0u)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetRaw(cardIndex, module, NAI_SD_RAW_TEST_ANGLE, testAngleRaw));
            }
            else
            {
               printf("\nInvalid value entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetRaw(cardIndex, module, NAI_SD_RAW_TEST_ANGLE, testAngleRaw));
         }
      }
   }
   else
   {
      printf("Type Test Angle value to set: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         testAngle = atof((const char*)inputBuffer);
         if (testAngle == 0.0)
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_SD_SetTestAngle(cardIndex, module, testAngle));
            }
            else
            {
               printf("\nInvalid Test Angle entered\n");
            }
         }
         else
         {
            check_status(naibrd_SD_SetTestAngle(cardIndex, module, testAngle));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDTestMenu_SetD0TestEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("Enable or Disable D0 Test (0 for disable, 1 for enable): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      switch (inputBuffer[0])
      {
         case '0':
            check_status(naibrd_SD_SetModuleBITEnable(cardIndex, module, NAI_SD_TEST_ENABLE_D0, (bool_t)FALSE));
         break;
         case '1':
            check_status(naibrd_SD_SetModuleBITEnable(cardIndex, module, NAI_SD_TEST_ENABLE_D0, (bool_t)TRUE));
         break;
         default:
            printf("\nInvalid selection entered\n");
         break;
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SDTestMenu_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   int32_t channelCount = 0;
   bool_t pBitComplete = FALSE;
   uint32_t bitStatus = 0u;
   char strBitStatus[12] = "";
   p_naiapp_AppParameters_t p_sd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sd_params->cardIndex;
   int32_t module = p_sd_params->module;
   int32_t channel = p_sd_params->channel;
   channel = 0;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   channelCount = naibrd_SD_GetChannelCount(g_modId);

   /* Check to see if PBIT ran for the module. */
   printf("Checking if the Power-On BIT test has run...\n");
   check_status(naibrd_SD_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
   switch (pBitComplete)
   {
      case 0u:
         printf("\nPBIT Complete: NOT COMPLETED\n");
      break;
      case 1u:
         printf("\nPBIT Complete: COMPLETED\n");
      break;
      default:
         printf("\nPBIT Complete: UNKNOWN\n");
      break;
   }

   if (pBitComplete)
   {
      /* Read the BIT status */
      printf("Checking the result of the Power-on BIT test...\n");
      for (channel = 1; channel <= channelCount; channel++)
      {
         check_status(naibrd_SD_GetStatus(cardIndex, module, channel, NAI_SD_STATUS_BIT_LATCHED, &bitStatus));
         switch (bitStatus)
         {
            case 0:
               sprintf(strBitStatus, "BIT Passed");
            break;
            case 1:
               sprintf(strBitStatus, "BIT FAILED");
            break;
            default:
               sprintf(strBitStatus, "Unknown");
            break;
         }
         printf("Ch. %d: %s\n", channel, strBitStatus);
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

Help Bot

X