[tuxdroid-svn] r415 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: neimad <c2m...@c2...> - 2007-06-23 16:32:36
|
Author: neimad Date: 2007-06-23 18:32:33 +0200 (Sat, 23 Jun 2007) New Revision: 415 Removed: daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/libs/USBDaemon_usb_enum.h daemon/trunk/libs/USBDaemon_usb_readWrite.c daemon/trunk/libs/USBDaemon_usb_readWrite.h Log: * Forgot to remove old USB files in commit r413... Deleted: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-06-23 16:30:31 UTC (rev 414) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-06-23 16:32:33 UTC (rev 415) @@ -1,173 +0,0 @@ - -/* -* Tux Droid - USB Daemon -* Copyright (C) 2007 C2ME Sa <rem...@c2...> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -* 02111-1307, USA. -*/ - -/* $Id$ */ - -/*_____________________ I N C L U D E S____________________________________ */ -#include <stdio.h> -#include <errno.h> -#include "USBDaemon_usb_enum.h" -#include "USBDaemon_globals.h" -#include "USBDaemon_log.h" -#include "USBDaemon_status_table.h" -#include "USBDaemon_usb_readWrite.h" -#include "USBDaemon_tcp_server.h" - -/*_____________________ V A R I A B L E S __________________________________*/ -usb_dev_handle *tux_handle = NULL; -struct usb_device *tux_device = NULL; -usb_connection_status_t usb_connection_status = USB_DISCONNECTED; - -/*_____________________ F U N C T I O N S __________________________________*/ - -/************************************************************************ */ - -/* usb_find_TuxDroid() */ - -/************************************************************************ */ -struct usb_device *usb_find_TuxDroid(void) -{ - struct usb_bus *bus; - struct usb_device *tux_dev; - - usb_init(); - usb_find_busses(); - usb_find_devices(); - - for (bus = usb_busses; bus; bus = bus->next) - for (tux_dev = bus->devices; tux_dev; tux_dev = tux_dev->next) - if (tux_dev->descriptor.idVendor == TUX_VID - && tux_dev->descriptor.idProduct == TUX_PID) - return tux_dev; - - return NULL; -} - -/************************************************************************ */ - -/* usb_open_TuxDroid() */ - -/************************************************************************ */ -static struct usb_dev_handle *usb_open_TuxDroid(struct usb_device *tux_dev) -{ - usb_dev_handle *tux_hdl; - int error; - - /* Open usb device */ - tux_hdl = usb_open(tux_dev); - - if (!tux_hdl) - { - log_error("Can't open device: %s (%d)", strerror(errno), errno); - return NULL; - } - - /* Claim device interface */ - error = usb_claim_interface(tux_hdl, TUX_INTERFACE); - if (error != 0) - { - /*usb_detach_kernel_driver_np(tux_hdl, TUX_INTERFACE); */ - error = usb_claim_interface(tux_hdl, TUX_INTERFACE); - if (error != 0) - { - log_error("Can't claim interface: %s (%d)", strerror(errno), errno); - return NULL; - } - } - return tux_hdl; -} - - -/** - * Close a Tux droid previously opened with usb_open_TuxDroid(). - */ -static void usb_close_TuxDroid(usb_dev_handle *tux_hdl) -{ - if (usb_release_interface(tux_hdl, TUX_INTERFACE) < 0) - log_warning("failed releasing USB interface: %s (%d)", - strerror(errno), errno); - - if (usb_close(tux_hdl) < 0) - log_warning("failed closing USB device: %s (%d)", - strerror(errno), errno); -} - -/** - * Capture a Tux droid. - * - * \return 1 if successful, 0 otherwise - */ -int usb_capture_TuxDroid(void) -{ - log_debug("Capturing USB device"); - - /* Find Tux */ - do - { - tux_device = usb_find_TuxDroid(); - if (tux_device == NULL) - log_error("Tux dongle not found"); - - sleep(1); - } - while (!tux_device); - - /* Old firmware should be discarded here */ - if (tux_device->descriptor.bcdDevice < 0x100) - { - log_error("Your dongle firmware is too old.\n" - "This version is not compatible with this daemon, please \ - update\n" - "the firmware to version 1.00 or better.\n" - "Check http://www.tuxisalive.com/documentation/how-to/\ - updating-the-firmware\nfor details."); - return 0; - } - - log_debug("Fux found on the USB bus"); - - /* Get Device handle */ - tux_handle = usb_open_TuxDroid(tux_device); - if (tux_handle == NULL) - { - log_error("You must load the daemon in root mode"); - return 0; - } - log_debug("Fux USB device opened"); - - usb_connection_status = USB_CONNECTED; - - return 1; -} - -/** - * Release a Tux droid previously captured. - */ -void usb_release_TuxDroid(void) -{ - log_debug("Releasing USB device"); - - if (tux_handle != NULL) - usb_close_TuxDroid(tux_handle); - - tux_handle = NULL; - tux_device = NULL; -} Deleted: daemon/trunk/libs/USBDaemon_usb_enum.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.h 2007-06-23 16:30:31 UTC (rev 414) +++ daemon/trunk/libs/USBDaemon_usb_enum.h 2007-06-23 16:32:33 UTC (rev 415) @@ -1,81 +0,0 @@ - -/* -* Tux Droid - USB Daemon -* Copyright (C) 2007 C2ME Sa <rem...@c2...> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -* 02111-1307, USA. -*/ - -/* $Id$ */ - -#ifndef __USBDAEMON_USB_ENUM_H__ -#define __USBDAEMON_USB_ENUM_H__ - -/*_____________________ I N C L U D E S____________________________________ */ -#include <usb.h> - -/*_____________________ D E F I N E S ______________________________________*/ - -#define USB_FRAME_SIZE 5 -/*_____________________ E N U M S ______________________________________*/ -typedef enum -{ - USB_DISCONNECTED = 0, - USB_CONNECTED = 1 -} usb_connection_status_t; - -typedef enum -{ - USB_TUX_CMD = 0, - USB_DONGLE_CMD = 1, - USB_BOOTLOADER_CMD = 2, -} usb_command_header_t; - -typedef enum -{ - USB_TUX_CONNECTION_CMD = 0, - USB_STATUS_CMD = 1, - USB_AUDIO_CMD = 2, - USB_VERSION_CMD = 6, -} usb_dongle_commands_t; - -/* tux connection commands available on the usb dongle - * - * These are of the following type: - * USB_DONGLE_CMD, USB_TUX_CONNECTION_CMD - */ -typedef enum -{ - USB_TUX_CONNECTION_DISCONNECT = 1, - USB_TUX_CONNECTION_CONNECT = 2, - USB_TUX_CONNECTION_ID_REQUEST = 3, - USB_TUX_CONNECTION_ID_LOOKUP = 4, - USB_TUX_CONNECTION_CHANGE_ID = 5, - USB_TUX_CONNECTION_WAKEUP = 6, - USB_TUX_CONNECTION_WIRELESS_CHANNEL = 7, -} usb_tux_connection_t; - -/*_____________________ V A R I A B L E S __________________________________*/ -extern usb_dev_handle *tux_handle; -extern usb_connection_status_t usb_connection_status; - -/*_____________________ F U N C T I O N S __________________________________*/ - -extern struct usb_device *usb_find_TuxDroid(void); -extern int usb_capture_TuxDroid(void); -extern void usb_release_TuxDroid(void); - -#endif Deleted: daemon/trunk/libs/USBDaemon_usb_readWrite.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_readWrite.c 2007-06-23 16:30:31 UTC (rev 414) +++ daemon/trunk/libs/USBDaemon_usb_readWrite.c 2007-06-23 16:32:33 UTC (rev 415) @@ -1,126 +0,0 @@ - -/* -* Tux Droid - USB Daemon -* Copyright (C) 2007 C2ME Sa <rem...@c2...> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -* 02111-1307, USA. -*/ - -/* $Id$ */ - -#include <stdio.h> -#include "USBDaemon_usb_enum.h" -#include "USBDaemon_globals.h" -#include "USBDaemon_log.h" -#include "USBDaemon_status_table.h" -#include "USBDaemon_tcp_server.h" -#include "USBDaemon_usb_readWrite.h" - -/** - * Get Tux droid's status. - * - * FIXME: the status of *what* exactly ? - * FIXME: "getting" something and not actually returning anything - * is weird; "updating" would be more correct. - */ -void usb_get_status_TuxDroid(void) -{ - const unsigned char cmd_send[5] = { 0x01, 0x01, 0x00, 0x00, 0x00 }; - unsigned char data[64] = { [0 ... 63] = 0 }; - unsigned char *d; - int idx; - int num_frames, i; - - if (usb_connection_status != USB_CONNECTED) - return; - - idx = usb_interrupt_write(tux_handle, TUX_WRITE_EP, (char *)cmd_send, - sizeof(cmd_send), TUX_WRITE_TIMEOUT); - if (idx <= 0) - return; - - idx = usb_interrupt_read(tux_handle, TUX_READ_EP, (char *)data, - sizeof(data), TUX_READ_TIMEOUT); - if (idx <= 0) - return; - - update_system_status_table(data); - - num_frames = data[3]; - - if (show_frames) - log_debug("RF_st: %.2x CMD_st: %.2x NB_frames : %d idx : %d", - RF_status, CMD_status, num_frames, idx); - - /* XXX Should assert in this case, I guess ? */ - if (num_frames >= 16) - return; - - d = data + 4; - for (i = 0; i < num_frames; i++) - { - if (show_raw_status) - log_debug("%.2x %.2x %.2x %.2x", d[0], d[1], d[2], d[3]); - - update_raw_status_table(d); - d += 4; - } -} - -/** - * Send data to Tux droid over usb. - * FIXME: the whole cmd_status_flag thing is clunky. - * - * @param[in] data Data to send - * - * @return Acknowledgement (ACK_xxx), may be success or error - */ -unsigned char usb_write_TuxDroid(unsigned char data[TUX_SEND_LENGTH]) -{ - int idx; - unsigned char counter; - unsigned char csf; - - if (usb_connection_status != USB_CONNECTED) - return ACK_CMD_DONGLE_NOT_PRESENT; - - /* Send data */ - cmd_status_flag = 1; - idx = usb_interrupt_write(tux_handle, TUX_WRITE_EP, (char *)data, - TUX_SEND_LENGTH, TUX_WRITE_TIMEOUT); - counter = 0; - csf = cmd_status_flag; - - while (csf) - { - usb_get_status_TuxDroid(); - csf = cmd_status_flag; - - counter++; - usleep(10000); - if (counter == 15) - { - return ACK_CMD_TIMEOUT; - } - } - - if (CMD_status == ACK_CMD_OK) - return ACK_CMD_OK; - else if (CMD_status == ACK_CMD_KO) - return ACK_CMD_KO; - else - return ACK_CMD_ERROR; -} Deleted: daemon/trunk/libs/USBDaemon_usb_readWrite.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_readWrite.h 2007-06-23 16:30:31 UTC (rev 414) +++ daemon/trunk/libs/USBDaemon_usb_readWrite.h 2007-06-23 16:32:33 UTC (rev 415) @@ -1,38 +0,0 @@ - -/* -* Tux Droid - USB Daemon -* Copyright (C) 2007 C2ME Sa <rem...@c2...> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -* 02111-1307, USA. -*/ - -/* $Id$ */ - -#ifndef __USBDAEMON_USB_READWRITE_H__ -#define __USBDAEMON_USB_READWRITE_H__ - -/*_____________________ I N C L U D E S____________________________________ */ -#include <usb.h> - -/*_____________________ D E F I N E S ______________________________________*/ - -/*_____________________ V A R I A B L E S __________________________________*/ - -/*_____________________ F U N C T I O N S __________________________________*/ -extern void usb_get_status_TuxDroid(void); -extern unsigned char usb_write_TuxDroid(unsigned char datas[]); - -#endif |