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 MT Monitor

M1553 MT Monitor Sample Application (SSK 2.x)

Overview

The M1553 MT Monitor sample application demonstrates how to configure a MIL-STD-1553 channel as a Bus Monitor (also called Monitor Terminal or MT) and capture bus traffic using the NAI Software Support Kit (SSK 2.x). The Bus Monitor passively listens to all traffic on the 1553 bus without participating as a BC or RT, making it ideal for diagnostics, bus analysis, and traffic logging.

This sample configures a channel as an MT, demonstrates message filtering using naibrd_1553_MtMsgMonitoringDisable() to exclude specific RT/subaddress combinations, starts the monitor for a user-specified duration, and decodes all captured messages from the MT command stack.

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

For the SSK 1.x version, see M1553 MT Monitor (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.

  • Active 1553 bus traffic (BC and RT communicating) for the monitor to capture.

How to Run

Launch the m1553_mt_monitor executable from your build output directory. On startup the application looks for a configuration file (default_1553_MTMonitor.txt). This file does not ship with the SSK — it is created when you save your connection settings from the board menu. On the first run the board menu always appears. Once connected, the application prompts for MT channel and logical device number, then enters a loop where the user specifies a duration for monitoring.

MT Role in 1553 Communication

MIL-STD-1553 defines three terminal roles. Understanding where the Monitor Terminal fits helps explain why its API surface is much smaller than the BC or RT APIs.

BC, RT, and MT Roles

The Bus Controller (BC) initiates all communication on the bus by issuing command words that direct data transfers. Remote Terminals (RTs) respond to those commands — they receive data, transmit data, or execute mode codes as instructed by the BC. The Monitor Terminal (MT) is a purely passive observer. It listens to every transaction on the bus but never transmits. Because it does not participate in the protocol, the MT cannot affect bus timing or interfere with normal BC/RT exchanges.

What the MT Captures

The MT captures every transaction that passes its filter criteria. For each message, the hardware records:

  • Command words — the BC-issued command word (and a second command word for RT-to-RT transfers).

  • Status words — the RT response status for each participating terminal.

  • Data words — the payload of the transfer, up to 32 words per message.

  • Time tags — a hardware timestamp marking when the transaction occurred.

  • Block status — a status word generated by the monitoring hardware that indicates error conditions, bus selection, and message type.

When to Use MT

MT mode is the right choice when you need to observe the bus without influencing it:

  • Bus analysis — capture all traffic to understand the communication pattern between a BC and its RTs.

  • Protocol debugging — verify that command words, status words, and data payloads match expectations.

  • Traffic logging — record bus activity over time for post-processing or compliance evidence.

  • System validation — confirm that an integrated system produces the correct transactions at the correct rates.

No Data Blocks or Frame Hierarchy

Unlike the BC, which organizes transmissions into frames, minor frames, and opcodes, and unlike the RT, which maps data into subaddress-based data blocks, the MT has no comparable data structures to configure. The MT workflow is: initialize the device, optionally configure filters, start monitoring, and read captured messages. This is why the MT sample is significantly shorter and simpler than the BC or RT samples.

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. For details on board connection configuration, see the First Time Setup Guide.

The main() function follows the standard SSK 2.x startup flow: board menu, card index query, module selection, and module ID retrieval. After confirming a valid module is present, it calls Run_m1553_mt_monitor().

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_mt_monitor(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_mt_monitor(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;
}
Important

Common Connection Errors

  • No board found — verify the board is powered and the connection is active.

  • 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

Entry Point

The program entry point is main() on most platforms, or m1553_mt_monitor() on VxWorks. After the board connection and module selection, the application calls Run_m1553_mt_monitor(), which handles all MT-specific configuration and monitoring.

User Input Flow

Once inside Run_m1553_mt_monitor(), the application collects monitoring parameters through utility functions:

  1. Get1553MTCfg() — prompts for the 1553 channel number to use for monitoring. The default is channel 1. The available channels depend on the installed module type.

  2. Get1553LogicalDevNum() — assigns a logical device handle that the naibrd API uses to identify this 1553 session. The default is device 1.

Timed Monitoring Loop

Once configuration is complete, the application enters a loop that repeats until the user quits:

  1. Prompt for a duration in seconds (default: 5).

  2. Call naibrd_1553_MtStart() to begin capturing bus traffic.

  3. Run MonitorMessages() for the specified duration, polling for and displaying captured messages.

  4. Call naibrd_1553_MtStop() to halt capture.

  5. Prompt again — enter a new duration to monitor again, or press Q to exit.

This structure lets you observe the bus in successive windows without tearing down and reinitializing the MT session each time.

MT Initialization

The application opens the 1553 channel and initializes it in MT mode:

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

/* Initialize Device */
swResult = naibrd_1553_Init(DevNum, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_MT, 0, 0, 0);
  • naibrd_1553_Open() associates the card, module, and channel with a logical device number. All subsequent API calls use this device number.

  • naibrd_1553_Init() with NAIBRD_1553_MODE_MT puts the device into Monitor Terminal mode. The three trailing zeros are reserved parameters unused for MT initialization.

MT initialization is notably simpler than BC or RT initialization. There is no reset sequence, no auxiliary register configuration, no data block allocation, and no frame or subaddress table setup. The entire initialization path is: open, initialize with mode flag, optionally configure filters, and start.

Message Filtering

MT filtering controls which messages the hardware captures. By selectively disabling monitoring for specific RT addresses and subaddresses, you can reduce noise and focus on the traffic you care about.

Default Behavior

At power-on, the MT monitors all messages on the bus. Every transaction from every RT address across all subaddresses is captured. No filtering configuration is required to begin monitoring.

Selective Disabling

The sample demonstrates filtering by disabling monitoring for RT address 1, subaddress 3:

#define RT_DISABLE      1
#define SA_DISABLE      3

/* Disable Monitoring for RT 1, SA 3 Message Types */
swResult = naibrd_1553_MtMsgMonitoringDisable(DevNum, RT_DISABLE, NAIBRD_1553_DIRECTION_ALL, 1 << SA_DISABLE);

The parameters break down as follows:

  • RT_DISABLE (value 1) — the RT address to stop monitoring. This is the 5-bit terminal address (0-31).

  • NAIBRD_1553_DIRECTION_ALL — the direction filter. This disables monitoring in both the receive and transmit directions for the specified RT/subaddress combination.

  • 1 << SA_DISABLE (value 1 << 3 = 8, binary 0b1000) — a bitmask identifying the subaddress to disable. Bit N corresponds to subaddress N, so setting bit 3 disables subaddress 3.

After this call, the MT will silently ignore any transaction involving RT 1, subaddress 3, regardless of direction.

Subaddress Bitmask Explained

The subaddress parameter is a bitmask, not a single value. Each bit position corresponds to one subaddress:

  • Bit 0 = subaddress 0

  • Bit 1 = subaddress 1

  • Bit 2 = subaddress 2

  • Bit 3 = subaddress 3

  • …​and so on up to bit 31

You can disable multiple subaddresses in a single call by setting multiple bits. For example, (1 << 3) | (1 << 7) disables subaddresses 3 and 7 simultaneously.

Direction Constants

The direction filter parameter accepts:

  • NAIBRD_1553_DIRECTION_ALL — affects both receive and transmit directions.

For finer control in your own application, consult the API documentation for additional direction filter values that target only receive (BC-to-RT) or only transmit (RT-to-BC) messages.

Practical Guidance

To reduce noise during monitoring, disable monitoring for RT addresses and subaddresses you do not care about. This is especially useful on busy buses where dozens of RTs may be active but you only need to observe a few specific transactions.

Important
  • Filter accidentally disabled needed traffic — double-check the RT address, direction, and subaddress mask. A wrong mask value can silently suppress the messages you intended to capture.

  • No messages captured — all RTs disabled — if no messages appear at all, confirm that monitoring has not been disabled for every RT address. Also verify that naibrd_1553_MtStart() was called before entering the monitoring loop.

Monitoring Messages

The MonitorMessages() function is the core runtime loop. It runs for a user-specified duration, polling the MT command stack every 10 ms for captured messages.

Polling Loop

Each iteration calls naibrd_1553_MtMsgGetFromStackRaw() to check for a new message on the active stack:

swResult = naibrd_1553_MtMsgGetFromStackRaw(DevNum, wsBuffer, NAIBRD_1553_MAX_MESSAGE_SIZE_MT, NAIBRD_1553_MT_STACK_ACTIVE);
if (swResult < 0)
{
   naiif_printf("Error: naibrd_1553_MtMessageGetFromStackRaw %d\r\n\r\n", swResult);
   return 0;
}

The return value conventions are:

  • Less than 0 — an error occurred.

  • 0 — no new messages are available.

  • Greater than 0 — a message was retrieved (value is the message size).

NAIBRD_1553_MT_STACK_ACTIVE specifies the active (current) command stack.

Decoding

When a message is successfully retrieved, the raw buffer is decoded:

swResult = naibrd_1553_MtMsgDecodeRaw(DevNum, wsBuffer, &DecodedMsgStruct);

naibrd_1553_MtMsgDecodeRaw() parses the raw word buffer into a naibrd_1553_msgstruct_t structure, which provides named fields for the block status, time tag, command words, data word count, and data payload.

Message Direction Discrimination

The TR (transmit/receive) bit — bit 10 (mask 0x0400) — in command word 1 determines the direction of the transfer:

if ((DecodedMsgStruct.commandWord1 & 0x0400) != 0x0400)   /* If this is a Rx message */
{
   naiif_printf("Rx Msg Received\r\n");
   naiif_printf("\r\n\r\nDecoded Message:\r\n\r\n");
   naiif_printf("Block Status - 0x%04X\r\n", DecodedMsgStruct.blockStatus);
   naiif_printf("Time Tag - 0x%04X\r\n", DecodedMsgStruct.timeTag);
   naiif_printf("Command Word - 0x%04X\r\n", DecodedMsgStruct.commandWord1);
   naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
   naiif_printf("Data:");
   for (i = 0; i < DecodedMsgStruct.dataWordCount; i++)
   {
      if (i % 8 == 0)
      {
         naiif_printf("\r\n");
      }
      naiif_printf("0x%04X ", DecodedMsgStruct.data[i]);
   }
   naiif_printf("count: %d\r\n", count++);
   naiif_printf("\r\n\r\n");
}
else
{
   naiif_printf("Tx Msg Received\r\n");
   naiif_printf("\r\n\r\nDecoded Message:\r\n\r\n");
   naiif_printf("Block Status - 0x%04X\r\n", DecodedMsgStruct.blockStatus);
   naiif_printf("Time Tag - 0x%04X\r\n", DecodedMsgStruct.timeTag);
   naiif_printf("Command Word - 0x%04X\r\n", DecodedMsgStruct.commandWord1);
   naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
   naiif_printf("count: %d\r\n", count++);
   naiif_printf("\r\n\r\n");
}
  • When the TR bit is clear (0), this is an Rx message — the BC sent data to the RT. The application prints the full decoded message including the data payload.

  • When the TR bit is set (1), this is a Tx message — the BC requested data from the RT. The application prints the message header fields but omits the data words since the data was sent by the RT.

Decoded Message Fields

Each decoded message (naibrd_1553_msgstruct_t) contains:

Field Description

blockStatus

Hardware-generated status flags for the message transfer. Indicates error conditions (parity, Manchester encoding), bus selection (A or B), and message type.

timeTag

Hardware timestamp marking when the transaction was captured. Resolution depends on module configuration.

commandWord1

The 1553 command word issued by the BC. Contains the RT address (bits 15-11), TR bit (bit 10), subaddress (bits 9-5), and word count/mode code (bits 4-0).

dataWordCount

Number of data words in the message payload (0 to 32).

data[]

The actual data words. Up to 32 16-bit words. Displayed for Rx messages; available but not displayed for Tx messages in this sample.

When to Use Stack-Based Monitoring

The stack-based polling approach used in this sample is best suited for:

  • Simple monitoring — straightforward implementation with minimal setup.

  • Low-to-moderate traffic — bus traffic rate is low enough that polling at 10 ms intervals does not miss messages.

  • Easy implementation — the one-message-at-a-time retrieval model is easier to understand and debug than bulk FIFO reads.

For high-traffic buses where messages arrive faster than the polling interval can service them, consider using the FIFO-based retrieval approach instead.

Important
  • Stack overflow — if messages are not polled fast enough, the stack can overflow and messages will be lost. Increase the polling rate or switch to a FIFO-based approach.

  • Decode error — naibrd_1553_MtMsgDecodeRaw() returned a negative value. Verify that the buffer size is at least NAIBRD_1553_MAX_MESSAGE_SIZE_MT and that naibrd_1553_MtMsgGetFromStackRaw() returned a positive value before attempting to decode.

Device Cleanup

When the user quits the application, the 1553 device must be released by calling naibrd_1553_Free():

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

naibrd_1553_Free() releases all resources associated with the logical device number, including any internal buffers and stack allocations. Always call this function when you are done with the 1553 channel to avoid resource leaks. After calling naibrd_1553_Free(), the device number is invalid and must not be used in subsequent API calls without re-opening.

Troubleshooting Reference

Error / Symptom Possible Causes Suggested Resolution

naibrd_1553_Open returns non-zero

Channel already open, invalid indices

Verify indices, ensure no other application holds the channel.

naibrd_1553_Init returns non-zero

Device not opened, wrong mode

Ensure naibrd_1553_Open() succeeded before calling Init().

No messages captured

No bus traffic, bus not connected, monitoring duration too short

Verify BC and RT are actively communicating, increase duration.

Messages from filtered RT/SA still appearing

Filter applied after MT start, wrong bitmask

Apply filter before naibrd_1553_MtStart(), verify bitmask calculation.

MT captures garbled data

Bus noise, improper termination

Check bus wiring and termination resistors.

Stack overflow / messages lost

Bus traffic rate exceeds polling rate

Increase polling rate (reduce delay) or switch to FIFO-based retrieval.

naibrd_1553_Free returns non-zero

Device not opened or already freed

Ensure each Open() is paired with exactly one Free().

Full Source

Full Source — m1553_mt_monitor.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"

/* naiif include files */
#include "nai_libs/naiif/include/naiif.h"
#include "nai_libs/naiif/include/naiif_stdio.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"

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

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

/* Function prototypes */
static bool_t Run_m1553_mt_monitor(int32_t cardIndex, int32_t module, uint32_t modid);
static int32_t MonitorMessages(uint16_t DevNum, int32_t duration);

static const int32_t DEF_MT_CHANNEL       = 1;
static const int16_t DEF_MT_DEV_NUM       = 1;

#define RT_DISABLE      1
#define SA_DISABLE      3

/**************************************************************************************************************/
/** \defgroup M1553_MT_Monitor

\brief This sample application demonstrates how to configure a channel as a Bus Monitor and log bus traffic.

The purpose of the m1553_mt_monitor is to illustrate the methods to call in the naibrd library to configure
and run the 1553 channel as a Message Monitor. If an Rx message is detected on the bus, the Rx message data will
be displayed. If a Tx message is detected, the Tx message will be displayed. This application also demonstrates
message filtering using the naibrd_1553_MtMsgMonitoringDisable() function to disable monitoring for certain
message types.

The main steps include:
- Querying the user for the card index and module number.
- Configuring the channel for Bus Monitor functionality.
- Starting the MT to start capturing traffic.
- Displaying any messages on the bus.
*/
/**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_mt_monitor(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_mt_monitor(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_mt_monitor(int32_t cardIndex, int32_t module, uint32_t modid)
{
   /* Variables */
   bool_t bQuit = NAI_FALSE;
   int32_t mtchan;
   int16_t DevNum = 0;
   int32_t swResult;
   bool_t bContinue = NAI_TRUE;
   int32_t duration;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Get Card, Module, Channel Numbers and Open a Handle */
   bQuit = Get1553MTCfg(modid, DEF_MT_CHANNEL, &mtchan);
   if (bQuit)
   {
      return bQuit;
   }

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

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

   /* Initialize Device */
   swResult = naibrd_1553_Init(DevNum,NAIBRD_1553_ACCESS_CARD,NAIBRD_1553_MODE_MT,0,0,0);
   if(swResult != 0)
   {
      bQuit = NAI_TRUE;
      naiif_printf("Error: naibrd_1553_Initialize  %d", swResult);
      return bQuit;
   }

   /* Disable Monitoring for RT 1, SA 3 Message Types (In default power on state, all messages are monitored) */
   swResult = naibrd_1553_MtMsgMonitoringDisable(DevNum, RT_DISABLE, NAIBRD_1553_DIRECTION_ALL, 1 << SA_DISABLE);
   if(swResult != 0)
   {
      bQuit = NAI_TRUE;
      naiif_printf("Error: naibrd_1553_Initialize  %d", swResult);
      return bQuit;
   }

   while (bContinue)
   {
      naiif_printf("\r\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 MT */
         swResult = naibrd_1553_MtStart(DevNum);
         if(swResult != 0)
         {
            bQuit = NAI_TRUE;
            naiif_printf("Error: naibrd_1553_MtStart  %d", swResult);
            return bQuit;
         }

         /* Start the monitor and display any new messages */
         MonitorMessages(DevNum, duration);

         /* Stop MT */
         swResult = naibrd_1553_MtStop(DevNum);
         if(swResult != 0)
         {
            bQuit = NAI_TRUE;
            naiif_printf("Error: naibrd_1553_MtStop  %d", swResult);
            return bQuit;
         }
      }
      else
         bContinue = NAI_FALSE;
   }

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

   return bQuit;
}

static int32_t MonitorMessages(uint16_t DevNum, int32_t duration)
{
   int32_t counter_mS = 0, end_mS = 0;
   uint32_t swResult;
   int32_t i;
   naibrd_1553_msgstruct_t DecodedMsgStruct;
   uint16_t wsBuffer[80] = { 0x0000 };
   int32_t count = 0;

   end_mS = duration*1000;    /* in milliseconds */

   while (counter_mS < end_mS)
   {
      /* If the stack pointer has updated (new data arrived), read one message at a time */
      swResult = naibrd_1553_MtMsgGetFromStackRaw(DevNum, wsBuffer, NAIBRD_1553_MAX_MESSAGE_SIZE_MT, NAIBRD_1553_MT_STACK_ACTIVE);
      if (swResult < 0)
      {
         naiif_printf("Error: naibrd_1553_MtMessageGetFromStackRaw %d\r\n\r\n", swResult);
         return 0;
      }
      else if (swResult > 0)
      {
         /* Decode Raw Message */
         swResult = naibrd_1553_MtMsgDecodeRaw(DevNum, wsBuffer, &DecodedMsgStruct);
         if (swResult < 0)
         {
            naiif_printf("Error: naibrd_1553_MtMessageDecodeRaw %d\r\n\r\n", swResult);
            return 0;
         }

         if ((DecodedMsgStruct.commandWord1 & 0x0400) != 0x0400)   /* If this is a Rx message */
         {
            naiif_printf("Rx Msg Received\r\n");
            naiif_printf("\r\n\r\nDecoded Message:\r\n\r\n");
            naiif_printf("Block Status - 0x%04X\r\n", DecodedMsgStruct.blockStatus);
            naiif_printf("Time Tag - 0x%04X\r\n", DecodedMsgStruct.timeTag);
            naiif_printf("Command Word - 0x%04X\r\n", DecodedMsgStruct.commandWord1);
            naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
            naiif_printf("Data:");
            for (i = 0; i < DecodedMsgStruct.dataWordCount; i++)
            {
               if (i % 8 == 0)
               {
                  naiif_printf("\r\n");
               }
               naiif_printf("0x%04X ", DecodedMsgStruct.data[i]);
            }
            naiif_printf("count: %d\r\n", count++);
            naiif_printf("\r\n\r\n");
         }
         else
         {
            naiif_printf("Tx Msg Received\r\n");
            naiif_printf("\r\n\r\nDecoded Message:\r\n\r\n");
            naiif_printf("Block Status - 0x%04X\r\n", DecodedMsgStruct.blockStatus);
            naiif_printf("Time Tag - 0x%04X\r\n", DecodedMsgStruct.timeTag);
            naiif_printf("Command Word - 0x%04X\r\n", DecodedMsgStruct.commandWord1);
            naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
            naiif_printf("count: %d\r\n", count++);
            naiif_printf("\r\n\r\n");
         }
      }
      naibrd_msDelay(10);
      counter_mS += 10;
   }

   return 1;
}

Help Bot

X