void	InstrumentTest::testInstrument() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testInstrument() begin");
	ConfigurationPtr	config = Configuration::get(dbfilename);
	Database	database = config->database();

	// create an instrument
	Instrument	instrument(database, "BLUBB");

	// add a few components
	InstrumentComponentPtr	camera = InstrumentComponentPtr(
		new InstrumentComponentDirect(DeviceName::Camera,
			DeviceName("camera:simulator/camera"), 7, "localhost"));
	instrument.add(camera);
	InstrumentComponentPtr	ccd = InstrumentComponentPtr(
		new InstrumentComponentDerived(DeviceName::Ccd,
			instrument, DeviceName::Camera, 5));
	instrument.add(ccd);

	// check instrument
	CPPUNIT_ASSERT(instrument.name() == "BLUBB");

	// has method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'has' method");
	CPPUNIT_ASSERT(instrument.has(DeviceName::Camera));
	CPPUNIT_ASSERT(instrument.has(DeviceName::Ccd));

	// component_type method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'component_type' method");
	CPPUNIT_ASSERT(instrument.component_type(DeviceName::Camera)
		== InstrumentComponent::direct);
	CPPUNIT_ASSERT(instrument.component_type(DeviceName::Ccd)
		== InstrumentComponent::derived);

	// devicename method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'devicename' method");
	CPPUNIT_ASSERT(instrument.devicename(DeviceName::Camera)
		== DeviceName("camera:simulator/camera"));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "ccd device: %s",
		instrument.devicename(DeviceName::Ccd).toString().c_str());
	CPPUNIT_ASSERT(instrument.devicename(DeviceName::Ccd)
		== DeviceName("camera:simulator/camera"));

	// name method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'name' method");
	debug(LOG_DEBUG, DEBUG_LOG, 0, "name(camera) = %s",
		instrument.name(DeviceName::Camera).c_str());
	CPPUNIT_ASSERT(instrument.name(DeviceName::Camera)
		== DeviceName("camera:simulator/camera").toString());

	debug(LOG_DEBUG, DEBUG_LOG, 0, "name(ccd) = %s",
		instrument.name(DeviceName::Ccd).c_str());
	CPPUNIT_ASSERT(instrument.name(DeviceName::Ccd) == "camera");

	// unit method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'unit' method");
	CPPUNIT_ASSERT(instrument.unit(DeviceName::Camera) == 7);
	CPPUNIT_ASSERT(instrument.unit(DeviceName::Ccd) == 5);
	
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testInstrument() end");
}
Example #2
0
Alsa9Buf::Alsa9Buf( hw hardware, int channels_ )
{
	GetSoundCardDebugInfo();
		
	InitializeErrorHandler();
	
	channels = channels_;
	samplerate = 44100;
	samplebits = 16;
	last_cursor_pos = 0;
	samplerate_set_explicitly = false;
	preferred_writeahead = 8192;
	preferred_chunksize = 1024;

	/* Open the device. */
	int err;
	err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
	if (err < 0)
		RageException::ThrowNonfatal("dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err));

	if( !SetHWParams() )
	{
		CHECKPOINT;
		dsnd_pcm_close(pcm);
		CHECKPOINT;
		RageException::ThrowNonfatal( "SetHWParams failed" );
	}

	SetSWParams();
}
Example #3
0
int CdromDriverLinux::OpenDrive(memptr device)
{
	int drive;

	drive = GetDrive(device);
	drive = DriveFromLetter(drive);
	
	/* Drive exist ? */
	if (drive < 0 || drive >= CD_MAX_DRIVES || (drives_mask & (1<<drive)) == 0 ||
		DeviceName(drive = bx_options.nfcdroms[drive].physdevtohostdev) == NULL)
	{
		D(bug(NFCD_NAME " physical device %c does not exist", GetDrive(device)));
		return TOS_EUNDEV;
	}

	/* Drive opened ? */
	if (cddrives[drive].handle>=0) {
		return drive;
	}

	/* Open drive */
	cddrives[drive].handle=open(DeviceName(drive), O_RDONLY|O_EXCL|O_NONBLOCK, 0);
	if (cddrives[drive].handle<0) {
		cddrives[drive].handle=-1;
		int errorcode = errnoHost2Mint(errno, TOS_EFILNF);
		D(bug(NFCD_NAME " error opening drive %s: %s", DeviceName(drive), strerror(errno)));
		return errorcode;
	}

	return drive;
}
void	InstrumentTest::testRead() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testRead() begin");
	ConfigurationPtr	config = Configuration::get(dbfilename);
	InstrumentConfigurationPtr	instrumentconfig
		= InstrumentConfiguration::get(config);
	InstrumentPtr	instrument = instrumentconfig->instrument("BLUBB");

	// check instrument
	CPPUNIT_ASSERT(instrument->name() == "BLUBB");

	// has method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'has' method");
	CPPUNIT_ASSERT(instrument->has(DeviceName::Camera));
	CPPUNIT_ASSERT(instrument->has(DeviceName::Ccd));

	// component_type method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'component_type' method");
	CPPUNIT_ASSERT(instrument->component_type(DeviceName::Camera)
		== InstrumentComponent::direct);
	CPPUNIT_ASSERT(instrument->component_type(DeviceName::Ccd)
		== InstrumentComponent::derived);
	CPPUNIT_ASSERT(instrument->component_type(DeviceName::Filterwheel)
		== InstrumentComponent::mapped);

	// devicename method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'devicename' method");
	CPPUNIT_ASSERT(instrument->devicename(DeviceName::Camera)
		== DeviceName("camera:simulator/camera"));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "ccd device: %s",
		instrument->devicename(DeviceName::Ccd).toString().c_str());
	CPPUNIT_ASSERT(instrument->devicename(DeviceName::Ccd)
		== DeviceName("camera:simulator/camera"));
	CPPUNIT_ASSERT(instrument->devicename(DeviceName::Filterwheel).toString()
		== "filterwheel:sx/0");

	// name method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'name' method");
	debug(LOG_DEBUG, DEBUG_LOG, 0, "name(camera) = %s",
		instrument->name(DeviceName::Camera).c_str());
	CPPUNIT_ASSERT(instrument->name(DeviceName::Camera)
		== DeviceName("camera:simulator/camera").toString());

	debug(LOG_DEBUG, DEBUG_LOG, 0, "name(ccd) = %s",
		instrument->name(DeviceName::Ccd).c_str());
	CPPUNIT_ASSERT(instrument->name(DeviceName::Ccd) == "camera");
	CPPUNIT_ASSERT(instrument->name(DeviceName::Filterwheel)
		== "TEST");

	// unit method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'unit' method");
	CPPUNIT_ASSERT(instrument->unit(DeviceName::Camera) == 7);
	CPPUNIT_ASSERT(instrument->unit(DeviceName::Ccd) == 5);
	CPPUNIT_ASSERT(instrument->unit(DeviceName::Filterwheel) == 1291);
	
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testRead() end");
}
SimFilterWheel::SimFilterWheel(SimLocator& locator)
	: FilterWheel(DeviceName("filterwheel:simulator/filterwheel")),
	  _locator(locator) {
	_currentposition = 0;
	_currentstate = FilterWheel::unknown;
	_changetime = Timer::gettime() + 5;
}
SimFocuser::SimFocuser(SimLocator& locator)
	: Focuser(DeviceName("focuser:simulator/focuser")),
	  _locator(locator) {
	_value = /* 10000 + */ (max() + min()) / 2;
debug(LOG_DEBUG, DEBUG_LOG, 0, "focuser set to %d", _value);
	target = _value;
	lastset = 0;
}
void CShdrEchoInstance::Init(std::string devicesxmlfilename, 
									 std::string shdrfilename, 
									 int ipport, 
									 double dOverride,
									 std::string devicename)
{
	DevicesXmlFilename()=devicesxmlfilename;
	ShdrFilename() =shdrfilename;
	IpAddress() ="127.0.0.1"; // really cant be anything else
	IpPort()=ipport;
	DeviceName() = devicename;
	Override()=dOverride;
	_bFaultThread=false;

	if(DevicesXmlFilename().empty())
		DevicesXmlFilename()=ExeDirectory() + "devices.xml";

	_bRepeat=true;

	_backend = new CoComMTCShdrBackEnd();
	_backend->Init(_bstr_t(IpAddress().c_str()), IpPort(), _bstr_t(DeviceName().c_str()));
	_backend->MyLogger().AddListener(boost::bind(&CShdrEchoInstance::EchoShdr, this,_1));

	_dict = _deviceparser.ReadDeviceDescription(DevicesXmlFilename());
	std::string storemap,itemlist, typelist;
	int i=0;
	for(DataDictionary::iterator it = _dict.begin(); it!=_dict.end(); it++, i++)
	{
		if((*it).first.empty())
		{
			i--;
			continue;
		}
		if(i>0) itemlist+=",";
		if(i>0) typelist+=",";
		storemap+=(*it).first+"="+(*it).first+"\n";  // isomorphic: alias = name
		itemlist+=(*it).first;
		typelist+=_dict[(*it).first];
	}
	_backend->StoreTagMap(_bstr_t(storemap.c_str()));
	_backend->StoreTypeMap(_bstr_t(itemlist.c_str()),bstr_t(typelist.c_str()));

	Open();
	_state=Ready;
}
Mock1Camera::Mock1Camera(int _id) : astro::camera::Camera(cameraname(_id)), id(_id) {

	CcdInfo	ccd0(DeviceName(name(), DeviceName::Ccd, "primary ccd"),
		ImageSize(1024, 768), 0);
	ccd0.addMode(Binning(1,1));
	ccd0.pixelwidth(0.00001);
	ccd0.pixelheight(0.00001);
	ccdinfo.push_back(ccd0);

	CcdInfo	ccd1(DeviceName(name(), DeviceName::Ccd, "secondary ccd"),
		ImageSize(640, 480), 1);
	ccd1.addMode(Binning(1,1));
	ccd1.pixelwidth(0.00001);
	ccd1.pixelheight(0.00001);
	ccdinfo.push_back(ccd1);

	debug(LOG_DEBUG, DEBUG_LOG, 0, "mock1 has %d ccds", this->nCcds());
}
/**
 * \brief Name of the device
 *
 * For derived components, this only returns the device name of the
 * parent device, it is the client's responsibilty to retrieve the
 * correct subdevice of the parent device.
 */
