DS Rotation
Edit this on GitLab
DS Rotation
Explanation
About the Sample Application Code
This C application code is designed to interact with North Atlantic Industries' (NAI) embedded function modules using the Software Support Kit (SSK). It provides functions to configure, control, and monitor Data/Signal (DS) rotation modules on a specified card. Below is an explanation of the components and the flow of the application.
Key Components
-
Header Files:
-
#include <stdio.h>
: Standard input/output library. -
#include <stdlib.h>
: Standard library for memory allocation, process control, etc. -
#include <string.h>
: String handling functions. -
#include <time.h>
: Time and date functions. -
#include <math.h>
: Math library functions. -
#include <ctype.h>
: Character type functions. -
Custom headers from NAI for board and display access along with utility functions.
-
#include "DS_Common.h"
: Common definitions and declarations. -
#include "nai.h"
: Main NAI library. -
#include "naibrd.h"
: NAI board-specific functions. -
#include "functions/naibrd_ds.h"
: Functions specific to Data/Signal modules. -
#include "advanced/nai_ether_adv.h"
: Advanced Ethernet functions.
-
-
Constants and Variables:
-
CONFIG_FILE
: Path to the default configuration file. -
Various function prototypes for handling DS rotation configuration and controls.
-
-
Enumerations:
-
dsfunc_commands
: Lists main commands for the DS rotation functionality. -
dsfunc_userInputs
: Enumerations for expected user inputs.
-
-
Structures:
-
dsdemofunc_cmdtbl
: Command table for main DS demo functions. -
dsUserInputLimitTable
: Defines limits for user inputs.
-
-
Main Function (
main
):-
Initializes and runs the board menu using the configuration file.
-
Queries the user for card index and module number.
-
Runs the
Run_DS_Rotation
function based on user inputs. -
Provides an option to quit or restart the application.
-
Functions
-
Run_DS_Rotation (int32_t cardIndex, int32_t module, uint32_t moduleID):
-
Queries the user for the module and channel to configure for DS output.
-
Displays available commands and processes user inputs.
-
-
Show_DSDemoFunc_Commands (void):
-
Displays the DS rotation command menu.
-
-
DS_SetRotation (int32_t cardIndex, int32_t module, int32_t channel):
-
Enables and sets rotation parameters like rate, mode, start/stop angles, and power for the specified card, module, and channel.
-
-
DS_ShowSetRotationTestResult (int32_t cardIndex, int32_t module, int32_t channel):
-
Displays the current settings and state of the DS rotation for the specified channel.
-
-
DS_SetRotationRate, DS_SetRotationMode, DS_SetRotationStartAngle, DS_SetRotationStopAngle, DS_StartRotation, DS_StopRotation, DS_SetPower:
-
These functions capture user input for various DS rotation parameters and apply the settings.
-
-
checkUserInput (uint32_t uTypeIdx, float64_t dUserInput):
-
Validates the user input against the defined limits.
-
-
printInvalidUserInputMessage (uint32_t uTypeIdx, float64_t dUserInput):
-
Prints an error message if the user input is outside the valid range.
-
Application Flow
-
Initialization:
-
The application begins by setting up the board using the default configuration file.
-
-
User Interaction:
-
The user is prompted to enter the card index and module number for the board they wish to configure.
-
-
Run_DS_Rotation:
-
Based on the card index and module number, the
Run_DS_Rotation
function is invoked to manage the DS rotation settings.
-
-
Command Input:
-
Users are presented with a menu of commands to configure the DS rotation parameters.
-
Functions are called based on user input to modify the rotation rate, mode, start/stop angles, and other parameters.
-
-
Display and Validation:
-
The application validates user inputs and displays current settings and statuses.
-
-
Loop and Exit:
-
The application loops until the user decides to quit, after which it closes all open connections and exits gracefully.
-
Conclusion
This application provides a comprehensive interface to configure and control DS rotation modules on NAI’s embedded function modules. The code is structured to prompt user inputs, validate them, apply settings, and display the current state, making it an essential tool for users working with NAI’s DS modules.
#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_DsRotation.txt";
/* Function prototypes */
static void Run_DS_Rotation(int32_t cardIndex, int32_t module, uint32_t moduleID);
static void Show_DSDemoFunc_Commands(void);
static void DS_SetRotation(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_ShowSetRotationTestResult(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationRate(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationMode(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationStartAngle(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationStopAngle(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_StartRotation(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_StopRotation(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetPower(int32_t cardIndex, int32_t module, int32_t channel);
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_ROTATION,
DS_FUNC_CMD_SET_MODULE,
DS_FUNC_CMD_SET_CHANNEL,
DS_FUNC_CMD_COUNT
};
/****** User Input Table *******/
enum dsfunc_userInputs
{
DS_USER_INPUT_SET_ROT_RATE,
DS_USER_INPUT_SET_ROT_MODE,
DS_USER_INPUT_SET_ROT_START_ANG,
DS_USER_INPUT_SET_ROT_STOP_ANG,
DS_USER_INPUT_INITIATE_ROTATION,
DS_USER_INPUT_STOP_ROTATION,
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 *)"RR", (int8_t *)"Run Rotation", DS_FUNC_CMD_SET_ROTATION, DS_SetRotation},\
{(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 *)"RATE", (int8_t *)"Set Rotation Rate", DS_USER_INPUT_SET_ROT_RATE, DS_SetRotationRate},
{(int8_t *)"MODE", (int8_t *)"Set Rotation Mode", DS_USER_INPUT_SET_ROT_MODE, DS_SetRotationMode},
{(int8_t *)"STRANG", (int8_t *)"Set Rotation Start Angle", DS_USER_INPUT_SET_ROT_START_ANG, DS_SetRotationStartAngle},
{(int8_t *)"STPANG", (int8_t *)"Set Rotation Stop Angle", DS_USER_INPUT_SET_ROT_STOP_ANG, DS_SetRotationStopAngle},
{(int8_t *)"STRROT", (int8_t *)"Start Rotation", DS_USER_INPUT_INITIATE_ROTATION, DS_StartRotation},
{(int8_t *)"STPROT", (int8_t *)"Stop Rotation", DS_USER_INPUT_STOP_ROTATION, DS_StopRotation},
{(int8_t *)"PWER", (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_ROT_RATE, (int8_t *)"Rot. Rate", 1000.0, -1000.0 },
{DS_USER_INPUT_SET_ROT_MODE, (int8_t *)"Rot. Mode", 1.0, 0.0 },
{DS_USER_INPUT_SET_ROT_START_ANG, (int8_t *)"Rot. Start Angle", 359.9954, 0.0 },
{DS_USER_INPUT_SET_ROT_STOP_ANG, (int8_t *)"Rot. Stop Angle", 359.9954, 0.0 },
{DS_USER_INPUT_INITIATE_ROTATION, (int8_t *)"Start Rot", 1.0, 0.0 },
{DS_USER_INPUT_STOP_ROTATION, (int8_t *)"Stop Rot.", 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 Run_DS_RotationSample(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_DS_Rotation(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_DS_Rotation queries the user for the module and channel to configure for DS output.
</summary>
*/
/**************************************************************************************************************/
static void Run_DS_Rotation(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_ROTATION:
if ((module > 0) && (channel > 0))
DS_SetRotation(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 Rotation 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_Rotation_UserInput_Commands(void)
{
int i;
printf("\n\t\t Rotation 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 rotation attributes:
1. Rotation Rate.
2. Rotation Mode (Continuous / Start-stop).
3. Rotation Start Angle.
4. Rotation Stop Angle.
5. Initiate Rotation
6. Stop Rotation
This function sets rotation trigger source to internal(software) and
the user can query the current rotation state. */
static void DS_SetRotation(int32_t cardIndex, int32_t module, int32_t channel)
{
uint32_t udUserInput;
bool_t bYes = FALSE;
printf("\n================================================================");
printf("\nThis program puts the specific D/S channel in roation mode.");
printf("\nThe user can set the following rotation attributes:");
printf("\n1. Rotation Rate.");
printf("\n2. Rotation Mode (Continuous / Start-stop).");
printf("\n3. Rotation Start Angle");
printf("\n4. Rotation Stop Angle");
printf("\n5. Initiate Rotation");
printf("\n6. Stop Rotation");
printf("\n7. Set Module Power");
printf("\nThe rotation trigger source is set to internal(software trigger) ");
printf("\nand the user can query the current rotation state.\n");
printf("\n================================================================");
/*set up voltage threshold*/
/* check_status( naibrd_DS_SetThresholdVoltage(cardIndex, module, channel, NAI_DS_THRESHOLD_VOLT_REFERENCE, dDSExpRefVolt * THRESHOLD_VOLT_GAIN ) ); */
/* check_status( naibrd_DS_SetThresholdVoltage(cardIndex, module, channel, NAI_DS_THRESHOLD_VOLT_SIGNAL, dDSExpSigVolt * THRESHOLD_VOLT_GAIN ) ); */
/*set up expected VLL*/
/* check_status( naibrd_DS_SetExpectedVoltage(cardIndex, module, channel, NAI_DS_EXP_VOLT_REFERENCE, dDSExpRefVolt ) ); */
/* check_status( naibrd_DS_SetExpectedVoltage(cardIndex, module, channel, NAI_DS_EXP_VOLT_SIGNAL, dDSExpSigVolt ) ); */
/*set up ratio/fixed mode*/
check_status(naibrd_DS_SetRatioFixedMode(cardIndex, module, channel, NAI_DS_OUTPUT_FIXED));
/*set up active channel*/
check_status(naibrd_DS_SetActiveChannel(cardIndex, module, channel, NAI_ENABLE));
/*set up rotation trigger source to Internal*/
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_TRIG_SOURCE, (float64_t)NAI_DS_ROT_TRIG_INTERNAL));
/*set up power*/
check_status(naibrd_DS_SetPowerEnable(cardIndex, module, channel, NAI_ENABLE));
do
{
DS_ShowSetRotationTestResult(cardIndex, module, channel);
showCurrentModChan(module, channel);
Show_Rotation_UserInput_Commands();
udUserInput = getUserInput();
switch (udUserInput)
{
case DS_USER_INPUT_SET_ROT_RATE:
case DS_USER_INPUT_SET_ROT_MODE:
case DS_USER_INPUT_SET_ROT_START_ANG:
case DS_USER_INPUT_SET_ROT_STOP_ANG:
case DS_USER_INPUT_INITIATE_ROTATION:
case DS_USER_INPUT_STOP_ROTATION:
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_ShowSetRotationTestResult(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
uint32_t unValue = 0;
uint8_t u8Value = 0;
/* 1 1 1 1 1 1 1 1 1 1 1 1 */
/* 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
/*printf("\nRot. Rate Rot. Mode Start Angle Stop Angle Rot. Source Rot. State Power "); */
printf("\nRot. Rate Rot. Mode Meas. Ang Start Angle Stop Angle Rot. Source Rot. State Power ");
printf("\n---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n");
/*get rotation rate*/
check_status(naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_RATE, &dValue));
printf("%-15.4f", dValue);
/*get rotation Mode*/
check_status(naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_MODE, &dValue));
if ((nai_ds_rotation_mode_t)dValue == NAI_DS_ROT_CONTINUOUS_MODE)
printf("%-15s", DS_ROTATION_CONTINUOUS);
else
printf("%-15s", DS_ROTATION_START_STOP);
/*get measured angle*/
check_status(naibrd_DS_GetMeasuredValue(cardIndex, module, channel, NAI_DS_MEASURED_ANGLE, &dValue));
printf("%-15.4f", dValue); /*wrap angle*/
/*get rotation Start Angle*/
check_status(naibrd_DS_GetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, &dValue));
printf("%-15.4f", dValue);
/*get rotation Stop Angle*/
check_status(naibrd_DS_GetAngle(cardIndex, module, channel, NAI_DS_ANGLE_ROTATION_STOP, &dValue));
printf("%-15.4f", dValue);
/*get rotation Source*/
check_status(naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_TRIG_SOURCE, &dValue));
if ((nai_ds_rotation_trigger_source_t)dValue == NAI_DS_ROT_TRIG_INTERNAL)
printf("%-15s", DS_ROTATION_SRC_INT);
else if ((nai_ds_rotation_trigger_source_t)dValue == NAI_DS_ROT_TRIG_EXTERNAL)
printf("%-15s", DS_ROTATION_SRC_EXT);
else
printf("%-15s", DS_NOT_DEFINED);
/*get rotation State*/
check_status(naibrd_DS_GetRotationStatus(cardIndex, module, channel, &unValue));
if (unValue == NAI_DS_STATUS_ROT_NOT_DONE)
printf("%-15s", DS_ROTATION_STATUS_ROTATING);
else
printf("%-15s", DS_ROTATION_STATUS_NOT_ROTATING);
/*get power State*/
check_status(naibrd_DS_GetPowerEnable(cardIndex, module, channel, &u8Value));
if (u8Value == NAI_ENABLE)
printf("%-15s", DS_ENABLE);
else
printf("%-15s", DS_DISABLE);
printf("\n");
}
static void DS_SetRotationRate(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 Rotation Rate(DPS)\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_RATE, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_RATE, dValue);
else
{
/*Set rotation rate*/
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_RATE, dValue));
}
}
static void DS_SetRotationMode(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 Rotation Mode (Continuous = 0 / Start-Stop = 1)\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_MODE, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_MODE, dValue);
else
{
/*Set rotation mode*/
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_MODE, dValue));
}
}
static void DS_SetRotationStartAngle(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 Rotation Start Angle [0.0 - 359.9954]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_START_ANG, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_START_ANG, dValue);
else
{
/*Set rotation start angle*/
check_status(naibrd_DS_SetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, dValue));
}
}
static void DS_SetRotationStopAngle(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 Rotation Stop Angle [0.0 - 359.9954]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_STOP_ANG, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_STOP_ANG, dValue);
else
{
/*Set rotation stop angle*/
check_status(naibrd_DS_SetAngle(cardIndex, module, channel, NAI_DS_ANGLE_ROTATION_STOP, dValue));
}
}
static void DS_StartRotation(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("\nTrigger Start Rotation[STOP = 0, GO = 1]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_INITIATE_ROTATION, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_INITIATE_ROTATION, dValue);
else
{
/*Start Rotation*/
check_status(naibrd_DS_SetRotationEnable(cardIndex, module, channel, (uint8_t)dValue));
}
}
static void DS_StopRotation(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("\nTrigger Stop Rotation[STOP = 0, GO = 1]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_STOP_ROTATION, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_STOP_ROTATION, dValue);
else
{
/*Stop Rotation*/
check_status(naibrd_DS_SetRotationEnable(cardIndex, module, channel, (uint8_t)dValue));
}
}
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 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)
{
printf("\nModule :%d", nModule);
printf("\nChannel :%d", nChannel);
}