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

VR BasicOps

VR BasicOps Sample Application (SSK 2.x)

Overview

The VR BasicOps sample application demonstrates how to configure and read variable reluctance (VR) sensor channels using the NAI Software Support Kit (SSK 2.x). It covers channel setup (teeth count, monopole/dipole selection, threshold configuration, auto-threshold, range, polarity, AC coupling, termination, averaging, torque phase settings), continuous readings display with configurable update rates, system test operations (test enable, power supply enable, floating-point enable), and channel status monitoring with latched status clearing.

This sample supports the VR1 module type. The application is organized into four sub-menus: Channel Setup, Display Readings, System Test Setup, and Display Monitor/Status. It features threaded polling for both readings and status displays. Refer to the VR1 Manual for detailed module specifications.

For the SSK 1.x version, see VR BasicOps (SSK 1.x).

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a VR1 module installed.

  • SSK 2.x installed on your development host.

  • The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.

How to Run

Launch the vr_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_VR_BasicOps.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, a top-level menu lets you navigate to the four sub-menus.

Board Connection and Module Selection

Note
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to VR.

The main() function follows a standard SSK 2.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_VR_BasicOps.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear.

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Retrieve the module ID with naibrd_GetModuleName() so downstream code can adapt to the specific VR variant installed.

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t VR_BasicOps(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = NAI_FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   g_ReadingsUpdateRate = 1000;
   g_StatusUpdateRate = 1000;
   g_stopReadingsUpdateThread = NAI_TRUE;
   g_stopStatusUpdateThread = NAI_TRUE;
   g_initialReadingsThreadStarted = NAI_FALSE;
   g_initialStatusThreadStarted = NAI_FALSE;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  VRBasicMenu_Run(cardIndex, module, moduleID);
               }
            }
         }
         naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }
   naiif_printf("\r\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();
   return 0;
}

Note the SSK 2.x differences from SSK 1.x in this startup sequence:

  • The VxWorks preprocessor guard uses NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS (SSK 1.x uses __VXWORKS__).

  • The module identifier is retrieved with naibrd_GetModuleName() (SSK 1.x uses naibrd_GetModuleID()).

  • Boolean constants are NAI_TRUE / NAI_FALSE (SSK 1.x uses TRUE / FALSE).

  • Console output uses naiif_printf() from the platform abstraction layer (SSK 1.x uses printf() directly).

Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — indices are zero-based for cards and one-based for modules. Ensure the values you pass match your hardware setup.

  • Module not present at selected slot — the slot you selected does not contain the expected module. Use the board menu to verify which slots are populated.

Program Structure

Entry Point

On standard platforms (Petalinux, DEOS) the entry point is main(). On VxWorks the entry point is VR_BasicOps() — the SSK 2.x build system selects the correct variant via a preprocessor guard.

Command Loop

The VRBasicMenu_Run() function presents the top-level menu with four sub-menus. Each sub-menu loads its own command table and manages its own interaction loop.

Command Description

CS

Channel Setup Menu — configure per-channel VR parameters

R

Display Readings Menu — continuous polling display of VR measurements

T

System Test Setup Menu — enable test modes and power supply control

Mon

Display Monitor/Status Menu — view and manage channel statuses

Channel Setup

The Channel Setup sub-menu provides extensive per-channel configuration. Commands can be applied to a single channel or all channels simultaneously. The setup display shows the current configuration for all channels.

Key API calls:

  • naibrd_VR_SetNumberOfTeeth() — sets the tooth count for the VR sensor.

  • naibrd_VR_SetMonopoleDipole() — selects monopole or dipole sensing mode.

  • naibrd_VR_SetChannelEnable() — enables or disables a channel.

  • naibrd_VR_SetVoltageThresholdHigh() / naibrd_VR_SetVoltageThresholdLow() — set voltage detection thresholds.

  • naibrd_VR_SetAutoThresholdEnable() — enables automatic threshold adjustment.

  • naibrd_VR_SetRange() — sets the input voltage range.

  • naibrd_VR_SetPolaritySelect() — sets signal polarity.

  • naibrd_VR_SetACCoupleEnable() — enables AC coupling.

  • naibrd_VR_SetTerminationEnable() — enables input termination.

  • naibrd_VR_SetAveragingTime() — sets the measurement averaging time.

Configuration can be saved to and loaded from the module using VRChannelMenu_SaveSetup() and VRChannelMenu_LoadSetup().

Display Readings

The Display Readings sub-menu starts a background thread that periodically reads and displays VR measurements including frequency, RPM, amplitude, phase, and cycle count. The update rate is configurable (default 1000 ms).

Key API calls (used in the display thread):

  • naibrd_VR_GetFrequency() — reads the measured frequency.

  • naibrd_VR_GetRPM() — reads the computed RPM.

  • naibrd_VR_GetAmplitude() — reads the signal amplitude.

  • naibrd_VR_GetPhase() — reads the signal phase.

System Test and Status Monitoring

The System Test sub-menu provides test enable, power supply enable, and floating-point enable controls. The Status Monitor sub-menu displays channel status bits and supports clearing latched statuses.

Key API calls:

  • naibrd_VR_SetTestEnable() — enables or disables test mode.

  • naibrd_VR_SetChanStatusEnable() — enables channel status reporting.

  • naibrd_VR_ClearStatus() — clears a latched status bit.

Troubleshooting Reference

Error / Symptom Possible Causes Suggested Resolution

No board found

Board not powered or not connected

Verify power and physical connections; check configuration file

Connection timeout

Network/bus misconfiguration

Confirm IP address, subnet, or PCI/PCIe settings

Invalid card or module index

Wrong index values entered

Cards are zero-based, modules are one-based

Module not present at selected slot

Slot is empty or contains a different module type

Use the board menu to verify slot population

Frequency reads zero

No VR sensor signal connected or channel disabled

Check sensor wiring and ensure channel is enabled

Auto-threshold not tracking

Auto-threshold not enabled or signal too weak

Enable auto-threshold and verify minimum amplitude setting

Readings thread not updating

Thread stopped or update rate too high

Use the Continue Poll command; check update rate value

Status bits stuck high

Latched status not cleared

Use the Clear Status command to reset latched bits

RPM reads unexpected values

Incorrect teeth count configured

Verify the number of teeth matches your VR sensor target

Phase readings unstable

Signal below minimum amplitude threshold

Increase signal level or adjust minimum amplitude setting

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail.

Full Source — vr_basic_ops.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"

/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_vr.h"
#include "nai_libs/naibrd/src/maps/nai_map_vr.h"

/* naiif include files */
#include "nai_libs/naiif/include/naiif.h"
#include "nai_libs/naiif/include/naiif_stdio.h"

/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
#include <pthread.h>
#endif
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
#include "taskLib.h"
#endif

#define MSG_LENGTH               (10)

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

/* Function prototypes */
static bool_t VRBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modid);

static nai_status_t VRBasicMenu_ChannelSetupMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t VRBasicMenu_DisplayReadingsMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t VRBasicMenu_SystemTestSetupMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t VRBasicMenu_DisplayMonitorStatusMenu(int32_t paramCount, int32_t* p_params);