DeviceName	InstrumentComponentDerived::devicename() {
	DeviceName	name = _instrument.devicename(_derivedfrom);
	if (type() != DeviceName::Ccd) {
		name.type(type());
		return name;
	} else {
		return DeviceName(name, type(), stringprintf("%d", unit()));
	}
}
Example #10
0
RString Alsa9Buf::Init( int channels_,
		int iWriteahead,
		int iChunkSize,
		int iSampleRate )
{
	channels = channels_;
	preferred_writeahead = iWriteahead;
	preferred_chunksize = iChunkSize;
	if( iSampleRate == 0 )
		samplerate = 44100;
	else
		samplerate = iSampleRate;
	
	GetSoundCardDebugInfo();
		
	InitializeErrorHandler();
	
	/* Open the device. */
	int err;
	err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
	if( err < 0 )
		return ssprintf( "dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err) );

	if( !SetHWParams() )
	{
		CHECKPOINT;
		return "SetHWParams failed";
	}

	SetSWParams();

	LOG->Info( "ALSA: Mixing at %ihz", samplerate );

	if( preferred_writeahead != writeahead )
		LOG->Info( "ALSA: writeahead adjusted from %u to %u", (unsigned) preferred_writeahead, (unsigned) writeahead );
	if( preferred_chunksize != chunksize )
		LOG->Info( "ALSA: chunksize adjusted from %u to %u", (unsigned) preferred_chunksize, (unsigned) chunksize );

	return "";
}
void	InstrumentTest::testSave() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testSave() begin");
	ConfigurationPtr	config = Configuration::get(dbfilename);
	Database	database = config->database();
	DeviceMapperConfigurationPtr	devicemapperconfig
		= DeviceMapperConfiguration::get(config);

	// make sure we have an entry in the device mapper for TEST
	DeviceMapperPtr	devicemapper = devicemapperconfig->devicemapper();
	DeviceMap	mapentry(DeviceName("filterwheel:sx/0"));
	mapentry.name("TEST");
	mapentry.unitid(1291);
	mapentry.description("test filterwheel");
	devicemapper->add(mapentry);

	// create an instrument
	InstrumentPtr	instrument(new Instrument(database, "BLUBB"));

	// add a few components
	InstrumentComponentPtr	camera = InstrumentComponentPtr(
		new InstrumentComponentDirect(DeviceName::Camera,
			DeviceName("camera:simulator/camera"), 7, "localhost"));
	instrument->add(camera);
	InstrumentComponentPtr	ccd = InstrumentComponentPtr(
		new InstrumentComponentDerived(DeviceName::Ccd,
			*instrument, DeviceName::Camera, 5));
	instrument->add(ccd);
	InstrumentComponentPtr	filterwheel = InstrumentComponentPtr(
		new InstrumentComponentMapped(DeviceName::Filterwheel,
			database, "TEST"));
	instrument->add(filterwheel);

	// add the instrument to the database
	InstrumentConfigurationPtr	instrumentconfig
		= InstrumentConfiguration::get(config);
	instrumentconfig->addInstrument(instrument);

	debug(LOG_DEBUG, DEBUG_LOG, 0, "testSave() end");
}
QsiFilterWheel::QsiFilterWheel(QsiCamera& camera)
	: FilterWheel(DeviceName(camera.name(), DeviceName::Filterwheel,
		"filterwheel")),
	  _camera(camera) {
	std::unique_lock<std::recursive_mutex>	lock(_camera.mutex);
	int	filtercount = 0;
	_camera.camera().get_FilterCount(filtercount);
	nfilters = filtercount;
	// retrieve filter names
	std::string	*names = new std::string[nfilters];
	_camera.camera().get_Names(names);
	for (unsigned int index = 0; index < nfilters; index++) {
		filternames.push_back(names[index]);
	}
	delete[] names;
}
DeviceName	InstrumentComponent::remoteName() const {
	// find out whether the name is local or uses the nice module
	bool	useNice = true;

	// if this is already a local name, used unchanged
	if (!useNice) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "using localized name %s",
			_deviceurl.c_str());
		return DeviceName(_deviceurl);
	}

	// this is a remote name, so construct a remote name
	device::nice::DeviceNicer	nicer(_servicename);
	DeviceName	result = nicer(_deviceurl);
	debug(LOG_DEBUG, DEBUG_LOG, 0, "localized name: %s",
		result.toString().c_str());
	return result;
}
Example #14
0
/// Gets the lists of names and lists of labels which are
/// used in the choice controls.
/// The names are what the user sees in the wxChoice.
/// The corresponding labels are what gets stored.
void AudioIOPrefs::GetNamesAndLabels()
{
   // Get lists of devices both for play and record.
   int j;
   wxString Name;
   wxString Label;

#if USE_PORTAUDIO_V19
   int nDevices = Pa_GetDeviceCount();
#else
   int nDevices = Pa_CountDevices();
#endif

   for(j=0; j<nDevices; j++) {
      const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
      Name = DeviceName(info);
      Label = Name;
      if (info->maxOutputChannels > 0) {
         mmPlayNames.Add( Name );
         mmPlayLabels.Add( Label );
      }
      if (info->maxInputChannels > 0) {
         mmRecordNames.Add( Name );
         mmRecordLabels.Add( Label );
      }
   }

   // Channel counts, mono, stereo etc...
   const int numChannels = 16;
   for(int c=0; c<numChannels; c++)
   {
      mmChannelNames.Add(  wxString::Format(wxT("%d"), c+1));
      mmChannelLabels.Add( c+1 );
   }
   mmChannelNames[0] = wxString::Format(_("1 (Mono)"));
   mmChannelNames[1] = wxString::Format(_("2 (Stereo)"));
}
Example #15
0
RString Alsa9Buf::GetHardwareID( RString name )
{
	InitializeErrorHandler();

	if( name.empty() )
		name = DeviceName();
	
	snd_ctl_t *handle;
	int err;
	err = dsnd_ctl_open( &handle, name, 0 );
	if ( err < 0 )
	{
		LOG->Info( "Couldn't open card \"%s\" to get ID: %s", name.c_str(), dsnd_strerror(err) );
		return "???";
	}

	snd_ctl_card_info_t *info;
	dsnd_ctl_card_info_alloca(&info);
	err = dsnd_ctl_card_info( handle, info );
	RString ret = dsnd_ctl_card_info_get_id( info );
	dsnd_ctl_close(handle);

	return ret;
}
Example #16
0
	void TestMemory::DumpStats(std::ostream& out)
	{
		out << DeviceName() << ":EvictionsReceived:" << evictionsReceived << endl;
		out << DeviceName() << ":ReadsReceived:" << readsReceived << endl;
		out << DeviceName() << ":WritessReceived:" << writesReceived << endl;
	}
