Integrator Resources

The official home for NAI Support

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

Toggle Components with Visual Button
JavaScript Form Processing

SG BasicOpsMenu

SG BasicOpsMenu

Explanation

About the Code

This application code is provided by North Atlantic Industries and is designed to interact with their embedded function modules using their Strain Gage (SG) module libraries. The code primarily focuses on configuring and operating SG modules, including setting parameters, reading data, and performing calibrations.

Code Walkthrough

Includes The code begins by including the necessary headers for standard C libraries, NAI application utilities, and SG-specific functionalities:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
#include "nai_sg_utils.h"
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_sg.h"
#include "advanced/nai_ether_adv.h"

Constants and Prototypes Key constants and function prototypes are defined next:

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

static nai_status_t Run_SG_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);
static nai_status_t Handle_SG_Configuration(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StandardOperation(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ToggleHexModeOps(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ToggleHexModeConfig(int32_t paramCount, int32_t* p_params);

Enumerations Enumerations for various commands associated with SG basic operations, configurations, and standard operations are defined:

enum sg_basicops_commands {
   SG_BASICOP_CMD_CONFIG,
   SG_BASICOP_CMD_STANDARDOPS,
   SG_BASICOP_CMD_COUNT
};

Command Tables Commands are defined along with their descriptions and corresponding handler functions:

naiapp_cmdtbl_params_t SG_BasicOpMenuCmds[] = {
   {"CFG", "SG Configuration Functions", SG_BASICOP_CMD_CONFIG, Handle_SG_Configuration},
   {"OPS", "SG Standard Operation Functions", SG_BASICOP_CMD_STANDARDOPS, Handle_SG_StandardOperation},
};

// Similarly other command tables are defined

Main Function The main function initializes the basic SG operations interface and drives the application’s core logic:

#if defined (__VXWORKS__)
int32_t SG_BasicOps(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   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)
               {
                  Run_SG_BasicOps(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 NAI_SUCCESS;
}

Run SG Basic Operations Runs basic operations for SG modules based on user input:

static nai_status_t Run_SG_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   naiapp_AppParameters_t sg_basicops_params;
   p_naiapp_AppParameters_t p_sg_basicops_params = &sg_basicops_params;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_sg_basicops_params->cardIndex = cardIndex;
   p_sg_basicops_params->module = module;
   p_sg_basicops_params->channel = 0;
   p_sg_basicops_params->maxChannels = naibrd_SG_GetChannelCount(modid);

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands(SG_BASICOP_CMD_COUNT, SG_BasicOpMenuCmds);
      naiapp_display_ParamMenuCommands((int8_t *)"SG Basic Operation Menu");
      printf("\nType SG command or %c to quit : main >", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
            if (bCmdFound)
            {
               switch (cmd)
               {
                  case SG_BASICOP_CMD_CONFIG:
                  case SG_BASICOP_CMD_STANDARDOPS:
                     SG_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_sg_basicops_params);
                     break;
                  default:
                     printf("Invalid command entered\n");
                     break;
               }
            }
            else
               printf("Invalid command entered\n");
         }
      }
      else
         bContinue = FALSE;
   }
   return bQuit;
}

Handle Configuration Handles the configuration of SG modules:

static nai_status_t Handle_SG_Configuration(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   p_naiapp_AppParameters_t p_sg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sg_params->cardIndex;
   int32_t module = p_sg_params->module;
   int32_t maxChannels = p_sg_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   ...
}

The rest of the code follows a similar pattern for handling different configurations, queries, and standard operations.

Conclusion

This code provides a comprehensive interface for configuring and operating North Atlantic Industries' SG modules. Users interact with the application via a console menu, which guides them through various operations such as configuring module settings, reading data, and performing calibrations. The main goal of this application is to simplify the process of interfacing with SG modules and to demonstrate the functionalities provided by North Atlantic Industries' libraries.

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

/* Common SG Sample Program include files */
#include "nai_sg_utils.h"

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

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

/* Function prototypes */
static nai_status_t Run_SG_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);

