[tuxdroid-svn] r724 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-26 15:39:12
|
Author: jaguarondi Date: 2007-11-26 16:38:58 +0100 (Mon, 26 Nov 2007) New Revision: 724 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: * CHARGER_LED_STATUS is now simply CHARGER_STATUS and represents now the charger state as defined in charger_status_t enum. Removed the charger inhibit status that was stull unused. * Added status and API for the sound flash but these values are still not sent by the firmware. * Now sending the release flag with the firmware version command. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-11-23 13:23:59 UTC (rev 723) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-11-26 15:38:58 UTC (rev 724) @@ -572,10 +572,6 @@ case DATA_STATUS_HEAD_PUSH_POSITION: result[1] = portb.bits.PB5; break; - case DATA_STATUS_CHARGER_INHIBIT_SIGNAL: - result[0] = DATA_STATUS_CHARGER_INHIBIT_SIGNAL; - result[1] = portb.bits.PB6; - break; case DATA_STATUS_WINGS_POSITION_SWITCH: result[1] = portc.bits.PB0; break; @@ -623,8 +619,8 @@ case DATA_STATUS_HEAD_PUSH_SWITCH: result[1] = sensors1.bits.PB3; break; - case DATA_STATUS_CHARGER_LED_STATUS: - result[1] = sensors1.bits.PB4; + case DATA_STATUS_CHARGER_STATUS: + result[1] = tux_status.battery.charger_state; break; case DATA_STATUS_MUTE_STATUS: result[1] = sensors1.bits.PB7; @@ -634,9 +630,9 @@ result[2] = sensors2.light_level % 256; break; case DATA_STATUS_BATTERY: - result[1] = battery.level / 256; - result[2] = battery.level % 256; - result[3] = battery.status; + result[1] = tux_status.battery.level / 256; + result[2] = tux_status.battery.level % 256; + result[3] = tux_status.battery.loaded; break; case DATA_STATUS_AUDIO: result[1] = audio.play; @@ -661,6 +657,12 @@ case DATA_STATUS_SOUND_COUNT: result[1] = tux_status.sound_flash.number_of_sounds; break; + case DATA_STATUS_FLASH_USAGE: + result[1] = tux_status.sound_flash.flash_usage; + break; + case DATA_STATUS_AVAILABLE_RECORD_TIME: + result[1] = tux_status.sound_flash.available_record_time; + break; } } @@ -1014,7 +1016,8 @@ /************************************************************************ */ static void tux_req_info(unsigned char const data[], unsigned char result[]) { - struct firmware_info_t const *const firmware = &tux_status.firmware_info[data[1]]; + struct firmware_info_t const *const firmware = + &tux_status.firmware_info[data[1]]; result[0] = data[0]; @@ -1027,6 +1030,7 @@ result[5] = (unsigned char)(firmware->revision & 0x00FF); result[6] = (unsigned char)((firmware->author& 0xFF00) >> 8); result[7] = (unsigned char)(firmware->author& 0x00FF); + result[8] = firmware->release; } } Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-11-23 13:23:59 UTC (rev 723) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-11-26 15:38:58 UTC (rev 724) @@ -22,6 +22,7 @@ /*_____________________ I N C L U D E S____________________________________ */ #include <stdio.h> +#include <stdbool.h> #include <assert.h> #include "USBDaemon_status_table.h" @@ -155,7 +156,8 @@ { tcp_frame[4] = DATA_STATUS_POWER_PLUG_SWITCH; tcp_frame[5] = !sensors1.bits.PB2; - log_debug("power plug insertion switch %s", tcp_frame[5] ? "off" : "on"); + log_debug("power plug insertion switch %s", + tcp_frame[5] ? "off" : "on"); tcp_server_send_raw(tcp_frame); } @@ -171,8 +173,22 @@ /* Led charger */ if ((sensors1.Byte & 0x10) != (new_value & 0x10)) { - tcp_frame[4] = DATA_STATUS_CHARGER_LED_STATUS; - tcp_frame[5] = sensors1.bits.PB4; + tcp_frame[4] = DATA_STATUS_CHARGER_STATUS; + + /* XXX should be removed when charger status will be added in firmware, + * now using this simplified status. */ + if (sensors1.bits.PB4) + { + tux_status.battery.charger_state = CHARGER_UNPLUGGED; + tcp_frame[5] = CHARGER_UNPLUGGED; + } + else + { + tux_status.battery.charger_state = CHARGER_CHARGING; + tcp_frame[5] = CHARGER_CHARGING; + } + + /*tcp_frame[5] = sensors1.bits.PB4;*/ log_debug("Charger led %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -209,7 +225,9 @@ tcp_server_send_raw(tcp_frame); } -static void battery_changed(int level, int status) +/* TODO Add functions to get the average battery voltage and status */ +static void battery_changed(unsigned int const level, + unsigned int const loaded) { tcp_frame_t tcp_frame; @@ -222,12 +240,12 @@ tcp_frame[4] = DATA_STATUS_BATTERY; - battery.level = level; - battery.status = status; + tux_status.battery.level = level; + tux_status.battery.loaded = loaded; tcp_frame[5] = level / 256; tcp_frame[6] = level % 256; - tcp_frame[7] = status; + tcp_frame[7] = loaded; tcp_server_send_raw(tcp_frame); } @@ -331,15 +349,6 @@ tcp_server_send_raw(tcp_frame); } - /* charger inhibit signal */ - if ((portb.Byte & 0x40) != (new_value & 0x40)) - { - tcp_frame[4] = DATA_STATUS_CHARGER_INHIBIT_SIGNAL; - tcp_frame[5] = !portb.bits.PB6; - log_debug("charger inhibit signal %d", tcp_frame[5]); - tcp_server_send_raw(tcp_frame); - } - portb.Byte = new_value; } @@ -650,7 +659,6 @@ new_status[2], new_status[3]); break; } - } /************************************************************************ */ Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-11-23 13:23:59 UTC (rev 723) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-11-26 15:38:58 UTC (rev 724) @@ -74,7 +74,7 @@ #define SUBDATA_TP_STATUS 0x03 #define SUBDATA_TP_INFO 0x04 -/* ------------------------------ ACK --------------------------------------// */ +/* ------------------------------ ACK -------------------------------------- */ /* ACK daemon processing */ #define ACK_DP_OK 0x01 @@ -92,7 +92,7 @@ #define ACK_CMD_NO_ACK 0x04 #define ACK_CMD_ERROR 0xFF -/* ----------------------------- Sub daemon const --------------------------// */ +/* ----------------------------- Sub daemon const -------------------------- */ /* Sub daemon commands */ #define SUB_D_CMD_STRUC_DISCONNECT_CLIENT 0x01 @@ -107,7 +107,7 @@ #define SUB_D_REQ_INFO_MY_CLIENT_ID 0x04 #define SUB_D_REQ_INFO_PID 0x05 -/* ----------------------------- TUX const ---------------------------------// */ +/* ----------------------------- TUX const --------------------------------- */ /* Tux structured commands */ #define TUX_CMD_STRUCT_EYES 0x01 @@ -151,7 +151,6 @@ #define DATA_STATUS_MOUTH_OPEN_POSITION 0x04 #define DATA_STATUS_MOUTH_CLOSED_POSITION 0x05 #define DATA_STATUS_HEAD_PUSH_POSITION 0x06 -#define DATA_STATUS_CHARGER_INHIBIT_SIGNAL 0x07 #define DATA_STATUS_WINGS_POSITION_SWITCH 0x08 #define DATA_STATUS_MOTOR_FOR_WINGS 0x09 #define DATA_STATUS_LEFT_BLUE_LED 0x0A @@ -169,7 +168,7 @@ #define DATA_STATUS_RIGHT_WING_PUSH 0x16 #define DATA_STATUS_POWER_PLUG_SWITCH 0x17 #define DATA_STATUS_HEAD_PUSH_SWITCH 0x18 -#define DATA_STATUS_CHARGER_LED_STATUS 0x19 +#define DATA_STATUS_CHARGER_STATUS 0x19 #define DATA_STATUS_MUTE_STATUS 0x1A #define DATA_STATUS_LIGHT_LEVEL 0x1B #define DATA_STATUS_EYES_POSITION_COUNTER 0x1C @@ -183,6 +182,8 @@ #define DATA_STATUS_PONG 0x24 #define DATA_STATUS_BATTERY 0x25 #define DATA_STATUS_AUDIO 0x26 +#define DATA_STATUS_FLASH_USAGE 0x27 +#define DATA_STATUS_AVAILABLE_RECORD_TIME 0x28 /* tux connection commands available on the usb dongle */ typedef enum @@ -204,7 +205,7 @@ TUX_CONNECTION_ACK = 1, TUX_CONNECTION_NOTFOUND = 2, } tux_connection_ack_t; -/* ------------------ Daemon to Application, frame construction ----------------- */ +/* ----------------- Daemon to Application, frame construction ------------ */ /*_____________________ T Y P E _ D E F ____________________________________*/ typedef unsigned char _BIT_; @@ -250,13 +251,6 @@ } sensors2; struct { - _PORT_BYTE_ level_high; - _PORT_BYTE_ level_low; - int status; - int level; -} battery; -struct -{ int play; int record; int status; @@ -289,33 +283,104 @@ /** Size of the version string. */ #define VERSION_STRING_LENGTH 100 +/** States of the battery charger */ +typedef enum charger_status +{ + CHARGER_UNPLUGGED, /**< unplugged, on batteries */ + CHARGER_CHARGING, /**< fast charge ongoing */ + CHARGER_PLUGGED_NO_POWER, /**< transformer plugged on tux but not in the + wall socket */ + CHARGER_TRICKLE, /**< trickle mode, mainly activated at the end of + charge */ + CHARGER_INHIBITED, /**< the CPU has inhibited the charger */ +} charger_status_t; + +/** States of the battery level */ +typedef enum battery_status +{ + FULL, + HIGH, + LOW, + EMPTY, +} battery_status_t; + +/** States of the audio recording (flash programming) process */ +typedef enum audiorec_status +{ + NOP, /**< XXX to be defined */ +} audiorec_status_t; + /** * Tux status table. * - * This hierarchical structure holds all available status of tux and the dongle. + * This hierarchical structure holds all available status of tux and the + * dongle. */ struct tux_status_t { - /** Firmware versioning , svn revision and author. */ + /** Firmware general information like versioning , svn revision, author and + * a couple more stuff. + * + * The version number is written as 'major.minor.update'. + * + * When local_modification or mixed_revisions are found, it can't be a + * release. */ struct firmware_info_t { - int version_major; - int version_minor; - int version_update; - int revision; - bool release; - bool local_modification; - bool mixed_revisions; - int author; - int variation; - char version_string[VERSION_STRING_LENGTH]; + unsigned int version_major; /**< Major version number */ + unsigned int version_minor; /**< Minor version number */ + unsigned int version_update;/**< Update version number */ + unsigned int revision; /**< SVN revision number */ + bool release; /**< Set for a released firmware */ + bool local_modification; /**< Has local modifications compared to + the SVN revision copy */ + bool mixed_revisions; /**< Has been compiled with a mix of SVN + revisions */ + unsigned int author;/**< Number representing the author of the + firmware, '0' is the official firmware of Kysoh */ + unsigned int variation; /**< Variation can be used by the author to + differentiate multiple variations of the + same firmware */ + char version_string[VERSION_STRING_LENGTH]; /**< Whole version number + stored as a string */ } firmware_info[NUMBER_OF_FIRMWARE]; + /** Sound flash properties. */ struct sound_flash_t { - int number_of_sounds; - int filled_space; + unsigned int number_of_sounds; /**< number of sounds stored in the + sound flash */ + unsigned int flash_usage; /**< flash space percentage filled */ + unsigned int available_record_time; /**< time (in seconds) of free + space remaining in the flash */ } sound_flash; + + /** Battery status. + * 'loaded' can be used to filter out 'level' measurements that occurred + * when the motors were running as the battery voltage is highly affected + * by the load. */ + struct + { + unsigned int level; /**< Last battery level measurement (raw data + from the ADC) */ + bool loaded; /**< Set if the battery was loaded when the + measurement was done (i.e. motors running). */ + float voltage; /**< Mean battery voltage */ + battery_status_t status;/**< Battery level status (low, high, etc.) */ + charger_status_t charger_state; /**<Battery charger state. */ + } battery; + + /** Audio status */ + struct audio_t + { + unsigned int play_internal_sound; /**< Number of the sound currently + playing ('0' when none) */ + bool streaming; /**< Set when audio data is streamed through the RF + link */ + bool mute; /**< Set when the amplifier has been muted */ + audiorec_status_t record_state; /**< XXX need to define the enum for + the states */ + } audio; }; /** |