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 BC SendMsg Async

M1553 BC SendMsg Async Sample Application (SSK 2.x)

Overview

The M1553 BC SendMsg Async sample application demonstrates how to send asynchronous MIL-STD-1553 Bus Controller (BC) messages during normal scheduled transmissions using the NAI Software Support Kit (SSK 2.x). Unlike the basic BC SendMsg sample which sends single-shot synchronous messages, this sample shows how to inject additional messages into the BC schedule at either high or low priority while the BC is actively running a synchronous message frame.

The application configures one BC-to-RT synchronous message that runs continuously in a major frame, then creates two additional BC-to-RT messages that are transmitted asynchronously. The user selects whether to send asynchronous messages at high priority (one message at a time, injected between synchronous messages) or low priority (queued and drained from the async message list). This is useful in systems where time-critical commands must be injected into an existing BC schedule without stopping the schedule.

This sample supports the following 1553 module types:

  • FT0 through FTF — 4-channel MIL-STD-1553 modules

  • FTJ, FTK — 2-channel MIL-STD-1760 modules

For detailed 1553 protocol specifications, message formats, and hardware register descriptions, see the FTA-FTF Manual.

For the SSK 1.x version, see M1553 BC SendMessage Async (SSK 1.x).

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a 1553 module installed (FTA-FTF, FTJ-FTK).

  • SSK 2.x installed on your development host.

  • The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.

  • A second 1553 device (RT) connected on the same bus to respond to BC messages.

How to Run

Launch the m1553_bc_send_msg_async executable from your build output directory. On startup the application looks for a configuration file (default_1553BC_SendMessageAsync.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. Once connected, the application prompts for channel, bus selection, async message priority (high or low), and software override settings, then transmits synchronous and asynchronous messages in a loop.

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 2.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_1553BC_SendMessageAsync.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_GetModuleName() so downstream code can adapt to the specific 1553 variant installed.

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_bc_send_msg_async(void)
#else
int32_t main(void)
#endif
{
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   bool_t  stop = NAI_FALSE;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_m1553_bc_send_msg_async(cardIndex, module, moduleID);
               }
            }
         }

         naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}
Important

Common Connection Errors

  • No board found — verify the board is powered and the connection (PCIe, Ethernet, etc.) is active.

  • Connection timeout — check network settings and firewall rules for Ethernet connections.

  • Invalid card/module index — indices are 0-based for cards and 1-based for modules.

  • Module not present — confirm the 1553 module is physically installed in the expected slot.

Program Structure

The application is organized into three functions:

  • main() — standard SSK 2.x startup: board menu, card/module selection, then delegates to the run function.

  • Run_m1553_bc_send_msg_async() — validates the module supports 1553 via IsFTx1553() or 1760 via IsFTx1760(), queries for a channel number, and calls RunSendMessageAsync().

  • RunSendMessageAsync() — the core workflow: opens the device, initializes as BC with async support, creates synchronous and asynchronous messages, sends them, and checks results.

Entry Point

The Run_m1553_bc_send_msg_async() function checks whether the installed module supports 1553 functionality, then queries for a channel number before delegating to RunSendMessageAsync().

Command Loop

RunSendMessageAsync() prompts for configuration, then loops: each iteration writes data to the synchronous data block, starts the BC running forever, sends async messages (high or low priority), waits, then stops the BC.

Opening and Initializing the 1553 Channel

The sample opens the channel with naibrd_1553_Open() and initializes it as a BC with naibrd_1553_Init(). It then enables asynchronous message support with naibrd_1553_BcCfg().

/* Open 1553 Device(s) */
status = naibrd_1553_Open(cardIndex, module, channel, devnum);

/* Software override for BC_DISABLE and M1760 pins */
if (bSoftware)
{
   naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_MISC_BITS,
      (naibrd_1553_aux_reg_value_t)0xA000);
}

/* Reset Device */
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET,
   NAIBRD_1553_AUX_REG_MISC_BITS_MASK_TX_INHA);
naibrd_msDelay(100);
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET,
   (naibrd_1553_aux_reg_value_t)0x0);

/* Initialize as BC */
status = naibrd_1553_Init(devnum, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_BC, 0, 0, 0);

