PB BasicOps
Edit this on GitLab
PB BasicOps
Explanation
About PB_BasicOps C Application Code
This C application code is designed to perform basic Profibus operations using North Atlantic Industries' (NAI) libraries and their Standard Software Kit (SSK). The code illustrates various functionalities provided by the NAI Profibus module and helps in interfacing with the hardware.
Key Elements of the Application
-
Includes and Definitions:
-
Header Files: Includes standard C headers along with NAI-specific headers like
nai.h
,naibrd.h
, and headers specific to Profibus operations (naibrd_pb.h
). -
Constants: Defines NAI_TRUE and NAI_FALSE for boolean values.
-
Static Variables: Declares a static variable
CONFIG_FILE
pointing to the configuration file.
-
-
Data Structures:
-
PBConfig
: Stores information about the specific Profibus card, including card index, module number, and module ID.
-
Application Flow
-
Function Prototypes:
-
Internal and executable function prototypes for various Profibus operations such as getting connection status, resetting counters, getting alarm data, etc.
-
-
Main Function:
-
Initialization:
-
Checks for board configuration using
naiapp_RunBoardMenu
. -
Sets up card and module indices based on user input.
-
Profibus Operations:
-
Runs the main Profibus operations through a loop, querying the user for inputs and executing the appropriate functions based on the selections.
-
-
Execution Functions:
-
Functions prefixed with
EXEC_
are designed to execute specific Profibus operations. For example,EXEC_naibrd_PB_GetMS0ConnectionStatus
retrieves the connection status of a slave device. -
Each function follows a similar pattern where it prints messages, queries the user for required input, and calls respective NAI library functions to perform the operation.
-
The results are printed, and any errors encountered during the operation are reported.
-
-
Helper Functions:
-
Functions like
printMasterState
,printOperationMode
, andnaibrd_PB_PrintPBStatus
help in decoding and displaying specific statuses and modes.
-
-
Static Function naiapp_Run_PB_BasicOps:
-
Presents a menu-driven interface for the user to select and execute various Profibus operations.
-
Uses a
do-while
loop to keep querying the user until they choose to quit.
-
Detailed Function Explanations
-
EXEC_naibrd_PB_GetMS0ConnectionStatus:
-
Retrieves cyclic connection status for a given slave address, displaying details such as data exchange status, restarts, and response counts.
-
EXEC_naibrd_PB_ResetMS0ConnectionCounters:
-
Resets the connection counters for a specified slave address to initial values.
-
EXEC_naibrd_PB_GetAlarmCounters:
-
Fetches and displays alarm counters for a given slave address, detailing the count of diagnostic, process, pull, status, update, and manufacturer alarms.
-
EXEC_naibrd_PB_GetLastAlarmData:
-
Retrieves the last alarm data related to a specified slave address, including block length, type, slot number, and user data.
-
EXEC_naibrd_PB_GetSlaveDiagnostics:
-
Provides diagnostic information for a specified slave address, such as station statuses, master address, identity number, and extra diagnostic data if available.
Menu System
The application presents a text-based menu to the user, allowing easy selection and execution of various Profibus operations. Users can: - Get connection and alarm status management. - Reset counters and alarms. - Fetch CPU load and start system reconfiguration. - Set and retrieve system time. - Manage live list operations and many more.
By following the menu prompts, a user can interact with the NAI embedded function modules through this application. The application is designed to handle user inputs gracefully and provide meaningful outputs or errors based on the operations performed.
Conclusion
This code provides a robust example of how to interface with NAI Profibus modules for performing numerous tasks necessary for managing and diagnosing Profibus networks. Each function demonstrates clear steps about querying user inputs, executing library functions, and displaying the results, making it an excellent reference for developers working with NAI hardware.
/**************************************************************************************************************/
/**
* <summary>
* The purpose of the PB_BasicOps is to illustrate the methods to call in the library to perform basic profibus
* operations.
* </summary>
*/
/**************************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.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"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_pb.h"
/**********************/
/* Application Name */
/**********************/
static const int8_t *CONFIG_FILE = (const int8_t *)"default_PBBasicOps.txt";
#define NAI_TRUE (1)
#define NAI_FALSE (0)
typedef struct
{
int32_t cardIndex;
int32_t module;
uint32_t modId;
} PBConfig;
PBConfig inputPBConfig;
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t naiapp_Run_PB_BasicOps(void);
static void printMasterState(NAIBRD_PB_DPM_MASTER_STATE masterState);
static void printOperationMode(NAIBRD_PB_DPM_OPERATION_MODE operationMode);
static void naibrd_PB_PrintPBStatus(int32_t pbStatus);
bool_t EXEC_naibrd_PB_GetMS0ConnectionStatus();
bool_t EXEC_naibrd_PB_ResetMS0ConnectionCounters();
bool_t EXEC_naibrd_PB_GetAlarmCounters();
bool_t EXEC_naibrd_PB_ResetAlarmCounters();
bool_t EXEC_naibrd_PB_GetLastAlarmData();
bool_t EXEC_naibrd_PB_GetSlaveDiagnostics();
bool_t EXEC_naibrd_PB_SetandEnableMaxCycleCounter();
bool_t EXEC_naibrd_PB_GetCPULoad();
bool_t EXEC_naibrd_PB_StartReconfiguration();
bool_t EXEC_naibrd_PB_SetSystemTime();
#if defined (_FUTURE_CAPABILITY)
bool_t EXEC_naibrd_PB_GetSystemTime();
bool_t EXEC_naibrd_PB_EnableRedundancy();
#endif
bool_t EXEC_naibrd_PB_GetLiveList();
bool_t EXEC_naibrd_PB_BusParamReconfiguration();
bool_t EXEC_naibrd_PB_GetOperationMode();
bool_t EXEC_naibrd_PB_SetPollCycleMode();
bool_t EXEC_naibrd_PB_ReadIOData();
bool_t EXEC_naibrd_PB_GetStatistics();
bool_t EXEC_naibrd_PB_SetNewIOConfig();
bool_t EXEC_naibrd_PB_GetPSAKVersion();
bool_t EXEC_naibrd_PB_WriteIOData();
bool_t EXEC_naibrd_PB_SetDynamicBusParams();
bool_t EXEC_naibrd_PB_SetBusParams();
bool_t EXEC_naibrd_PB_TestSegment();
bool_t EXEC_naibrd_PB_TestTermination();
bool_t EXEC_naibrd_PB_SetOffline();
bool_t EXEC_naibrd_PB_SetStop();
bool_t EXEC_naibrd_PB_SetClear();
bool_t EXEC_naibrd_PB_SetOperate();
bool_t EXEC_naibrd_PB_AcyclicRead();
bool_t EXEC_naibrd_PB_AcyclicWrite();
bool_t EXEC_naibrd_PB_InitiateCommunication();
bool_t EXEC_naibrd_PB_AbortCommunication();
bool_t EXEC_naibrd_PB_GetLockStatusForSegments();
/**************************************************************************************************************/
/**
* <summary>
*
* The main routine assists in gaining access to the board.
*
* The following routines from the nai_sys_cfg.c file are
* called to assist with accessing and configuring the board.
*
* - ConfigDevice
* - DisplayDeviceCfg
* - GetBoardSNModCfg
* - CheckModule
*
* </summary>
*/
/***************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t PB_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t moduleCnt;
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, &inputPBConfig.cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(inputPBConfig.cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &inputPBConfig.module);
if (stop != TRUE)
{
inputPBConfig.modId = naibrd_GetModuleID(inputPBConfig.cardIndex, inputPBConfig.module);
if ((inputPBConfig.modId != 0))
{
naiapp_Run_PB_BasicOps();
}
}
}
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;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetMS0ConnectionStatus */
bool_t EXEC_naibrd_PB_GetMS0ConnectionStatus()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetMS0ConnectionStatus\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_CONNECTION_STATUS connectionStatus;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetMS0ConnectionStatus(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &connectionStatus);
if (status == NAI_SUCCESS)
{
printf("Cyclic Connection Status for Slave Address %d: \n", slaveAddr);
printf("Is Slave in Data Exchange = %d\n", connectionStatus.isSlaveInDataExchange);
printf("Number of Restarts = %d\n", connectionStatus.numberOfRestarts);
printf("Missing Response Count = %d\n", connectionStatus.missingResponseCount);
printf("Invalid Response Count = %d\n", connectionStatus.invalidResponseCount);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetMS0ConnectionStatus - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_ResetMS0ConnectionCounters */
bool_t EXEC_naibrd_PB_ResetMS0ConnectionCounters()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("ResetMS0ConnectionCounters\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_ResetMS0ConnectionCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr);
if (status == NAI_SUCCESS)
{
printf("Reset Ms0 Connection Counters - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_ResetMS0ConnectionStatus - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetAlarmCounters */
bool_t EXEC_naibrd_PB_GetAlarmCounters()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetAlarmCounters\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_ALARM_COUNTERS alarmCounters;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetAlarmCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &alarmCounters);
if (status == NAI_SUCCESS)
{
printf("Alarm Counters for Slave Address %d: \n", slaveAddr);
printf("Number Diagnostic Alarms = %d\n", alarmCounters.numberDiagAlarms);
printf("Number Process Alarms = %d\n", alarmCounters.numberProcessAlarms);
printf("Number Pull Alarms = %d\n", alarmCounters.numberPullAlarms);
printf("Number Status Alarms = %d\n", alarmCounters.numberStatusAlarms);
printf("Number Update Alarms = %d\n", alarmCounters.numberUpdateAlarms);
printf("Number Manufacturer Alarms = %d\n", alarmCounters.numberManufacturerAlarms);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetAlarmCounters - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_ResetAlarmCounters */
bool_t EXEC_naibrd_PB_ResetAlarmCounters()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("ResetAlarmCounters\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_ResetAlarmCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr);
if (status == NAI_SUCCESS)
{
printf("Reset Alarm Counters - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_ResetAlarmCounters - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetLastAlarmData */
bool_t EXEC_naibrd_PB_GetLastAlarmData()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetLastAlarmData\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_ALARM_DATA lastAlarmData;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetLastAlarmData(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &lastAlarmData);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("naibrd_PB_GetLastAlarmData - Success\n");
printf("BlockLength = %d\n", lastAlarmData.blockLength);
printf("Type = %d\n", lastAlarmData.type);
printf("SlotNumber = %d\n", lastAlarmData.slotNumber);
printf("Specifier = %d\n", lastAlarmData.specifier);
printf("Diagnostic User Data Count = %d\n", lastAlarmData.diagnosticUserDataCount);
for (i = 0; i < lastAlarmData.diagnosticUserDataCount; i++)
{
printf("DiagnosticUserDataArray[%d] = %dn", i, lastAlarmData.diagnosticUserDataArray[i]);
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetLastAlarmData - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetSlaveDiagnostics */
bool_t EXEC_naibrd_PB_GetSlaveDiagnostics()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetSlaveDiagnostics\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_SLAVE_DIAGNOSTICS slaveDiagnostics;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetSlaveDiagnostics(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &slaveDiagnostics);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("Slave Diagnostic Data for Slave = 0x%x\n", slaveAddr);
printf("StationStatus1 = 0x%x\nStationStatus2 = 0x%x\nStationStatus3 = 0x%x\n", slaveDiagnostics.stationStatus1,
slaveDiagnostics.stationStatus2, slaveDiagnostics.stationStatus3);
printf("Master Address = 0x%x\nIdentity Number High Byte = 0x%x\nIdentity Number Low Byte = 0x%x\n",
slaveDiagnostics.masterAddr, slaveDiagnostics.identityNumberHigh, slaveDiagnostics.identityNumberLow);
if (slaveDiagnostics.lengthOfExtraDiagData > 0)
{
printf("\nExtra Diagnostic Data was Found!\n");
for (i = 0; i < slaveDiagnostics.lengthOfExtraDiagData; i++)
{
printf("0x%x ", slaveDiagnostics.extraDiagDataArray[i]);
}
printf("\n\n");
}
else
{
printf("No extra diagnostic data was found!\n");
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetSlaveDiagnostics - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetandEnableMaxCycleCounter */
bool_t EXEC_naibrd_PB_SetandEnableMaxCycleCounter()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetandEnableMaxCycleCounter\n");
printf("-------------------------------------------------\n");
printf("\nEnter Max Cycle Count prior to channel going offline: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxCycleCount = 0;
naiapp_query_NumberFromResponse(&maxCycleCount, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetAndEnableMaxCycleCounter(inputPBConfig.cardIndex, inputPBConfig.module, maxCycleCount);
if (status == NAI_SUCCESS)
{
printf("Set And Enable Max Cycle Count - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetAndEnableMaxCycleCounter - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetCPULoad */
bool_t EXEC_naibrd_PB_GetCPULoad()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
NAIBRD_PB_CPU_LOAD cpuLoad;
printf("-------------------------------------------------\n");
printf("GetCPULoad\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetCPULoad(inputPBConfig.cardIndex, inputPBConfig.module, &cpuLoad);
if (status == NAI_SUCCESS)
{
printf("CPU Load:\n");
printf("Last 100ms = %d%%\n", cpuLoad.last100ms);
printf("Last 1s = %d%%\n", cpuLoad.last1s);
printf("Last 10s = %d%%\n", cpuLoad.last10s);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetCPULoad - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_StartReconfiguration */
bool_t EXEC_naibrd_PB_StartReconfiguration()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("StartReconfiguration\n");
printf("-------------------------------------------------\n");
printf("\nEnter 1 to enable Start Reconfiguration or 0 to disable Start Reconfiguration: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t startReconfig = 0;
naiapp_query_NumberFromResponse(&startReconfig, inputBuffer, inputResponseCnt);
status = naibrd_PB_StartReconfiguration(inputPBConfig.cardIndex, inputPBConfig.module, startReconfig);
if (status == NAI_SUCCESS)
{
printf("Start Reconfiguration - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetSlaveDiagnostics - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetSystemTime */
bool_t EXEC_naibrd_PB_SetSystemTime()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetSystemTime\n");
printf("-------------------------------------------------\n");
printf("\nEnter Clock Status: (see naibrd_pb.h for valid combinations of High and Low bytes) ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
uint32_t clockStatus = 0;
naiapp_query_UnsignedNumberFromResponse(&clockStatus, inputBuffer, inputResponseCnt);
printf("\nEnter Seconds since 1970: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
uint32_t sysTimeSeconds = 0;
naiapp_query_UnsignedNumberFromResponse(&sysTimeSeconds, inputBuffer, inputResponseCnt);
printf("\nEnter Nano Seconds: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
uint32_t sysTimeNanoSeconds = 0;
naiapp_query_UnsignedNumberFromResponse(&sysTimeNanoSeconds, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetSystemTime(inputPBConfig.cardIndex, inputPBConfig.module, clockStatus, sysTimeSeconds, sysTimeNanoSeconds);
if (status == NAI_SUCCESS)
{
printf("Set System Time - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetSystemTime - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetLiveList */
bool_t EXEC_naibrd_PB_GetLiveList()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetLiveList\n");
printf("-------------------------------------------------\n");
printf("\nEnter 1 to make request to collect data or 0 to display data already collected: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t makeRequest = 0;
naiapp_query_NumberFromResponse(&makeRequest, inputBuffer, inputResponseCnt);
if (makeRequest)
{
status = naibrd_PB_KickoffGetLiveList(inputPBConfig.cardIndex, inputPBConfig.module);
if (status == NAI_SUCCESS)
{
printf("Kickoff Get Live List - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_KickoffGetLiveList - Status = %d\n", status);
}
}
else /* Interested in collected results */
{
NAIBRD_PB_LIVELIST_RESULTS liveListResults;
status = naibrd_PB_GetLiveListResults(inputPBConfig.cardIndex, inputPBConfig.module, &liveListResults);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("Get Live List Results - Success\n");
for (i = 0; i < liveListResults.passiveStationCount; i++)
{
printf("Found PASSIVE Station %d\n", liveListResults.passiveStations[i]);
}
for (i = 0; i < liveListResults.activeStationCount; i++)
{
printf("Found ACTIVE Station %d\n", liveListResults.activeStations[i]);
}
printf("\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetLiveListResults - Status = %d\n", status);
if (status == NAI_ERROR_FUNCTION_SPECIFIC_ERROR)
{
int32_t pbStatus;
status = naibrd_PB_GetLastFunctionCallStatus(inputPBConfig.cardIndex, inputPBConfig.module, &pbStatus);
naibrd_PB_PrintPBStatus(pbStatus);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_BusParamReconfiguration */
bool_t EXEC_naibrd_PB_BusParamReconfiguration()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("BusParamReconfiguration\n");
printf("-------------------------------------------------\n");
printf("\nEnter 0 to reconfigure Master Address\nEnter 1 to reconfigure Hsa\nEnter 2 to reconfigure Min Slave Interval: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t busParam = 0;
bool_t requiresField2 = NAI_FALSE;
naiapp_query_NumberFromResponse(&busParam, inputBuffer, inputResponseCnt);
if (busParam == 0)
{
printf("\nEnter new Master Address: ");
}
else if (busParam == 1)
{
printf("\nEnter new Hsa: ");
}
else if (busParam == 2)
{
printf("\nEnter new Min Slave Interval Hi Byte: ");
requiresField2 = NAI_TRUE;
}
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t field1Value = 0;
int32_t field2Value = 0;
naiapp_query_NumberFromResponse(&field1Value, inputBuffer, inputResponseCnt);
if (requiresField2)
{
printf("\nEnter new Min Slave Interval Lo Byte: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&field2Value, inputBuffer, inputResponseCnt);
}
}
if (!bQuit)
{
status = naibrd_PB_BusParamReconfiguration(inputPBConfig.cardIndex, inputPBConfig.module, busParam, field1Value, field2Value);
if (status == NAI_SUCCESS)
{
printf("Bus Param Reconfiguration - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_BusParamReconfiguration - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetOperationMode */
bool_t EXEC_naibrd_PB_GetOperationMode()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
NAIBRD_PB_DPM_MASTER_STATE masterState;
NAIBRD_PB_DPM_OPERATION_MODE operationMode;
printf("-------------------------------------------------\n");
printf("GetOperationMode\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetOperationMode(inputPBConfig.cardIndex, inputPBConfig.module, &masterState, &operationMode);
if (status == NAI_SUCCESS)
{
printf("Get Operation Mode - Success\n");
printMasterState(masterState);
printOperationMode(operationMode);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetOperationMode - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetPollCycleMode */
bool_t EXEC_naibrd_PB_SetPollCycleMode()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetPollCycleMode\n");
printf("-------------------------------------------------\n");
printf("\nEnter 0 for ACYCLIC mode or 1 for CYCLIC mode: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t pollCycleMode = 0;
naiapp_query_NumberFromResponse(&pollCycleMode, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetPollCycleMode(inputPBConfig.cardIndex, inputPBConfig.module, pollCycleMode);
if (status == NAI_SUCCESS)
{
printf("Set Poll Cycle Mode - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetPollCycleMode - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_ReadIOData */
bool_t EXEC_naibrd_PB_ReadIOData()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("ReadIOData\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Offset into slave: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t offset = 0;
naiapp_query_NumberFromResponse(&offset, inputBuffer, inputResponseCnt);
printf("\nPlease enter Number of Bytes to Read: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t readCount = 0;
int8_t data[NAIBRD_PB_MAX_PDU_LENGTH];
naiapp_query_NumberFromResponse(&readCount, inputBuffer, inputResponseCnt);
status = naibrd_PB_ReadIOData(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, offset, readCount, &(data[0]));
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("Read IO Data - Success\n");
printf("IO Data:\n");
for (i = 0; i < readCount; i++)
{
printf("0x%02x ", (data[i] & 0xFF));
}
printf("\n\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_ReadIOData - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetStatistics */
bool_t EXEC_naibrd_PB_GetStatistics()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
NAIBRD_PB_STATISTICS statistics;
printf("-------------------------------------------------\n");
printf("GetStatistics\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetStatistics(inputPBConfig.cardIndex, inputPBConfig.module, &statistics);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("naibrd_PB_GetStatistics - Success\n");
printf("NumMasterStations = %d\n", statistics.numMasterStations);
printf("Master Active Stations:\n");
for (i = 0; i < statistics.numMasterStations; i++)
{
printf("%d\n", statistics.masterStationsArray[i]);
}
printf("\n");
printf("NumSlaveStations = %d\n", statistics.numSlaveStations);
printf("Slave Active Stations:\n");
for (i = 0; i < statistics.numSlaveStations; i++)
{
printf("%d\n", statistics.slaveStationsArray[i]);
}
printf("\n");
printf("Bus Parameters:\n");
printf("\tStation Address:\t%d\n", statistics.stationAddress);
printf("\tBaudrate:\t%d\n", statistics.baudRate);
printf("\tTIdle1:\t\t%d\n", statistics.tIdle1);
printf("\tTIdle2:\t\t%d\n", statistics.tIdle2);
printf("\tTSlot:\t\t%d\n", statistics.tSlot);
printf("\tTtr:\t\t%d\n", statistics.tTr);
printf("\tMinSlaveInterval:\t\t%d\n", statistics.minSlaveInterval);
printf("\tMaxAcyclicServicesPerPollCycle:\t%d\n", statistics.maxAcyclicServicesPerPollCycle);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetStatistics - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetNewIOConfig */
bool_t EXEC_naibrd_PB_SetNewIOConfig()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetNewIOConfig\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
int32_t cfgDataLength = 0;
int8_t cfgData[NAIBRD_PB_MAX_CFG_DATA_LENGTH];
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter number of bytes of configuration (1 - %d): ", NAIBRD_PB_MAX_CFG_DATA_LENGTH);
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t i = 0;
naiapp_query_NumberFromResponse(&cfgDataLength, inputBuffer, inputResponseCnt);
/* Now prompt for data to be written */
printf("\nPlease enter configuration data in the form of 0x00");
for (i = 0; i < cfgDataLength; i++)
{
printf("\ncfgData[%d]: ", i);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit)
{
break;
}
cfgData[i] = (int8_t)strtol((char*)inputBuffer, NULL, 16);
}
if (!bQuit)
{
status = naibrd_PB_SetNewIOConfig(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, cfgDataLength, &(cfgData[0]));
if (status == NAI_SUCCESS)
{
printf("Set New IO Config - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetNewIOConfig - Status = %d\n", status);
if (status == NAI_ERROR_FUNCTION_SPECIFIC_ERROR)
{
int32_t pbStatus = NAI_PB_SUCCESS;
status = naibrd_PB_GetLastFunctionCallStatus(inputPBConfig.cardIndex, inputPBConfig.module, &pbStatus);
if (status == NAI_SUCCESS)
{
printf("PB Specific Status = %d\n", pbStatus);
}
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetPSAKVersion */
bool_t EXEC_naibrd_PB_GetPSAKVersion()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
char firmwareVersion[NAIBRD_PB_VERSION_MAX_LENGTH];
char psakVersion[NAIBRD_PB_VERSION_MAX_LENGTH];
printf("-------------------------------------------------\n");
printf("GetPSAKVersion\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetPSAKVersion(inputPBConfig.cardIndex, inputPBConfig.module, NAIBRD_PB_VERSION_MAX_LENGTH, &(firmwareVersion[0]),
NAIBRD_PB_VERSION_MAX_LENGTH, &(psakVersion[0]));
if (status == NAI_SUCCESS)
{
printf("Get PSAK Version - Success\n");
printf("Firmware Version = %s\n", firmwareVersion);
printf("PSAK Version = %s\n", psakVersion);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetPSAKVersion - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_WriteIOData */
bool_t EXEC_naibrd_PB_WriteIOData()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("WriteIOData\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Offset into slave: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t offset = 0;
int8_t bytesToWrite[2];
int32_t numBytesToWrite = 0;
naiapp_query_NumberFromResponse(&offset, inputBuffer, inputResponseCnt);
printf("\nPlease enter number of bytes to be written: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t i = 0;
naiapp_query_NumberFromResponse(&numBytesToWrite, inputBuffer, inputResponseCnt);
/* Now prompt for data to be written */
printf("\nPlease enter data in the form of 0x00");
for (i = 0; i < numBytesToWrite; i++)
{
printf("\nData[%d]: ", i);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit)
{
break;
}
bytesToWrite[i] = (int8_t)strtol((char*)inputBuffer, NULL, 16);
}
if (!bQuit)
{
status = naibrd_PB_WriteIOData(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, offset, numBytesToWrite,
bytesToWrite);
if (status == NAI_SUCCESS)
{
printf("Write IO Data - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_WriteIOData - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetDynamicBusParams */
bool_t EXEC_naibrd_PB_SetDynamicBusParams()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetDynamicBusParams\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter StationAddress: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t stationAddr = 0;
naiapp_query_NumberFromResponse(&stationAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Retry Limit: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxRetryLimit = 0;
naiapp_query_NumberFromResponse(&maxRetryLimit, inputBuffer, inputResponseCnt);
printf("\nPlease enter TSlot: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t tSlot = 0;
naiapp_query_NumberFromResponse(&tSlot, inputBuffer, inputResponseCnt);
printf("\nPlease enter MaxTSDR: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxTsdr = 0;
naiapp_query_NumberFromResponse(&maxTsdr, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetDynamicBusParams(inputPBConfig.cardIndex, inputPBConfig.module, stationAddr, maxRetryLimit, tSlot,
maxTsdr);
if (status == NAI_SUCCESS)
{
printf("Set Dynamic Bus Params - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetDynamicBusParams - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetBusParams */
bool_t EXEC_naibrd_PB_SetBusParams()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetBusParams\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter tSlot (Slot time - max time master has to wait for 1st byte of response or frame from token receiver after\
a token exchange) Valid values (37 - 16383): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
NAIBRD_PB_BUS_PARAMS busParams;
naiapp_query_NumberFromResponse(&(busParams.tSlot), inputBuffer, inputResponseCnt);
printf("\nPlease enter Min Tsdr (Min time delay of the slave processing a request to sending the response) Valid values \
(11 - 1023): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.minTsdr), inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Tsdr (Max time delay of the slave processing a request to sending the response) Valid values \
(37 - 65535): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.maxTsdr), inputBuffer, inputResponseCnt);
printf("\nPlease enter Baudrate: (Valid values defined in naibrd_pb.h): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.baudrate), inputBuffer, inputResponseCnt);
printf("\nPlease enter TQui (Quiet Time is the time during which the PB control logic has to close its sender and \
its receiver) Valid values (0 - 493): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tQui), inputBuffer, inputResponseCnt);
printf("\nPlease enter TSet (Setup Time - indicates the latency of the data link layer) Valid values (1 - 494): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tSet), inputBuffer, inputResponseCnt);
printf("\nPlease enter TtrHigh (Target Rotation Time - the maximum permissible rotation time of a token in the \
PB network) Valid values (256 - 16776960): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tTrHi), inputBuffer, inputResponseCnt);
printf("\nPlease enter TtrLow (Target Rotation Time - the maximum permissible rotation time of a token in \
the PB network) Valid values (256 - 16776960): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tTrLow), inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Retry Limit (Maximum number of frame repititions indicates how often the \
master repeats a request, after the end of the slot time, before it designates the responder as \
not available) Valid values (0 - 7): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.maxRetryLimit), inputBuffer, inputResponseCnt);
status = naibrd_PB_SetBusParams(inputPBConfig.cardIndex, inputPBConfig.module, &busParams);
if (status == NAI_SUCCESS)
{
printf("Set Dynamic Bus Params - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetBusParams - Status = %d\n", status);
}
}
}
}
}
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_TestSegment */
bool_t EXEC_naibrd_PB_TestSegment()
{
bool_t bQuit = NAI_FALSE;
bool_t enable = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int32_t segment = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("TestSegment\n");
printf("-------------------------------------------------\n");
printf("2 Parameters Required to Execute naibrd_PB_EnableSegmentForUse\n");
printf("\nPlease enter Segment to test. Valid values (1 - 8) and 255 for Aux port: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&segment, inputBuffer, inputResponseCnt);
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' to Enable Segment or 'N' to Disable the Segment",
(int8_t *)"Invalid value detected for Enable",
NAI_FALSE, &enable);
if (!bQuit)
{
status = naibrd_PB_EnableSegmentForUse(inputPBConfig.cardIndex, inputPBConfig.module, segment, enable);
if (status == NAI_SUCCESS)
{
if (enable)
{
printf("Segment %d is now Enabled!\n", segment);
}
else
{
printf("Segment %d is now Disabled!\n", segment);
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_EnableSegmentForUse - Status = %d\n", status);
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_TestTermination */
bool_t EXEC_naibrd_PB_TestTermination()
{
bool_t bQuit = NAI_FALSE;
bool_t enable = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int32_t segment = 0;
uint32_t terminationEnableRegVal = 0;
uint32_t segmentTermination = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("TestTermination\n");
printf("-------------------------------------------------\n");
printf("2 Parameters Required to Execute naibrd_PB_SetTerminationEnableForSegments\n");
printf("\nPlease enter Segment to test termination. Valid values (1 - 8) and 255 for Aux port: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&segment, inputBuffer, inputResponseCnt);
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' to Enable Termination or 'N' to Disable Termination",
(int8_t *)"Invalid value detected for Enable",
NAI_FALSE, &enable);
if (!bQuit)
{
status = naibrd_PB_GetTerminationEnableForSegments(inputPBConfig.cardIndex, inputPBConfig.module, &terminationEnableRegVal);
if (status == NAI_SUCCESS)
{
printf("\nCurrent value of Termination Enable register before granting request: 0x%x\n", terminationEnableRegVal);
switch (segment)
{
case SEGMENT_1:
segmentTermination = 0x01;
break;
case SEGMENT_2:
segmentTermination = 0x02;
break;
case SEGMENT_3:
segmentTermination = 0x04;
break;
case SEGMENT_4:
segmentTermination = 0x08;
break;
case SEGMENT_5:
segmentTermination = 0x10;
break;
case SEGMENT_6:
segmentTermination = 0x20;
break;
case SEGMENT_7:
segmentTermination = 0x40;
break;
case SEGMENT_8:
segmentTermination = 0x80;
break;
case SEGMENT_AUX:
segmentTermination = 0x0100;
break;
default:
status = NAI_ERROR_INVALID_RANGE;
break;
}
if (status == NAI_SUCCESS)
{
if (enable)
{
terminationEnableRegVal |= segmentTermination;
}
else
{
terminationEnableRegVal &= (~segmentTermination);
}
status = naibrd_PB_SetTerminationEnableForSegments(inputPBConfig.cardIndex, inputPBConfig.module, terminationEnableRegVal);
if (status == NAI_SUCCESS)
{
printf("New value of Termination Enable register after granting request: 0x%x\n", terminationEnableRegVal);
if (enable)
{
printf("Segment %d is now Terminated!\n", segment);
}
else
{
printf("Segment %d is now NOT Terminated!\n", segment);
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetTerminationEnableForSegments - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetOffline */
bool_t EXEC_naibrd_PB_SetOffline()
{
bool_t bQuit = NAI_FALSE;
bool_t redMode = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetOffline\n");
printf("-------------------------------------------------\n");
printf("1 Parameter Required to Execute naibrd_PB_SetOffline\n");
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' for Redundancy Mode or 'N' for Normal", (int8_t *)"Invalid value detected for Redundancy Mode",
NAI_FALSE, &redMode);
if (!bQuit)
{
status = naibrd_PB_SetOffline(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED OFFLINE. Please Confirm bus light is off for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetOffline - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetStop */
bool_t EXEC_naibrd_PB_SetStop()
{
nai_status_t status = NAI_SUCCESS;
printf("-------------------------------------------------\n");
printf("SetStop\n");
printf("-------------------------------------------------\n");
printf("No Parameters Required to Execute naibrd_PB_SetStop\n");
status = naibrd_PB_SetStop(inputPBConfig.cardIndex, inputPBConfig.module);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED TO STOP. Please Confirm bus light is on for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetStop - Status = %d\n", status);
}
return NAI_FALSE;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetClear */
bool_t EXEC_naibrd_PB_SetClear()
{
bool_t bQuit = NAI_FALSE;
bool_t redMode = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetClear\n");
printf("-------------------------------------------------\n");
printf("1 Parameter Required to Execute naibrd_PB_SetClear\n");
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' for Redundancy Mode or 'N' for Normal",
(int8_t *)"Invalid value detected for Redundancy Mode", NAI_FALSE, &redMode);
if (!bQuit)
{
status = naibrd_PB_SetClear(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED TO CLEAR. Please Confirm bus light is on for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetClear - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetOperate */
bool_t EXEC_naibrd_PB_SetOperate()
{
bool_t bQuit = NAI_FALSE;
bool_t redMode = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetOperate\n");
printf("-------------------------------------------------\n");
printf("1 Parameter Required to Execute naibrd_PB_SetOperate\n");
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' for Redundancy Mode or 'N' for Normal", (int8_t *)"Invalid value detected for Redundancy Mode",
NAI_FALSE, &redMode);
if (!bQuit)
{
status = naibrd_PB_SetOperate(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED TO OPERATE. Please Confirm bus light is on for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetOperate - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_AcyclicRead */
bool_t EXEC_naibrd_PB_AcyclicRead()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("AcyclicRead\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Slot Number: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slotNumber = 0;
naiapp_query_NumberFromResponse(&slotNumber, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Index: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t paramIndex = 0;
naiapp_query_NumberFromResponse(¶mIndex, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Data Length: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t paramDataLength = 0;
int8_t data[NAIBRD_PB_MAX_CFG_DATA_LENGTH];
int32_t dataReadCount = 0;
naiapp_query_NumberFromResponse(¶mDataLength, inputBuffer, inputResponseCnt);
status = naibrd_PB_AcyclicRead(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, slotNumber, paramIndex,
paramDataLength, &dataReadCount, &(data[0]));
if (status == NAI_SUCCESS)
{
int i = 0;
printf("naibrd_PB_AcyclicRead - Success\n");
printf("Acyclic Read Data:\n");
for (i = 0; i < dataReadCount; i++)
{
printf("0x%02x ", (data[i] & 0xFF));
}
printf("\n\n");
}
else
{
printf("ERROR naibrd_PB_AcyclicRead - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_AcyclicWrite */
bool_t EXEC_naibrd_PB_AcyclicWrite()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("AcyclicWrite\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Slot Number: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slotNumber = 0;
naiapp_query_NumberFromResponse(&slotNumber, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Index: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t paramIndex = 0;
naiapp_query_NumberFromResponse(¶mIndex, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Data Length: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t i = 0;
int32_t paramDataLength = 0;
int32_t paramData[NAIBRD_PB_MAX_CMD_PARAMS];
naiapp_query_NumberFromResponse(¶mDataLength, inputBuffer, inputResponseCnt);
for (i = 0; i < paramDataLength; i++)
{
printf("\nEnter Value for Param Data: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(paramData[i]), inputBuffer, inputResponseCnt);
}
}
if (!bQuit && status == NAI_SUCCESS)
{
status = naibrd_PB_AcyclicWrite(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, slotNumber, paramIndex,
paramDataLength, &(paramData[0]));
if (status == NAI_SUCCESS)
{
printf("naibrd_PB_AcyclicRead - Success\n");
}
else
{
printf("ERROR naibrd_PB_AcyclicRead - Status = %d\n", status);
}
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_InitiateCommunication */
bool_t EXEC_naibrd_PB_InitiateCommunication()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("InitiateCommunication\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Comm Ref: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t commRef = 0;
naiapp_query_NumberFromResponse(&commRef, inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Timeout in Milliseconds: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxTimeoutInMS = 0;
naiapp_query_NumberFromResponse(&maxTimeoutInMS, inputBuffer, inputResponseCnt);
status = naibrd_PB_InitiateCommunication(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, commRef, maxTimeoutInMS);
if (status == NAI_SUCCESS)
{
printf("Initiate Communication - Success\n");
}
else
{
printf("ERROR initiating communication - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_AbortCommunication */
bool_t EXEC_naibrd_PB_AbortCommunication()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("AbortCommunication\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Comm Ref: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t commRef = 0;
naiapp_query_NumberFromResponse(&commRef, inputBuffer, inputResponseCnt);
status = naibrd_PB_AbortCommunication(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, commRef);
if (status == NAI_SUCCESS)
{
printf("Abort Communication - Success\n");
}
else
{
printf("ERROR aborting communication - Status = %d\n", status);
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetLockStatusForSegments */
bool_t EXEC_naibrd_PB_GetLockStatusForSegments()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
uint32_t lockStatusRegValue = 0;
printf("-------------------------------------------------\n");
printf("GetLockStatusForSegment\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetLockStatusForSegments(inputPBConfig.cardIndex, inputPBConfig.module, &lockStatusRegValue);
if (status == NAI_SUCCESS)
{
printf("Segments Lock Status = 0x%x\n", lockStatusRegValue);
if (lockStatusRegValue & 0x00000001)
printf("Segment 1 Lock Status = LOCKED\n");
else
printf("Segment 1 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000002)
printf("Segment 2 Lock Status = LOCKED\n");
else
printf("Segment 2 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000004)
printf("Segment 3 Lock Status = LOCKED\n");
else
printf("Segment 3 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000008)
printf("Segment 4 Lock Status = LOCKED\n");
else
printf("Segment 4 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000010)
printf("Segment 5 Lock Status = LOCKED\n");
else
printf("Segment 5 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000020)
printf("Segment 6 Lock Status = LOCKED\n");
else
printf("Segment 6 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000040)
printf("Segment 7 Lock Status = LOCKED\n");
else
printf("Segment 7 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000080)
printf("Segment 8 Lock Status = LOCKED\n");
else
printf("Segment 8 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000100)
printf("Segment Aux Lock Status = LOCKED\n");
else
printf("Segment Aux Lock Status = NOT LOCKED\n");
}
else
{
printf("ERROR naibrd_PB_GetLockStatusForSegments - Status = %d\n", status);
}
return bQuit;
}
/**************************************************************************************************************/
/**
* <summary>
* naiapp_Run_PB_BasicOps illustrates...
* </summary>
*/
/**************************************************************************************************************/
static bool_t naiapp_Run_PB_BasicOps(void)
{
bool_t bQuit = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
do
{
printf("\n\n");
printf("**************************************************************************\n");
printf("* A. Execute naibrd_PB_GetMS0ConnectionStatus (Cyclic Status) *\n");
printf("* B. Execute naibrd_PB_ResetMS0ConnectionCounters (Cyclic Counters) *\n");
printf("* C. Execute naibrd_PB_GetAlarmCounters *\n");
printf("* D. Execute naibrd_PB_ResetAlarmCounters *\n");
printf("* E. Execute naibrd_PB_GetLastAlarmData *\n");
printf("* F. Execute naibrd_PB_GeSlaveDiagnostics *\n");
printf("* G. Execute naibrd_PB_SetandEnableMaxCycleCounter *\n");
printf("* H. Execute naibrd_PB_GetCPULoad *\n");
printf("* I. Execute naibrd_PB_StartReconfiguration *\n");
printf("* J. Execute naibrd_PB_SetSystemTime *\n");
#if defined (_FUTURE_CAPABILITY)
printf("* K. Execute naibrd_PB_EnableRedundancy *\n");
#else
printf("* K. *\n");
#endif
printf("* L. Execute naibrd_PB_GetLiveList *\n");
printf("* M. *\n");
printf("* N. Execute naibrd_PB_BusParamReconfiguration *\n");
printf("* O. Execute naibrd_PB_GetOperationMode *\n");
printf("* P. Execute naibrd_PB_SetPollCycleMode *\n");
printf("* Q. QUIT *\n");
printf("* R. Execute naibrd_PB_ReadIOData *\n");
printf("* S. Execute naibrd_PB_GetStatistics *\n");
printf("* T. *\n");
printf("* U. Execute naibrd_PB_SetNewIOConfig *\n");
printf("* V. Execute naibrd_PB_GetPSAKVersion *\n");
printf("* W. Execute naibrd_PB_WriteIOData *\n");
printf("* X. Execute naibrd_PB_SetDynamicBusParams *\n");
printf("* Y. Execute naibrd_PB_SetBusParams *\n");
printf("* Z. Execute naibrd_PB_SetTerminationEnableForSegments *\n");
printf("--------------------------------------------------------------------------\n");
printf("* 0. Execute naibrd_PB_EnableSegmentForUse *\n");
printf("* 1. Execute naibrd_PB_SetOffline *\n");
printf("* 2. Execute naibrd_PB_SetStop *\n");
printf("* 3. Execute naibrd_PB_SetClear *\n");
printf("* 4. Execute naibrd_PB_SetOperate *\n");
printf("* 5. Execute naibrd_PB_AcyclicRead *\n");
printf("* 6. Execute naibrd_PB_AcyclicWrite *\n");
printf("* 7. Execute naibrd_PB_InitiateCommunication *\n");
printf("* 8. Execute naibrd_PB_AbortCommunication *\n");
printf("* 9. Execute naibrd_PB_GetLockStatusForSegments *\n");
printf("**************************************************************************\n");
printf("\nPlease enter your selection: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
switch (tolower(inputBuffer[0]))
{
case 'a':
bQuit = EXEC_naibrd_PB_GetMS0ConnectionStatus();
break;
case 'b':
bQuit = EXEC_naibrd_PB_ResetMS0ConnectionCounters();
break;
case 'c':
bQuit = EXEC_naibrd_PB_GetAlarmCounters();
break;
case 'd':
bQuit = EXEC_naibrd_PB_ResetAlarmCounters();
break;
case 'e':
bQuit = EXEC_naibrd_PB_GetLastAlarmData();
break;
case 'f':
bQuit = EXEC_naibrd_PB_GetSlaveDiagnostics();
break;
case 'g':
bQuit = EXEC_naibrd_PB_SetandEnableMaxCycleCounter();
break;
case 'h':
bQuit = EXEC_naibrd_PB_GetCPULoad();
break;
case 'i':
bQuit = EXEC_naibrd_PB_StartReconfiguration();
break;
case 'j':
bQuit = EXEC_naibrd_PB_SetSystemTime();
break;
case 'k':
#if defined (_FUTURE_CAPABILITY)
bQuit = EXEC_naibrd_PB_GetSystemTime();
#endif
break;
case 'l':
bQuit = EXEC_naibrd_PB_GetLiveList();
break;
case 'm':
break;
case 'n':
bQuit = EXEC_naibrd_PB_BusParamReconfiguration();
break;
case 'o':
bQuit = EXEC_naibrd_PB_GetOperationMode();
break;
case 'p':
bQuit = EXEC_naibrd_PB_SetPollCycleMode();
break;
case 'q':
bQuit = NAI_TRUE;
break;
case 'r':
bQuit = EXEC_naibrd_PB_ReadIOData();
break;
case 's':
bQuit = EXEC_naibrd_PB_GetStatistics();
break;
case 't':
break;
case 'u':
bQuit = EXEC_naibrd_PB_SetNewIOConfig();
break;
case 'v':
bQuit = EXEC_naibrd_PB_GetPSAKVersion();
break;
case 'w':
bQuit = EXEC_naibrd_PB_WriteIOData();
break;
case 'x':
bQuit = EXEC_naibrd_PB_SetDynamicBusParams();
break;
case 'y':
bQuit = EXEC_naibrd_PB_SetBusParams();
break;
case 'z':
#if defined (_FUTURE_CAPABILITY)
bQuit = EXEC_naibrd_PB_EnableRedundancy();
#endif
bQuit = EXEC_naibrd_PB_TestTermination();
break;
case '0':
bQuit = EXEC_naibrd_PB_TestSegment();
break;
case '1':
bQuit = EXEC_naibrd_PB_SetOffline();
break;
case '2':
bQuit = EXEC_naibrd_PB_SetStop();
break;
case '3':
bQuit = EXEC_naibrd_PB_SetClear();
break;
case '4':
bQuit = EXEC_naibrd_PB_SetOperate();
break;
case '5':
bQuit = EXEC_naibrd_PB_AcyclicRead();
break;
case '6':
bQuit = EXEC_naibrd_PB_AcyclicWrite();
break;
case '7':
bQuit = EXEC_naibrd_PB_InitiateCommunication();
break;
case '8':
bQuit = EXEC_naibrd_PB_AbortCommunication();
break;
case '9':
bQuit = EXEC_naibrd_PB_GetLockStatusForSegments();
break;
}
}
} while (!bQuit);
return bQuit;
}
static void printMasterState(NAIBRD_PB_DPM_MASTER_STATE masterState)
{
switch (masterState)
{
case DPM_MASTER_STATE_OK:
printf("Master state: OK\n");
break;
case DPM_MASTER_STATE_AUTOCLEAR:
printf("WARNING: Master state: AUTOCLEAR\n");
break;
case DPM_MASTER_STATE_DISTURBED_BUS_ERROR:
printf("WARNING: Master state: DISTURBED BUS ERROR\n");
break;
case DPM_MASTER_STATE_DOUBLE_ADDRESS_ERROR:
printf("WARNING: Master state: DOUBLE ADDRESS ERROR\n");
break;
case DPM_MASTER_STATE_PROTOCOL_ERROR:
printf("WARNING: Master state: PROTOCOL ERROR\n");
break;
case DPM_MASTER_STATE_HARDWARE_ERROR:
printf("WARNING: Master state: HARDWARE ERROR\n");
break;
case DPM_MASTER_STATE_APPL_WATCHDOG_EXPIRED:
printf("WARNING: Master state: APPL WATCHDOG EXPIRED\n");
break;
case DPM_MASTER_STATE_ASPC2_WATCHDOG_EXPIRED:
printf("WARNING: Master state: ASPC2 WATCHDOG EXPIRED\n");
break;
case DPM_MASTER_STATE_NO_TRAFFIC:
printf("WARNING: Master state: NO TRAFFIC\n");
break;
case DPM_MASTER_STATE_NO_FREE_ADDRESS:
printf("WARNING: Master state: NO FREE ADDRESS\n");
break;
case DPM_MASTER_STATE_NO_PARAMETERS:
printf("WARNING: Master state: NO PARAMETERS\n");
break;
case DPM_MASTER_STATE_LICENSE_ERROR:
printf("WARNING: Master state: LICENSE ERROR\n");
break;
default:
printf("UNKOWN MASTER STATE!\n");
break;
}
}
static void printOperationMode(NAIBRD_PB_DPM_OPERATION_MODE operationMode)
{
switch (operationMode)
{
case DPM_OPERATION_MODE_OFFLINE:
printf("Mode: OFFLINE\n");
break;
case DPM_OPERATION_MODE_STOP:
printf("Mode: STOP\n");
break;
case DPM_OPERATION_MODE_CLEAR:
printf("Mode: CLEAR\n");
break;
case DPM_OPERATION_MODE_OPERATE:
printf("Mode: OPERATE\n");
break;
case DPM_OPERATION_MODE_RED_CLEAR:
printf("Mode: RED CLEAR\n");
break;
case DPM_OPERATION_MODE_RED_OPERATE:
printf("Mode: RED OPERATE\n");
break;
case DPM_OPERATION_MODE_RED_OFFLINE:
printf("Mode: RED OFFLINE\n");
break;
case DPM_OPERATION_MODE_AUTOBAUD:
printf("Mode: AUTOBAUD\n");
break;
default:
printf("Mode is undefined\n");
break;
}
}
static void naibrd_PB_PrintPBStatus(int32_t pbStatus)
{
switch (pbStatus)
{
case NAI_PB_REQUEST_STILL_RUNNING_ERROR:
printf("PB Requested Operation is Still Running! Status = %d\n", pbStatus);
break;
case NAI_PB_STRING_LENGTH_ERROR:
printf("PB String Length Error! Status = %d\n", pbStatus);
break;
case NAI_PB_TIMEOUT_ERROR:
printf("PB Function Request Timed Out Prior to Completion! Status = %d\n", pbStatus);
break;
case NAI_PB_ARRAY_BOUNDS_EXCEEDED_ERROR:
printf("PB Array Bounds Were Exceeded! Status = %d\n", pbStatus);
break;
case NAI_PB_BUSY_ERROR:
printf("PB Busy Processing! Status = %d\n", pbStatus);
break;
case NAI_PB_SUCCESS:
printf("PB Success! Status = %d\n", pbStatus);
break;
default:
printf("PB UNKNOWN ERROR CODE! Status = %d\n", pbStatus);
break;
}
}