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

M1553 RT Receive ModeCodes

M1553 RT Receive ModeCodes Sample Application (SSK 1.x)

Overview

The M1553 RT Receive ModeCodes sample application demonstrates how to configure a MIL-STD-1553 channel as a Remote Terminal (RT) with mode code handling using the NAI Software Support Kit (SSK 1.x). Mode codes are special 1553 commands that use subaddresses 0 and 31 for control and status functions rather than data transfer. This sample provides a menu-driven interface for reading and writing mode code data, configuring RT options, managing BIT (Built-In Test) word settings, setting status bits, and running the RT to process incoming messages.

The key mode code API calls demonstrated are:

  • naibrd_1553_RtModeCodeReadData() — reads the current data word for a specific mode code.

  • naibrd_1553_RtModeCodeWriteData() — writes a data word to a specific mode code.

  • naibrd_1553_RtInitialize() — reinitializes the RT with option flags (e.g., alternate status mode).

  • naibrd_1553_RtBITWordConfigure() — configures the BIT word source and busy behavior.

  • naibrd_1553_RtBITWordRead() — reads the BIT word from register or memory.

  • naibrd_1553_RtBITWordWrite() — writes a BIT word value.

  • naibrd_1553_RtResponseStatusBitsSet() / naibrd_1553_RtResponseStatusBitsUnset() / naibrd_1553_RtResponseStatusBitsGet() — manage RT status word response bits.

  • naibrd_1553_RtMessageLegalityEnable() — legalizes all mode codes and subaddresses for the RT.

This sample supports the following 1553 module types:

  • 4-channel modules: FT0 through FT9 and FTA through FTF

  • 2-channel 1760 modules: FTJ and FTK

  • Combination modules: CM1, CM5, and CM8

For detailed register maps and module-specific behavior, refer to the FTA-FTF Manual and FTJ-FTK Manual.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a supported 1553 module installed.

  • SSK 1.x installed on your development host.

  • The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.

How to Run

Launch the M1553_RT_Receive_ModeCodes executable from your build output directory. On startup the application looks for a configuration file (default_1553_RTReceiveModeCodes.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, the application configures the RT channel, address, and options, then presents a menu with five operations: Mode Code Data Table, RT Options, BIT Options, Status Bits, and Start RT.

Board Connection and Module Selection

Note
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to 1553.

The main() function follows a standard SSK 1.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_1553_RTReceiveModeCodes.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear.

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Retrieve the module ID with naibrd_GetModuleID() so downstream code can adapt to the specific 1553 variant installed.

  5. If a valid module is found, call Run_M1553_RT_Receive_ModeCodes() to begin RT configuration.

#if defined (__VXWORKS__)
int32_t M1553_RT_Receive_ModeCodes(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)
      {
         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)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_M1553_RT_Receive_ModeCodes(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;
}
Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — indices are zero-based for cards and one-based for modules. Ensure the values you pass match your hardware setup.

  • Module not present at selected slot — the slot you selected does not contain a 1553 module. Use the board menu to verify which slots are populated.

Program Structure

Entry Point

The program entry point is main() on most platforms or M1553_RT_Receive_ModeCodes() on VxWorks. After the board connection and module selection, the application calls Run_M1553_RT_Receive_ModeCodes(), which configures the RT and presents a command menu.

User Input Flow

Run_M1553_RT_Receive_ModeCodes() collects RT parameters through the standard utility functions:

  1. Get1553RTCfg() — prompts for the 1553 channel number and RT address (defaults: channel 1, RT address 1).

  2. Get1553LogicalDevNum() — prompts for a logical device number (default: device 1).

  3. Get1553RTAddressSource() — asks whether to set the RT address in software or use the hardware address pins.

Unlike the other RT Receive samples, this sample does not prompt for a subaddress or Rx buffer type because it legalizes all subaddresses and mode codes when the RT is started.

After initial RT configuration, the application presents a menu with five options:

  1. MODE CODE DATA TABLE — read and write mode code data words.

  2. RT OPTIONS — configure RT behavioral options.

  3. BIT OPTIONS — configure BIT word source and behavior.

  4. STATUS BITS — set or unset individual RT status response bits.

  5. START RT — legalize all subaddresses/mode codes and run the RT for a specified duration.

Note
The menu system is a sample convenience — in your own code, call these API functions directly.

RT Address Configuration

The RT address configuration follows the same pattern as other 1553 RT samples. To set the address in software, write RTAD_SW_EN and RT_ADR_LAT bits (value 0x0018) to auxiliary register 0x2 via naibrd_1553_WriteAuxReg(), then program the address with naibrd_1553_RtSetAddress(). For hardware pin addressing, set only RT_ADR_LAT (value 0x0008).

if (bSoftwareRTAddr)
{
   swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0018);
   swResult = naibrd_1553_RtSetAddress(DevNum, rtaddr);
}
else
{
   swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0008);
}

For complete register bit definitions, refer to the FTA-FTF Manual.

Important
  • RT not responding — verify that the address and source mode match. A common mistake is configuring software addressing while the hardware is wired for pin addressing, or vice versa.

  • RT address conflict — two RTs with the same address on the same bus cause unpredictable behavior. Each RT on a bus must have a unique address (0-30).

Mode Code Data Table

Mode codes are special 1553 commands that use subaddresses 0 and 31. Some mode codes carry a data word (e.g., Synchronize with Data, Transmit Vector Word). The Mode Code Data Table menu lets you read the current data word for each mode code and write new values.

The sample supports nine mode code data entries:

Entry Mode Code Direction

1

Synchronize with Data

From BC

2

Selected Transmitter Shutdown

From BC

3

Override Selected Transmitter Shutdown

From BC

4

Transmit Vector Word

To BC

5

Transmit Last Command Word

Updated by Core

6

Transmit BIT Word

To BC

7

Broadcast Synchronize with Data

From BC

8

Broadcast Selected Transmitter Shutdown

From BC

9

Broadcast Override Selected Transmitter Shutdown

From BC

To read the current data word for a mode code in your own application, call naibrd_1553_RtModeCodeReadData():

