overwrite_serial_number.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Yujin Robot.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Yujin Robot nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00037 /*****************************************************************************
00038  ** Includes
00039  *****************************************************************************/
00040 
00041 #include <iostream>
00042 #include <ecl/command_line.hpp>
00043 #include "kobuki_ftdi/writer.hpp"
00044 #include "kobuki_ftdi/scanner.hpp"
00045 
00046 /*****************************************************************************
00047  ** Using
00048  *****************************************************************************/
00049 
00050 using ecl::CmdLine;
00051 using ecl::UnlabeledValueArg;
00052 using ecl::ValueArg;
00053 using ecl::SwitchArg;
00054 using std::string;
00055 
00056 /*****************************************************************************
00057  ** Main
00058  *****************************************************************************/
00059 
00060 int main(int argc, char **argv)
00061 {
00062   /*********************
00063    ** Parse Command Line
00064    **********************/
00065   CmdLine cmd_line("This is used to write a new serial id string to the ftdi device.", ' ', "0.1");
00066   ValueArg<std::string> old_arg(
00067       "o", "old", "Identify the device via the old serial id (if there are multiple devices attached) ['unspecified'].", false,
00068       "unspecified", "string");
00069   UnlabeledValueArg<std::string> new_arg("new_id", "New serial id used to identify the device [xxx].", true,
00070                                          "xxx", "string");
00071   cmd_line.add(old_arg);
00072   cmd_line.add(new_arg);
00073   cmd_line.parse(argc, argv);
00074   bool using_old_id = false;
00075   string old_id;
00076   if (old_arg.getValue() != "unspecified")
00077   {
00078     using_old_id = true;
00079     old_id = old_arg.getValue();
00080   }
00081   string new_id = new_arg.getValue();
00082 
00083 
00084   /*********************
00085    ** Debug output
00086    **********************/
00087   std::cout << "Input Information" << std::endl;
00088   if (!using_old_id)
00089   {
00090     std::cout << "  Old id: unused (first device found.)" << std::endl;
00091   }
00092   else
00093   {
00094     std::cout << "  Old id: " << old_id << std::endl;
00095   }
00096   std::cout << "  New id: " << new_id << std::endl;
00097 
00098 
00099   /*********************
00100    ** Writing serial id
00101    **********************/
00102   FTDI_Writer writer;
00103   int ret_val = 0;
00104   ret_val = writer.write(new_id);
00105   if (ret_val<0) {
00106     std::cerr << "Something went wrong." << std::endl;
00107     return ret_val;
00108   }
00109 
00110   FTDI_Scanner scanner;
00111   ret_val = scanner.reset();
00112   if (ret_val<0 && ret_val !=-19) {
00113     std::cerr << "Something went wrong." << std::endl;
00114     return ret_val;
00115   }
00116 
00117   std::cout << "ret_val: " << ret_val << std::endl;
00118   return 0;
00119 }
00120 


kobuki_ftdi
Author(s): Younghun Ju
autogenerated on Mon Oct 6 2014 01:31:47