static nai_status_t VRChannelMenu_SetNumberOfTeeth(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetMonopoleDipoleSelect(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetChannelEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetVoltageThresholdHigh(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetVoltageThresholdLow(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetAutoThresholdEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetAutoThresholdPercent(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetAutoThresholdHysteresis(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetAutoDownRangeTime(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetRange(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetPolaritySelect(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetACCoupleEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetTerminationEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetAveragingTime(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetZeroTorqueSigPhase(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetZeroTorqueSigPhaseToPhaseReading(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetMaxTorqueSigPhase(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetDebounceTime(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetMinimumAmplitude(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SetMinimumFrequency(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_ResetCycleCount(int32_t paramCount, int32_t* p_params);
static void VRChannelMenu_DisplayChannelSetup(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_SaveSetup(int32_t paramCount, int32_t* p_params);
static nai_status_t VRChannelMenu_LoadSetup(int32_t paramCount, int32_t* p_params);

static void VRReadingsMenu_StartDisplayReadingsThread(int32_t* p_params);
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static void VRReadingsMenu_RunDisplayReadingsThread(int32_t * p_params);
#endif

static void VRReadingsMenu_DisplayChannelReadings(int32_t* p_params);

static nai_status_t VRReadingsMenu_ChangeUpdateRate(int32_t paramCount, int32_t* p_params);
static nai_status_t VRReadingsMenu_ContinuePoll(int32_t paramCount, int32_t* p_params);
static nai_status_t VRReadingsMenu_StopPolling(int32_t paramCount, int32_t* p_params);

static void VRTestMenu_DisplayTestSettings(int32_t paramCount, int32_t* p_params);
static nai_status_t VRTestMenu_SetTestEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t VRTestMenu_SetPowerSupplyEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t VRTestMenu_SetFloatingPointEnable(int32_t paramCount, int32_t* p_params);

static void VRStatusMenu_StartDisplayStatusThread(int32_t* p_params);
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static void VRStatusMenu_RunDisplayStatusThread(int32_t * p_params);
#endif

static void VRStatusMenu_DisplayStatuses(int32_t* p_params);

static nai_status_t VRStatusMenu_SetChanStatusEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t VRStatusMenu_ClearStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t VRStatusMenu_ChangeUpdateRate(int32_t paramCount, int32_t* p_params);
static nai_status_t VRStatusMenu_ContinuePoll(int32_t paramCount, int32_t* p_params);
static nai_status_t VRStatusMenu_StopPolling(int32_t paramCount, int32_t* p_params);

static long g_ReadingsUpdateRate;
static long g_StatusUpdateRate;
static bool_t g_stopReadingsUpdateThread;
static bool_t g_stopStatusUpdateThread;
static bool_t g_initialReadingsThreadStarted;
static bool_t g_initialStatusThreadStarted;

/****** Command Table *******/
enum vr_basicOps_commands
{
   VR_BASICMENU_CMD_CHANNEL_SETUP_MENU,
   VR_BASICMENU_CMD_DISPLAY_READINGS_MENU,
   VR_BASICMENU_CMD_SYSTEM_TEST_SETUP_MENU,
   VR_BASICMENU_CMD_DISPLAY_MONITOR_STATUS_MENU,
   VR_BASICMENU_CMD_COUNT
};

enum vr_channel_setup_commands
{
   VR_CHANNELMENU_CMD_SET_NUMBER_OF_TEETH,
   VR_CHANNELMENU_CMD_SET_MONOPOLE_DIPOLE_SELECT,
   VR_CHANNELMENU_CMD_SET_CHANNEL_ENABLE,
   VR_CHANNELMENU_CMD_SET_VOLTAGE_THRESHOLD_HIGH,
   VR_CHANNELMENU_CMD_SET_VOLTAGE_THRESHOLD_LOW,
   VR_CHANNELMENU_CMD_SET_AUTO_THRESHOLD_ENABLE,
   VR_CHANNELMENU_CMD_SET_AUTO_THRESHOLD_PERCENT,
   VR_CHANNELMENU_CMD_SET_AUTO_THRESHOLD_HYSTERESIS,
   VR_CHANNELMENU_CMD_SET_AUTO_DOWN_RANGE_TIME,
   VR_CHANNELMENU_CMD_SET_RANGE_SELECT,
   VR_CHANNELMENU_CMD_SET_POLARITY_SELECT,
   VR_CHANNELMENU_CMD_SET_AC_COUPLE_ENABLE,
   VR_CHANNELMENU_CMD_SET_TERMINATION_ENABLE,
   VR_CHANNELMENU_CMD_SET_AVERAGING_TIME,
   VR_CHANNELMENU_CMD_SET_ZERO_TORQUE_SIG_PHASE,
   VR_CHANNELMENU_CMD_SET_ZERO_TORQUE_SIG_PHASE_TO_PHASE_READING,
   VR_CHANNELMENU_CMD_SET_MAX_TORQUE_SIG_PHASE,
   VR_CHANNELMENU_CMD_SET_DEBOUNCE_TIME,
   VR_CHANNELMENU_CMD_SET_MINIMUM_AMPLITUDE,
   VR_CHANNELMENU_CMD_SET_MINIMUM_FREQUENCY,
   VR_CHANNELMENU_CMD_RESET_CYCLE_COUNT,
   VR_CHANNELMENU_CMD_MAIN_MENU,
   VR_CHANNELMENU_CMD_UPDATE,
   VR_CHANNELMENU_CMD_SAVE_SETUP,
   VR_CHANNELMENU_CMD_LOAD_SETUP,
   VR_CHANNELMENU_CMD_COUNT
};

enum vr_readings_commands
{
   VR_READINGSMENU_CMD_MAIN_MENU,
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   VR_READINGSMENU_CMD_CHANGE_UPDATE_RATE,
   VR_READINGSMENU_CMD_CONTINUE_POLL,
   VR_READINGSMENU_CMD_STOP_POLLING,
#endif
   VR_READINGSMENU_CMD_COUNT
};

enum vr_test_commands
{
   VR_TESTMENU_CMD_MAIN_MENU,
   VR_TESTMENU_CMD_SET_TEST_ENABLE,
   VR_TESTMENU_CMD_SET_POWER_SUPPLY_ENABLE,
   VR_TESTMENU_CMD_SET_FLOATING_POINT_ENABLE,
   VR_TESTMENU_CMD_COUNT
};

enum vr_status_commands
{
   VR_STATUSMENU_CMD_MAIN_MENU,
   VR_STATUSMENU_CMD_SET_CHAN_STATUS_ENABLE,
   VR_STATUSMENU_CMD_CLEAR_STATUS,
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   VR_STATUSMENU_CMD_CHANGE_UPDATE_RATE,
   VR_STATUSMENU_CMD_CONTINUE_POLL,
   VR_STATUSMENU_CMD_STOP_POLLING,
#endif
   VR_STATUSMENU_CMD_COUNT
};

naiapp_cmdtbl_params_t VR_BasicOpCmds[] = {
   {"CS",  "Channel Set-Up Menu",         VR_BASICMENU_CMD_CHANNEL_SETUP_MENU,          VRBasicMenu_ChannelSetupMenu},
   {"R",   "Display Readings Menu",       VR_BASICMENU_CMD_DISPLAY_READINGS_MENU,       VRBasicMenu_DisplayReadingsMenu},
   {"T",   "System Test Set-Up Menu",     VR_BASICMENU_CMD_SYSTEM_TEST_SETUP_MENU,      VRBasicMenu_SystemTestSetupMenu},
   {"Mon", "Display Monitor/Status Menu", VR_BASICMENU_CMD_DISPLAY_MONITOR_STATUS_MENU, VRBasicMenu_DisplayMonitorStatusMenu}
};

naiapp_cmdtbl_params_t VR_ChannelSetupMenuCmds[] = {
   {"1",  "Number of Teeth",            VR_CHANNELMENU_CMD_SET_NUMBER_OF_TEETH,                        VRChannelMenu_SetNumberOfTeeth},
   {"2",  "Monopole / Dipole",          VR_CHANNELMENU_CMD_SET_MONOPOLE_DIPOLE_SELECT,                 VRChannelMenu_SetMonopoleDipoleSelect},
   {"3",  "Channel Enable",             VR_CHANNELMENU_CMD_SET_CHANNEL_ENABLE,                         VRChannelMenu_SetChannelEnable},
   {"4",  "Voltage Threshold Hi ( V )", VR_CHANNELMENU_CMD_SET_VOLTAGE_THRESHOLD_HIGH,                 VRChannelMenu_SetVoltageThresholdHigh},
   {"5",  "Voltage Threshold Lo ( V )", VR_CHANNELMENU_CMD_SET_VOLTAGE_THRESHOLD_LOW,                  VRChannelMenu_SetVoltageThresholdLow},
   {"6",  "Auto Threshold Enable",      VR_CHANNELMENU_CMD_SET_AUTO_THRESHOLD_ENABLE,                  VRChannelMenu_SetAutoThresholdEnable},
   {"7",  "Auto Threshold Percent",     VR_CHANNELMENU_CMD_SET_AUTO_THRESHOLD_PERCENT,                 VRChannelMenu_SetAutoThresholdPercent},
   {"8",  "Auto Threshold Hysteresis",  VR_CHANNELMENU_CMD_SET_AUTO_THRESHOLD_HYSTERESIS,              VRChannelMenu_SetAutoThresholdHysteresis},
   {"9",  "Auto Down-Range Time",       VR_CHANNELMENU_CMD_SET_AUTO_DOWN_RANGE_TIME,                   VRChannelMenu_SetAutoDownRangeTime},
   {"10", "Range Select",               VR_CHANNELMENU_CMD_SET_RANGE_SELECT,                           VRChannelMenu_SetRange},
   {"11", "Polarity Select",            VR_CHANNELMENU_CMD_SET_POLARITY_SELECT,                        VRChannelMenu_SetPolaritySelect},
   {"12", "AC Couple Enable",           VR_CHANNELMENU_CMD_SET_AC_COUPLE_ENABLE,                       VRChannelMenu_SetACCoupleEnable},
   {"13", "Termination Enable",         VR_CHANNELMENU_CMD_SET_TERMINATION_ENABLE,                     VRChannelMenu_SetTerminationEnable},
   {"14", "Averaging Time ( Sec )",     VR_CHANNELMENU_CMD_SET_AVERAGING_TIME,                         VRChannelMenu_SetAveragingTime},
   {"15", "Zero Torque Sig Phase",      VR_CHANNELMENU_CMD_SET_ZERO_TORQUE_SIG_PHASE,                  VRChannelMenu_SetZeroTorqueSigPhase},
   {"16", "Set Zero Torque Sig Phase",  VR_CHANNELMENU_CMD_SET_ZERO_TORQUE_SIG_PHASE_TO_PHASE_READING, VRChannelMenu_SetZeroTorqueSigPhaseToPhaseReading},
   {"17", "Max Torque Sig Phase",       VR_CHANNELMENU_CMD_SET_MAX_TORQUE_SIG_PHASE,                   VRChannelMenu_SetMaxTorqueSigPhase},
   {"18", "Debounce Time ( Sec )",      VR_CHANNELMENU_CMD_SET_DEBOUNCE_TIME,                          VRChannelMenu_SetDebounceTime},
   {"19", "Minimum Amplitude ( V )",    VR_CHANNELMENU_CMD_SET_MINIMUM_AMPLITUDE,                      VRChannelMenu_SetMinimumAmplitude},
   {"20", "Minimum Frequency ( Hz )",   VR_CHANNELMENU_CMD_SET_MINIMUM_FREQUENCY,                      VRChannelMenu_SetMinimumFrequency},
   {"R",  "Reset Cycle Count",          VR_CHANNELMENU_CMD_RESET_CYCLE_COUNT,                          VRChannelMenu_ResetCycleCount},
   {"MM", "Return to Main Menu",        VR_CHANNELMENU_CMD_MAIN_MENU,                                  NULL},
   {"UD", "Update",                     VR_CHANNELMENU_CMD_UPDATE,                                     NULL},
   {"S",  "Save Setup",                 VR_CHANNELMENU_CMD_SAVE_SETUP,                                 VRChannelMenu_SaveSetup},
   {"L",  "Load Setup",                 VR_CHANNELMENU_CMD_LOAD_SETUP,                                 VRChannelMenu_LoadSetup}
};

naiapp_cmdtbl_params_t VR_ChannelReadingsMenuCmds[] = {
   {"MM", "Return to Main Menu",                                 VR_READINGSMENU_CMD_MAIN_MENU,          NULL},
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   {"R",  "Change Update Rate in milliSeconds [default:1000mS]", VR_READINGSMENU_CMD_CHANGE_UPDATE_RATE, VRReadingsMenu_ChangeUpdateRate},
   {"C",  "Continue Poll",                                       VR_READINGSMENU_CMD_CONTINUE_POLL,      VRReadingsMenu_ContinuePoll},
   {"S",  "Stop Polling",                                        VR_READINGSMENU_CMD_STOP_POLLING,       VRReadingsMenu_StopPolling}
#endif
};

naiapp_cmdtbl_params_t VR_TestMenuCmds[] = {
   {"MM", "Return to Main Menu",   VR_TESTMENU_CMD_MAIN_MENU,                 NULL},
   {"TE", "Test Enable",           VR_TESTMENU_CMD_SET_TEST_ENABLE,           VRTestMenu_SetTestEnable},
   {"PS", "Power Supply Enable",   VR_TESTMENU_CMD_SET_POWER_SUPPLY_ENABLE,   VRTestMenu_SetPowerSupplyEnable},
   {"FE", "Floating-Point Enable", VR_TESTMENU_CMD_SET_FLOATING_POINT_ENABLE, VRTestMenu_SetFloatingPointEnable}
};

naiapp_cmdtbl_params_t VR_StatusMenuCmds[] = {
   {"MM", "Return to Main Menu",                                VR_STATUSMENU_CMD_MAIN_MENU,              NULL},
   {"E",  "Channel Status Enable",                              VR_STATUSMENU_CMD_SET_CHAN_STATUS_ENABLE, VRStatusMenu_SetChanStatusEnable},
   {"C",  "Clear Status",                                       VR_STATUSMENU_CMD_CLEAR_STATUS,           VRStatusMenu_ClearStatus},
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   {"R",  "Change Update Rate in milliSeconds [default:1000mS]", VR_STATUSMENU_CMD_CHANGE_UPDATE_RATE,     VRStatusMenu_ChangeUpdateRate},
   {"P",  "Continue Poll",                                      VR_STATUSMENU_CMD_CONTINUE_POLL,          VRStatusMenu_ContinuePoll},
   {"S",  "Stop Polling",                                       VR_STATUSMENU_CMD_STOP_POLLING,           VRStatusMenu_StopPolling}
#endif
};

/*****************************************************************************/
/**
<summary>
The purpose of the vr_basic_ops is to illustrate the methods to call in the
naibrd library to perform basic operations with the VR modules for
configuration setup and reading the channels.
</summary>
*/
/*****************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t VR_BasicOps(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = NAI_FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   g_ReadingsUpdateRate = 1000;
   g_StatusUpdateRate = 1000;
   g_stopReadingsUpdateThread = NAI_TRUE;
   g_stopStatusUpdateThread = NAI_TRUE;
   g_initialReadingsThreadStarted = NAI_FALSE;
   g_initialStatusThreadStarted = NAI_FALSE;

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

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  VRBasicMenu_Run(cardIndex, module, moduleID);
               }
            }
         }

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

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

   return 0;
}
/*****************************************************************************/
/**
<summary>
VRBasicMenu_Run prepares the menu which will handle user command requests.
Returns NAI_TRUE if the user enters the Quit Command at any point
within its scope.
</summary>
*/
/*****************************************************************************/
static bool_t VRBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   int32_t MAX_CHANNELS = 0;

   naiapp_AppParameters_t  VR_basicOps_params;
   p_naiapp_AppParameters_t p_VR_basicOps_params = &VR_basicOps_params;
   p_VR_basicOps_params->cardIndex = cardIndex;
   p_VR_basicOps_params->module = module;
   p_VR_basicOps_params->modId = modid;
   MAX_CHANNELS = naibrd_VR_GetChannelCount(modid);
   p_VR_basicOps_params->maxChannels = MAX_CHANNELS;

   do
   {
      g_initialReadingsThreadStarted = NAI_FALSE;
      g_initialStatusThreadStarted = NAI_FALSE;
      g_stopReadingsUpdateThread = NAI_TRUE;
      g_stopStatusUpdateThread = NAI_TRUE;
      naiapp_utils_LoadParamMenuCommands(VR_BASICMENU_CMD_COUNT, VR_BasicOpCmds);
      naiapp_display_ParamMenuCommands((int8_t*)"VR Basic Operations");
      naiif_printf("\r\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))
      {
         bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
         if (bCmdFound)
         {
            VR_BasicOpCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_VR_basicOps_params);
         }
         else
         {
            naiif_printf(" Invalid command entered\r\n");
         }
      }
   } while (!bQuit);
   return bQuit;
}

static nai_status_t VRBasicMenu_ChannelSetupMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bCancelCmd = NAI_FALSE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt = 0;
   p_naiapp_AppParameters_t p_VR_basicOps_params = (p_naiapp_AppParameters_t)p_params;
   int32_t MAX_CHANNELS = p_VR_basicOps_params->maxChannels;

   do
   {
      naiapp_utils_LoadParamMenuCommands(VR_CHANNELMENU_CMD_COUNT, VR_ChannelSetupMenuCmds);
      VRChannelMenu_DisplayChannelSetup(paramCount, p_params);
      naiif_printf("\r\n>Please Enter Channel Setup Menu command or %c to quit (commands are listed to the left of each option, ", NAI_QUIT_CHAR);
      naiif_printf("and numbers are included as commands): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
         if (bCmdFound)
         {
            if ((cmd != VR_CHANNELMENU_CMD_MAIN_MENU) && (cmd != VR_CHANNELMENU_CMD_UPDATE) && (cmd != VR_CHANNELMENU_CMD_SAVE_SETUP) &&
                (cmd != VR_CHANNELMENU_CMD_LOAD_SETUP))
            {
               naiif_printf("\r\nType 'a' or 'A' to apply command to all channels, or type 's' or 'S' to select a channel: ");
               bCancelCmd = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               if ((!bCancelCmd) && (inputResponseCnt > 0))
               {
                  if ((toupper(inputBuffer[0]) == 'A') || (toupper(inputBuffer[0]) == 'S'))
                  {
                     if (toupper(inputBuffer[0]) == 'A')
                     {
                        p_VR_basicOps_params->channel = 0;
                     }
                     else
                     {
                        naiapp_query_ChannelNumber(MAX_CHANNELS, 1, &(p_VR_basicOps_params->channel));
                     }
                  }
                  else
                  {
                     bCancelCmd = NAI_TRUE;
                     naiif_printf("\r\nInvalid option entered\r\n");
                  }
               }
               else
               {
                  bCancelCmd = NAI_TRUE;
               }
            }
            if (cmd == VR_CHANNELMENU_CMD_MAIN_MENU)
            {
               bQuit = NAI_TRUE;
            }
            else if (cmd != VR_CHANNELMENU_CMD_UPDATE)
            {
               if (!bCancelCmd)
               {
                  VR_ChannelSetupMenuCmds[cmd].func(paramCount, (int32_t*)p_VR_basicOps_params);
               }
               else
               {
                  bCancelCmd = NAI_FALSE;
               }
            }
         }
         else
         {
            naiif_printf("Invalid command entered\r\n");
         }
      }
   } while (!bQuit);

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRBasicMenu_DisplayReadingsMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt = 0;

   do
   {
      naiapp_utils_LoadParamMenuCommands(VR_READINGSMENU_CMD_COUNT, VR_ChannelReadingsMenuCmds);
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
      if (g_initialReadingsThreadStarted == NAI_FALSE)
      {
         VRReadingsMenu_StartDisplayReadingsThread(p_params);
         g_initialReadingsThreadStarted = NAI_TRUE;
      }
#else
      VRReadingsMenu_DisplayChannelReadings(p_params);
#endif
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
         if (bCmdFound)
         {
            if (cmd == VR_READINGSMENU_CMD_MAIN_MENU)
            {
               g_stopReadingsUpdateThread = NAI_TRUE;
               bQuit = NAI_TRUE;
            }
            else
            {
               VR_ChannelReadingsMenuCmds[cmd].func(paramCount, p_params);
            }
         }
         else
         {
            naiif_printf("Invalid command entered\r\n");
         }
      }
   } while (!bQuit);

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRBasicMenu_SystemTestSetupMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt = 0;

   do
   {
      naiapp_utils_LoadParamMenuCommands(VR_TESTMENU_CMD_COUNT, VR_TestMenuCmds);
      VRTestMenu_DisplayTestSettings(paramCount, p_params);
      naiif_printf("\r\n>Please Enter Test Menu command or %c to quit : ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
         if (bCmdFound)
         {
            if (cmd == VR_TESTMENU_CMD_MAIN_MENU)
            {
               bQuit = NAI_TRUE;
            }
            else
            {
               VR_TestMenuCmds[cmd].func(paramCount, p_params);
            }
         }
         else
         {
            naiif_printf("Invalid command entered\r\n");
         }
      }
   } while (!bQuit);

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRBasicMenu_DisplayMonitorStatusMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bCancelCmd = NAI_FALSE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt = 0;
   p_naiapp_AppParameters_t p_VR_basicOps_params = (p_naiapp_AppParameters_t)p_params;
   int32_t MAX_CHANNELS = p_VR_basicOps_params->maxChannels;

   do
   {
      naiapp_utils_LoadParamMenuCommands(VR_STATUSMENU_CMD_COUNT, VR_StatusMenuCmds);
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
      if (g_initialStatusThreadStarted == NAI_FALSE)
      {
         VRStatusMenu_StartDisplayStatusThread(p_params);
         g_initialStatusThreadStarted = NAI_TRUE;
      }
#else
      VRStatusMenu_DisplayStatuses(p_params);
#endif
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0))
      {
         bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
         if (bCmdFound)
         {
            if ((cmd == VR_STATUSMENU_CMD_SET_CHAN_STATUS_ENABLE) || (cmd == VR_STATUSMENU_CMD_CLEAR_STATUS))
            {
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
               VRStatusMenu_StopPolling(paramCount, p_params);
#endif
               naiif_printf("\r\nType 'a' or 'A' to apply command to all channels, or type 's' or 'S' to select a channel: ");
               bCancelCmd = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               if ((!bCancelCmd) && (inputResponseCnt > 0))
               {
                  if ((toupper(inputBuffer[0]) == 'A') || (toupper(inputBuffer[0]) == 'S'))
                  {
                     if (toupper(inputBuffer[0]) == 'A')
                     {
                        p_VR_basicOps_params->channel = 0;
                     }
                     else
                     {
                        naiapp_query_ChannelNumber(MAX_CHANNELS, 1, &(p_VR_basicOps_params->channel));
                     }
                  }
                  else
                  {
                     bCancelCmd = NAI_TRUE;
                     naiif_printf("\r\nInvalid option entered\r\n");
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
                     VRStatusMenu_ContinuePoll(paramCount, p_params);
#endif
                  }
               }
               else
               {
                  bCancelCmd = NAI_TRUE;
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
                  VRStatusMenu_ContinuePoll(paramCount, p_params);
#endif
               }
            }
            if (cmd == VR_STATUSMENU_CMD_MAIN_MENU)
            {
               g_stopStatusUpdateThread = NAI_TRUE;
               bQuit = NAI_TRUE;
            }
            else
            {
               if (!bCancelCmd)
               {
                  VR_StatusMenuCmds[cmd].func(paramCount, (int32_t*)p_VR_basicOps_params);
               }
               else
               {
                  bCancelCmd = NAI_FALSE;
               }
            }
         }
         else
         {
            naiif_printf("Invalid command entered\r\n");
         }
      }
   } while (!bQuit);

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}


static nai_status_t VRChannelMenu_SetNumberOfTeeth(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t numberOfTeeth = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Number Of Teeth value to set: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      numberOfTeeth = atof((const char*)inputBuffer);
      if (numberOfTeeth == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Number Of Teeth value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetMonopoleDipoleSelect(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enableDipole = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Enter Monopole/Dipole setting to set (0 for monopole, 1 for dipole): ");
   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')
         {
            enableDipole = NAI_TRUE;
         }
         else
         {
            enableDipole = NAI_FALSE;
         }
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
                                                           NAIBRD_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE, enableDipole));
            }
         }
         else
         {
            check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE,
                                                        enableDipole));
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetChannelEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   if (channel == 0)
   {
      naiif_printf("Do you want to enable or disable all channels? (1 to enable, 0 to disable): ");
   }
   else
   {
      naiif_printf("Do you want to enable or disable channel %d? (1 to enable, 0 to disable): ", channel);
   }
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
                                                           NAIBRD_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE, enable));
            }
         }
         else
         {
            check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE, enable));
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetVoltageThresholdHigh(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t voltThresHigh = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Voltage High Threshold Value to set (in V): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      voltThresHigh = atof((const char*)inputBuffer);
      if (voltThresHigh == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel,
                                                        NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Voltage High Threshold value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetVoltageThresholdLow(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t voltThresLow = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Voltage Low Threshold Value to set (in V): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      voltThresLow = atof((const char*)inputBuffer);
      if (voltThresLow == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Voltage Low Threshold value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetAutoThresholdEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Do you want to enable or disable automatic threshold levels? (1 to enable, 0 to disable): ");
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
                                                           enable));
            }
         }
         else
         {
            check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
                                                        enable));
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetAutoThresholdPercent(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t autoThresholdPercent = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Automatic Threshold Percent Value to set: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      autoThresholdPercent = atof((const char*)inputBuffer);
      if (autoThresholdPercent == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
                                                        autoThresholdPercent));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
                                                     autoThresholdPercent));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Automatic Threshold Percent value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
                                                     autoThresholdPercent));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
                                                  autoThresholdPercent));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetAutoThresholdHysteresis(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t autoThresholdHysteresis = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Automatic Threshold Hysteresis Value to set (%%): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      autoThresholdHysteresis = atof((const char*)inputBuffer);
      if (autoThresholdHysteresis == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS,
                                                        autoThresholdHysteresis));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS,
                                                     autoThresholdHysteresis));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Automatic Threshold Hysteresis value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS,
                                                     autoThresholdHysteresis));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS,
                                                  autoThresholdHysteresis));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetAutoDownRangeTime(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Enter Auto Down-Range Time selection to set (0 for 100ms, 1 for 500ms, 2 for 1s, 3 for 2s, 4 for 5s, 5 for 10s): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      if (channel == 0)
      {
         for (channel = 1; channel <= MAX_CHANNELS; channel++)
         {
            switch (inputBuffer[0])
            {
               case '0':
                  check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_100MS));
               break;
               case '1':
                  check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_500MS));
               break;
               case '2':
                  check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_1S));
               break;
               case '3':
                  check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_2S));
               break;
               case '4':
                  check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_5S));
               break;
               case '5':
                  check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_10S));
               break;
               default:
                  naiif_printf("\r\nInvalid Selection Entered\r\n");
               break;
            }
         }
      }
      else
      {
         switch (inputBuffer[0])
         {
            case '0':
               check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_100MS));
            break;
            case '1':
               check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_500MS));
            break;
            case '2':
               check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_1S));
            break;
            case '3':
               check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_2S));
            break;
            case '4':
               check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_5S));
            break;
            case '5':
               check_status(naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAIBRD_VR_AUTO_DOWN_RANGE_TIME_10S));
            break;
            default:
               naiif_printf("\r\nInvalid Selection Entered\r\n");
            break;
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetRange(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Enter Range selection to set (0 for Auto, 1 for 50mV, 2 for 100mV, 3 for 250mV, 4 for 500mV, ");
   naiif_printf("5 for 1V, 6 for 2.5V, 7 for 5V, 8 for 12.5V, 9 for 25V, A for 50V, B for 100V): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      if (channel == 0)
      {
         for (channel = 1; channel <= MAX_CHANNELS; channel++)
         {
            switch (inputBuffer[0])
            {
               case '0':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_AUTO));
               break;
               case '1':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_50mV));
               break;
               case '2':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_100mV));
               break;
               case '3':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_250mV));
               break;
               case '4':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_500mV));
               break;
               case '5':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_1V));
               break;
               case '6':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_2P5V));
               break;
               case '7':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_5V));
               break;
               case '8':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_12P5V));
               break;
               case '9':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_25V));
               break;
               case 'A':
               case 'a':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_50V));
               break;
               case 'B':
               case 'b':
                  check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_100V));
               break;
               default:
                  naiif_printf("\r\nInvalid Selection Entered\r\n");
               break;
            }
         }
      }
      else
      {
         switch (inputBuffer[0])
         {
            case '0':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_AUTO));
            break;
            case '1':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_50mV));
            break;
            case '2':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_100mV));
            break;
            case '3':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_250mV));
            break;
            case '4':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_500mV));
            break;
            case '5':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_1V));
            break;
            case '6':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_2P5V));
            break;
            case '7':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_5V));
            break;
            case '8':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_12P5V));
            break;
            case '9':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_25V));
            break;
            case 'A':
            case 'a':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_50V));
            break;
            case 'B':
            case 'b':
               check_status(naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAIBRD_VR_RANGE_100V));
            break;
            default:
               naiif_printf("\r\nInvalid Selection Entered\r\n");
            break;
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetPolaritySelect(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enableFallingEdgeMeas = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Enter signal edge on which to take measurements (0 for rising edge, 1 for falling edge): ");
   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')
         {
            enableFallingEdgeMeas = NAI_TRUE;
         }
         else
         {
            enableFallingEdgeMeas = NAI_FALSE;
         }
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
                                                           NAIBRD_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE,
                                                           enableFallingEdgeMeas));
            }
         }
         else
         {
            check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
                                                        NAIBRD_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE,
                                                        enableFallingEdgeMeas));
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetACCoupleEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Do you want to enable or disable AC couple? (1 to enable, 0 to disable): ");
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE,
                                                           enable));
            }
         }
         else
         {
            check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE,
                                                        enable));
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetTerminationEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Do you want to enable or disable termination? (1 to enable, 0 to disable): ");
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE,
                                                           enable));
            }
         }
         else
         {
            check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE,
                                                        enable));
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetAveragingTime(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t averagingTime = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Averaging Time Value to set (in seconds): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      averagingTime = atof((const char*)inputBuffer);
      if (averagingTime == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AVERAGING_TIME, averagingTime));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AVERAGING_TIME, averagingTime));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Averaging Time value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AVERAGING_TIME, averagingTime));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_AVERAGING_TIME, averagingTime));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetZeroTorqueSigPhase(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t zeroTorqueSigPhase = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Zero Torque Signal Phase Value to set (in degrees): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      zeroTorqueSigPhase = atof((const char*)inputBuffer);
      if (zeroTorqueSigPhase == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE,
                                                        zeroTorqueSigPhase));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE,
                                                     zeroTorqueSigPhase));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Zero Torque Signal Phase value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE,
                                                     zeroTorqueSigPhase));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE,
                                                  zeroTorqueSigPhase));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetZeroTorqueSigPhaseToPhaseReading(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Are you sure you want to set the zero torque signal phase to the current phase reading? (Y for Yes, N for No): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      if ((toupper(inputBuffer[0]) == 'Y') || (toupper(inputBuffer[0]) == 'N'))
      {
         if (toupper(inputBuffer[0]) == 'Y')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetZeroTorqueSignalPhaseToPhaseReading(cardIndex, module, channel));
               }
            }
            else
            {
               check_status(naibrd_VR_SetZeroTorqueSignalPhaseToPhaseReading(cardIndex, module, channel));
            }
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetMaxTorqueSigPhase(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t maxTorqueSigPhase = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Max Torque Signal Phase Value to set (in degrees): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      maxTorqueSigPhase = atof((const char*)inputBuffer);
      if (maxTorqueSigPhase == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE,
                                                        maxTorqueSigPhase));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE,
                                                     maxTorqueSigPhase));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Max Torque Signal Phase value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE,
                                                     maxTorqueSigPhase));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE, maxTorqueSigPhase));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetDebounceTime(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t debounceTime = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Debounce Time Value to set (in seconds): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      debounceTime = atof((const char*)inputBuffer);
      if (debounceTime == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_DEBOUNCE_TIME, debounceTime));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_DEBOUNCE_TIME, debounceTime));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Debounce Time value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_DEBOUNCE_TIME, debounceTime));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_DEBOUNCE_TIME, debounceTime));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetMinimumAmplitude(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t minAmplitude = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Minimum Amplitude Value to set (in V): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      minAmplitude = atof((const char*)inputBuffer);
      if (minAmplitude == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_AMPLITUDE, minAmplitude));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_AMPLITUDE, minAmplitude));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Minimum Amplitude value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_AMPLITUDE, minAmplitude));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_AMPLITUDE, minAmplitude));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_SetMinimumFrequency(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t minFreq = 0.0;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Type Minimum Frequency Value to set (in Hz): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      minFreq = atof((const char*)inputBuffer);
      if (minFreq == 0.0)
      {
         if (inputBuffer[0] == '0')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_FREQUENCY, minFreq));
               }
            }
            else
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_FREQUENCY, minFreq));
            }
         }
         else
         {
            naiif_printf("\r\nInvalid Minimum Frequency value entered\r\n");
         }
      }
      else
      {
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_FREQUENCY, minFreq));
            }
         }
         else
         {
            check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAIBRD_VR_CONFIG_MINIMUM_FREQUENCY, minFreq));
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_ResetCycleCount(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Are you sure you want to reset the cycle count? (Y for Yes, N for No): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      if ((toupper(inputBuffer[0]) == 'Y') || (toupper(inputBuffer[0]) == 'N'))
      {
         if (toupper(inputBuffer[0]) == 'Y')
         {
            if (channel == 0)
            {
               for (channel = 1; channel <= MAX_CHANNELS; channel++)
               {
                  check_status(naibrd_VR_ResetCycleCount(cardIndex, module, channel));
               }
            }
            else
            {
               check_status(naibrd_VR_ResetCycleCount(cardIndex, module, channel));
            }
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static void VRChannelMenu_DisplayChannelSetup(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_VR_basicOps_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIdx = p_VR_basicOps_params->cardIndex;
   int32_t modNum = p_VR_basicOps_params->module;
   int32_t chanNum = 1;
   int32_t MAX_CHANNELS = p_VR_basicOps_params->maxChannels;
   float64_t numberOfTeeth = 0.0;
   bool_t monopoleDipole = NAI_FALSE;
   bool_t channelEnable = NAI_FALSE;
   float64_t voltThresHi = 0.0;
   float64_t voltThresLo = 0.0;
   bool_t autoThresholdEnable = NAI_FALSE;
   float64_t autoThresholdPercent = 0.0;
   float64_t autoThresholdHysteresis = 0.0;
   naibrd_vr_auto_down_range_time_type_t autoDownRangeTime = NAIBRD_VR_AUTO_DOWN_RANGE_TIME_100MS;
   naibrd_vr_range_select_type_t rangeSelect = NAIBRD_VR_RANGE_AUTO;
   bool_t polaritySelect = NAI_FALSE;
   bool_t acCoupleEnable = NAI_FALSE;
   bool_t terminationEnable = NAI_FALSE;
   float64_t averagingTime = 0.0;
   float64_t zeroTorqueSigPhase = 0.0;
   bool_t setZeroTorqueSigPhase = NAI_FALSE;
   float64_t maxTorqueSigPhase = 0.0;
   float64_t debounceTime = 0.0;
   float64_t minAmplitude = 0.0;
   float64_t minFreq = 0.0;
   char strMonopoleDipole[MSG_LENGTH] = "";
   char strChannelEnable[MSG_LENGTH] = "";
   char strRangeSelect[MSG_LENGTH] = "";
   char strPolaritySelect[MSG_LENGTH] = "";
   char strACCoupleEnable[MSG_LENGTH] = "";
   char strTerminationEnable[MSG_LENGTH] = "";
   char strSetZeroTorqueSigPhase[MSG_LENGTH] = "";
   char strAutoThresholdEnable[MSG_LENGTH] = "";
   char strAutoDownRangeTime[MSG_LENGTH] = "";

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

   naiif_printf("\r\n    Channel Setup Group Menu           Ch 1          Ch 2          Ch 3          Ch 4          Ch 5          Ch 6          ");
   naiif_printf("Ch 7          Ch 8\r\n\r\n");
   naiif_printf(" 1    Number of Teeth      ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_NUMBER_OF_TEETH, &numberOfTeeth));
      naiif_printf("%14d", (int32_t)(numberOfTeeth + 0.5));
   }
   naiif_printf("\r\n 2    Monopole / Dipole    ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE,
                                                  &monopoleDipole));
      switch (monopoleDipole)
      {
         case NAI_TRUE:
            naiif_snprintf(strMonopoleDipole, MSG_LENGTH + 1, "D");
         break;
         case NAI_FALSE:
            naiif_snprintf(strMonopoleDipole, MSG_LENGTH + 1, "M");
         break;
         default:
            naiif_snprintf(strMonopoleDipole, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strMonopoleDipole);
   }
   naiif_printf("\r\n 3    Channel Enable       ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE, &channelEnable));
      switch (channelEnable)
      {
         case NAI_TRUE:
            naiif_snprintf(strChannelEnable, MSG_LENGTH + 1, "On");
         break;
         case NAI_FALSE:
            naiif_snprintf(strChannelEnable, MSG_LENGTH + 1, "Off");
         break;
         default:
            naiif_snprintf(strChannelEnable, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strChannelEnable);
   }
   naiif_printf("\r\n 4    Voltage Threshold Hi ( V )");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, &voltThresHi));
      if (chanNum == 1)
      {
         naiif_printf("%9.3f", voltThresHi);
      }
      else
      {
         naiif_printf("%14.3f", voltThresHi);
      }
   }
   naiif_printf("\r\n 5    Voltage Threshold Lo ( V )");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, &voltThresLo));
      if (chanNum == 1)
      {
         naiif_printf("%9.3f", voltThresLo);
      }
      else
      {
         naiif_printf("%14.3f", voltThresLo);
      }
   }
   naiif_printf("\r\n 6    Auto Threshold Enable");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
                                                  &autoThresholdEnable));
      switch (autoThresholdEnable)
      {
         case NAI_TRUE:
            naiif_snprintf(strAutoThresholdEnable, MSG_LENGTH + 1, "On");
         break;
         case NAI_FALSE:
            naiif_snprintf(strAutoThresholdEnable, MSG_LENGTH + 1, "Off");
         break;
         default:
            naiif_snprintf(strAutoThresholdEnable, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strAutoThresholdEnable);
   }
   naiif_printf("\r\n 7    Auto Threshold Percent");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_PERCENT, &autoThresholdPercent));
      if (chanNum == 1)
      {
         naiif_printf("%13.3f", autoThresholdPercent);
      }
      else
      {
         naiif_printf("%14.3f", autoThresholdPercent);
      }
   }
   naiif_printf("\r\n 8    Auto Threshold Hysteresis (%%)");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS,
                                            &autoThresholdHysteresis));
      if (chanNum == 1)
      {
         naiif_printf("%6.3f", autoThresholdHysteresis);
      }
      else
      {
         naiif_printf("%14.3f", autoThresholdHysteresis);
      }
   }
   naiif_printf("\r\n 9    Auto Down-Range Time ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetAutoDownRangeTime(cardIdx, modNum, chanNum, &autoDownRangeTime));
      switch (autoDownRangeTime)
      {
         case NAIBRD_VR_AUTO_DOWN_RANGE_TIME_100MS:
            naiif_snprintf(strAutoDownRangeTime, MSG_LENGTH + 1, "100ms");
         break;
         case NAIBRD_VR_AUTO_DOWN_RANGE_TIME_500MS:
            naiif_snprintf(strAutoDownRangeTime, MSG_LENGTH + 1, "500ms");
         break;
         case NAIBRD_VR_AUTO_DOWN_RANGE_TIME_1S:
            naiif_snprintf(strAutoDownRangeTime, MSG_LENGTH + 1, "1s");
         break;
         case NAIBRD_VR_AUTO_DOWN_RANGE_TIME_2S:
            naiif_snprintf(strAutoDownRangeTime, MSG_LENGTH + 1, "2s");
         break;
         case NAIBRD_VR_AUTO_DOWN_RANGE_TIME_5S:
            naiif_snprintf(strAutoDownRangeTime, MSG_LENGTH + 1, "5s");
         break;
         case NAIBRD_VR_AUTO_DOWN_RANGE_TIME_10S:
            naiif_snprintf(strAutoDownRangeTime, MSG_LENGTH + 1, "10s");
         break;
         case NAIBRD_VR_AUTO_DOWN_RANGE_TIME_UNKNOWN:
         default:
            naiif_snprintf(strAutoDownRangeTime, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strAutoDownRangeTime);
   }
   naiif_printf("\r\n 10   Range Select         ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetRangeSelect(cardIdx, modNum, chanNum, &rangeSelect));
      switch (rangeSelect)
      {
         case NAIBRD_VR_RANGE_AUTO:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "Auto");
         break;
         case NAIBRD_VR_RANGE_50mV:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "50mV");
         break;
         case NAIBRD_VR_RANGE_100mV:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "100mV");
         break;
         case NAIBRD_VR_RANGE_250mV:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "250mV");
         break;
         case NAIBRD_VR_RANGE_500mV:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "500mV");
         break;
         case NAIBRD_VR_RANGE_1V:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "1V");
         break;
         case NAIBRD_VR_RANGE_2P5V:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "2.5V");
         break;
         case NAIBRD_VR_RANGE_5V:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "5V");
         break;
         case NAIBRD_VR_RANGE_12P5V:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "12.5V");
         break;
         case NAIBRD_VR_RANGE_25V:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "25V");
         break;
         case NAIBRD_VR_RANGE_50V:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "50V");
         break;
         case NAIBRD_VR_RANGE_100V:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "100V");
         break;
         default:
            naiif_snprintf(strRangeSelect, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strRangeSelect);
   }
   naiif_printf("\r\n 11   Polarity Select      ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE,
                                                  &polaritySelect));
      switch (polaritySelect)
      {
         case NAI_TRUE:
            naiif_snprintf(strPolaritySelect, MSG_LENGTH + 1, "Falling");
         break;
         case NAI_FALSE:
            naiif_snprintf(strPolaritySelect, MSG_LENGTH + 1, "Rising");
         break;
         default:
            naiif_snprintf(strPolaritySelect, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strPolaritySelect);
   }
   naiif_printf("\r\n 12   AC Couple Enable     ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE,
                                                  &acCoupleEnable));
      switch (acCoupleEnable)
      {
         case NAI_TRUE:
            naiif_snprintf(strACCoupleEnable, MSG_LENGTH + 1, "On");
         break;
         case NAI_FALSE:
            naiif_snprintf(strACCoupleEnable, MSG_LENGTH + 1, "Off");
         break;
         default:
            naiif_snprintf(strACCoupleEnable, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strACCoupleEnable);
   }
   naiif_printf("\r\n 13   Termination Enable   ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE,
                                                  &terminationEnable));
      switch (terminationEnable)
      {
         case NAI_TRUE:
            naiif_snprintf(strTerminationEnable, MSG_LENGTH + 1, "On");
         break;
         case NAI_FALSE:
            naiif_snprintf(strTerminationEnable, MSG_LENGTH + 1, "Off");
         break;
         default:
            naiif_snprintf(strTerminationEnable, MSG_LENGTH + 1, "Unknown");
         break;
      }
      naiif_printf("%14s", strTerminationEnable);
   }
   naiif_printf("\r\n 14   Averaging Time ( Sec )");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AVERAGING_TIME, &averagingTime));
      if (chanNum == 1)
      {
         naiif_printf("%13.3f", averagingTime);
      }
      else
      {
         naiif_printf("%14.3f", averagingTime);
      }
   }
   naiif_printf("\r\n 15   Zero Torque Sig Phase");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE, &zeroTorqueSigPhase));
      naiif_printf("%14.3f", zeroTorqueSigPhase);
   }
   naiif_printf("\r\n 16   Set Zero Torque Sig Phase");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetZeroTorqueSignalPhaseToPhaseReading(cardIdx, modNum, chanNum, &setZeroTorqueSigPhase));
      switch (setZeroTorqueSigPhase)
      {
         case NAI_TRUE:
            naiif_snprintf(strSetZeroTorqueSigPhase, MSG_LENGTH + 1, "Set");
         break;
         case NAI_FALSE:
            naiif_snprintf(strSetZeroTorqueSigPhase, MSG_LENGTH + 1, "Unset");
         break;
         default:
            naiif_snprintf(strSetZeroTorqueSigPhase, MSG_LENGTH + 1, "Unknown");
         break;
      }
      if (chanNum == 1)
      {
         naiif_printf("%10s", strSetZeroTorqueSigPhase);
      }
      else
      {
         naiif_printf("%14s", strSetZeroTorqueSigPhase);
      }
   }
   naiif_printf("\r\n 17   Max Torque Sig Phase ");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE, &maxTorqueSigPhase));
      naiif_printf("%14.3f", maxTorqueSigPhase);
   }
   naiif_printf("\r\n 18   Debounce Time ( Sec )");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_DEBOUNCE_TIME, &debounceTime));
      naiif_printf("%14.2E", debounceTime);
   }
   naiif_printf("\r\n 19   Minimum Amplitude ( V )");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MINIMUM_AMPLITUDE, &minAmplitude));
      if (chanNum == 1)
      {
         naiif_printf("%12.3f", minAmplitude);
      }
      else
      {
         naiif_printf("%14.3f", minAmplitude);
      }
   }
   naiif_printf("\r\n 20   Minimum Frequency ( Hz )");
   for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MINIMUM_FREQUENCY, &minFreq));
      if (chanNum == 1)
      {
         naiif_printf("%11.3f", minFreq);
      }
      else
      {
         naiif_printf("%14.3f", minFreq);
      }
   }
   naiif_printf("\r\n R    Reset Cycle Count");
   naiif_printf("\r\n\r\n MM   Return to Main Menu");
   naiif_printf("\r\n UD   Update");
   naiif_printf("\r\n S    Save Setup");
   naiif_printf("\r\n L    Load Setup\r\n");
}