uint16_t data;
naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_VECTOR_WORD, &data);

To write a new data word, call naibrd_1553_RtModeCodeWriteData():

naibrd_1553_RtModeCodeWriteData(DevNum, NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_VECTOR_WORD, data);

Mode code constants are defined in the naibrd_1553.h header. The "From BC" entries store data received from the Bus Controller. The "To BC" entries store data that the RT will transmit when the BC requests it. The "Transmit Last Command Word" entry is updated automatically by the 1553 core and is read-only from the application’s perspective.

Important
  • Mode code data not updating — verify that the correct NAI_1553_RT_MODECODE_DATA_* constant is used. Using the wrong constant writes to a different mode code entry.

  • Transmit Last Command Word read-only — this entry is maintained by the 1553 hardware core. Writing to it has no effect.

RT Options

The RT Options menu lets you enable or disable 12 RT behavioral options. Each option maps to a flag in the naibrd_1553_RtInitialize() options parameter. When you change an option, the sample calls ConfigureRTOptions(), which OR’s all enabled flags together and calls naibrd_1553_RtInitialize() to apply them:

static int16_t ConfigureRTOptions(int16_t DevNum)
{
   uint32_t options = 0;
   int32_t i;

   for (i = 0; i < NUM_RT_OPTIONS; i++)
   {
      if (rtOptions[i])
      {
         options |= rtOptionsMap[i];
      }
   }

   swResult = naibrd_1553_RtInitialize(DevNum, NAI_1553_RT_CMDSTK_SIZE_2048, options);
   swResult = naibrd_1553_RtResponseStatusBitsSet(DevNum, statusBitsWord);

   return swResult;
}

The available RT options are:

Option Description

NAI_1553_RT_OPT_CLEAR_SERVICE_REQUEST

Clear Service Request after Tx Vector Word

NAI_1553_RT_OPT_LOAD_TIME_TAG

Load time tag on synchronize command

NAI_1553_RT_OPT_CLEAR_TIME_TAG

Clear time tag on synchronize command

NAI_1553_RT_OPT_OVERWRITE_DATA

Overwrite invalid data

NAI_1553_RT_OPT_OVERRIDE_MODE_BIT

Override mode T/R* error

NAI_1553_RT_OPT_ALTERNATE_STATUS

RT alternate status word enable

NAI_1553_RT_OPT_ILL_RX_DISABLE

Illegal receive transfer disable

NAI_1553_RT_OPT_BUSY_RX_DISABLE

Busy receive transfer disable

NAI_1553_RT_OPT_SET_RT_FLAG

Flag if loopback test failed

NAI_1553_RT_OPT_1553A_MODE_CODES

1553A mode codes enabled

NAI_1553_RT_OPT_MODE_COMMAND_OVERRIDE_BUSY

Busy bit and data word sent

NAI_1553_RT_OPT_BROADCAST_DISABLE

Broadcast disabled

Note
After calling naibrd_1553_RtInitialize(), the status bits are re-applied with naibrd_1553_RtResponseStatusBitsSet() because reinitialization clears the status word.
Important
  • Options not taking effect — naibrd_1553_RtInitialize() must be called for option changes to take effect. Changing the rtOptions array alone does nothing.

  • Status bits cleared after reinitialize — reinitialization resets the RT status word. The sample re-applies status bits after each reinitialize call.

BIT Word Configuration

The BIT (Built-In Test) word is a 16-bit value that the RT transmits in response to a Transmit BIT Word mode code command from the BC. This sample lets you configure three aspects of the BIT word:

BIT Word Source

The BIT word can be sourced from a hardware register (updated by the 1553 core) or from a memory location (writable by the application). To configure the source, call naibrd_1553_RtBITWordConfigure():

swResult = naibrd_1553_RtBITWordConfigure(DevNum, NAI_1553_RT_BIT_REGISTER, NAI_1553_RT_BIT_ENABLED);

The first parameter selects the source (NAI_1553_RT_BIT_REGISTER or NAI_1553_RT_BIT_MEMORY). The second parameter controls whether BIT word transmission is permitted when the RT is busy (NAI_1553_RT_BIT_ENABLED or NAI_1553_RT_BIT_DISABLED).

Reading the BIT Word

To read the current BIT word value from either source, call naibrd_1553_RtBITWordRead():

uint16_t data;
swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_REGISTER, &data);
swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_MEMORY, &data);

Writing the BIT Word

To write a new BIT word value (only effective when the source is set to memory), call naibrd_1553_RtBITWordWrite():

swResult = naibrd_1553_RtBITWordWrite(DevNum, data);
Important
  • BIT word not changing — if the source is set to NAI_1553_RT_BIT_REGISTER, the hardware core controls the value and naibrd_1553_RtBITWordWrite() writes to the memory location but the register value is what gets transmitted. Switch the source to NAI_1553_RT_BIT_MEMORY to transmit application-written values.

  • BIT word inhibited when busy — if the busy inhibit option is set to NAI_1553_RT_BIT_DISABLED, the RT will not transmit the BIT word when its busy bit is set.

Status Bits Configuration

The RT status word is returned to the BC with every response. Certain bits in the status word can be set by the application to signal conditions to the BC. The Status Bits menu displays the current state of status bits 1 through 11 and lets you set or unset individual bits.

To set status bits in your own application, call naibrd_1553_RtResponseStatusBitsSet():

swResult = naibrd_1553_RtResponseStatusBitsSet(DevNum, (1 << bitNumber));

To unset (clear) status bits, call naibrd_1553_RtResponseStatusBitsUnset():

swResult = naibrd_1553_RtResponseStatusBitsUnset(DevNum, (1 << bitNumber));

To read the current status word, call naibrd_1553_RtResponseStatusBitsGet():

swResult = naibrd_1553_RtResponseStatusBitsGet(DevNum, &statusBitsWord);

The status bits and their standard/alternate meanings are:

Bit Standard Mode Alternate Status Mode

11

Dynamic Bus Control

Message Error

10

Busy

Instrumentation

9

Service Request

Service Request

8

Subsystem Flag

