VR BasicOps Sample Application (SSK 1.x)
Overview
The VR BasicOps sample application demonstrates how to configure a Variable Reluctance (VR) module, read its measurements, and monitor channel status using the NAI Software Support Kit (SSK 1.x). A VR module conditions the signal from a variable-reluctance speed/position sensor (the toothed-wheel pickups used for engine speed, turbine RPM, and shaft torque) and converts each channel’s waveform into measurements you can read back directly: amplitude, frequency, RPM, period, phase, percent torque, and accumulated cycle count.
This sample supports the VR1 module. It serves as a practical API reference — each menu command maps directly to one or more naibrd_VR_*() API calls that you can lift into your own code.
The application is organized as a top-level menu with four submenus, each backed by its own command table:
- Channel Set-Up — per-channel signal conditioning: number of teeth, monopole/dipole, thresholds, range, edge polarity, AC coupling, termination, averaging, torque-phase references, and more.
- Display Readings — a live, polled view of every channel’s measurements (amplitude, frequency, RPM, period, phase, percent torque, cycle count).
- System Test Set-Up — module-level test controls: IBIT, power-supply enable, and floating-point mode.
- Display Monitor/Status — a live, polled view of per-channel status (BIT, termination fault, signal loss, summary) with enable and clear controls.
Prerequisites
Before running this sample, make sure you have:
- An NAI board with a VR module (VR1) installed.
- SSK 1.x installed on your development host.
- The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.
- A variable-reluctance signal source (or the module’s built-in test source) connected to at least one channel if you want to see live measurements.
How to Run
Launch the VR_BasicOps 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, the VR Basic Operations menu lets you exercise each group of operations.
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 1.x startup flow:
- Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. - Query the user for a card index with
naiapp_query_CardIndex(). - Retrieve the module count with
naibrd_GetModuleCount()and query for a module slot withnaiapp_query_ModuleNumber(). - Retrieve the module ID with
naibrd_GetModuleID()and, if valid, hand control toVRBasicMenu_Run().
#if defined (__VXWORKS__)
int32_t VR_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
g_ReadingsUpdateRate = 1000;
g_StatusUpdateRate = 1000;
/* ... initialize the remaining global thread flags ... */
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
VRBasicMenu_Run(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiapp_access_CloseAllOpenCards();
return 0;
}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 a VR module. Use the board menu to verify which slots are populated.
Program Structure
Entry Point
On standard platforms the entry point is main(). On VxWorks the entry point is VR_BasicOps() — the SSK 1.x build system selects the correct variant via a preprocessor guard:
#if defined (__VXWORKS__)
int32_t VR_BasicOps(void)
#else
int32_t main(void)
#endifApplication Parameters
VRBasicMenu_Run() populates an naiapp_AppParameters_t struct that is passed to every command handler. Your application will need to track these same values to identify which board, module, and channel you are targeting:
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;
p_VR_basicOps_params->maxChannels = naibrd_VR_GetChannelCount(modid);cardIndex— identifies which board in a multi-board system.module— the slot number where the VR module is installed.channel— the channel a command applies to. The sample uses a value of0as a sentinel meaning “apply to all channels”; otherwise it holds the one-based channel number the user selected.maxChannels— total channel count for the detected module, retrieved by callingnaibrd_VR_GetChannelCount()with the module ID.modId— the module identifier returned bynaibrd_GetModuleID().
Command Loop
VRBasicMenu_Run() drives the top-level command loop. On each iteration it loads the command table, displays the menu, and dispatches the user’s selection to the matching submenu handler:
static bool_t VRBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modid)
{
/* ... populate VR_basicOps_params (see above) ... */
do
{
naiapp_utils_LoadParamMenuCommands(VR_BASICMENU_CMD_COUNT, VR_BasicOpCmds);
naiapp_display_ParamMenuCommands((int8_t*)"VR Basic Operations");
printf("\n Type command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if (naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd))
VR_BasicOpCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_VR_basicOps_params);
else
printf(" Invalid command entered\n");
}
} while (!bQuit);
return bQuit;
}The top-level commands are registered in the VR_BasicOpCmds[] table:
| Command | Description |
|---|---|
| CS | Open the Channel Set-Up submenu |
| R | Open the Display Readings submenu |
| T | Open the System Test Set-Up submenu |
| Mon | Open the Display Monitor/Status submenu |
Each submenu has its own command table (VR_ChannelSetupMenuCmds[], VR_ChannelReadingsMenuCmds[], VR_TestMenuCmds[], VR_StatusMenuCmds[]) and is loaded the same way when you enter it. The menu-driven structure is a convenience of the sample application. In your own application, you would call the same underlying naibrd_VR_*() API functions directly.
Note
Most channel set-up commands first prompt with “Type ‘a’ or ‘A’ to apply command to all channels, or type ‘s’ or ‘S’ to select a channel.” Choosing all sets
channel = 0; every handler then loops from channel 1 tomaxChannels. Choosing select stores the one-based channel number. The code samples below show the single-channel call; the all-channels case is just that call inside aforloop.
Channel Configuration
The Channel Set-Up submenu configures how each VR channel conditions and interprets its input signal. Two API functions cover most of these settings:
naibrd_VR_SetConfigValue()— sets a floating-point configuration value (thresholds, teeth count, timing, torque phases, amplitude/frequency limits) selected by anai_vr_config_value_type_t.naibrd_VR_SetChanMappedControl()— enables or disables a boolean channel control (channel enable, dipole, edge polarity, termination, AC couple, auto-threshold) selected by anai_vr_chan_mapped_control_type_t.
A few settings have dedicated functions (naibrd_VR_SetRangeSelect(), naibrd_VR_SetAutoDownRangeTime(), naibrd_VR_SetZeroTorqueSignalPhaseToPhaseReading(), naibrd_VR_ResetCycleCount()), covered below.
Number of Teeth
The number of teeth on the sensed wheel is what lets the module convert measured frequency into RPM. Set it with naibrd_VR_SetConfigValue() and the NAI_VR_CONFIG_NUMBER_OF_TEETH selector.
float64_t numberOfTeeth = 60.0;
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth);channel— the channel to configure (loop 1..maxChannelsto apply to all).NAI_VR_CONFIG_NUMBER_OF_TEETH— selects the teeth-count configuration value.numberOfTeeth— the tooth count of the target wheel, as afloat64_t.
Note
The RPM measurement (
NAI_VR_MEASURED_RPM) is only meaningful once the number of teeth is set correctly for the channel. An incorrect tooth count produces a proportionally incorrect RPM.
Monopole / Dipole
VR sensors come in monopole and dipole varieties. Select the sensor type with naibrd_VR_SetChanMappedControl() and the NAI_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE selector (FALSE = monopole, TRUE = dipole).
bool_t enableDipole = TRUE; /* FALSE for monopole */
naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
NAI_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE, enableDipole);Channel Enable
Enable or disable signal processing on a channel with the NAI_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE selector.
bool_t enable = TRUE;
naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
NAI_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE, enable);Voltage Thresholds (High / Low)
The high and low voltage thresholds define the hysteresis band the module uses to detect a valid tooth crossing. Set each one with naibrd_VR_SetConfigValue():
float64_t voltThresHigh = 2.5; /* volts */
float64_t voltThresLow = -2.5; /* volts */
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh);
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow);These manual thresholds are used when auto-threshold is disabled (see below).
Auto Threshold
Instead of fixed thresholds, the module can track the signal automatically. Enabling auto-threshold is a boolean control; the percent, hysteresis, and down-range time are tuning values.
/* Enable automatic threshold tracking */
naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
NAI_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE, TRUE);
/* Tune the auto-threshold behavior */
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_AUTO_THRESHOLD_PERCENT, 50.0);
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS, 10.0);
/* Set how quickly the module ranges back down after a drop in amplitude */
naibrd_VR_SetAutoDownRangeTime(cardIndex, module, channel, NAI_VR_AUTO_DOWN_RANGE_TIME_1S);NAI_VR_CONFIG_AUTO_THRESHOLD_PERCENT— the percent of peak amplitude at which the threshold is placed.NAI_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS— the hysteresis band, as a percent, around that threshold.naibrd_VR_SetAutoDownRangeTime()takes anai_vr_auto_down_range_time_type_t(NAI_VR_AUTO_DOWN_RANGE_TIME_100MSthrough..._10S) that controls how long the module waits before selecting a lower range after the input amplitude falls.
Range Select
The input range can be fixed or set to auto-range. naibrd_VR_SetRangeSelect() takes a nai_vr_range_select_type_t:
naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAI_VR_RANGE_AUTO);
/* or a fixed range, e.g. NAI_VR_RANGE_5V */
naibrd_VR_SetRangeSelect(cardIndex, module, channel, NAI_VR_RANGE_5V);The available fixed ranges run from NAI_VR_RANGE_50mV through NAI_VR_RANGE_100V (50 mV, 100 mV, 250 mV, 500 mV, 1 V, 2.5 V, 5 V, 12.5 V, 25 V, 50 V, 100 V), plus NAI_VR_RANGE_AUTO for automatic ranging.
Edge Polarity
“Polarity Select” chooses which signal edge the module triggers measurements on, via the NAI_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE control (FALSE = rising edge, TRUE = falling edge).
bool_t enableFallingEdgeMeas = TRUE; /* FALSE = rising edge */
naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
NAI_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE, enableFallingEdgeMeas);AC Couple and Termination
Two more boolean controls condition the input: AC coupling (NAI_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE, where FALSE = DC coupling) and input termination (NAI_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE).
naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE, TRUE);
naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE, TRUE);Averaging, Debounce, and Minimum Limits
Four more naibrd_VR_SetConfigValue() settings tune measurement stability and noise rejection:
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_AVERAGING_TIME, 0.5); /* seconds */
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_DEBOUNCE_TIME, 0.001); /* seconds */
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_MINIMUM_AMPLITUDE, 0.1); /* volts */
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_MINIMUM_FREQUENCY, 5.0); /* Hz */NAI_VR_CONFIG_AVERAGING_TIME— the window over which measurements are averaged.NAI_VR_CONFIG_DEBOUNCE_TIME— minimum time between accepted edges, to reject contact bounce/noise.NAI_VR_CONFIG_MINIMUM_AMPLITUDE— inputs below this amplitude are treated as signal loss.NAI_VR_CONFIG_MINIMUM_FREQUENCY— inputs below this frequency are treated as signal loss.
Torque Phase References
For torque measurement, the module compares the measured signal phase against a configured zero-torque reference. Set the zero- and max-torque phases directly, or capture the current phase as the zero-torque reference:
/* Set the phase references explicitly (degrees) */
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE, 0.0);
naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE, 30.0);
/* Or latch the current measured phase as the zero-torque reference */
naibrd_VR_SetZeroTorqueSignalPhaseToPhaseReading(cardIndex, module, channel);The percent-torque reading reported in the Readings menu is derived from how far the measured phase has shifted away from the zero-torque phase toward the max-torque phase.
Reset Cycle Count
The module accumulates a running cycle (tooth) count per channel. Reset it to zero with:
naibrd_VR_ResetCycleCount(cardIndex, module, channel);Important
Common Errors
- Invalid value entered — the configuration handlers validate numeric input; non-numeric entries (other than a literal
0) are rejected with an “Invalid … value entered” message and no API call is made.- Manual thresholds ignored — if auto-threshold is enabled, the manual high/low voltage thresholds are not used. Disable
NAI_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLEto use manual thresholds.- RPM looks wrong — verify the number of teeth matches the sensed wheel; RPM scales directly with this value.
Reading Channel Measurements
The Display Readings submenu shows a live table of every channel’s measurements, refreshed on a polling thread. All measurements are read with a single function, naibrd_VR_GetMeasurement(), selected by a nai_vr_measured_value_type_t:
float64_t amplitude = 0.0, frequency = 0.0, rpm = 0.0, period = 0.0;
float64_t phase = 0.0, percentTorque = 0.0, cycleCount = 0.0;
for (channel = 1; channel <= maxChannels; channel++)
{
naibrd_VR_GetMeasurement(cardIndex, module, channel, NAI_VR_MEASURED_AMPLITUDE, &litude);
naibrd_VR_GetMeasurement(cardIndex, module, channel, NAI_VR_MEASURED_FREQUENCY, &frequency);
naibrd_VR_GetMeasurement(cardIndex, module, channel, NAI_VR_MEASURED_RPM, &rpm);
naibrd_VR_GetMeasurement(cardIndex, module, channel, NAI_VR_MEASURED_PERIOD, &period);
naibrd_VR_GetMeasurement(cardIndex, module, channel, NAI_VR_MEASURED_PHASE, &phase);
naibrd_VR_GetMeasurement(cardIndex, module, channel, NAI_VR_MEASURED_PERCENT_TORQUE, &percentTorque);
naibrd_VR_GetMeasurement(cardIndex, module, channel, NAI_VR_MEASURED_CYCLE_COUNT, &cycleCount);
}NAI_VR_MEASURED_AMPLITUDE— peak input amplitude, in volts.NAI_VR_MEASURED_FREQUENCY— signal frequency, in Hz.NAI_VR_MEASURED_RPM— rotational speed in RPM (derived from frequency and the configured tooth count).NAI_VR_MEASURED_PERIOD— signal period, in seconds.NAI_VR_MEASURED_PHASE— measured phase, in degrees.NAI_VR_MEASURED_PERCENT_TORQUE— torque as a percentage, derived from the phase shift relative to the zero-torque reference.NAI_VR_MEASURED_CYCLE_COUNT— accumulated tooth count.
The sample also computes a phase delta for display by reading the configured zero-torque phase with naibrd_VR_GetConfigValue(..., NAI_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE, ...) and subtracting it from the measured phase.
Polling and Update Rate
The readings table runs on a background thread (VRReadingsMenu_StartDisplayReadingsThread()), implemented with pthread on Linux, native threads on Windows, and taskLib on VxWorks. The submenu commands control the thread rather than the hardware:
- R — change the update rate (milliseconds); the default is 1000 ms, stored in
g_ReadingsUpdateRate. - C — continue (restart) polling.
- S — stop polling.
- MM — stop the thread and return to the main menu.
In your own application you do not need the threading machinery — call naibrd_VR_GetMeasurement() whenever you need a fresh value.
System Test
The System Test Set-Up submenu exposes three module-level controls. Their current states are read back for display with the matching Get functions (naibrd_VR_GetModuleBITEnable(), naibrd_VR_GetPowerSupplyEnable(), naibrd_GetRunningInFloatingPointMode()).
IBIT (Initiated BIT)
Enable or disable the initiated built-in test (D3) with naibrd_VR_SetModuleBITEnable():
bool_t enable = TRUE;
naibrd_VR_SetModuleBITEnable(cardIndex, module, NAI_VR_TEST_ENABLE_IBIT_D3, enable);Power Supply Enable
VR modules drive an excitation/power supply for the sensor. Toggle it with naibrd_VR_SetPowerSupplyEnable():
bool_t enable = TRUE;
naibrd_VR_SetPowerSupplyEnable(cardIndex, module, enable);Floating-Point Mode
Enable hardware floating-point conversion mode for the module with the common naibrd_SetFloatingPointModeEnable() function:
bool_t enable = TRUE;
naibrd_SetFloatingPointModeEnable(cardIndex, module, enable);Status and Monitoring
The Display Monitor/Status submenu shows a live, polled table of per-channel status. Like the readings table, it runs on a background thread and refreshes at g_StatusUpdateRate (default 1000 ms).
Reading Status
Each status condition is read with naibrd_VR_GetChanMappedStatus(), selected by a nai_vr_chan_mapped_status_type_t. Every condition has both a real-time and a latched variant:
nai_status_bit_t bitRT, bitLT, termRT, termLT, lossRT, lossLT, sumRT, sumLT;
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_BIT_REALTIME, &bitRT);
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitLT);
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_REALTIME, &termRT);
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_LATCHED, &termLT);
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_REALTIME, &lossRT);
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_LATCHED, &lossLT);
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SUMMARY_REALTIME, &sumRT);
naibrd_VR_GetChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED, &sumLT);The sample displays each pair in R/L (real-time / latched) format:
- R/L — the first value is the real-time status, the second is the latched status. Real-time reflects the current condition; latched holds the value until explicitly cleared.
- BIT — a built-in-test fault on the channel.
- Termination Fault — a fault in the channel’s input termination.
- Signal Loss — the input fell below the configured minimum amplitude or frequency.
- Summary — an aggregate of the channel’s error conditions; set if any individual status is set.
Channel Status Enable and Clear
Status reporting is enabled per channel. When disabled, the module does not report status (or assert status-driven interrupts) for that channel.
/* Enable status reporting on a channel */
naibrd_VR_SetChanStatusEnable(cardIndex, module, channel, TRUE);
/* Read back whether it is enabled */
bool_t enabled = FALSE;
naibrd_VR_GetChanStatusEnable(cardIndex, module, channel, &enabled);Latched status is cleared with naibrd_VR_ClearChanMappedStatus(), selecting the latched status type to clear:
naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED);Note
The submenu stops polling while you change the status-enable setting or clear status, then resumes polling automatically. This avoids the display thread and your command racing on the same registers.
Save and Load Setup
The Channel Set-Up submenu can persist the current channel configuration to a text file (naibrd-side values are read back with the Get functions and written out) and reload it later:
- S (Save Setup) —
VRChannelMenu_SaveSetup()reads the current configuration for every channel and writes it to a setup file. - L (Load Setup) —
VRChannelMenu_LoadSetup()reads a setup file and applies each value with the correspondingnaibrd_VR_Set*()call.
This is a convenience of the sample for reproducing a known configuration; it is not required to use the VR API.
Troubleshooting Reference
This table summarizes common errors and symptoms covered in the sections above. Consult your module’s manual for hardware-specific diagnostic procedures.
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
| No board found or connection timeout | Board not powered, incorrect or missing configuration file, network issue | Verify hardware is powered and connected. If default_VR_BasicOps.txt exists, check that it lists the correct interface and address; otherwise configure and save your connection in the board menu. |
| Module not detected at selected slot | No module installed at the specified slot, incorrect module number entered | Verify hardware configuration and module slot assignment. |
| No measurements / signal loss reported | Input below minimum amplitude/frequency, channel disabled, power supply off, or wrong thresholds | Enable the channel, verify the excitation power supply is on, and check minimum amplitude/frequency and threshold settings against the input signal. |
| RPM reading is incorrect | Number of teeth not set or wrong for the sensed wheel | Set NAI_VR_CONFIG_NUMBER_OF_TEETH to match the wheel. |
| Percent torque looks wrong | Zero-/max-torque phase references not configured | Set the zero- and max-torque phases, or latch the current phase with naibrd_VR_SetZeroTorqueSignalPhaseToPhaseReading(). |
| Manual thresholds have no effect | Auto-threshold is enabled | Disable NAI_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE to use manual thresholds. |
NAI_ERROR_INVALID_VALUE | Out-of-range value passed to an API call | Verify input values against your module’s manual specifications. |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — VR_BasicOps.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "boards/naibrd_gen5.h"
#include "functions/naibrd_vr.h"
#include "advanced/nai_ether_adv.h"
#include "maps/nai_map_vr.h"
#if defined (LINUX)
#include <pthread.h>
#endif
#if defined (__VXWORKS__)
#include "taskLib.h"
#endif
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 (WIN32)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params);
#elif defined (LINUX)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params);
#elif defined (__VXWORKS__)
static void VRReadingsMenu_RunDisplayReadingsThread(int * 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 (WIN32)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params);
#elif defined (LINUX)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params);
#elif defined (__VXWORKS__)
static void VRStatusMenu_RunDisplayStatusThread(int * 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,
VR_READINGSMENU_CMD_CHANGE_UPDATE_RATE,
VR_READINGSMENU_CMD_CONTINUE_POLL,
VR_READINGSMENU_CMD_STOP_POLLING,
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,
VR_STATUSMENU_CMD_CHANGE_UPDATE_RATE,
VR_STATUSMENU_CMD_CONTINUE_POLL,
VR_STATUSMENU_CMD_STOP_POLLING,
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},
{"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}
};
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},
{"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}
};
/*****************************************************************************/
/**
<summary>
The purpose of the VR_BasicOps 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.
The following system configuration routines from the nai_sys_cfg.c file are
called to assist with the configuration setup for this program prior to
calling the naibrd VR routines.
- ConfigDevice
- DisplayDeviceCfg
- GetBoardSNModCfg
- CheckModule
</summary>
*/
/*****************************************************************************/
#if defined (__VXWORKS__)
int32_t VR_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
g_ReadingsUpdateRate = 1000;
g_StatusUpdateRate = 1000;
g_stopReadingsUpdateThread = TRUE;
g_stopStatusUpdateThread = TRUE;
g_initialReadingsThreadStarted = FALSE;
g_initialStatusThreadStarted = FALSE;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
VRBasicMenu_Run(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/*****************************************************************************/
/**
<summary>
VRBasicMenu_Run illustrates the channel configuration and prepares the menu
which will handle user command requests. Returns TRUE if the user enters
the Quit Command at any point within its scope.
</summary>
*/
/*****************************************************************************/
static bool_t VRBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = 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 = FALSE;
g_initialStatusThreadStarted = FALSE;
g_stopReadingsUpdateThread = TRUE;
g_stopStatusUpdateThread = TRUE;
naiapp_utils_LoadParamMenuCommands(VR_BASICMENU_CMD_COUNT, VR_BasicOpCmds);
naiapp_display_ParamMenuCommands((int8_t*)"VR Basic Operations");
printf("\n Type command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
VR_BasicOpCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_VR_basicOps_params);
}
else
{
printf(" Invalid command entered\n");
}
}
} while (!bQuit);
return bQuit;
}
static nai_status_t VRBasicMenu_ChannelSetupMenu(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCancelCmd = FALSE;
bool_t bCmdFound = 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);
printf("\n>Please Enter Channel Setup Menu command or %c to quit (commands are listed to the left of each option, and numbers are included as commands): ", 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_CHANNELMENU_CMD_MAIN_MENU) && (cmd != VR_CHANNELMENU_CMD_UPDATE) && (cmd != VR_CHANNELMENU_CMD_SAVE_SETUP) &&
(cmd != VR_CHANNELMENU_CMD_LOAD_SETUP))
{
printf("\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 = TRUE;
printf("\nInvalid option entered\n");
}
}
else
{
bCancelCmd = TRUE;
}
}
if (cmd == VR_CHANNELMENU_CMD_MAIN_MENU)
{
bQuit = TRUE;
}
else if (cmd != VR_CHANNELMENU_CMD_UPDATE)
{
if (!bCancelCmd)
{
VR_ChannelSetupMenuCmds[cmd].func(paramCount, (int32_t*)p_VR_basicOps_params);
}
else
{
bCancelCmd = FALSE;
}
}
}
else
{
printf("Invalid command entered\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 = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt = 0;
do
{
naiapp_utils_LoadParamMenuCommands(VR_READINGSMENU_CMD_COUNT, VR_ChannelReadingsMenuCmds);
if (g_initialReadingsThreadStarted == FALSE)
{
VRReadingsMenu_StartDisplayReadingsThread(p_params);
g_initialReadingsThreadStarted = TRUE;
}
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 = TRUE;
bQuit = TRUE;
}
else
{
VR_ChannelReadingsMenuCmds[cmd].func(paramCount, p_params);
}
}
else
{
printf("Invalid command entered\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 = FALSE;
bool_t bCmdFound = 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);
printf("\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 = TRUE;
}
else
{
VR_TestMenuCmds[cmd].func(paramCount, p_params);
}
}
else
{
printf("Invalid command entered\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 = FALSE;
bool_t bCancelCmd = FALSE;
bool_t bCmdFound = 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);
if (g_initialStatusThreadStarted == FALSE)
{
VRStatusMenu_StartDisplayStatusThread(p_params);
g_initialStatusThreadStarted = TRUE;
}
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))
{
VRStatusMenu_StopPolling(paramCount, p_params);
printf("\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 = TRUE;
printf("\nInvalid option entered\n");
VRStatusMenu_ContinuePoll(paramCount, p_params);
}
}
else
{
bCancelCmd = TRUE;
VRStatusMenu_ContinuePoll(paramCount, p_params);
}
}
if (cmd == VR_STATUSMENU_CMD_MAIN_MENU)
{
g_stopStatusUpdateThread = TRUE;
bQuit = TRUE;
}
else
{
if (!bCancelCmd)
{
VR_StatusMenuCmds[cmd].func(paramCount, (int32_t*)p_VR_basicOps_params);
}
else
{
bCancelCmd = FALSE;
}
}
}
else
{
printf("Invalid command entered\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 = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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, NAI_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
}
}
else
{
printf("\nInvalid Number Of Teeth value entered\n");
}
}
else
{
if (channel == 0)
{
for (channel = 1; channel <= MAX_CHANNELS; channel++)
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_NUMBER_OF_TEETH, numberOfTeeth));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_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 = FALSE;
bool_t enableDipole = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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 = TRUE;
}
else
{
enableDipole = FALSE;
}
if (channel == 0)
{
for (channel = 1; channel <= MAX_CHANNELS; channel++)
{
check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel,
NAI_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE, enableDipole));
}
}
else
{
check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE,
enableDipole));
}
}
else
{
printf("\nInvalid Selection Entered\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRChannelMenu_SetChannelEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t enable = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if (channel == 0)
{
printf("Do you want to enable or disable all channels? (1 to enable, 0 to disable): ");
}
else
{
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 = TRUE;
}
else
{
enable = FALSE;
}
if (channel == 0)
{
for (channel = 1; channel <= MAX_CHANNELS; channel++)
{
check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE, enable));
}
}
else
{
check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE, enable));
}
}
else
{
printf("\nInvalid Selection Entered\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRChannelMenu_SetVoltageThresholdHigh(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh));
}
}
else
{
printf("\nInvalid Voltage High Threshold value entered\n");
}
}
else
{
if (channel == 0)
{
for (channel = 1; channel <= MAX_CHANNELS; channel++)
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, voltThresHigh));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_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 = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow));
}
}
else
{
printf("\nInvalid Voltage Low Threshold value entered\n");
}
}
else
{
if (channel == 0)
{
for (channel = 1; channel <= MAX_CHANNELS; channel++)
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, voltThresLow));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_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 = FALSE;
bool_t enable = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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 = TRUE;
}
else
{
enable = FALSE;
}
if (channel == 0)
{
for (channel = 1; channel <= MAX_CHANNELS; channel++)
{
check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
enable));
}
}
else
{
check_status(naibrd_VR_SetChanMappedControl(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
enable));
}
}
else
{
printf("\nInvalid Selection Entered\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRChannelMenu_SetAutoThresholdPercent(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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, NAI_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
autoThresholdPercent));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
autoThresholdPercent));
}
}
else
{
printf("\nInvalid Automatic Threshold Percent value entered\n");
}
}
else
{
if (channel == 0)
{
for (channel = 1; channel <= MAX_CHANNELS; channel++)
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_VR_CONFIG_AUTO_THRESHOLD_PERCENT,
autoThresholdPercent));
}
}
else
{
check_status(naibrd_VR_SetConfigValue(cardIndex, module, channel, NAI_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 = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Type Automatic Threshold Hysteresis Value to set ()");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS, &autoThresholdHysteresis));
if (chanNum == 1)
{
printf("%6.3f", autoThresholdHysteresis);
}
else
{
printf("%14.3f", autoThresholdHysteresis);
}
}
printf("\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 NAI_VR_AUTO_DOWN_RANGE_TIME_100MS:
sprintf(strAutoDownRangeTime, "100ms");
break;
case NAI_VR_AUTO_DOWN_RANGE_TIME_500MS:
sprintf(strAutoDownRangeTime, "500ms");
break;
case NAI_VR_AUTO_DOWN_RANGE_TIME_1S:
sprintf(strAutoDownRangeTime, "1s");
break;
case NAI_VR_AUTO_DOWN_RANGE_TIME_2S:
sprintf(strAutoDownRangeTime, "2s");
break;
case NAI_VR_AUTO_DOWN_RANGE_TIME_5S:
sprintf(strAutoDownRangeTime, "5s");
break;
case NAI_VR_AUTO_DOWN_RANGE_TIME_10S:
sprintf(strAutoDownRangeTime, "10s");
break;
case NAI_VR_AUTO_DOWN_RANGE_TIME_TYPE_ENUM_COUNT:
default:
sprintf(strAutoDownRangeTime, "Unknown");
break;
}
printf("%14s", strAutoDownRangeTime);
}
printf("\n 10 Range Select ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetRangeSelect(cardIdx, modNum, chanNum, &rangeSelect));
switch (rangeSelect)
{
case NAI_VR_RANGE_AUTO:
sprintf(strRangeSelect, "Auto");
break;
case NAI_VR_RANGE_50mV:
sprintf(strRangeSelect, "50mV");
break;
case NAI_VR_RANGE_100mV:
sprintf(strRangeSelect, "100mV");
break;
case NAI_VR_RANGE_250mV:
sprintf(strRangeSelect, "250mV");
break;
case NAI_VR_RANGE_500mV:
sprintf(strRangeSelect, "500mV");
break;
case NAI_VR_RANGE_1V:
sprintf(strRangeSelect, "1V");
break;
case NAI_VR_RANGE_2P5V:
sprintf(strRangeSelect, "2.5V");
break;
case NAI_VR_RANGE_5V:
sprintf(strRangeSelect, "5V");
break;
case NAI_VR_RANGE_12P5V:
sprintf(strRangeSelect, "12.5V");
break;
case NAI_VR_RANGE_25V:
sprintf(strRangeSelect, "25V");
break;
case NAI_VR_RANGE_50V:
sprintf(strRangeSelect, "50V");
break;
case NAI_VR_RANGE_100V:
sprintf(strRangeSelect, "100V");
break;
default:
sprintf(strRangeSelect, "Unknown");
break;
}
printf("%14s", strRangeSelect);
}
printf("\n 11 Polarity Select ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE,
&polaritySelect));
switch (polaritySelect)
{
case TRUE:
sprintf(strPolaritySelect, "Falling");
break;
case FALSE:
sprintf(strPolaritySelect, "Rising");
break;
default:
sprintf(strPolaritySelect, "Unknown");
break;
}
printf("%14s", strPolaritySelect);
}
printf("\n 12 AC Couple Enable ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE, &acCoupleEnable));
switch (acCoupleEnable)
{
case TRUE:
sprintf(strACCoupleEnable, "On");
break;
case FALSE:
sprintf(strACCoupleEnable, "Off");
break;
default:
sprintf(strACCoupleEnable, "Unknown");
break;
}
printf("%14s", strACCoupleEnable);
}
printf("\n 13 Termination Enable ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE,
&terminationEnable));
switch (terminationEnable)
{
case TRUE:
sprintf(strTerminationEnable, "On");
break;
case FALSE:
sprintf(strTerminationEnable, "Off");
break;
default:
sprintf(strTerminationEnable, "Unknown");
break;
}
printf("%14s", strTerminationEnable);
}
printf("\n 14 Averaging Time ( Sec )");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_AVERAGING_TIME, &averagingTime));
if (chanNum == 1)
{
printf("%13.3f", averagingTime);
}
else
{
printf("%14.3f", averagingTime);
}
}
printf("\n 15 Zero Torque Sig Phase");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE, &zeroTorqueSigPhase));
printf("%14.3f", zeroTorqueSigPhase);
}
printf("\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 TRUE:
sprintf(strSetZeroTorqueSigPhase, "Set");
break;
case FALSE:
sprintf(strSetZeroTorqueSigPhase, "Unset");
break;
default:
sprintf(strSetZeroTorqueSigPhase, "Unknown");
break;
}
if (chanNum == 1)
{
printf("%10s", strSetZeroTorqueSigPhase);
}
else
{
printf("%14s", strSetZeroTorqueSigPhase);
}
}
printf("\n 17 Max Torque Sig Phase ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE, &maxTorqueSigPhase));
printf("%14.3f", maxTorqueSigPhase);
}
printf("\n 18 Debounce Time ( Sec )");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_DEBOUNCE_TIME, &debounceTime));
printf("%14.2E", debounceTime);
}
printf("\n 19 Minimum Amplitude ( V )");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_MINIMUM_AMPLITUDE, &minAmplitude));
if (chanNum == 1)
{
printf("%12.3f", minAmplitude);
}
else
{
printf("%14.3f", minAmplitude);
}
}
printf("\n 20 Minimum Frequency ( Hz )");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_MINIMUM_FREQUENCY, &minFreq));
if (chanNum == 1)
{
printf("%11.3f", minFreq);
}
else
{
printf("%14.3f", minFreq);
}
}
printf("\n R Reset Cycle Count");
printf("\n\n MM Return to Main Menu");
printf("\n UD Update");
printf("\n S Save Setup");
printf("\n L Load Setup\n");
}
static nai_status_t VRChannelMenu_SaveSetup(int32_t paramCount, int32_t* p_params)
{
FILE* fp;
bool_t bQuit = 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 = FALSE;
bool_t channelEnable = FALSE;
float64_t voltThresHi = 0.0;
float64_t voltThresLo = 0.0;
bool_t autoThresholdEnable = FALSE;
float64_t autoThresholdPercent = 0.0;
float64_t autoThresholdHysteresis = 0.0;
nai_vr_auto_down_range_time_type_t autoDownRangeTime = NAI_VR_AUTO_DOWN_RANGE_TIME_100MS;
nai_vr_range_select_type_t range = NAI_VR_RANGE_AUTO;
bool_t polaritySelect = FALSE;
bool_t acCoupleEnable = FALSE;
bool_t terminationEnable = 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_BasicOps_Setup.txt";
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Note: Relative paths are relative to the program running directory.\n");
printf("Type path of file to save setup to (default: ./VR_BasicOps_Setup.txt): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
filename = (char*)inputBuffer;
}
fp = fopen((const char*)filename, "w");
if (!fp)
{
perror(filename);
printf("\nFile path invalid!\n");
}
else
{
fprintf(fp, "Number of Teeth: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_NUMBER_OF_TEETH, &numberOfTeeth));
fprintf(fp, "%d,", (int32_t)(numberOfTeeth + 0.5));
}
fprintf(fp, "\n[Monopole/Dipole: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_DIPOLE_ENABLE,
&monopoleDipole));
fprintf(fp, "%u,", monopoleDipole);
}
fprintf(fp, "\n[Channel Enable: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_CHANNEL_ENABLE, &channelEnable));
fprintf(fp, "%u,", channelEnable);
}
fprintf(fp, "\n[Voltage Threshold High: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_HIGH, &voltThresHi));
fprintf(fp, "%f,", voltThresHi);
}
fprintf(fp, "\n[Voltage Threshold Low: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_VOLTAGE_THRESHOLD_LOW, &voltThresLo));
fprintf(fp, "%f,", voltThresLo);
}
fprintf(fp, "\n[Auto Threshold Enable: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_AUTO_THRESHOLD_ENABLE,
&autoThresholdEnable));
fprintf(fp, "%u,", autoThresholdEnable);
}
fprintf(fp, "\n[Auto Threshold Percent: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_AUTO_THRESHOLD_PERCENT, &autoThresholdPercent));
fprintf(fp, "%f,", autoThresholdPercent);
}
fprintf(fp, "\n[Auto Threshold Hysteresis: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_AUTO_THRESHOLD_HYSTERESIS, &autoThresholdHysteresis));
fprintf(fp, "%f,", autoThresholdHysteresis);
}
fprintf(fp, "\n[Auto Down-Range Time: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetAutoDownRangeTime(cardIdx, modNum, chanNum, &autoDownRangeTime));
fprintf(fp, "%u,", autoDownRangeTime);
}
fprintf(fp, "\n[Range Select: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetRangeSelect(cardIdx, modNum, chanNum, &range));
fprintf(fp, "%u,", range);
}
fprintf(fp, "\n[Polarity Select: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_FALLING_EDGE_MEASUREMENT_ENABLE,
&polaritySelect));
fprintf(fp, "%u,", polaritySelect);
}
fprintf(fp, "\n[AC Couple Enable: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_AC_COUPLE_ENABLE, &acCoupleEnable));
fprintf(fp, "%u,", acCoupleEnable);
}
fprintf(fp, "\n[Termination Enable: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetChanMappedControl(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_CONTROL_TERMINATION_ENABLE,
&terminationEnable));
fprintf(fp, "%u,", terminationEnable);
}
fprintf(fp, "\n[Averaging Time: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_AVERAGING_TIME, &averagingTime));
fprintf(fp, "%f,", averagingTime);
}
fprintf(fp, "\n[Zero Torque Sig Phase: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE, &zeroTorqueSigPhase));
fprintf(fp, "%f,", zeroTorqueSigPhase);
}
fprintf(fp, "\n[Max Torque Sig Phase: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_MAX_TORQUE_SIGNAL_PHASE, &maxTorqueSigPhase));
fprintf(fp, "%f,", maxTorqueSigPhase);
}
fprintf(fp, "\n[Debounce Time: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_DEBOUNCE_TIME, &debounceTime));
fprintf(fp, "%14.9f,", debounceTime);
}
fprintf(fp, "\n[Minimum Amplitude: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_MINIMUM_AMPLITUDE, &minAmplitude));
fprintf(fp, "%f,", minAmplitude);
}
fprintf(fp, "\n[Minimum Frequency: ");
for (chanNum = 1; chanNum <= MAX_CHANNELS; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_MINIMUM_FREQUENCY, &minFreq));
fprintf(fp, "%f,", minFreq);
}
fclose(fp);
printf("\nSetup Saved\n");
}
}
return NAI_SUCCESS;
}
static nai_status_t VRChannelMenu_LoadSetup(int32_t paramCount, int32_t* p_params)
{
FILE* fp;
bool_t bQuit = 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 = FALSE;
bool_t channelEnable = FALSE;
float64_t voltThresHi = 0.0;
float64_t voltThresLo = 0.0;
bool_t autoThresholdEnable = FALSE;
float64_t autoThresholdPercent = 0.0;
float64_t autoThresholdHysteresis = 0.0;
nai_vr_auto_down_range_time_type_t autoDownRangeTime = NAI_VR_AUTO_DOWN_RANGE_TIME_100MS;
nai_vr_range_select_type_t range = NAI_VR_RANGE_AUTO;
bool_t polaritySelect = FALSE;
bool_t acCoupleEnable = FALSE;
bool_t terminationEnable = 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_BasicOps_Setup.txt";
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Note: Relative paths are relative to the program running directory.\n");
printf("Type path of file to load setup from (default: ./VR_BasicOps_Setup.txt): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
filename = (char*)inputBuffer;
}
fp = fopen((const char*)filename, "r");
if (!fp)
{
perror(filename);
printf("\nSetup file not found! Please save a setup first before loading.\n");
}
else
{
fseek(fp, 0L, SEEK_END);
lSize = ftell(fp);
rewind(fp);
buffer = (char*)calloc(1, lSize + 1);
if (!buffer)
{
printf("\nFailed to allocate memory for loading setup\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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_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 = (nai_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 = (nai_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,
NAI_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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_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, NAI_VR_CONFIG_MINIMUM_FREQUENCY, minFreq));
}
}
printf("\nSetup Loaded\n");
free(buffer);
}
fclose(fp);
}
}
return NAI_SUCCESS;
}
static void VRReadingsMenu_StartDisplayReadingsThread(int32_t* p_params)
{
#if defined (LINUX)
pthread_t thread1;
#endif
g_stopReadingsUpdateThread = FALSE;
#if defined (WIN32)
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)VRReadingsMenu_RunDisplayReadingsThread, (void*)p_params, 0, 0);
#elif defined (LINUX)
pthread_create(&thread1, 0, (void *)&VRReadingsMenu_RunDisplayReadingsThread, (void*)p_params);
#elif defined (__VXWORKS__)
taskSpawn("MonitorRxBuffer", 99, 0, 0x4000, (FUNCPTR)VRReadingsMenu_RunDisplayReadingsThread, (int32_t *)p_params, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#else
#error Implementation Required.
#endif
}
#if defined (WIN32)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params)
{
int32_t* p_params_int = (int32_t*)p_params;
while (g_stopReadingsUpdateThread == FALSE)
{
system("cls");
VRReadingsMenu_DisplayChannelReadings(p_params_int);
nai_msDelay(g_ReadingsUpdateRate);
}
}
#elif defined (LINUX)
static void VRReadingsMenu_RunDisplayReadingsThread(void* p_params)
{
int32_t* p_params_int = (int32_t*)p_params;
while (g_stopReadingsUpdateThread == FALSE)
{
printf("\033[H\033[J");
VRReadingsMenu_DisplayChannelReadings(p_params_int);
nai_msDelay(g_ReadingsUpdateRate);
}
}
#elif defined (__VXWORKS__)
static void VRReadingsMenu_RunDisplayReadingsThread(int32_t* p_params)
{
int32_t* p_params_int = (int32_t*)p_params;
while (g_stopReadingsUpdateThread == FALSE)
{
printf("\033[H\033[J");
VRReadingsMenu_DisplayChannelReadings(p_params_int);
nai_msDelay(g_ReadingsUpdateRate);
}
}
#else
#error Implementation Required.
#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;
printf("\n Readings Group Menu Ch 1 Ch 2 Ch 3 Ch 4 Ch 5 Ch 6 ");
printf("Ch 7 Ch 8\n\n");
printf(" Amplitude ( V ) ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAI_VR_MEASURED_AMPLITUDE, &litudeMeas));
printf("%14.3f", amplitudeMeas);
}
printf("\n Frequency ( Hz ) ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAI_VR_MEASURED_FREQUENCY, &freqMeas));
printf("%14.3f", freqMeas);
}
printf("\n RPM ( RPM ) ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAI_VR_MEASURED_RPM, &rpmMeas));
printf("%14.3f", rpmMeas);
}
printf("\n Period ( Sec ) ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAI_VR_MEASURED_PERIOD, &periodMeas));
printf("%14.2E", periodMeas);
}
printf("\n Phase ( Deg ) ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAI_VR_MEASURED_PHASE, &(phaseMeas[chanNum - 1])));
printf("%14.3f", phaseMeas[chanNum - 1]);
}
printf("\n Phase Delta ( Deg ) ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetConfigValue(cardIdx, modNum, chanNum, NAI_VR_CONFIG_ZERO_TORQUE_SIGNAL_PHASE, &zeroTorqueSigPhase));
/* phase delta = NAI_VR_MEASURED_PHASE - trigger phase */
phaseDelta = phaseMeas[chanNum - 1] - zeroTorqueSigPhase;
printf("%14.3f", phaseDelta);
}
printf("\n Percent Torque ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAI_VR_MEASURED_PERCENT_TORQUE, &percentTorqueMeas));
printf("%14.3f", percentTorqueMeas);
}
printf("\n Cycle Count ");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetMeasurement(cardIdx, modNum, chanNum, NAI_VR_MEASURED_CYCLE_COUNT, &cycleCount));
if (cycleCount > 9999999999.0)
{
printf("%14.5E", cycleCount);
}
else
{
printf("%14u", (uint32_t)(cycleCount + 0.5));
}
}
printf("\n\nMM Return to Main Menu");
printf("\nR Change Update Rate in milliSeconds [default:1000mS]");
printf("\nC Continue Poll");
printf("\nS Stop Polling\n");
printf("\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 = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
long updateRateToSet = 0l;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
VRReadingsMenu_StopPolling(paramCount, p_params);
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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
if (g_stopReadingsUpdateThread == TRUE)
{
VRReadingsMenu_StartDisplayReadingsThread(p_params);
}
return NAI_SUCCESS;
}
static nai_status_t VRReadingsMenu_StopPolling(int32_t paramCount, int32_t* p_params)
{
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
g_stopReadingsUpdateThread = TRUE;
printf("\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 = FALSE;
bool_t powerSupplyEnabled = FALSE;
bool_t floatingPointModeEnabled = FALSE;
char strIBitTestEnabled[10] = "";
char strPowerSupplyEnabled[10] = "";
char strFloatingPointModeEnabled[10] = "";
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n Test Group Menu\n\n");
check_status(naibrd_VR_GetModuleBITEnable(cardIdx, modNum, NAI_VR_TEST_ENABLE_IBIT_D3, &iBitTestEnabled));
switch (iBitTestEnabled)
{
case TRUE:
sprintf(strIBitTestEnabled, "Enabled");
break;
case FALSE:
sprintf(strIBitTestEnabled, "Disabled");
break;
default:
sprintf(strIBitTestEnabled, "Unknown");
break;
}
printf("IBIT (D3) Test State: %s\n", strIBitTestEnabled);
check_status(naibrd_VR_GetPowerSupplyEnable(cardIdx, modNum, &powerSupplyEnabled));
switch (powerSupplyEnabled)
{
case TRUE:
sprintf(strPowerSupplyEnabled, "Enabled");
break;
case FALSE:
sprintf(strPowerSupplyEnabled, "Disabled");
break;
default:
sprintf(strPowerSupplyEnabled, "Unknown");
break;
}
printf("Power Supply State: %s\n", strPowerSupplyEnabled);
check_status(naibrd_GetRunningInFloatingPointMode(cardIdx, modNum, &floatingPointModeEnabled));
switch (floatingPointModeEnabled)
{
case TRUE:
sprintf(strFloatingPointModeEnabled, "Enabled");
break;
case FALSE:
sprintf(strFloatingPointModeEnabled, "Disabled");
break;
default:
sprintf(strFloatingPointModeEnabled, "Unknown");
break;
}
printf("Floating-Point Mode State: %s\n\n", strFloatingPointModeEnabled);
printf("MM Return to Main Menu\n");
printf("TE Test Enable (IBIT)\n");
printf("PS Power Supply Enable\n");
printf("FE Floating-Point Enable\n");
}
static nai_status_t VRTestMenu_SetTestEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t enable = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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 = TRUE;
}
else
{
enable = FALSE;
}
check_status(naibrd_VR_SetModuleBITEnable(cardIndex, module, NAI_VR_TEST_ENABLE_IBIT_D3, enable));
}
else
{
printf("\nInvalid Selection Entered\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRTestMenu_SetPowerSupplyEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t enable = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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 = TRUE;
}
else
{
enable = FALSE;
}
check_status(naibrd_VR_SetPowerSupplyEnable(cardIndex, module, enable));
}
else
{
printf("\nInvalid Selection Entered\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRTestMenu_SetFloatingPointEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t enable = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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 = TRUE;
}
else
{
enable = FALSE;
}
check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, enable));
}
else
{
printf("\nInvalid Selection Entered\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static void VRStatusMenu_StartDisplayStatusThread(int32_t* p_params)
{
#if defined (LINUX)
pthread_t thread1;
#endif
g_stopStatusUpdateThread = FALSE;
#if defined (WIN32)
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)VRStatusMenu_RunDisplayStatusThread, (void*)p_params, 0, 0);
#elif defined (LINUX)
pthread_create(&thread1, 0, (void *)&VRStatusMenu_RunDisplayStatusThread, (void*)p_params);
#elif defined (__VXWORKS__)
taskSpawn("VRStatusMenu_RunDisplayStatusThread", 99, 0, 0x4000, (FUNCPTR)VRStatusMenu_RunDisplayStatusThread,
(int32_t*)p_params, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#else
#error Implementation Required.
#endif
}
#if defined (WIN32)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params)
{
int32_t* p_params_int = (int32_t*)p_params;
while (g_stopStatusUpdateThread == FALSE)
{
system("cls");
VRStatusMenu_DisplayStatuses(p_params_int);
nai_msDelay(g_StatusUpdateRate);
}
}
#elif defined (LINUX)
static void VRStatusMenu_RunDisplayStatusThread(void* p_params)
{
int32_t* p_params_int = (int32_t*)p_params;
while (g_stopStatusUpdateThread == FALSE)
{
printf("\033[H\033[J");
VRStatusMenu_DisplayStatuses(p_params_int);
nai_msDelay(g_StatusUpdateRate);
}
}
#elif defined (__VXWORKS__)
static void VRStatusMenu_RunDisplayStatusThread(int32_t* p_params)
{
int32_t* p_params_int = (int32_t*)p_params;
while (g_stopStatusUpdateThread == FALSE)
{
printf("\033[H\033[J");
VRStatusMenu_DisplayStatuses(p_params_int);
nai_msDelay(g_StatusUpdateRate);
}
}
#else
#error Implementation Required.
#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 = FALSE;
char strChanStatusEnable[10] = "";
printf("\n Status Monitoring Group Menu\n\n");
printf(" Chan Chan Status BIT Termination Fault Signal Loss Summary\n");
printf(" Enable (R/L) (R/L) (R/L) (R/L)\n");
printf("=========================================================================\n");
for (chanNum = 1; chanNum <= maxChannel; chanNum++)
{
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitLatchedStatus));
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_BIT_REALTIME, &bitRealtimeStatus));
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_LATCHED, &terminationLatchedStatus));
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_REALTIME, &terminationRealtimeStatus));
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_LATCHED, &signalLossLatchedStatus));
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_REALTIME, &signalLossRealtimeStatus));
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED, &summaryLatchedStatus));
check_status(naibrd_VR_GetChanMappedStatus(cardIdx, modNum, chanNum, NAI_VR_CHAN_MAPPED_STATUS_SUMMARY_REALTIME, &summaryRealtimeStatus));
check_status(naibrd_VR_GetChanStatusEnable(cardIdx, modNum, chanNum, &chanStatusEnable));
switch (chanStatusEnable)
{
case TRUE:
sprintf(strChanStatusEnable, " Enabled");
break;
case FALSE:
sprintf(strChanStatusEnable, "Disabled");
break;
default:
sprintf(strChanStatusEnable, " Unknown");
break;
}
printf(" %2d %8s (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d)\n", chanNum, strChanStatusEnable,
bitRealtimeStatus, bitLatchedStatus, terminationRealtimeStatus, terminationLatchedStatus, signalLossRealtimeStatus,
signalLossLatchedStatus, summaryRealtimeStatus, summaryLatchedStatus);
}
printf("\nMM Return to Main Menu");
printf("\nE Channel Status Enable");
printf("\nC Clear Status");
printf("\nR Change Update Rate in milliSeconds [default:1000mS]");
printf("\nP Continue Poll");
printf("\nS Stop Polling");
printf("\n\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 = FALSE;
bool_t enable = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if (channel == 0)
{
printf("Do you want to enable or disable status reporting for all channels? (1 to enable, 0 to disable): ");
}
else
{
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 = TRUE;
}
else
{
enable = 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
{
printf("\nInvalid Selection Entered\n");
}
}
VRStatusMenu_ContinuePoll(paramCount, p_params);
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRStatusMenu_ClearStatus(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = 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 (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
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, NAI_VR_CHAN_MAPPED_STATUS_BIT_LATCHED));
break;
case '1':
check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel,
NAI_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_LATCHED));
break;
case '2':
check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_LATCHED));
break;
case '3':
check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED));
break;
default:
printf("\nInvalid Selection Entered\n");
break;
}
}
}
else
{
switch (inputBuffer[0])
{
case '0':
check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_BIT_LATCHED));
break;
case '1':
check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel,
NAI_VR_CHAN_MAPPED_STATUS_TERMINATION_FAULT_LATCHED));
break;
case '2':
check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SIGNAL_LOSS_LATCHED));
break;
case '3':
check_status(naibrd_VR_ClearChanMappedStatus(cardIndex, module, channel, NAI_VR_CHAN_MAPPED_STATUS_SUMMARY_LATCHED));
break;
default:
printf("\nInvalid Selection Entered\n");
break;
}
}
}
VRStatusMenu_ContinuePoll(paramCount, p_params);
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRStatusMenu_ChangeUpdateRate(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
long updateRateToSet = 0l;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
VRStatusMenu_StopPolling(paramCount, p_params);
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;
}
}
VRStatusMenu_ContinuePoll(paramCount, p_params);
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t VRStatusMenu_ContinuePoll(int32_t paramCount, int32_t* p_params)
{
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
if (g_stopStatusUpdateThread == TRUE)
{
VRStatusMenu_StartDisplayStatusThread(p_params);
}
return NAI_SUCCESS;
}
static nai_status_t VRStatusMenu_StopPolling(int32_t paramCount, int32_t* p_params)
{
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
g_stopStatusUpdateThread = TRUE;
printf("\n\n>Please Enter Status Menu command or %c to quit : ", NAI_QUIT_CHAR);
return NAI_SUCCESS;
}