nai ar utils
Edit this on GitLab
nai ar utils
Explanation
About This Sample Code
This C sample code is designed to work with North Atlantic Industries' (NAI) embedded function modules, specifically focusing on ARINC (Aeronautical Radio, Incorporated) data communication protocols. The application facilitates interaction with these modules and includes user queries for configurations and settings. Here is a detailed breakdown of what each segment of the code does:
Header Inclusions
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
// Common Sample Program include files
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.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 ARINC Sample Program include files
#include "nai_ar_utils.h"
// naibrd include files
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ar.h"
These headers provide necessary functions, data types, and macros for interacting with NAI’s hardware, handling interrupts and module communications, and providing utilities for board access and display.
Function Definitions and Explanations
-
IsARINC(uint32_t moduleID)
c bool_t IsARINC(uint32_t moduleID);
-
Determines if a given module ID supports ARINC functionality.
-
Returns
TRUE
if the module ID matches any of the predefined ARINC module IDs (A4, AR1, AR2, CM5), otherwise returnsFALSE
.
-
-
GetARCfg(int32_t defcard, int32_t defmod, int32_t defchan, int32_t *cardIndex, int32_t *module, int32_t *archan)
c bool_t GetARCfg(int32_t defcard, int32_t defmod, int32_t defchan, int32_t *cardIndex, int32_t *module, int32_t *archan);
-
Interactively queries the user to select a card, module, and channel for ARINC configuration.
-
Confirms ARINC support, fetches channel count, and prompts user input until valid configuration is achieved or the user quits.
-
-
GetAR2Cfg(int32_t defcard, int32_t defmod, int32_t *cardIndex, int32_t *module)
c bool_t GetAR2Cfg(int32_t defcard, int32_t defmod, int32_t *cardIndex, int32_t *module);
-
Similar to
GetARCfg
but focuses only on configuring the card and module without involving channels.
-
-
GetARINCDataRate(int32_t defdatarate, nai_ar_datarate_t *datarate)
c bool_t GetARINCDataRate(int32_t defdatarate, nai_ar_datarate_t *datarate);
-
Prompts the user to input the ARINC data speed (Low: 12.5 KHz, High: 100 KHz), with a default option.
-
Ensures valid input and allows quitting.
-
-
GetARScheduleTransmitModeEnabled(bool_t defSchedEnabled, bool_t* outenable)
c bool_t GetARScheduleTransmitModeEnabled(bool_t defSchedEnabled, bool_t* outenable);
-
Prompts the user to enable or disable the ARINC message schedule transmission mode.
-
Verifies binary user input for scheduled transmissions.
-
-
GetARTransmitDataCount(int32_t defDataCount, int32_t* outdatacount)
c bool_t GetARTransmitDataCount(int32_t defDataCount, int32_t* outdatacount);
-
Queries the user for the number of ARINC data items to transmit.
-
Allows user quit any time during the query.
-
-
GetARReceiverTimestampEnabled(bool_t defTimestampEnabled, bool_t* outenable)
c bool_t GetARReceiverTimestampEnabled(bool_t defTimestampEnabled, bool_t* outenable);
-
Asks the user if timestamping of received ARINC messages should be enabled, taking a default value into account.
-
-
GetARReceiverValidationEnable(bool_t defValidationEnabled, bool_t* outenable)
c bool_t GetARReceiverValidationEnable(bool_t defValidationEnabled, bool_t* outenable);
-
Queries the user on enabling validation for ARINC receiver functionality.
-
-
GetARReceiverMailboxEnable(bool_t defMailboxEnabled, bool_t* outenable)
c bool_t GetARReceiverMailboxEnable(bool_t defMailboxEnabled, bool_t* outenable);
-
Prompts the user to enable or disable the mailbox feature for ARINC message receiving.
-
-
GetARRxBoundedFIFOEnable(bool_t defBoundedFIFOEnabled, bool_t* outenable)
c bool_t GetARRxBoundedFIFOEnable(bool_t defBoundedFIFOEnabled, bool_t* outenable);
-
Queries the user on enabling bounded Rx FIFO for ARINC messages.
-
-
GetSampleARCSDILabel(int32_t labelvalues[])
c int32_t GetSampleARCSDILabel(int32_t labelvalues[]);
-
Initializes the SDI (Significant Data Item) and Label values for ARINC communication, setting them to a sequence of label numbers from 0 to
MAX_AR_SDI_LABELS
.
-
Enumerations and Data Types - bool_t: A custom boolean type used throughout the code for TRUE/FALSE values. - nai_status_t: Data type for representing status codes returned by NAI library functions. - nai_ar_datarate_t: An enumeration representing the ARINC data rates.
This code is highly interactive, leveraging user input to configure and manage ARINC communication modules. It includes robust error checking and sensible defaults to facilitate easy configuration.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.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 ARINC Sample Program include files */
#include "nai_ar_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ar.h"
bool_t IsARINC(uint32_t moduleID)
{
bool_t bARINCFunc = FALSE;
switch (moduleID)
{
case NAI_MODULE_ID_A4:
case NAI_MODULE_ID_AR1:
case NAI_MODULE_ID_AR2:
case NAI_MODULE_ID_CM5:
bARINCFunc = TRUE;
break;
default:
bARINCFunc = FALSE;
break;
}
return bARINCFunc;
}
bool_t GetARCfg(int32_t defcard, int32_t defmod, int32_t defchan, int32_t *cardIndex, int32_t *module, int32_t *archan)
{
bool_t bQuit;
bool_t bContinue;
nai_status_t status;
int32_t MaxModule, MaxChannel;
uint32_t moduleID;
/* Query user on the Card and Module to use for this example */
bQuit = naiapp_query_CardIndex(naiapp_GetBoardCnt(), defcard, cardIndex);
if (!bQuit)
{
status = check_status(naibrd_GetModuleCount(*cardIndex, &MaxModule));
if (status == NAI_SUCCESS)
{
bContinue = TRUE;
while (bContinue)
{
bQuit = naiapp_query_ModuleNumber(MaxModule, defmod, module);
if (!bQuit)
{
/* Get the number of ARINC channels on the module */
moduleID = naibrd_GetModuleID(*cardIndex, *module);
if (IsARINC(moduleID))
{
MaxChannel = naibrd_AR_GetChannelCount(moduleID);
bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, archan);
bContinue = FALSE;
}
else
{
printf("ERROR: Module selected does not support ARINC Functionality\n");
bContinue = FALSE;
bQuit = TRUE;
}
}
else
bContinue = FALSE;
}
}
}
return bQuit;
}
bool_t GetAR2Cfg(int32_t defcard, int32_t defmod, int32_t *cardIndex, int32_t *module)
{
bool_t bQuit;
nai_status_t status;
int32_t MaxModule;
/* Query user on the Card and Module to use for this example */
bQuit = naiapp_query_CardIndex(naiapp_GetBoardCnt(), defcard, cardIndex);
if (!bQuit)
{
status = check_status(naibrd_GetModuleCount(*cardIndex, &MaxModule));
if (status == NAI_SUCCESS)
{
bQuit = naiapp_query_ModuleNumber(MaxModule, defmod, module);
}
}
return bQuit;
}
bool_t GetARINCDataRate(int32_t defdatarate, nai_ar_datarate_t *datarate)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
*datarate = (nai_ar_datarate_t)defdatarate;
while (bContinue)
{
printf("Enter ARINC Data Speed (0=Low (12.5 KHz), 1=High (100 KHz)) [default = %d]: ", defdatarate);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit)
bContinue = FALSE;
else
{
if (inputResponseCnt > 0)
{
if ((inputBuffer[0] != '0') && (inputBuffer[0] != '1'))
printf("ERROR: Invalid data rate value.\n\n");
else
{
if (inputBuffer[0] == '1')
*datarate = 1;
else
*datarate = 0;
bContinue = FALSE;
}
}
else
bContinue = FALSE;
}
}
return bQuit;
}
bool_t GetARScheduleTransmitModeEnabled(bool_t defSchedEnabled, bool_t* outenable)
{
int8_t inputBuffer[80];
int32_t inputResponseCnt;
return naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt, (int8_t *)"Send ARINC Message Schedule?", (int8_t *)"Invalid schedule enable value.", defSchedEnabled, outenable);
}
bool_t GetARTransmitDataCount(int32_t defDataCount, int32_t* outdatacount)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
*outdatacount = defDataCount;
while (bContinue)
{
bContinue = FALSE;
printf("\nEnter the ARINC Transmit Data Count or Type %c to quit [default=%d]: ", NAI_QUIT_CHAR, defDataCount);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
*outdatacount = atol((const char*)inputBuffer);
bContinue = FALSE;
}
else
bContinue = FALSE;
}
else
{
bContinue = FALSE;
}
}
return bQuit;
}
bool_t GetARReceiverTimestampEnabled(bool_t defTimestampEnabled, bool_t* outenable)
{
int8_t inputBuffer[80];
int32_t inputResponseCnt;
return naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt, (int8_t *)"Enable ARINC Receiver Timestamp?", (int8_t *)"Invalid timestamp enable value.", defTimestampEnabled, outenable);
}
bool_t GetARReceiverValidationEnable(bool_t defValidationEnabled, bool_t* outenable)
{
int8_t inputBuffer[80];
int32_t inputResponseCnt;
return naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt, (int8_t *)"Enable ARINC Receiver Validation?", (int8_t *)"Invalid validation enable value.", defValidationEnabled, outenable);
}
bool_t GetARReceiverMailboxEnable(bool_t defMailboxEnabled, bool_t* outenable)
{
int8_t inputBuffer[80];
int32_t inputResponseCnt;
return naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt, (int8_t *)"Use Mailbox?", (int8_t *)"Invalid mailbox enable value.", defMailboxEnabled, outenable);
}
bool_t GetARRxBoundedFIFOEnable(bool_t defBoundedFIFOEnabled, bool_t* outenable)
{
int8_t inputBuffer[80];
int32_t inputResponseCnt;
return naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt, (int8_t *)"Use Bounded Rx FIFO?", (int8_t *)"Invalid mailbox enable value.", defBoundedFIFOEnabled, outenable);
}
int32_t GetSampleARCSDILabel(int32_t labelvalues[])
{
int32_t sdilabelCnt = MAX_AR_SDI_LABELS;
int32_t i;
/* Set Validation SDI/Labels */
for (i = 0; i < sdilabelCnt; i++)
{
/* Lower 10 bits of the ARCINC data is for the SDI/Label (D9:D8 SDI bits, D7:D0 Label bits) */
labelvalues[i] = i;
}
return sdilabelCnt;
}