N/A

7

Terminal (RT) Flag

N/A

4

N/A

Busy

3

N/A

Subsystem Flag

1

N/A

Terminal Flag

Important
  • Status bits cleared unexpectedly — calling naibrd_1553_RtInitialize() (e.g., through the RT Options menu) resets the status word. The sample re-applies the bits after each reinitialize.

  • Alternate status mode — alternate status bit meanings only apply when NAI_1553_RT_OPT_ALTERNATE_STATUS is enabled in RT Options.

Running the RT

The "Start RT" menu option legalizes all mode codes and subaddresses, then enters a timed monitoring loop. The legalization call enables the RT to respond to any BC command:

swResult = naibrd_1553_RtMessageLegalityEnable(DevNum, NAI_1553_RT_ADDRESS_BOTH,
   NAI_1553_MT_FILTER_ALL, NAI_1553_RT_SA_ALL, 0xFFFFFFFF);

This legalizes all subaddresses (0-31) on both receive and transmit for the configured RT address. The 0xFFFFFFFF mask enables all mode codes. In a production application, you would typically legalize only the specific subaddresses and mode codes your system requires.

After legalization, the RT is started with naibrd_1553_RtStart() and the ProcessMessages() loop runs for the specified duration, reading messages from the stack and decoding them:

swResult = naibrd_1553_RtStart(DevNum);

/* Process messages using stack-based retrieval */
swResult = naibrd_1553_RtMessageGetFromStackRaw(DevNum, wsBuffer, NAI_1553_MAX_MESSAGE_SIZE_RT);
if (swResult > 0)
{
   swResult = naibrd_1553_RtMessageDecodeRaw(DevNum, wsBuffer, &DecodedMsgStruct);
}

swResult = naibrd_1553_RtStop(DevNum);
Important
  • No messages appearing — verify that naibrd_1553_RtMessageLegalityEnable() was called before naibrd_1553_RtStart(). Without legalization, the RT ignores all BC commands.

  • Mode code responses incorrect — verify that the mode code data table contains the expected values. Use the Mode Code Data Table menu to check.

Troubleshooting Reference

This table summarizes common errors and symptoms covered in the sections above. For detailed context on each entry, refer to the relevant section. Consult your module’s manual for hardware-specific diagnostic procedures.

Error / Symptom Possible Causes Suggested Resolution

No board found or connection timeout

Board not powered, missing configuration file, network issue

Verify hardware and configuration file. If file doesn’t exist, configure and save from board menu.

Module not recognized as 1553

Selected module is not FT-series or CM with 1553

Verify module type at the selected slot.

Device open or initialization failure

Wrong card/module/channel, or device already in use

Verify parameters. Close other applications using this channel.

RT address mismatch

RT address doesn’t match what BC is targeting

Confirm address set via RtSetAddress() or hardware pins matches BC command word.

RT options not taking effect

naibrd_1553_RtInitialize() not called after changing options

Call RtInitialize() with the updated options bitmask.

Status bits cleared unexpectedly

naibrd_1553_RtInitialize() resets the status word

Re-apply status bits with RtResponseStatusBitsSet() after each reinitialize.

BIT word not changing

Source set to REGISTER (hardware-controlled) instead of MEMORY

Switch source to NAI_1553_RT_BIT_MEMORY to use application-written values.

Mode code data not updating

Wrong NAI_1553_RT_MODECODE_DATA_* constant used

Verify the constant matches the desired mode code entry.

No messages appearing when RT is running

Subaddresses/mode codes not legalized

Call naibrd_1553_RtMessageLegalityEnable() before naibrd_1553_RtStart().

Stack overflow / lost messages

Application not reading from stack frequently enough

Increase polling rate or reduce loop delay.

Alternate status bits not working

NAI_1553_RT_OPT_ALTERNATE_STATUS not enabled

Enable alternate status in RT Options before setting alternate status bits.

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail.

Full Source — M1553_RT_Receive_ModeCodes.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"

/* Common 1553 Sample Program include files */
#include "nai_1553_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"

#define NUM_MENU_ITEMS  6
#define NUM_RT_OPTIONS 12
#define NUM_BIT_MENU_ITEMS 3

static const int8_t *CONFIG_FILE = (int8_t *)"default_1553_RTReceiveModeCodes.txt";

/* Function prototypes */
static bool_t Run_M1553_RT_Receive_ModeCodes(int32_t cardIndex, int32_t module, uint32_t modid);
static int32_t ProcessMessages(uint16_t DevNum, int32_t duration);
static int16_t ConfigureRTOptions(int16_t DevNum);
static bool_t ModeCodeDataTable(int16_t DevNum);
static bool_t RTOptions(int16_t DevNum);
static bool_t BITOptions(int16_t DevNum);
static bool_t StatusBits(int16_t DevNum);
static bool_t RunRT(int16_t DevNum);

static const int32_t DEF_RT_CHANNEL       = 1;
static const int16_t DEF_RT_DEV_NUM       = 1;
static const uint8_t DEF_RT_ADDRESS       = 1;

/* Global Variables */
static nai_1553_cmdtbl_type mainMenuCmds[NUM_MENU_ITEMS] =
{
   {"1",  "MODE CODE DATA TABLE",   1,    ModeCodeDataTable},
   {"2",  "RT OPTIONS",             2,    RTOptions},
   {"3",  "BIT OPTIONS",            3,    BITOptions},
   {"4",  "STATUS BITS",            4,    StatusBits},
   {"5",  "START RT",               5,    RunRT},
   {"6",  "QUIT",                   6,    NULL},
};

static const int8_t *modeCodeDataStrings[9] =
{
   (int8_t *)"SYNCHRONIZE WITH DATA (From BC)",
   (int8_t *)"SELECTED TRANSMITTER SHUTDOWN (From BC)",
   (int8_t *)"OVERRIDE SELECTED TRANSMITTER SHUTDOWN (From BC)",
   (int8_t *)"TRANSMIT VECTOR WORD (To BC)",
   (int8_t *)"TRANSMIT LAST COMMAND WORD (Updated by Core)",
   (int8_t *)"TRANSMIT BIT WORD (To BC)",
   (int8_t *)"BROADCAST SYNCHRONIZE WITH DATA (From BC)",
   (int8_t *)"BROADCAST SELECTED TRANSMITTER SHUTDOWN (From BC)",
   (int8_t *)"BROADCAST OVERRIDE SELECTED TRANSMITTER SHUTDOWN (From BC)"
};

