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

almost working

This commit is contained in:
Bas Wijnen
2010-01-18 05:01:59 +01:00
parent 05f79658e1
commit f1c608288f
15 changed files with 114 additions and 63 deletions

View File

@@ -39,7 +39,7 @@ struct data:
static int const boot_product = 0x4740
static int const run_vendor = 0xfffe
static int const run_product = 0x0002
static unsigned const timeout = 1000
static unsigned const timeout = 10000
void boot (unsigned entry)
data (std::string const &port):
handle = NULL
@@ -75,10 +75,15 @@ static std::string files ("fs")
struct Name:
char name[16]
std::string full
std::string content
Name (std::string const &n):
full = files + '/' + n
memset (name, 0, 16)
memcpy (name, n.data (), n.size () > 16 ? 16 : n.size ())
std::ifstream f (full.c_str ())
std::ostringstream s
s << f.rdbuf ()
content = s.str ()
static std::vector <Name> dir
unsigned lock (0)
@@ -160,15 +165,13 @@ void data::poll ():
return
unsigned pos = buffer[0] >> 16
std::cerr << "getting data from " << pos << '\n'
std::ifstream file (dir[buffer[1]].full.c_str ())
file.seekg (pos << 12)
char page[1 << 12]
memset (page, 0, 1 << 12)
file.read (page, 1 << 12)
shevek::dump (std::string (page, 32), std::cerr)
std::cerr << "sending bulk\n"
std::string page
if dir[buffer[1]].content.size () <= pos << 12:
page = std::string (1 << 12, 0)
else:
page = (dir[buffer[1]].content.substr (pos << 12, 1 << 12) + std::string (1 << 12, 0)).substr (0, 1 << 12)
for unsigned i = 0; i < (1 << 12); i += 64:
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, &page[i], 64, timeout) != 64:
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, &page.data ()[i], 64, timeout) != 64:
std::cerr << "unable to send file to device: " << usb_strerror () << std::endl
usb_release_interface (handle, 0)
usb_close (handle)
@@ -182,9 +185,7 @@ void data::poll ():
usb_close (handle)
handle = NULL
return
std::ifstream file (dir[buffer[1]].full.c_str ())
file.seekg (0, std::ios_base::end)
unsigned long long size = file.tellg ()
unsigned long long size = dir[buffer[1]].content.size ()
std::cerr << "sending file size " << size << "\n"
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, String::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
std::cerr << "unable to send size to device: " << usb_strerror () << std::endl