static nai_status_t VRChannelMenu_SaveSetup(int32_t paramCount, int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
   naiif_printf("\r\nSaving setup is not supported in Deos!\r\n");
#else
   FILE* fp;
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t p_VR_basicOps_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIdx = p_VR_basicOps_params->cardIndex;
   int32_t modNum = p_VR_basicOps_params->module;
   int32_t chanNum = 1;
   int32_t MAX_CHANNELS = p_VR_basicOps_params->maxChannels;
   float64_t numberOfTeeth = 0.0;
   bool_t monopoleDipole = NAI_FALSE;
   bool_t channelEnable = NAI_FALSE;
   float64_t voltThresHi = 0.0;
   float64_t voltThresLo = 0.0;
   bool_t autoThresholdEnable = NAI_FALSE;
   float64_t autoThresholdPercent = 0.0;
   float64_t autoThresholdHysteresis = 0.0;
   naibrd_vr_auto_down_range_time_type_t autoDownRangeTime = NAIBRD_VR_AUTO_DOWN_RANGE_TIME_100MS;
   naibrd_vr_range_select_type_t range = NAIBRD_VR_RANGE_AUTO;
   bool_t polaritySelect = NAI_FALSE;
   bool_t acCoupleEnable = NAI_FALSE;
   bool_t terminationEnable = NAI_FALSE;
   float64_t averagingTime = 0.0;
   float64_t zeroTorqueSigPhase = 0.0;
   float64_t maxTorqueSigPhase = 0.0;
   float64_t debounceTime = 0.0;
   float64_t minAmplitude = 0.0;
   float64_t minFreq = 0.0;
   int8_t inputBuffer[160];
   int32_t inputResponseCnt;
   char* filename = "./vr_basic_ops_setup.txt";

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

   naiif_printf("Note: Relative paths are relative to the program running directory.\r\n");
   naiif_printf("Type path of file to save setup to (default: ./vr_basic_ops_setup.txt): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         filename = (char*)inputBuffer;
      }
      fp = naiif_fopen((const char*)filename, "w");
      if (!fp)
      {
         perror(filename);
         naiif_printf("\r\nFile path invalid!\r\n");
      }
      else
      {
         naiif_fprintf(fp, "Number of Teeth: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_NUMBER_OF_TEETH, &numberOfTeeth));
            naiif_fprintf(fp, "%d,", (int32_t)(numberOfTeeth + 0.5));
         }
         naiif_fprintf(fp, "\r\n[Monopole/Dipole: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE,
                                                        &monopoleDipole));
            naiif_fprintf(fp, "%u,", monopoleDipole);
         }
         naiif_fprintf(fp, "\r\n[Channel Enable: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE,
                                                        &channelEnable));
            naiif_fprintf(fp, "%u,", channelEnable);
         }
         naiif_fprintf(fp, "\r\n[Voltage Threshold High: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, &voltThresHi));
            naiif_fprintf(fp, "%f,", voltThresHi);
         }
         naiif_fprintf(fp, "\r\n[Voltage Threshold Low: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, &voltThresLo));
            naiif_fprintf(fp, "%f,", voltThresLo);
         }
         naiif_fprintf(fp, "\r\n[Auto Threshold Enable: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
                                                        &autoThresholdEnable));
            naiif_fprintf(fp, "%u,", autoThresholdEnable);
         }
         naiif_fprintf(fp, "\r\n[Auto Threshold Percent: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
                                                  &autoThresholdPercent));
            naiif_fprintf(fp, "%f,", autoThresholdPercent);
         }
         naiif_fprintf(fp, "\r\n[Auto Threshold Hysteresis: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS,
                                                  &autoThresholdHysteresis));
            naiif_fprintf(fp, "%f,", autoThresholdHysteresis);
         }
         naiif_fprintf(fp, "\r\n[Auto Down-Range Time: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetAutoDownRangeTime(cardIdx, modNum, chanNum, &autoDownRangeTime));
            naiif_fprintf(fp, "%u,", autoDownRangeTime);
         }
         naiif_fprintf(fp, "\r\n[Range Select: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetRangeSelect(cardIdx, modNum, chanNum, &range));
            naiif_fprintf(fp, "%u,", range);
         }
         naiif_fprintf(fp, "\r\n[Polarity Select: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum,
                                                        NAIBRD_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE, &polaritySelect));
            naiif_fprintf(fp, "%u,", polaritySelect);
         }
         naiif_fprintf(fp, "\r\n[AC Couple Enable: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE,
                                                        &acCoupleEnable));
            naiif_fprintf(fp, "%u,", acCoupleEnable);
         }
         naiif_fprintf(fp, "\r\n[Termination Enable: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE,
                                                        &terminationEnable));
            naiif_fprintf(fp, "%u,", terminationEnable);
         }
         naiif_fprintf(fp, "\r\n[Averaging Time: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AVERAGING_TIME, &averagingTime));
            naiif_fprintf(fp, "%f,", averagingTime);
         }
         naiif_fprintf(fp, "\r\n[Zero Torque Sig Phase: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE,
                                                  &zeroTorqueSigPhase));
            naiif_fprintf(fp, "%f,", zeroTorqueSigPhase);
         }
         naiif_fprintf(fp, "\r\n[Max Torque Sig Phase: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE, &maxTorqueSigPhase));
            naiif_fprintf(fp, "%f,", maxTorqueSigPhase);
         }
         naiif_fprintf(fp, "\r\n[Debounce Time: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_DEBOUNCE_TIME, &debounceTime));
            naiif_fprintf(fp, "%14.9f,", debounceTime);
         }
         naiif_fprintf(fp, "\r\n[Minimum Amplitude: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MINIMUM_AMPLITUDE, &minAmplitude));
            naiif_fprintf(fp, "%f,", minAmplitude);
         }
         naiif_fprintf(fp, "\r\n[Minimum Frequency: ");
         for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
         {
            check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MINIMUM_FREQUENCY, &minFreq));
            naiif_fprintf(fp, "%f,", minFreq);
         }
         naiif_fclose(fp);
         naiif_printf("\r\nSetup Saved\r\n");
      }
   }