static const uint16_t modeCodeDataMap[9] =
{
   NAI_1553_RT_MODECODE_DATA_RX_SYNCHRONIZE,
   NAI_1553_RT_MODECODE_DATA_RX_TRANSMITTER_SHUTDOWN,
   NAI_1553_RT_MODECODE_DATA_RX_OVERRIDE_TRANSMITTER_SHUTDOWN,
   NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_VECTOR_WORD,
   NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_LAST_COMMAND_WORD,
   NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_BUILT_IN_TEST_WORD,
   NAI_1553_RT_MODECODE_DATA_BROADCAST_SYNCHRONIZE,
   NAI_1553_RT_MODECODE_DATA_BROADCAST_SELECTED_TRANSMITTER_SHUTDOWN,
   NAI_1553_RT_MODECODE_DATA_BROADCAST_OVERRIDE_SELECTED_TRANSMITTER_SHUTDOWN
};

static const uint16_t rtOptionsMap[NUM_RT_OPTIONS] =
{
   NAI_1553_RT_OPT_CLEAR_SERVICE_REQUEST,
   NAI_1553_RT_OPT_LOAD_TIME_TAG,
   NAI_1553_RT_OPT_CLEAR_TIME_TAG,
   NAI_1553_RT_OPT_OVERWRITE_DATA,
   NAI_1553_RT_OPT_OVERRIDE_MODE_BIT,
   NAI_1553_RT_OPT_ALTERNATE_STATUS,
   NAI_1553_RT_OPT_ILL_RX_DISABLE,
   NAI_1553_RT_OPT_BUSY_RX_DISABLE,
   NAI_1553_RT_OPT_SET_RT_FLAG,
   NAI_1553_RT_OPT_1553A_MODE_CODES,
   NAI_1553_RT_OPT_MODE_COMMAND_OVERRIDE_BUSY,
   NAI_1553_RT_OPT_BROADCAST_DISABLE
};

static bool_t rtOptions[NUM_RT_OPTIONS] =
{
   FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
};

typedef struct bitWordOptionsStruct
{
   uint16_t wWordLocation;
   uint16_t wPermitOrInhibitIfRtBusy;
} bitWordOptionsStruct_t;

bitWordOptionsStruct_t bitWordOptions;

static uint16_t statusBitsWord;

/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_RT_Receive_ModeCodes is to demonstrate the usage of the naibrd API to create a menu
application that lets the user configure how the Remote Terminal behaves or responds to Mode Code commands from the
Bus Controller.  Specifically, this application allows the user to read/write to the mode code data table,
configure RT options, configure BIT Word options, set/unset RT status word response bits and start running the RT.
This application demonstrates the usage of the following naibrd 1553 routines.
 - naibrd_1553_GetChannelCount
 - naibrd_1553_Open
 - naibrd_1553_Initialize
 - naibrd_1553_RtInitialize
 - naibrd_1553_WriteAuxReg
 - naibrd_1553_RtSetAddress
 - naibrd_1553_RtBITWordConfigure
 - naibrd_1553_RtBITWordRead
 - naibrd_1553_RtBITWordWrite
 - naibrd_1553_RtResponseStatusBitsGet
 - naibrd_1553_RtResponseStatusBitsSet
 - naibrd_1553_RtResponseStatusBitsUnset
 - naibrd_1553_RtModeCodeReadData
 - naibrd_1553_RtModeCodeWriteData
 - naibrd_1553_RtMessageLegalityEnable
 - naibrd_1553_RtStart
 - naibrd_1553_RtStop
 - naibrd_1553_RtMessageGetFromStackRaw
 - naibrd_1553_RtMessageDecodeRaw
 - naibrd_1553_Free

