Integrator Resources

The official home for NAI Support

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

Toggle Components with Visual Button
JavaScript Form Processing

DS BITTest

DS BITTest

Explanation

About the Sample Application Code

The provided C sample application code is designed to interact with embedded function modules from North Atlantic Industries (NAI). The code contains several components, which are explained in detail below.

Definitions and Inclusions

  1. Header Inclusions: The code includes standard C libraries for basic operations, mathematical calculations, and string manipulations: c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <math.h> #include <ctype.h>

  2. NAI-Specific Headers: The code includes specific headers that provide functions for board access, querying, displaying, and utility operations: c #include "include/naiapp_boardaccess_menu.h" #include "include/naiapp_boardaccess_query.h" #include "include/naiapp_boardaccess_access.h" #include "include/naiapp_boardaccess_display.h" #include "include/naiapp_boardaccess_utils.h" #include "DS_Common.h" #include "nai.h" #include "naibrd.h" #include "functions/naibrd_ds.h" #include "advanced/nai_ether_adv.h"

  3. Constants and Function Prototypes: c static const int8_t *CONFIG_FILE = (int8_t *)"default_DsBitTest.txt";

    Prototypes for the functions used to execute various tasks:
    ```c
    static void DS_ShowSetAngleTestResult(int32_t cardIndex, int32_t module, int32_t channel);
    // Other function prototypes...
    ```

