[tuxdroid-svn] r696 - daemon/trunk/libs firmware/tuxdefs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-13 14:31:38
|
Author: jaguarondi Date: 2007-11-13 15:31:33 +0100 (Tue, 13 Nov 2007) New Revision: 696 Modified: daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h firmware/tuxdefs/defines.h Log: * Added a version string. * Using assert for checking valid preconditions in versioning. Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-11-13 13:43:41 UTC (rev 695) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-11-13 14:31:33 UTC (rev 696) @@ -22,6 +22,7 @@ /*_____________________ 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" @@ -47,6 +48,17 @@ 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. @@ -59,7 +71,7 @@ */ struct connection_status_t connection_status; -/** +/** * Update tux_status with the given firmware version data. */ void update_firmware_version(const unsigned char *data) @@ -72,14 +84,7 @@ * 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. */ - if ((current_cpu < 0) || (current_cpu > 4)) - { - log_error("received an INVALID CPU number: %d", current_cpu); - /* Mark current_cpu as invalid to discard any new information data - * until a valid CPU number is received. */ - current_cpu = INVALID_CPU_NUM; - return; - } + 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. */ @@ -87,7 +92,7 @@ firmware->version_minor = data[2]; firmware->version_update = data[3]; - log_debug("version of %i: %i.%i.%i", CPU_VER_CPU(current_cpu), + log_debug("version of %s: %d.%d.%d", cpu_name[current_cpu], CPU_VER_MAJ(firmware->version_major), firmware->version_minor, firmware->version_update); } @@ -97,19 +102,38 @@ */ 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; - /* Check that a valid CPU number has been received. */ + + /* 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]; - - log_debug("revision of %i: %i", current_cpu, firmware->revision); + /* 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) @@ -123,17 +147,17 @@ /* Save author. */ firmware->author = (data[2] << 8) + data[1]; - log_debug("author of %i: %i", current_cpu, firmware->author); + 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) { tux_status.sound_flash.number_of_sounds = data[1]; - log_debug("%i sounds in flash", tux_status.sound_flash.number_of_sounds); + log_debug("%d sounds in flash", tux_status.sound_flash.number_of_sounds); } static void update_ir(const unsigned char *new_status) @@ -308,7 +332,7 @@ tcp_frame[4] = DATA_STATUS_AUDIO; - + tcp_frame[5] = play; tcp_frame[6] = record; tcp_frame[7] = status; @@ -617,7 +641,7 @@ /* The answer from the usb_tux_connection command has been received */ connection_status.usb_request_f = false; connection_status.tux_id = (new_status[1] << 8) + new_status[2]; - log_debug("id returned by tux: %i (0x%.2x%.2x)", + log_debug("id returned by tux: %d (0x%.2x%.2x)", connection_status.tux_id, new_status[1], new_status[2]); break; case STATUS_PORTS_CMD: @@ -659,7 +683,7 @@ break; case STATUS_AUDIO_CMD: - { + { int play; int record; int status; Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-11-13 13:43:41 UTC (rev 695) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-11-13 14:31:33 UTC (rev 696) @@ -283,7 +283,11 @@ int version_minor; int version_update; int revision; + int release; + int local_modification; + int mixed_revisions; int author; + char version_string[100]; } firmware[5]; /** Sound flash properties. */ struct sound_flash_t Modified: firmware/tuxdefs/defines.h =================================================================== --- firmware/tuxdefs/defines.h 2007-11-13 13:43:41 UTC (rev 695) +++ firmware/tuxdefs/defines.h 2007-11-13 14:31:33 UTC (rev 696) @@ -56,6 +56,12 @@ /** We use '-1' to indicate an invalid CPU number. */ INVALID_CPU_NUM = -1, }; +/** Lowest valid value for a CPU identifier. + * Should be set according to CPU_IDENTIFIERS. */ +#define LOWEST_CPU_NUM 0 +/** Highest valid value for a CPU identifier. + * Should be set according to CPU_IDENTIFIERS. */ +#define HIGHEST_CPU_NUM 4 /** * I2C addresses of all CPUs. |