The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd 1553 routines.
 - ConfigDevice
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - CheckModule
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t M1553_RT_Receive_ModeCodes(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_M1553_RT_Receive_ModeCodes(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;
}

static bool_t Run_M1553_RT_Receive_ModeCodes(int32_t cardIndex, int32_t module, uint32_t modid)
{
   /* Variables */
   bool_t bQuit = FALSE;
   int32_t rtchan;
   uint8_t rtaddr;
   int16_t DevNum = 0;
   int32_t swResult;
   bool_t bContinue = TRUE;
   int8_t cmdRequest[20];
   int32_t cmdNum;
   bool_t bSoftwareRTAddr;

   /* Set all RT Options to FALSE */
   memset((void *)rtOptions, 0, sizeof(rtOptions));

   /* Get Card, Module, Channel Numbers and Open a Handle */
   bQuit = Get1553RTCfg(modid, DEF_RT_CHANNEL, DEF_RT_ADDRESS, &rtchan, &rtaddr);
   if (bQuit)
   {
      return bQuit;
   }

   /* Get Logical Device # */
   bQuit = Get1553LogicalDevNum(DEF_RT_DEV_NUM, &DevNum);
   if (bQuit)
   {
      return bQuit;
   }

   /* Associate Card, Module and Channel Numbers with the Logical Device # */
   swResult = naibrd_1553_Open(cardIndex, module, rtchan, DevNum);
   if(swResult)
   {
      bQuit = TRUE;
      printf("Error: naibrd_1553_Open  %d", swResult);
      return bQuit;
   }

   /* Initialize Device */
   swResult = naibrd_1553_Initialize(DevNum,NAI_1553_ACCESS_CARD,NAI_1553_MODE_RT,0,0,0);
   if(swResult != 0)
   {
      bQuit = TRUE;
      printf("Error: naibrd_1553_Initialize  %d", swResult);
      return bQuit;
   }

   /* Get RT Address Source from user */
   bQuit = Get1553RTAddressSource(TRUE, &bSoftwareRTAddr);
   if (bQuit)
   {
      return bQuit;
   }

   if (bSoftwareRTAddr)
   {
      /* Set RTAD_SW_EN and RT_ADR_LAT in software */
      swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0018);

      /* Set RT address */
      swResult = naibrd_1553_RtSetAddress(DevNum, rtaddr);
      if(swResult != 0)
      {
         bQuit = TRUE;
         printf("Error: naibrd_1553_RtSetAddress  %d", swResult);
         return bQuit;
      }
   }
   else
   {
      /* Unset RTAD_SW_EN and set RT_ADR_LAT in software */
      swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0008);
   }

   if (modid == NAI_MODULE_ID_FT8)
   {
      /* Simplex Enable (for internal NAI testing only, do not enable) */
      /*naibrd_1553_WriteAuxReg(DevNum, 0x3, 0x4000);
        naibrd_1553_WriteAuxReg(DevNum, 0xF, 0x1);*/
   }

   /* Set initial BIT Word options */
   bitWordOptions.wWordLocation = NAI_1553_RT_BIT_REGISTER;
   bitWordOptions.wPermitOrInhibitIfRtBusy = NAI_1553_RT_BIT_ENABLED;
   swResult = naibrd_1553_RtBITWordConfigure(DevNum, bitWordOptions.wWordLocation, bitWordOptions.wPermitOrInhibitIfRtBusy);
   if(swResult != 0)
   {
      bQuit = TRUE;
      printf("Error: naibrd_1553_RtBITWordConfigure  %d", swResult);
      return bQuit;
   }

   /* Get the status bits word */
   swResult = naibrd_1553_RtResponseStatusBitsGet(DevNum, &statusBitsWord);

   Load1553MenuCommands(NUM_MENU_ITEMS, mainMenuCmds);
   bContinue = FALSE;
   Display1553MenuCommands((int8_t *)"MENU SELECTION");
   while (!bContinue)
   {
      printf("\nEnter Menu Selection: ");
      swResult = naiapp_fgets_stdin(cmdRequest, 20);
      if (swResult <= 0)
      {
         printf("\nInvalid command entered.\n\n");
         Display1553MenuCommands((int8_t *)"MENU SELECTION");
      }
      else
      {
         if (Get1553CmdNum(NUM_MENU_ITEMS - 1, cmdRequest, &cmdNum))
         {
            if (cmdNum == (NUM_MENU_ITEMS - 1))
            {
               /* Quit */
               bContinue = TRUE;
            }
            else
            {
               Menu1553Command(cmdNum, DevNum);
               Display1553MenuCommands((int8_t *)"MENU SELECTION");
            }
         }
         else
         {
            if (toupper(cmdRequest[0]) == 'Q')
            {
               /* Quit */
               bContinue = TRUE;
            }
            else
            {
               printf("\nInvalid command entered.\n\n");
               Display1553MenuCommands((int8_t *)"MENU SELECTION");
            }
         }
      }
   }

   /* Free 1553 Device */
   swResult = naibrd_1553_Free(DevNum);
   if(swResult != 0)
   {
      bQuit = TRUE;
      printf("Error: naibrd_1553_Free  %d", swResult);
      return bQuit;
   }

   return bQuit;
}

static int ProcessMessages(uint16_t DevNum, int32_t duration)
{
   time_t end;
   uint32_t swResult;
   int32_t i;
   naiDecodedMessageStructure DecodedMsgStruct;
   uint16_t wsBuffer[72] = { 0x0000 };
   int32_t count = 0;

   end = time(NULL) + duration;

   while (time(NULL) < end)
   {
      /* If the stack pointer has updated (new data arrived), read one message at a time */
      swResult = naibrd_1553_RtMessageGetFromStackRaw(DevNum, wsBuffer, NAI_1553_MAX_MESSAGE_SIZE_RT);
      if (swResult < 0)
      {
         printf("Error: naibrd_1553_RtMessageGetFromStackRaw %d\n\n", swResult);
         return 0;
      }
      else if (swResult > 0)
      {
         /* Decode Raw Message */
         swResult = naibrd_1553_RtMessageDecodeRaw(DevNum, wsBuffer, &DecodedMsgStruct);
         if (swResult < 0)
         {
            printf("Error: naibrd_1553_RtMessageDecodeRaw %d\n\n", swResult);
            return 0;
         }

         if ((DecodedMsgStruct.wCommandWord1 & 0x0400) != 0x0400)   /* If this is a Rx message */
         {
            printf("Rx Msg Received\n");
            printf("\n\nDecoded Message:\n\n");
            printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
            printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
            printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
            printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
            printf("Data:");
            for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
            {
               if (i % 8 == 0)
               {
                  printf("\n");
               }
               printf("0x%04X ", DecodedMsgStruct.waData[i]);
            }
            printf("count: %d\n", count++);
            printf("\n\n");
         }
         else
         {
            printf("Tx Msg Received\n");
            printf("\n\nDecoded Message:\n\n");
            printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
            printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
            printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
            printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
            printf("count: %d\n", count++);
            printf("\n\n");
         }
      }
      nai_msDelay(10);
   }

   return 1;
}

static int16_t ConfigureRTOptions(int16_t DevNum)
{
   uint32_t options = 0;
   int32_t i;
   int16_t swResult;

   for (i = 0; i < NUM_RT_OPTIONS; i++)
   {
      if (rtOptions[i])
      {
         options |= rtOptionsMap[i];
      }
   }

   swResult = naibrd_1553_RtInitialize(DevNum, NAI_1553_RT_CMDSTK_SIZE_2048, options);

   /* Update the status bits word to the user's latest setting */
   swResult = naibrd_1553_RtResponseStatusBitsSet(DevNum, statusBitsWord);

   return swResult;
}

