[tuxdroid-svn] r714 - in daemon/trunk: . libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-19 16:14:43
|
Author: jaguarondi Date: 2007-11-19 17:14:36 +0100 (Mon, 19 Nov 2007) New Revision: 714 Added: daemon/trunk/supervise.c daemon/trunk/supervise.h daemon/trunk/versioning.c daemon/trunk/versioning.h Modified: daemon/trunk/Makefile daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h daemon/trunk/libs/USBDaemon_tcp_server.c Log: * Added a supervise module which will add new functionalities to the daemon. * Added versioning which collects all version information from all CPUs and store them in the main status table. Still need to update the API to send out these new status. Modified: daemon/trunk/Makefile =================================================================== --- daemon/trunk/Makefile 2007-11-19 16:09:54 UTC (rev 713) +++ daemon/trunk/Makefile 2007-11-19 16:14:36 UTC (rev 714) @@ -43,6 +43,8 @@ $(OBJ_DIR)/USBDaemon_pidfile.o \ $(OBJ_DIR)/USBDaemon_command_tux.o \ $(OBJ_DIR)/USBDaemon_tcp_server.o \ + $(OBJ_DIR)/supervise.o \ + $(OBJ_DIR)/versioning.o \ $(OBJ_DIR)/USBDaemon_log.o define build_target @@ -92,6 +94,12 @@ version.h $(compile_source) +$(OBJ_DIR)/supervise.o: supervise.c supervise.h + $(compile_source) + +$(OBJ_DIR)/versioning.o: versioning.c versioning.h + $(compile_source) + $(OBJ_DIR)/USBDaemon_log.o: libs/USBDaemon_log.c libs/USBDaemon_log.h $(compile_source) Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-11-19 16:09:54 UTC (rev 713) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-11-19 16:14:36 UTC (rev 714) @@ -1013,7 +1013,7 @@ /************************************************************************ */ static void tux_req_info(unsigned char const data[], unsigned char result[]) { - struct firmware_version_t const *const firmware = &tux_status.firmware[data[1]]; + struct firmware_info_t const *const firmware = &tux_status.firmware_info[data[1]]; result[0] = data[0]; Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-11-19 16:09:54 UTC (rev 713) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-11-19 16:14:36 UTC (rev 714) @@ -23,11 +23,14 @@ /*_____________________ I N C L U D E S____________________________________ */ #include <stdio.h> #include <assert.h> + #include "USBDaemon_status_table.h" #include "USBDaemon_usb.h" #include "USBDaemon_globals.h" #include "USBDaemon_log.h" #include "USBDaemon_tcp_server.h" +#include "../supervise.h" +#include "../versioning.h" #include "../tuxdefs/commands.h" #include "../tuxdefs/defines.h" @@ -42,23 +45,11 @@ unsigned char CMD_status = 0; unsigned char pong_received; unsigned char cmd_status_flag; -static int current_cpu = INVALID_CPU_NUM; static unsigned char last_remote_key = 0xFF; static unsigned char last_toggle_key = 0xFF; unsigned char sound_flash_count = 0; /** - * CPU names mapped from their identifiers. - * Should be in sync with CPU_IDENTIFIERS so that cpu_name[some_cpu_id] - * should return its CPU name. - * XXX is there a better way to achieve this functionality? I didn't want to - * have that array declared in defines.h otherwise it would end up in all - * firmware too. - */ -char const *const cpu_name[] = {"tuxcore", "tuxaudio", "tuxrf", "fuxrf", - "fuxusb"}; - -/** * Tux status table. * * This hierarchical structure holds all current status of tux and the dongle. @@ -72,85 +63,6 @@ struct connection_status_t connection_status; /** - * Update tux_status with the given firmware version data. - */ -void update_firmware_version(const unsigned char *data) -{ - struct firmware_version_t *firmware; - - /* When returning 'information', the firmware starts by sending this - * version information which includes the CPU number. This number is - * used to determine which CPU is sending the upcoming information data - * like revision and author. So we should save that number. */ - current_cpu = CPU_VER_CPU(data[1]); - /* Check if the value received is a valid CPU number. */ - assert(current_cpu >= LOWEST_CPU_NUM && current_cpu <= HIGHEST_CPU_NUM); - /* Select the corresponding CPU entry in the status table. */ - firmware = &tux_status.firmware[current_cpu]; - /* Save major, minor and update numbers. */ - firmware->version_major = CPU_VER_MAJ(data[1]); - firmware->version_minor = data[2]; - firmware->version_update = data[3]; - - log_debug("version of %s: %d.%d.%d", cpu_name[current_cpu], - CPU_VER_MAJ(firmware->version_major), firmware->version_minor, - firmware->version_update); -} - -/** - * Update tux_status with the given firmware revision data. - */ -static void update_firmware_revision(const unsigned char *data) -{ - /* Release types defined as strings. See parameters of REVISION_CMD. */ - char revision_string[40]; - struct firmware_version_t *firmware; - - /* Preconditions */ - assert((current_cpu == INVALID_CPU_NUM) || - (current_cpu >= LOWEST_CPU_NUM && current_cpu <= HIGHEST_CPU_NUM)); - /* Check that a valid CPU number has been received. INVALID_CPU_NUM can be - * be received if the version frame is lost and we directly get the - * revision frame. */ - if (current_cpu == INVALID_CPU_NUM) - return; - /* Select the corresponding CPU entry in the status table. */ - firmware = &tux_status.firmware[current_cpu]; - /* Save revision number. */ - firmware->revision = (data[2] << 8) + data[1]; - /* We already got the version when receiving the revision so we can now - * store the version string. */ - sprintf(revision_string, " - r%d (SVN/UNRELEASED)", firmware->revision); - sprintf(firmware->version_string, "%s %d.%d.%d%s%s%s", cpu_name[current_cpu], - CPU_VER_MAJ(firmware->version_major), firmware->version_minor, - firmware->version_update, - data[3] & 1<<2 ? "" : revision_string, - data[3] & 1<<0 ? "(modified locally)" : "", - data[3] & 1<<1 ? "(mixed revisions)" : ""); - printf(firmware->version_string); - printf("\n"); - log_debug("revision of %s: %d - type %d", cpu_name[current_cpu], - firmware->revision, data[3]); -} - -/** - * Update tux_status with the given firmware author data. - */ -static void update_firmware_author(const unsigned char *data) -{ - struct firmware_version_t *firmware; - /* Check that a valid CPU number has been received. */ - if (current_cpu == INVALID_CPU_NUM) - return; - /* Select the corresponding CPU entry in the status table. */ - firmware = &tux_status.firmware[current_cpu]; - /* Save author. */ - firmware->author = (data[2] << 8) + data[1]; - - log_debug("author of %s: %d", cpu_name[current_cpu], firmware->author); -} - -/** * Update tux_status with the given properties of the sound flash. */ static void update_sound_flash_properties(const unsigned char *data) @@ -629,9 +541,7 @@ } /************************************************************************ */ - /* update_raw_status_table() */ - /************************************************************************ */ void update_raw_status_table(const unsigned char *new_status) { @@ -740,6 +650,7 @@ new_status[2], new_status[3]); break; } + } /************************************************************************ */ @@ -758,24 +669,27 @@ tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; - /* RF connection change. */ + /* DONGLE_status is null for now */ if (new_status[0] != DONGLE_status) { DONGLE_status = new_status[0]; - if (DONGLE_status == 1) + } + + /* RF connection change. */ + if (new_status[1] != RF_status) + { + RF_status = new_status[1]; + if (RF_status == 1) /* RF connected */ { + on_connect_status_update(); } else /* RF disconnected */ { + on_disconnect_status_cleaning(); } - } - /*RF status change */ - if (RF_status != new_status[1]) - { - RF_status = new_status[1]; tcp_frame[4] = DATA_STATUS_RF_CONNECTED; tcp_frame[5] = RF_status; tcp_server_send_raw(tcp_frame); @@ -785,6 +699,7 @@ if (CMD_status != new_status[2]) { CMD_status = new_status[2]; + //if (CMD_status == ACK_CMD_OK || CMD_status == ACK_CMD_KO) if (CMD_status == ACK_CMD_OK || CMD_status == ACK_CMD_KO) cmd_status_flag = 0; } Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-11-19 16:09:54 UTC (rev 713) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-11-19 16:14:36 UTC (rev 714) @@ -25,6 +25,7 @@ /*_____________________ I N C L U D E S____________________________________ */ #include "../tuxdefs/api.h" +#include "../tuxdefs/defines.h" #include <stdbool.h> /*_____________________ D E F I N E S ______________________________________*/ @@ -273,6 +274,15 @@ extern unsigned char cmd_status_flag; extern unsigned char pong_received; +/** Number of firmware information structures to store. + * There's one for each firmware and one for the general release package. + * Firmware will have the same index as defined in CPU_IDENTIFIERS, the last + * one will be the release package. */ +#define NUMBER_OF_FIRMWARE (HIGHEST_CPU_NUM + 2) +/** Index of the general release package information structure defined in + * tux_status. */ +#define RELEASE_INDEX (NUMBER_OF_FIRMWARE - 1) + /** * Tux status table. * @@ -280,8 +290,8 @@ */ struct tux_status_t { - /** Firmware version numbers, svn revision and author. */ - struct firmware_version_t + /** Firmware versioning , svn revision and author. */ + struct firmware_info_t { int version_major; int version_minor; @@ -291,8 +301,9 @@ int local_modification; int mixed_revisions; int author; + int variation; char version_string[100]; - } firmware[5]; + } firmware_info[NUMBER_OF_FIRMWARE]; /** Sound flash properties. */ struct sound_flash_t { Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-11-19 16:09:54 UTC (rev 713) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-11-19 16:14:36 UTC (rev 714) @@ -35,6 +35,7 @@ #include "USBDaemon_tcp_server.h" #include "USBDaemon_usb.h" #include "USBDaemon_pidfile.h" +#include "../supervise.h" #include "USBDaemon_log.h" /*_____________________ V A R I A B L E S __________________________________*/ @@ -191,6 +192,8 @@ exit(1); } + supervise(); + timeout = TIMEOUT; } else if (r < 0) Added: daemon/trunk/supervise.c =================================================================== --- daemon/trunk/supervise.c (rev 0) +++ daemon/trunk/supervise.c 2007-11-19 16:14:36 UTC (rev 714) @@ -0,0 +1,49 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 C2ME S.A. <tux...@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 "versioning.h" +#include "libs/USBDaemon_status_table.h" + +/** + * Actions that should be triggered when tux is just getting disconnected. + */ +void on_disconnect_status_cleaning(void) +{ + tux_information_cleaning(); +} + +/** + * Actions that should be triggered when tux is just getting connected. + */ +void on_connect_status_update(void) +{ + get_versioning(); +} + +/** + * This functions is called regularly to supervise all the functionalities that + * the daemon should manage. + */ +void supervise(void) +{ + versioning_call(); +} Property changes on: daemon/trunk/supervise.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: daemon/trunk/supervise.h =================================================================== --- daemon/trunk/supervise.h (rev 0) +++ daemon/trunk/supervise.h 2007-11-19 16:14:36 UTC (rev 714) @@ -0,0 +1,33 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 C2ME S.A. <tux...@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 _SUPERVISE_H_ +#define _SUPERVISE_H_ + +void init_versioning(void); +void versioning(void); + +void on_disconnect_status_cleaning(void); +void on_connect_status_update(void); +void supervise(void); + +#endif /* _SUPERVISE_H_ */ Property changes on: daemon/trunk/supervise.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: daemon/trunk/versioning.c =================================================================== --- daemon/trunk/versioning.c (rev 0) +++ daemon/trunk/versioning.c 2007-11-19 16:14:36 UTC (rev 714) @@ -0,0 +1,393 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 C2ME S.A. <tux...@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 <string.h> +#include <assert.h> + +#include "libs/USBDaemon_log.h" +#include "libs/USBDaemon_status_table.h" +#include "libs/USBDaemon_globals.h" +#include "libs/USBDaemon_usb.h" +#include "tuxdefs/defines.h" +#include "tuxdefs/api.h" + +/** + * CPU names mapped from their identifiers. + * Should be in sync with CPU_IDENTIFIERS so that cpu_name[some_cpu_id] + * should return its CPU name. + * XXX is there a better way to achieve this functionality? I didn't want to + * have that array declared in defines.h otherwise it would end up in all + * firmware too. + */ +static char const *const cpu_name[] = +{ + [TUXCORE_CPU_NUM] = "tuxcore", + [TUXAUDIO_CPU_NUM] = "tuxaudio", + [TUXRF_CPU_NUM] = "tuxrf", + [FUXRF_CPU_NUM] = "fuxrf", + [FUXUSB_CPU_NUM] = "fuxusb" +}; + +/** + * Versioning states. + */ +typedef enum versioning_state +{ + STDBY, + INIT, + INFO_REQ, + INFO_GET, + SPECIAL, + RELEASE, + FINALIZE, +} versioning_state_t; + +/** State of the versioning state machine. */ +static versioning_state_t versioning_state = STDBY; + +/** Used to hold the CPU number that is currently sending its information as it + * needs multiple commands to send it all. */ +static int current_cpu = INVALID_CPU_NUM; + +/** + * Remove all information associated with tux: tuxcore, tuxaudio and tuxrf. + * + * This can be used when a tux is disconnected to avoid having information + * buffered but which is not relevant anymore. + */ +void tux_information_cleaning(void) +{ + int firmware_num[4] = {TUXCORE_CPU_NUM, TUXAUDIO_CPU_NUM, TUXRF_CPU_NUM, + RELEASE_INDEX}; + struct firmware_info_t *firmware; + int i; + + for (i=0; i<4; i++) + { + firmware = &tux_status.firmware_info[firmware_num[i]]; + memset((char*)firmware, 0, sizeof(struct firmware_info_t)); + } + tux_status.sound_flash.number_of_sounds = 0; +} + +/** + * Update tux_status with the given firmware version data. + */ +void update_firmware_version(const unsigned char *data) +{ + struct firmware_info_t *firmware; + + /* When returning 'information', the firmware starts by sending this + * version information which includes the CPU number. This number is + * used to determine which CPU is sending the upcoming information data + * like revision and author. So we should save that number. */ + current_cpu = CPU_VER_CPU(data[1]); + /* Check if the value received is a valid CPU number. */ + assert(current_cpu >= LOWEST_CPU_NUM && current_cpu <= HIGHEST_CPU_NUM); + /* Select the corresponding CPU entry in the status table. */ + firmware = &tux_status.firmware_info[current_cpu]; + /* Save major, minor and update numbers. */ + firmware->version_major = CPU_VER_MAJ(data[1]); + firmware->version_minor = data[2]; + firmware->version_update = data[3]; + + log_debug("FW: version of %s: %d.%d.%d", cpu_name[current_cpu], + CPU_VER_MAJ(firmware->version_major), firmware->version_minor, + firmware->version_update); +} + +/** + * Update tux_status with the given firmware revision data. + */ +void update_firmware_revision(const unsigned char *data) +{ + char revision_string[40]; + struct firmware_info_t *firmware; + + /* Preconditions */ + assert((current_cpu == INVALID_CPU_NUM) || + (current_cpu >= LOWEST_CPU_NUM && current_cpu <= HIGHEST_CPU_NUM)); + /* Check that a valid CPU number has been received. INVALID_CPU_NUM can be + * be received if the version frame is lost and we directly get the + * revision frame. */ + if (current_cpu == INVALID_CPU_NUM) + return; + /* Select the corresponding CPU entry in the status table, save. */ + firmware = &tux_status.firmware_info[current_cpu]; + firmware->revision = (data[2] << 8) + data[1]; + firmware->release = (data[3] & 1<<2) ? 1 : 0; + firmware->local_modification = (data[3] & 1<<0) ? 1 : 0; + firmware->mixed_revisions = (data[3] & 1<<1) ? 1 : 0; + /* A release shouldn't get local_modifications or mixed revisions. */ + if ((firmware->local_modification || firmware->mixed_revisions) + && firmware->release) + { + firmware->release = 0; + log_debug("FW: this firmware is released with local modifications or " + "mixed revisions. 'release' status has been dropped."); + } + /* We already got the version when receiving the revision so we can now + * store the version string. */ + sprintf(revision_string, " - r%d (SVN/UNRELEASED)", firmware->revision); + sprintf(firmware->version_string, "%s %d.%d.%d%s%s%s", + cpu_name[current_cpu], + CPU_VER_MAJ(firmware->version_major), firmware->version_minor, + firmware->version_update, + firmware->release ? "" : revision_string, + firmware->local_modification ? "(modified locally)" : "", + firmware->mixed_revisions ? "(mixed revisions)" : ""); + log_debug("FW: revision of %s: %d - type %d", cpu_name[current_cpu], + firmware->revision, data[3]); +} + +/** + * Update tux_status with the given firmware author data. + */ +void update_firmware_author(const unsigned char *data) +{ + struct firmware_info_t *firmware; + /* Check that a valid CPU number has been received. */ + if (current_cpu == INVALID_CPU_NUM) + return; + /* Select the corresponding CPU entry in the status table. */ + firmware = &tux_status.firmware_info[current_cpu]; + /* Save author. */ + firmware->author = (data[2] << 8) + data[1]; + firmware->variation = data[3]; + + log_debug("FW: author of %s: %d (variation %d)", cpu_name[current_cpu], + firmware->author, firmware->variation); +} + +/** + * Determine the general release package information from all firmware + * information. + * + * \todo TODO This general release package information can only be found in an + * external file, ideally an xml generated from the firmware release section of + * the website. For now, we simply hardcode the available releases in the + * daemon. This needs to be changed later on when the xml file will be + * available. */ +void determine_release_package(void) +{ + int cpu_num = LOWEST_CPU_NUM; + int major, minor, update = 0; + struct firmware_info_t *release, *firmware; + + release = &tux_status.firmware_info[RELEASE_INDEX]; + /* We first check that all firmware are released and have the same + * major/minor version numbers. Also find the update number. */ + major = tux_status.firmware_info[LOWEST_CPU_NUM].version_major; + minor = tux_status.firmware_info[LOWEST_CPU_NUM].version_minor; + while (cpu_num <= HIGHEST_CPU_NUM) + { + firmware = &tux_status.firmware_info[cpu_num]; + if (update < firmware->version_update) + update = firmware->version_update; + if (!firmware->release + || (firmware->version_major != major) + || (firmware->version_minor != minor)) + return; + cpu_num ++; + } + /* Check that all different versions are part of a package released on the + * website, hardcoded here for now. */ + if (major == 0 && minor == 3 && update == 0) + /* release 0.3.0, all CPUs have the same version number 0.3.0. */ + { + if ((tux_status.firmware_info[TUXCORE_CPU_NUM].version_update != 0) + || (tux_status.firmware_info[TUXAUDIO_CPU_NUM].version_update != 0) + || (tux_status.firmware_info[TUXRF_CPU_NUM].version_update != 0) + || (tux_status.firmware_info[FUXRF_CPU_NUM].version_update != 0) + || (tux_status.firmware_info[FUXUSB_CPU_NUM].version_update != 0)) + return; + } + else if (major == 0 && minor == 3 && update == 1) + /* release 0.3.1, tuxcore and tuxaudio updated to 0.3.1 */ + { + if ((tux_status.firmware_info[TUXCORE_CPU_NUM].version_update != 1) + || (tux_status.firmware_info[TUXAUDIO_CPU_NUM].version_update != 1) + || (tux_status.firmware_info[TUXRF_CPU_NUM].version_update != 0) + || (tux_status.firmware_info[FUXRF_CPU_NUM].version_update != 0) + || (tux_status.firmware_info[FUXUSB_CPU_NUM].version_update != 0)) + return; + } + + /* It's a release. */ + release->version_major = major; + release->version_minor = minor; + release->version_update = update; + /* Author and variation are taken from tuxcore as that's the CPU most + * likely to be customized. */ + release->author = tux_status.firmware_info[TUXCORE_CPU_NUM].author; + release->variation = tux_status.firmware_info[TUXCORE_CPU_NUM].variation; + sprintf(release->version_string, "tuxdroid firmware release %d.%d.%d", + major, minor, update); + log_debug("FW: %s", release->version_string); +} + +/** + * Fake versioning of old fimware that didn't support it. + * The first release of tuxrf and fuxrf are 0.3.0 but those + * firmware can't send their version information. So if we don't + * have those CPUs now, we simply assign this version number. */ +void old_firmware_versioning(const int cpu_num) +{ + uint8_t const tuxrf_version[4] = {0xC8, 2, 3, 0}; + uint8_t const fuxrf_version[4] = {0xC8, 3, 3, 0}; + uint8_t const revision[4] = {0xC9, 0xA9, 0x02, 0x04}; + uint8_t const author[4] = {0xC9, 0, 0, 0}; + if (cpu_num == TUXRF_CPU_NUM) + { + update_firmware_version(tuxrf_version); + update_firmware_revision(revision); + update_firmware_author(author); + } + else if (cpu_num == FUXRF_CPU_NUM) + { + update_firmware_version(fuxrf_version); + update_firmware_revision(revision); + update_firmware_author(author); + } +} + +/** + * Get the version information of all different firmware. + * + * This function has to be called to initiate the retrieving process. + */ +void get_versioning(void) +{ + if (versioning_state == STDBY) + versioning_state = INIT; +} + +/** Number of times the info command will be restarted if no responses have + * been received after the TIMEOUT period. So there will be RETRY+1 attempts in + * total. */ +#define RETRY 1 +/** Timeout of the INFO command before we retry or skip. */ +#define TIMEOUT 5 + +/** + * This is the state machine to collect all firmware version information one at + * a time and do the required processing to update the status. + * + * This function should be called at a regular basis in order to do its job. + */ +void versioning_call(void) +{ + int ret; + uint8_t usb_command[TUX_SEND_LENGTH] = {0, 0, 0, 0, 0}; + static int cpu_num; + static unsigned int retries, wait; + + switch(versioning_state) + { + case STDBY: + break; + case INIT: + /* Preconditions */ + assert(RETRY >= 0); + assert(TIMEOUT >= 0); + + cpu_num = LOWEST_CPU_NUM; + versioning_state = INFO_REQ; + retries = RETRY; + break; + case INFO_REQ: + { + const uint8_t info_cpu_cmd[5] = {INFO_TUXCORE_CMD, + INFO_TUXAUDIO_CMD, INFO_TUXRF_CMD, INFO_FUXRF_CMD, + INFO_FUXUSB_CMD}; + /* Check when all CPUs are done. */ + if ((cpu_num) > HIGHEST_CPU_NUM) + { + versioning_state = SPECIAL; + break; + } + usb_command[1] = info_cpu_cmd[cpu_num]; + /* By-pass if we already have the information. We need to do that + * otherwise the command will be sent and the version_string + * detected immediately after even though we might not yet have + * received the answer from the CPU. At that point a new request + * can be sent for the next CPU and all answers will be mixed. */ + if (tux_status.firmware_info[cpu_num].version_string[0] == '\0') + { + ret = usb_send_TuxDroid(usb_command); + if (ret <=0) + break; + wait = TIMEOUT; + } + versioning_state = INFO_GET; + } + break; + case INFO_GET: + if (tux_status.firmware_info[cpu_num].version_string[0]) + { + cpu_num++; + retries = RETRY; + } + else if (!wait) + { + /* Retry or abandon. */ + if (retries-- == 0) + { + cpu_num++; + retries = RETRY; + } + } + else + { + wait--; + break; + } + versioning_state = INFO_REQ; + break; + case SPECIAL: + { + /* The first release of tuxrf and fuxrf are 0.3.0 but those + * firmware can't send their version information. So if we don't + * have those CPUs now, we simply assign this version number. + * XXX This probably have to be removed at a later stage when we + * won't support old firmwares anymore and be replaced by a + * warning. */ + if (tux_status.firmware_info[TUXRF_CPU_NUM].version_string[0] + == '\0') + old_firmware_versioning(TUXRF_CPU_NUM); + if (tux_status.firmware_info[FUXRF_CPU_NUM].version_string[0] + == '\0') + old_firmware_versioning(FUXRF_CPU_NUM); + } + versioning_state = RELEASE; + break; + case RELEASE: + determine_release_package(); + versioning_state = STDBY; + break; + case FINALIZE: + /* Can be used later on to trigger omething when versioning has been + * completed, like a callback function or set a flag. */ + break; + } +} Property changes on: daemon/trunk/versioning.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: daemon/trunk/versioning.h =================================================================== --- daemon/trunk/versioning.h (rev 0) +++ daemon/trunk/versioning.h 2007-11-19 16:14:36 UTC (rev 714) @@ -0,0 +1,33 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 C2ME S.A. <tux...@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 _VERSIONING_H_ +#define _VERSIONING_H_ + +extern void tux_information_cleaning(void); +extern void get_versioning(void); +extern void versioning_call(void); +extern void update_firmware_version(const unsigned char *data); +extern void update_firmware_revision(const unsigned char *data); +extern void update_firmware_author(const unsigned char *data); + +#endif /* _VERSIONING_H_ */ Property changes on: daemon/trunk/versioning.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native |