tool/CommandFoeRead.cpp
changeset 1804 742607c464c4
parent 1363 11c0b2caa253
child 1826 ec6223c3b7ec
equal deleted inserted replaced
1803:5b04770444df 1804:742607c464c4
    48 string CommandFoeRead::helpString() const
    48 string CommandFoeRead::helpString() const
    49 {
    49 {
    50     stringstream str;
    50     stringstream str;
    51 
    51 
    52     str << getName() << " [OPTIONS] <SOURCEFILE>" << endl
    52     str << getName() << " [OPTIONS] <SOURCEFILE>" << endl
    53     	<< endl
    53         << endl
    54     	<< getBriefDescription() << endl
    54         << getBriefDescription() << endl
    55     	<< endl
    55         << endl
    56         << "This command requires a single slave to be selected." << endl
    56         << "This command requires a single slave to be selected." << endl
    57     	<< endl
    57         << endl
    58         << "Arguments:" << endl
    58         << "Arguments:" << endl
    59         << "  SOURCEFILE is the name of the source file on the slave." << endl
    59         << "  SOURCEFILE is the name of the source file on the slave." << endl
    60         << endl
    60         << endl
    61     	<< "Command-specific options:" << endl
    61         << "Command-specific options:" << endl
    62         << "  --output-file -o <file>   Local target filename. If" << endl
    62         << "  --output-file -o <file>   Local target filename. If" << endl
    63         << "                            '-' (default), data are" << endl
    63         << "                            '-' (default), data are" << endl
    64         << "                            printed to stdout." << endl
    64         << "                            printed to stdout." << endl
    65         << "  --alias       -a <alias>  " << endl
    65         << "  --alias       -a <alias>  " << endl
    66         << "  --position    -p <pos>    Slave selection. See the help" << endl
    66         << "  --position    -p <pos>    Slave selection. See the help" << endl
    67         << "                            of the 'slaves' command." << endl
    67         << "                            of the 'slaves' command." << endl
    68     	<< endl
    68         << endl
    69 		<< numericInfo();
    69         << numericInfo();
    70 
    70 
    71 	return str.str();
    71     return str.str();
    72 }
    72 }
    73 
    73 
    74 /****************************************************************************/
    74 /****************************************************************************/
    75 
    75 
    76 void CommandFoeRead::execute(MasterDevice &m, const StringVector &args)
    76 void CommandFoeRead::execute(MasterDevice &m, const StringVector &args)
   102     data.buffer_size = 0x8800;
   102     data.buffer_size = 0x8800;
   103     data.buffer = new uint8_t[data.buffer_size];
   103     data.buffer = new uint8_t[data.buffer_size];
   104 
   104 
   105     strncpy(data.file_name, args[0].c_str(), sizeof(data.file_name));
   105     strncpy(data.file_name, args[0].c_str(), sizeof(data.file_name));
   106 
   106 
   107 	try {
   107     try {
   108 		m.readFoe(&data);
   108         m.readFoe(&data);
   109 	} catch (MasterDeviceException &e) {
   109     } catch (MasterDeviceException &e) {
   110         delete [] data.buffer;
   110         delete [] data.buffer;
   111         if (data.result) {
   111         if (data.result) {
   112             if (data.result == FOE_OPCODE_ERROR) {
   112             if (data.result == FOE_OPCODE_ERROR) {
   113                 err << "FoE read aborted with error code 0x"
   113                 err << "FoE read aborted with error code 0x"
   114                     << setw(8) << setfill('0') << hex << data.error_code
   114                     << setw(8) << setfill('0') << hex << data.error_code
   119             }
   119             }
   120             throwCommandException(err);
   120             throwCommandException(err);
   121         } else {
   121         } else {
   122             throw e;
   122             throw e;
   123         }
   123         }
   124 	}
   124     }
   125 
   125 
   126     // TODO --output-file
   126     // TODO --output-file
   127 	for (i = 0; i < data.data_size; i++) {
   127     for (i = 0; i < data.data_size; i++) {
   128 		uint8_t *w = data.buffer + i;
   128         uint8_t *w = data.buffer + i;
   129 		cout << *(uint8_t *) w ;
   129         cout << *(uint8_t *) w ;
   130 	}
   130     }
   131 
   131 
   132     delete [] data.buffer;
   132     delete [] data.buffer;
   133 }
   133 }
   134 
   134 
   135 /*****************************************************************************/
   135 /*****************************************************************************/