Wrong number of stimulations delivered by the Acq Server

Come here to discuss about OpenViBE in general!
Post Reply
toncho11
Posts: 124
Joined: Tue Apr 19, 2011 7:58 pm

Wrong number of stimulations delivered by the Acq Server

Post by toncho11 »

Hi,

I am implementing hardware trigger support for the GTEC usb amplifier. My problem is that if I send 500 stimulation with "SetStimulations" method of the AcquistionServer then I get a different output number like: 350. I mean the driver sends 500 and Acqusition server sends 350 to the Designer. Not always - sometimes I just get the right number.

I have disabled the drfit correction, but I still get the wrong number of stimulations leaving the Acq. Server.

I think the code below is problematic. It changes the number of stimulations and before that they seem fine (when drift correction disabled):

File: ovasCAcquisitionServer.cpp
Method: boolean CAcquisitionServer::loop(void)
Position: after
// Eventually builds up buffer and
// sends data to connected client(s)

"start" and "end" added by me for clarity.

Code: Select all

uint64 start = (((m_ui64SampleCount-m_vPendingBuffer.size()                              )+l_rInfo.m_ui64SignalSampleCountToSkip<<32)/m_ui32SamplingFrequency;

uint64 end = (((m_ui64SampleCount-m_vPendingBuffer.size()+m_ui32SampleCountPerSentBlock)+l_rInfo.m_ui64SignalSampleCountToSkip)<<32)/m_ui32SamplingFrequency;
				
OpenViBEToolkit::Tools::StimulationSet::appendRange(
l_oStimulationSet,
m_oPendingStimulationSet,
start,end);
			
OpenViBEToolkit::Tools::StimulationSet::copy(*ip_pStimulationSet, l_oStimulationSet, -int64(l_rInfo.m_ui64StimulationTimeOffset));
Maybe instead of "m_vPendingBuffer.size" it must be m_oPendingStimulationSet.getStimulationCount() when constructing "start" and "end"??
This sounds plausible because when both are the same then this could be the case when I do not have the problem.

What do you think?

-Anton

toncho11
Posts: 124
Joined: Tue Apr 19, 2011 7:58 pm

Re: Wrong number of stimulations delivered by the Acq Server

Post by toncho11 »

And just for reference I have added the code inside the GTEC driver that generates the stimulations. The way the time is generated might be wrong? I mean the "setStimulationDate" part.

Code: Select all

if (TriggerInputEnabled)
					{
						int l_ui32NbStimulations = 0;

						int k= m_oHeader.getChannelCount();//+1 channel
						for(uint32 iSample=0; iSample<m_ui32SampleCountPerSentBlock; iSample++)
						{
							float code = m_pSampleTranspose[iSample*(g_ui32AcquiredChannelCount+1)+k];

							//for debug only
							if (code!=STIMULATION_0 && code!=64) 
								m_rDriverContext.getLogManager() << LogLevel_Error << "Wrong values detected!";
					    
							if ( (code != STIMULATION_0) //the user sends 0 after each stimulatuion to clear it
								  && (code != m_ui32LastStimulation) 
							   )
							{
								m_vStimulationDate[l_ui32NbStimulations] = iSample;
								l_ui32NbStimulations++;
								m_totalNumberParallelPortStimulations++; //for debug
							}

							m_ui32LastStimulation = code;
						}

						if (l_ui32NbStimulations>0) //we detected stimulations
						{
							CStimulationSet   l_oStimulationSet;
							l_oStimulationSet.setStimulationCount(l_ui32NbStimulations);

							for ( OpenViBE::uint32 iStimulation=0; iStimulation < l_ui32NbStimulations; iStimulation++ )
							{
								OpenViBE::uint64 identifier = OVTK_StimulationId_Label_00;
		
								l_oStimulationSet.setStimulationIdentifier(iStimulation, identifier);
								l_oStimulationSet.setStimulationDate(iStimulation, ( uint64(m_vStimulationDate[iStimulation]) << 32) / m_oHeader.getSamplingFrequency());
								l_oStimulationSet.setStimulationDuration(iStimulation, 10);
								m_totalStimsAdded++;
								//std::cout << "Trigger " << std::hex << m_vStimulationIdentifier[iStimulation] << " ";
							}

							if (l_oStimulationSet.getStimulationCount()!=l_ui32NbStimulations)
							  m_rDriverContext.getLogManager() << LogLevel_Info << "Stim count problem: " << l_oStimulationSet.getStimulationCount() << "\n";
						
							m_pCallback->setStimulationSet(l_oStimulationSet);
						}
						//End process trigger stimulations 
					}

					m_pCallback->setSamples(m_pSample);
					
					m_rDriverContext.correctDriftSampleCount(m_rDriverContext.getSuggestedDriftCorrectionSampleCount()); 

Post Reply