#endif
   return NAI_SUCCESS;
}

static nai_status_t VRChannelMenu_LoadSetup(int32_t paramCount, int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
   naiif_printf("\r\nLoading setup is not supported in Deos!\r\n");
#else
   FILE* fp;
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t p_VR_basicOps_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIdx = p_VR_basicOps_params->cardIndex;
   int32_t modNum = p_VR_basicOps_params->module;
   int32_t chanNum = 1;
   int32_t MAX_CHANNELS = p_VR_basicOps_params->maxChannels;
   float64_t numberOfTeeth = 0.0;
   bool_t monopoleDipole = NAI_FALSE;
   bool_t channelEnable = NAI_FALSE;
   float64_t voltThresHi = 0.0;
   float64_t voltThresLo = 0.0;
   bool_t autoThresholdEnable = NAI_FALSE;
   float64_t autoThresholdPercent = 0.0;
   float64_t autoThresholdHysteresis = 0.0;
   naibrd_vr_auto_down_range_time_type_t autoDownRangeTime = NAIBRD_VR_AUTO_DOWN_RANGE_TIME_100MS;
   naibrd_vr_range_select_type_t range = NAIBRD_VR_RANGE_AUTO;
   bool_t polaritySelect = NAI_FALSE;
   bool_t acCoupleEnable = NAI_FALSE;
   bool_t terminationEnable = NAI_FALSE;
   float64_t averagingTime = 0.0;
   float64_t zeroTorqueSigPhase = 0.0;
   float64_t maxTorqueSigPhase = 0.0;
   float64_t debounceTime = 0.0;
   float64_t minAmplitude = 0.0;
   float64_t minFreq = 0.0;
   int8_t inputBuffer[160];
   int32_t inputResponseCnt;
   long lSize = 0;
   char* buffer;
   char* line;
   char* filename = "./vr_basic_ops_setup.txt";

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

   naiif_printf("Note: Relative paths are relative to the program running directory.\r\n");
   naiif_printf("Type path of file to load setup from (default: ./vr_basic_ops_setup.txt): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         filename = (char*)inputBuffer;
      }
      fp = naiif_fopen((const char*)filename, "r");
      if (!fp)
      {
         perror(filename);
         naiif_printf("\r\nSetup file not found! Please save a setup first before loading.\r\n");
      }
      else
      {
         fseek(fp, 0L, SEEK_END);
         lSize = ftell(fp);
         rewind(fp);

         buffer = (char*)calloc(1, lSize + 1);
         if (!buffer)
         {
            naiif_printf("\r\nFailed to allocate memory for loading setup\r\n");
         }
         else
         {
            fread(buffer, lSize, 1, fp);
            line = buffer;

            line = strtok(line, ":");
            if (strcmp(line, "Number of Teeth") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  numberOfTeeth = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Monopole/Dipole") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  monopoleDipole = (bool_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE,
                                                              monopoleDipole));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Channel Enable") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  channelEnable = (bool_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE,
                                                              channelEnable));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Voltage Threshold High") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  voltThresHi = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHi));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Voltage Threshold Low") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  voltThresLo = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLo));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Auto Threshold Enable") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  autoThresholdEnable = (bool_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
                                                              autoThresholdEnable));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Auto Threshold Percent") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  autoThresholdPercent = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
                                                        autoThresholdPercent));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Auto Threshold Hysteresis") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  autoThresholdHysteresis = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS,
                                                        autoThresholdHysteresis));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Auto Down-Range Time") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  autoDownRangeTime = (naibrd_vr_auto_down_range_time_type_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetAutoDownRangeTime(cardIdx, modNum, chanNum, autoDownRangeTime));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Range Select") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  range = (naibrd_vr_range_select_type_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetRangeSelect(cardIdx, modNum, chanNum, range));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Polarity Select") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  polaritySelect = (bool_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetChanMappedControl(cardIdx, modNum, chanNum,
                                                              NAIBRD_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE,
                                                              polaritySelect));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "AC Couple Enable") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  acCoupleEnable = (bool_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE,
                                                              acCoupleEnable));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Termination Enable") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  terminationEnable = (bool_t)(atoi((const char*)line));
                  check_status(naibrd_VR_SetChanMappedControl(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE,
                                                              terminationEnable));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Averaging Time") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  averagingTime = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_AVERAGING_TIME, averagingTime));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Zero Torque Sig Phase") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  zeroTorqueSigPhase = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE,
                                                        zeroTorqueSigPhase));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Max Torque Sig Phase") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  maxTorqueSigPhase = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE,
                                                        maxTorqueSigPhase));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Debounce Time") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  debounceTime = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_DEBOUNCE_TIME, debounceTime));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Minimum Amplitude") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  minAmplitude = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MINIMUM_AMPLITUDE, minAmplitude));
               }
            }

            line = strtok(NULL, "[");
            line = strtok(NULL, ":");
            if (strcmp(line, "Minimum Frequency") == 0)
            {
               for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
               {
                  line = strtok(NULL, ",");
                  minFreq = atof((const char*)line);
                  check_status(naibrd_VR_SetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_MINIMUM_FREQUENCY, minFreq));
               }
            }

            naiif_printf("\r\nSetup Loaded\r\n");
            free(buffer);
         }
         naiif_fclose(fp);
      }
   }
