AJA NTV2 SDK  18.1.0.2262
NTV2 SDK 18.1.0.2262
konaipjsonsetup.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 #include "konaipjsonsetup.h"
3 #include <QFile>
4 #include <QJsonArray>
5 #include <QJsonDocument>
6 #include <QDebug>
7 #include "ajatypes.h"
8 #include "ntv2enums.h"
9 #include "ntv2democommon.h"
10 #include "ntv2endian.h"
11 #include "ntv2devicefeatures.h"
12 #include "ntv2devicescanner.h"
14 #if defined (AJALinux) || defined (AJAMac)
15  #include <arpa/inet.h>
16 #endif
17 
18 using std::endl;
19 using std::cout;
20 using std::cerr;
21 
22 NTV2Channel getChannel(QString channelDesignator);
23 bool getEnable(QString enableBoolString);
24 
26 {
27  mIs2110 = false;
28  mEnable2022_7 = false;
29  mNetworkPathDifferential = 50;
30 }
31 
32 bool CKonaIpJsonSetup::openJson(QString fileName)
33 {
34  bool result = false;
35 
36  QFile loadFile(fileName);
37  if ( !loadFile.open(QIODevice::ReadOnly))
38  {
39  qWarning("Couldn't open json file.");
40  return false;
41 
42  }
43  QByteArray saveData = loadFile.readAll();
44 
45  QJsonParseError err;
46  QJsonDocument loadDoc = (QJsonDocument::fromJson(saveData,&err));
47  if (err.error != QJsonParseError::NoError)
48  {
49  qDebug() << "JSON ERROR" << err.errorString() << "offset=" << err.offset;
50  //saveData[err.offset = 0];
51  qDebug() << saveData;
52  return false;
53  }
54 
55  // default is 2110 unless specified by protocol
56  mIs2110 = true;
57 
58  const QJsonObject & json = loadDoc.object();
59  QJsonValue qjv = json.value("protocol");
60  if (qjv != QJsonValue::Undefined)
61  {
62  QString protocol = qjv.toString();
63  if (protocol == "2022")
64  {
65  mIs2110 = false;
66  }
67  }
68 
69  if (mIs2110)
70  {
71  cout << "-----Protocol2110-----" << endl;
72  result = parse2110.SetJson(json, true);
73  }
74  else
75  {
76  cout << "-----Protocol2022-----" << endl;
77  qjv = json.value("enable2022_7");
78  if (qjv != QJsonValue::Undefined)
79  {
80  mEnable2022_7 = getEnable(qjv.toString());
81  }
82  else
83  {
84  mEnable2022_7 = false;
85  }
86  cout << "2022-7 mode " << mEnable2022_7 << endl;
87 
88  qjv = json.value("networkPathDifferential");
89  if (qjv != QJsonValue::Undefined)
90  {
91  mNetworkPathDifferential = qjv.toString().toUInt();
92  }
93  else
94  {
95  mNetworkPathDifferential = 50;
96  }
97  cout << "NetworkPathDifferential " << mNetworkPathDifferential << endl;
98 
99  result = readJson2022(json);
100  }
101 
102  return result;
103 }
104 
105 
106 bool CKonaIpJsonSetup::readJson2022(const QJsonObject &json)
107 {
108  mKonaIP2022Params.mSFPs.clear();
109  QJsonArray sfpArray = json["sfps"].toArray();
110  for (int sfpIndex = 0; sfpIndex < sfpArray.size(); ++sfpIndex)
111  {
112  cout << "SFP" << endl;
113 
114  QJsonObject sfpObject = sfpArray[sfpIndex].toObject();
115  SFPStruct sfpStruct;
116 
117  sfpStruct.mSfpDesignator = sfpObject["designator"].toString();
118  if (!sfpStruct.mSfpDesignator.isEmpty())
119  cout << "SFPDesignator " << sfpStruct.mSfpDesignator.toStdString() << endl;
120 
121  sfpStruct.mIPAddress = sfpObject["ipAddress"].toString();
122  if (!sfpStruct.mIPAddress.isEmpty())
123  cout << "IPAddress " << sfpStruct.mIPAddress.toStdString() << endl;
124 
125  sfpStruct.mSubnetMask = sfpObject["subnetMask"].toString();
126  if (!sfpStruct.mSubnetMask.isEmpty())
127  cout << "SubnetMask " << sfpStruct.mSubnetMask.toStdString() << endl;
128 
129  sfpStruct.mGateway = sfpObject["gateway"].toString();
130  if (!sfpStruct.mGateway.isEmpty())
131  cout << "Gateway " << sfpStruct.mGateway.toStdString() << endl;
132 
133  sfpStruct.mEnable = sfpObject["enable"].toString();
134  if (!sfpStruct.mEnable.isEmpty())
135  cout << "Enable " << sfpStruct.mEnable.toStdString() << endl;
136  cout << endl;
137 
138  mKonaIP2022Params.mSFPs.append(sfpStruct);
139  }
140 
142  QJsonArray receiveChannelArray = json["receive2022"].toArray();
143  for (int receiveChannelIndex = 0; receiveChannelIndex < receiveChannelArray.size(); ++receiveChannelIndex)
144  {
145  cout << "Receive2022Channels" << endl;
146 
147  QJsonObject receiveChannelObject = receiveChannelArray[receiveChannelIndex].toObject();
148  ReceiveStruct2022 receive2022Struct;
149 
150  receive2022Struct.mChannelDesignator = receiveChannelObject["designator"].toString();
151  if (!receive2022Struct.mChannelDesignator.isEmpty())
152  cout << "ChannelDesignator " << receive2022Struct.mChannelDesignator.toStdString() << endl;
153 
154  receive2022Struct.mSfp1SrcIPAddress = receiveChannelObject["sfp1SrcIPAddress"].toString();
155  if (!receive2022Struct.mSfp1SrcIPAddress.isEmpty())
156  cout << "SFP1SrcIPAddress " << receive2022Struct.mSfp1SrcIPAddress.toStdString() << endl;
157 
158  receive2022Struct.mSfp1SrcPort = receiveChannelObject["sfp1SrcPort"].toString();
159  if (!receive2022Struct.mSfp1SrcPort.isEmpty())
160  cout << "SFP1SrcPort " << receive2022Struct.mSfp1SrcPort.toStdString() << endl;
161 
162  receive2022Struct.mSfp1DestIPAddress = receiveChannelObject["sfp1DestIPAddress"].toString();
163  if (!receive2022Struct.mSfp1DestIPAddress.isEmpty())
164  cout << "SFP1DestIPAddress " << receive2022Struct.mSfp1DestIPAddress.toStdString() << endl;
165 
166  receive2022Struct.mSfp1DestPort = receiveChannelObject["sfp1DestPort"].toString();
167  if (!receive2022Struct.mSfp1DestPort.isEmpty())
168  cout << "SFP1DestPort " << receive2022Struct.mSfp1DestPort.toStdString() << endl;
169 
170  receive2022Struct.mSfp1Filter = receiveChannelObject["sfp1Filter"].toString();
171  if (!receive2022Struct.mSfp1Filter.isEmpty())
172  cout << "SFP1Filter " << receive2022Struct.mSfp1Filter.toStdString() << endl;
173 
174  receive2022Struct.mSfp2SrcIPAddress = receiveChannelObject["sfp2SrcIPAddress"].toString();
175  if (!receive2022Struct.mSfp2SrcIPAddress.isEmpty())
176  cout << "SFP2SrcIPAddress " << receive2022Struct.mSfp2SrcIPAddress.toStdString() << endl;
177 
178  receive2022Struct.mSfp2SrcPort = receiveChannelObject["sfp2SrcPort"].toString();
179  if (!receive2022Struct.mSfp2SrcPort.isEmpty())
180  cout << "SFP2SrcPort " << receive2022Struct.mSfp2SrcPort.toStdString() << endl;
181 
182  receive2022Struct.mSfp2DestIPAddress = receiveChannelObject["sfp2DestIPAddress"].toString();
183  if (!receive2022Struct.mSfp2DestIPAddress.isEmpty())
184  cout << "SFP1DestIPAddress " << receive2022Struct.mSfp2DestIPAddress.toStdString() << endl;
185 
186  receive2022Struct.mSfp2DestPort = receiveChannelObject["sfp2DestPort"].toString();
187  if (!receive2022Struct.mSfp2DestPort.isEmpty())
188  cout << "SFP1DestPort " << receive2022Struct.mSfp2DestPort.toStdString() << endl;
189 
190  receive2022Struct.mSfp2Filter = receiveChannelObject["sfp2Filter"].toString();
191  if (!receive2022Struct.mSfp2Filter.isEmpty())
192  cout << "SFP1Filter " << receive2022Struct.mSfp2Filter.toStdString() << endl;
193 
194  receive2022Struct.mPlayoutDelay = receiveChannelObject["playoutDelay"].toString();
195  if (!receive2022Struct.mPlayoutDelay.isEmpty())
196  cout << "PlayoutDelay " << receive2022Struct.mPlayoutDelay.toStdString() << endl;
197 
198  receive2022Struct.mVLAN = receiveChannelObject["vlan"].toString();
199  if (!receive2022Struct.mVLAN.isEmpty())
200  cout << "VLAN " << receive2022Struct.mVLAN.toStdString() << endl;
201 
202  receive2022Struct.mSSRC = receiveChannelObject["ssrc"].toString();
203  if (!receive2022Struct.mSSRC.isEmpty())
204  cout << "SSRC " << receive2022Struct.mSSRC.toStdString() << endl;
205 
206  receive2022Struct.mSfp1Enable = receiveChannelObject["sfp1Enable"].toString();
207  if (!receive2022Struct.mSfp1Enable.isEmpty())
208  cout << "SFP1 Enable " << receive2022Struct.mSfp1Enable.toStdString() << endl;
209 
210  receive2022Struct.mSfp2Enable = receiveChannelObject["sfp2Enable"].toString();
211  if (!receive2022Struct.mSfp2Enable.isEmpty())
212  cout << "SFP2 Enable " << receive2022Struct.mSfp2Enable.toStdString() << endl;
213 
214  receive2022Struct.mEnable = receiveChannelObject["enable"].toString();
215  if (!receive2022Struct.mEnable.isEmpty())
216  cout << "Enable " << receive2022Struct.mEnable.toStdString() << endl;
217  cout << endl;
218 
219  mKonaIP2022Params.mReceive2022Channels.append(receive2022Struct);
220  }
221 
223  QJsonArray transmitChannelArray = json["transmit2022"].toArray();
224  for (int transmitChannelIndex = 0; transmitChannelIndex < transmitChannelArray.size(); ++transmitChannelIndex)
225  {
226  cout << "Transmit2022Channels" << endl;
227 
228  QJsonObject transmitChannelObject = transmitChannelArray[transmitChannelIndex].toObject();
229  TransmitStruct2022 transmitStruct2022;
230 
231  transmitStruct2022.mChannelDesignator = transmitChannelObject["designator"].toString();
232  if (!transmitStruct2022.mChannelDesignator.isEmpty())
233  cout << "ChannelDesignator " << transmitStruct2022.mChannelDesignator.toStdString() << endl;
234 
235  transmitStruct2022.mSfp1RemoteIPAddress = transmitChannelObject["sfp1RemoteIPAddress"].toString();
236  if (!transmitStruct2022.mSfp1RemoteIPAddress.isEmpty())
237  cout << "SFP1RemoteIPAddress " << transmitStruct2022.mSfp1RemoteIPAddress.toStdString() << endl;
238 
239  transmitStruct2022.mSfp1RemotePort = transmitChannelObject["sfp1RemotePort"].toString();
240  if (!transmitStruct2022.mSfp1RemotePort.isEmpty())
241  cout << "SFP1RemotePort " << transmitStruct2022.mSfp1RemotePort.toStdString() << endl;
242 
243  transmitStruct2022.mSfp1LocalPort = transmitChannelObject["sfp1LocalPort"].toString();
244  if (!transmitStruct2022.mSfp1LocalPort.isEmpty())
245  cout << "SFP1LocalPort " << transmitStruct2022.mSfp1LocalPort.toStdString() << endl;
246 
247  transmitStruct2022.mSfp2RemoteIPAddress = transmitChannelObject["sfp2RemoteIPAddress"].toString();
248  if (!transmitStruct2022.mSfp2RemoteIPAddress.isEmpty())
249  cout << "SFP2RemoteIPAddress " << transmitStruct2022.mSfp2RemoteIPAddress.toStdString() << endl;
250 
251  transmitStruct2022.mSfp2RemotePort = transmitChannelObject["sfp2RemotePort"].toString();
252  if (!transmitStruct2022.mSfp2RemoteIPAddress.isEmpty())
253  cout << "SFP2RemotePort " << transmitStruct2022.mSfp2RemotePort.toStdString() << endl;
254 
255  transmitStruct2022.mSfp2LocalPort = transmitChannelObject["sfp2LocalPort"].toString();
256  if (!transmitStruct2022.mSfp2LocalPort.isEmpty())
257  cout << "SFP2LocalPort " << transmitStruct2022.mSfp2LocalPort.toStdString() << endl;
258 
259  transmitStruct2022.mTOS = transmitChannelObject["tos"].toString();
260  if (!transmitStruct2022.mTOS.isEmpty())
261  cout << "TOS " << transmitStruct2022.mTOS.toStdString() << endl;
262 
263  transmitStruct2022.mTTL = transmitChannelObject["ttl"].toString();
264  if (!transmitStruct2022.mTTL.isEmpty())
265  cout << "TTL " << transmitStruct2022.mTTL.toStdString() << endl;
266 
267  transmitStruct2022.mSSRC = transmitChannelObject["ssrc"].toString();
268  if (!transmitStruct2022.mSSRC.isEmpty())
269  cout << "SSRC " << transmitStruct2022.mSSRC.toStdString() << endl;
270 
271  transmitStruct2022.mSfp1Enable = transmitChannelObject["sfp1Enable"].toString();
272  if (!transmitStruct2022.mSfp1Enable.isEmpty())
273  cout << "SFP1 Enable " << transmitStruct2022.mSfp1Enable.toStdString() << endl;
274 
275  transmitStruct2022.mSfp2Enable = transmitChannelObject["sfp2Enable"].toString();
276  if (!transmitStruct2022.mSfp2Enable.isEmpty())
277  cout << "SFP2 Enable " << transmitStruct2022.mSfp2Enable.toStdString() << endl;
278 
279  transmitStruct2022.mEnable = transmitChannelObject["enable"].toString();
280  if (!transmitStruct2022.mEnable.isEmpty())
281  cout << "Enable " << transmitStruct2022.mEnable.toStdString() << endl;
282  cout << endl;
283 
284  mKonaIP2022Params.mTransmit2022Channels.append(transmitStruct2022);
285  }
286  return true;
287 }
288 
289 bool CKonaIpJsonSetup::setupBoard(std::string deviceSpec)
290 {
291  if (mIs2110)
292  {
293  return setupBoard2110(deviceSpec);
294  }
295  else
296  {
297  return setupBoard2022(deviceSpec);
298  }
299 }
300 
301 bool CKonaIpJsonSetup::setupBoard2022(std::string deviceSpec)
302 {
303  CNTV2Card mDevice;
305  if (!mDevice.IsOpen())
306  {
307  cerr << "## ERROR: No devices found " << deviceSpec.c_str() << endl;
308  return false;
309  }
310  //if (!mDevice.IsIPDevice())
311  // {cerr << "## ERROR: Not an IP device" << endl; return false;}
312 
313  // Wait for device ready
314  while (!mDevice.IsMBSystemReady())
315  {
316  cout << "## NOTE: Waiting for device to become ready... (Ctrl-C will abort)" << endl;
317  AJATime::Sleep(1000);
318  if (mDevice.IsMBSystemReady ())
319  {
320  cout << "## NOTE: Device is ready" << endl;
321  }
322  }
323 
324  if (!mDevice.IsMBSystemValid())
325  {
326  cerr << "## ERROR: board firmware package is incompatible with this application" << endl;
327  return false;
328  }
329 
330  CNTV2Config2022 config2022 (mDevice);
331 
332  if (mKonaIP2022Params.mSFPs.size() < 1)
333  {
334  cerr << "## ERROR: Need To Specify at Least 1 SFP" << endl;
335  return false;
336  }
337 
338  QListIterator<SFPStruct> sfpIter(mKonaIP2022Params.mSFPs);
339  while (sfpIter.hasNext())
340  {
341  SFPStruct sfp = sfpIter.next();
342 
343  if ( sfp.mSfpDesignator == "sfp1")
344  {
345  bool enable;
346  if (sfp.mEnable.isEmpty())
347  enable = true;
348  else
349  enable = getEnable(sfp.mEnable);
350 
351  if (enable)
352  {
353  bool rv = config2022.SetNetworkConfiguration (SFP_1,
354  sfp.mIPAddress.toStdString(),
355  sfp.mSubnetMask.toStdString(),
356  sfp.mGateway.toStdString());
357  if (!rv)
358  {
359  cerr << "Error: " << config2022.getLastError() << endl;
360  return false;
361  }
362  }
363  else
364  {
365  config2022.DisableNetworkInterface(SFP_1);
366  }
367  }
368  else if ( sfp.mSfpDesignator == "sfp2")
369  {
370  bool enable;
371  if (sfp.mEnable.isEmpty())
372  enable = true;
373  else
374  enable = getEnable(sfp.mEnable);
375 
376  if (enable)
377  {
378  bool rv = config2022.SetNetworkConfiguration (SFP_2,
379  sfp.mIPAddress.toStdString(),
380  sfp.mSubnetMask.toStdString(),
381  sfp.mGateway.toStdString());
382  if (!rv)
383  {
384  cerr << "Error: " << config2022.getLastError() << endl;
385  return false;
386  }
387  }
388  else
389  {
390  config2022.DisableNetworkInterface(SFP_2);
391  }
392  }
393  }
394 
395  uint32_t val;
396  mDevice.ReadRegister(SAREK_REGS + kRegSarekFwCfg, val);
397  bool supports2022_7 = ((val & SAREK_2022_7) != 0);
398  if (supports2022_7)
399  {
400  bool rv = config2022.Set2022_7_Mode(mEnable2022_7,mNetworkPathDifferential);
401  if (!rv)
402  {
403  cerr << "Error: " << config2022.getLastError() << endl;
404  return false;
405  }
406  }
407 
408  cerr << "## receiveIter" << endl;
409 
410  QListIterator<ReceiveStruct2022> receiveIter(mKonaIP2022Params.mReceive2022Channels);
411  while (receiveIter.hasNext())
412  {
413  cerr << "## receiveIter " << endl;
414 
415  ReceiveStruct2022 receive = receiveIter.next();
416  rx_2022_channel rxChannelConfig;
417  bool ok;
418  NTV2Channel channel = getChannel(receive.mChannelDesignator);
419 
420  if (mEnable2022_7)
421  {
422  rxChannelConfig.sfp1Enable = true;
423  rxChannelConfig.sfp2Enable = true;
424  }
425  else
426  {
427  if (!receive.mSfp1Enable.isEmpty())
428  rxChannelConfig.sfp1Enable = (getEnable(receive.mSfp1Enable));
429  if (!receive.mSfp2Enable.isEmpty())
430  rxChannelConfig.sfp2Enable = (getEnable(receive.mSfp2Enable));
431  }
432  rxChannelConfig.sfp1SourceIP = receive.mSfp1SrcIPAddress.toStdString();
433  rxChannelConfig.sfp1SourcePort = receive.mSfp1SrcPort.toUInt();
434  rxChannelConfig.sfp1DestIP = receive.mSfp1DestIPAddress.toStdString();
435  rxChannelConfig.sfp1DestPort = receive.mSfp1DestPort.toUInt();
436  rxChannelConfig.sfp1RxMatch = receive.mSfp1Filter.toUInt(&ok, 16);
437  rxChannelConfig.sfp2SourceIP = receive.mSfp2SrcIPAddress.toStdString();
438  rxChannelConfig.sfp2SourcePort = receive.mSfp2SrcPort.toUInt();
439  rxChannelConfig.sfp2DestIP = receive.mSfp2DestIPAddress.toStdString();
440  rxChannelConfig.sfp2DestPort = receive.mSfp2DestPort.toUInt();
441  rxChannelConfig.sfp2RxMatch = receive.mSfp2Filter.toUInt(&ok, 16);
442  rxChannelConfig.playoutDelay = receive.mPlayoutDelay.toUInt();
443  rxChannelConfig.ssrc = receive.mSSRC.toUInt();
444 
445  bool rv = config2022.SetRxChannelConfiguration (channel, rxChannelConfig);
446  if (!rv)
447  {
448  cerr << "Error (config2022.SetRxChannelConfiguration) " << config2022.getLastError() << endl;
449  return false;
450  }
451  rv = config2022.SetRxChannelEnable (channel, getEnable(receive.mEnable));
452  if (!rv)
453  {
454  cerr << "Error (config2022.SetRxChannelConfiguration) " << config2022.getLastError() << endl;
455  return false;
456  }
457  }
458  cerr << "## transmitIter" << endl;
459 
460  QListIterator<TransmitStruct2022> transmitIter(mKonaIP2022Params.mTransmit2022Channels);
461  while (transmitIter.hasNext())
462  {
463  cerr << "## transmitIter " << endl;
464 
465  TransmitStruct2022 transmit = transmitIter.next();
466  tx_2022_channel txChannelConfig;
467 
468  NTV2Channel channel = getChannel(transmit.mChannelDesignator);
469  if (mEnable2022_7)
470  {
471  txChannelConfig.sfp1Enable = true;
472  txChannelConfig.sfp2Enable = true;
473  }
474  else
475  {
476  if (!transmit.mSfp1Enable.isEmpty())
477  txChannelConfig.sfp1Enable = (getEnable(transmit.mSfp1Enable));
478  if (!transmit.mSfp2Enable.isEmpty())
479  txChannelConfig.sfp2Enable = (getEnable(transmit.mSfp2Enable));
480  }
481  txChannelConfig.sfp1LocalPort = transmit.mSfp1LocalPort.toUInt();
482  txChannelConfig.sfp1RemoteIP = transmit.mSfp1RemoteIPAddress.toStdString();
483  txChannelConfig.sfp1RemotePort = transmit.mSfp1RemotePort.toUInt();
484  txChannelConfig.sfp2LocalPort = transmit.mSfp2LocalPort.toUInt();
485  txChannelConfig.sfp2RemoteIP = transmit.mSfp2RemoteIPAddress.toStdString();
486  txChannelConfig.sfp2RemotePort = transmit.mSfp2RemotePort.toUInt();
487  txChannelConfig.ssrc = transmit.mSSRC.toUInt();
488  txChannelConfig.tos = transmit.mTOS.toUInt();
489  txChannelConfig.ttl = transmit.mTTL.toUInt();
490 
491  bool rv = config2022.SetTxChannelConfiguration (channel, txChannelConfig);
492  if (!rv)
493  {
494  cerr << "Error (config2022.SetTxChannelConfiguration) " << config2022.getLastError() << endl;
495  return false;
496  }
497  rv = config2022.SetTxChannelEnable (channel, getEnable(transmit.mEnable));
498  if (!rv)
499  {
500  cerr << "Error (config2022.SetTxChannelEnable) " << config2022.getLastError() << endl;
501  return false;
502  }
503  }
504 
505  return true;
506 }
507 
508 bool CKonaIpJsonSetup::setupBoard2110(std::string deviceSpec)
509 {
510  CNTV2Card device;
512  if (!device.IsOpen())
513  {cerr << "## ERROR: No devices found " << deviceSpec.c_str() << endl; return false;}
514  //if (!mDevice.IsIPDevice())
515  // {cerr << "## ERROR: Not an IP device" << endl; return false;}
516 
517  // Read MicroBlaze Uptime in Seconds, to see if it's running...
518  while (!device.IsMBSystemReady())
519  {
520  cout << "## NOTE: Waiting for device to become ready... (Ctrl-C will abort)" << endl;
521  AJATime::Sleep(1000);
522  if (device.IsMBSystemReady ())
523  {
524  cout << "## NOTE: Device is ready" << endl;
525  if (device.IsMBSystemValid())
526  {
527  cerr << "## ERROR: board firmware package is incompatible with this application" << endl;
528  return false;
529  }
530  }
531  }
532 
533  CNTV2Config2110 config2110 (device);
534 
535  // fetch parsed newtwork struct
536  NetworkData2110 net2110 = parse2110.m_net2110;
537 
538  // Only if a non zero domain was passed in
539  if (net2110.ptpDomain)
540  {
541  config2110.SetPTPDomain(net2110.ptpDomain);
542  }
543 
544  // Only if a non zero grandMasterID was passed in
545  if (net2110.ptpPreferredGMID[0] || net2110.ptpPreferredGMID[1] || net2110.ptpPreferredGMID[2] || net2110.ptpPreferredGMID[3] ||
546  net2110.ptpPreferredGMID[4] || net2110.ptpPreferredGMID[5] || net2110.ptpPreferredGMID[6] || net2110.ptpPreferredGMID[7])
547  {
548  config2110.SetPTPPreferredGrandMasterId(net2110.ptpPreferredGMID);
549  }
550 
552  config2110.Set4KModeEnable(net2110.setup4k);
553  config2110.SetAudioCombineEnable(net2110.audioCombine);
554  config2110.SetPTPDomain(net2110.ptpDomain);
555  config2110.SetPTPPreferredGrandMasterId(net2110.ptpPreferredGMID);
556 
557  for (uint32_t i = 0; i < net2110.numSFPs; i++)
558  {
559  cerr << "## network " << i+1 << endl;
560 
561  eSFP sfp = SFP_1;
562  if (i > 0)
563  sfp = SFP_2;
564 
565  bool rv;
566  if (net2110.sfp[i].enable)
567  {
568  rv = config2110.SetNetworkConfiguration(sfp,
569  net2110.sfp[i].ipAddress,
570  net2110.sfp[i].subnetMask,
571  net2110.sfp[i].gateWay);
572  if (!rv)
573  {
574  cerr << "Error: " << config2110.getLastError() << endl;
575  return false;
576  }
577  }
578  else
579  {
580  config2110.DisableNetworkInterface(sfp);
581  }
582  }
583 
584  rx_2110Config rxChannelConfig;
585 
586  // fetch parsed receive video struct
587  ReceiveVideoData2110 receiveVideo2110 = parse2110.m_receiveVideo2110;
588  for (uint32_t i = 0; i < receiveVideo2110.numRxVideoChannels; i++)
589  {
590  cerr << "## receiveVideo " << i+1 << endl;
591 
592  rxChannelConfig.init();
593 
594  // If sfp2 is on use it otherwise assume we are always dealing with sfp1
595  // (RX does not support both at the moment)
596  eSFP sfp = SFP_INVALID;
597  if (receiveVideo2110.rxVideoCh[i].sfpEnable[0])
598  sfp = SFP_1;
599  else if (receiveVideo2110.rxVideoCh[i].sfpEnable[1])
600  sfp = SFP_2;
601 
602  // Until we support -7, only use one link
603  if (sfp == SFP_1)
604  {
605  rxChannelConfig.sourceIP = receiveVideo2110.rxVideoCh[i].sourceIP[0];
606  rxChannelConfig.destIP = receiveVideo2110.rxVideoCh[i].destIP[0];
607  rxChannelConfig.sourcePort = receiveVideo2110.rxVideoCh[i].sourcePort[0];
608  rxChannelConfig.destPort = receiveVideo2110.rxVideoCh[i].destPort[0];
609  }
610  else
611  {
612  rxChannelConfig.sourceIP = receiveVideo2110.rxVideoCh[i].sourceIP[1];
613  rxChannelConfig.destIP = receiveVideo2110.rxVideoCh[i].destIP[1];
614  rxChannelConfig.sourcePort = receiveVideo2110.rxVideoCh[i].sourcePort[1];
615  rxChannelConfig.destPort = receiveVideo2110.rxVideoCh[i].destPort[1];
616  }
617  rxChannelConfig.ssrc = receiveVideo2110.rxVideoCh[i].vlan;
618  rxChannelConfig.vlan = receiveVideo2110.rxVideoCh[i].ssrc;
619  rxChannelConfig.payloadType = receiveVideo2110.rxVideoCh[i].payloadType;
620 
621  rxChannelConfig.videoFormat = receiveVideo2110.rxVideoCh[i].videoFormat;
622  rxChannelConfig.videoSamples = VPIDSampling_YUV_422;
623 
624  // Set RX match based on non zero passed in params
625  rxChannelConfig.rxMatch = 0;
626  uint32_t ip = 0;
627  ip = inet_addr(rxChannelConfig.sourceIP.c_str());
628  ip = NTV2EndianSwap32(ip);
629  if (ip)
630  rxChannelConfig.rxMatch |= RX_MATCH_2110_SOURCE_IP;
631  ip = inet_addr(rxChannelConfig.destIP.c_str());
632  ip = NTV2EndianSwap32(ip);
633  if (ip)
634  rxChannelConfig.rxMatch |= RX_MATCH_2110_DEST_IP;
635  if (rxChannelConfig.sourcePort)
636  rxChannelConfig.rxMatch |= RX_MATCH_2110_SOURCE_PORT;
637  if (rxChannelConfig.destPort)
638  rxChannelConfig.rxMatch |= RX_MATCH_2110_DEST_PORT;
639  if (rxChannelConfig.vlan)
640  rxChannelConfig.rxMatch |= RX_MATCH_2110_VLAN;
641  if (rxChannelConfig.payloadType)
642  rxChannelConfig.rxMatch |= RX_MATCH_2110_PAYLOAD;
643  if (rxChannelConfig.ssrc)
644  rxChannelConfig.rxMatch |= RX_MATCH_2110_SSRC;
645 
646 
647  bool rv;
648  rv = config2110.SetRxStreamConfiguration (sfp,
649  receiveVideo2110.rxVideoCh[i].stream,
650  rxChannelConfig);
651  if (!rv)
652  {
653  cerr << "SetRxStreamConfiguration: Video FAILED: " << config2110.getLastError() << endl;
654  }
655  else
656  {
657  rv = config2110.SetRxStreamEnable(sfp,
658  receiveVideo2110.rxVideoCh[i].stream,
659  receiveVideo2110.rxVideoCh[i].enable);
660  if (!rv)
661  {
662  cerr << "SetRxStreamEnable: Video FAILED: " << config2110.getLastError() << endl;
663  }
664  }
665  }
666 
667  // fetch parsed receive audio struct
668  ReceiveAudioData2110 receiveAudio2110 = parse2110.m_receiveAudio2110;
669  for (uint32_t i = 0; i < receiveAudio2110.numRxAudioChannels; i++)
670  {
671  cerr << "## receiveAudio " << i+1 << endl;
672 
673  rxChannelConfig.init();
674 
675  // If sfp2 is on use it otherwise assume we are always dealing with sfp1
676  // (RX does not support both at the moment)
677  eSFP sfp = SFP_INVALID;
678  if (receiveAudio2110.rxAudioCh[i].sfpEnable[0])
679  sfp = SFP_1;
680  else if (receiveAudio2110.rxAudioCh[i].sfpEnable[1])
681  sfp = SFP_2;
682 
683  // Until we support -7, only use one link
684  if (sfp == SFP_1)
685  {
686  rxChannelConfig.sourceIP = receiveAudio2110.rxAudioCh[i].sourceIP[0];
687  rxChannelConfig.destIP = receiveAudio2110.rxAudioCh[i].destIP[0];
688  rxChannelConfig.sourcePort = receiveAudio2110.rxAudioCh[i].sourcePort[0];
689  rxChannelConfig.destPort = receiveAudio2110.rxAudioCh[i].destPort[0];
690  }
691  else
692  {
693  rxChannelConfig.sourceIP = receiveAudio2110.rxAudioCh[i].sourceIP[1];
694  rxChannelConfig.destIP = receiveAudio2110.rxAudioCh[i].destIP[1];
695  rxChannelConfig.sourcePort = receiveAudio2110.rxAudioCh[i].sourcePort[1];
696  rxChannelConfig.destPort = receiveAudio2110.rxAudioCh[i].destPort[1];
697  }
698  rxChannelConfig.ssrc = receiveAudio2110.rxAudioCh[i].vlan;
699  rxChannelConfig.vlan = receiveAudio2110.rxAudioCh[i].ssrc;
700  rxChannelConfig.payloadType = receiveAudio2110.rxAudioCh[i].payloadType;
701  rxChannelConfig.numAudioChannels = receiveAudio2110.rxAudioCh[i].numAudioChannels;
702  rxChannelConfig.audioPktInterval = receiveAudio2110.rxAudioCh[i].audioPktInterval;
703 
704  // Set RX match based on non zero passed in params
705  rxChannelConfig.rxMatch = 0;
706  uint32_t ip = 0;
707  ip = inet_addr(rxChannelConfig.sourceIP.c_str());
708  ip = NTV2EndianSwap32(ip);
709  if (ip)
710  rxChannelConfig.rxMatch |= RX_MATCH_2110_SOURCE_IP;
711  ip = inet_addr(rxChannelConfig.destIP.c_str());
712  ip = NTV2EndianSwap32(ip);
713  if (ip)
714  rxChannelConfig.rxMatch |= RX_MATCH_2110_DEST_IP;
715  if (rxChannelConfig.sourcePort)
716  rxChannelConfig.rxMatch |= RX_MATCH_2110_SOURCE_PORT;
717  if (rxChannelConfig.destPort)
718  rxChannelConfig.rxMatch |= RX_MATCH_2110_DEST_PORT;
719  if (rxChannelConfig.vlan)
720  rxChannelConfig.rxMatch |= RX_MATCH_2110_VLAN;
721  if (rxChannelConfig.payloadType)
722  rxChannelConfig.rxMatch |= RX_MATCH_2110_PAYLOAD;
723  if (rxChannelConfig.ssrc)
724  rxChannelConfig.rxMatch |= RX_MATCH_2110_SSRC;
725 
726 
727  bool rv;
728  rv = config2110.SetRxStreamConfiguration (sfp,
729  receiveAudio2110.rxAudioCh[i].stream,
730  rxChannelConfig);
731  if (!rv)
732  {
733  cerr << "SetRxStreamConfiguration: Audio FAILED: " << config2110.getLastError() << endl;
734  }
735  else
736  {
737  rv = config2110.SetRxStreamEnable(sfp,
738  receiveAudio2110.rxAudioCh[i].stream,
739  receiveAudio2110.rxAudioCh[i].enable);
740  if (!rv)
741  {
742  cerr << "SetRxStreamEnable: Audio FAILED: " << config2110.getLastError() << endl;
743  }
744  }
745  }
746 
747  // fetch parsed receive anc struct
748  ReceiveAncData2110 receiveAnc2110 = parse2110.m_receiveAnc2110;
749  for (uint32_t i = 0; i < receiveAnc2110.numRxAncChannels; i++)
750  {
751  cerr << "## receiveAnc " << i+1 << endl;
752 
753  rxChannelConfig.init();
754 
755  // If sfp2 is on use it otherwise assume we are always dealing with sfp1
756  // (RX does not support both at the moment)
757  eSFP sfp = SFP_INVALID;
758  if (receiveAnc2110.rxAncCh[i].sfpEnable[0])
759  sfp = SFP_1;
760  else if (receiveAnc2110.rxAncCh[i].sfpEnable[1])
761  sfp = SFP_2;
762 
763  // Until we support -7, only use one link
764  if (sfp == SFP_1)
765  {
766  rxChannelConfig.sourceIP = receiveAnc2110.rxAncCh[i].sourceIP[0];
767  rxChannelConfig.destIP = receiveAnc2110.rxAncCh[i].destIP[0];
768  rxChannelConfig.sourcePort = receiveAnc2110.rxAncCh[i].sourcePort[0];
769  rxChannelConfig.destPort = receiveAnc2110.rxAncCh[i].destPort[0];
770  }
771  else
772  {
773  rxChannelConfig.sourceIP = receiveAnc2110.rxAncCh[i].sourceIP[1];
774  rxChannelConfig.destIP = receiveAnc2110.rxAncCh[i].destIP[1];
775  rxChannelConfig.sourcePort = receiveAnc2110.rxAncCh[i].sourcePort[1];
776  rxChannelConfig.destPort = receiveAnc2110.rxAncCh[i].destPort[1];
777  }
778  rxChannelConfig.ssrc = receiveAnc2110.rxAncCh[i].vlan;
779  rxChannelConfig.vlan = receiveAnc2110.rxAncCh[i].ssrc;
780  rxChannelConfig.payloadType = receiveAnc2110.rxAncCh[i].payloadType;
781 
782  // Set RX match based on non zero passed in params
783  rxChannelConfig.rxMatch = 0;
784  uint32_t ip = 0;
785  ip = inet_addr(rxChannelConfig.sourceIP.c_str());
786  ip = NTV2EndianSwap32(ip);
787  if (ip)
788  rxChannelConfig.rxMatch |= RX_MATCH_2110_SOURCE_IP;
789  ip = inet_addr(rxChannelConfig.destIP.c_str());
790  ip = NTV2EndianSwap32(ip);
791  if (ip)
792  rxChannelConfig.rxMatch |= RX_MATCH_2110_DEST_IP;
793  if (rxChannelConfig.sourcePort)
794  rxChannelConfig.rxMatch |= RX_MATCH_2110_SOURCE_PORT;
795  if (rxChannelConfig.destPort)
796  rxChannelConfig.rxMatch |= RX_MATCH_2110_DEST_PORT;
797  if (rxChannelConfig.vlan)
798  rxChannelConfig.rxMatch |= RX_MATCH_2110_VLAN;
799  if (rxChannelConfig.payloadType)
800  rxChannelConfig.rxMatch |= RX_MATCH_2110_PAYLOAD;
801  if (rxChannelConfig.ssrc)
802  rxChannelConfig.rxMatch |= RX_MATCH_2110_SSRC;
803 
804  bool rv;
805  rv = config2110.SetRxStreamConfiguration (sfp,
806  receiveAnc2110.rxAncCh[i].stream,
807  rxChannelConfig);
808  if (!rv)
809  {
810  cerr << "SetRxStreamConfiguration: ANC FAILED: " << config2110.getLastError() << endl;
811  }
812  else
813  {
814  rv = config2110.SetRxStreamEnable(sfp,
815  receiveAnc2110.rxAncCh[i].stream,
816  receiveAnc2110.rxAncCh[i].enable);
817  if (!rv)
818  {
819  cerr << "SetRxStreamEnable: ANC FAILED: " << config2110.getLastError() << endl;
820  }
821  }
822  }
823 
824  tx_2110Config txChannelConfig;
825 
826  // fetch parsed transmit video struct
827  TransmitVideoData2110 transmitVideo2110 = parse2110.m_transmitVideo2110;
828  for (uint32_t i = 0; i < transmitVideo2110.numTxVideoChannels; i++)
829  {
830  cerr << "## transmitVideo " << i+1 << endl;
831 
832  bool rv;
833  txChannelConfig.init();
834 
835  txChannelConfig.localPort[0] = transmitVideo2110.txVideoCh[i].localPort[0];
836  txChannelConfig.remoteIP[0] = transmitVideo2110.txVideoCh[i].remoteIP[0];
837  txChannelConfig.remotePort[0] = transmitVideo2110.txVideoCh[i].remotePort[0];
838  txChannelConfig.localPort[1] = transmitVideo2110.txVideoCh[i].localPort[1];
839  txChannelConfig.remoteIP[1] = transmitVideo2110.txVideoCh[i].remoteIP[1];
840  txChannelConfig.remotePort[1] = transmitVideo2110.txVideoCh[i].remotePort[1];
841 
842  txChannelConfig.payloadType = transmitVideo2110.txVideoCh[i].payloadType;
843  txChannelConfig.ssrc = transmitVideo2110.txVideoCh[i].ssrc;
844  txChannelConfig.ttl = transmitVideo2110.txVideoCh[i].ttl;
845  txChannelConfig.videoFormat = transmitVideo2110.txVideoCh[i].videoFormat;
846  txChannelConfig.videoSamples = transmitVideo2110.txVideoCh[i].sampling;
847 
848  rv = config2110.SetTxStreamConfiguration(transmitVideo2110.txVideoCh[i].stream,
849  txChannelConfig);
850  if (!rv)
851  {
852  cerr << "SetTxStreamConfiguration Video: FAILED: " << config2110.getLastError() << endl;
853  }
854  else
855  {
856  if (transmitVideo2110.txVideoCh[i].enable)
857  {
858  rv = config2110.SetTxStreamEnable(transmitVideo2110.txVideoCh[i].stream,
859  transmitVideo2110.txVideoCh[i].sfpEnable[0],
860  transmitVideo2110.txVideoCh[i].sfpEnable[1]);
861  if (!rv)
862  {
863  cerr << "SetTxStreamEnable Video: FAILED: " << config2110.getLastError() << endl;
864  }
865  }
866  }
867  }
868 
869  // fetch parsed transmit audio struct
870  TransmitAudioData2110 transmitAudio2110 = parse2110.m_transmitAudio2110;
871  for (uint32_t i = 0; i < transmitAudio2110.numTxAudioChannels; i++)
872  {
873  cerr << "## transmitAudio " << i+1 << endl;
874 
875  bool rv;
876  txChannelConfig.init();
877 
878  txChannelConfig.localPort[0] = transmitAudio2110.txAudioCh[i].localPort[0];
879  txChannelConfig.remoteIP[0] = transmitAudio2110.txAudioCh[i].remoteIP[0];
880  txChannelConfig.remotePort[0] = transmitAudio2110.txAudioCh[i].remotePort[0];
881  txChannelConfig.localPort[1] = transmitAudio2110.txAudioCh[i].localPort[1];
882  txChannelConfig.remoteIP[1] = transmitAudio2110.txAudioCh[i].remoteIP[1];
883  txChannelConfig.remotePort[1] = transmitAudio2110.txAudioCh[i].remotePort[1];
884 
885  txChannelConfig.payloadType = transmitAudio2110.txAudioCh[i].payloadType;
886  txChannelConfig.ssrc = transmitAudio2110.txAudioCh[i].ssrc;
887  txChannelConfig.ttl = transmitAudio2110.txAudioCh[i].ttl;
888 
889  txChannelConfig.numAudioChannels = transmitAudio2110.txAudioCh[i].numAudioChannels;
890  txChannelConfig.firstAudioChannel = transmitAudio2110.txAudioCh[i].firstAudioChannel;
891  txChannelConfig.audioPktInterval = transmitAudio2110.txAudioCh[i].audioPktInterval;
892 
893  txChannelConfig.channel = transmitAudio2110.txAudioCh[i].channel;
894 
895  rv = config2110.SetTxStreamConfiguration(transmitAudio2110.txAudioCh[i].stream,
896  txChannelConfig);
897  if (!rv)
898  {
899  cerr << "SetTxStreamConfiguration Audio: FAILED: " << config2110.getLastError() << endl;
900  }
901  else
902  {
903  if (transmitAudio2110.txAudioCh[i].enable)
904  {
905  rv = config2110.SetTxStreamEnable(transmitAudio2110.txAudioCh[i].stream,
906  transmitAudio2110.txAudioCh[i].sfpEnable[0],
907  transmitAudio2110.txAudioCh[i].sfpEnable[1]);
908  if (!rv)
909  {
910  cerr << "SetTxStreamEnable Audio: FAILED: " << config2110.getLastError() << endl;
911  }
912  }
913  }
914  }
915 
916  // fetch parsed transmit anc struct
917  TransmitAncData2110 transmitAnc2110 = parse2110.m_transmitAnc2110;
918  for (uint32_t i = 0; i < transmitAnc2110.numTxAncChannels; i++)
919  {
920  cerr << "## transmitAnc " << i+1 << endl;
921 
922  bool rv;
923  txChannelConfig.init();
924 
925  txChannelConfig.localPort[0] = transmitAnc2110.txAncCh[i].localPort[0];
926  txChannelConfig.remoteIP[0] = transmitAnc2110.txAncCh[i].remoteIP[0];
927  txChannelConfig.remotePort[0] = transmitAnc2110.txAncCh[i].remotePort[0];
928  txChannelConfig.localPort[1] = transmitAnc2110.txAncCh[i].localPort[1];
929  txChannelConfig.remoteIP[1] = transmitAnc2110.txAncCh[i].remoteIP[1];
930  txChannelConfig.remotePort[1] = transmitAnc2110.txAncCh[i].remotePort[1];
931 
932  txChannelConfig.payloadType = transmitAnc2110.txAncCh[i].payloadType;
933  txChannelConfig.ssrc = transmitAnc2110.txAncCh[i].ssrc;
934  txChannelConfig.ttl = transmitAnc2110.txAncCh[i].ttl;
935 
936  rv = config2110.SetTxStreamConfiguration(transmitAnc2110.txAncCh[i].stream,
937  txChannelConfig);
938  if (!rv)
939  {
940  cerr << "SetTxStreamConfiguration ANC: FAILED: " << config2110.getLastError() << endl;
941  }
942  else
943  {
944  if (transmitAnc2110.txAncCh[i].enable)
945  {
946  rv = config2110.SetTxStreamEnable(transmitAnc2110.txAncCh[i].stream,
947  transmitAnc2110.txAncCh[i].sfpEnable[0],
948  transmitAnc2110.txAncCh[i].sfpEnable[1]);
949  if (!rv)
950  {
951  cerr << "SetTxStreamEnable ANC: FAILED: " << config2110.getLastError() << endl;
952  }
953  }
954  }
955  }
956 
957 
958  return true;
959 }
960 
961 NTV2Channel getChannel(QString channelDesignator)
962 {
963  NTV2Channel channel = NTV2_CHANNEL1;
964 
965  if ( channelDesignator == "channel2")
966  channel = NTV2_CHANNEL2;
967  else if ( channelDesignator == "channel3")
968  channel = NTV2_CHANNEL3;
969  else if ( channelDesignator == "channel4")
970  channel = NTV2_CHANNEL4;
971 
972  return channel;
973 }
974 
975 bool getEnable(QString enableBoolString)
976 {
977  return (enableBoolString == "true");
978 }
bool setupBoard2022(std::string deviceSpec)
nlohmann::json json
bool readJson2022(const QJsonObject &json)
virtual bool SetReference(const NTV2ReferenceSource inRefSource, const bool inKeepFramePulseSelect=(0))
Sets the device&#39;s clock reference source. See Video Output Clocking & Synchronization for more inform...
bool setupBoard2110(std::string deviceSpec)
ReceiveAncData2110 m_receiveAnc2110
QString mSfp2RemoteIPAddress
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
QList< TransmitStruct2022 > mTransmit2022Channels
Declares the AJATime class.
bool getEnable(QString enableBoolString)
Defines a number of handy byte-swapping macros.
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1359
TransmitAncData2110 m_transmitAnc2110
ReceiveVideoData2110 m_receiveVideo2110
NetworkData2110 m_net2110
Enumerations for controlling NTV2 devices.
virtual bool IsOpen(void) const
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...
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
TransmitAudioData2110 m_transmitAudio2110
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
QString mSfpDesignator
QString mChannelDesignator
QString mSfp2DestIPAddress
Specifies the PTP source on SFP 1.
Definition: ntv2enums.h:1471
Specifies channel or FrameStore 2 (or the 2nd item).
Definition: ntv2enums.h:1362
Declares the CNTV2DeviceScanner class.
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...
NTV2Channel getChannel(QString channelDesignator)
QString mSfp1DestIPAddress
ReceiveAudioData2110 m_receiveAudio2110
QString mSfp1RemoteIPAddress
QString mGateway
Specifies channel or FrameStore 1 (or the first item).
Definition: ntv2enums.h:1361
KonaIP2022ParamSetupStruct mKonaIP2022Params
bool SetJson(const QJsonObject &topObj, bool verbose)
Specifies channel or FrameStore 4 (or the 4th item).
Definition: ntv2enums.h:1364
QList< ReceiveStruct2022 > mReceive2022Channels
This file contains some structures, constants, classes and functions that are used in some of the dem...
virtual bool IsMBSystemValid(void)
QList< SFPStruct > mSFPs
QString mEnable
virtual bool IsMBSystemReady(void)
bool setupBoard(std::string deviceSpec)
#define NTV2EndianSwap32(__val__)
Definition: ntv2endian.h:19
Declares device capability functions.
QString mIPAddress
TransmitVideoData2110 m_transmitVideo2110
Specifies channel or FrameStore 3 (or the 3rd item).
Definition: ntv2enums.h:1363
bool openJson(QString fileName)
QString mSubnetMask