AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
main.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 // Includes
9 #include <stdio.h>
10 #include <iostream>
11 #include <string>
12 #include <signal.h>
13 
14 #include "ajatypes.h"
15 #include "ntv2enums.h"
16 #include "ntv2devicefeatures.h"
17 #include "ntv2devicescanner.h"
18 #include "ntv2utils.h"
19 #include "ntv2bitfile.h"
20 #include "ntv2bitfilemanager.h"
22 #include "ajabase/common/common.h"
23 
24 using namespace std;
25 
26 #ifdef MSWindows
27  #pragma warning(disable : 4996)
28 #endif
29 
30 #ifdef AJALinux
32 #endif
33 
34 
35 int main(int argc, const char ** argv)
36 {
37  char * pDeviceSpec (AJA_NULL); // Device argument
38  char * pDeviceID (AJA_NULL); // Device ID argument
39  int showVersion (0); // Show version?
40  int isVerbose (0); // Verbose output?
41  int isInfo (0); // Info output?
42  NTV2DeviceID deviceID (NTV2DeviceID(0)); // Desired device ID to be loaded
43  poptContext optionsContext; // Context for parsing command line arguments
44  int resultCode (0);
45 
46  const struct poptOption userOptionsTable[] =
47  {
48  {"version", 0, POPT_ARG_NONE | POPT_ARGFLAG_OPTIONAL, &showVersion, 0, "show version & exit", AJA_NULL },
49  { "device", 'd', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
50  { "info", 'i', POPT_ARG_NONE | POPT_ARGFLAG_OPTIONAL, &isInfo, 0, "bitfile info?", AJA_NULL },
51  { "load", 'l', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &pDeviceID, 'l',"device ID to load", "index# or hex32value" },
52  { "verbose",'v', POPT_ARG_NONE | POPT_ARGFLAG_OPTIONAL, &isVerbose, 0, "verbose output?", AJA_NULL },
55  };
56 
57  // Read command line arguments...
58  optionsContext = ::poptGetContext (AJA_NULL, argc, argv, userOptionsTable, 0);
59  ::poptGetNextOpt (optionsContext);
60  optionsContext = ::poptFreeContext (optionsContext);
61  if (showVersion)
62  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
63 
64  CNTV2Card device;
65  const string deviceSpec(pDeviceSpec ? pDeviceSpec : "0");
66  if (!CNTV2DeviceScanner::GetFirstDeviceFromArgument (deviceSpec, device))
67  {cerr << "## ERROR: Opening device '" << deviceSpec << "' failed" << endl; return 1;}
68  NTV2DeviceID eBoardID (device.GetDeviceID());
69 
70  // Scan the current directory for bitfiles...
71  device.AddDynamicDirectory(".");
72 
73  const string deviceStr(pDeviceID ? pDeviceID : "");
74  if (!deviceStr.empty())
75  {
76  size_t checkIndex(0);
77  size_t index = aja::stoul(deviceStr, &checkIndex, 10);
78  if (index < 100)
79  {
80  const NTV2DeviceIDList deviceList (device.GetDynamicDeviceList());
81  if ((index == 0) || (index > deviceList.size()))
82  {cerr << "## ERROR: Bad device index '" << index << "'" << endl; return 1;}
83  deviceID = deviceList.at(index-1);
84  }
85  else
86  {
87  deviceID = NTV2DeviceID(aja::stoul(deviceStr, &checkIndex, 16));
88  isVerbose = true;
89  }
90  }
91 
92  if (isVerbose)
93  cout << "Active device is " << ::NTV2DeviceIDToString(eBoardID) << " ("
94  << xHEX0N(eBoardID,8) << ")" << endl;
95  else
96  cout << "Active device is " << ::NTV2DeviceIDToString(eBoardID) << endl;
97 
98  do
99  {
100  // Check if requested device loadable...
101  if (deviceID)
102  {
103  if (!device.CanLoadDynamicDevice(deviceID))
104  {
105  cerr << "## ERROR: Cannot load device: " << ::NTV2DeviceIDToString(deviceID) << " ("
106  << xHEX0N(deviceID,8) << ")" << endl;
107  deviceID = NTV2DeviceID(0);
108  }
109  else
110  {
111  if (isVerbose)
112  cout << "Can load device: " << ::NTV2DeviceIDToString(deviceID) << " (" << xHEX0N(deviceID,8) << ")" << endl;
113  else
114  cout << "Can load device: " << ::NTV2DeviceIDToString(deviceID) << endl;
115  }
116  }
117 
118  // Load requested device...
119  if (deviceID)
120  {
121  if (!device.LoadDynamicDevice(deviceID))
122  {
123  eBoardID = device.GetDeviceID();
124  cerr << "## ERROR: Load failed for device: " << ::NTV2DeviceIDToString(eBoardID)
125  << " (" << xHEX0N(eBoardID,8) << ")";
126  resultCode = 2;
127  }
128  eBoardID = device.GetDeviceID();
129  if (deviceID == eBoardID)
130  {
131  if (isVerbose)
132  cout << "Device: " << ::NTV2DeviceIDToString(eBoardID) << " (" << xHEX0N(eBoardID,8)
133  << ") loaded successfully" << endl;
134  else
135  cout << "Device: " << ::NTV2DeviceIDToString(eBoardID) << " loaded successfully" << endl;
136  }
137  else
138  {
139  cerr << "## ERROR: Unexpected device: " << ::NTV2DeviceIDToString(eBoardID)
140  << " (" << xHEX0N(eBoardID,8) << ")";
141  resultCode = 3;
142  }
143  }
144 
145  // Print loadable device list...
146  if (!deviceID && !isInfo)
147  {
148  const NTV2DeviceIDList deviceList (device.GetDynamicDeviceList());
149  if (deviceList.empty())
150  {cout << "No loadable devices found" << endl; break;}
151 
152  cout << DEC(deviceList.size()) << " Device(s) for dynamic loading:" << endl;
153  for (size_t ndx(0); ndx < deviceList.size(); ndx++)
154  {
155  if (isVerbose)
156  cout << DECN(ndx+1,2) << ": " << ::NTV2DeviceIDToString(deviceList.at(ndx))
157  << " (" << xHEX0N(deviceList.at(ndx),8) << ")" << endl;
158  else
159  cout << DECN(ndx+1,2) << ": " << ::NTV2DeviceIDToString(deviceList.at(ndx)) << endl;
160  }
161  }
162 
163  // Print detailed bitfile info
164  if (isInfo)
165  {
166  // Get current design ID and version...
167  NTV2ULWordVector reg;
168  device.BitstreamStatus(reg);
171  NTV2DeviceID currentDeviceID (device.GetDeviceID());
172  ULWord bitfileID (CNTV2Bitfile::ConvertToBitfileID(currentDeviceID));
173  UWord bitfileVersion(0);
174  string flags = " Active";
175  device.GetRunningFirmwareRevision(bitfileVersion);
176  cout << std::setw(20) << std::left << ::NTV2DeviceIDToString(currentDeviceID) << std::right
177  << " DevID " << xHEX0N(currentDeviceID,8)
178  << " DesID " << xHEX0N(designID,2) << " DesVer " << xHEX0N(designVersion,2)
179  << " BitID " << xHEX0N(bitfileID,2) << " BitVer " << xHEX0N(bitfileVersion,2)
180  << " " << flags << endl;
181 
182  CNTV2BitfileManager bitMan;
183  bitMan.AddDirectory(".");
184  const NTV2BitfileInfoList infoList(bitMan.GetBitfileInfoList());
185  for (NTV2BitfileInfoListConstIter it(infoList.begin()); it != infoList.end(); ++it)
186  {
187  flags = "";
188  if (it->bitfileFlags & NTV2_BITFILE_FLAG_TANDEM)
189  flags += " Tandem";
190  if (it->bitfileFlags & NTV2_BITFILE_FLAG_PARTIAL)
191  flags += " Partial";
192  if (it->bitfileFlags & NTV2_BITFILE_FLAG_CLEAR)
193  flags += " Clear";
194  cout << std::setw(20) << std::left << ::NTV2DeviceIDToString(it->deviceID) << std::right
195  << " DevID " << xHEX0N(it->deviceID,8)
196  << " DesID " << xHEX0N(it->designID,2) << " DesVer " << xHEX0N(it->designVersion,2)
197  << " BitID " << xHEX0N(it->bitfileID,2) << " BitVer " << xHEX0N(it->bitfileVersion,2)
198  << " " << flags << endl;
199  }
200  }
201 
202  } while (false);
203 
204  return resultCode;
205 } // main
aja::stoul
unsigned long stoul(const std::string &str, std::size_t *idx, int base)
Definition: common.cpp:143
NTV2BitfileHeaderParser::GetDesignID
static ULWord GetDesignID(const ULWord userID)
Definition: ntv2bitfile.h:54
CNTV2Card::LoadDynamicDevice
virtual bool LoadDynamicDevice(const NTV2DeviceID inDeviceID)
Quickly, dynamically loads the given device ID firmware.
Definition: ntv2dynamicdevice.cpp:145
poptOption
Definition: options_popt.h:148
ntv2devicefeatures.h
Declares device capability functions.
CNTV2Bitfile::ConvertToBitfileID
static ULWord ConvertToBitfileID(const NTV2DeviceID inDeviceID)
Definition: ntv2bitfile.cpp:799
NTV2_BITFILE_FLAG_CLEAR
#define NTV2_BITFILE_FLAG_CLEAR
This is a clear bitfile.
Definition: ntv2bitfilemanager.h:25
CNTV2DeviceScanner::GetFirstDeviceFromArgument
static bool GetFirstDeviceFromArgument(const std::string &inArgument, CNTV2Card &outDevice)
Rescans the host, and returns an open CNTV2Card instance for the AJA device that matches a command li...
Definition: ntv2devicescanner.cpp:374
NTV2DeviceID
NTV2DeviceID
Identifies a specific AJA NTV2 device model number. The NTV2DeviceID is actually the PROM part number...
Definition: ntv2enums.h:20
CNTV2Card::AddDynamicDirectory
virtual bool AddDynamicDirectory(const std::string &inDirectory)
Adds all bitfiles found in the given host file directory to the list of available dynamic bitfiles.
Definition: ntv2dynamicdevice.cpp:220
main
int main(int argc, const char **argv)
Definition: main.cpp:30
NTV2_BITFILE_FLAG_PARTIAL
#define NTV2_BITFILE_FLAG_PARTIAL
This is a partial bitfile.
Definition: ntv2bitfilemanager.h:24
poptContext_s
Definition: options_popt.cpp:289
BITSTREAM_VERSION
#define BITSTREAM_VERSION
Bitstream version register.
Definition: ntv2publicinterface.h:5568
ajatypes.h
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
NTV2BitfileHeaderParser::GetDesignVersion
static ULWord GetDesignVersion(const ULWord userID)
Definition: ntv2bitfile.h:55
CNTV2BitfileManager::AddDirectory
virtual bool AddDirectory(const std::string &inDirectory)
Add the bitfile(s) at the given path to the list of bitfiles.
Definition: ntv2bitfilemanager.cpp:87
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
CNTV2BitfileManager
I manage and cache any number of bitfiles for any number of NTV2 devices/designs.
Definition: ntv2bitfilemanager.h:52
CNTV2BitfileManager::GetBitfileInfoList
virtual const NTV2BitfileInfoList & GetBitfileInfoList(void) const
Returns an NTV2BitfileInfoList standard C++ vector.
Definition: ntv2bitfilemanager.h:94
ULWord
uint32_t ULWord
Definition: ajatypes.h:255
ntv2devicescanner.h
Declares the CNTV2DeviceScanner class.
CNTV2Card::GetDynamicDeviceList
virtual NTV2DeviceIDList GetDynamicDeviceList(void)
Definition: ntv2dynamicdevice.cpp:68
NTV2DeviceIDToString
std::string NTV2DeviceIDToString(const NTV2DeviceID inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:4673
UWord
uint16_t UWord
Definition: ajatypes.h:253
ntv2enums.h
Enumerations for controlling NTV2 devices.
options_popt.h
ntv2utils.h
Declares numerous NTV2 utility functions.
poptFreeContext
poptContext poptFreeContext(poptContext con)
Definition: options_popt.cpp:3539
NTV2Version
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
NTV2BitfileInfoList
std::vector< NTV2BitfileInfo > NTV2BitfileInfoList
Definition: ntv2bitfilemanager.h:43
CNTV2Card::CanLoadDynamicDevice
virtual bool CanLoadDynamicDevice(const NTV2DeviceID inDeviceID)
Definition: ntv2dynamicdevice.cpp:139
CNTV2Card
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
NTV2ULWordVector
std::vector< ULWord > NTV2ULWordVector
An ordered sequence of ULWords.
Definition: ntv2publicinterface.h:3825
POPT_ARGFLAG_OPTIONAL
#define POPT_ARGFLAG_OPTIONAL
Definition: options_popt.h:88
CNTV2DriverInterface::BitstreamStatus
virtual bool BitstreamStatus(NTV2ULWordVector &outRegValues)
Definition: ntv2driverinterface.cpp:857
ntv2linuxpublicinterface.h
Types and defines shared between NTV2 user application interface and Linux device driver.
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:199
ntv2bitfile.h
Declares the CNTV2Bitfile class.
poptGetContext
poptContext poptGetContext(const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
Definition: options_popt.cpp:2264
DEC
#define DEC(__x__)
Definition: ntv2publicinterface.h:5606
NTV2BitfileInfoListConstIter
NTV2BitfileInfoList::const_iterator NTV2BitfileInfoListConstIter
Definition: ntv2bitfilemanager.h:45
poptGetNextOpt
int poptGetNextOpt(poptContext con)
Definition: options_popt.cpp:3236
common.h
Private include file for all ajabase sources.
std
Definition: json.hpp:5362
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
CNTV2DriverInterface::GetDeviceID
virtual NTV2DeviceID GetDeviceID(void)
Definition: ntv2driverinterface.cpp:407
ntv2bitfilemanager.h
Declares the CNTV2BitfileManager class that manages Xilinx bitfiles.
NTV2DeviceIDList
std::vector< NTV2DeviceID > NTV2DeviceIDList
An ordered list of NTV2DeviceIDs.
Definition: ntv2utils.h:1032
xHEX0N
#define xHEX0N(__x__, __n__)
Definition: ntv2publicinterface.h:5605
NTV2_BITFILE_FLAG_TANDEM
#define NTV2_BITFILE_FLAG_TANDEM
This is a tandem bitfile.
Definition: ntv2bitfilemanager.h:23
CNTV2Card::GetRunningFirmwareRevision
virtual bool GetRunningFirmwareRevision(UWord &outRevision)
Reports the revision number of the currently-running firmware.
Definition: ntv2register.cpp:2300
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
DECN
#define DECN(__x__, __n__)
Definition: ntv2publicinterface.h:5607