#endif
   return NAI_SUCCESS;
}


static void VRReadingsMenu_StartDisplayReadingsThread(int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
   pthread_t thread1;
#endif

   g_stopReadingsUpdateThread = NAI_FALSE;
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)VRReadingsMenu_RunDisplayReadingsThread, (void*)p_params, 0, 0);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
   pthread_create(&thread1, 0, (void *)&VRReadingsMenu_RunDisplayReadingsThread, (void*)p_params);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
   taskSpawn("MonitorRxBuffer", 99, 0, 0x4000, (FUNCPTR)VRReadingsMenu_RunDisplayReadingsThread, (int)(int32_t *)p_params, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
   VRReadingsMenu_DisplayChannelReadings(p_params);
#else
   naiif_printf("StartDisplayReadingsThread not supported.\r\n");
#endif
}

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params)
{
   int32_t* p_params_int = (int32_t*)p_params;
   while (g_stopReadingsUpdateThread == NAI_FALSE)
   {
      system("cls");

      VRReadingsMenu_DisplayChannelReadings(p_params_int);
      naiif_msDelay(g_ReadingsUpdateRate);
   }
}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params)
{
   int32_t* p_params_int = (int32_t*)p_params;
   while (g_stopReadingsUpdateThread == NAI_FALSE)
   {

      naiif_printf("\033[H\033[J");

      VRReadingsMenu_DisplayChannelReadings(p_params_int);
      naiif_msDelay(g_ReadingsUpdateRate);
   }
}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static void VRReadingsMenu_RunDisplayReadingsThread(int32_t* p_params)
{
   int32_t* p_params_int = (int32_t*)p_params;
   while (g_stopReadingsUpdateThread == NAI_FALSE)
   {
      naiif_printf("\033[H\033[J");
      VRReadingsMenu_DisplayChannelReadings(p_params_int);
      naiif_msDelay(g_ReadingsUpdateRate);
   }
}
#endif

