User Tools

Site Tools


tvr0tator.c

tvr0tator.c

/* Licensed under CC0 1.0 Universal (CC0 1.0)
 * by andy (andy_@jabber.ccc.de)
 * see http://r0ket.badge.events.ccc.de/r0ketlauncher
 */

#include <usb.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <string.h>

usb_dev_handle* launcher;
pid_t pID;

int send_message(char* msg, int index)
{
	int i = 0, j;
	j = usb_control_msg(launcher, 0x21, 0x9, 0x200, index, msg, 8, 1000);
	memset(msg, 0, 8);

	return j;
}

void movement_handler(char control)
{
	/* grabbed from http://www.amctrl.com/rocketlauncher.html */
	int deally;
	char msg[8];
	memset(msg, 0, 8);

	deally = send_message(msg, 1);
	msg[0] = control;
	deally = send_message(msg, 0);
	deally = send_message(msg, 1);

}

void bye()
{
	kill(pID, SIGTERM);
	usb_close(launcher);
	usb_release_interface(launcher, 0);
}

int main( int argc, const char* argv[] )
{
	struct usb_bus *busses, *bus;
	struct usb_device *dev;
	FILE *fpipe;
	char line[256];
	const char *command = "dvbsnoop -pd 2 -n 1 -s signal | grep Sig | sed 's/Sig: \\([0-9]*\\).*/\\1/'";
	int claimed, maxsignal = 0;

	usb_init();
	usb_find_busses();
	usb_find_devices();

	busses = usb_get_busses();

	for (bus = busses; bus; bus = bus->next)
	{
		for (dev = bus->devices; dev; dev = dev->next)
		{
			if (dev->descriptor.idVendor == 0x0a81)
			{
				printf("found r0ketlauncher!");
				goto _goon;
			}
		}
	}
	printf("r0ketlauncher not found :(");
	exit(0);
	_goon:
	atexit(bye);
	launcher = usb_open(dev);
	claimed = usb_claim_interface(launcher, 0);
	if(claimed == EBUSY)
	{
		printf("Claim of USB r0cket failed, maybe wrong permissions or pedobear alias generic-usb module rapes it");
		exit(0);
	}

	printf("found r0ketlauncher, be shure to turn on your DVB Viewer :)");

	pID = fork();
	if (pID == 0) {
		while(1)
		{
			fpipe = (FILE*)popen(command,"r");
			if(!fpipe)
			{
				fprintf(stderr, "failed executing %s", command);
				sleep(5);
				continue;
			}
			fgets(line, sizeof line, fpipe);
			fclose(fpipe);

			if(maxsignal > atoi(line))
			{
				movement_handler((rand() % 2 > 0) ? 4 : 8);
				sleep(rand() % 3);
				movement_handler(1);
			}
			else
			{
				maxsignal = atoi(line);
				sleep(10);
			}
			sleep(4);

		}
	} else {
		wait(NULL);
	}
}
tvr0tator.c.txt · Last modified: 2011/12/30 13:15 by andy

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki