unflasher.cpp
Go to the documentation of this file.
1 
13 #include <iostream>
14 
15 #include "../include/kobuki_ftdi/scanner.hpp"
16 #include "../include/kobuki_ftdi/writer.hpp"
17 
18 int main(int argc, char** argv)
19 {
20  int ret_val;
21  FTDI_Scanner scanner;
22  FTDI_Writer writer;
23 
24 
25  /*-------- 1 --------
26  SCANNING
27  -------- 1 --------*/
28  // check and find ftdi device
29  ret_val = scanner.scan();
30  if( ret_val < 0 )
31  {
32  std::cerr << "not found!!!" << std::endl;
33  return -1; // if not found
34  }
35  unsigned int no_devices = (unsigned)ret_val;
36 
37 
38  /*-------- 2 --------
39  WRITING
40  -------- 2 --------*/
41  for (unsigned int i=0; i<no_devices; i++) {
42  // get serial id
43  std::string serial_id;
44  ret_val = scanner.get_serial_id(i, serial_id);
45  if (ret_val == -2) {
46  std::cout << ret_val << ": ";
47  std::cout << "failed to get serial_id. did you run with sudo?" << std::endl;
48  return -2; // if failed to get serial id
49  }
50  if (ret_val == -1) {
51  std::cout << ret_val << ": ";
52  std::cout << "Something went wrong." << std::endl;
53  return -1;
54  }
55 
56  //writing kobuki as serial id
57  if( serial_id.substr(0,6) != std::string("kobuki") )
58  {
59  std::cout << "Not flashed yet [" << serial_id << "]." << std::endl;
60  //return 1; // if not flashed yet
61  continue;
62  }
63 
64  std::string new_id = serial_id.substr(7); // Removes first 7 character
65  // find the device that serial nummber is 'serial_id', and replace it with 'new_id.substr(0,20)'
66  ret_val = writer.write( serial_id, new_id, "FTDI", "USB Serial Converter" );
67  if (ret_val < 0) {
68  std::cout << ret_val << ": ";
69  std::cout << "Something went wrong." << std::endl;
70  return -1; // if failed to writing kobuki
71  }
72  }
73 
74 
75  /*-------- 3 --------
76  RESETTING
77  -------- 3 --------*/
78  //std::cout << "done." << std::endl;
79  ret_val = scanner.reset();
80  if (ret_val < 0 && ret_val != -19) {
81  std::cout << ret_val << ": ";
82  std::cout << "Something went wrong." << std::endl;
83  return -1; // if failed to reset ftdi chip
84  }
85  return 0; // if success to reset.
86 }
FTDI_Scanner::reset
int reset()
Definition: scanner.hpp:215
FTDI_Scanner::scan
int scan()
Definition: scanner.hpp:93
FTDI_Writer
A Writer class.
Definition: writer.hpp:52
main
int main(int argc, char **argv)
Definition: unflasher.cpp:18
FTDI_Scanner::get_serial_id
int get_serial_id(unsigned int index, std::string &serial_id)
Definition: scanner.hpp:147
FTDI_Writer::write
int write(const std::string &new_id_)
Definition: writer.hpp:87
FTDI_Scanner
A Scanner class.
Definition: scanner.hpp:56


kobuki_ftdi
Author(s): Younghun Ju
autogenerated on Wed Mar 2 2022 00:26:19