/**
 * \brief Create the name of the filterwheel
 */
DeviceName	FilterWheel::defaultname(const DeviceName& parent,
			const std::string& unitname) {
	return DeviceName(parent, DeviceName::Filterwheel, unitname);
}
Example #18
0
void DeviceToolBar::Populate()
{
   int i;
   wxArrayString inputs;
   wxArrayString outputs;

#if USE_PORTAUDIO_V19
   int nDevices = Pa_GetDeviceCount();
#else
   int nDevices = Pa_CountDevices();
#endif

   for (i = 0; i < nDevices; i++) {
      const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
      wxString name = DeviceName(info);

      if (info->maxOutputChannels > 0) {
         outputs.Add(name);
      }

      if (info->maxInputChannels > 0) {
         inputs.Add(name);
      }
   }

   wxColour backgroundColour =
      wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);

   // Output device
   mPlayBitmap = new wxBitmap(theTheme.Bitmap(bmpSpeaker));

   Add(new wxStaticBitmap(this,
                          wxID_ANY, 
                          *mPlayBitmap), 0, wxALIGN_CENTER);

   mOutput = new wxChoice(this,
                               wxID_ANY,
                               wxDefaultPosition,
                               wxDefaultSize,
                               outputs);
   mOutput->SetName(_("Output Device"));
