overwrite_serial_number.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Yujin Robot.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Yujin Robot nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
37 /*****************************************************************************
38  ** Includes
39  *****************************************************************************/
40 
41 #include <iostream>
42 #include <ecl/command_line.hpp>
43 #include "kobuki_ftdi/writer.hpp"
44 #include "kobuki_ftdi/scanner.hpp"
45 
46 /*****************************************************************************
47  ** Using
48  *****************************************************************************/
49 
50 using ecl::CmdLine;
52 using ecl::ValueArg;
53 using ecl::SwitchArg;
54 using std::string;
55 
56 /*****************************************************************************
57  ** Main
58  *****************************************************************************/
59 
60 int main(int argc, char **argv)
61 {
62  /*********************
63  ** Parse Command Line
64  **********************/
65  CmdLine cmd_line("This is used to write a new serial id string to the ftdi device.", ' ', "0.1");
66  ValueArg<std::string> old_arg(
67  "o", "old", "Identify the device via the old serial id (if there are multiple devices attached) ['unspecified'].", false,
68  "unspecified", "string");
69  UnlabeledValueArg<std::string> new_arg("new_id", "New serial id used to identify the device [xxx].", true,
70  "xxx", "string");
71  cmd_line.add(old_arg);
72  cmd_line.add(new_arg);
73  cmd_line.parse(argc, argv);
74  bool using_old_id = false;
75  string old_id;
76  if (old_arg.getValue() != "unspecified")
77  {
78  using_old_id = true;
79  old_id = old_arg.getValue();
80  }
81  string new_id = new_arg.getValue();
82 
83 
84  /*********************
85  ** Debug output
86  **********************/
87  std::cout << "Input Information" << std::endl;
88  if (!using_old_id)
89  {
90  std::cout << " Old id: unused (first device found.)" << std::endl;
91  }
92  else
93  {
94  std::cout << " Old id: " << old_id << std::endl;
95  }
96  std::cout << " New id: " << new_id << std::endl;
97 
98 
99  /*********************
100  ** Writing serial id
101  **********************/
102  FTDI_Writer writer;
103  int ret_val = 0;
104  ret_val = writer.write(new_id);
105  if (ret_val<0) {
106  std::cerr << "Something went wrong." << std::endl;
107  return ret_val;
108  }
109 
110  FTDI_Scanner scanner;
111  ret_val = scanner.reset();
112  if (ret_val<0 && ret_val !=-19) {
113  std::cerr << "Something went wrong." << std::endl;
114  return ret_val;
115  }
116 
117  std::cout << "ret_val: " << ret_val << std::endl;
118  return 0;
119 }
120 
int write(const std::string &new_id_)
Definition: writer.hpp:81
void add(Arg &a)
A Writer class.
Definition: writer.hpp:52
int reset()
Definition: scanner.hpp:211
Provides common modulde for wrting serial number and other data into the eeprom of ftdi chip...
void parse(int argc, char **argv)
A Scanner class.
Definition: scanner.hpp:56
int main(int argc, char **argv)
Scan the usb devices, and retrieve its serial id and else descriptions, especially for ftdi devices...


kobuki_ftdi
Author(s): Younghun Ju
autogenerated on Mon Jun 10 2019 13:41:32