Title: Alternate User Interfaces
1Alternate User Interfaces
2User Interfaces
- Traditional User Interfaces for Devices
- Allow the user control of/over the internal state
of the device - Buttons/Keys
- Lamps, LEDs, LCD panels
- Knobs, sliders
- On devices with embedded microcontrollers this
can also be done via a web based user Interface
(web page)?
3Common Gateway Interface
- A specification that describes how a web server
exchanges data with a web program - How data from a web form is sent to a web server
- What the web server does with the data
- How the web server activates a specific program
- How the program gets the user data and how it
responds - http//hoohoo.ncsa.uiuc.edu/cgi/
4CGI
- Standard HTTP used
- can use GET or POST methods to send data
- GET sends data (as name/value pairs) attached to
URL - POST send data (as name/value pairs) in the HTTP
body - Server will receive the request packet and place
the data in an environment variable called
QUERYSTRING and place it in SYSIN so that it can
be retrieved by the processing program - SYSOUT is connected to the outgoing socket of the
web server so that whatever is sent to sysout
will go back as the body of the response packet
(this could be a subsequent web page or just a
positive response)?
5Pictorially
Browser
Request Packet
SYSIN
Web Server
C Program
SYSOUT
Response Packet
6cgipio.c
/ This program is free software you can
redistribute it and/or modify it under the
terms of the GNU General Public License version 2
as published by the Free Software Foundation.
/ include ltstdio.hgt include lterrno.hgt include
ltfcntl.hgt include ltstring.hgt include
ltunistd.hgt define BUFFERSIZE 257 define
LED_OFFSET 19 int main(int argc, char
argv)? int i 0 int pio 0 int retval
0 int toggle 0 int led_on -1 int
read_bytes 0 unsigned int pio_buffer char
bufferBUFFERSIZE / Read in stuff from
stdinn / while ((i read(0, buffer,
BUFFERSIZE-1)) ! 0) read_bytes
i bufferread_bytes '\0' if(strstr(buff
er, "toggle1") ! 0) toggle 1
7(cont.)?
/ Print basic headers / printf("HTTP/1.0 200
OK\n") printf("Content-type text/html\n\n") p
rintf( "lt?xml version\"1.0\"
encoding\"utf-8\"?gt\n" "lt!DOCTYPE html PUBLIC
\"-//W3C//DTD XHTML 1.1//EN\" \"http//www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd\"gt\n" "lthtml
xmlns\"http//www.w3.org/1999/xhtml\"gt\n" "ltli
nk rel\"stylesheet\" type\"text/css\"
media\"screen\" href\"/webif.css\"
/gt" "lt?xml-stylesheet href\"/include/style.css
\" type\"text/css\" media\"screen\"
?gt" "ltheadgt\n" "lttitlegtAVR32 NGW pin
togglerlt/titlegt\n" "lt/headgt\n" "ltbody
style\"margin 30px color C3C4D2
background-color 213242\"gt\n"
) printf("lth1gtAVR32 NGW pin togglerlt/h1gt\n") p
rintf("ltpgtlta style\"color inherit\"
href\"/\"gtBack to home...lt/agtlt/pgt\n") printf("
ltbr /gt") printf("ltpgt")
8(cont.)?
/ Get status on LED / pio
open("/dev/gpio1", O_RDWRO_NONBLOCK) get_status
if (pio lt 0) printf("Error I could not
open the GPIO device.lt/pgt\n") goto error
else retval read(pio, pio_buffer, 4) if
(retval 4) led_on pio_buffer
(1ltltLED_OFFSET) ? 0 1 else if (retval
gt 0) printf("Error I could only read d
bytes from the GPIO device.lt/pgt\n", retval)
else if (errno ! EAGAIN)
printf("Error I could not read from the
GPIO device (d).lt/pgt\n", errno)
9 (cont.)?
if (led_on) printf("LED is on gt ") else
printf("LED is off gt ") if (toggle
1 led_on 1) unsigned int off
1ltltLED_OFFSET write(pio, off,
4) printf("turning LED off gt ") toggle
0 goto get_status else if (toggle 1
led_on 0) unsigned int on
0 write(pio, on, 4) printf("turning LED on
gt ") toggle 0 goto get_status else
if (toggle 1) printf( "LED was ordered
to be toggled, but I could " "not find out if
I was supposed to turn it " "off or on, I am
very sorry '(" ) else if (led_on)
printf("do you want to turn it off?")
else printf("do you want to turn it
on?") printf("lt/pgt\n") printf("ltbr
/gt\n") printf( "ltdivgtltform method\"post\"
action\"cgipio.cgi\" " "name\"cgipio\"gt\n"
"ltinput type\"hidden\" name\"toggle\"
value\"1\" /gt\n" "ltinput type\"submit\"
value\"Change LED\" /gt\n" "lt/formgtlt/divgt\n"
) close(pio) error printf("lt/bodygtlt/ht
mlgt\n") return 0