DS MultiSpd
Edit this on GitLab
DS MultiSpd
Explanation
About the Sample Application Code
This sample application code demonstrates how to interact with embedded function modules from North Atlantic Industries (NAI) using their Software Support Kit (SSK). The application is written in C and handles tasks such as querying user inputs, configuring settings, and displaying status information for a Direct/Sync (DS) module. Below is a detailed explanation of different parts of the code.
Includes
#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"
These headers provide standard C library functions and specific functions for interacting with NAI’s hardware modules.
Config File and Function Prototypes
static const int8_t *CONFIG_FILE = (int8_t *)"default_DsMultiSpd.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, int32_t maxModule);
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_SetMultiSpd(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 uint32_t getUserInput(void);
static bool_t checkUserInput(uint32_t uTypeIdx, float64_t dUserInput);
These are the function prototypes used in the application. They handle various operations such as displaying results, running programs, setting angles and thresholds, and managing user input.
Enumerations and Struct Definitions
enum dsfunc_commands
{
DS_FUNC_CMD_SET_ANGLE,
DS_FUNC_CMD_SET_MODULE,
DS_FUNC_CMD_COUNT
};
enum dsfunc_userInputs
{
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_MULT_SPD,
DS_USER_INPUT_POWER,
DS_USER_INPUT_REFRESH,
DS_USER_INPUT_QUIT,
DS_USER_INVALID_INPUT,
DS_USER_INPUT_COUNT
};
struct dsdemofunc_cmdtbl {
int8_t *cmdstr;
int8_t *menustr;
int32_t cmdnum;
void (*func)(int32_t cardIndex, int32_t module, int32_t channel);
};
struct dsUserInputLimitTable {
int32_t cmdnum;
int8_t *cmdstr;
float64_t upperLimit;
float64_t lowerLimit;
};
These define the command and user input types in enumeration form and set up structures for command tables and input limits.
Command Tables
static struct dsdemofunc_cmdtbl DS_DemoFuncMenuCmds[] = {
{(int8_t *)"RM", (int8_t *)"Run Multi-speed", DS_FUNC_CMD_SET_ANGLE, DS_RunAngleFunc},
{(int8_t *)"M ", (int8_t *)"Select Module", DS_FUNC_CMD_SET_MODULE, NULL},
{NULL, NULL, 0, NULL}
};
static struct dsdemofunc_cmdtbl DS_DemoUserInputs[] = {
{(int8_t *)"ANG ", (int8_t *)"Set Multi-speed 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 *)"MULTSPD", (int8_t *)"Set Mulit Speed Ratio", DS_USER_INPUT_MULT_SPD, DS_SetMultiSpd},
{(int8_t *)"PWR ", (int8_t *)"Set Power", DS_USER_INPUT_POWER, DS_SetPower},
{(int8_t *)"UPDATE ", (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_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_MULT_SPD, (int8_t *)"Multi Speed", 255.0, 1.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 }
};
These tables define commands available to the user along with their corresponding functions and limit values.
Main Function
#if defined (__VXWORKS__)
int32_t DS_RunMultSpdProgramSample(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t moduleCnt;
int32_t cardIndex;
int32_t module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == (bool_t)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)
{
DS_RunAngleProgram(cardIndex, module, moduleCnt);
}
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 is the main function of the application. It handles the setup and execution of the main program loop, querying the user for actions, and processes commands according to user inputs.
Functions Overview
DS_RunAngleProgram
static void DS_RunAngleProgram(int32_t cardIndex, int32_t module, int32_t maxModule)
{
bool_t bQuit;
int32_t channel = 0;
int32_t cmdIdx;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
channel = 1;
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)
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;
default:
break;
}
}
} while (bQuit == FALSE);
}
This function handles querying the user for module and channel information, displaying available commands, and performing actions based on user input.
Other Functions
The rest of the functions are used for setting various configurations on the DS module, querying for inputs, and displaying status information. Each configuration function (e.g., DS_SetNewAngle
, DS_SetExpVLL
) adjusts specific properties of the DS module based on user input.
Example Helper Functions
-
DS_ShowSetAngleTestResult
: Displays test results for the angle settings. -
Show_DSDemoFunc_Commands
: Prints available command options. -
Show_MultiSpd_UserInput_Commands
: Prints user input options for multi-speed settings.
These helper functions facilitate user interaction by providing clear feedback and options.
Overall, this application is designed to assist developers in configuring and testing NAI’s DS modules efficiently. The flow of the program ensures that users can navigate through different settings, make changes, and review the outcomes interactively.
#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_DsMultiSpd.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, int32_t maxModule);
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_SetMultiSpd(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 uint32_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_COUNT
};
/****** User Input Table *******/
enum dsfunc_userInputs
{
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_MULT_SPD,
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 *)"RM", (int8_t *)"Run Multi-speed", DS_FUNC_CMD_SET_ANGLE, DS_RunAngleFunc},\
{(int8_t *)"M ", (int8_t *)"Select Module", DS_FUNC_CMD_SET_MODULE, NULL},\
{NULL, NULL, 0, NULL}
};
/****** User Input Command Tables *******/
static struct dsdemofunc_cmdtbl DS_DemoUserInputs[] = {
{(int8_t *)"ANG ", (int8_t *)"Set Multi-speed 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 *)"MULTSPD", (int8_t *)"Set Mulit Speed Ratio", DS_USER_INPUT_MULT_SPD, DS_SetMultiSpd},
{(int8_t *)"PWR ", (int8_t *)"Set Power", DS_USER_INPUT_POWER, DS_SetPower},
{(int8_t *)"UPDATE ", (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_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_MULT_SPD, (int8_t *)"Multi Speed", 255.0, 1.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_RunMultSpdProgramSample(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t moduleCnt;
int32_t cardIndex;
int32_t module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == (bool_t)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));
/* Select Module */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
DS_RunAngleProgram(cardIndex, module, moduleCnt);
}
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, int32_t maxModule)
{
bool_t bQuit;
int32_t channel = 0;
int32_t cmdIdx;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
channel = 1;
/*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)
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;
default:
break;
}
}
} while (bQuit == FALSE);
}
static void Show_DSDemoFunc_Commands(void)
{
int i;
printf("\n\t\t DS Set Multi Speed 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_MultiSpd_UserInput_Commands(void)
{
int i;
printf("\n\t\t Multi-Speed 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 multi-speed 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 multi-speed ratio in ");
printf("\na D/S module. It also reports back its measured coarse and ");
printf("\nfine angle of the channel. The following D/S properties can ");
printf("\nbe changed by the upser: ");
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 Mulit-speed ratio");
printf("\n8. Set Module Power");
printf("\n================================================================\n");
do
{
DS_ShowSetAngleTestResult(cardIndex, module, channel);
showCurrentModChan(module, channel);
Show_MultiSpd_UserInput_Commands();
udUserInput = getUserInput();
switch(udUserInput)
{
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_MULT_SPD:
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;
uint32_t unCoarseChan = 1;
uint32_t unFineChan = 2;
memset(u8Status, 0, sizeof(u8Status));
printf("\nSet angle Meas angle Meas angle Multi Spd VLL VRef Mode Meas. VLL Meas. VRef Meas.RFreq VLL.Thres VREF.Thres Power \n");
printf("\n (coarse) (fine) ratio ");
printf("\n---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- \n");
/*Set Angle*/
check_status( naibrd_DS_GetAngle(cardIndex, module, unCoarseChan, NAI_DS_ANGLE_TWO_SPEED, &dValue ) );
printf("%-12.4f",dValue);
/*get measured coarse angle Ch1*/
check_status( naibrd_DS_GetMeasuredValue( cardIndex, module, unCoarseChan, NAI_DS_MEASURED_ANGLE, &dValue) );
printf("%-12.4f",dValue);
/*get measured fine angle Ch2*/
check_status( naibrd_DS_GetMeasuredValue( cardIndex, module, unFineChan, NAI_DS_MEASURED_ANGLE, &dValue) );
printf("%-12.4f",dValue);
/*get multi-speed ratio*/
check_status( naibrd_DS_GetMultiSpeedRatio( cardIndex, module, NAI_DS_MULTI_SPD_CH1_2_PAIR, &unValue) );
printf("%-12d",unValue);
/*expected VLl */
check_status( naibrd_DS_GetExpectedVoltage( cardIndex, module, channel, NAI_DS_EXP_VOLT_SIGNAL, &dValue) );
printf("%-12.4f",dValue);
/*expected Vref */
check_status( naibrd_DS_GetExpectedVoltage( cardIndex, module, channel, NAI_DS_EXP_VOLT_REFERENCE, &dValue) );
printf("%-12.4f",dValue);
/*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*/
/*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;
uint32_t unCoarseChan = 1;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
channel = unCoarseChan;
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, unCoarseChan, NAI_DS_ANGLE_TWO_SPEED, 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_SetMultiSpd(int32_t cardIndex, int32_t module, int32_t channel)
{
uint32_t unValue = 0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
channel = 0;
printf("\nSet Multi Speed Ratio [1-255]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
unValue = atoi((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_MULT_SPD, unValue);
if(bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_MULT_SPD, unValue);
else
{
check_status( naibrd_DS_SetMultiSpeedRatio(cardIndex, module, NAI_DS_MULTI_SPD_CH1_2_PAIR, (uint32_t)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
{
/*power*/
check_status( naibrd_DS_SetPowerEnable(cardIndex, module, channel, (uint8_t)dValue ) );
}
}
static uint32_t getUserInput()
{
uint32_t unCmdNumber=0;
int8_t str1[80];
int8_t str2[80];
uint32_t udCommand=0;
int32_t x;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
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)
{
udCommand = unCmdNumber;
break;
}
}
return(udCommand);
}
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)
{
nChannel = 1;
printf("\nModule :%d", nModule);
printf("\nChannel :%d", nChannel);
}