Enumerations and Structures

  1. Command and User Input Enumerations: These enumerations define possible command and user input actions: c enum dsfunc_commands { DS_FUNC_CMD_SET_ANGLE, DS_FUNC_CMD_SET_MODULE, DS_FUNC_CMD_SET_CHANNEL, DS_FUNC_CMD_COUNT }; enum dsfunc_userInputs { DS_USER_INPUT_SET_ANGLE, DS_USER_INPUT_SET_D2, DS_USER_INPUT_SET_D3, DS_USER_INPUT_SET_TEST_VERIFY, DS_USER_INPUT_ACTIVE_CHAN, DS_USER_INPUT_POWER, DS_USER_INPUT_REFRESH, DS_USER_INPUT_QUIT, DS_USER_INVALID_INPUT, DS_USER_INPUT_COUNT };

  2. Command and User Input Tables: The dsdemofunc_cmdtbl structure maps user commands 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); };

    struct dsUserInputLimitTable {
       int32_t  cmdnum;
       int8_t *cmdstr;
       float64_t upperLimit;
       float64_t lowerLimit;
    };
    ```
    They initialize the command and user input tables:
    ```c
    static struct dsdemofunc_cmdtbl DS_DemoFuncMenuCmds[] = { /* Initialization */ };
    static struct dsdemofunc_cmdtbl DS_DemoUserInputs[] = { /* Initialization */ };
    static struct dsUserInputLimitTable DS_Inputs_Limits[] = { /* Initialization */ };
    ```

Main Function

Depending on the operating system, the main function or DS_RunBitProgramSample function is executed:

#if defined (__VXWORKS__)
int32_t DS_RunBitProgramSample(void)
#else
int32_t main(void)
#endif
{
    /* Variable declarations and initializations */
    if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE) {
        /* Main loop to query user inputs and execute commands */
        while (stop != TRUE) {
            /* Card, module, and channel selection */
            stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
            /* Other query operations */
            DS_RunAngleProgram(cardIndex, module, moduleID, 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;
}

Core Function Implementations

  1. DS_RunAngleProgram: Interacts with the user to configure the module and channel for DS output: c static void DS_RunAngleProgram(int32_t cardIndex, int32_t module, uint32_t moduleID, int32_t maxModule) { /* Core logic to display commands and update configurations / do { Show_DSDemoFunc_Commands(); / Handle user commands / switch (cmdIdx) { case DS_FUNC_CMD_SET_ANGLE: DS_RunBitTestFunc(cardIndex, module, channel); break; / Other cases for commands */ } } while (!bQuit); }

  2. User Input and Status Functions: Handle user inputs and status display: c static uint32_t getUserInput() { /* Logic to get and validate user input / } static bool_t checkUserInput(uint32_t uTypeIdx, float64_t dUserInput) { / Check if input is within valid range / } static void printInvalidUserInputMessage(uint32_t uTypeIdx, float64_t dUserInput) { / Print invalid input message / } static void showCurrentModChan(int32_t nModule, int32_t nChannel) { / Display current module and channel / } static void getStatus(int32_t cardIndex, int32_t module, int32_t channel, uint8_t *u8Status) { / Get status of module and channel */ }

  3. Command Handling Functions: These functions set various parameters like angle, power, and test modes: c static void DS_SetNewAngle(int32_t cardIndex, int32_t module, int32_t channel) { /* Set a new angle / } static void DS_SetD2Test(int32_t cardIndex, int32_t module, int32_t channel) { / Configure D2 test mode / } static void DS_SetD3Test(int32_t cardIndex, int32_t module, int32_t channel) { / Configure D3 test mode / } static void DS_SetTestVerifyValue(int32_t cardIndex, int32_t module, int32_t channel) { / Set test verify value / } static void DS_SetActiveChannel(int32_t cardIndex, int32_t module, int32_t channel) { / Set the active channel / } static void DS_SetPower(int32_t cardIndex, int32_t module, int32_t channel) { / Enable or disable power */ }

Conclusion

This sample application demonstrates how to interact with NAI’s embedded function modules by using a combination of standard C libraries and NAI-specific functions. The application queries the user for various inputs to configure and test the modules dynamically. The provided enumerations, structures, and extensive function implementations enable robust interaction with the hardware.

#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_DsBitTest.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, int32_t maxModule);
static void DS_RunBitTestFunc(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_SetD2Test(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetTestVerifyValue(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_SetActiveChannel(int32_t cardIndex, int32_t module, int32_t channel);

static void Show_DSDemoFunc_Commands(void);
static void DS_SetD3Test(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 void getStatus(int32_t cardIndex, int32_t module, int32_t channel, uint8_t *u8Status);

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_SET_CHANNEL,
   DS_FUNC_CMD_COUNT
};
/****** User Input Table *******/
enum dsfunc_userInputs
{
   DS_USER_INPUT_SET_ANGLE,
   DS_USER_INPUT_SET_D2,
   DS_USER_INPUT_SET_D3,
   DS_USER_INPUT_SET_TEST_VERIFY,
   DS_USER_INPUT_ACTIVE_CHAN,
   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 *)"BIT",  (int8_t *)"Run BIT ON/OFF LINE TEST",    DS_FUNC_CMD_SET_ANGLE,         DS_RunBitTestFunc},\
    {(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 *)"ANG    ",            (int8_t *)"Set Angle",                     DS_USER_INPUT_SET_ANGLE,             DS_SetNewAngle},
    {(int8_t *)"D2    ",             (int8_t *)"Set On-Line(D2) Test",          DS_USER_INPUT_SET_D2,                DS_SetD2Test},
    {(int8_t *)"D3    ",             (int8_t *)"Set On-Line(D3) Test",          DS_USER_INPUT_SET_D3,                DS_SetD3Test},
    {(int8_t *)"VERIFY",             (int8_t *)"Set Test Verify Value",         DS_USER_INPUT_SET_TEST_VERIFY,       DS_SetTestVerifyValue},
    {(int8_t *)"ACT    ",            (int8_t *)"Set Active Channel",            DS_USER_INPUT_ACTIVE_CHAN,           DS_SetActiveChannel},
    {(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_D2,                (int8_t *)"D2 TestDisable/Enable",      1.0,        0.0},
    {DS_USER_INPUT_SET_D3,                (int8_t *)"D3 TestDisable/Enable",      1.0,        0.0},
    {DS_USER_INPUT_SET_TEST_VERIFY,       (int8_t *)"D2 Test Verify Value",       65535.0,    0.0},
    {DS_USER_INPUT_ACTIVE_CHAN,           (int8_t *)"Active Channel",             1.0,        0.0},
    {DS_USER_INPUT_POWER,                 (int8_t *)"Set Power",                  1.0,        0.0},
    {DS_USER_INPUT_REFRESH,               (int8_t *)"",                           0.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_RunBitProgramSample(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t moduleCnt;
   int32_t cardIndex;
   int32_t module;
   uint32_t moduleID = 0;
   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)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);

               if ((moduleID != 0))
               {
                  DS_RunAngleProgram(cardIndex, module, moduleID, moduleCnt);
               }
               else
               {
                  printf(" *** Module selection not recognized as valid module type for this application. ***\n\n");
               }
            }

            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, int32_t maxModule)
{
   bool_t bQuit;
   int32_t channel = 0;
   int32_t channelCount;
   int32_t cmdIdx;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   channelCount = 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_RunBitTestFunc(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 > channelCount))
            {
               printf("\n%s: %d is outside the limits[%d - %d]", "Channel #", channel, 1, channelCount);
            }
            break;

         default:
            break;
         }
      }
   } while (bQuit == FALSE);
}

static void Show_DSDemoFunc_Commands(void)
{
   int i;
   printf("\n\t\t DS Set Back-ground Test Demo 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 D/S module in different test mode.  The
user can set the following test modes:
1. Set on line back-ground test mode (D2 Test).
2. Set off line back-ground test mode (D3 Test).
3. Set test verify value.
4. Set Active Channel.
5. Set Power.
*/
static void DS_RunBitTestFunc(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 put the D/S module in different ");
   printf("\ntest modes.  The modes are: 1. On-line back ground test (D2).   ");
   printf("\n2. Off-line back ground test (D3).                              ");
   printf("\n1. Disable/Enable on-line back ground test (D2).");
   printf("\n2. Disable/Enable off-line back ground test (D3).");
   printf("\n3. Set test verify value.");
   printf("\n4. Set Angle");
   printf("\n5. Set Active Channel");
   printf("\n6. Set Module Power");
   printf("\n================================================================\n");

   do
   {
      DS_ShowSetAngleTestResult(cardIndex, module, channel);
      showCurrentModChan(module, channel);
      Show_SetAngle_UserInput_Commands();
      udUserInput = getUserInput();
      switch (udUserInput)
      {
      case DS_USER_INPUT_SET_ANGLE:
      case DS_USER_INPUT_SET_D2:
      case DS_USER_INPUT_SET_D3:
      case DS_USER_INPUT_SET_TEST_VERIFY:
      case DS_USER_INPUT_ACTIVE_CHAN:
      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  D2          D3          Mode        Test Verify Meas. VLL   Meas. VRef  Meas.RFreq  Status      Act.Chan.   Power     \n");
   printf("\n                        Off/On      Off/On      Ratio/Fixed   Value                                         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);
   /*Get D2 Test */
   check_status(naibrd_DS_GetTestModeEnable(cardIndex, module, NAI_DS_ON_LINE_TEST, &u8Value));
   if (u8Value == NAI_ENABLE)
      printf("%-12s", DS_ENABLE);
   else
      printf("%-12s", DS_DISABLE);
   /*Get D3 Test */
   check_status(naibrd_DS_GetTestModeEnable(cardIndex, module, NAI_DS_OFF_LINE_TEST, &u8Value));
   if (u8Value == NAI_ENABLE)
      printf("%-12s", DS_ENABLE);
   else
      printf("%-12s", DS_DISABLE);
   /*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*/
  /*D2 Verify Value*/
   check_status(naibrd_DS_GetTestVerify(cardIndex, module, &unValue));
   printf("0x%-10x", unValue);
   /*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*/
   /*get Status: S=Signal Loss, R=Reference Loss, B=BIT Loss, P=Phase Loss*/
   getStatus(cardIndex, module, channel, u8Status);
   printf("%-12s", u8Status);        /*status*/
   /*get Active Channel*/
   check_status(naibrd_DS_GetActiveChannel(cardIndex, module, channel, &u8Value));
   if (u8Value == 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_SetD2Test(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 = 1;
   printf("\nOn-line Test (D2):[0=Disable, 1 =Enable]\n");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   unValue = atoi((const char *)inputBuffer);
   bQuit = checkUserInput(DS_USER_INPUT_SET_D2, unValue);
   if (bQuit == TRUE)
      printInvalidUserInputMessage(DS_USER_INPUT_SET_D2, unValue);
   else
   {
      if (unValue == NAI_ENABLE)
         check_status(naibrd_DS_SetTestModeEnable(cardIndex, module, NAI_DS_ON_LINE_TEST, (uint8_t)NAI_ENABLE));
      else
         check_status(naibrd_DS_SetTestModeEnable(cardIndex, module, NAI_DS_ON_LINE_TEST, (uint8_t)NAI_DISABLE));
   }
}

static void DS_SetD3Test(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 = 1;
   printf("\nOff-line Test (D3):[0=Disable, 1 =Enable]\n");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   unValue = atoi((const char *)inputBuffer);
   bQuit = checkUserInput(DS_USER_INPUT_SET_D2, unValue);
   if (bQuit == TRUE)
      printInvalidUserInputMessage(DS_USER_INPUT_SET_D2, unValue);
   else
   {
      if (unValue == NAI_ENABLE)
         check_status(naibrd_DS_SetTestModeEnable(cardIndex, module, NAI_DS_OFF_LINE_TEST, (uint8_t)NAI_ENABLE));
      else
         check_status(naibrd_DS_SetTestModeEnable(cardIndex, module, NAI_DS_OFF_LINE_TEST, (uint8_t)NAI_DISABLE));
   }
}

static void DS_SetTestVerifyValue(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 = 1;
   printf("\nEnter Test Verify Value\n");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   unValue = atol((const char *)inputBuffer);
   bQuit = checkUserInput(DS_USER_INPUT_SET_TEST_VERIFY, unValue);
   if (bQuit == TRUE)
      printInvalidUserInputMessage(DS_USER_INPUT_SET_TEST_VERIFY, unValue);
   else
   {
      /*Set Test Verify*/
      check_status(naibrd_DS_SetTestVerify(cardIndex, module, unValue));
   }
}

static void DS_SetActiveChannel(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_ACTIVE_CHAN, unValue);
   if (bQuit == TRUE)
      printInvalidUserInputMessage(DS_USER_INPUT_ACTIVE_CHAN, unValue);
   else
   {
      /*Set active channel*/
      check_status(naibrd_DS_SetActiveChannel(cardIndex, module, channel, (uint8_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 Enable*/
      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);
}

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_LATCH_SIGNAL_LOST, &unSingalLoss));
   check_status(naibrd_DS_GetStatus(cardIndex, module, channel, NAI_DS_STATUS_LATCH_REFERENCE_LOST, &unRefLoss));
   check_status(naibrd_DS_GetStatus(cardIndex, module, channel, NAI_DS_STATUS_LATCH_BIT_LOST, &unBitLoss));
   check_status(naibrd_DS_GetStatus(cardIndex, module, channel, NAI_DS_STATUS_LATCH_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];
}

Help Bot

X