Changeset 320

Show
Ignore:
Timestamp:
11/06/06 12:49:46 (16 years ago)
Author:
wagi
Message:

setting volume works as implemented

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libfreebob/src/libfreebobavc/avc_feature_function_block.cpp

    r319 r320  
    5555    bStatus &= se.write( m_controlSelector,    "FeatureFunctionBlockVolume controlSelector" ); 
    5656    bStatus &= se.write( m_controlDataLength,  "FeatureFunctionBlockVolume controlDataLength" ); 
    57     val = m_volume >> 16
     57    val = (byte_t)(m_volume >> 8)
    5858    bStatus &= se.write( val,                  "FeatureFunctionBlockVolume volume high" ); 
    5959    val = m_volume & 0xff; 
     
    7373    bStatus = de.read( &m_controlDataLength ); 
    7474    bStatus = de.read( &val ); 
    75     m_volume = val << 16
     75    m_volume = val << 8
    7676    bStatus = de.read( &val ); 
    7777    m_volume |= val; 
     
    9191FeatureFunctionBlockCmd::FeatureFunctionBlockCmd( Ieee1394Service* ieee1394service ) 
    9292    : AVCCommand( ieee1394service, AVC1394_FUNCTION_BLOCK_CMD ) 
    93     , m_functionBlockType( eFCS_Volume ) 
     93    , m_functionBlockType( 0x81 ) // feature function block 
    9494    , m_functionBlockId( 0xff ) 
    9595    , m_controlAttribute( eCA_Current ) 
  • trunk/libfreebob/tests/test-volume.cpp

    r319 r320  
    2323#include "libfreebobavc/ieee1394service.h" 
    2424 
    25 #include <argp.h> 
    26  
    27 using namespace std; 
    28  
    29 //////////////////////////////////////////////// 
    30 // arg parsing 
    31 //////////////////////////////////////////////// 
    32 const char *argp_program_version = "test-volume 0.1"; 
    33 const char *argp_program_bug_address = "<freebob-devel@lists.sf.net>"; 
    34 static char doc[] = "test-extplugcmd -- tests some extended plug info commands on a BeBoB device"; 
    35 static char args_doc[] = "NODE_ID FFB_ID VOL"; 
    36 static struct argp_option options[] = { 
    37     {"verbose",   'v', 0,           0,  "Produce verbose output" }, 
    38     {"port",      'p', "PORT",      0,  "Set port" }, 
    39    { 0 } 
    40 }; 
    41  
    42 struct arguments 
     25short int getMaxVolume(Ieee1394Service& ieee1394service, int node_id, int ffb_id) 
    4326{ 
    44     arguments() 
    45         : verbose( false ) 
    46         , test( false ) 
    47         , port( 0 ) 
    48         { 
    49             args[0] = 0; 
    50         } 
    51  
    52     char* args[3]; 
    53     bool  verbose; 
    54     bool  test; 
    55     int   port; 
    56 } arguments; 
    57  
    58 // Parse a single option. 
    59 static error_t 
    60 parse_opt( int key, char* arg, struct argp_state* state ) 
    61 
    62     // Get the input argument from `argp_parse', which we 
    63     // know is a pointer to our arguments structure. 
    64     struct arguments* arguments = ( struct arguments* ) state->input; 
    65  
    66     char* tail; 
    67     switch (key) { 
    68     case 'v': 
    69         arguments->verbose = true; 
    70         break; 
    71     case 't': 
    72         arguments->test = true; 
    73         break; 
    74     case 'p': 
    75         errno = 0; 
    76         arguments->port = strtol(arg, &tail, 0); 
    77         if (errno) { 
    78             perror("argument parsing failed:"); 
    79             return errno; 
    80         } 
    81         break; 
    82     case ARGP_KEY_ARG: 
    83         if (state->arg_num >= 3) { 
    84             // Too many arguments. 
    85             argp_usage (state); 
    86         } 
    87         arguments->args[state->arg_num] = arg; 
    88         break; 
    89     case ARGP_KEY_END: 
    90         if (state->arg_num < 3 ) { 
    91             // Not enough arguments. 
    92             argp_usage (state); 
    93         } 
    94         break; 
    95     default: 
    96         return ARGP_ERR_UNKNOWN; 
     27    FeatureFunctionBlockCmd ffbCmd( &ieee1394service ); 
     28    ffbCmd.setNodeId( node_id ); 
     29    ffbCmd.setSubunitId( 0x00 ); 
     30    ffbCmd.setCommandType( AVCCommand::eCT_Status ); 
     31    ffbCmd.setFunctionBlockId( ffb_id ); 
     32    ffbCmd.setControlAttribute(FeatureFunctionBlockCmd::eCA_Maximum); 
     33         
     34    if ( !ffbCmd.fire() ) { 
     35        printf( "cmd failed\n" ); 
    9736    } 
    98     return 0
     37    return ffbCmd.m_volumeControl.m_volume
    9938} 
    10039 
    101 static struct argp argp = { options, parse_opt, args_doc, doc }; 
     40short int getMinVolume(Ieee1394Service& ieee1394service, int node_id, int ffb_id) 
     41
     42    FeatureFunctionBlockCmd ffbCmd( &ieee1394service ); 
     43    ffbCmd.setNodeId( node_id ); 
     44    ffbCmd.setSubunitId( 0x00 ); 
     45    ffbCmd.setCommandType( AVCCommand::eCT_Status ); 
     46    ffbCmd.setFunctionBlockId( ffb_id ); 
     47    ffbCmd.setControlAttribute(FeatureFunctionBlockCmd::eCA_Minimum); 
    10248 
    103 //////////////////////////////////////// 
    104 // Application 
    105 //////////////////////////////////////// 
     49    if ( !ffbCmd.fire() ) { 
     50        printf( "cmd failed\n" ); 
     51    } 
     52    return ffbCmd.m_volumeControl.m_volume; 
     53
     54 
     55short int getCurrentVolume(Ieee1394Service& ieee1394service, int node_id, int ffb_id) 
     56
     57    FeatureFunctionBlockCmd ffbCmd( &ieee1394service ); 
     58    ffbCmd.setNodeId( node_id ); 
     59    ffbCmd.setSubunitId( 0x00 ); 
     60    ffbCmd.setCommandType( AVCCommand::eCT_Status ); 
     61    ffbCmd.setFunctionBlockId( ffb_id ); 
     62 
     63    if ( !ffbCmd.fire() ) { 
     64        printf( "cmd failed\n" ); 
     65    } 
     66    return ffbCmd.m_volumeControl.m_volume; 
     67
    10668 
    10769bool 
    10870doApp(Ieee1394Service& ieee1394service, int node_id, int ffb_id, int vol ) 
    10971{ 
     72    short int maxVolume = getMaxVolume(ieee1394service, node_id, ffb_id); 
     73    short int minVolume = getMinVolume(ieee1394service, node_id, ffb_id); 
     74 
     75    printf("max volume value = %d\n", maxVolume); 
     76    printf("min volume value = %d\n", minVolume); 
     77 
     78    short int volume = getCurrentVolume(ieee1394service, node_id, ffb_id); 
     79    printf("old volume value = %d\n", volume); 
     80 
    11081    FeatureFunctionBlockCmd ffbCmd( &ieee1394service ); 
    11182    ffbCmd.setNodeId( node_id ); 
    112     ffbCmd.setSubunitId( 0x01 ); 
     83    ffbCmd.setSubunitId( 0x00 ); 
    11384    ffbCmd.setCommandType( AVCCommand::eCT_Control ); 
    11485    ffbCmd.setFunctionBlockId( ffb_id ); 
    11586    ffbCmd.m_volumeControl.m_volume = vol; 
    11687 
    117     ffbCmd.setVerbose( arguments.verbose ); 
    11888    if ( !ffbCmd.fire() ) { 
    11989        printf( "cmd failed\n" ); 
    12090    } 
    121     CoutSerializer se; 
    122     ffbCmd.serialize( se ); 
     91 
     92    volume = getCurrentVolume(ieee1394service, node_id, ffb_id); 
     93    printf("new volume value = %d\n", volume); 
     94 
    12395    return true; 
    12496} 
     
    130102main(int argc, char **argv) 
    131103{ 
    132     // arg parsing 
    133     argp_parse( &argp, argc, argv, 0, 0, &arguments ); 
    134104 
    135     errno = 0; 
     105    if (argc < 3) { 
     106        printf("usage: NODE_ID FFB_ID VOL\n"); 
     107        exit(0); 
     108    } 
     109 
     110    int errno = 0; 
    136111    char* tail; 
    137     int node_id = strtol( arguments.args[0], &tail, 0 ); 
    138     int ffb_id  = strtol( arguments.args[1], &tail, 0 ); 
    139     int vol     = strtol( arguments.args[2], &tail, 0 ); 
     112    int node_id = strtol( argv[1], &tail, 0 ); 
     113    int ffb_id  = strtol( argv[2], &tail, 0 ); 
     114    int vol     = strtol( argv[3], &tail, 0 ); 
    140115 
    141116    if (errno) { 
     
    144119    } 
    145120    Ieee1394Service ieee1394service; 
    146     if ( !ieee1394service.initialize( arguments.port ) ) { 
     121    if ( !ieee1394service.initialize( 0 ) ) { 
    147122        fprintf( stderr, "could not set port on ieee1394service\n" ); 
    148123        return -1;