static void VRReadingsMenu_DisplayChannelReadings(int32_t* p_params)
{
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIdx = VR_params->cardIndex;
   int32_t modNum = VR_params->module;
   int32_t chanNum = 1;
   int32_t maxChannel = VR_params->maxChannels;
   float64_t amplitudeMeas = 0.0;
   float64_t freqMeas = 0.0;
   float64_t rpmMeas = 0.0;
   float64_t periodMeas = 0.0;
   float64_t phaseMeas[NAI_VR_GEN5_CHANNELS] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
   float64_t zeroTorqueSigPhase = 0.0;
   float64_t phaseDelta = 0.0;
   float64_t percentTorqueMeas = 0.0;
   float64_t cycleCount = 0.0;

   naiif_printf("\r\n   Readings Group Menu               Ch 1          Ch 2          Ch 3          Ch 4          Ch 5          Ch 6          ");
   naiif_printf("Ch 7          Ch 8\r\n\r\n");
   naiif_printf("   Amplitude ( V )         ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAIBRD_VR_MEASURED_AMPLITUDE, &amplitudeMeas));
      naiif_printf("%14.3f", amplitudeMeas);
   }
   naiif_printf("\r\n   Frequency ( Hz )        ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAIBRD_VR_MEASURED_FREQUENCY, &freqMeas));
      naiif_printf("%14.3f", freqMeas);
   }
   naiif_printf("\r\n   RPM       ( RPM )       ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAIBRD_VR_MEASURED_RPM, &rpmMeas));
      naiif_printf("%14.3f", rpmMeas);
   }
   naiif_printf("\r\n   Period    ( Sec )       ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAIBRD_VR_MEASURED_PERIOD, &periodMeas));
      naiif_printf("%14.2E", periodMeas);
   }
   naiif_printf("\r\n   Phase     ( Deg )       ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAIBRD_VR_MEASURED_PHASE, &(phaseMeas[chanNum - 1])));
      naiif_printf("%14.3f", phaseMeas[chanNum - 1]);
   }

   naiif_printf("\r\n   Phase Delta    ( Deg )  ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAIBRD_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE, &zeroTorqueSigPhase));
      /* phase delta = NAIBRD_VR_MEASURED_PHASE - trigger phase */
      phaseDelta = phaseMeas[chanNum - 1] - zeroTorqueSigPhase;
      naiif_printf("%14.3f", phaseDelta);
   }

   naiif_printf("\r\n   Percent Torque          ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAIBRD_VR_MEASURED_PERCENT_TORQUE, &percentTorqueMeas));
      naiif_printf("%14.3f", percentTorqueMeas);
   }

   naiif_printf("\r\n   Cycle Count             ");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAIBRD_VR_MEASURED_CYCLE_COUNT, &cycleCount));
      if (cycleCount > 9999999999.0)
      {
         naiif_printf("%14.5E", cycleCount);
      }
      else
      {
         naiif_printf("%14u", (uint32_t)(cycleCount + 0.5));
      }
   }

   naiif_printf("\r\n\r\nMM   Return to Main Menu");
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   naiif_printf("\r\nR    Change Update Rate in milliSeconds [default:1000mS]");
   naiif_printf("\r\nC    Continue Poll");
   naiif_printf("\r\nS    Stop Polling\r\n");