#if wxUSE_TOOLTIPS
   mOutput->SetToolTip(_("Output Device"));
#endif
   Add(mOutput, 0, wxALIGN_CENTER);

   if (outputs.GetCount() == 0)
      mOutput->Enable(false);

   // Input device
   mRecordBitmap = new wxBitmap(theTheme.Bitmap(bmpMic));

   Add(new wxStaticBitmap(this,
                          wxID_ANY, 
                          *mRecordBitmap), 0, wxALIGN_CENTER);

   mInput = new wxChoice(this,
                         wxID_ANY,
                         wxDefaultPosition,
                         wxDefaultSize,
                         inputs);
   mInput->SetName(_("Input Device"));
#if wxUSE_TOOLTIPS
   mInput->SetToolTip(_("Input Device"));
#endif
   Add(mInput, 0, wxALIGN_CENTER);

   if (inputs.GetCount() == 0)
      mInput->Enable(false);

   UpdatePrefs();
}
static DeviceName	guideportname(const DeviceName& cameraname) {
	return DeviceName(cameraname, DeviceName::Guideport, "guideport");
}
DeviceName	DeviceName::child(const DeviceName::device_type& devicetype,
			const std::string& unitname) const {
	return DeviceName(*this, devicetype, unitname);
}
/**
 * \brief Create a new Instrument
 */
