[tuxdroid-svn] r336 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-06-01 17:29:34
|
Author: jaguarondi Date: 2007-06-01 19:29:28 +0200 (Fri, 01 Jun 2007) New Revision: 336 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_command_tux.h daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: - BUG: send_usb_dongle_cmd() was checking for an RF acknowledge which it shouldn't as these commands don't acknowledge as tux raw commands. I replaced the call to usb_write_TuxDroid() by a direct usb write. - ADD: id_lookup function basically works but it's still not called by the main program. It sends the ID_LOOKUP request then monitors the status until the id has been received back. - UPD: added the possibility to disable the wifi avoidance function by using channel 0. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-06-01 14:43:59 UTC (rev 335) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-06-01 17:29:28 UTC (rev 336) @@ -1,4 +1,3 @@ - /* * Tux Droid - USB Daemon * Copyright (C) 2007 C2ME Sa <rem...@c2...> @@ -37,7 +36,6 @@ /*_____________________ F U N C T I O N S __________________________________*/ unsigned char connect_to_tux(uint16_t id); unsigned char disconnect_from_tux(void); -unsigned char id_lookup(void); unsigned char change_id(uint16_t id); unsigned char wakeup_tux(void); unsigned char free_wifi_channel(unsigned char wifi_channel); @@ -844,14 +842,19 @@ unsigned char send_usb_dongle_cmd(USB_DONGLE_COMMANDS cmd, unsigned char param1, unsigned char param2, unsigned char param3) { - unsigned char usb_frame[TUX_SEND_LENGTH]; + unsigned char data[TUX_SEND_LENGTH]; + int ret; - usb_frame[0] = USB_DONGLE_CMD; - usb_frame[1] = cmd; - usb_frame[2] = param1; - usb_frame[3] = param2; - usb_frame[4] = param3; - return usb_write_TuxDroid(usb_frame); + data[0] = USB_DONGLE_CMD; + data[1] = cmd; + data[2] = param1; + data[3] = param2; + data[4] = param3; + log_debug("USB PC->Dongle: %#x, %#x, %#x, %#x, %#x\n", data[0], data[1], + data[2], data[3], data[4]); + ret = usb_interrupt_write(tux_handle, TUX_WRITE_EP, (char *)data, + TUX_SEND_LENGTH, TUX_WRITE_TIMEOUT); + return ret; } /** @@ -859,7 +862,8 @@ */ unsigned char connect_to_tux(uint16_t id) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CONNECT, (uint8_t)id, (uint8_t)(id>>8)); + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CONNECT, + (uint8_t)id, (uint8_t)(id>>8)); } /** @@ -867,22 +871,42 @@ */ unsigned char disconnect_from_tux(void) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_DISCONNECT, 0, 0); + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_DISCONNECT, + 0, 0); } /** * \brief Get the ID of the first disconnected tux which is discoverred * * The first disconnected tux that will detect this command will reply with - * it's ID and disconnect immediately. You can then connect to the tux with the - * ID you just got. + * it's ID and disconnect immediately. You can then connect to that tux with + * the ID you just got. * * In order to get the ID's of more than one disconnected tux, you have to * issue this command multiple times until you don't get any new ID. */ -unsigned char id_lookup(void) +#define ID_LOOKUP_TIMEOUT 20 /* 100ms time unit */ +unsigned char id_lookup(uint16_t *id) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, 0, 0); + unsigned char ack; + int timeout_cnt = 0; + + ack = send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, 0, 0); + if (ack != 5) /* error when writing data on the USB */ + return 0; + connection_status.usb_request_f = 1; /* this flag is reset when the id is received in usb_get_status_TuxDroid */ + while (connection_status.usb_request_f) + { + usleep(200000); + usb_get_status_TuxDroid(); + if (timeout_cnt++ == ID_LOOKUP_TIMEOUT) + { + return 0; + } + } + /* At this time the id should be stored in connection_status.tux_id */ + *id = connection_status.tux_id; + return 1; } /** @@ -894,7 +918,8 @@ */ unsigned char change_id(uint16_t id) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, (uint8_t)id, (uint8_t)(id>>8)); + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, + (uint8_t)id, (uint8_t)(id>>8)); } /** @@ -902,27 +927,35 @@ */ unsigned char wakeup_tux(void) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, 0, 0); + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, + 0, 0); } /** * \brief Configure the RF module to avoid a given wifi channel * - * This sets the frequencies to avoid in the dongle but these settings take - * effect only when a connection is initiated with a tux. This function should + * This sets the frequencies to avoid in the dongle. These settings only take + * effect when a connection is initiated with a tux. This function should * be called before conneting to a tux or you have to disconnect and reconnect * to change it on the go. + * + * Channels from 1 to 14 are valid wifi channels. Set the wifi channel to 0 to + * disable channel avoidance and use the complete range of frequencies. */ unsigned char free_wifi_channel(unsigned char wifi_channel) { - /* + /* * Conversion of the lower and higher frequencies of a wifi channel into * ATR2406 channel numbers. + * Channel 0 sends 0 as both low and high ATR channels. */ - uint8_t const lower_ATR_channel[14] = {0, 6, 12, 18, 24, 29, 35, 41, 47, 52, 58, 64, 70, 76}; - uint8_t const higher_ATR_channel[14] = {26, 32, 38, 43, 49, 55, 61, 67, 72, 78, 84, 90, 94, 94}; + uint8_t const lower_ATR_channel[15] = {0, 0, 6, 12, 18, 24, 29, 35, 41, 47, + 52, 58, 64, 70, 76}; + uint8_t const higher_ATR_channel[15] = {0, 26, 32, 38, 43, 49, 55, 61, 67, + 72, 78, 84, 90, 94, 94}; - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, lower_ATR_channel[wifi_channel-1], higher_ATR_channel[wifi_channel-1]); + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, + lower_ATR_channel[wifi_channel], higher_ATR_channel[wifi_channel]); } /** Modified: daemon/trunk/libs/USBDaemon_command_tux.h =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.h 2007-06-01 14:43:59 UTC (rev 335) +++ daemon/trunk/libs/USBDaemon_command_tux.h 2007-06-01 17:29:28 UTC (rev 336) @@ -25,6 +25,7 @@ #define __USBDAEMON_COMMAND_TUX_H__ /*_____________________ I N C L U D E S____________________________________ */ +#include <stdint.h> #include "USBDaemon_usb_enum.h" /*_____________________ D E F I N E S ______________________________________*/ @@ -72,5 +73,6 @@ unsigned char middle_add, unsigned char higher_add); extern unsigned char send_test_sound(); +unsigned char id_lookup(uint16_t *id); #endif Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-06-01 14:43:59 UTC (rev 335) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-06-01 17:29:28 UTC (rev 336) @@ -24,6 +24,7 @@ /*_____________________ I N C L U D E S____________________________________ */ #include <stdio.h> #include "USBDaemon_status_table.h" +#include "USBDaemon_usb_enum.h" #include "USBDaemon_globals.h" #include "USBDaemon_log.h" #include "USBDaemon_tcp_server.h" @@ -51,6 +52,11 @@ unsigned char sound_flash_count = 0; unsigned char current_audio_channel = 0; +/** + * \brief Status table and settings of the dongle and RF modules + */ +struct connection_status_t connection_status; + /*_____________________ F U N C T I O N S __________________________________*/ /************************************************************************ */ @@ -62,6 +68,11 @@ { switch (new_status[0]) { + case STATUS_ID_CMD: + connection_status.usb_request_f = 0; /* the answer from the usb command has been received */ + printf("flag set: %i\n",connection_status.usb_request_f); + connection_status.tux_id = (new_status[1] << 8) + new_status[2]; + break; case STATUS_PORTS_CMD: if (portb.Byte != new_status[1]) portb_changed(new_status[1]); Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-06-01 14:43:59 UTC (rev 335) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-06-01 17:29:28 UTC (rev 336) @@ -26,6 +26,7 @@ /*_____________________ I N C L U D E S____________________________________ */ #include "../tuxdefs/commands.h" +#include <stdbool.h> /*_____________________ D E F I N E S ______________________________________*/ @@ -238,6 +239,13 @@ extern unsigned char sound_flash_count; extern unsigned char current_audio_channel; +struct connection_status_t { + bool usb_request_f; /** usb request flag set when a USB command is issued and reset when the answer has been received in the status; only used for functions that should get an answer */ + uint16_t tux_id; /** id of the tux which is currently connected or was last connected */ + uint8_t wifi_channel; /** wifi channel that the RF modules will avoid; set to 0 to disable this function */ +}; +extern struct connection_status_t connection_status; + /*_____________________ F U N C T I O N S __________________________________*/ extern void update_raw_status_table(unsigned char new_status[]); extern void update_system_status_table(unsigned char new_status[]); |