mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-04-21 12:27:27 +03:00
usb fs mostly working
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <shevek/server.hh>
|
||||
#include <shevek/args.hh>
|
||||
#include <shevek/dir.hh>
|
||||
#include <shevek/error.hh>
|
||||
#include "devices.hh"
|
||||
|
||||
struct client
|
||||
@@ -70,15 +71,15 @@ struct data:
|
||||
void get_device (unsigned vendor, unsigned product, unsigned tries)
|
||||
void poll ()
|
||||
|
||||
static std::string files ("fs")
|
||||
struct Name:
|
||||
char name[16]
|
||||
std::string full
|
||||
Name (std::string const &n):
|
||||
full = n
|
||||
full = files + '/' + 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 ():
|
||||
@@ -101,6 +102,12 @@ void data::poll ():
|
||||
break
|
||||
case Directory::GET_SIZE:
|
||||
unsigned long long size = dir.size ()
|
||||
std::cerr << "sending dir size\n"
|
||||
std::cerr << Directory::GET_SIZE << '\n'
|
||||
char *str = (char *)&size
|
||||
for unsigned i = 0; i < 8; ++i:
|
||||
std::cerr << " " << (unsigned)(str[i] & 0xff)
|
||||
std::cerr << '\n'
|
||||
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)
|
||||
@@ -115,6 +122,7 @@ void data::poll ():
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
std::cerr << "sending filename\n"
|
||||
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_NAME, 0, 0, dir[buffer[1]].name, 16, timeout) != 16:
|
||||
std::cerr << "unable to send name to device: " << usb_strerror () << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
@@ -123,13 +131,17 @@ void data::poll ():
|
||||
return
|
||||
continue
|
||||
case Directory::LOCK_RO:
|
||||
std::cerr << "lock\n"
|
||||
if !lock++:
|
||||
std::cerr << "freezing file list\n"
|
||||
shevek::dir d (files)
|
||||
dir.clear ()
|
||||
for shevek::dir::const_iterator i = d.begin (); i == d.end (); ++i:
|
||||
dir.push_back (Name (i->name))
|
||||
for shevek::dir::const_iterator i = d.begin (); i != d.end (); ++i:
|
||||
if !i->name.empty () && i->name[0] != '.':
|
||||
dir.push_back (Name (i->name))
|
||||
continue
|
||||
case Directory::UNLOCK_RO:
|
||||
std::cerr << "unlock\n"
|
||||
if !lock:
|
||||
std::cerr << "unlocking without lock" << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
@@ -139,19 +151,22 @@ void data::poll ():
|
||||
if !--lock:
|
||||
dir.clear ()
|
||||
continue
|
||||
case Directory::GET_FILE_RO:
|
||||
unsigned f = buffer[0] >> 16
|
||||
if f >= dir.size ():
|
||||
case String::GET_PAGE:
|
||||
if buffer[1] >= dir.size ():
|
||||
std::cerr << "reading invalid file" << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
std::ifstream file (dir[f].full.c_str ())
|
||||
file.seekg (buffer[1] << 12)
|
||||
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"
|
||||
for unsigned i = 0; i < (1 << 12); i += 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
|
||||
@@ -160,15 +175,33 @@ void data::poll ():
|
||||
handle = NULL
|
||||
return
|
||||
continue
|
||||
case String::GET_SIZE:
|
||||
if buffer[1] >= dir.size ():
|
||||
std::cerr << "reading invalid file size" << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
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 ()
|
||||
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
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
continue
|
||||
default:
|
||||
std::cerr << "invalid request" << std::endl
|
||||
std::cerr << "invalid request " << buffer[0] << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
// If the code reaches this point, break out of the loop. The loop continues if a continue statement is reached.
|
||||
break
|
||||
(shevek::absolute_time () + shevek::relative_time (1, 0)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
(shevek::absolute_time () + shevek::relative_time (0, 100000000)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
|
||||
struct client : public shevek::server <client, data *>::connection:
|
||||
static Glib::RefPtr <client> create ():
|
||||
@@ -225,7 +258,7 @@ void data::get_device (unsigned vendor, unsigned product, unsigned tries):
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
continue
|
||||
(shevek::absolute_time () + shevek::relative_time (1, 0)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
(shevek::absolute_time () + shevek::relative_time (0, 100000000)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
return
|
||||
if i + 1 < tries:
|
||||
//std::cerr << "failed to find device, still trying...\n"
|
||||
@@ -277,6 +310,21 @@ void data::boot (unsigned entry):
|
||||
return
|
||||
std::cerr << "(re)booted NanoNote\n"
|
||||
|
||||
static void dump_devices ():
|
||||
std::cerr << std::hex << "String: " << String::ID
|
||||
std::cerr << "\nWString: " << WString::ID
|
||||
std::cerr << "\nDevice: " << Device::ID
|
||||
std::cerr << "\nParent: " << Parent::ID
|
||||
std::cerr << "\nKeyboard: " << Keyboard::ID
|
||||
std::cerr << "\nBuzzer: " << Buzzer::ID
|
||||
std::cerr << "\nDisplay: " << Display::ID
|
||||
std::cerr << "\nSetting: " << Setting::ID
|
||||
std::cerr << "\nDirectory: " << Directory::ID
|
||||
std::cerr << "\nWDirectory: " << WDirectory::ID
|
||||
std::cerr << "\nFilesystem: " << Filesystem::ID
|
||||
std::cerr << "\nStream: " << Stream::ID
|
||||
std::cerr << "\n"
|
||||
|
||||
int main (int argc, char **argv):
|
||||
usb_init ()
|
||||
std::string port ("5050")
|
||||
@@ -285,5 +333,6 @@ int main (int argc, char **argv):
|
||||
}
|
||||
shevek::args args (argc, argv, opts, 0, 0, "device server for testing Iris on NanoNote", "2009")
|
||||
data d (port)
|
||||
dump_devices ()
|
||||
shevek::loop ()
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user