#endif
   naiif_printf("\r\n>Please Enter Channel Readings Menu command or %c to quit : ", NAI_QUIT_CHAR);
}

static nai_status_t VRReadingsMenu_ChangeUpdateRate(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   long updateRateToSet = 0l;

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   UNREFERENCED_PARAMETER(paramCount);
   UNREFERENCED_PARAMETER(p_params);
#endif

   VRReadingsMenu_StopPolling(paramCount, p_params);
   naiif_printf("Enter Update Rate to set in milliSeconds: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      updateRateToSet = (long)(atoi((const char*)inputBuffer));
      if (updateRateToSet > 0l)
      {
         g_ReadingsUpdateRate = updateRateToSet;
      }
   }
   VRReadingsMenu_ContinuePoll(paramCount, p_params);
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRReadingsMenu_ContinuePoll(int32_t paramCount, int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   UNREFERENCED_PARAMETER(paramCount);
   UNREFERENCED_PARAMETER(p_params);
#endif

   if (g_stopReadingsUpdateThread == NAI_TRUE)
   {
      VRReadingsMenu_StartDisplayReadingsThread(p_params);
   }
   return NAI_SUCCESS;
}

static nai_status_t VRReadingsMenu_StopPolling(int32_t paramCount, int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   UNREFERENCED_PARAMETER(paramCount);
   UNREFERENCED_PARAMETER(p_params);
#endif

   g_stopReadingsUpdateThread = NAI_TRUE;
   naiif_printf("\r\n>Please Enter Channel Readings Menu command or %c to quit : ", NAI_QUIT_CHAR);
   return NAI_SUCCESS;
}


static void VRTestMenu_DisplayTestSettings(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_VR_basicOps_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIdx = p_VR_basicOps_params->cardIndex;
   int32_t modNum = p_VR_basicOps_params->module;
   bool_t iBitTestEnabled = NAI_FALSE;
   bool_t powerSupplyEnabled = NAI_FALSE;
   bool_t floatingPointModeEnabled = NAI_FALSE;
   char strIBitTestEnabled[MSG_LENGTH] = "";
   char strPowerSupplyEnabled[MSG_LENGTH] = "";
   char strFloatingPointModeEnabled[MSG_LENGTH] = "";

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

   naiif_printf("\r\n   Test Group Menu\r\n\r\n");
   check_status(naibrd_VR_GetModuleBITEnable(cardIdx, modNum, NAIBRD_VR_TEST_ENABLE_IBIT_D3, &iBitTestEnabled));
   switch (iBitTestEnabled)
   {
      case NAI_TRUE:
         naiif_snprintf(strIBitTestEnabled, MSG_LENGTH + 1, "Enabled");
      break;
      case NAI_FALSE:
         naiif_snprintf(strIBitTestEnabled, MSG_LENGTH + 1, "Disabled");
      break;
      default:
         naiif_snprintf(strIBitTestEnabled, MSG_LENGTH + 1, "Unknown");
      break;
   }
   naiif_printf("IBIT (D3) Test State:      %s\r\n", strIBitTestEnabled);
   check_status(naibrd_VR_GetPowerSupplyEnable(cardIdx, modNum, &powerSupplyEnabled));
   switch (powerSupplyEnabled)
   {
      case NAI_TRUE:
         naiif_snprintf(strPowerSupplyEnabled, MSG_LENGTH + 1, "Enabled");
      break;
      case NAI_FALSE:
         naiif_snprintf(strPowerSupplyEnabled, MSG_LENGTH + 1, "Disabled");
      break;
      default:
         naiif_snprintf(strPowerSupplyEnabled, MSG_LENGTH + 1, "Unknown");
      break;
   }
   naiif_printf("Power Supply State:        %s\r\n", strPowerSupplyEnabled);
   check_status(naibrd_GetRunningInFloatingPointMode(cardIdx, modNum, &floatingPointModeEnabled));
   switch (floatingPointModeEnabled)
   {
      case NAI_TRUE:
         naiif_snprintf(strFloatingPointModeEnabled, MSG_LENGTH + 1, "Enabled");
      break;
      case NAI_FALSE:
         naiif_snprintf(strFloatingPointModeEnabled, MSG_LENGTH + 1, "Disabled");
      break;
      default:
         naiif_snprintf(strFloatingPointModeEnabled, MSG_LENGTH + 1, "Unknown");
      break;
   }
   naiif_printf("Floating-Point Mode State: %s\r\n\r\n", strFloatingPointModeEnabled);
   naiif_printf("MM   Return to Main Menu\r\n");
   naiif_printf("TE   Test Enable (IBIT)\r\n");
   naiif_printf("PS   Power Supply Enable\r\n");
   naiif_printf("FE   Floating-Point Enable\r\n");
}

static nai_status_t VRTestMenu_SetTestEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Do you want to enable or disable the IBIT (D3) Test? (1 to enable, 0 to disable): ");
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         check_status(naibrd_VR_SetModuleBITEnable(cardIndex, module, NAIBRD_VR_TEST_ENABLE_IBIT_D3, enable));
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRTestMenu_SetPowerSupplyEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Do you want to enable or disable the module power supply? (1 to enable, 0 to disable): ");
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         check_status(naibrd_VR_SetPowerSupplyEnable(cardIndex, module, enable));
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRTestMenu_SetFloatingPointEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Do you want to enable or disable floating-point mode for the module? (1 to enable, 0 to disable): ");
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, enable));
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}


