#!/usr/bin/perl -w

$dev = "/sys/bus/usb/devices";
$detected = 0;

opendir(DIR1, $dev) or die ("Error: " . $dev . " directory not found!");
@files1 = readdir(DIR1);
closedir(DIR1);

foreach $file1 (@files1) 
{
	open(FILE2, "<" . $dev . "/" . $file1 . "/product") or next ;
	$contents1 = readline(FILE2);
	close(FILE2);

	if (index ($contents1, "RigExpert") >= 0)
	{
		print ($contents1);
		
		for ($i=0; $i<2; $i++)
		{
			opendir(DIR2, $dev . "/" . $file1 . ":1." . $i) or next;
			@files2 = grep(/^ttyUSB/,readdir(DIR2));
			closedir(DIR2);

			foreach $file2 (@files2)
			{
				print("\tSerial port " . ($i+1) . ": /dev/" . $file2 . "\n");
				$detected++;
			}
		}
	}

	if (index ($contents1, "USB Audio CODEC") >= 0)
	{
		print ($contents1);

		for ($i=0; $i<10; $i++)
		{
			opendir(DIR3, $dev . "/" . $file1 . ":1.0/sound/card" . $i) or next;
			@files3 = grep(/^dsp/,readdir(DIR3));
			closedir(DIR3);

			foreach $file3 (@files3)
			{
				print("\tAudio device: /dev/" . $file3 . "\n");
				$detected++;
			}
		}
	}

}

if ($detected == 0)
{
	print("No RigExpert devices detected!\n");
}

print("Press Enter to exit...");
until (<STDIN>) {last};

