AJA NTV2 SDK  18.1.0.2262
NTV2 SDK 18.1.0.2262
ntv2link.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
9 #include "ntv2link.h"
10 #include "ntv2card.h"
11 #include "ntv42message.h"
12 
13 bool ntv2card_open(int index, void** card)
14 {
15  CNTV2Card* pCard = new CNTV2Card(index);
16  if (!pCard->IsOpen())
17  {
18  delete pCard;
19  return false;
20  }
21 
22  *card = (void*)pCard;
23  return true;
24 }
25 
26 void ntv2card_close(void* card)
27 {
28  CNTV2Card* pCard = (CNTV2Card*)card;
29  if (pCard != NULL)
30  {
31  delete pCard;
32  }
33 }
34 
35 bool ntv2card_get_display_name(void* card, char* display, int size)
36 {
37  if ((card == NULL) || (display == NULL) || (size == 0))
38  return false;
39  CNTV2Card* pCard = (CNTV2Card*)card;
40  std::string str = pCard->GetModelName();
41  snprintf(display, size, "%s", str.c_str());
42  return true;
43 }
44 
45 bool ntv2card_get_description(void* card, char* description, int size)
46 {
47  if ((card == NULL) || (description == NULL) || (size == 0))
48  return false;
49  CNTV2Card* pCard = (CNTV2Card*)card;
50  std::string str = pCard->GetDisplayName();
51  snprintf(description, size, "%s", str.c_str());
52  return true;
53 }
54 
55 bool ntv2card_get_serial_number(void* card, char* serial, int size)
56 {
57  if ((card == NULL) || (serial == NULL) || (size == 0))
58  return false;
59  CNTV2Card* pCard = (CNTV2Card*)card;
60  std::string str;
61  if (!pCard->GetSerialNumberString(str))
62  str = "Unknown";
63  snprintf(serial, size, "%s", str.c_str());
64  return true;
65 }
66 
67 bool ntv2card_register_read(void* card, unsigned int reg, unsigned int* data)
68 {
69  if ((card == NULL) || (data == NULL))
70  return false;
71  CNTV2Card* pCard = (CNTV2Card*)card;
72  #ifndef AJA_BAREMETAL // Xilinx compiler doesn't like this for some reason...
73  return pCard->ReadRegister(reg, *data);
74  #else
75  ULWord tmp;
76  bool status = pCard->ReadRegister(reg, tmp);
77  *data = tmp;
78  return status;
79  #endif
80 
81 }
82 
83 bool ntv2card_register_write(void* card, unsigned int reg, unsigned int data)
84 {
85  if (card == NULL)
86  return false;
87  CNTV2Card* pCard = (CNTV2Card*)card;
88  return pCard->WriteRegister(reg, data);
89 }
90 
91 bool ntv2card_send_message(void* card, void* data, unsigned int size)
92 {
93  if ((card == NULL) || (data == NULL) || size < sizeof(struct ntv42_message_header_t))
94  return false;
95  CNTV2Card* pCard = (CNTV2Card*)card;
96  struct ntv42_message_header_t* header = (struct ntv42_message_header_t*)data;
98 
99  NTV2MessageData msg(data, size, flags);
100  if (!pCard->NTV2Message(reinterpret_cast<NTV2_HEADER*>(&msg)))
101  return false;
102 
103  if (msg.GetStatus() != 0)
104  return false;
105 
106  return true;
107 }
108 
109 
#define NTV42_MESSAGE_FLAG_RW
Definition: ntv42message.h:39
#define NULL
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
#define NTV2_MESSAGE_DATA_RW
This is used to perform virtual data reads or writes.
uint32_t ULWord
Definition: ajatypes.h:236
virtual bool IsOpen(void) const
virtual bool GetSerialNumberString(std::string &outSerialNumberString)
Answers with a string that contains my human-readable serial number.
Definition: ntv2card.cpp:229
virtual std::string GetDisplayName(void)
Answers with this device&#39;s display name.
Definition: ntv2card.cpp:88
virtual bool ReadRegister(const ULWord inRegNum, ULWord &outValue, const ULWord inMask=0xFFFFFFFF, const ULWord inShift=0)
Reads all or part of the 32-bit contents of a specific register (real or virtual) on the AJA device...
virtual std::string GetModelName(void)
Answers with this device&#39;s model name.
Definition: ntv2card.cpp:82
virtual bool NTV2Message(NTV2_HEADER *pInMessage)
Sends a message to the NTV2 driver (the new, improved, preferred way).
virtual bool WriteRegister(const ULWord inRegNum, const ULWord inValue, const ULWord inMask=0xFFFFFFFF, const ULWord inShift=0)
Updates or replaces all or part of the 32-bit contents of a specific register (real or virtual) on th...
Declares the CNTV2Card class.