Instrument::Instrument(Database db, const std::string& name)
	: _database(db), _name(name) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "instrument '%s' constructed",
		name.c_str());

	// get the information from the instruments table
	InstrumentTable	instruments(_database);

	// find out whether there already is an instrument in the table
	int	instrumentid = -1;
	try {
		instrumentid = instruments.id(name);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "instrument already exists");
	} catch (const std::runtime_error& x) {
		debug(LOG_DEBUG, DEBUG_LOG, 0,
			"instrument does not exist, creating one");
		InstrumentRecord        instrumentrecord;
		instrumentrecord.name = name;
		instrumentid = instruments.add(instrumentrecord);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "id of new instrument: %d",
			instrumentid);
	}

	// retrieve all the matching metadata
	InstrumentComponentTable	components(_database);
	std::string	condition = stringprintf("instrument = %d",
						instrumentid);
	auto l = components.select(condition);
	for (auto ptr = l.begin(); ptr != l.end(); ptr++) {
		// find the type from the string version of the type
		DeviceName::device_type	type
			= InstrumentComponentTableAdapter::type(ptr->type);
		InstrumentComponent::component_t	ctype
			= InstrumentComponentTableAdapter::component_type(
				ptr->componenttype);

		// construct suitable InstrumentComponent objects depending
		// on the mapped field of the component record
		InstrumentComponentPtr	iptr;
		switch (ctype) {
		case InstrumentComponent::mapped:
			// in the case of mapped devices, teh device name is
			// not an actuald evie name, but rather the name of
			// the map entry
			iptr = InstrumentComponentPtr(
				new InstrumentComponentMapped(type, _database,
					ptr->devicename));
			break;
		case InstrumentComponent::direct:
			// for direct components, matters are simplest, so
			// all fields have the meaning the name suggest
			iptr = InstrumentComponentPtr(
				new InstrumentComponentDirect(type,
					DeviceName(ptr->devicename),
					ptr->unit, ptr->servername));
			break;
		case InstrumentComponent::derived:
			// in this case, the devicename is really the component
			// type from which the component should be derived
			iptr = InstrumentComponentPtr(
				new InstrumentComponentDerived(type, *this,
					InstrumentComponentTableAdapter::type(
						ptr->devicename),
					ptr->unit));
			break;
		}

		// add the new component
		add(iptr);
	}

	debug(LOG_DEBUG, DEBUG_LOG, 0, "instrument constructed");
}