tool/CommandSiiWrite.cpp
changeset 1157 04d1c950cf9d
parent 1155 bd4e5b544473
child 1161 d1324ac71232
equal deleted inserted replaced
1156:ecaf2a896ea3 1157:04d1c950cf9d
    28 
    28 
    29     str << getName() << " [OPTIONS] <FILENAME>" << endl
    29     str << getName() << " [OPTIONS] <FILENAME>" << endl
    30         << endl 
    30         << endl 
    31         << getBriefDescription() << endl
    31         << getBriefDescription() << endl
    32         << endl
    32         << endl
       
    33         << "This command requires a single slave to be selected." << endl
       
    34     	<< endl
    33         << "The file contents are checked for validity and integrity." << endl
    35         << "The file contents are checked for validity and integrity." << endl
    34         << "These checks can be overridden with the --force option." << endl
    36         << "These checks can be overridden with the --force option." << endl
    35         << endl
    37         << endl
    36         << "Arguments:" << endl
    38         << "Arguments:" << endl
    37         << "  FILENAME must be a path to a file that contains a" << endl
    39         << "  FILENAME must be a path to a file that contains a" << endl
    38         << "           positive number of words." << endl
    40         << "           positive number of words." << endl
    39         << endl
    41         << endl
    40         << "Command-specific options:" << endl
    42         << "Command-specific options:" << endl
    41         << "  --slave -s <index>  Positive numerical ring position" << endl
    43         << "  --alias    -a <alias>" << endl
    42         << "                      (mandatory)." << endl
    44         << "  --position -p <pos>    Slave selection. See the help of" << endl
    43         << "  --force -f          Override validity checks." << endl
    45         << "                         the 'slaves' command." << endl
       
    46         << "  --force    -f          Override validity checks." << endl
    44         << endl
    47         << endl
    45         << numericInfo();
    48         << numericInfo();
    46 
    49 
    47     return str.str();
    50     return str.str();
    48 }
    51 }
    57     ifstream file;
    60     ifstream file;
    58     unsigned int byte_size;
    61     unsigned int byte_size;
    59     const uint16_t *categoryHeader;
    62     const uint16_t *categoryHeader;
    60     uint16_t categoryType, categorySize;
    63     uint16_t categoryType, categorySize;
    61     uint8_t crc;
    64     uint8_t crc;
    62 
       
    63     slaves = selectedSlaves(m);
       
    64 
       
    65     if (slaves.size() != 1) {
       
    66         throwSingleSlaveRequired(slaves.size());
       
    67     }
       
    68     data.slave_position = slaves.front().position;
       
    69 
    65 
    70     if (args.size() != 1) {
    66     if (args.size() != 1) {
    71         err << "'" << getName() << "' takes exactly one argument!";
    67         err << "'" << getName() << "' takes exactly one argument!";
    72         throwInvalidUsageException(err);
    68         throwInvalidUsageException(err);
    73     }
    69     }
   129             categoryHeader += 2 + categorySize;
   125             categoryHeader += 2 + categorySize;
   130             categoryType = le16tocpu(*categoryHeader);
   126             categoryType = le16tocpu(*categoryHeader);
   131         }
   127         }
   132     }
   128     }
   133 
   129 
       
   130     m.open(MasterDevice::ReadWrite);
       
   131     slaves = selectedSlaves(m);
       
   132     if (slaves.size() != 1) {
       
   133         throwSingleSlaveRequired(slaves.size());
       
   134     }
       
   135     data.slave_position = slaves.front().position;
       
   136 
   134     // send data to master
   137     // send data to master
   135     m.open(MasterDevice::ReadWrite);
       
   136     data.offset = 0;
   138     data.offset = 0;
   137 	m.writeSii(&data);
   139 	m.writeSii(&data);
   138 }
   140 }
   139 
   141 
   140 /*****************************************************************************/
   142 /*****************************************************************************/