<categorytree style="float:right; clear:right; margin-left:1ex; border: 1px solid gray; padding: 0.7ex;" mode=pages>Tools</categorytree>
__TOC__

= QWIP, a Quick Web Interface for Paparazzi =
[[Image:qwip_screenshot.png|thumb|screenshot]]

Source is hosted on github: [https://github.com/paparazzi/qwip qwip repo]
== Introduction ==

The qwip software is a simple collection of software that presents a basic ground station interface in a web browser. 

=== Various groundstation elements ===

# Position on map (googlemaps api)
# Battery level
# flight time
# RC status
# datalink settings

=== Modes ===

It can operate in two modes :

# boa and qwip run on '''[[Lisa]]/[[Overo]]''' (primary motivation for this project)
#: In this configuration the qwip "server" sw running on overo communicates with the stm32 autopilot.
# boa and qwip run on '''PC groundstation''' (for debugging or if you don't have a gumstix/lisa)
#: Here the qwip software attaches to the ivy bus to get aircraft info\

In either case, the "server" software places data in a shared memory area for a  boa cgi program ("update_qwip") to access. The cgi program is accessed by the browser javascript code.

=== Architecture ===

Insert pretty block diagrams here

=== Remote ground stations ===

Finally, the qwip "server" can communicate with remote ground stations (paparazzi ocaml-based servers) to become aware of additional aircraft and display them to the browser user.

== Quickstart ==

=== PC-based installation and usage ===

#sudo apt-get install libevent-dev
#install boa and enable configuration in boa.conf (cgi, etc)
#place qwip sw in /var/www or use links, etc (mindful of permissions)
#take a look at makefile and edit hardcoded paths to point to the right places
#take a look at source and make sure hardcoded aircraft names/paths available

==== Compile and Run server ====

: build pc_gs_server
<pre>
paul@paul-Inspiron-1210:/var/www$ make server/pc_gs_server
cc -Wall -std=gnu99 -I/home/paul/paparazzi -I/home/paul/paparazzi/sw/include `pkg-config glib-2.0 --cflags`  -DDISABLE_SPI_LINK -DFMS_PERIODIC_FREQ=512 server/gs_server.c server/gs_shm.c server/qwip_gs_link.c server/qwip_settings.c /home/paul/paparazzi/sw/airborne/fms/fms_spi_link.c /home/paul/paparazzi/sw/airborne/fms/fms_periodic.c /home/paul/paparazzi/sw/airborne/math/pprz_geodetic_double.c -o server/pc_gs_server -lm -levent  `pkg-config glib-2.0 --libs` `pcre-config --libs`
server/gs_server.c: In function ‘main_init’:
server/gs_server.c:77: warning: passing argument 1 of ‘g_strlcpy’ from incompatible pointer type
/usr/include/glib-2.0/glib/gstrfuncs.h:109: note: expected ‘gchar *’ but argument is of type ‘char (*)[128]’
server/gs_server.c:85: warning: passing argument 1 of ‘strcpy’ from incompatible pointer type
/usr/include/string.h:128: note: expected ‘char * restrict’ but argument is of type ‘char (*)[128]’
</pre>

: build ivy_gs_gateway
<pre>
paul@paul-Inspiron-1210:/var/www$ make server/ivy_gs_gateway
gcc -Wall -std=gnu99 -I/home/paul/paparazzi -I/home/paul/paparazzi/sw/include `pkg-config glib-2.0 --cflags` server/ivy_gs_gateway.c server/gs_shm.c /home/paul/paparazzi/sw/airborne/math/pprz_geodetic_double.c -o server/ivy_gs_gateway `pkg-config glib-2.0 --libs` `pcre-config --libs` -lglibivy -lm
paul@paul-Inspiron-1210:/var/www$ cd server/
</pre>

: run pc_gs_server
<pre>
cd server
paul@paul-Inspiron-1210:/var/www/server$ ./pc_gs_server 
Starting initialization
fms_periodic : hs sched_setscheduler failed : Operation not permitted (1)
gs server listening on port 4343
fms_periodic : hs sched_setscheduler failed : Operation not permitted (1)
Entering mainloop
</pre>

: If you need to kill off the shared memory area

 run ipcs to find it
 look for a line with 0x2b at the start (this is the shared mem key in hex)
 0x0000002b 37453850   root       777        7116936    0      
 kill it with "sudo ipcrm -m 37453850"

==== Testing CGI ====

First, start paparazzi and run a simulation (Microjet in this example).

Now we can call the cgi program to see if it returns something useful.
<pre>

[[Category:Software]] [[Category:Projects]]
paul@paul-Inspiron-1210:/var/www/cgi-bin$ export QUERY_STRING="req=fleet"
paul@paul-Inspiron-1210:/var/www/cgi-bin$ ./update_qwip
Content-type: application/xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<content>
  <time_running>1396 s</time_running>
  <aircrafts>
    <aircraft name="Microjet"/>
  </aircrafts>
</content>

paul@paul-Inspiron-1210:/var/www/cgi-bin$ export QUERY_STRING="req=flight_param"

paul@paul-Inspiron-1210:/var/www/cgi-bin$ ./update_qwip
Content-type: application/xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<content>
  <time_running>0 s</time_running>
  <cpu_time>0.0 s</cpu_time>
  <supply>0.0 V</supply>
  <radio_control>ok</radio_control>
  <latitude>0.0000000</latitude>
  <longitude>0.0000000</longitude>
</content>
</pre>

I'm still hunting for why everything is zeroes :-( ([[User:Paulcox|Paulcox]] 10:25, 9 February 2011 (CET))

==== Testing with browser ====
#open a browser and point it to "localhost"
(see image at top)

check boa logs for errors and access

<pre>
tail -f /var/log/boa/access.log
tail -f /var/log/boa/error.log

127.0.0.1 - - [08/Feb/2011:23:38:46 +0000] "GET /cgi-bin/update_qwip?req=fleet 
HTTP/1.1" 404 0 "http://localhost/" "Mozilla/5.0 (X11; U; Linux i686; en-US) 
AppleWebKit/534.13 (KHTML, like Gecko) Ubuntu/10.10 Chromium/9.0.597.84 
Chrome/9.0.597.84 Safari/534.13"
</pre>

== Future Direction ==

# additional functionality in qwip will require recoding much of the current ocaml ground station logic in c, which isn't the easiest language for processing xml. 
#The alternative might be running the ocaml groundstation code on the gumstix, but the use of the ivy may bog down the omap more than we would like.
#how does this fit in with the pow (paparazzi on the web) project?

[[Category:Tools]]