static void VRStatusMenu_StartDisplayStatusThread(int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
   pthread_t thread1;
#endif

   g_stopStatusUpdateThread = NAI_FALSE;
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)VRStatusMenu_RunDisplayStatusThread, (void*)p_params, 0, 0);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
   pthread_create(&thread1, 0, (void *)&VRStatusMenu_RunDisplayStatusThread, (void*)p_params);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
   taskSpawn("VRStatusMenu_RunDisplayStatusThread", 99, 0, 0x4000, (FUNCPTR)VRStatusMenu_RunDisplayStatusThread,
         (int)(int32_t*)p_params, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
   VRStatusMenu_DisplayStatuses(p_params);
#else
   naiif_printf("StartDisplayStatusThread not supported.\r\n");
#endif
}

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params)
{
   int32_t* p_params_int = (int32_t*)p_params;
   while (g_stopStatusUpdateThread == NAI_FALSE)
   {
      system("cls");

      VRStatusMenu_DisplayStatuses(p_params_int);
      naiif_msDelay(g_StatusUpdateRate);
   }
}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params)
{
   int32_t* p_params_int = (int32_t*)p_params;
   while (g_stopStatusUpdateThread == NAI_FALSE)
   {
      naiif_printf("\033[H\033[J");

      VRStatusMenu_DisplayStatuses(p_params_int);
      naiif_msDelay(g_StatusUpdateRate);
   }
}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static void VRStatusMenu_RunDisplayStatusThread(int32_t* p_params)
{
   int32_t* p_params_int = (int32_t*)p_params;
   while (g_stopStatusUpdateThread == NAI_FALSE)
   {
      naiif_printf("\033[H\033[J");
      VRStatusMenu_DisplayStatuses(p_params_int);
      naiif_msDelay(g_StatusUpdateRate);
   }
}
#endif

static void VRStatusMenu_DisplayStatuses(int32_t* p_params)
{
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIdx = VR_params->cardIndex;
   int32_t modNum = VR_params->module;
   int32_t chanNum = 1;
   int32_t maxChannel = VR_params->maxChannels;
   nai_status_bit_t bitLatchedStatus = NAI_STATUS_BIT_LO;
   nai_status_bit_t bitRealtimeStatus = NAI_STATUS_BIT_LO;
   nai_status_bit_t terminationLatchedStatus = NAI_STATUS_BIT_LO;
   nai_status_bit_t terminationRealtimeStatus = NAI_STATUS_BIT_LO;
   nai_status_bit_t signalLossLatchedStatus = NAI_STATUS_BIT_LO;
   nai_status_bit_t signalLossRealtimeStatus = NAI_STATUS_BIT_LO;
   nai_status_bit_t summaryLatchedStatus = NAI_STATUS_BIT_LO;
   nai_status_bit_t summaryRealtimeStatus = NAI_STATUS_BIT_LO;
   bool_t chanStatusEnable = NAI_FALSE;
   char strChanStatusEnable[MSG_LENGTH] = "";

   naiif_printf("\r\n  Status Monitoring Group Menu\r\n\r\n");
   naiif_printf("   Chan   Chan Status    BIT    Termination Fault   Signal Loss   Summary\r\n");
   naiif_printf("            Enable      (R/L)         (R/L)            (R/L)       (R/L)\r\n");
   naiif_printf("=========================================================================\r\n");
   for (chanNum = 1; chanNum <= maxChannel; chanNum++)
   {
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitLatchedStatus));
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_BIT_REALTIME, &bitRealtimeStatus));
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_LATCHED,
                                                 &terminationLatchedStatus));
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_REALTIME,
                                                 &terminationRealtimeStatus));
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_LATCHED,
                                                 &signalLossLatchedStatus));
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_REALTIME,
                                                 &signalLossRealtimeStatus));
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED,
                                                 &summaryLatchedStatus));
      check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAIBRD_VR_CHAN_MAPPED_STATUS_SUMMARY_REALTIME,
                                                 &summaryRealtimeStatus));
      check_status(naibrd_VR_GetChanStatusEnable(cardIdx, modNum, chanNum, &chanStatusEnable));
      switch (chanStatusEnable)
      {
         case NAI_TRUE:
            naiif_snprintf(strChanStatusEnable, MSG_LENGTH + 1, " Enabled");
         break;
         case NAI_FALSE:
            naiif_snprintf(strChanStatusEnable, MSG_LENGTH + 1, "Disabled");
         break;
         default:
            naiif_snprintf(strChanStatusEnable, MSG_LENGTH + 1, " Unknown");
         break;
      }
      naiif_printf("   %2d      %8s     (%1d/%1d)         (%1d/%1d)            (%1d/%1d)       (%1d/%1d)\r\n", chanNum, strChanStatusEnable,
             bitRealtimeStatus, bitLatchedStatus, terminationRealtimeStatus, terminationLatchedStatus, signalLossRealtimeStatus,
             signalLossLatchedStatus, summaryRealtimeStatus, summaryLatchedStatus);
   }

   naiif_printf("\r\nMM   Return to Main Menu");
   naiif_printf("\r\nE    Channel Status Enable");
   naiif_printf("\r\nC    Clear Status");
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   naiif_printf("\r\nR    Change Update Rate in milliSeconds [default:1000mS]");
   naiif_printf("\r\nP    Continue Poll");
   naiif_printf("\r\nS    Stop Polling");
#endif
   naiif_printf("\r\n\r\n>Please Enter Status Menu command or %c to quit : ", NAI_QUIT_CHAR);
}

static nai_status_t VRStatusMenu_SetChanStatusEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   if (channel == 0)
   {
      naiif_printf("Do you want to enable or disable status reporting for all channels? (1 to enable, 0 to disable): ");
   }
   else
   {
      naiif_printf("Do you want to enable or disable status reporting for channel %d? (1 to enable, 0 to disable): ", channel);
   }
   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 = NAI_TRUE;
         }
         else
         {
            enable = NAI_FALSE;
         }
         if (channel == 0)
         {
            for (channel = 1; channel <= MAX_CHANNELS; channel++)
            {
               check_status(naibrd_VR_SetChanStatusEnable(cardIndex, module, channel, enable));
            }
         }
         else
         {
            check_status(naibrd_VR_SetChanStatusEnable(cardIndex, module, channel, enable));
         }
      }
      else
      {
         naiif_printf("\r\nInvalid Selection Entered\r\n");
      }
   }
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   VRStatusMenu_ContinuePoll(paramCount, p_params);
#endif
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRStatusMenu_ClearStatus(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t VR_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = VR_params->cardIndex;
   int32_t module = VR_params->module;
   int32_t channel = VR_params->channel;
   int32_t MAX_CHANNELS = VR_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf("Enter Latched Status Type to clear (0 for BIT, 1 for Termination Fault, 2 for Signal Loss, 3 for Summary): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      if (channel == 0)
      {
         for (channel = 1; channel <= MAX_CHANNELS; channel++)
         {
            switch (inputBuffer[0])
            {
               case '0':
                  check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_STATUS_BIT_LATCHED));
               break;
               case '1':
                  check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel,
                                                               NAIBRD_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_LATCHED));
               break;
               case '2':
                  check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel,
                                                               NAIBRD_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_LATCHED));
               break;
               case '3':
                  check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED));
               break;
               default:
                  naiif_printf("\r\nInvalid Selection Entered\r\n");
               break;
            }
         }
      }
      else
      {
         switch (inputBuffer[0])
         {
            case '0':
               check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_STATUS_BIT_LATCHED));
            break;
            case '1':
               check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel,
                                                            NAIBRD_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_LATCHED));
            break;
            case '2':
               check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_LATCHED));
            break;
            case '3':
               check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAIBRD_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED));
            break;
            default:
               naiif_printf("\r\nInvalid Selection Entered\r\n");
            break;
         }
      }
   }
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   VRStatusMenu_ContinuePoll(paramCount, p_params);
#endif
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRStatusMenu_ChangeUpdateRate(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   long updateRateToSet = 0l;

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   UNREFERENCED_PARAMETER(paramCount);
   UNREFERENCED_PARAMETER(p_params);
#endif

   VRStatusMenu_StopPolling(paramCount, p_params);
   naiif_printf("Enter Update Rate to set in milliSeconds: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      updateRateToSet = (long)(atoi((const char*)inputBuffer));
      if (updateRateToSet > 0l)
      {
         g_StatusUpdateRate = updateRateToSet;
      }
   }
#ifndef NAIBSP_CONFIG_SOFTWARE_OS_DEOS
   VRStatusMenu_ContinuePoll(paramCount, p_params);
#endif
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t VRStatusMenu_ContinuePoll(int32_t paramCount, int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   UNREFERENCED_PARAMETER(paramCount);
   UNREFERENCED_PARAMETER(p_params);
#endif

   if (g_stopStatusUpdateThread == NAI_TRUE)
   {
      VRStatusMenu_StartDisplayStatusThread(p_params);
   }
   return NAI_SUCCESS;
}

static nai_status_t VRStatusMenu_StopPolling(int32_t paramCount, int32_t* p_params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   UNREFERENCED_PARAMETER(paramCount);
   UNREFERENCED_PARAMETER(p_params);
#endif

   g_stopStatusUpdateThread = NAI_TRUE;
   naiif_printf("\r\n\r\n>Please Enter Status Menu command or %c to quit : ", NAI_QUIT_CHAR);
   return NAI_SUCCESS;
}

Help Bot

X