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
00026
00027
00028
00029 ret_val = scanner.scan();
00030 if( ret_val < 0 )
00031 {
00032 std::cerr << "not found!!!" << std::endl;
00033 return -1;
00034 }
00035 unsigned int no_devices = (unsigned)ret_val;
00036
00037
00038
00039
00040
00041 for (unsigned int i=0; i<no_devices; i++) {
00042
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;
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
00057 if( serial_id.substr(0,6) != std::string("kobuki") )
00058 {
00059 std::cout << "Not flashed yet [" << serial_id << "]." << std::endl;
00060
00061 continue;
00062 }
00063
00064 std::string new_id = serial_id.substr(7);
00065
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;
00071 }
00072 }
00073
00074
00075
00076
00077
00078
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;
00084 }
00085 return 0;
00086 }