/* Enable Asynchronous Messages */
status = naibrd_1553_BcCfg(devnum, NAIBRD_1553_BC_ASYNCHRONOUS_BOTH_PRIORITY_MODES);
  • NAIBRD_1553_BC_ASYNCHRONOUS_BOTH_PRIORITY_MODES — enables both high-priority and low-priority asynchronous message modes. This must be called before using the _ExecuteOnce async send functions.

Creating Messages and Frame Hierarchy

The sample creates a single synchronous BC-to-RT message (MSG1) with a standard frame hierarchy, then creates two asynchronous BC-to-RT messages (MSG3, MSG4) with their own data blocks.

Synchronous Message

/* Create BC Data Block */
status = naibrd_1553_BcDataBlkCreate(devnum, DBLK1, 32, NULL, 0);

/* Create BC to RT Message */
status = naibrd_1553_BcMsgCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus);

/* Create Execute Message Command */
status = naibrd_1553_BcCmdCreate(devnum, OP1, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE,
   NAIBRD_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);

/* Create Minor and Major Frames */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrmCreate(devnum, MNR1, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrmCreate(devnum, MJR, NAIBRD_1553_BC_FRAME_MAJOR, aOpCodes, 1,
   MNR_FRAME_TIME * 10, 0);

The minor frame time (MNR_FRAME_TIME) is set to 500 ms. The major frame time is expressed in 0.1 ms units, so 500 * 10 = 5000 gives a 500 ms cycle period.

Asynchronous Messages

/* Create BC to RT Async Message 1 with data 0xBCBC */
for (i = 0; i < 32; i++) aData[i] = 0xBCBC;
status = naibrd_1553_BcAsyncMsgCreateBcToRt(devnum, MSG3, DBLK3, RT_ADDRESS, RT_SUBADDRESS,
   32, 0, usBus, aData);

/* Create BC to RT Async Message 2 with data 0xAAAA */
for (i = 0; i < 32; i++) aData[i] = 0xAAAA;
status = naibrd_1553_BcAsyncMsgCreateBcToRt(devnum, MSG4, DBLK4, RT_ADDRESS, RT_SUBADDRESS,
   32, 0, usBus, aData);

Unlike synchronous messages, asynchronous messages include their data payload directly in the creation call via the aData parameter.

Sending Asynchronous Messages

The BC is started with NAIBRD_1553_BC_FRAME_RUN_FOREVER so the synchronous schedule runs continuously in the background. Asynchronous messages are then injected using one of two modes.

High Priority Mode

status = naibrd_1553_BcAsyncMsgSendAtHighPriority_ExecuteOnce(devnum, MSG3, 0);

High-priority async messages are injected between the currently executing synchronous messages. The _ExecuteOnce suffix means the async message is sent once and the call returns immediately with the result. If the return value is NAIBRD_1553_RC_ASYNCHRONOUS_MESSAGE_ERROR, the application decodes the block status with naibrd_1553_GetBlkStatusWordErrorString() to determine the error type.

Low Priority Mode

do
{
   status = naibrd_1553_BcAsyncMsgSendAtLowPriority_ExecuteOnce(devnum, &dummycount, 0);
   if (status > 0)
   {
      naiif_printf("\r\nremaining async count: %d", status);
   }
   naibrd_msDelay(MNR_FRAME_TIME);
} while (status > 0);

Low-priority async messages are queued and sent one at a time during idle time between minor frames. Each call to naibrd_1553_BcAsyncMsgSendAtLowPriority_ExecuteOnce() returns the number of remaining async messages in the queue. The loop continues until the queue is empty (NAIBRD_1553_RC_ASYNCHRONOUS_LIST_IS_EMPTY). The delay between calls should match the minor frame time.

After low-priority transmission completes, the sample deletes the async messages and their data blocks using naibrd_1553_BcMsgDelete() and naibrd_1553_BcDataBlkDelete() to free resources for the next iteration.

Cleanup

When finished, the BC is stopped and the logical device is freed:

status = naibrd_1553_BcStop(devnum);
status = naibrd_1553_Free(devnum);

Troubleshooting Reference

Note
This table summarizes errors covered in preceding sections. Consult the FTA-FTF Manual for hardware-specific diagnostics.
Error / Symptom Possible Causes Suggested Resolution

naibrd_1553_Open returns non-zero

Channel already open, invalid card/module/channel index

Verify indices, ensure no other application holds the channel

naibrd_1553_BcCfg returns non-zero

Device not initialized as BC before calling BcCfg

Ensure naibrd_1553_Init with NAIBRD_1553_MODE_BC completes before naibrd_1553_BcCfg

NAIBRD_1553_RC_ASYNCHRONOUS_MESSAGE_ERROR from high-priority send

RT not responding, bus wiring issue

Decode block status with naibrd_1553_GetBlkStatusWordErrorString(), check RT and cabling

Low-priority queue never empties

Minor frame time too short, too many queued messages

Increase delay between _ExecuteOnce calls to match minor frame time

No response from RT

RT not on bus, bus wiring issue, wrong bus (A/B) selected

Verify RT is active, check cabling, try other bus

Software override needed

BC_DISABLE or M1760 pins not externally driven high

Enable software override when prompted for bench testing

Module not recognized as 1553

Module ID not in IsFTx1553() or IsFTx1760() switch cases

Verify the module type is FT0-FTF, FTJ/FTK, or a combination module

Full Source

Full Source — m1553_bc_send_msg_async.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"

/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_1553.h"
#include "nai_libs/naibrd/include/functions/naibrd_1553_1760_status.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"

/* Common 1553 Sample Program include files */
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/m1553_common_utils.h"
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/BC/m1553_bc_common_utils.h"

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

static const int8_t *DEF_CONFIG_FILE = (int8_t *)"default_1553BC_SendMessageAsync.txt";

/* Function prototypes */
static bool_t Run_m1553_bc_send_msg_async(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t RunSendMessageAsync(int32_t cardIndex, int32_t module, int32_t channel);

/* define message constants */
#define MSG1         1
#define MSG2         2
#define MSG3         3
#define MSG4         4
#define MSG5         5
#define MSG6         6

/* define opcodes */
#define OP1          1
#define OP2          2
#define OP3          3
#define OP4          4

/* define frame constants */
#define MNR1         1
#define MNR2         3
#define MJR          2

/* define data block numbers */
#define DBLK1        1
#define DBLK2        2
#define DBLK3        3
#define DBLK4        4
#define DBLK5        5
#define DBLK6        6

#define DEF_M1553_CARD_INDEX                 0
#define DEF_M1553_MODULE                     1
#define DEF_M1553_CHANNEL                    1
#define DEF_M1553_DEVNUM                     1

#define RT_ADDRESS                           1
#define RT_SUBADDRESS                        2

#define MNR_FRAME_TIME                       500         /* in ms */

/**************************************************************************************************************/
/** \defgroup M1553_BC_SendMessage_Async

\brief This sample application demonstrates how to configure a channel as a Bus Controller and send an asynchronous message.

The purpose of the m1553_bc_send_msg_async is to illustrate the methods to call in the naibrd library to configure
the 1553 channel as a Bus Controller and send asynchronous messages during normal BC message transmissions.

The main steps include:
- Querying the user for the card index and module number.
- Configuring the channel for Bus Controller functionality with aync messages enabled.
- Configuring a sync frame with one message of a selected type.
- Create two more messages to be transmitted asynchronously.
- Starting the BC to transmit the synchronous message.
- Send the two asynchronous messages, one at high and one at low priority.
- Displaying the RT response and BC Status.
*/
/**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_bc_send_msg_async(void)
#else
int32_t main(void)
#endif
{
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   bool_t  stop = NAI_FALSE;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         /* Select Card Index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Select Module */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_m1553_bc_send_msg_async(cardIndex, module, moduleID);
               }
            }
         }

         naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   naiif_printf("\r\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_bc_send_msg_async(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = NAI_FALSE;
   int32_t channel;
   int32_t MaxChannel = 4;

   if ((IsFTx1553(modid)) || (IsFTx1760(modid)))
   {
      MaxChannel = 4;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channel);
      if (!bQuit)
      {
         bQuit = RunSendMessageAsync(cardIndex, module, channel);
      }
   }
   else
      naiif_printf("\r\nThis module does not support 1553 functionality.\r\n");

   return bQuit;
}

