M1553 RT Receive ModeCodes
Edit this on GitLab
M1553 RT Receive ModeCodes
Explanation
The provided C sample code is designed to demonstrate how to interact with North Atlantic Industries (NAI) embedded function modules, specifically focusing on configuring a Remote Terminal (RT) to receive mode codes using the MIL-STD-1553 protocol. Below is an explanation and walkthrough of the code.
Libraries and Headers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
Standard C libraries for input/output operations, memory management, string manipulation, time handling, and character type analysis.
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
#include "nai_1553_utils.h"
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"
NAI specific header files for board access, menu handling, 1553 utility functions, and interaction with their hardware modules.
Definitions and Constants
#define NUM_MENU_ITEMS 6
#define NUM_RT_OPTIONS 12
#define NUM_BIT_MENU_ITEMS 3
#define DEF_RT_CHANNEL 1
#define DEF_RT_DEV_NUM 1
#define DEF_RT_ADDRESS 1
-
NUM_MENU_ITEMS
: Number of items in the main menu. -
NUM_RT_OPTIONS
: Number of options for configuring the RT. -
NUM_BIT_MENU_ITEMS
: Number of items in the BIT word menu. -
DEF_RT_CHANNEL
,DEF_RT_DEV_NUM
,DEF_RT_ADDRESS
: Default values for RT configuration.
Data and Function Prototypes
static const int8_t *CONFIG_FILE = (int8_t *)"default_1553_RTReceiveModeCodes.txt";
Path to the configuration file for the default mode codes.
Function Prototypes
Various function prototypes including the primary function Run_M1553_RT_Receive_ModeCodes
.
Enumerations and Structs
static nai_1553_cmdtbl_type mainMenuCmds[NUM_MENU_ITEMS] = { ... };
Main menu commands and their corresponding function pointers for handling user input.
Global Variables
static const uint16_t modeCodeDataMap[9] = { ... };
static uint16_t statusBitsWord;
Mappings for mode codes to their respective operations and a placeholder for status bits of the RT.
Main Function
int32_t main(void) {...}
The main function initializes the application, displays the menu, and processes user inputs.
-
naiapp_RunBoardMenu(CONFIG_FILE)
: Loads the board menu using the config file. -
User Queries: User is prompted to enter card and module indices to configure the RT.
-
Run_M1553_RT_Receive_ModeCodes(cardIndex, module, moduleID)
: The main function to run the RT receive mode codes functionality based on user inputs. -
Loop for User Input: Allows the user to restart or quit the application.
Core Functionality
Run_M1553_RT_Receive_ModeCodes
Configures and runs the RT for receiving mode codes:
1. RT Configuration: Opens and initializes the 1553 device, sets RT address and options.
2. BIT Word Configuration: Initial settings for Built-In Test (BIT) words.
3. Menu Interaction: Displays a menu and handles user inputs to configure RT options, status bits, etc.
4. Message Processing: Reads and decodes messages received from the bus.
ProcessMessages
Processes messages for a specified duration:
- Reads messages from the stack and decodes them.
- Displays the details of each message.
ConfigureRTOptions
Configures various options for the RT:
- Sets enable or disable status for different RT options based on user choices.
ModeCodeDataTable
Allows the user to read and write mode code data words.
Other Menu Functions Functions for configuring RT options, BIT options, status bits, and running the RT.
Utility Functions
Utility functions like naiapp_query_ForQuitResponse
, naiapp_fgets_stdin
, and others handle user inputs and querying.
Summary The purpose of this sample code is to demonstrate the use of NAI’s API for MIL-STD-1553 communication. It provides a comprehensive menu-driven interface to configure and interact with the RT, showcasing essential routines and configurations for handling mode codes, status bits, and other RT functions.
#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;
}