static nai_status_t Handle_SG_Configuration(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StandardOperation(int32_t paramCount, int32_t* p_params);

static nai_status_t Handle_SG_ToggleHexModeOps(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ToggleHexModeConfig(int32_t paramCount, int32_t* p_params);

static nai_status_t Display_SG_ChannelCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_GainRange(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ExcitationMode(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_Excitation(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_BridgeSensitivity(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_SensorFS(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_RemoteDriveSense(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_Calibration(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_BridgeConfig(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_NominalRes(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_GaugeFactor(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_PoissonRatio(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_LeadRes(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_SampleRate(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlarmLo(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlertLo(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlertHi(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlarmHi(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ImbalanceOffset(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_BridgeComp(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_PGAGain(int32_t paramCount, int32_t* p_params);

static nai_status_t Display_SG_StandardOpOptions(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_ForceTable(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_RangeScaledTable(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_UnscaledTable(int32_t paramCount, int32_t* p_params);

static nai_status_t Display_SG_StandardOpsData(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ResetMinMaxStrain(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ClearStatus(int32_t paramCount, int32_t* p_params);

static nai_status_t Display_SG_CalibrationData(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_CalibrationInterval(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_CalibrationType(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_HelpMessage(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_RunOneTimeCal(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_CalChans(int32_t paramCount, int32_t* p_params);

static const int32_t DEF_SG_CHANNEL = 1;

static nai_status_t g_DisplayHex = FALSE;

/****** Command Table *******/
enum sg_basicops_commands
{
   SG_BASICOP_CMD_CONFIG,
   SG_BASICOP_CMD_STANDARDOPS,
   SG_BASICOP_CMD_COUNT
};

enum sg_config_commands
{
   SG_CONFIG_CMD_READ,
   SG_CONFIG_CMD_GAIN_RANGE,
   SG_CONFIG_CMD_EXCITATION_MODE,
   SG_CONFIG_CMD_EXCITATION,
   SG_CONFIG_CMD_BRIDGE_SENSITIVITY,
   SG_CONFIG_CMD_SENSOR_FS,
   SG_CONFIG_CMD_REMOTE_DRIVE_SENSE,
   SG_CONFIG_CMD_CALIBRATION,
   SG_CONFIG_CMD_COUNT
};

enum sg_gen5_config_commands
{
   SG_GEN5_CONFIG_CMD_READ,
   SG_GEN5_CONFIG_CMD_EXCITATION,
   SG_GEN5_CONFIG_CMD_BRIDGE_CONFIG,
   SG_GEN5_CONFIG_CMD_PGA_GAIN,
   SG_GEN5_CONFIG_CMD_REMOTE_SENSE,
   SG_GEN5_CONFIG_CMD_NOMINAL_RES,
   SG_GEN5_CONFIG_CMD_GAUGE_FACTOR,
   SG_GEN5_CONFIG_CMD_POISSON_RATIO,
   SG_GEN5_CONFIG_CMD_LEAD_RES,
   SG_GEN5_CONFIG_CMD_SAMPLE_RATE,
   SG_GEN5_CONFIG_CMD_STRAIN_ALARM_LO,
   SG_GEN5_CONFIG_CMD_STRAIN_ALERT_LO,
   SG_GEN5_CONFIG_CMD_STRAIN_ALERT_HI,
   SG_GEN5_CONFIG_CMD_STRAIN_ALARM_HI,
   SG_GEN5_CONFIG_CMD_IMBALANCE_OFFSET,
   SG_GEN5_CONFIG_CMD_INTERNAL_BRIDGE_COMPLETION,
   SG_GEN5_CONFIG_CMD_TOGGLE_HEX_MODE,
   SG_GEN5_CONFIG_CMD_COUNT
};

enum sg_standard_operations_commands
{
   SG_STANDARD_OPERATIONS_CMD_FORCE,
   SG_STANDARD_OPERATIONS_CMD_RANGE_SCALED,
   SG_STANDARD_OPERATIONS_CMD_UNSCALED,
   SG_STANDARD_OPERATIONS_CMD_COUNT
};

enum sg_gen5_standard_operations_commands
{
   SG_GEN5_STANDARD_OPERATIONS_CMD_READ_DATA,
   SG_GEN5_STANDARD_OPERATIONS_CMD_RESET_MIN_MAX_STRAIN,
   SG_GEN5_STANDARD_OPERATIONS_CMD_CLEAR_STATUS,
   SG_GEN5_STANDARD_OPERATIONS_CMD_TOGGLE_HEX_MODE,
   SG_GEN5_STANDARD_OPERATIONS_CMD_COUNT
};

enum sg_calibration_commands
{
   SG_CALIBRATION_CMD_READ,
   SG_CALIBRATION_CMD_INTERVAL,
   SG_CALIBRATION_CMD_TYPE,
   SG_CALIBRATION_CMD_HELP,
   SG_CALIBRATION_CMD_RUN_ONE_TIME_CAL,
   SG_CALIBRATION_CMD_CAL_CHANNEL,
   SG_CALIBRATION_CMD_COUNT
};

/****** Command Tables *******/
naiapp_cmdtbl_params_t SG_BasicOpMenuCmds[] = {
   {"CFG", "SG Configuration Functions",                  SG_BASICOP_CMD_CONFIG,              Handle_SG_Configuration},
   {"OPS", "SG Standard Operation Functions",             SG_BASICOP_CMD_STANDARDOPS,         Handle_SG_StandardOperation},
};

naiapp_cmdtbl_params_t SG_ConfigMenuCmds[] = {
   {"GET                ", "Retrieve Configuration",            SG_CONFIG_CMD_READ,                     Display_SG_ChannelCfg},
   {"RANGE              ", "Set Gain Range",                    SG_CONFIG_CMD_GAIN_RANGE,               Handle_SG_GainRange},
   {"MODE, EXCITATION   ", "Set Excitation Mode",               SG_CONFIG_CMD_EXCITATION_MODE,          Handle_SG_ExcitationMode},
   {"VOLTAGE, EXCITATION", "Set Excitation",                    SG_CONFIG_CMD_EXCITATION,               Handle_SG_Excitation},
   {"BRIDGE SENSITIVITY ", "Set Bridge Sensitivity",            SG_CONFIG_CMD_BRIDGE_SENSITIVITY,       Handle_SG_BridgeSensitivity},
   {"SENSOR             ", "Set Sensor FS",                     SG_CONFIG_CMD_SENSOR_FS,                Handle_SG_SensorFS},
   {"REMOTE DRIVE SENSE ", "Set Remote Drive Sense",            SG_CONFIG_CMD_REMOTE_DRIVE_SENSE,       Handle_SG_RemoteDriveSense},
   {"CALIBRATION        ", "Configure Calibration Options",     SG_CONFIG_CMD_CALIBRATION,              Handle_SG_Calibration}
};

naiapp_cmdtbl_params_t SG_Gen5_ConfigMenuCmds[] = {
   {"READ       ", "Retrieve Configuration",                    SG_GEN5_CONFIG_CMD_READ,                       Display_SG_ChannelCfg},
   {"EXCITATION ", "Set Excitation Voltage",                    SG_GEN5_CONFIG_CMD_EXCITATION,                 Handle_SG_Excitation},
   {"BRIDGE     ", "Set Bridge Configuration",                  SG_GEN5_CONFIG_CMD_BRIDGE_CONFIG,              Handle_SG_BridgeConfig},
   {"GAIN       ", "Set PGA Gain",                              SG_GEN5_CONFIG_CMD_PGA_GAIN,                   Handle_SG_PGAGain},
   {"SENSE      ", "Set Remote Sense Mode",                     SG_GEN5_CONFIG_CMD_REMOTE_SENSE,               Handle_SG_RemoteDriveSense},
   {"NOMINAL RES", "Set Nominal Resistance",                    SG_GEN5_CONFIG_CMD_NOMINAL_RES,                Handle_SG_NominalRes},
   {"FACTOR     ", "Set Gauge Factor",                          SG_GEN5_CONFIG_CMD_GAUGE_FACTOR,               Handle_SG_GaugeFactor},
   {"POISSON    ", "Set Poisson Ratio",                         SG_GEN5_CONFIG_CMD_POISSON_RATIO,              Handle_SG_PoissonRatio},
   {"LEAD RES   ", "Set Lead Resistance",                       SG_GEN5_CONFIG_CMD_LEAD_RES,                   Handle_SG_LeadRes},
   {"RATE       ", "Set Sample Rate",                           SG_GEN5_CONFIG_CMD_SAMPLE_RATE,                Handle_SG_SampleRate},
   {"MIN THRESH ", "Set Strain Alarm Lo Threshold",             SG_GEN5_CONFIG_CMD_STRAIN_ALARM_LO,            Handle_SG_StrainAlarmLo},
   {"LOW THRESH ", "Set Strain Alert Lo Threshold",             SG_GEN5_CONFIG_CMD_STRAIN_ALERT_LO,            Handle_SG_StrainAlertLo},
   {"HIGH THRESH", "Set Strain Alert Hi Threshold",             SG_GEN5_CONFIG_CMD_STRAIN_ALERT_HI,            Handle_SG_StrainAlertHi},
   {"MAX THRESH ", "Set Strain Alarm Hi Threshold",             SG_GEN5_CONFIG_CMD_STRAIN_ALARM_HI,            Handle_SG_StrainAlarmHi},
   {"IMBALANCE  ", "Set Imbalance Offset",                      SG_GEN5_CONFIG_CMD_IMBALANCE_OFFSET,           Handle_SG_ImbalanceOffset},
   {"COMPLETION ", "Enable/Disable Internal Bridge Completion", SG_GEN5_CONFIG_CMD_INTERNAL_BRIDGE_COMPLETION, Handle_SG_BridgeComp},
   {"TOGGLE HEX ", "Enable/Disable Raw Hex Mode",               SG_GEN5_CONFIG_CMD_TOGGLE_HEX_MODE,            Handle_SG_ToggleHexModeConfig}
};

naiapp_cmdtbl_params_t SG_StandardOperationMenuCmds[] = {
   {"FORCE       ", "Show Force Display Table",                   SG_STANDARD_OPERATIONS_CMD_FORCE,            Display_SG_ForceTable},
   {"RANGE SCALED", "Show Range Scaled Display Table",            SG_STANDARD_OPERATIONS_CMD_RANGE_SCALED,     Display_SG_RangeScaledTable},
   {"UNSCALED    ", "Show Unscaled Display Table",                SG_STANDARD_OPERATIONS_CMD_UNSCALED,         Display_SG_UnscaledTable}
};

naiapp_cmdtbl_params_t SG_Gen5_StandardOperationMenuCmds[] = {
   {"GET  ", "Retrieve Data",               SG_GEN5_STANDARD_OPERATIONS_CMD_READ_DATA,            Display_SG_StandardOpsData},
   {"RESET", "Reset Min and Max Strain",    SG_GEN5_STANDARD_OPERATIONS_CMD_RESET_MIN_MAX_STRAIN, Handle_SG_ResetMinMaxStrain},
   {"CLEAR", "Clear Statuses",              SG_GEN5_STANDARD_OPERATIONS_CMD_CLEAR_STATUS,         Handle_SG_ClearStatus},
   {"HEX  ", "Enable/Disable Raw Hex Mode", SG_GEN5_STANDARD_OPERATIONS_CMD_TOGGLE_HEX_MODE,      Handle_SG_ToggleHexModeOps}
};

naiapp_cmdtbl_params_t SG_CalibrationMenuCmds[] = {
   {"GET         ", "Retrieve Calibration Options",           SG_CALIBRATION_CMD_READ,               Display_SG_CalibrationData},
   {"INTERVAL    ", "Set Calibration Interval",               SG_CALIBRATION_CMD_INTERVAL,           Handle_SG_CalibrationInterval},
   {"TYPE        ", "Set Calibration Type",                   SG_CALIBRATION_CMD_TYPE,               Handle_SG_CalibrationType},
   {"HELP        ", "Display Help Message",                   SG_CALIBRATION_CMD_HELP,               Display_SG_HelpMessage},
   {"ONE TIME CAL", "Run One Time Calibration",               SG_CALIBRATION_CMD_RUN_ONE_TIME_CAL,   Handle_SG_RunOneTimeCal},
   {"CAL CHAN    ", "Set Calibration Channels",               SG_CALIBRATION_CMD_CAL_CHANNEL,        Handle_SG_CalChans}
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the SG_BasicOpsMenu is to illustrate the methods to call in the naibrd library to perform basic
 operations with the SG modules for configuration setup, controlling the drive outputs, 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 SG routines.
 - ConfigDevice
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - CheckModule
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SG_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;

   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)
               {
                  Run_SG_BasicOps(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 NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function asks for the channel number, checks if it is valid, and if it is, calls Handle_SG_Configuration()
or Handle_SG_StandardOperation(), depending on what the user specifies.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Run_SG_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   naiapp_AppParameters_t sg_basicops_params;
   p_naiapp_AppParameters_t p_sg_basicops_params = &sg_basicops_params;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_sg_basicops_params->cardIndex = cardIndex;
   p_sg_basicops_params->module = module;
   p_sg_basicops_params->channel = 0;
   p_sg_basicops_params->maxChannels = naibrd_SG_GetChannelCount(modid);

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands(SG_BASICOP_CMD_COUNT, SG_BasicOpMenuCmds);
      while (bContinue)
      {
         naiapp_utils_LoadParamMenuCommands(SG_BASICOP_CMD_COUNT, SG_BasicOpMenuCmds); //reload main menu
         naiapp_display_ParamMenuCommands((int8_t *)"SG Basic Operation Menu");
         printf("\nType SG command or %c to quit : main >", NAI_QUIT_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                     case SG_BASICOP_CMD_CONFIG:
                     case SG_BASICOP_CMD_STANDARDOPS:
                        SG_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_sg_basicops_params);
                        break;
                     default:
                        printf("Invalid command entered\n");
                        break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
   return bQuit;
}

/**************************************************************************************************************/
/**
<summary>
This function is called if the user chooses to configure the SG module or to read the configuration data.
There are options to read configuration data, set gain range, set excitation mode, set excitation, set
bridge sensitivity, set sensor fs, and set remote drive sense.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_Configuration(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   p_naiapp_AppParameters_t p_sg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_sg_params->cardIndex;
   int32_t module = p_sg_params->module;
   int32_t maxChannels = p_sg_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   if (p_sg_params->modId == NAI_MODULE_ID_SG1)
   {
      if (g_DisplayHex == TRUE)
      {
         SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
      }
      else
      {
         SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
      }
      while (bContinue)
      {
         naiapp_utils_LoadParamMenuCommands(SG_GEN5_CONFIG_CMD_COUNT, SG_Gen5_ConfigMenuCmds);
         naiapp_display_ParamMenuCommands((int8_t *)"SG Configuration Menu");
         printf("\nType SG command or %c to go back : cfg >", BACK_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                     case SG_GEN5_CONFIG_CMD_READ:
                     case SG_GEN5_CONFIG_CMD_EXCITATION:
                     case SG_GEN5_CONFIG_CMD_BRIDGE_CONFIG:
                     case SG_GEN5_CONFIG_CMD_PGA_GAIN:
                     case SG_GEN5_CONFIG_CMD_REMOTE_SENSE:
                     case SG_GEN5_CONFIG_CMD_NOMINAL_RES:
                     case SG_GEN5_CONFIG_CMD_GAUGE_FACTOR:
                     case SG_GEN5_CONFIG_CMD_POISSON_RATIO:
                     case SG_GEN5_CONFIG_CMD_LEAD_RES:
                     case SG_GEN5_CONFIG_CMD_SAMPLE_RATE:
                     case SG_GEN5_CONFIG_CMD_STRAIN_ALARM_LO:
                     case SG_GEN5_CONFIG_CMD_STRAIN_ALERT_LO:
                     case SG_GEN5_CONFIG_CMD_STRAIN_ALERT_HI:
                     case SG_GEN5_CONFIG_CMD_STRAIN_ALARM_HI:
                     case SG_GEN5_CONFIG_CMD_IMBALANCE_OFFSET:
                     case SG_GEN5_CONFIG_CMD_INTERNAL_BRIDGE_COMPLETION:
                     case SG_GEN5_CONFIG_CMD_TOGGLE_HEX_MODE:
                        SG_Gen5_ConfigMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_sg_params);     //TODO: checkcnt.
                        break;
                     default:
                        printf("Invalid command entered\n");
                        break;
                  }
               }
               else
               {
                  printf("Invalid command entered\n");
               }
            }
         }
         else
         {
            bContinue = FALSE;
         }
      }
   }
   else
   {
      SG_DisplayCfg(cardIndex, module, maxChannels);
      while (bContinue)
      {
         naiapp_utils_LoadParamMenuCommands(SG_CONFIG_CMD_COUNT, SG_ConfigMenuCmds);
         while (bContinue)
         {
            naiapp_utils_LoadParamMenuCommands(SG_CONFIG_CMD_COUNT, SG_ConfigMenuCmds);
            naiapp_display_ParamMenuCommands((int8_t *)"SG Configuration Menu");
            printf("\nType SG command or %c to go back : cfg >", BACK_CHAR);
            bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt);
            if (!bQuit)
            {
               if (inputResponseCnt > 0)
               {
                  bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
                  if (bCmdFound)
                  {
                     switch (cmd)
                     {
                        case SG_CONFIG_CMD_READ:
                        case SG_CONFIG_CMD_GAIN_RANGE:
                        case SG_CONFIG_CMD_EXCITATION_MODE:
                        case SG_CONFIG_CMD_EXCITATION:
                        case SG_CONFIG_CMD_BRIDGE_SENSITIVITY:
                        case SG_CONFIG_CMD_SENSOR_FS:
                        case SG_CONFIG_CMD_REMOTE_DRIVE_SENSE:
                        case SG_CONFIG_CMD_CALIBRATION:
                           SG_ConfigMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_sg_params);
                           break;
                        default:
                           printf("Invalid command entered\n");
                           break;
                     }
                  }
                  else
                     printf("Invalid command entered\n");
               }
            }
            else
               bContinue = FALSE;
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function is called if the user chooses to perform SG standard operations checks to retrieve the
SG standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StandardOperation(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd = 0;
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
   {
      if (g_DisplayHex == TRUE)
      {
         SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
      }
      else
      {
         SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
      }
      while (bContinue)
      {
         naiapp_utils_LoadParamMenuCommands(SG_GEN5_STANDARD_OPERATIONS_CMD_COUNT, SG_Gen5_StandardOperationMenuCmds);
         naiapp_display_ParamMenuCommands((int8_t*)"SG Standard Operations Menu");
         printf("\nType SG command or %c to go back : ops >", BACK_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                     case SG_GEN5_STANDARD_OPERATIONS_CMD_READ_DATA:
                     case SG_GEN5_STANDARD_OPERATIONS_CMD_RESET_MIN_MAX_STRAIN:
                     case SG_GEN5_STANDARD_OPERATIONS_CMD_CLEAR_STATUS:
                     case SG_GEN5_STANDARD_OPERATIONS_CMD_TOGGLE_HEX_MODE:
                        SG_Gen5_StandardOperationMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)sg_basicops_params);
                        break;
                     default:
                        printf("Invalid command entered\n");
                        break;
                  }
               }
               else
               {
                  printf("Invalid command entered\n");
               }
            }
         }
         else
         {
            bContinue = FALSE;
         }
      }
   }
   else
   {
      Display_SG_StandardOpOptions(paramCount, p_params);
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the raw hex mode enabled/disabled setting to the value specified by the user
and then displays all of the standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ToggleHexModeOps(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t enableHexMode = FALSE;
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   printf("Type Raw Hex Mode Enable/Disable setting to set (0 for disable, 1 for enable): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         enableHexMode = (bool_t)atoi((const char *)inputBuffer);
         if (enableHexMode <= TRUE)
         {
            g_DisplayHex = enableHexMode;
         }
         else
         {
            printf("\nInvalid value entered!\n");
         }

         if (g_DisplayHex == TRUE)
         {
            SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
         }
         else
         {
            SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the raw hex mode enabled/disabled setting to the value specified by the user
and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ToggleHexModeConfig(int32_t paramCount, int32_t* p_params)
{

   bool_t bQuit = FALSE;
   bool_t enableHexMode = FALSE;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   printf("Type Raw Hex Mode Enable/Disable setting to set (0 for disable, 1 for enable): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         enableHexMode = (bool_t)atoi((const char *)inputBuffer);
         if (enableHexMode <= TRUE)
         {
            g_DisplayHex = enableHexMode;
         }
         else
         {
            printf("\nInvalid value entered!\n");
         }

         if (g_DisplayHex == TRUE)
         {
            SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
         }
         else
         {
            SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function displays the configuration data for the SG module (for Gen 3: gain range, excitation mode,
excitation voltage, bridge sensitivity, sensor full scale, and remote drive sense; for Gen 5: excitation
voltage, bridge configuration, PGA gain, remote/local sense mode, nominal resistance, gauge factor,
Poisson ratio, lead resistance, sample rate, strain alarm low threshold, strain alert low threshold,
strain alert high threshold, strain alarm high threshold, imbalance offset, and internal bridge
completion enable value).
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_ChannelCfg(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
   {
      if (g_DisplayHex == TRUE)
      {
         SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
      }
      else
      {
         SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
      }
   }
   else
   {
      SG_DisplayCfg(cardIndex, module, maxChannels);
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the gain range to the value specified by the user and then displays all of the configuration
data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_GainRange(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sg_gain_range_t range;
   int32_t channel;
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Gain Range Values:\n\n");
      printf("Value To Write         Gain Range Value (V/V)\n");
      printf("----------------------------------------------\n");
      printf("      0           =          0.0078125\n");
      printf("      1           =          0.0156250\n");
      printf("      2           =          0.0312500\n");
      printf("      3           =          0.0625000\n");
      printf("      4           =          0.1250000\n");
      printf("      5           =          1.0000000\n\n");
      printf("*Note: Writing any values other than\n");
      printf("those specified will cause the gain\n");
      printf("range to stay the same as it was prior\n");
      printf("to the calling of this function.\n\n");
      printf("Type Gain Range value to set: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            range = (nai_sg_gain_range_t)atof((const char *)inputBuffer);
            if (range < 6)
            {
               check_status(naibrd_SG_SetGainRange(cardIndex, module, channel, range));
            }
            SG_DisplayCfg(cardIndex, module, maxChannels);
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the excitation mode to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ExcitationMode(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sg_excitation_mode_t mode;
   int32_t channel;
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type Excitation Mode value to set (0 for DC, 1 for AC, anything else for no change): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            mode = (nai_sg_excitation_mode_t)atof((const char *)inputBuffer);
            if (mode < 2)
            {
               check_status(naibrd_SG_SetExcitationMode(cardIndex, module, channel, mode));
            }
            SG_DisplayCfg(cardIndex, module, maxChannels);
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the excitation voltage to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_Excitation(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t excitationVoltRaw = 0u;
   float32_t excitationvolt = 0.0f;
   float64_t excitationVoltGen5 = 0.0;
   int32_t channel;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if ((g_DisplayHex == FALSE) || (sg_basicops_params->modId != NAI_MODULE_ID_SG1))
      {
         printf("Type Excitation Voltage value to set (V): ");
      }
      else
      {
         printf("Type raw hex Excitation Voltage register value to set: ");
      }
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
            {
               if (g_DisplayHex == TRUE)
               {
                  excitationVoltRaw = strtol((const char *)inputBuffer, NULL, 16);
                  check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_EXCITATION_VOLT, excitationVoltRaw));
                  SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
               }
               else
               {
                  excitationVoltGen5 = atof((const char *)inputBuffer);
                  check_status(naibrd_SG_SetExcitationSignal(cardIndex, module, channel, excitationVoltGen5));
                  SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
               }
            }
            else
            {
               excitationvolt = (float32_t)atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetExcitation(cardIndex, module, channel, excitationvolt));
               SG_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the bridge sensitivity to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_BridgeSensitivity(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float32_t bridgesensitivity;
   float32_t bridgesensitivityVV;
   int32_t channel;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type Bridge Sensitivity value to set (mV/V): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            bridgesensitivity = (float32_t)atof((const char *)inputBuffer);
            bridgesensitivityVV = bridgesensitivity / 1000;
            check_status(naibrd_SG_SetBridgeSensitivity(cardIndex, module, channel, bridgesensitivityVV));
            SG_DisplayCfg(cardIndex, module, maxChannels);
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the sensor full scale to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_SensorFS(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float32_t sensorfs;
   int32_t channel;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type Sensor Full Scale value to set: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            sensorfs = (float32_t)atof((const char *)inputBuffer);
            check_status(naibrd_SG_SetSensorFS(cardIndex, module, channel, sensorfs));
            SG_DisplayCfg(cardIndex, module, maxChannels);
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the remote drive sense to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_RemoteDriveSense(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sg_remote_sense_t remoteDriveSense;
   int32_t channel;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
      {
         printf("Type Remote Drive Sense Selection (6 for remote sense, 4 for local): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               remoteDriveSense = (nai_sg_remote_sense_t)atoi((const char *)inputBuffer);
               if ((remoteDriveSense == SG_GEN5_REMOTE_SENSE) || (remoteDriveSense == SG_GEN5_LOCAL_SENSE))
               {
                  check_status(naibrd_SG_SetRemoteDriveSense(cardIndex, module, channel, remoteDriveSense));
               }
               else
               {
                  printf("\nInvalid value entered!\n");
               }

               if (g_DisplayHex == TRUE)
               {
                  SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
               }
               else
               {
                  SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
               }
            }
         }
      }
      else
      {
         printf("Type Remote Drive Sense Selection (1 for remote sense, 0 for local): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               remoteDriveSense = (nai_sg_remote_sense_t)atoi((const char *)inputBuffer);
               if ((remoteDriveSense == SG_GEN3_REMOTE_SENSE_OFF) || (remoteDriveSense == SG_GEN3_REMOTE_SENSE_ON))
               {
                  check_status(naibrd_SG_SetRemoteDriveSense(cardIndex, module, channel, remoteDriveSense));
               }
               else
               {
                  printf("\nInvalid value entered!\n");
               }

               SG_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function is called if the user chooses to configure or read the SG Module calibration data.
There are options to read calibration data, set calibration interval, and set calibration type.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_Calibration(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

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

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands(SG_CALIBRATION_CMD_COUNT, SG_CalibrationMenuCmds);
      while (bContinue)
      {
         naiapp_display_ParamMenuCommands((int8_t *)"SG Calibration Menu");
         printf("\nType SG command or %c to go back : cal >", BACK_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                     case SG_CALIBRATION_CMD_READ:
                     case SG_CALIBRATION_CMD_INTERVAL:
                     case SG_CALIBRATION_CMD_TYPE:
                     case SG_CALIBRATION_CMD_HELP:
                     case SG_CALIBRATION_CMD_RUN_ONE_TIME_CAL:
                     case SG_CALIBRATION_CMD_CAL_CHANNEL:
                        SG_CalibrationMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)sg_basicops_params);
                        break;
                     default:
                        printf("Invalid command entered\n");
                        break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the bridge configuration to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_BridgeConfig(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sg_bridge_config_type_t bridgeConfig = 0u;
   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type Bridge Configuration Selection (0 for quarter bridge 1, 1 for quarter bridge 2, 2 for half bridge 1, ");
      printf("3 for half bridge 2, 4 for full bridge 1, 5 for full bridge 2, 6 for full bridge 3): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            bridgeConfig = (nai_sg_bridge_config_type_t)atoi((const char *)inputBuffer);
            if (bridgeConfig < NAI_SG_BRIDGE_CONFIG_COUNT)
            {
               check_status(naibrd_SG_SetBridgeConfiguration(cardIndex, module, channel, bridgeConfig));
            }
            else
            {
               printf("\nInvalid value entered!\n");
            }

            if (g_DisplayHex == TRUE)
            {
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
            else
            {
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the nominal resistance to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_NominalRes(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t nominalResRaw = 0u;
   float64_t nominalRes = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Nominal Resistance register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               nominalResRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_NOMINAL_RESISTANCE, nominalResRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Nominal Resistance value to set (Ohms): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               nominalRes = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetNominalResistance(cardIndex, module, channel, nominalRes));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the gauge factor to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_GaugeFactor(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t gaugeFactorRaw = 0u;
   float64_t gaugeFactor = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Gauge Factor register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               gaugeFactorRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_GAUGE_FACTOR, gaugeFactorRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Gauge Factor value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               gaugeFactor = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetGaugeFactor(cardIndex, module, channel, gaugeFactor));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the Poisson ratio to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_PoissonRatio(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t poissonRatioRaw = 0u;
   float64_t poissonRatio = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Poisson Ratio register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               poissonRatioRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_POISSON_RATIO, poissonRatioRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Poisson Ratio value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               poissonRatio = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetPoissonRatio(cardIndex, module, channel, poissonRatio));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the lead resistance to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_LeadRes(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t leadResRaw = 0u;
   float64_t leadRes = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Lead Resistance register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               leadResRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_LEAD_RESISTANCE, leadResRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Lead Resistance value to set (Ohms): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               leadRes = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetLeadResistance(cardIndex, module, channel, leadRes));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the sample rate to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_SampleRate(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sg_sample_rate_type_t sampleRate = 0u;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type Sample Rate Selection (All values are in Hz: 0 for 2.5, 1 for 5, 2 for 10, 3 for 16.6666, 4 for 20, ");
      printf("5 for 50, 6 for 60, 7 for 100, 8 for 400, 9 for 1200, 10 for 2400, 11 for 4800, 12 for 7200, 13 for 14400, 14 for 19200, ");
      printf("15 for 38400): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            sampleRate = (nai_sg_sample_rate_type_t)atoi((const char *)inputBuffer);
            if (sampleRate < NAI_SG_SAMPLE_RATE_COUNT)
            {
               check_status(naibrd_SG_SetSampleRate(cardIndex, module, channel, sampleRate));
            }
            else
            {
               printf("\nInvalid value entered!\n");
            }

            if (g_DisplayHex == TRUE)
            {
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
            else
            {
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the strain alarm low threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlarmLo(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t strainAlarmLoRaw = 0u;
   float64_t strainAlarmLo = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Strain Alarm Low Threshold register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlarmLoRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALARM_LO_THRESHOLD, strainAlarmLoRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Strain Alarm Low Threshold value to set (microstrain): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlarmLo = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_LOW_STRAIN_ALERT_2_VALUE, strainAlarmLo));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the strain alert low threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlertLo(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t strainAlertLoRaw = 0u;
   float64_t strainAlertLo = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Strain Alert Low Threshold register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlertLoRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALERT_LO_THRESHOLD, strainAlertLoRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Strain Alert Low Threshold value to set (microstrain): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlertLo = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_LOW_STRAIN_ALERT_1_VALUE, strainAlertLo));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the strain alert high threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlertHi(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t strainAlertHiRaw = 0u;
   float64_t strainAlertHi = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Strain Alert High Threshold register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlertHiRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALERT_HI_THRESHOLD, strainAlertHiRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Strain Alert High Threshold value to set (microstrain): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlertHi = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_HIGH_STRAIN_ALERT_1_VALUE, strainAlertHi));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the strain alarm high threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlarmHi(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t strainAlarmHiRaw = 0u;
   float64_t strainAlarmHi = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Strain Alarm High Threshold register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlarmHiRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALARM_HI_THRESHOLD, strainAlarmHiRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Strain Alarm High Threshold value to set (microstrain): ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               strainAlarmHi = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_HIGH_STRAIN_ALERT_2_VALUE, strainAlarmHi));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the imbalance offset value to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ImbalanceOffset(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t imbalanceOffsetRaw = 0u;
   float64_t imbalanceOffset = 0.0;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      if (g_DisplayHex == TRUE)
      {
         printf("Type raw hex Imbalance Offset register value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               imbalanceOffsetRaw = strtol((const char *)inputBuffer, NULL, 16);
               check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_IMBALANCE_OFFSET, imbalanceOffsetRaw));
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
         }
      }
      else
      {
         printf("Type Imbalance Offset value to set: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               imbalanceOffset = atof((const char *)inputBuffer);
               check_status(naibrd_SG_SetImbalanceOffsetValue(cardIndex, module, channel, imbalanceOffset));
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the internal bridge completion enabled/disabled setting to the value specified by the user
and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_BridgeComp(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t useBridgeComp = FALSE;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type Internal Bridge Completion Enable/Disable setting to set (0 for disable, 1 for enable): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            useBridgeComp = (bool_t)atoi((const char *)inputBuffer);
            if (useBridgeComp <= TRUE)
            {
               check_status(naibrd_SG_SetUseInternalBridgeCompletion(cardIndex, module, channel, useBridgeComp));
            }
            else
            {
               printf("\nInvalid value entered!\n");
            }

            if (g_DisplayHex == TRUE)
            {
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
            else
            {
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the PGA Gain setting to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_PGAGain(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sg_pga_gain_type_t pgaGain = 0u;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type PGA Gain setting to set (0 for 1, 1 for 2, 2 for 4, 3 for 8, 4 for 16, 5 for 32): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            pgaGain = (nai_sg_pga_gain_type_t)atoi((const char *)inputBuffer);
            if (pgaGain < NAI_SG_PGA_GAIN_COUNT)
            {
               check_status(naibrd_SG_SetPGAGain(cardIndex, module, channel, pgaGain));
            }
            else
            {
               printf("\nInvalid value entered!\n");
            }

            if (g_DisplayHex == TRUE)
            {
               SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
            }
            else
            {
               SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function displays the SG Standard Operations options.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_StandardOpOptions(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

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

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands(SG_STANDARD_OPERATIONS_CMD_COUNT, SG_StandardOperationMenuCmds);
      while (bContinue)
      {
         naiapp_display_ParamMenuCommands((int8_t *)"SG Standard Operations Menu");
         printf("\nType SG command or %c to go back : bas >", BACK_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                     case SG_STANDARD_OPERATIONS_CMD_FORCE:
                     case SG_STANDARD_OPERATIONS_CMD_RANGE_SCALED:
                     case SG_STANDARD_OPERATIONS_CMD_UNSCALED:
                        SG_StandardOperationMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)sg_basicops_params);
                        break;
                     default:
                        printf("Invalid command entered\n");
                        break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayForceTable to display the SG Standard Operations Force Table.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_ForceTable(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   SG_DisplayForceTable(cardIndex, module, maxChannels);

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayRangeScaledTable to display the SG Standard Operations Range Scaled Table.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_RangeScaledTable(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   SG_DisplayRangeScaledTable(cardIndex, module, maxChannels);

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayUnscaledTable to display the SG Standard Operations Unscaled Table.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_UnscaledTable(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   SG_DisplayUnscaledTable(cardIndex, module, maxChannels);

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayStandardOpsData to display the SG Standard Operations Table for Gen 5 SG modules.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_StandardOpsData(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   if (g_DisplayHex == TRUE)
   {
      SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
   }
   else
   {
      SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
   }

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function resets the min and max strain values stored in the module (if the user chooses to) and then
displays all of the standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ResetMinMaxStrain(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_status_t status = NAI_SUCCESS;

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Are you sure you want to reset min and max strain? (Y = Yes, N = No): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            if (toupper(inputBuffer[0]) == 'Y')
            {
               status = naibrd_SG_ResetMinimumAndMaximumStrain(cardIndex, module, channel);
               if (status == NAI_SUCCESS)
               {
                  printf("\nReset Min and Max Strain Successful\n");
               }
               else
               {
                  printf("\nReset Min and Max Strain Failed!\n");
               }
            }
            else if (toupper(inputBuffer[0]) == 'N')
            {
               printf("\nMin and Max Strain will not be reset\n");
            }
            else
            {
               printf("\nInvalid value entered!\n");
            }

            if (g_DisplayHex == TRUE)
            {
               SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
            }
            else
            {
               SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function clears the status corresponding to the status type specified by the user
(if the user chooses to) and then displays all of the standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ClearStatus(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_status_t status = NAI_SUCCESS;
   nai_sg_status_type_t statusType = 0u;
   uint32_t mask = 0x1u;
   int32_t responseNum = 0;
   char statusTypeStr[20] = "";

   int32_t channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;
   int32_t maxChannels = sg_basicops_params->maxChannels;

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

   bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
   if (!bQuit)
   {
      printf("Type status type to clear (0 for BIT, 1 for Open, 2 for High Strain Alert, ");
      printf("3 for High Strain Alarm, 4 for Low Strain Alert, 5 for Low Strain Alarm): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            responseNum = atoi((const char *)inputBuffer);
            switch (responseNum)
            {
               case 0:
                  statusType = NAI_SG_STATUS_BIT_LATCHED;
                  sprintf(statusTypeStr, "BIT");
                  break;
               case 1:
                  statusType = NAI_SG_STATUS_OPEN_LATCHED;
                  sprintf(statusTypeStr, "Open");
                  break;
               case 2:
                  statusType = NAI_SG_STATUS_HIGH_STRAIN_ALERT_1_LATCHED;
                  sprintf(statusTypeStr, "High Strain Alert");
                  break;
               case 3:
                  statusType = NAI_SG_STATUS_HIGH_STRAIN_ALERT_2_LATCHED;
                  sprintf(statusTypeStr, "High Strain Alarm");
                  break;
               case 4:
                  statusType = NAI_SG_STATUS_LOW_STRAIN_ALERT_1_LATCHED;
                  sprintf(statusTypeStr, "Low Strain Alert");
                  break;
               case 5:
                  statusType = NAI_SG_STATUS_LOW_STRAIN_ALERT_2_LATCHED;
                  sprintf(statusTypeStr, "Low Strain Alarm");
                  break;
               default:
                  printf("\nInvalid value entered!\n");
                  status = NAI_ERROR_INVALID_VALUE;
                  break;
            }

            if (status == NAI_SUCCESS)
            {
               printf("Are you sure you want to clear the %s status? (Y = Yes, N = No): ", statusTypeStr);
               bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               if (!bQuit)
               {
                  if (inputResponseCnt > 0)
                  {
                     if (toupper(inputBuffer[0]) == 'Y')
                     {
                        mask <<= (channel - 1);
                        status = naibrd_SG_ClearStatusRaw(cardIndex, module, statusType, mask);
                        if (status == NAI_SUCCESS)
                        {
                           printf("\nSuccessfully cleared %s status\n", statusTypeStr);
                        }
                        else
                        {
                           printf("\nFailed to clear %s status!\n", statusTypeStr);
                        }
                     }
                     else if (toupper(inputBuffer[0]) == 'N')
                     {
                        printf("\n%s status will not be cleared\n", statusTypeStr);
                     }
                     else
                     {
                        printf("\nInvalid value entered!\n");
                     }
                  }
               }
            }

            if (g_DisplayHex == TRUE)
            {
               SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
            }
            else
            {
               SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function displays the calibration data for the SG module (calibration interval and calibration type).
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_CalibrationData(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;

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

   SG_DisplayCalData(cardIndex, module);

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the calibration interval to the value specified by the user and then displays all of the
calibration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_CalibrationInterval(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float32_t calIntervalSec;
   float32_t outputDataRate;
   uint32_t calIntervalRaw;
   nai_sg_chop_stab_enable_t chopStabEnable;
   nai_sg_SINC_filter_t SINCFilter;
   uint32_t ODRScale;
   nai_sg_reject_60Hz_enable_t reject60Hz;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;

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

   printf("Type Calibration Interval to set (seconds): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         calIntervalSec = (float32_t)atof((const char *)inputBuffer);
         check_status(naibrd_SG_GetOutputDataCfg(cardIndex, module, &chopStabEnable, &SINCFilter, &ODRScale, &reject60Hz, &outputDataRate));
         calIntervalRaw = (uint32_t)(calIntervalSec * outputDataRate / 256);
         check_status(naibrd_SG_SetCalInterval(cardIndex, module, calIntervalRaw));
         SG_DisplayCalData(cardIndex, module);
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the calibration type to the value specified by the user and then displays all of the
calibration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_CalibrationType(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_sg_cal_type_t calType;
   uint32_t tempCalType;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;

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

   printf("\nOptions for setting the Calibration Type:\n");
   printf("0 = Off           : No calibration scheduled\n");
   printf("1 = Internal Cal  : Nulls the internal A/D for optimal accuracy. This is usually scheduled for periodic cal\n");
   printf("2 = System Offset : Nulls the reading to the present signal input, which should be 0 before execution\n");
   printf("3 = System Gain   : Sets gain to the full scale value with present signal input.\n");
   printf("                    Input signal should be full scale when this is run\n\n");
   printf("Type Calibration Type to set: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         tempCalType = (uint32_t)atof((const char *)inputBuffer);
         switch (tempCalType)
         {
            case 0:
               calType = (nai_sg_cal_type_t)SG_GEN3_CAL_OFF;
               break;
            case 1:
               calType = (nai_sg_cal_type_t)SG_GEN3_CAL_INT_ZERO_INT_FULL;
               break;
            case 2:
               calType = (nai_sg_cal_type_t)SG_GEN3_CAL_CAL_SYS_ZERO_SCALE;
               break;
            case 3:
               calType = (nai_sg_cal_type_t)SG_GEN3_CAL_CAL_SYS_FULL_SCALE;
               break;
            default:
               calType = (nai_sg_cal_type_t)SG_GEN3_CAL_INT_ZERO_INT_FULL;
               break;
         }
         check_status(naibrd_SG_SetCalType(cardIndex, module, calType));
         SG_DisplayCalData(cardIndex, module);
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function displays the help message for setting the Calibration Type.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_HelpMessage(int32_t paramCount, int32_t* p_params)
{
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
   UNREFERENCED_PARAMETER(p_params);
#endif

   printf("\nGET               Display the calibration options                                                           \n\n");
   printf("INTERVAL          Sets the periodic interval for automatic calibration                                      \n");
   printf("                  Determines how often the calibration is run; tradeoff of measurement      \n");
   printf("                  holdoff time vs. better accuracy from nulling drift in readings                    \n\n");
   printf("TYPE              Selects the type of calibration to be run.  System calibration options should only be    \n");
   printf("                  run one time rather than on a periodic basis due to signal requirements.            \n\n");
   printf("ONE TIME CAL      Performs an immediate run of calibration one time, then turns off periodic cal interval.   \n\n");
   printf("CAL CHAN          Selects the channels that will be calibrated.                                             \n");

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function writes a value of 0xFFFF to the Cal Interval register.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_RunOneTimeCal(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t calVal = 0xFFFF;
   uint32_t count = 20000;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;

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

   printf("\nThis will write a value of 0xFFFF to the cal interval register and trigger\n");
   printf("an immediate calibration one time. Interval will be set back to 0 when complete.\n\n");
   printf("Are you sure you want to run one time calibration? (ENTER to continue, Q to quit): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (check_status(naibrd_SG_SetCalInterval(cardIndex, module, calVal)) == 0)
      {
         naibrd_SG_GetCalInterval(cardIndex, module, &calVal);
         while ((calVal != 0) && (count > 0))
         {
            naibrd_SG_GetCalInterval(cardIndex, module, &calVal);
            count--;
         }
         if (count > 0)
            printf("\nOne time calibration complete\n");
         else
            printf("\nOne time calibration failed\n");
      }
      SG_DisplayCalData(cardIndex, module);
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function enables/disables the calibration channels based on the hex value set by the user.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_CalChans(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t calChanRawWord;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;

   int32_t cardIndex = sg_basicops_params->cardIndex;
   int32_t module = sg_basicops_params->module;

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

   printf("\nCalibration Channel value is bitmapped to the calibration channel register:\n");
   printf("Bit 0 (LSB)  -->  Channel 1\n");
   printf("Bit 1        -->  Channel 2\n");
   printf("Bit 2        -->  Channel 3\n");
   printf("Bit 3 (MSB)  -->  Channel 4\n\n");
   printf("Type Calibration Channel value to set in decimal: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         calChanRawWord = (uint32_t)atof((const char *)inputBuffer);
         check_status(naibrd_SG_SetRaw(cardIndex, module, NAI_SG_RAW_CAL_CHAN, calChanRawWord));
         SG_DisplayCalData(cardIndex, module);
      }
   }
   return NAI_SUCCESS;
}

Help Bot

X