Writing device drivers in Linux: A brief tutorial
Contingut
Referències, llibres
Un llibre sobre programació de drivers a Linux: LInux Device Drivers 3d Ed:
És la 3a edició del llibre que cobreix el kernel 2.6
Understanding the Linux Kernel:
Driver per al port paral.le.
Aquest article és una introducció a la programacié de drivers a Linux per a dispositius hardware (concretament un port paral.lel)
Creo els fitxers nothing.c i Makefile en el directori /usr/src/linux-headers-2.6.28-11-generic/pwd, doncs el make li dic on ha de buscar el Makefile:
$ make -C /usr/src/linux-headers-2.6.28-11-generic M=pwd modules
opció -C:
-C dir, --directory=dir Change to directory dir before reading the makefiles or doing any‐ thing else.
# make -C /usr/src/linux-headers-2.6.28-11-generic M=pwd modules make: se ingresa al directorio `/usr/src/linux-headers-2.6.28-11-generic' CC [M] pwd/nothing.o Building modules, stage 2. MODPOST 1 modules CC pwd/nothing.mod.o LD [M] pwd/nothing.ko make: se sale del directorio `/usr/src/linux-headers-2.6.28-11-generic'
S'ha creat tota una sèrie de fitxers, entre els quals nothing.ko i nothing.o
INSMOD(8) INSMOD(8) NAME insmod - simple program to insert a module into the Linux Kernel SYNOPSIS insmod [ filename ] [ module options ... ]
carreguel el mòdul en el linux kernel:
# cd /usr/src/linux-headers-2.6.28-11-generic/pwd # insmod nothing.ko # lsmod | grep nothing nothing 9088 0
i elimino el mòdul del Linux Kernel
# rmmod nothing
He carregat i descarregat un mòdul que no fa res.
exemple hello.c
compilem igual que abans
$ insmod hello.ko
comprovem que s'ha carregat el mòdul amb lsmod, i mirem els missatges que s'han produït en el log de dues maneres:
$ cat /var/log/syslog ... Feb 24 16:30:28 ubuntu-bbdd kernel: [ 3189.090368] Hello world! $ dmesg ... [ 3189.090368] Hello world!
exemple memory
# mknod /dev/memory c 60 0
In the above, c means that a char device is to be created, 60 is the major number and 0 is the minor number.
En el fitxer memory.c, he comentat la línia //#include <linux/config.h> que em donava problemes en el moment de la compilació.
# insmod memory.ko
It’s also convenient to unprotect the device:
# chmod 666 /dev/memory
If everything went well, you will have a device /dev/memory to which you can write a string of characters and it will store the last one of them. You can perform the operation like this:
$ echo -n abcdef >/dev/memory
To check the content of the device you can use a simple cat:
$ cat /dev/memory f
Exemple ParlelPort: cas real de fer un driver que treballi amb el port paral.lel
# cat /proc/ioports | grep 378 0378-037a : parport0
compilo com abans, i carrego el mòdul en el kernel
# insmod parlelport.ko # lsmod | grep parlelport parlelport 10116 0 # cat /var/log/syslog Feb 24 17:11:07 ubuntu-bbdd kernel: [ 5627.971102] Inserting parlelport module
Per enviar un byte al port paral.lel:
$ echo -n A >/dev/parlelport
això ha d'encendre els LEDs 0 i 6è (o 1r i 7è, depèn de com es miri). I com és això el caràcter 'A' en el codi ASCII és el 65 (Dec) o 41 (Hex), que equival a 1000001 i també puc llegir la informació:
$ cat /dev/parlelport
hem de fer un petit array de LEDs per comprovar que funciona.
I ara ja tenim fet el driver, podem construir les nostres aplicacions que utilitzin aquest driver. Final application: flashing lights
$ gcc -o lights lights.c
USB missile launcher
1a prova (no funciona)
Writing a Linux kernel driver for an unknown USB device: DreamCheeky USB missile launcher
- http://www.thinkgeek.com/geektoys/warfare/8a0f/
- http://www.lukecole.name/research_and_projects/personal/usb_missile_launcher/
- http://matthias.vallentin.net/2007/04/writing-linux-kernel-driver-for-unknown.html (ben explicat)
És un projecte que està a Sourceforge
$ make CC USBMissileLauncherUtils.o En el fichero incluído de USBMissileLauncherUtils.c:40: USBMissileLauncher.h:37:17: error: usb.h: No existe el fichero ó directorio make: *** [USBMissileLauncherUtils.o] Error 1 $ sudo apt-get install libusb-dev i ara sí $ make $ sudo make install
compila i s'instal.la bé, ha de funcionar sense problemes. Esperant que arribi... Imprimeixo el codi i es pot seguir bastant bé.
2a prova (quasi funciona)
segueixo:
$ lsusb -v ... Bus 005 Device 002: ID 0a81:0701 Chesen Electronics Corp. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x0a81 Chesen Electronics Corp. idProduct 0x0701 bcdDevice 0.01 iManufacturer 1 Dream Link iProduct 2 USB Missile Launcher v1.0 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 34 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xa0 (Bus Powered) Remote Wakeup MaxPower 100mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 No Subclass bInterfaceProtocol 0 None iInterface 0 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.00 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 52 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0001 1x 1 bytes bInterval 20 Device Status: 0x0000 (Bus Powered)
i fixem-nos que:
idVendor 0x0a81 Chesen Electronics Corp. idProduct 0x0701
això ho he de canviar en el fitxer ml_driver.c: Descarrego el codi:
$ svn checkout http://mavam.googlecode.com/svn/trunk/ mavam-read-only
i compilo però dóna un error:
$ make scripts/Makefile.build:46: *** CFLAGS was changed in "/home/joan/ml-driver/hola/mavam-read-only/ml-driver/Makefile". Fix it to use EXTRA_CFLAGS. Alto.
Cercant per google trobo la solució:
$ sudo joe /usr/src/linux-headers-2.6.28-11-generic/scripts/Makefile.build Delete -> ---------------------------------------------------------------------------------------------------------------------------- # If the save-* variables changed error out ifeq ($(KBUILD_NOPEDANTIC),) ifneq ("$(save-cflags)","$(CFLAGS)") $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS) endif endif ---------------------------------------------------------------------------------------------------------------------------- Save
i ara ja compila
i es generen els fitxers del driver:
$ ls -la total 172 drwxrwxrwx 4 joan joan 4096 2011-05-18 18:45 . drwxrwxrwx 5 joan joan 4096 2011-05-18 17:32 .. -rwxrwxrwx 1 joan joan 49 2011-05-18 17:32 AUTHORS -rwxrwxrwx 1 joan joan 131 2011-05-18 17:32 ChangeLog -rwxrwxrwx 1 joan joan 775 2011-05-18 17:32 INSTALL -rwxrwxrwx 1 joan joan 401 2011-05-18 17:41 Makefile -rwxrwxrwx 1 joan joan 15755 2011-05-18 17:32 ml_driver.c -rw-r--r-- 1 joan joan 23027 2011-05-18 18:45 ml_driver.ko -rw-r--r-- 1 joan joan 302 2011-05-18 18:45 .ml_driver.ko.cmd -rw-r--r-- 1 joan joan 1552 2011-05-18 18:45 ml_driver.mod.c -rw-r--r-- 1 joan joan 11744 2011-05-18 18:45 ml_driver.mod.o -rw-r--r-- 1 joan joan 19322 2011-05-18 18:45 .ml_driver.mod.o.cmd -rw-r--r-- 1 joan joan 11968 2011-05-18 18:45 ml_driver.o -rw-r--r-- 1 joan joan 26421 2011-05-18 18:45 .ml_driver.o.cmd -rwxrwxrwx 1 joan joan 640 2011-05-18 17:32 ml_manage.sh -rw-r--r-- 1 joan joan 0 2011-05-18 18:45 Module.markers -rw-r--r-- 1 joan joan 72 2011-05-18 18:45 modules.order -rw-r--r-- 1 joan joan 0 2011-05-18 18:45 Module.symvers -rwxrwxrwx 1 joan joan 429 2011-05-18 17:32 README drwxrwxrwx 6 joan joan 4096 2011-05-18 17:32 .svn drwxrwxrwx 2 joan joan 4096 2011-05-18 18:45 .tmp_versions -rwxrwxrwx 1 joan joan 2221 2011-05-18 17:32 user-space.c -rwxrwxrwx 1 joan joan 6 2011-05-18 17:32 VERSION
abans hem de crear el grup wheel, i afegir el nostre usuari a aquest grup.
$ sudo ./ml_manage.sh load (també es pot fer unload) mknod -m 664 /dev/ml0 c 189 0 mknod -m 664 /dev/ml1 c 189 1 mknod -m 664 /dev/ml2 c 189 2 mknod -m 664 /dev/ml3 c 189 3 chgrp: grupo inválido «wheel» chgrp ${group} /dev/${device}[0-3] sudo chgrp wheel /dev/ml0 sudo chgrp wheel /dev/ml1 sudo chgrp wheel /dev/ml2 sudo chgrp wheel /dev/ml3
Comprovem els missatges del sistema:
$ dmesg [185521.655507] usbcore: registered new interface driver missile_launcher [185521.655835] [info] usb_ml_init(646): driver registered successfully
Ara compilo l'apliació de prova:
$ gcc -o ml_control user-space.c
de moment no funciona:
$ sudo ./ml_control -l could not send command to -1
desconnecto i torno a connectar:
$ dmesg [186325.048074] usb 5-1: USB disconnect, address 2 [186327.672021] usb 5-1: new low speed USB device using uhci_hcd and address 3 [186327.849524] usb 5-1: configuration #1 chosen from 1 choice [186327.875253] generic-usb 0003:0A81:0701.0003: hiddev96,hidraw1: USB HID v1.00 Device [Dream Link USB Missile Launcher v1.0] on usb-0000:00:1d.3-1/input0
però estem igual.
El problema està en què aquest codi no utilitza la llibreria libusb, sinó que programa un mòdul del kernel directament per al dispositiu. Ara bé, jo no sé com desinstal.lar/deshabilitar el libusb sense que tot se'n vagi al garete, doncs eliminar el paquet libusb desinstal.la moltíssimes coses.
3a prova: launcher (de moment no funciona)
És un link dels proposats per Mathias Valentin a Related Work (*http://matthias.vallentin.net/2007/04/writing-linux-kernel-driver-for-unknown.html)
El problema està en què està molt mal documentat.
$ ./configure $ make $ sudo make install
Ja sé compilar el programes que estan a src/test, com per exemple fire.c:
$ make clean (si cal) $ make fire
Les comandes que genera el make i que fan compilar fire.c són:
gcc -DHAVE_CONFIG_H -I. -I. -I../../src/include -g -O2 -MT fire.o -MD -MP -MF ".deps/fire.Tpo" -c -o fire.o fire.c; gcc -g -O2 -o fire fire.o ../../src/lib/liblauncher.a
$ ./fire --help Failed to open device '/dev/usb/hiddev0': No such device or address (6)
ho provo com a joan sense sudo i amb sudo, i com a root, però sempre obtinc el mateix missatge.
# ls -la /dev/usb/hiddev0 crw-rw---- 1 root root 180, 96 2011-05-23 13:13 /dev/usb/hiddev0
Però això pot ser perquè no he actualitzat el id_vendor del dispositiu.
$ make calibrate $ make control $ make enum $ make fire $ make status
Però fixem-nos:
Amb el Rocket Launcher desconnectat:
# ./enum Failed to enumerate devices: No such file or directory (2)
Amb el Rocket Launcher connectat:
# ./enum /dev/usb/hiddev0: Unknown Device
Per tant no el troba, i és lógic doncs el id_vendor i id_product encara estan malament, no els he canviat per a la nova versió.
$ ./fire Failed to open device '/dev/usb/hiddev0': No such file or directory (2)
$ find /home/joan/launcher-1.0 -type f -print | xargs egrep -i 1941
la informació del id_vendor està en la línia 35 del fitxer src/lib/device.c. Canvio
if ((info.vendor & 0xFFFF) == 0x1941 && (info.product & 0xFFFF) == 0x8021)
per
if ((info.vendor & 0xFFFF) == 0x0a81 && (info.product & 0xFFFF) == 0x0701)
instal.lo libhid-dev i libhid0, doncs com es comenta en el README, The library uses the USB HID API of the operating system for hardware access.
Si ens fixem en la sortida de enum no s'ha arreglat res, però si veiem la sortida de fire ara veiem que sí que ha detectat el dispositiu. Tanmateix, encara no funciona. Hi ha la possibilitat de que els missatges que dóna la versió nova i la versió vella del dispositiu siguin diferents.
# ./enum /dev/usb/hiddev0: Unknown Device
# ./fire Setting feedback... Failed to get 1: Invalid argument (22) Failed to set feedback '/dev/usb/hiddev0': Invalid argument (22) Failed to send 1: Invalid argument (22)
4a prova: ahmissile (funciona, amb libusb)
És un link dels proposats per Mathias Valentin a Related Work (*http://matthias.vallentin.net/2007/04/writing-linux-kernel-driver-for-unknown.html)
llegim en el README
lsusb vendor/device id example for supported device: Bus 001 Device 013: ID 1941:8021 Dream Cheeky USB Missile Launcher Since version 0.5 the new model (which looks identical) is also supported thanks to Philipp Stern <info@getdigital.de> who sent me one: Bus 002 Device 049: ID 0a81:0701 Chesen Electronics Corp.
i efectivament, aquest és el nostre model, per tant segur que ha de funcionar.
Dependencies: libusb (http://libusb.sf.net) GTK+ (http://www.gtk.org) Current status: - basic movement (up, down, left, right, fire) works. - basic safety implemented (stop when reaching max position). - tested on Debian GNU/Linux Unstable AMD64 (and older versions on Debian GNU/Linux 4.0 Etch PowerPC). - Device gets claimed by the kernel usbhid driver, try running this program as root if you have problems to give it permissions to detach the attached drivers on startup. See example udev rules in contrib/ to get permissions to the missile launcher as a regular user. TODO: The program is not actively developed. Here's a list of things that I've thought would be nice to have but will probably not implement. The main reason this exists is to not forget the ideas, or if someone else wants to have ideas for patches that I'd be happy if I received. :) == core == - find out how to *reliably* poll the device (tested only on old device, maybe the new one can be polled without problem) to detect and stop the fire sequence as soon as an arrow has been fired instead of just sleeping until a timeout is triggered. - Robustness fixes. . Cache max positions to avoid triggering tiny movements again and again after reaching a max position. . Handle usb message errors (sleep to await recovery? retry?). - implement "goto-fixed-position" (maxleft, maxtop, ...). - implement "reset". == interface == - add nice dialog for when attaching/claiming device fails. - make it possible to record commands and then play them back. - add posibility to go to fixed positions like "top left corner" - add sound effects playback function. == not (currently) planned == - implement support for multiple missile launchers. - restructure into a true missile-control backend library. - implement web interface. - implement motion-sensoring webcam.
Instal.lem sense problemes:
$ ./configure $ make $ sudo make install
ara endollem el Missile Launcher:
$ dmesg [ 1664.108752] usb 2-1.1: new low speed USB device using ehci_hcd and address 4 [ 1664.224301] usb 2-1.1: configuration #1 chosen from 1 choice [ 1664.227825] generic-usb 0003:0A81:0701.0002: hiddev96,hidraw1: USB HID v1.00 Device [Dream Link USB Missile Launcher v1.0] on usb-0000:00:1d.0-1.1/input0
El problema és que l'aplicació no és molt fina, i només em mostra una interfície gràfica (GTK). No és una aplicació de consola. Per la qual cosa d'entrada és difícil crear front-ends nous. S'hauria de reprogramar per extreure'n només una funcionalitat de consola.
Ara bé, almenys funciona.
destripant ahmissile
del make es dedueix les següent instruccions per compilar:
generem main.o gcc -DHAVE_CONFIG_H -I. -I. -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -DPACKAGE_LOCALE_DIR=\""/usr/local/share/locale"\" -pthread -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -g -O2 -MT main.o -MD -MP -MF ".deps/main.Tpo" -c -o main.o main.c generem support.o gcc -DHAVE_CONFIG_H -I. -I. -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -DPACKAGE_LOCALE_DIR=\""/usr/local/share/locale"\" -pthread -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -g -O2 -MT support.o -MD -MP -MF ".deps/support.Tpo" -c -o support.o support.c generem interface.o gcc -DHAVE_CONFIG_H -I. -I. -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -DPACKAGE_LOCALE_DIR=\""/usr/local/share/locale"\" -pthread -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -g -O2 -MT interface.o -MD -MP -MF ".deps/interface.Tpo" -c -o interface.o interface.c generem callbacks.o gcc -DHAVE_CONFIG_H -I. -I. -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -DPACKAGE_LOCALE_DIR=\""/usr/local/share/locale"\" -pthread -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -g -O2 -MT callbacks.o -MD -MP -MF ".deps/callbacks.Tpo" -c -o callbacks.o callbacks.c genereme ahmissile.o gcc -DHAVE_CONFIG_H -I. -I. -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -DPACKAGE_LOCALE_DIR=\""/usr/local/share/locale"\" -pthread -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -g -O2 -MT ahmissile.o -MD -MP -MF ".deps/ahmissile.Tpo" -c -o ahmissile.o ahmissile.c; generem usbhelper.o gcc -DHAVE_CONFIG_H -I. -I. -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -DPACKAGE_LOCALE_DIR=\""/usr/local/share/locale"\" -pthread -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -g -O2 -MT usbhelper.o -MD -MP -MF ".deps/usbhelper.Tpo" -c -o usbhelper.o usbhelper.c generem l'executable ahmissile gcc -g -O2 -o ahmissile main.o support.o interface.o callbacks.o ahmissile.o usbhelper.o -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lusb
Interfície web per al USB Missile Launcher
També es pot programar amb python:
i en aquest projecte hi ha el fitxer missile.php on es veu clarament com des d'una pàgina web s'executa un fitxer python. Per tant, des de PHP també podem executar l'aplicatiu USBMissileLauncherUtils.
missile.php:
<!-- Chris -christopherrowson (at) gmail.com You are free to copy, modify or build upon this work, but you must keep this statement intact. I take no responsibility for the way in which you use this code, or any damage it may cause to you, your system or anyone else. By using it you agree that it is provided as is without any implied fitness for purpose --> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>missile</title> </head> <body> <table style="width: 200px; text-align: left;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="vertical-align: top;"><br> </td> <td style="vertical-align: top; text-align: center;"><a href="/missile.php?cmd=up"><img alt="up" src="/images/arrowup.png" style="border: 0px solid ; width: 80px; height: 78px;"></a><br> </td> <td style="vertical-align: top;"><br> </td> <td style="vertical-align: top;"><br> </td> <td style="vertical-align: top;"><br> </td> </tr> <tr> <td style="vertical-align: top;"><a href="/missile.php?cmd=left"><img alt="left" src="/images/arrowleft.png" style="border: 0px solid ; width: 80px; height: 82px;"></a><br> </td> <td style="vertical-align: top; text-align: center;"><a href="/missile.php?cmd=stop"><img alt="stop" src="/images/stop.png" style="border: 0px solid ; width: 80px; height: 80px;"></a><br> </td> <td style="vertical-align: top;"><a href="/missile.php?cmd=right"><img alt="right" src="/images/arrowright.png" style="border: 0px solid ; width: 80px; height: 82px;"></a><br> </td> <td style="vertical-align: top;"><br> </td> <td style="vertical-align: top;"><a href="/missile.php?cmd=fire"><img alt="fire" src="images/circle.png" style="border: 0px solid ; width: 80px; height: 80px;"></a><br> </td> </tr> <tr> <td style="vertical-align: top;"><br> </td> <td style="vertical-align: top; text-align: center;"><a href="/missile.php?cmd=down"><img alt="down" src="/images/arrowdown.png" style="border: 0px solid ; width: 80px; height: 78px;"></a><br> </td> <td style="vertical-align: top;"><br> </td> <td style="vertical-align: top;"><br> </td> <td style="vertical-align: top;"><br> </td> </tr> </tbody> </table> <br> </body> </html> <?php // This code takes input from a webpage a passes it to the up.py perl script. The up.py perl script then sends an argument to the usb-missile-launcher controller perl script on a remote machine via the UDP network protocol. // Defines the switch to be used and which functions to call when a command is passed. switch($_REQUEST['cmd']) { case "up": up(); break; case "down": down(); break; case "left": left(); break; case "right": right(); break; case "stop": stop(); break; case "fire": fire(); break; } // Functions defining which command to execute. In this case the command is passed to the perl script telling it which command to send to the usb-missile-launcher controller. function up() { echo exec('./up.py w'); } function left() { echo exec('./up.py a'); } function right() { echo exec('./up.py d'); } function down() { echo exec('./up.py x'); } function stop() { echo exec('./up.py s'); } function fire() { echo exec('./up.py f'); } ?>
creat per Joan Quintana Compte, febrer 2011, maig 2011