static bool_t RunSendMessageAsync(int32_t cardIndex, int32_t module, int32_t channel)
{
   int32_t i;
   bool_t bQuit = NAI_FALSE;
   uint32_t usBus;
   naibrd_1553_t status;
   uint16_t increment = 0;
   uint16_t aData[32] = { 0 };
   int16_t aOpCodes[20] = { 0 };
   bool_t bContinue = NAI_TRUE;
   int16_t devnum;
   uint16_t dummycount;
   bool_t bSoftware, bHighPriority, bNewAsyncMsgWasCreated = NAI_FALSE;
   naibrd_1553_msgstruct_t DecodedMsgStruct;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Get the Logical Device Number */
   bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUM, &devnum);
   if (!bQuit)
   {
      /* Which bus are we firing on? */
      bQuit = GetBus(&usBus);
      if (!bQuit)
      {
         bQuit = Get1553BCAsyncMsgType(NAI_TRUE, &bHighPriority);
         if (!bQuit)
         {
            bQuit = Get1553BCSoftwareOverride(NAI_TRUE, &bSoftware);
            if (!bQuit)
            {
               /* Open 1553 Device(s) */
               status = naibrd_1553_Open(cardIndex, module, channel, devnum);
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_Open Ch %d, status = %d", channel, status);
                  return NAI_TRUE;
               }

               if (bSoftware)
               {
                  /* Override external BC_DISABLE and M1760 (In order to configure as BC, this needs to */
                  /* be set if BC_DISABLE and M1760 pins are not driven high) */
                  naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, (naibrd_1553_aux_reg_value_t)0xA000);
               }
               else
               {
                  /* Do not override external BC_DISABLE and M1760 Inputs */
                  naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, (naibrd_1553_aux_reg_value_t)0x0000);
               }

               /* Reset Device */
               naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET, NAIBRD_1553_AUX_REG_MISC_BITS_MASK_TX_INHA);
#if defined (__VXWORKS__)
               naibrd_msDelay(1);
#elif defined (LINUX)
               naibrd_msDelay(100);
#else
               naibrd_msDelay(100);
#endif
               naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET, (naibrd_1553_aux_reg_value_t)0x0);

               /* Initialize 1553 Device(s) */
               status = naibrd_1553_Init(devnum, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_BC, 0, 0, 0);
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_Init Ch %d, status = %d", channel, status);
                  return NAI_TRUE;
               }

               /* Enable Asynchronous Messages */
               status = naibrd_1553_BcCfg(devnum, NAIBRD_1553_BC_ASYNCHRONOUS_BOTH_PRIORITY_MODES);    /* Needed to use the *_ExecuteOnce functions */
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_BcCfg Ch %d, status = %d", channel, status);
                  return NAI_TRUE;
               }

               /* Create BC Data Block */
               status = naibrd_1553_BcDataBlkCreate(devnum, DBLK1, 32, NULL, 0);
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_BcDataBlkCreate Ch %d, status = %d", channel, status);
                  return NAI_TRUE;
               }

               /* Create BC to RT Message */
               status = naibrd_1553_BcMsgCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus);
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_BcMsgCreateBcToRt status = %d", status);
                  return NAI_TRUE;
               }

               /* Create Execute Message Command */
               status = naibrd_1553_BcCmdCreate(devnum, OP1, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE, NAIBRD_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_BcCmdCreate status = %d", status);
                  return NAI_TRUE;
               }

               /* Create Call Subroutine Command */
               status = naibrd_1553_BcCmdCreate(devnum, OP2, NAIBRD_1553_OPCODE_CALL_SUBROUTINE, NAIBRD_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_BcCmdCreate status = %d", status);
                  return NAI_TRUE;
               }

               /* Create Minor Frame */
               aOpCodes[0] = OP1;
               status = naibrd_1553_BcFrmCreate(devnum, MNR1, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_BcFrmCreate status = %d", status);
                  return NAI_TRUE;
               }

               /* Create Major Frame */
               aOpCodes[0] = OP2;
               status = naibrd_1553_BcFrmCreate(devnum, MJR, NAIBRD_1553_BC_FRAME_MAJOR, aOpCodes, 1, MNR_FRAME_TIME * 10, 0);     /* wFrameTime: 1 = 0.1 ms */
               if (status != 0)
               {
                  naiif_printf("Error: naibrd_1553_BcFrmCreate status = %d", status);
                  return NAI_TRUE;
               }

               while (bContinue)
               {
                  static uint16_t txHighPriorityMsgSendCount;

                  /* Load Scheduled BC Message data block with incremental data */
                  for (i = 0; i < 32; i++)
                  {
                     aData[i] = increment++;
                  }
                  status = naibrd_1553_BcDataBlkWrite(devnum, DBLK1, aData, 32, 0);
                  if (status != 0)
                  {
                     naiif_printf("Error: naibrd_1553_BcDataBlkWrite status = %d", status);
                     return NAI_TRUE;
                  }

                  /**********************************************************************/
                  /*** ADD 2 MESSAGES TO THE ASYNC QUEUE (For Low priority messaging) ***/
                  /**********************************************************************/
                  /* Create BC to RT Async Message 1 */
                  if (((!bNewAsyncMsgWasCreated) && (!bHighPriority)) || (txHighPriorityMsgSendCount == 0)) /* Do not re-created async msg if sending in high priority */
                  {
                     for (i = 0; i < 32; i++)
                     {
                        aData[i] = 0xBCBC;
                     }
                     status = naibrd_1553_BcAsyncMsgCreateBcToRt(devnum, MSG3, DBLK3, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus, aData);
                     if (status != 0)
                     {
                        naiif_printf("Error: naibrd_1553_BcAsyncMsgCreateBcToRt status = %d", status);
                        return NAI_TRUE;
                     }
                     else
                     {
                        bNewAsyncMsgWasCreated = NAI_TRUE;
                     }
                     /* Create BC to RT Async Message 2 */
                     for (i = 0; i < 32; i++)
                     {
                        aData[i] = 0xAAAA;
                     }
                     status = naibrd_1553_BcAsyncMsgCreateBcToRt(devnum, MSG4, DBLK4, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus, aData);
                     if (status != 0)
                     {
                        naiif_printf("Error: naibrd_1553_BcAsyncMsgCreateBcToRt status = %d", status);
                        return NAI_TRUE;
                     }
                  }
                  /*********************************************************/
                  /* START BC TO TRANSMIT SYNCHRONOUS (SCHEDULED) MESSAGES */
                  /*********************************************************/
                  status = naibrd_1553_BcStart(devnum, MJR, NAIBRD_1553_BC_FRAME_RUN_FOREVER);
                  if (status != 0)
                  {
                     naiif_printf("Error: naibrd_1553_BcStart status = %d", status);
                     return NAI_TRUE;
                  }

                  naibrd_msDelay(50);

                  /*******************************/
                  /* SEND MSG WITH HIGH PRIORITY */
                  /*******************************/
                  if (bHighPriority)
                  {
                     /* Send High Priority Async Message */
                     status = naibrd_1553_BcAsyncMsgSendAtHighPriority_ExecuteOnce(devnum, MSG3, 0);
                     if (status == NAIBRD_1553_RC_ASYNCHRONOUS_MESSAGE_ERROR)
                     {
                        /* OPTIONAL check to determine the message error type */
                        naiif_printf("\r\nASYNC msg error:");
                        {
                           /* Get Decoded Msg Structure for Message 3 */
                           status = naibrd_1553_BcMsgGetByIdDecoded(devnum, MSG3, &DecodedMsgStruct, 1);
                           if (status < 0)
                           {
                              naiif_printf("\r\nError: naibrd_1553_BcMsgGetByIdDecoded status = %d\r\n\r\n", status);
                           }
                           else if (status > 0)
                           {
                              naiif_printf("\r\n%s", naibrd_1553_GetBlkStatusWordErrorString(NAIBRD_1553_MODE_BC, DecodedMsgStruct.blockStatus));
                              naiif_printf("\r\n\r\n");
                           }
                        }
                     }
                     else if (status == 0)
                     {
                        naiif_printf("\r\nASYNC msg sent successfully\r\n\r\n");
                     }
                     else
                     {
                        naiif_printf("Error: naibrd_1553_BcAsyncMsgSendAtHighPriority_ExecuteOnce status = %d\r\n\r\n", status);
                     }

                     txHighPriorityMsgSendCount++;
                  }
                  /**********************************/
                  /* OR SEND MSGS WITH LOW PRIORITY */
                  /**********************************/
                  else
                  {
                     do
                     {
                        /* Each call to naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce() will re-update */
                        /* the BC async message queue so that already transmitted messages are not re-sent. */
                        /* A positive value returned in status is the count of async messages in the queue that are not yet sent. */
                        status = naibrd_1553_BcAsyncMsgSendAtLowPriority_ExecuteOnce(devnum, &dummycount, 0);
                        if (status > 0)
                        {
                           naiif_printf("\r\nremaining async count: %d", status);
                        }
                        if (status == NAIBRD_1553_RC_ASYNCHRONOUS_LIST_IS_EMPTY)
                        {
                           /* Exit loop */
                           break;
                        }
                        /* Delay between calls to naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce should be */
                        /* set to the minor frame time, or the smallest minor frame time if multiple minor frames exist */
                        naibrd_msDelay(MNR_FRAME_TIME);
                     } while (status > 0);

                     naiif_printf("\r\nasync transmission complete");

                     /* OPTIONAL check errors in async messages, if any */
                     /* Get Decoded Msg Structure for Message 3 */
                     status = naibrd_1553_BcMsgGetByIdDecoded(devnum, MSG3, &DecodedMsgStruct, 1);
                     if (status < 0)
                     {
                        naiif_printf("\r\nError: naibrd_1553_BcMsgGetByIdDecoded status = %d", status);
                     }
                     else if (status > 0)
                     {
                        naiif_printf("\r\nMSG3: %s", naibrd_1553_GetBlkStatusWordErrorString(NAIBRD_1553_MODE_BC, DecodedMsgStruct.blockStatus));
                     }
                     /* Get Decoded Msg Structure for Message 4 */
                     status = naibrd_1553_BcMsgGetByIdDecoded(devnum, MSG4, &DecodedMsgStruct, 1);
                     if (status < 0)
                     {
                        naiif_printf("\r\nError: naibrd_1553_BcMsgGetByIdDecoded status = %d", status);
                     }
                     else if (status > 0)
                     {
                        naiif_printf("\r\nMSG4: %s", naibrd_1553_GetBlkStatusWordErrorString(NAIBRD_1553_MODE_BC, DecodedMsgStruct.blockStatus));
                        naiif_printf("\r\n\r\n");
                     }

                     /* Delete async message */
                     status = naibrd_1553_BcMsgDelete(devnum, MSG3);
                     if (status != 0)
                     {
                        naiif_printf("Error: naibrd_1553_BcMsgDelete status = %d", status);
                        return NAI_TRUE;
                     }
                     /* Delete async message data block */
                     status = naibrd_1553_BcDataBlkDelete(devnum, DBLK3);
                     if (status != 0)
                     {
                        naiif_printf("Error: naibrd_1553_BcDataBlkDelete status = %d", status);
                        return NAI_TRUE;
                     }

                     /* Delete async message */
                     status = naibrd_1553_BcMsgDelete(devnum, MSG4);
                     if (status != 0)
                     {
                        naiif_printf("Error: naibrd_1553_BcMsgDelete status = %d", status);
                        return NAI_TRUE;
                     }
                     /* Delete async message data block */
                     status = naibrd_1553_BcDataBlkDelete(devnum, DBLK4);
                     if (status != 0)
                     {
                        naiif_printf("Error: naibrd_1553_BcDataBlkDelete status = %d", status);
                        return NAI_TRUE;
                     }
                  }

                  /* Allow 1 more second before stopping BC */
                  naibrd_msDelay(1000);

                  /* Stop BC */
                  status = naibrd_1553_BcStop(devnum);
                  if (status != 0)
                  {
                     naiif_printf("Error: naibrd_1553_BcStop status = %d", status);
                     return NAI_TRUE;
                  }

                  naiif_printf("\r\nPress any key to send another message or Q to quit.");
                  bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
                  if (bQuit)
                  {
                     bContinue = NAI_FALSE;
                     txHighPriorityMsgSendCount = 0;
                  }
               }
            }
         }
      }
   }

   /* Free 1553 Device */
   status = naibrd_1553_Free(devnum);
   if (status != 0)
   {
      naiif_printf("Error: naibrd_1553_Free status = %d", status);
      return NAI_TRUE;
   }

   return bQuit;
}

Help Bot

X