/*** CALLBACK FUNCTIONS ***/
static bool_t ModeCodeDataTable(int16_t DevNum)
{
   uint16_t data;
   int32_t swResult;
   int8_t cmdRequest[20];
   bool_t bContinue = FALSE;
   int32_t cmdNum = 0;
   int8_t *endptr;

   printf("\n\n");
   printf("=========================== MODE CODE DATA TABLE ============================\n");
   printf("Cmd |       Mode Code                                           |  Data Word \n");
   printf("-----------------------------------------------------------------------------\n");
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_RX_SYNCHRONIZE, &data);
   printf(" 1   SYNCHRONIZE WITH DATA (From BC)                                0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_RX_TRANSMITTER_SHUTDOWN, &data);
   printf(" 2   SELECTED TRANSMITTER SHUTDOWN (From BC)                        0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_RX_OVERRIDE_TRANSMITTER_SHUTDOWN, &data);
   printf(" 3   OVERRIDE SELECTED TRANSMITTER SHUTDOWN (From BC)               0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_VECTOR_WORD, &data);
   printf(" 4   TRANSMIT VECTOR WORD (To BC)                                   0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_LAST_COMMAND_WORD, &data);
   printf(" 5   TRANSMIT LAST COMMAND WORD (Updated by Core)                   0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_TX_TRANSMIT_BUILT_IN_TEST_WORD, &data);
   printf(" 6   TRANSMIT BIT WORD (To BC)                                      0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_BROADCAST_SYNCHRONIZE, &data);
   printf(" 7   BROADCAST SYNCHRONIZE WITH DATA (From BC)                      0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_BROADCAST_SELECTED_TRANSMITTER_SHUTDOWN, &data);
   printf(" 8   BROADCAST SELECTED TRANSMITTER SHUTDOWN (From BC)              0x%04X\n", data);
   naibrd_1553_RtModeCodeReadData(DevNum, NAI_1553_RT_MODECODE_DATA_BROADCAST_OVERRIDE_SELECTED_TRANSMITTER_SHUTDOWN, &data);
   printf(" 9   BROADCAST OVERRIDE SELECTED TRANSMITTER SHUTDOWN (From BC)     0x%04X\n", data);

   while (!bContinue)
   {
      printf("\nEnter Mode Code Cmd to Write (or Q to quit): ");
      swResult = naiapp_fgets_stdin(cmdRequest, 20);
      if (swResult <= 0)
      {
         printf("Invalid command entered. Please enter a valid command.\n");
      }
      else
      {
         if (toupper(cmdRequest[0]) == 'Q')
         {
            return TRUE;
         }
         else
         {
            cmdNum = atoi((char *)cmdRequest);
            if ((cmdNum < 1) || (9 < cmdNum))
            {
               printf("Invalid command entered. Please enter a valid command.\n");
            }
            else
            {
               printf("Selected:\n");
               printf("%s\n", modeCodeDataStrings[cmdNum - 1]);
               bContinue = TRUE;
            }
         }
      }
   }

   bContinue = FALSE;

   while (!bContinue)
   {
      printf("\nEnter Data Word to Write (or Q to quit): ");
      swResult = naiapp_fgets_stdin(cmdRequest, 20);
      if (swResult <= 0)
      {
         printf("Invalid word entered. Please enter a valid data word.\n");
      }
      else
      {
         if (toupper(cmdRequest[0]) == 'Q')
         {
            return TRUE;
         }
         else
         {
            data = (uint16_t)strtol((char *)cmdRequest, (char **)&endptr, 16);
            if (((char *)cmdRequest) == (char *)endptr)
            {
               printf("Invalid word entered. Please enter a valid data word.\n");
            }
            else
            {
               naibrd_1553_RtModeCodeWriteData(DevNum, modeCodeDataMap[cmdNum - 1], data);
               printf("Data Word set to: 0x%04X\n", data);
               bContinue = TRUE;
            }
         }
      }
   }

   return TRUE;
}

static bool_t RTOptions(int16_t DevNum)
{
   bool_t bContinue = TRUE;
   int32_t swResult;
   int8_t cmdRequest[20];
   int32_t cmdNum;

   while (bContinue)
   {
      bContinue = FALSE;

      printf("\n\n");
      printf("================================ RT OPTIONS =================================\n");
      printf("Cmd |       RT Option                                            |  Enabled? \n");
      printf("-----------------------------------------------------------------------------\n");
      printf(" 1   Clear Service Request after Tx Vector Word                        %s    \n", rtOptions[0] ? "Y" : "N");
      printf(" 2   Load time tag on synchronize command                              %s    \n", rtOptions[1] ? "Y" : "N");
      printf(" 3   Clear time tag on synchronize command                             %s    \n", rtOptions[2] ? "Y" : "N");
      printf(" 4   Overwrite invalid data                                            %s    \n", rtOptions[3] ? "Y" : "N");
      printf(" 5   Override mode T/R* error                                          %s    \n", rtOptions[4] ? "Y" : "N");
      printf(" 6   RT alternate status word enable                                   %s    \n", rtOptions[5] ? "Y" : "N");
      printf(" 7   Illegal receive transfer disable                                  %s    \n", rtOptions[6] ? "Y" : "N");
      printf(" 8   Busy receive transfer disable                                     %s    \n", rtOptions[7] ? "Y" : "N");
      printf(" 9   Flag if loopback test failed                                      %s    \n", rtOptions[8] ? "Y" : "N");
      printf(" 10  1553a mode codes enabled                                          %s    \n", rtOptions[9] ? "Y" : "N");
      printf(" 11  Busy bit and data word sent                                       %s    \n", rtOptions[10] ? "Y" : "N");
      printf(" 12  Broadcast disabled                                                %s    \n", rtOptions[11] ? "Y" : "N");

      printf("\nEnter RT Option Cmd to set (or Q to quit): ");
      swResult = naiapp_fgets_stdin(cmdRequest, 20);
      if (swResult <= 0)
      {
         printf("Invalid command entered. Please enter a valid command.\n");
      }
      else
      {
         if (toupper(cmdRequest[0]) == 'Q')
         {
            return TRUE;
         }
         else
         {
            cmdNum = atoi((char *)cmdRequest);
            if ((cmdNum < 1) || (NUM_RT_OPTIONS < cmdNum))
            {
               printf("Invalid command entered. Please enter a valid command.\n");
            }
            else
            {
               printf("Selected: %d\n", cmdNum);

               while (!bContinue)
               {
                  printf("\nEnable (Y) or Disable (N) option (or Q to quit): ");
                  swResult = naiapp_fgets_stdin(cmdRequest, 20);
                  if (swResult <= 0)
                  {
                     printf("Invalid word entered. Please enter a valid data word.\n");
                  }
                  else
                  {
                     if (toupper(cmdRequest[0]) == 'Q')
                     {
                        return TRUE;
                     }
                     else if (toupper(cmdRequest[0]) == 'Y')
                     {
                        rtOptions[cmdNum - 1] = TRUE;
                        ConfigureRTOptions(DevNum);
                        bContinue = TRUE;
                     }
                     else if (toupper(cmdRequest[0]) == 'N')
                     {
                        rtOptions[cmdNum - 1] = FALSE;
                        ConfigureRTOptions(DevNum);
                        bContinue = TRUE;
                     }
                     else
                     {
                        printf("Invalid command entered. Please enter a valid command.\n");
                     }
                  }
               }
            }
         }
      }
   }

   return TRUE;
}

static bool_t BITOptions(int16_t DevNum)
{
   bool_t bContinue = TRUE;
   int32_t swResult;
   int8_t cmdRequest[20];
   int32_t cmdNum;
   uint16_t data;
   char *endptr;

   while (bContinue)
   {
      bContinue = FALSE;

      printf("\n\n");
      printf("========================= BIT WORD MENU ==========================\n");
      printf("BIT Word Source (REGISTER/MEMORY):                       %s\n", (bitWordOptions.wWordLocation == NAI_1553_RT_BIT_REGISTER) ? "REGISTER" : "MEMORY");
      printf("Permit BIT Word Transmit when RT is Busy:                %s\n", (bitWordOptions.wPermitOrInhibitIfRtBusy == NAI_1553_RT_BIT_ENABLED) ? "YES" : "NO");
      swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_REGISTER, &data);
      printf("BIT Word Value in Register (Read only, updated by core): 0x%04X\n", data);
      swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_MEMORY, &data);
      printf("BIT Word Value in Memory (R/W):                          0x%04X\n\n\n", data);
      printf("Cmd |       Selection                                             \n");
      printf("------------------------------------------------------------------\n");
      printf(" 1   Select BIT Word Source\n");
      printf(" 2   RT Busy\n");
      printf(" 3   Write BIT Word\n");

      printf("\nEnter Menu Selection Cmd Number (or Q to quit): ");
      swResult = naiapp_fgets_stdin(cmdRequest, 20);
      if (swResult <= 0)
      {
         printf("Invalid command entered. Please enter a valid command.\n");
      }
      else
      {
         if (toupper(cmdRequest[0]) == 'Q')
         {
            return TRUE;
         }
         else
         {
            cmdNum = atoi((char *)cmdRequest);
            if ((cmdNum < 1) || (NUM_BIT_MENU_ITEMS < cmdNum))
            {
               printf("Invalid command entered. Please enter a valid command.\n");
            }
            else
            {
               printf("Selected: %d\n", cmdNum);

               switch (cmdNum)
               {
                  case 1:
                     while (!bContinue)
                     {
                        printf("\nBIT Word from Register (R) or Memory (M) (or Q to quit)? ");
                        swResult = naiapp_fgets_stdin(cmdRequest, 20);
                        if (swResult <= 0)
                        {
                           printf("Invalid word entered. Please enter a valid data word.\n");
                        }
                        else
                        {
                           if (toupper(cmdRequest[0]) == 'Q')
                           {
                              return TRUE;
                           }
                           else if (toupper(cmdRequest[0]) == 'R')
                           {
                              bitWordOptions.wWordLocation = NAI_1553_RT_BIT_REGISTER;
                              swResult = naibrd_1553_RtBITWordConfigure(DevNum, bitWordOptions.wWordLocation, bitWordOptions.wPermitOrInhibitIfRtBusy);
                              bContinue = TRUE;
                           }
                           else if (toupper(cmdRequest[0]) == 'M')
                           {
                              bitWordOptions.wWordLocation = NAI_1553_RT_BIT_MEMORY;
                              swResult = naibrd_1553_RtBITWordConfigure(DevNum, bitWordOptions.wWordLocation, bitWordOptions.wPermitOrInhibitIfRtBusy);
                              bContinue = TRUE;
                           }
                           else
                           {
                              printf("Invalid command entered. Please enter a valid command.\n");
                           }
                        }
                     }
                     break;
                  case 2:
                     while (!bContinue)
                     {
                        printf("\nPermit (P) or Inhibit (I) Transmission of BIT Word when RT is busy (or Q to quit)? ");
                        swResult = naiapp_fgets_stdin(cmdRequest, 20);
                        if (swResult <= 0)
                        {
                           printf("Invalid word entered. Please enter a valid data word.\n");
                        }
                        else
                        {
                           if (toupper(cmdRequest[0]) == 'Q')
                           {
                              return TRUE;
                           }
                           else if (toupper(cmdRequest[0]) == 'P')
                           {
                              bitWordOptions.wPermitOrInhibitIfRtBusy = NAI_1553_RT_BIT_ENABLED;
                              swResult = naibrd_1553_RtBITWordConfigure(DevNum, bitWordOptions.wWordLocation, bitWordOptions.wPermitOrInhibitIfRtBusy);
                              bContinue = TRUE;
                           }
                           else if (toupper(cmdRequest[0]) == 'I')
                           {
                              bitWordOptions.wPermitOrInhibitIfRtBusy = NAI_1553_RT_BIT_DISABLED;
                              swResult = naibrd_1553_RtBITWordConfigure(DevNum, bitWordOptions.wWordLocation, bitWordOptions.wPermitOrInhibitIfRtBusy);
                              bContinue = TRUE;
                           }
                           else
                           {
                              printf("Invalid command entered. Please enter a valid command.\n");
                           }
                        }
                     }
                     break;
                  case 3:
                     while (!bContinue)
                     {
                        printf("\nEnter 16-bit value to write as the BIT Word (or Q to quit): ");
                        swResult = naiapp_fgets_stdin(cmdRequest, 20);
                        if (swResult <= 0)
                        {
                           printf("Invalid word entered. Please enter a valid data word.\n");
                        }
                        else
                        {
                           if (toupper(cmdRequest[0]) == 'Q')
                           {
                              return TRUE;
                           }
                           else
                           {
                              data = (uint16_t)strtol((char *)cmdRequest, (char **)&endptr, 16);
                              if (((char *)cmdRequest) == (char *)endptr)
                              {
                                 printf("Invalid word entered. Please enter a valid data word.\n");
                              }
                              else
                              {
                                 swResult = naibrd_1553_RtBITWordWrite(DevNum, data);
                                 printf("BIT Word set to: 0x%04X\n", data);
                                 bContinue = TRUE;
                              }
                           }
                        }
                     }
                     break;
                  default:
                     break;
               }
            }
         }
      }
   }

   return TRUE;
}

static bool_t StatusBits(int16_t DevNum)
{
   bool_t bContinue = TRUE;
   int32_t swResult;
   int8_t cmdRequest[20];
   int32_t cmdNum;

   while (bContinue)
   {
      bContinue = FALSE;

      swResult = naibrd_1553_RtResponseStatusBitsGet(DevNum, &statusBitsWord);

      printf("\n\n");
      printf("============================= SET STATUS BITS ===============================\n");
      printf("Bit |       Bit Description                                    | Set or Unset\n");
      printf("-----------------------------------------------------------------------------\n");
      printf(" 11  Dynamic Bus Control (Alt Status: Message Error)                %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S10) ? "SET" : "UNSET");
      printf(" 10  Busy Bit (Alt Status: Instrumentation)                         %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S09) ? "SET" : "UNSET");
      printf(" 9   Service Request (Alt Status: Service Request)                  %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S08) ? "SET" : "UNSET");
      printf(" 8   Subsystem Flag (Alt Status: N/A)                               %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S07) ? "SET" : "UNSET");
      printf(" 7   Terminal (RT) Flag (Alt Status: N/A)                           %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S06) ? "SET" : "UNSET");
      printf(" 6   N/A                                                            %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S05) ? "SET" : "UNSET");
      printf(" 5   N/A                                                            %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S04) ? "SET" : "UNSET");
      printf(" 4   N/A (Alt Status: Busy Bit)                                     %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S03) ? "SET" : "UNSET");
      printf(" 3   N/A (Alt Status: Subsystem Flag)                               %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S02) ? "SET" : "UNSET");
      printf(" 2   N/A                                                            %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S01) ? "SET" : "UNSET");
      printf(" 1   N/A (Alt Status: Terminal Flag)                                %s\n", (statusBitsWord & NAI_1553_RT_STATUS_BIT_S00) ? "SET" : "UNSET");

      printf("\nEnter Status Bit (or Q to quit): ");
      swResult = naiapp_fgets_stdin(cmdRequest, 20);
      if (swResult <= 0)
      {
         printf("Invalid command entered. Please enter a valid command.\n");
      }
      else
      {
         if (toupper(cmdRequest[0]) == 'Q')
         {
            return TRUE;
         }
         else
         {
            cmdNum = atoi((char *)cmdRequest);
            if ((cmdNum < 1) || (11 < cmdNum))
            {
               printf("Invalid command entered. Please enter a valid command.\n");
            }
            else
            {
               printf("Selected Bit %d\n", cmdNum);

               while (!bContinue)
               {
                  printf("\nSet (S) or Unset (U) bit (or Q to quit): ");
                  swResult = naiapp_fgets_stdin(cmdRequest, 20);
                  if (swResult <= 0)
                  {
                     printf("Invalid word entered. Please enter a valid data word.\n");
                  }
                  else
                  {
                     if (toupper(cmdRequest[0]) == 'Q')
                     {
                        return TRUE;
                     }
                     else if (toupper(cmdRequest[0]) == 'S')
                     {
                        swResult = naibrd_1553_RtResponseStatusBitsSet(DevNum, (1 << cmdNum));
                        swResult = naibrd_1553_RtResponseStatusBitsGet(DevNum, &statusBitsWord);
                        bContinue = TRUE;
                     }
                     else if (toupper(cmdRequest[0]) == 'U')
                     {
                        swResult = naibrd_1553_RtResponseStatusBitsUnset(DevNum, (1 << cmdNum));
                        swResult = naibrd_1553_RtResponseStatusBitsGet(DevNum, &statusBitsWord);
                        bContinue = TRUE;
                     }
                     else
                     {
                        printf("Invalid command entered. Please enter a valid command.\n");
                     }
                  }
               }
            }
         }
      }
   }

   return TRUE;
}

static bool_t RunRT(int16_t DevNum)
{
   bool_t bContinue = TRUE;
   bool_t bQuit;
   int32_t duration;
   int32_t swResult;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Legalize all mode codes and subaddresses */
   swResult = naibrd_1553_RtMessageLegalityEnable(DevNum, NAI_1553_RT_ADDRESS_BOTH, NAI_1553_MT_FILTER_ALL, NAI_1553_RT_SA_ALL, 0xFFFFFFFF);

   while (bContinue)
   {
      printf("\nType duration (in seconds) to run RT or %c to quit (default: 5) : ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         duration = 5;
         if (inputResponseCnt > 0)
         {
            duration = (int)atol((const char*)inputBuffer);
         }

         /* Start RT */
         swResult = naibrd_1553_RtStart(DevNum);
         if(swResult != 0)
         {
            bQuit = TRUE;
            printf("Error: naibrd_1553_RtStart  %d", swResult);
            return bQuit;
         }

         /* Process New Messages */
         ProcessMessages(DevNum, duration);

         /* Stop RT */
         swResult = naibrd_1553_RtStop(DevNum);
         if(swResult != 0)
         {
            bQuit = TRUE;
            printf("Error: naibrd_1553_RtStop  %d", swResult);
            return bQuit;
         }
      }
      else
         bContinue = FALSE;
   }

   return TRUE;
}

Help Bot

X