TC BasicOps
Edit this on GitLab
TC BasicOps
Explanation
About the Sample Application Code
This C application code is designed for interaction with North Atlantic Industries (NAI) thermal coupling modules using the NAI Single Slot Kit (SSK). It illustrates the basic operations for configuration setup and channel reading of thermal coupling modules.
Code Overview
1. Includes and Definitions:
- The standard libraries such as stdio.h
, stdlib.h
, string.h
, etc., are included for basic operations.
- Custom NAI libraries (nai.h
, naibrd.h
, etc.) are included for accessing the board and module-specific functions.
2. Function Prototypes: - Functions are declared for running operations, configuring channels, displaying channel configurations, and handling menu commands.
3. Command Enumerations and Parameters:
- An enumeration tc_basicops_commands
defines the possible menu commands.
- The TC_BasicOpMenuCmds
array associates menu commands with their corresponding functions.
4. Main Function: - Initialization: Sets up the application by reading a configuration file. - User Interaction: Prompts the user to select a card and module, then runs the basic operations on the selected module. - Quit or Restart: Offers the user an option to quit or restart the application.
Function Descriptions
Run_TC_BasicOps
- Executes the basic operations for the given thermal coupling (TC) module. It configures channels and calls further configuration functions if valid.
Cfg_TC_Channel
- Manages the configuration of individual channels and interacts with the user to set parameters via a menu of commands.
Display Functions:
- Display_TC_ChannelCfg
: Displays the configuration status of the selected channel.
- TC_Display_XXX
: Several functions (TC_Display_ThermoCoupleType
, TC_Display_Temperature
, etc.) detail different aspects of the channel’s configuration and status.
Menu Command Helper Functions:
- Functions like TC_Set_ChanStatusEnable
, TC_Set_ThermoCoupleType
, etc., handle specific user requests to change module settings or perform actions (e.g., triggering calibration).
Enumerations and Structure:
- enum tc_basicops_commands
: Defines the list of basic operation commands.
- TC_BasicOpMenuCmds
: A table mapping command strings to their functions and descriptions.
Key Enumerations and Structures
-
naiapp_cmdtbl_params_t
: Likely a structure to hold command parameters for menu options. -
nai_tc_thermocouple_type_t
: Most likely enumerates different types of thermocouples (J, K, E, etc.). -
nai_tc_comp_type_t
: Enumerates types of Cold Junction Compensation (CJC). -
nai_tc_thresh_type_t
: Enumerates alert or alarm threshold types (low or high).
Execution Flow
-
Initialization and Configuration: The application starts by loading the configuration from
default_TC_BasicOps.txt
. -
User Interaction Loop: The user is repeatedly prompted to select a card and module. The
naiapp_query_CardIndex
andnaiapp_query_ModuleNumber
functions are used to get user input. -
Run Operations: For the selected module,
Run_TC_BasicOps
is called to configure and display the current status and configuration of the module’s channels. -
Channel Configuration Menu: The
Cfg_TC_Channel
function handles displaying the current configuration and reacting to user commands to change settings. -
Quit or Restart: The user can choose to either quit the application or restart the configuration process.
Commonly Used Functions
-
check_status
: Likely a macro or function to verify the function’s return status. -
naiapp_query_xxx
: Functions that query user input for various indices and parameters. -
naiapp_display_ParamMenuCommands
: Displays available menu commands to the user.
Conclusion
This sample application illustrates the basic operational workflow for configuring and interacting with thermal coupling modules using the NAI SSK. It includes user prompting for selecting the card/module, displaying current configurations, and allowing user-driven configuration through a command menu. Each aspect of the module’s configuration can be managed through specific functions, ensuring modular and maintainable code.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_tc.h"
#include "advanced/nai_ether_adv.h"
static const int8_t *CONFIG_FILE = (const int8_t *)"default_TC_BasicOps.txt";
/* Function prototypes */
int32_t Run_TC_BasicOps(int32_t cardIndex, int32_t module, uint32_t ModuleID);
static void Cfg_TC_Channel(int32_t cardIndex, int32_t module, int32_t MaxChannel, uint32_t ModuleID);
static void Display_TC_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan);
/* Channel Display Helper Functions*/
static void TC_Display_ThermoCoupleType(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_Temperature(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_Voltage(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_SampleRate(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_CompTemp(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_CJCEnable(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_Statuses(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_Thresholds(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_CJCType(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_OffsetTemp(int32_t cardIndex, int32_t module, int32_t chan);
static void TC_Display_BackgroundOpSuspension(int32_t cardIndex, int32_t module, int32_t chan);
/* Menu Command Helper Functions*/
static nai_status_t TC_Set_ChanStatusEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_ThermoCoupleType(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_SampleRate(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_CompTemp(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_CJCEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_Thresh(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_ClearStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_CJCType(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_OffsetTemp(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Set_BackgroundOpSuspension(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Trigger_SystemCalibration(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Trigger_OpenCheck(int32_t paramCount, int32_t* p_params);
static nai_status_t TC_Trigger_BIT(int32_t paramCount, int32_t* p_params);
static uint32_t g_TCModId = 0u;
/****** Command Tables *******/
enum tc_basicops_commands
{
TC_BASICOP_CMD_SET_CHAN_STATUS_ENABLE,
TC_BASICOP_CMD_SET_THERMO_COUPLE_TYPE,
TC_BASICOP_CMD_SET_SAMPLE_RATE,
TC_BASICOP_CMD_SET_COMP_TEMP,
TC_BASICOP_CMD_SET_CJC_ENABLE,
TC_BASICOP_CMD_SET_CJC_TYPE,
TC_BASICOP_CMD_SET_THRESH,
TC_BASICOP_CMD_CLEAR_STATUS,
TC_BASICOP_CMD_CHECK_POWER_ON_BIT,
TC_BASICOP_CMD_SET_OFFSET_TEMP,
TC_BASICOP_CMD_SET_BACKGROUND_OP_SUSPEND,
TC_BASICOP_CMD_TRIGGER_SYSTEM_CAL,
TC_BASICOP_CMD_TRIGGER_OPEN_CHECK,
TC_BASICOP_CMD_TRIGGER_BIT,
TC_BASICOP_CMD_COUNT
};
naiapp_cmdtbl_params_t TC_BasicOpMenuCmds[] = {
{"0", "Enable/Disable Channel Status Reporting", TC_BASICOP_CMD_SET_CHAN_STATUS_ENABLE, TC_Set_ChanStatusEnable},
{"1", "Set the Thermo Couple Type", TC_BASICOP_CMD_SET_THERMO_COUPLE_TYPE, TC_Set_ThermoCoupleType},
{"2", "Set the Sample Rate", TC_BASICOP_CMD_SET_SAMPLE_RATE, TC_Set_SampleRate},
{"3", "Set the Compensation Temperature", TC_BASICOP_CMD_SET_COMP_TEMP, TC_Set_CompTemp},
{"4", "Enable/Disable Cold Junction Compensation", TC_BASICOP_CMD_SET_CJC_ENABLE, TC_Set_CJCEnable},
{"5", "Set the CJC Type", TC_BASICOP_CMD_SET_CJC_TYPE, TC_Set_CJCType},
{"6", "Set a Threshold Value", TC_BASICOP_CMD_SET_THRESH, TC_Set_Thresh},
{"7", "Clear a Status", TC_BASICOP_CMD_CLEAR_STATUS, TC_ClearStatus},
{"8", "Check Power-On BIT", TC_BASICOP_CMD_CHECK_POWER_ON_BIT, TC_CheckPowerOnBIT},
{"9", "Set the Offset Temperature", TC_BASICOP_CMD_SET_OFFSET_TEMP, TC_Set_OffsetTemp},
{"A", "Suspend BIT/Open tests and System Cal", TC_BASICOP_CMD_SET_BACKGROUND_OP_SUSPEND, TC_Set_BackgroundOpSuspension},
{"B", "Trigger System Calibration", TC_BASICOP_CMD_TRIGGER_SYSTEM_CAL, TC_Trigger_SystemCalibration},
{"C", "Trigger Open-Line Check", TC_BASICOP_CMD_TRIGGER_OPEN_CHECK, TC_Trigger_OpenCheck},
{"D", "Trigger BIT", TC_BASICOP_CMD_TRIGGER_BIT, TC_Trigger_BIT}
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the TC_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
operations with the thermal coupling module for configuration setup and reading
the channels.
The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd TC routines.
- ClearDeviceCfg
- QuerySystemCfg
- DisplayDeviceCfg
- GetBoardSNModCfg
- SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t TC_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_TC_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 0;
}
/**************************************************************************************************************/
/**
<summary>
Run_TC_BasicOps prompts the user for the card, module and channel to use for the application and calls
Cfg_TC_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
int32_t Run_TC_BasicOps(int32_t cardIndex, int32_t module, uint32_t ModuleID)
{
int32_t MaxChannel;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
int32_t chanNum = 0;
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
MaxChannel = naibrd_TC_GetChannelCount(ModuleID);
g_TCModId = ModuleID;
if (MaxChannel == 0)
{
printf(" *** Module selection not recognized as TC module. ***\n\n");
}
else
{
for (chanNum = 1; chanNum <= MaxChannel; chanNum++)
{
check_status(naibrd_TC_SetConfiguration(cardIndex, module, chanNum, NAI_TC_CONFIG));
}
Cfg_TC_Channel(cardIndex, module, MaxChannel, ModuleID);
}
return cardIndex;
}
/**************************************************************************************************************/
/**
<summary>
Cfg_TC_Channel handles calling the Display_TC_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_TC_Channel(int32_t cardIndex, int32_t module, int32_t MaxChannel, uint32_t ModuleID)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
int32_t defaultchan = 1;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_AppParameters_t tc_basicops_params;
p_naiapp_AppParameters_t tc_basicOps_params = &tc_basicops_params;
tc_basicOps_params->cardIndex = cardIndex;
tc_basicOps_params->module = module;
tc_basicOps_params->maxChannels = naibrd_TC_GetChannelCount(MaxChannel);
tc_basicOps_params->modId = ModuleID;
tc_basicOps_params->displayHex = FALSE;
printf(" \r\n\r\n");
printf("Channel selection: \r\n");
printf("================= \r\n");
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &tc_basicOps_params->channel);
naiapp_utils_LoadParamMenuCommands(TC_BASICOP_CMD_COUNT, TC_BasicOpMenuCmds);
while (!bQuit)
{
/* Display the Channel Configuration */
Display_TC_ChannelCfg(cardIndex, module, tc_basicOps_params->channel);
/* Display the Menu Commands*/
naiapp_display_ParamMenuCommands((int8_t *)"TC Basic Operation Menu");
/* Prompt User For Command*/
printf("\nType TC command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit)
break;
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case TC_BASICOP_CMD_SET_CHAN_STATUS_ENABLE:
case TC_BASICOP_CMD_SET_THERMO_COUPLE_TYPE:
case TC_BASICOP_CMD_SET_SAMPLE_RATE:
case TC_BASICOP_CMD_SET_COMP_TEMP:
case TC_BASICOP_CMD_SET_CJC_ENABLE:
case TC_BASICOP_CMD_SET_CJC_TYPE:
case TC_BASICOP_CMD_SET_THRESH:
case TC_BASICOP_CMD_CLEAR_STATUS:
case TC_BASICOP_CMD_CHECK_POWER_ON_BIT:
case TC_BASICOP_CMD_SET_OFFSET_TEMP:
case TC_BASICOP_CMD_SET_BACKGROUND_OP_SUSPEND:
case TC_BASICOP_CMD_TRIGGER_SYSTEM_CAL:
case TC_BASICOP_CMD_TRIGGER_OPEN_CHECK:
case TC_BASICOP_CMD_TRIGGER_BIT:
TC_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)tc_basicOps_params);
break;
default:
printf("\n\n\nInvalid command entered\n\n");
break;
}
}
else
printf("\n\n\nInvalid command entered\n\n");
}
}
}
/**************************************************************************************************************/
/**
<summary>
Display_TC_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_TC_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan)
{
printf("\n===============================================================\n");
printf("CHANNEL %d\n", chan);
printf("===============================================================\n");
TC_Display_ThermoCoupleType(cardIndex, module, chan);
TC_Display_Temperature(cardIndex, module, chan);
TC_Display_Voltage(cardIndex, module, chan);
TC_Display_SampleRate(cardIndex, module, chan);
TC_Display_CompTemp(cardIndex, module, chan);
TC_Display_CJCEnable(cardIndex, module, chan);
TC_Display_CJCType(cardIndex, module, chan);
TC_Display_OffsetTemp(cardIndex, module, chan);
TC_Display_BackgroundOpSuspension(cardIndex, module, chan);
TC_Display_Thresholds(cardIndex, module, chan);
TC_Display_Statuses(cardIndex, module, chan);
printf("\n===============================================================");
}
static void TC_Display_ThermoCoupleType(int32_t cardIndex, int32_t module, int32_t chan)
{
bool_t isValidType = 1u;
nai_tc_thermocouple_type_t TcType;
char type = '\0';
check_status(naibrd_TC_GetThermocoupleType(cardIndex, module, chan, &TcType));
switch (TcType)
{
case NAI_TC_THERMOCOUPLE_TYPE_J:
type = 'J';
break;
case NAI_TC_THERMOCOUPLE_TYPE_K:
type = 'K';
break;
case NAI_TC_THERMOCOUPLE_TYPE_E:
type = 'E';
break;
case NAI_TC_THERMOCOUPLE_TYPE_T:
type = 'T';
break;
case NAI_TC_THERMOCOUPLE_TYPE_N:
type = 'N';
break;
case NAI_TC_THERMOCOUPLE_TYPE_B:
type = 'B';
break;
case NAI_TC_THERMOCOUPLE_TYPE_R:
type = 'R';
break;
case NAI_TC_THERMOCOUPLE_TYPE_S:
type = 'S';
break;
default:
isValidType = 0u;
break;
}
if (isValidType)
{
printf("\n%-35s %c\n", "ThermoCouple Type:", type);
}
else
{
printf("\n%-35s %s\n", "ThermoCouple Type:", "Invalid");
}
}
static void TC_Display_Temperature(int32_t cardIndex, int32_t module, int32_t chan)
{
float64_t cTemp = 0.0, fTemp = 0.0;
check_status(naibrd_TC_GetTemperature(cardIndex, module, chan, NAI_TC_TEMP_TYPE_CELSIUS, &cTemp));
check_status(naibrd_TC_GetTemperature(cardIndex, module, chan, NAI_TC_TEMP_TYPE_FAHRENHEIT, &fTemp));
printf("%-35s %f C\n", "Temperature(Celsius):", cTemp);
printf("%-35s %f F\n", "Temperature(Fahrenheit):", fTemp);
}
static void TC_Display_Voltage(int32_t cardIndex, int32_t module, int32_t chan)
{
float64_t voltage = 0.0;
check_status(naibrd_TC_GetVoltage(cardIndex, module, chan, &voltage));
printf("%-35s %.3f microVolts\n", "Voltage:", voltage);
}
static void TC_Display_SampleRate(int32_t cardIndex, int32_t module, int32_t chan)
{
float64_t rate = 0.0;
check_status(naibrd_TC_GetSampleRate(cardIndex, module, chan, &rate));
printf("%-35s %i Hz\n", "Sample Rate:", (int32_t)rate);
}
static void TC_Display_CompTemp(int32_t cardIndex, int32_t module, int32_t chan)
{
float64_t temp = 0.0;
check_status(naibrd_TC_GetCompTemperature(cardIndex, module, chan, &temp));
printf("%-35s %f C\n", "Compensation Temperature:", temp);
}
static void TC_Display_CJCEnable(int32_t cardIndex, int32_t module, int32_t chan)
{
bool_t enabled = FALSE;
#if defined (WIN32)
UNREFERENCED_PARAMETER(chan);
#endif
check_status(naibrd_TC_GetCJCEnable(cardIndex, module, &enabled));
printf("%-35s %s\n", "CJC Enabled:", enabled ? "True" : "False");
}
static void TC_Display_Statuses(int32_t cardIndex, int32_t module, int32_t chan)
{
/* declare array to hold status bits */
nai_status_bit_t statuses[NAI_TC_STATUS_TYPE_ENUM_COUNT];
/* get status bits for the channel*/
int i;
for (i = 0; i < NAI_TC_STATUS_TYPE_ENUM_COUNT; i++)
{
check_status(naibrd_TC_GetStatus(cardIndex, module, chan, i, &statuses[i]));
}
/* print headers (hardcoded) */
printf("\nStatus(latched):\n");
printf("%-10s %-10s %-10s %-10s %-10s %-10s %-10s\n", "bit", "open", "alert_lo", "alarm_lo", "alert_hi", "alarm_hi", "summary");
for (i = 0; i < 73; i++)
{
printf("-");
}
printf("\n");
/* print status bits */
for (i = 1; i < NAI_TC_STATUS_TYPE_ENUM_COUNT; i += 2)
{
printf("%-10i ", statuses[i]);
}
}
static void TC_Display_Thresholds(int32_t cardIndex, int32_t module, int32_t chan)
{
float64_t alert_lo, alarm_lo, alert_hi, alarm_hi;
check_status(naibrd_TC_GetThreshold(cardIndex, module, chan, NAI_TC_THRESH_ALERT_LO, &alert_lo));
check_status(naibrd_TC_GetThreshold(cardIndex, module, chan, NAI_TC_THRESH_ALARM_LO, &alarm_lo));
check_status(naibrd_TC_GetThreshold(cardIndex, module, chan, NAI_TC_THRESH_ALERT_HI, &alert_hi));
check_status(naibrd_TC_GetThreshold(cardIndex, module, chan, NAI_TC_THRESH_ALARM_HI, &alarm_hi));
printf("\nThresholds:\n");
printf("Alert Lo: %-13f C Alarm Lo: %-13f C \nAlert Hi: %-13f C Alarm Hi: %-13f C\n", alert_lo, alarm_lo, alert_hi, alarm_hi);
}
static void TC_Display_CJCType(int32_t cardIndex, int32_t module, int32_t chan)
{
nai_tc_comp_type_t type;
#if defined (WIN32)
UNREFERENCED_PARAMETER(chan);
#endif
check_status(naibrd_TC_GetCompType(cardIndex, module, chan, &type));
printf("%-35s ", "CJC Type:");
switch (type)
{
case NAI_TC_COMP_TYPE_MANUAL:
printf("Manual\n");
break;
case NAI_TC_COMP_TYPE_AUTO:
printf("Auto\n");
break;
default:
printf("Invalid CJC Type\n");
break;
}
}
static void TC_Display_OffsetTemp(int32_t cardIndex, int32_t module, int32_t chan)
{
float64_t temp = 0.0;
nai_status_t status = check_status(naibrd_TC_GetOffsetTemperature(cardIndex, module, chan, &temp));
if (status == NAI_SUCCESS)
{
printf("%-35s %f C\n", "Offset Temperature:", temp);
}
else if (status == NAI_ERROR_NOT_SUPPORTED)
{
printf("%-35s Not supported\n", "Offset Temperature:");
}
else
{
printf("%-35s Unknown\n", "Offset Temperature:");
}
}
static void TC_Display_BackgroundOpSuspension(int32_t cardIndex, int32_t module, int32_t chan)
{
bool_t disabled = FALSE;
nai_status_t status = check_status(naibrd_TC_GetBackgroundOpSuspend(cardIndex, module, chan, &disabled));
if (status == NAI_SUCCESS)
{
printf("%-35s %s\n", "Background Ops Suspended:", disabled ? "True" : "False");
}
else if (status == NAI_ERROR_NOT_SUPPORTED)
{
printf("%-35s Not supported\n", "Background Ops Suspended:");
}
else
{
printf("%-35s Unknown\n", "Background Ops Suspended:");
}
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_ChanStatusEnable handles the user request to enable or disable status reporting for the given channel
and calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_ChanStatusEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t enable = 0u;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Enter Channel Status Enabled/Disabled setting to set (0 for Disabled, 1 for Enabled): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
enable = (bool_t)atoi((const char *)inputBuffer);
switch (enable)
{
case FALSE:
case TRUE:
check_status(naibrd_TC_SetChanStatusEnable(cardIndex, module, chan, enable));
break;
default:
printf("\n\n\nInvalid Channel Status Enable setting!\n\n");
break;
}
}
else
{
printf("\n\n\nInvalid Channel Status Enable setting!\n\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_ThermoCoupleType handles the user request to configure the thermo couple type for the given channel and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_ThermoCoupleType(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
nai_tc_thermocouple_type_t type;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Enter new thermo couple type: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
switch (toupper(inputBuffer[0]))
{
case 'J':
type = NAI_TC_THERMOCOUPLE_TYPE_J;
break;
case 'K':
type = NAI_TC_THERMOCOUPLE_TYPE_K;
break;
case 'E':
type = NAI_TC_THERMOCOUPLE_TYPE_E;
break;
case 'T':
type = NAI_TC_THERMOCOUPLE_TYPE_T;
break;
case 'N':
type = NAI_TC_THERMOCOUPLE_TYPE_N;
break;
case 'B':
type = NAI_TC_THERMOCOUPLE_TYPE_B;
break;
case 'R':
type = NAI_TC_THERMOCOUPLE_TYPE_R;
break;
case 'S':
type = NAI_TC_THERMOCOUPLE_TYPE_S;
break;
default:
printf("\n\n\nInvalid ThermoCouple Type\n\n");
return bQuit;
}
check_status(naibrd_TC_SetThermocoupleType(cardIndex, module, chan, type));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_SampleRate handles the user request to configure the sample rate for the given channel and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_SampleRate(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
float64_t rate = 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Enter new sample rate: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
rate = atof((const char*)inputBuffer);
check_status(naibrd_TC_SetSampleRate(cardIndex, module, chan, rate));
}
else
printf("\n\n\nInvalid Sample Rate Entered\n\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_CompTemp handles the user request to configure the compensation temperature for the given channel and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_CompTemp(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
float64_t temp = 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Enter new compensation temperature: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
temp = atof((const char*)inputBuffer);
check_status(naibrd_TC_SetCompTemperature(cardIndex, module, chan, temp));
}
else
printf("\n\n\nInvalid Compensation Temperature Entered\n\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_CJCEnable handles the user request to configure the cold junction compensation for the TC module and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_CJCEnable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
bool_t bQuit = FALSE;
bool_t enable = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Enable cold junction compensation? (1 - Yes, 0 - No): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
enable = FALSE;
break;
case 1:
enable = TRUE;
break;
default:
printf("\n\n\nInvalid Response\n\n");
return bQuit;
}
check_status(naibrd_TC_SetCJCEnable(cardIndex, module, enable));
}
else
printf("\n\n\nInvalid Response\n\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_Thresh handles the user request to configure the threshold values for the given channel and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_Thresh(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
nai_tc_thresh_type_t type;
float64_t value;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* get threshold type*/
printf("Enter threshold type to set \n(0 - alert lo, 1 - alarm lo, 2 - alert hi, 3 - alarm hi):");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
type = NAI_TC_THRESH_ALERT_LO;
break;
case 1:
type = NAI_TC_THRESH_ALARM_LO;
break;
case 2:
type = NAI_TC_THRESH_ALERT_HI;
break;
case 3:
type = NAI_TC_THRESH_ALARM_HI;
break;
default:
printf("\n\n\nInvalid Threshold Type\n\n");
return bQuit;
}
}
else
{
printf("\n\n\nInvalid Threshold Type\n\n");
return bQuit;
}
}
else
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
/* get threshold value*/
printf("Enter threshold value:");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
value = atof((const char*)inputBuffer);
check_status(naibrd_TC_SetThreshold(cardIndex, module, chan, type, value));
}
else
printf("\n\n\nInvalid Threshold Value\n\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_ClearStatus handles the user request to clear the status for the given status type and channel and
calls the relevant method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_ClearStatus(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
nai_tc_status_type_t type;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* get status type*/
printf("Enter status type to clear\n");
printf("(0 - bit, 1 - open, 2 - alert lo, 3 - alarm lo, 4 - alert hi, 5 - alarm hi, 6 - summary):");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
type = NAI_TC_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_TC_STATUS_OPEN_LATCHED;
break;
case 2:
type = NAI_TC_STATUS_ALERT_LO_LATCHED;
break;
case 3:
type = NAI_TC_STATUS_ALARM_LO_LATCHED;
break;
case 4:
type = NAI_TC_STATUS_ALERT_HI_LATCHED;
break;
case 5:
type = NAI_TC_STATUS_ALARM_HI_LATCHED;
break;
case 6:
type = NAI_TC_STATUS_SUMMARY_LATCHED;
break;
default:
printf("\n\n\nInvalid Status Type\n\n");
return bQuit;
}
check_status(naibrd_TC_ClearStatus(cardIndex, module, chan, type));
}
else
printf("\n\n\nInvalid Status Type\n\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_CheckPowerOnBIT handles the user request to check the power-on BIT completed state and
calls the relevant methods in the naibrd library. If the power-on BIT has completed,
the Latched BIT Status of each TC channel is checked.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
int32_t channelCount = 0;
bool_t pBitComplete = FALSE;
nai_status_bit_t bitStatus = 0u;
char strBitStatus[12] = "";
chan = 0;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
channelCount = naibrd_TC_GetChannelCount(g_TCModId);
/* Check to see if PBIT ran for the module. */
printf("Checking if the Power-On BIT test has run...\n");
check_status(naibrd_TC_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
switch (pBitComplete)
{
case 0u:
printf("\nPBIT Complete: NOT COMPLETED\n");
break;
case 1u:
printf("\nPBIT Complete: COMPLETED\n");
break;
default:
printf("\nPBIT Complete: UNKNOWN\n");
break;
}
if (pBitComplete)
{
/* Read the BIT status */
printf("Checking the result of the Power-on BIT test...\n");
for (chan = 1; chan <= channelCount; chan++)
{
check_status(naibrd_TC_GetStatus(cardIndex, module, chan, NAI_TC_STATUS_BIT_LATCHED, &bitStatus));
switch (bitStatus)
{
case 0:
sprintf(strBitStatus, "BIT Passed");
break;
case 1:
sprintf(strBitStatus, "BIT FAILED");
break;
default:
sprintf(strBitStatus, "Unknown");
break;
}
printf("Ch. %d: %s\n", chan, strBitStatus);
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_CJCType handles the user request to configure the cold junction compensation type for the TC module and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_CJCType(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
nai_tc_comp_type_t type;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Set CJC Type (1 - Manual, 0 - Auto): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
type = NAI_TC_COMP_TYPE_AUTO;
break;
case 1:
type = NAI_TC_COMP_TYPE_MANUAL;
break;
default:
printf("\n\n\nInvalid Response\n\n");
return bQuit;
}
check_status(naibrd_TC_SetCompType(cardIndex, module, chan, type));
}
else
printf("\n\n\nInvalid Response\n\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_OffsetTemp handles the user request to configure the offset temperature for the given channel and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_OffsetTemp(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
float64_t temp = 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Enter new offset temperature: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
temp = atof((const char*)inputBuffer);
check_status(naibrd_TC_SetOffsetTemperature(cardIndex, module, chan, temp));
}
else
{
printf("\n\n\nInvalid Offset Temperature Entered\n\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Set_BackgroundOpSuspension handles the user request to suspend the BIT/Open-Line tests and
System Calibration for the given channel and calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Set_BackgroundOpSuspension(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
bool_t disable = FALSE;
bool_t failed = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Suspend or enable BIT/Open-Line tests and System Calibration? (1 - Suspend, 0 - Enable): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
disable = FALSE;
break;
case 1:
disable = TRUE;
break;
default:
printf("\n\n\nInvalid Response\n\n");
failed = TRUE;
break;
}
if (failed == FALSE)
{
check_status(naibrd_TC_SetBackgroundOpSuspend(cardIndex, module, chan, disable));
}
}
else
{
printf("\n\n\nInvalid Response\n\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Trigger_SystemCalibration handles the user request to trigger system calibration for the given channel and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Trigger_SystemCalibration(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Trigger System Calibration? (1 - Yes, 0 - No): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
break;
case 1:
check_status(naibrd_TC_TriggerBackgroundOperation(cardIndex, module, chan, NAI_TC_BACKGROUND_OP_SYSTEM_CAL));
break;
default:
printf("\n\n\nInvalid Response\n\n");
break;
}
}
else
{
printf("\n\n\nInvalid Response\n\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Trigger_OpenCheck handles the user request to trigger an open-line check for the given channel and
calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Trigger_OpenCheck(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Trigger Open-Line Check? (1 - Yes, 0 - No): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
break;
case 1:
check_status(naibrd_TC_TriggerBackgroundOperation(cardIndex, module, chan, NAI_TC_BACKGROUND_OP_OPEN));
break;
default:
printf("\n\n\nInvalid Response\n\n");
break;
}
}
else
{
printf("\n\n\nInvalid Response\n\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
TC_Trigger_BIT handles the user request to trigger BIT for the given channel and calls the relevant setter method
in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t TC_Trigger_BIT(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ad_params->cardIndex;
int32_t module = p_ad_params->module;
int32_t chan = p_ad_params->channel;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Trigger BIT? (1 - Yes, 0 - No): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (strlen((const char*)inputBuffer) > 0)
{
int response = atoi((const char*)inputBuffer);
switch (response)
{
case 0:
break;
case 1:
check_status(naibrd_TC_TriggerBackgroundOperation(cardIndex, module, chan, NAI_TC_BACKGROUND_OP_BIT));
break;
default:
printf("\n\n\nInvalid Response\n\n");
break;
}
}
else
{
printf("\n\n\nInvalid Response\n\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}