1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2025-04-21 12:27:27 +03:00

further towards a usb file system

This commit is contained in:
Bas Wijnen
2010-01-14 22:04:19 +01:00
parent 0c1dfe719b
commit 03e74d38d3
3 changed files with 62 additions and 9 deletions

View File

@@ -20,7 +20,7 @@ AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = usb-server
usb_server_SOURCES = usb-server.cc
usb_server_CPPFLAGS = $(SHEVEK_CFLAGS) -DSTAGE1_FILE=\"mips/nanonote/sdram-setup.raw\" -DSTAGE2_FILE=\"iris.raw\"
usb_server_CPPFLAGS = $(SHEVEK_CFLAGS) -DSTAGE1_FILE=\"mips/nanonote/sdram-setup.raw\" -DSTAGE2_FILE=\"iris.raw\" -I../../..
usb_server_LDFLAGS = $(SHEVEK_LIBS) -lusb
PYPP = /usr/bin/pypp

View File

@@ -26,6 +26,7 @@
#include <shevek/mainloop.hh>
#include <shevek/server.hh>
#include <shevek/args.hh>
#include <shevek/dir.hh>
#include "devices.hh"
struct client
@@ -69,6 +70,17 @@ struct data:
void get_device (unsigned vendor, unsigned product, unsigned tries)
void poll ()
struct Name:
char name[16]
std::string full
Name (std::string const &n):
full = n
memset (name, 0, 16)
memcpy (name, n.data (), n.size () > 16 ? 16 : n.size ())
static std::vector <Name> dir
static std::string files (".")
unsigned lock (0)
void data::poll ():
while true:
unsigned buffer[2]
@@ -89,7 +101,7 @@ void data::poll ():
break
case Directory::GET_SIZE:
unsigned long long size = dir.size ()
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_SIZE, 0, 0, (char const *)&size, 8, timeout) != 8:
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
std::cerr << "unable to send size to device: " << usb_strerror () << std::endl
usb_release_interface (handle, 0)
usb_close (handle)
@@ -112,7 +124,10 @@ void data::poll ():
continue
case Directory::LOCK_RO:
if !lock++:
dir.load (files)
shevek::dir d (files)
dir.clear ()
for shevek::dir::const_iterator i = d.begin (); i == d.end (); ++i:
dir.push_back (Name (i->name))
continue
case Directory::UNLOCK_RO:
if !lock:
@@ -121,7 +136,8 @@ void data::poll ():
usb_close (handle)
handle = NULL
return
--lock
if !--lock:
dir.clear ()
continue
case Directory::GET_FILE_RO:
unsigned f = buffer[0] >> 16
@@ -131,13 +147,13 @@ void data::poll ():
usb_close (handle)
handle = NULL
return
std::ifstream file (dir[f])
file.seek (buffer[1] << 12)
std::ifstream file (dir[f].full.c_str ())
file.seekg (buffer[1] << 12)
char page[1 << 12]
memset (page, 0, 1 << 12)
file.read (page, 1 << 12)
for unsigned i = 0; i < (1 << 12); i += 64:
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, p, 64) != 64:
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, &page[i], 64, timeout) != 64:
std::cerr << "unable to send file to device: " << usb_strerror () << std::endl
usb_release_interface (handle, 0)
usb_close (handle)