unflasher.cpp
Go to the documentation of this file.
00001 
00013 #include <iostream>
00014 
00015 #include "../include/kobuki_ftdi/scanner.hpp"
00016 #include "../include/kobuki_ftdi/writer.hpp"
00017 
00018 int main(int argc, char** argv)
00019 {
00020   int ret_val;
00021   FTDI_Scanner scanner;
00022   FTDI_Writer writer;
00023 
00024 
00025   /*-------- 1 --------
00026          SCANNING
00027     -------- 1 --------*/
00028   // check and find ftdi device
00029   ret_val = scanner.scan();
00030   if( ret_val < 0 )
00031   {
00032     std::cerr << "not found!!!" << std::endl;
00033     return -1; // if not found
00034   }
00035   unsigned int no_devices = (unsigned)ret_val;
00036 
00037 
00038   /*-------- 2 --------
00039           WRITING
00040     -------- 2 --------*/
00041   for (unsigned int i=0; i<no_devices; i++) {
00042     // get serial id
00043     std::string serial_id;
00044     ret_val = scanner.get_serial_id(i, serial_id);
00045     if (ret_val == -2) {
00046       std::cout << ret_val << ": ";
00047       std::cout << "failed to get serial_id. did you run with sudo?" << std::endl;
00048       return -2; // if failed to get serial id
00049     }
00050     if (ret_val == -1) {
00051       std::cout << ret_val << ": ";
00052       std::cout << "Something went wrong." << std::endl;
00053       return -1;
00054     }
00055 
00056     //writing kobuki as serial id
00057     if( serial_id.substr(0,6) != std::string("kobuki") ) 
00058     {
00059       std::cout << "Not flashed yet [" << serial_id << "]." << std::endl;
00060       //return 1; // if not flashed yet
00061       continue;
00062     }
00063 
00064     std::string new_id = serial_id.substr(7); // Removes first 7 character
00065     // find the device that serial nummber is 'serial_id', and replace it with 'new_id.substr(0,20)'
00066     ret_val = writer.write( serial_id, new_id, "FTDI", "USB Serial Converter" );
00067     if (ret_val < 0) {
00068       std::cout << ret_val << ": ";
00069       std::cout << "Something went wrong." << std::endl;
00070       return -1; // if failed to writing kobuki
00071     }
00072   }
00073 
00074 
00075   /*-------- 3 --------
00076          RESETTING
00077     -------- 3 --------*/
00078   //std::cout << "done." << std::endl;
00079   ret_val = scanner.reset();
00080   if (ret_val < 0 && ret_val != -19) {
00081     std::cout << ret_val << ": ";
00082     std::cout << "Something went wrong." << std::endl;
00083     return -1; // if failed to reset ftdi chip
00084   }
00085   return 0; // if success to reset.
00086 }


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