DS SetAngle
Edit this on GitLab
DS SetAngle
Explanation
About the Sample Application Code
The provided application code is designed for use with embedded function modules from North Atlantic Industries (NAI). The primary focus of this application is to interact and configure various parameters of Digital to Synchro (D/S) channels on a specified card and module. This guide will walk you through the code, explaining its structure, functionality, and key components.
Includes and Definitions
-
Standard Libraries:
-
stdio.h
: Standard input and output library. -
stdlib.h
: Standard library for memory allocation, process control, conversions, etc. -
string.h
: String handling functions. -
time.h
: Time and date functions. -
math.h
: Mathematics functions. -
ctype.h
: Character handling functions.
-
-
NAI Specific Include Files:
-
Various NAI-specific header files provide functions and definitions for interacting with their hardware:
-
naiapp_boardaccess_menu.h
-
naiapp_boardaccess_query.h
-
naiapp_boardaccess_access.h
-
naiapp_boardaccess_display.h
-
naiapp_boardaccess_utils.h
-
DS_Common.h
-
nai.h
-
naibrd.h
-
naibrd_ds.h
-
nai_ether_adv.h
-
Constants and Enums
-
Configuration File:
This defines the default configuration file name used by the application.c static const int8_t *CONFIG_FILE = (int8_t *)"default_DsSetAngle.txt";
-
Command Table Enum:
Defines command identifiers for the command table.c enum dsfunc_commands { DS_FUNC_CMD_SET_ANGLE, DS_FUNC_CMD_SET_MODULE, DS_FUNC_CMD_SET_CHANNEL, DS_FUNC_CMD_COUNT };
-
User Input Table Enum:
Defines identifiers for possible user inputs.c enum dsfunc_userInputs { DS_USER_INPUT_READ_REG, DS_USER_INPUT_WRITE_REG, DS_USER_INPUT_SET_ANGLE, DS_USER_INPUT_SET_EXP_VLL, DS_USER_INPUT_SET_EXP_VREF, DS_USER_INPUT_SET_VLL_THRESHOLD, DS_USER_INPUT_SET_VREF_THRESHOLD, DS_USER_INPUT_FIX_RATIO_MODE, DS_USER_INPUT_CHAN_STATUS_ENABLE, DS_USER_INPUT_POWER, DS_USER_INPUT_REFRESH, DS_USER_INPUT_QUIT, DS_USER_INVALID_INPUT, DS_USER_INPUT_COUNT };
Structures
-
Command Table Structure:
Defines the structure for command tables, linking input strings to functions.c struct dsdemofunc_cmdtbl { int8_t *cmdstr; int8_t *menustr; int32_t cmdnum; void(*func)(int32_t cardIndex, int32_t module, int32_t channel); };
-
User Input Limit Table Structure:
Defines the structure for managing user input limits.c struct dsUserInputLimitTable { int32_t cmdnum; int8_t *cmdstr; float64_t upperLimit; float64_t lowerLimit; };
Main Function
The main entry point of the application is the main
function:
#if defined (__VXWORKS__)
int32_t DS_RunAngleProgramSample(void)
#else
int32_t main(void)
#endif
{
// Variable declarations
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)) {
DS_RunAngleProgram(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;
}
This function initializes the application, runs a command menu, and handles user interaction for selecting cards and modules.
Key Functions
-
DS_RunAngleProgram
: This function queries the user for the module and channel to configure for D/S output. -
Show_DSDemoFunc_Commands
: Displays the available commands in the command table. -
DS_SetNewAngle
,DS_SetExpVLL
, etc.: Functions for configuring various D/S channel parameters like angle, expected voltages, thresholds, etc.
Utility Functions
-
getStatus
: Retrieves the status of a given D/S channel. -
getUserInput
: Captures and validates user input. -
checkUserInput
: Checks if the user input is within defined limits.
This application serves as a configurable interface for interacting with NAI’s D/S channels, allowing users to set angles, voltages, modes, and more while providing real-time feedback and validation.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.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 "DS_Common.h"
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ds.h"
#include "advanced/nai_ether_adv.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_DsSetAngle.txt";
/* Function prototypes */
static void DS_ShowSetAngleTestResult(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_RunAngleProgram(int32_t cardIndex, int32_t module, uint32_t moduleID);
static void DS_RunAngleFunc(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetNewAngle(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetExpVLL(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetExpVref(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetVllThrehold(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetVrefThreshold(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetFixedRatioMode(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetPower(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetChannelStatusCtrl(int32_t cardIndex, int32_t module, int32_t channel);
static void Show_DSDemoFunc_Commands(void);
static void printInvalidUserInputMessage(uint32_t uTypeIdx, float64_t dUserInput);
static void showCurrentModChan(int32_t nModule, int32_t nChannel);
static void getStatus(int32_t cardIndex, int32_t module, int32_t channel, uint8_t *u8Status);
static int32_t getUserInput(void);
static bool_t checkUserInput(uint32_t uTypeIdx, float64_t dUserInput);
/****** Command Table *******/
enum dsfunc_commands
{
DS_FUNC_CMD_SET_ANGLE,
DS_FUNC_CMD_SET_MODULE,
DS_FUNC_CMD_SET_CHANNEL,
DS_FUNC_CMD_COUNT
};
/****** User Input Table *******/
enum dsfunc_userInputs
{
DS_USER_INPUT_READ_REG,
DS_USER_INPUT_WRITE_REG,
DS_USER_INPUT_SET_ANGLE,
DS_USER_INPUT_SET_EXP_VLL,
DS_USER_INPUT_SET_EXP_VREF,
DS_USER_INPUT_SET_VLL_THRESHOLD,
DS_USER_INPUT_SET_VREF_THRESHOLD,
DS_USER_INPUT_FIX_RATIO_MODE,
DS_USER_INPUT_CHAN_STATUS_ENABLE,
DS_USER_INPUT_POWER,
DS_USER_INPUT_REFRESH,
DS_USER_INPUT_QUIT,
DS_USER_INVALID_INPUT,
DS_USER_INPUT_COUNT
};
/* "what to type", "what is displayed", assigned cmd #, function called */
struct dsdemofunc_cmdtbl {
int8_t *cmdstr;
int8_t *menustr;
int32_t cmdnum;
void(*func)(int32_t cardIndex, int32_t module, int32_t channel);
};
/* assigned cmd #, uppwer Limit, lower Limit*/
struct dsUserInputLimitTable {
int32_t cmdnum;
int8_t *cmdstr;
float64_t upperLimit;
float64_t lowerLimit;
};
/****** Command Tables *******/
static struct dsdemofunc_cmdtbl DS_DemoFuncMenuCmds[] = {
{(int8_t *)"ANG", (int8_t *)"Run Angle", DS_FUNC_CMD_SET_ANGLE, DS_RunAngleFunc},\
{(int8_t *)"M ", (int8_t *)"Select Module", DS_FUNC_CMD_SET_MODULE, NULL},\
{(int8_t *)"C ", (int8_t *)"Select Channel", DS_FUNC_CMD_SET_CHANNEL, NULL},\
{NULL, NULL, 0, NULL}
};
/****** User Input Command Tables *******/
static struct dsdemofunc_cmdtbl DS_DemoUserInputs[] = {
{(int8_t *)"READ ", (int8_t *)"Read Register", DS_USER_INPUT_READ_REG, NULL },\
{(int8_t *)"WRITE ", (int8_t *)"Write Register", DS_USER_INPUT_WRITE_REG, NULL}, \
{(int8_t *)"ANG ", (int8_t *)"Set Angle", DS_USER_INPUT_SET_ANGLE, DS_SetNewAngle},
{(int8_t *)"VLL ", (int8_t *)"Set Exp. VLL", DS_USER_INPUT_SET_EXP_VLL, DS_SetExpVLL},
{(int8_t *)"VREF ", (int8_t *)"Set Exp. Ref Volt", DS_USER_INPUT_SET_EXP_VREF, DS_SetExpVref},
{(int8_t *)"VLLTH ", (int8_t *)"Set VLL Threshold Volt", DS_USER_INPUT_SET_VLL_THRESHOLD, DS_SetVllThrehold},
{(int8_t *)"REFTH ", (int8_t *)"Set VREF Threshold Volt", DS_USER_INPUT_SET_VREF_THRESHOLD, DS_SetVrefThreshold},
{(int8_t *)"MODE ", (int8_t *)"Set Fixed / Ratio Mode", DS_USER_INPUT_FIX_RATIO_MODE, DS_SetFixedRatioMode},
{(int8_t *)"CSTATUS", (int8_t *)"Set Chan Status Enable(Formally Active Chan.)", DS_USER_INPUT_CHAN_STATUS_ENABLE, DS_SetChannelStatusCtrl},
{(int8_t *)"PWR ", (int8_t *)"Set Power", DS_USER_INPUT_POWER, DS_SetPower},
{(int8_t *)"U", (int8_t *)"Update", DS_USER_INPUT_REFRESH, NULL},
{(int8_t *)"Q ", (int8_t *)"Quit", DS_USER_INPUT_QUIT, NULL},
{(int8_t *)"", (int8_t *)"", DS_USER_INVALID_INPUT, NULL},
{NULL, NULL, 0, NULL}
};
static struct dsUserInputLimitTable DS_Inputs_Limits[] = {
{DS_USER_INPUT_READ_REG, (int8_t *)"Read Reg.", (float64_t)((2 ^ 32) - 1), -(float64_t)((2 ^ 32) - 1)},
{DS_USER_INPUT_WRITE_REG, (int8_t *)"Write Reg.", (float64_t)((2 ^ 32) - 1), -(float64_t)((2 ^ 32) - 1)},
{DS_USER_INPUT_SET_ANGLE, (int8_t *)"Angle", 359.9954, 0.0},
{DS_USER_INPUT_SET_EXP_VLL, (int8_t *)"Exp VLL", 115.0, 0.0},
{DS_USER_INPUT_SET_EXP_VREF, (int8_t *)"Exp Vref", 115.0, 0.0},
{DS_USER_INPUT_SET_VLL_THRESHOLD, (int8_t *)"VLL Threshold", 115.0, 0.0},
{DS_USER_INPUT_SET_VREF_THRESHOLD, (int8_t *)"Vref Threshold", 115.0, 0.0},
{DS_USER_INPUT_FIX_RATIO_MODE, (int8_t *)"Ratio/Fixed Mode", 1.0, 0.0},
{DS_USER_INPUT_CHAN_STATUS_ENABLE, (int8_t *)"Active Channel", 1.0, 0.0},
{DS_USER_INPUT_POWER, (int8_t *)"Set Power", 1.0, 0.0},
{DS_USER_INPUT_QUIT, (int8_t *)"", 0.0, 0.0},
{DS_USER_INVALID_INPUT, (int8_t *)"", 0.0, 0.0},
{DS_USER_INPUT_COUNT, (int8_t *)"", 0.0, 0.0}
};
#if defined (__VXWORKS__)
int32_t DS_RunAngleProgramSample(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))
{
DS_RunAngleProgram(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>
DS_RunAngleProgram queries the user for the module and channel to configure for DS output.
</summary>
*/
/**************************************************************************************************************/
static void DS_RunAngleProgram(int32_t cardIndex, int32_t module, uint32_t moduleID)
{
bool_t bQuit;
int32_t channel = 0;
int32_t MaxModule = 0;
int32_t MaxChannel = 0;
int32_t cmdIdx;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get the number of D/S channels on the module */
moduleID = naibrd_GetModuleID(cardIndex, module);
MaxChannel = naibrd_DS_GetChannelCount(moduleID);
/*Show data*/
do
{
Show_DSDemoFunc_Commands();
printf("\nType DS command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
for (cmdIdx = 0; cmdIdx < DS_FUNC_CMD_COUNT; cmdIdx++)
{
if (0 == naiapp_strnicmp((const int8_t*)inputBuffer, (const int8_t*)DS_DemoFuncMenuCmds[cmdIdx].cmdstr, inputResponseCnt))
break;
}
switch (cmdIdx)
{
case DS_FUNC_CMD_SET_ANGLE:
if ((module > 0) && (channel > 0))
DS_RunAngleFunc(cardIndex, module, channel);
break;
case DS_FUNC_CMD_SET_MODULE:
printf("\nEnter Module Number:\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
module = atoi((const char *)inputBuffer);
if ((module < 1) || (module > MaxModule))
{
printf("\n%s: %d is outside the limits[%d - %d]", "Module #", module, 1, MaxModule);
}
break;
case DS_FUNC_CMD_SET_CHANNEL:
printf("\nEnter Channel Number:\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
channel = atoi((const char *)inputBuffer);
if ((channel < 1) || (channel > MaxChannel))
{
printf("\n%s: %d is outside the limits[%d - %d]", "Channel #", channel, 1, MaxChannel);
}
break;
default:
break;
}
}
} while (bQuit == FALSE);
}
static void Show_DSDemoFunc_Commands(void)
{
int i;
printf("\n\t\t DS Set Angle Menu");
printf("\n\t\t =================\n");
printf("\n\nCommands");
printf("\n--------");
for (i = 0; i < DS_FUNC_CMD_COUNT && DS_DemoFuncMenuCmds[i].cmdstr != NULL; i++)
printf("\n%s\t%s", DS_DemoFuncMenuCmds[i].cmdstr, DS_DemoFuncMenuCmds[i].menustr);
printf("\n");
}
static void Show_SetAngle_UserInput_Commands(void)
{
int i;
printf("\n\t\t Set Angle User Inputs\n ");
printf("\n\nCommands");
for (i = 0; i < DS_USER_INPUT_COUNT && DS_DemoUserInputs[i].cmdstr != NULL; i++)
printf("\n%s\t%s", DS_DemoUserInputs[i].cmdstr, DS_DemoUserInputs[i].menustr);
printf("\n");
}
/*This function puts the specific D/S channel in roation mode. The
user can set the following set angle attributes:
1. Set Angle.
2. Set Expected VLL.
3. Set Expected VREF.
4. Set VLL Threshold.
5. Set VREF Threshold.
6. Set Fixed/Ratio Mode.
7. Set Active Channel.
8. Set Power.
*/
static void DS_RunAngleFunc(int32_t cardIndex, int32_t module, int32_t channel)
{
uint32_t udUserInput;
bool_t bYes = FALSE;
printf("\n================================================================");
printf("\nThis program allows the user to set the output angle of a ");
printf("\nspecified channel of a D/S module. The user can change the ");
printf("\nfollowing module properties. ");
printf("\n1. Set Angle.");
printf("\n2. Set Expected VLL");
printf("\n3. Set Expected VREF");
printf("\n4. Set VLL Threshold");
printf("\n5. Set VREF Threshold");
printf("\n6. Set Fixed/Ratio Mode");
printf("\n7. Set Active Channel");
printf("\n8. Set Module Power");
printf("\n================================================================\n");
do
{
DS_ShowSetAngleTestResult(cardIndex, module, channel);
showCurrentModChan(module, channel);
Show_SetAngle_UserInput_Commands();
if (getUserInput() >= 0)
{
udUserInput = (uint32_t)getUserInput();
switch (udUserInput)
{
case DS_USER_INPUT_READ_REG:
case DS_USER_INPUT_WRITE_REG:
case DS_USER_INPUT_SET_ANGLE:
case DS_USER_INPUT_SET_EXP_VLL:
case DS_USER_INPUT_SET_EXP_VREF:
case DS_USER_INPUT_SET_VLL_THRESHOLD:
case DS_USER_INPUT_SET_VREF_THRESHOLD:
case DS_USER_INPUT_FIX_RATIO_MODE:
case DS_USER_INPUT_CHAN_STATUS_ENABLE:
case DS_USER_INPUT_POWER:
DS_DemoUserInputs[udUserInput].func(cardIndex, module, channel);
break;
case DS_USER_INPUT_QUIT:
bYes = TRUE;
break;
case DS_USER_INPUT_REFRESH:
case DS_USER_INVALID_INPUT:
break;
}
}
} while (bYes == FALSE);
}
static void DS_ShowSetAngleTestResult(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
uint32_t unValue = 0;
uint8_t u8Status[10];
uint8_t u8Value = 0;
memset(u8Status, 0, sizeof(u8Status));
printf("\nSet angle Meas angle VLL VRef Mode Meas. VLL Meas. VRef Meas.RFreq VLL.Thres VREF.Thres Multi-Spd Status Act.Chan. Power \n");
printf("\n Ratio S/R/B/P ");
printf("\n---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- \n");
/*Set Angle*/
check_status(naibrd_DS_GetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, &dValue));
printf("%-12.4f", dValue);
/*get measured angle*/
check_status(naibrd_DS_GetMeasuredValue(cardIndex, module, channel, NAI_DS_MEASURED_ANGLE, &dValue));
printf("%-12.4f", dValue); /*wrap angle*/
/*expected VLl */
check_status(naibrd_DS_GetExpectedVoltage(cardIndex, module, channel, NAI_DS_EXP_VOLT_SIGNAL, &dValue));
printf("%-12.4f", dValue); /*expected Vll*/
/*expected Vref */
check_status(naibrd_DS_GetExpectedVoltage(cardIndex, module, channel, NAI_DS_EXP_VOLT_REFERENCE, &dValue));
printf("%-12.4f", dValue); /*expected VRef*/
/*fixed/ratio mode */
check_status(naibrd_DS_GetRatioFixedMode(cardIndex, module, channel, &unValue));
if ((nai_ds_output_ratio_fixed_mode_t)unValue == NAI_DS_OUTPUT_RATIO)
printf("%-12s", DS_RATIO); /*Ratio*/
else
printf("%-12s", DS_FIXED); /*Fixed*/
/*measured Vll */
check_status(naibrd_DS_GetMeasuredValue(cardIndex, module, channel, NAI_DS_MEASURED_SIGNAL_VOLTAGE, &dValue));
printf("%-12.4f", dValue); /*meas Vll*/
/*measured Vref */
check_status(naibrd_DS_GetMeasuredValue(cardIndex, module, channel, NAI_DS_MEASURED_REF_VOLTAGE, &dValue));
printf("%-12.4f", dValue); /*meas Vref*/
/*measured RefFreq */
check_status(naibrd_DS_GetMeasuredValue(cardIndex, module, channel, NAI_DS_MEASURED_REF_FREQUENCY, &dValue));
printf("%-12.4f", dValue); /*meas RefFreq*/
/*Vll Threshold*/
check_status(naibrd_DS_GetThresholdVoltage(cardIndex, module, channel, NAI_DS_THRESHOLD_VOLT_SIGNAL, &dValue));
printf("%-12.4f", dValue); /*VLL Threshold*/
/*VREF Threshold*/
check_status(naibrd_DS_GetThresholdVoltage(cardIndex, module, channel, NAI_DS_THRESHOLD_VOLT_REFERENCE, &dValue));
printf("%-12.4f", dValue); /*VREF Threshold*/
/*Multi-Spd*/
check_status(naibrd_DS_GetMultiSpeedRatio(cardIndex, module, NAI_DS_MULTI_SPD_CH1_2_PAIR, &unValue));
printf("%-12d", unValue); /*Multi-Spd*/
/*get Status: S=Signal Loss, R=Reference Loss, B=BIT Loss, P=Phase Loss*/
getStatus(cardIndex, module, channel, u8Status);
printf("%-12s", u8Status); /*status*/
/*get Channel Status Enable (formly Active Channel))*/
check_status(naibrd_DS_GetChanStatusEnable(cardIndex, module, channel, &unValue));
if (unValue == NAI_ENABLE)
printf("%-12s", DS_ENABLE);
else
printf("%-12s", DS_DISABLE);
/*get power State*/
check_status(naibrd_DS_GetPowerEnable(cardIndex, module, channel, &u8Value));
if (u8Value == NAI_ENABLE)
printf("%-12s", DS_ENABLE);
else
printf("%-12s", DS_DISABLE);
printf("\n");
}
static void DS_SetNewAngle(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter New Angle\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ANGLE, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ANGLE, dValue);
else
{
/*Set angle*/
check_status(naibrd_DS_SetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, dValue));
}
}
static void DS_SetExpVLL(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter Expected D/S VLL\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_EXP_VLL, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_EXP_VLL, dValue);
else
{
/*Set expected VLL*/
check_status(naibrd_DS_SetExpectedVoltage(cardIndex, module, channel, NAI_DS_EXP_VOLT_SIGNAL, dValue));
}
}
static void DS_SetExpVref(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter Expected D/S VREF\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_EXP_VREF, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_EXP_VREF, dValue);
else
{
/*Set expected VREF*/
check_status(naibrd_DS_SetExpectedVoltage(cardIndex, module, channel, NAI_DS_EXP_VOLT_REFERENCE, dValue));
}
}
static void DS_SetVllThrehold(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter VLL THRESHOLD\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_VLL_THRESHOLD, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_VLL_THRESHOLD, dValue);
else
{
/*Set VLL Threshold*/
check_status(naibrd_DS_SetThresholdVoltage(cardIndex, module, channel, NAI_DS_THRESHOLD_VOLT_SIGNAL, dValue));
}
}
static void DS_SetVrefThreshold(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter VREF THRESHOLD\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_VREF_THRESHOLD, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_VREF_THRESHOLD, dValue);
else
{
/*Set VLL Threshold*/
check_status(naibrd_DS_SetThresholdVoltage(cardIndex, module, channel, NAI_DS_THRESHOLD_VOLT_REFERENCE, dValue));
}
}
static void DS_SetFixedRatioMode(int32_t cardIndex, int32_t module, int32_t channel)
{
uint32_t unValue = 0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter Fixed/Ratio Mode [Fixed = 1, Ratio = 0]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
unValue = atoi((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_FIX_RATIO_MODE, unValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_FIX_RATIO_MODE, unValue);
else
{
/*Set Fixed/Ratio Mode*/
check_status(naibrd_DS_SetRatioFixedMode(cardIndex, module, channel, unValue));
}
}
static void DS_SetChannelStatusCtrl(int32_t cardIndex, int32_t module, int32_t channel)
{
uint32_t unValue = 0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nSet Active Channel [Disable = 0, Enable = 1]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
unValue = atoi((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_CHAN_STATUS_ENABLE, unValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_CHAN_STATUS_ENABLE, unValue);
else
{
/*Set channel status enable (formly active channel)*/
check_status(naibrd_DS_SetChanStatusEnable(cardIndex, module, channel, unValue));
}
}
static void DS_SetPower(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nSet Power[DISABLE = 0, ENABLE = 1]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_POWER, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_POWER, dValue);
else
{
/*Stop Rotation*/
check_status(naibrd_DS_SetPowerEnable(cardIndex, module, channel, (uint8_t)dValue));
}
}
static int32_t getUserInput()
{
uint32_t unCmdNumber = 0;
int8_t str1[80];
int8_t str2[80];
int32_t dCommand = -1;
int32_t x;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (inputResponseCnt > 0)
{
for (unCmdNumber = 0; unCmdNumber < DS_USER_INPUT_COUNT && DS_DemoUserInputs[unCmdNumber].cmdstr != NULL; unCmdNumber++)
{
memset(str1, 0, sizeof(str1));
memset(str2, 0, sizeof(str2));
strncpy((char*)str1, (const char*)DS_DemoUserInputs[unCmdNumber].cmdstr, inputResponseCnt);
strncpy((char*)str2, (const char*)inputBuffer, inputResponseCnt);
for (x = 0; x < inputResponseCnt; x++)
{
str1[x] = (int8_t)toupper(str1[x]);
str2[x] = (int8_t)toupper(str2[x]);
}
if (strncmp((const char*)str1, (const char*)str2, inputResponseCnt) == 0)
{
dCommand = unCmdNumber;
break;
}
}
}
return(dCommand);
}
static bool_t checkUserInput(uint32_t uTypeIdx, float64_t dUserInput)
{
bool_t bValidInput = FALSE;
if ((dUserInput > DS_Inputs_Limits[uTypeIdx].upperLimit) || (dUserInput < DS_Inputs_Limits[uTypeIdx].lowerLimit))
bValidInput = TRUE;
return(bValidInput);
}
static void printInvalidUserInputMessage(uint32_t uTypeIdx, float64_t dUserInput)
{
printf("\n%s: %0.4f is outside the limits[%0.4f - %0.4f]", DS_Inputs_Limits[uTypeIdx].cmdstr, dUserInput, DS_Inputs_Limits[uTypeIdx].lowerLimit, DS_Inputs_Limits[uTypeIdx].upperLimit);
}
static void showCurrentModChan(int32_t nModule, int32_t nChannel)
{
printf("\nModule :%d", nModule);
printf("\nChannel :%d", nChannel);
}
static void getStatus(int32_t cardIndex, int32_t module, int32_t channel, uint8_t *u8Status)
{
uint32_t unSingalLoss = 0;
uint32_t unRefLoss = 0;
uint32_t unBitLoss = 0;
uint32_t unPhaseLoss = 0;
check_status(naibrd_DS_GetStatus(cardIndex, module, channel, NAI_DS_STATUS_REAL_TIME_SIGNAL_LOST, &unSingalLoss));
check_status(naibrd_DS_GetStatus(cardIndex, module, channel, NAI_DS_STATUS_REAL_TIME_REFERENCE_LOST, &unRefLoss));
check_status(naibrd_DS_GetStatus(cardIndex, module, channel, NAI_DS_STATUS_REAL_TIME_BIT_LOST, &unBitLoss));
check_status(naibrd_DS_GetStatus(cardIndex, module, channel, NAI_DS_STATUS_REAL_TIME_PHASE_LOST, &unPhaseLoss));
/*SIG*/
if ((nai_ds_module_status_t)unSingalLoss == NAI_DS_MODULE_STATUS_GOOD)
*u8Status++ = DS_STATUS_GOOD[0];
else
*u8Status++ = DS_STATUS_BAD[0];
*u8Status++ = SYM_SLASH[0];
/*REF*/
if ((nai_ds_module_status_t)unRefLoss == NAI_DS_MODULE_STATUS_GOOD)
*u8Status++ = DS_STATUS_GOOD[0];
else
*u8Status++ = DS_STATUS_BAD[0];
*u8Status++ = SYM_SLASH[0];
/*BIT*/
if ((nai_ds_module_status_t)unBitLoss == NAI_DS_MODULE_STATUS_GOOD)
*u8Status++ = DS_STATUS_GOOD[0];
else
*u8Status++ = DS_STATUS_BAD[0];
*u8Status++ = SYM_SLASH[0];
/*PLL*/
if ((nai_ds_module_status_t)unPhaseLoss == NAI_DS_MODULE_STATUS_GOOD)
*u8Status++ = DS_STATUS_GOOD[0];
else
*u8Status++ = DS_STATUS_BAD[0];
}