[tuxdroid-svn] r664 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-08 09:51:04
|
Author: jaguarondi Date: 2007-11-08 10:50:57 +0100 (Thu, 08 Nov 2007) New Revision: 664 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: * Added a new structure which will hold all status of tux: tux_status. * Updated functions for versions, revisions, author and sound flash information to use the new structure. Added comments. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-11-08 09:36:40 UTC (rev 663) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-11-08 09:50:57 UTC (rev 664) @@ -637,7 +637,7 @@ result[1] = RF_status; break; case DATA_STATUS_SOUND_COUNT: - result[1] = sound_flash_count; + result[1] = tux_status.sound_flash.number_of_sounds; break; } } @@ -992,21 +992,19 @@ /************************************************************************ */ static void tux_req_info(unsigned char const data[], unsigned char result[]) { + struct firmware_version_t const *const firmware = &tux_status.firmware[data[1]]; + result[0] = data[0]; if (data[0] == TUX_REQ_INFO_VERSION) { - version_t *ver = &hw_version[data[1]]; - revision_t *rev = &hw_revision[data[1]]; - author_t *auth = &hw_author[data[1]]; - - result[1] = CPU_VER_MAJ(ver->cpu_ver_maj); - result[2] = ver->ver_minor; - result[3] = ver->ver_update; - result[4] = (unsigned char)((rev->revision & 0xFF00) >> 8); - result[5] = (unsigned char)(rev->revision & 0x00FF); - result[6] = (unsigned char)((auth->author_id & 0xFF00) >> 8); - result[7] = (unsigned char)(auth->author_id & 0x00FF); + result[1] = firmware->version_major; + result[2] = firmware->version_minor; + result[3] = firmware->version_update; + result[4] = (unsigned char)((firmware->revision & 0xFF00) >> 8); + result[5] = (unsigned char)(firmware->revision & 0x00FF); + result[6] = (unsigned char)((firmware->author& 0xFF00) >> 8); + result[7] = (unsigned char)(firmware->author& 0x00FF); } } Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-11-08 09:36:40 UTC (rev 663) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-11-08 09:50:57 UTC (rev 664) @@ -40,64 +40,84 @@ unsigned char CMD_status = 0; unsigned char pong_received; unsigned char cmd_status_flag; -version_t hw_version[4]; -revision_t hw_revision[4]; -author_t hw_author[4]; -static unsigned char last_cpu_ver; +static unsigned char current_cpu; static unsigned char last_remote_key = 0xFF; static unsigned char last_toggle_key = 0xFF; unsigned char sound_flash_count = 0; /** - * \brief Status table and settings of the dongle and RF modules + * Tux status table. + * + * This hierarchical structure holds all current status of tux and the dongle. + * As soon as a new status is received from tux, the structure is updated. */ +struct tux_status_t tux_status; + +/** + * 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 __________________________________*/ - -static void update_version_table(const unsigned char *new_status) +/** + * Update tux_status with the given firmware version data. + */ +void update_firmware_version(const unsigned char *data) { - unsigned long tmp; - version_t *hw_ver; + struct firmware_version_t *firmware; - tmp = (new_status[3] << 24) + (new_status[2] << 16) + (new_status[1] << 8) - + (new_status[0]); - hw_ver = (version_t *)&tmp; - last_cpu_ver = CPU_VER_CPU(hw_ver->cpu_ver_maj); - hw_version[last_cpu_ver] = *hw_ver; - log_debug("version of %i: %i.%i.%i", CPU_VER_CPU(hw_ver->cpu_ver_maj), - CPU_VER_MAJ(hw_ver->cpu_ver_maj), hw_ver->ver_minor, - hw_ver->ver_update); + /* Select the corresponding CPU entry in the status table. */ + firmware = &tux_status.firmware[current_cpu]; + /* When returning 'information', the firmware starts by sending this + * version information which includes the cpu number (id). 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]); + /* 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 %i: %i.%i.%i", CPU_VER_CPU(current_cpu), + CPU_VER_MAJ(firmware->version_major), firmware->version_minor, + firmware->version_update); } -static void update_revision_table(const unsigned char *new_status) +/** + * Update tux_status with the given firmware revision data. + */ +static void update_firmware_revision(const unsigned char *data) { - unsigned long tmp; - revision_t *hw_rev; + struct firmware_version_t *firmware; + /* 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]; - tmp = (new_status[3] << 24) + (new_status[2] << 16) + (new_status[1] << 8) - + (new_status[0]); - hw_rev = (revision_t *)&tmp; - hw_revision[last_cpu_ver] = *hw_rev; - log_debug("revision of %i: %i", last_cpu_ver, hw_rev->revision); + log_debug("revision of %i: %i", current_cpu, firmware->revision); } -static void update_author_table(const unsigned char *new_status) +/** + * Update tux_status with the given firmware author data. + */ +static void update_firmware_author(const unsigned char *data) { - unsigned long tmp; - author_t *hw_aut; + struct firmware_version_t *firmware; + /* Select the corresponding CPU entry in the status table. */ + firmware = &tux_status.firmware[current_cpu]; + /* Save author. */ + firmware->author = (data[2] << 8) + data[1]; - tmp = (new_status[3] << 24) + (new_status[2] << 16) + (new_status[1] << 8) - + (new_status[0]); - hw_aut = (author_t *)&tmp; - hw_author[last_cpu_ver] = *hw_aut; - log_debug("author of %i: %i", last_cpu_ver, hw_aut->author_id); + log_debug("author of %i: %i", current_cpu, firmware->author); } -static void update_sound_flash_count(const unsigned char *new_status) +/** + * Update tux_status with the given properties of the sound flash. + */ +static void update_sound_flash_properties(const unsigned char *data) { - sound_flash_count = new_status[1]; - log_debug("%i sounds in flash", sound_flash_count); + tux_status.sound_flash.number_of_sounds = data[1]; + + log_debug("%i sounds in flash", tux_status.sound_flash.number_of_sounds); } static void update_ir(const unsigned char *new_status) @@ -605,7 +625,7 @@ if (new_status[3] == 0) light_level = light_level / 8 + 1000; /* 1128 is the maximum value when there is no light - * We substract here to represent the lightness instead of darkness + * We subtract here to represent the lightness instead of darkness */ light_level = 1128 - light_level; sensors2_changed(light_level); @@ -655,19 +675,19 @@ break; case VERSION_CMD: - update_version_table(new_status); + update_firmware_version(new_status); break; case REVISION_CMD: - update_revision_table(new_status); + update_firmware_revision(new_status); break; case AUTHOR_CMD: - update_author_table(new_status); + update_firmware_author(new_status); break; case SOUND_VAR_CMD: - update_sound_flash_count(new_status); + update_sound_flash_properties(new_status); break; case STATUS_IR_CMD: Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-11-08 09:36:40 UTC (rev 663) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-11-08 09:50:57 UTC (rev 664) @@ -274,6 +274,29 @@ extern author_t hw_author[4]; extern unsigned char sound_flash_count; +/** + * Tux status table. + * + * This hierarchical structure holds all available status of tux and the dongle. + */ +struct tux_status_t +{ + /** Firmware version numbers, svn revision and author. */ + struct firmware_version_t + { + int version_major; + int version_minor; + int version_update; + int revision; + int author; + } firmware[5]; + /** Sound flash properties. */ + struct sound_flash_t + { + int number_of_sounds; + } sound_flash; +}; + struct connection_status_t { /** USB request flag set when a USB command is issued and reset @@ -289,6 +312,8 @@ uint8_t wifi_channel; }; +extern struct tux_status_t tux_status; + extern struct connection_status_t connection_status; extern void update_raw_status_table(const unsigned char *new_status); |