Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

WCFUtils.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //////////////////////////////////////////////////////////////////////
  2. //
  3. // (c) Copyright 2012-2013 Blackrock Microsystems
  4. //
  5. // $Workfile: WCFUtils.cpp $
  6. // $Archive: /Cerebus/Human/WindowsApps/cbhwlib/WCFUtils.cpp $
  7. // $Revision: 1 $
  8. // $Date: 9/10/12 4:0p $
  9. // $Author: Ehsan $
  10. //
  11. // $NoKeywords: $
  12. //
  13. //////////////////////////////////////////////////////////////////////
  14. #include "StdAfx.h"
  15. #include "WCFUtils.h"
  16. #include "cbhwlib.h"
  17. #include "debugmacs.h"
  18. #include "CCFUtilsXmlItems.h"
  19. #include "CCFUtilsXmlItemsGenerate.h"
  20. #include "CCFUtilsXmlItemsParse.h"
  21. #include "../CentralCommon/BmiVersion.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char THIS_FILE[]=__FILE__;
  25. #endif
  26. using namespace ccf;
  27. // Author & Date: Ehsan Azar 10 Sept 2012
  28. // Purpose: WCF base constructor
  29. WCFUtils::WCFUtils(bool bThreaded, UINT32 nInstance) :
  30. m_bThreaded(bThreaded), m_nInstance(nInstance)
  31. {
  32. }
  33. // Author & Date: Ehsan Azar 10 Sept 2012
  34. // Purpose: CCF base destructor
  35. WCFUtils::~WCFUtils()
  36. {
  37. }
  38. // Author & Date: Ehsan Azar 10 Sept 2012
  39. // Purpose: Read and send the given configuration to NSP
  40. // Inputs:
  41. // szFileName - the name of the file to write
  42. // channel - the channel apply waveform agaisnt
  43. int WCFUtils::SendWCF(LPCSTR szFileName, UINT16 channel)
  44. {
  45. ccfResult res = CCFRESULT_SUCCESS;
  46. m_szFileName = szFileName;
  47. QString strFilename = QString(szFileName);
  48. XmlFile xml(strFilename, true);
  49. xml.beginGroup("WCF");
  50. {
  51. // TODO: check protocol version
  52. {
  53. cbPKT_AOUT_WAVEFORM isWaveform[cbMAX_AOUT_TRIGGER];
  54. memset(isWaveform, 0, sizeof(isWaveform));
  55. ccf::ReadItem(&xml, isWaveform, cbMAX_AOUT_TRIGGER, "Waveforms/Waveform");
  56. bool bAnyWave = false;
  57. for (int i = 0; i < cbMAX_AOUT_TRIGGER; ++i)
  58. {
  59. if (isWaveform[i].chan)
  60. {
  61. bAnyWave = true;
  62. isWaveform[i].type |= 0x80;
  63. // Overwrite the written channel with channel we want to apply waveorm to
  64. isWaveform[i].chan = channel;
  65. cbSendPacket(&isWaveform[i]);
  66. }
  67. }
  68. if (bAnyWave)
  69. {
  70. UINT32 dwOptions;
  71. UINT32 nMonitoredChan;
  72. cbRESULT cbres = cbGetAoutOptions(channel, &dwOptions, &nMonitoredChan, NULL, m_nInstance);
  73. // Also make sure channel is to output waveform
  74. dwOptions &= ~(cbAOUT_MONITORSMP | cbAOUT_MONITORSPK);
  75. dwOptions |= cbAOUT_WAVEFORM;
  76. // Set monitoring option
  77. cbres = cbSetAoutOptions(channel, dwOptions, nMonitoredChan, 0, m_nInstance);
  78. }
  79. }
  80. }
  81. xml.endGroup(false); // CCF
  82. return 0;
  83. }
  84. // Author & Date: Ehsan Azar 10 Sept 2012
  85. // Purpose: Write out a WCF file. Overwrite any other file by this name.
  86. // Do NOT prompt for the file to write out.
  87. // Inputs:
  88. // szFileName - the name of the file to write
  89. // channel - the channel read waveform from
  90. int WCFUtils::WriteWCFNoPrompt(LPCSTR szFileName, UINT16 channel)
  91. {
  92. QString strFilename = QString(szFileName);
  93. m_szFileName = szFileName;
  94. QVariantList lst;
  95. if (channel <= cbFIRST_ANAOUT_CHAN)
  96. return -1;
  97. channel -= (cbFIRST_ANAOUT_CHAN + 1); // make it 0-based
  98. if (channel >= AOUT_NUM_GAIN_CHANS)
  99. return -1;
  100. cbPKT_AOUT_WAVEFORM isWaveform[cbMAX_AOUT_TRIGGER];
  101. UINT32 nIdx = cb_library_index[m_nInstance];
  102. memcpy(isWaveform, cb_cfg_buffer_ptr[nIdx]->isWaveform[channel], sizeof(isWaveform));
  103. // Unset triggered state, so that when loading it does not start generating waveform
  104. for (int i = 0; i < cbMAX_AOUT_TRIGGER; ++i)
  105. isWaveform[i].active = 0;
  106. lst += GetCCFXmlItem(isWaveform, cbMAX_AOUT_TRIGGER, "Waveforms/Waveform");
  107. // get computer name
  108. char szUsername[256];
  109. #ifdef WIN32
  110. DWORD cchBuff = sizeof(szUsername);
  111. GetComputerNameA(szUsername, &cchBuff) ; // get the computer name with NeuroMotive running
  112. #else
  113. strncpy(szUsername, getenv("HOSTNAME"), sizeof(szUsername));
  114. #endif
  115. XmlFile xml(strFilename, false);
  116. xml.beginGroup("WCF", "Version", WCF_XML_VERSION, lst);
  117. {
  118. // Session information
  119. xml.beginGroup("Session");
  120. {
  121. xml.beginGroup("Version");
  122. {
  123. xml.addGroup("Protocol", "", 0, QString("%1.%2").arg(cbVERSION_MAJOR).arg(cbVERSION_MINOR));
  124. xml.addGroup("Cerebus", "", 0, QString(BMI_VERSION_STR));
  125. cbPROCINFO isInfo;
  126. cbRESULT cbRet = cbGetProcInfo(cbNSP1, &isInfo, m_nInstance);
  127. if (cbRet == cbRESULT_OK)
  128. {
  129. int nspmajor = (isInfo.idcode & 0x000000ff);
  130. int nspminor = (isInfo.idcode & 0x0000ff00) >> 8;
  131. int nsprelease = (isInfo.idcode & 0x00ff0000) >> 16;
  132. int nspbeta = (isInfo.idcode & 0xff000000) >> 24;
  133. QString strBeta = ".";
  134. if (nspbeta)
  135. strBeta = " Beta ";
  136. xml.addGroup("NSP", "", 0, QString("%1.%2.%3" + strBeta + "%4")
  137. .arg(nspmajor)
  138. .arg(nspminor, 2, 10, QLatin1Char('0'))
  139. .arg(nsprelease, 2, 10, QLatin1Char('0'))
  140. .arg(nspbeta, 2, 10, QLatin1Char('0')));
  141. xml.addGroup("ID", "", 0, QString(isInfo.ident));
  142. }
  143. }
  144. xml.endGroup(); // Version
  145. xml.addGroup("Author", "", 0, szUsername);
  146. xml.addGroup("Date", "", 0, QDateTime::currentDateTime());
  147. }
  148. xml.endGroup(); // Session
  149. }
  150. bool bRes = xml.endGroup(true);
  151. if (bRes)
  152. return -1;
  153. return 0;
  154. }