53 #define REQUEST_EEPROM_SIZE 0
69 bool decode(
unsigned char* eeprom_binary,
const int &size) {
71 std::cout <<
" Decoding into eeprom structure." << std::endl;
73 if ( ftdi_eeprom_decode(&eeprom, eeprom_binary, size) != 0 ) {
76 std::cout <<
"Eeprom:" << std::endl;
77 std::cout <<
" Manufacturer: " << eeprom.manufacturer << std::endl;
78 std::cout <<
" Product : " << eeprom.product << std::endl;
79 std::cout <<
" Vendor Id : " << eeprom.vendor_id << std::endl;
80 std::cout <<
" Product Id : " << eeprom.product_id << std::endl;
81 std::cout <<
" Serial Id : " << eeprom.serial << std::endl;
82 std::cout <<
" Self Powered: " << eeprom.self_powered << std::endl;
83 std::cout <<
" Remote Wake : " << eeprom.remote_wakeup << std::endl;
84 std::cout <<
" Use Serial : " << eeprom.use_serial << std::endl;
85 std::cout <<
" In Iso : " << eeprom.in_is_isochronous << std::endl;
86 std::cout <<
" Out Iso : " << eeprom.out_is_isochronous << std::endl;
87 std::cout <<
" Suspend : " << eeprom.suspend_pull_downs << std::endl;
88 std::cout <<
" Max Power : " << eeprom.max_power << std::endl;
89 std::cout <<
" Chip Type : " << eeprom.chip_type << std::endl;
96 int main(
int argc,
char **argv)
98 const int vendor_id = 0x0403;
99 const int product_id = 0x6001;
104 CmdLine cmd_line(
"This is used to read an eeprom on an ftdi device.",
' ',
"0.1");
106 "s",
"serial",
"Identify the device via the old serial id (if there are multiple attached) ['unspecified'].",
false,
107 "unspecified",
"string");
108 cmd_line.
add(serial_arg);
109 cmd_line.
parse(argc, argv);
110 bool using_serial_id =
false;
112 if (serial_arg.
getValue() !=
"unspecified")
114 using_serial_id =
true;
121 std::cout <<
"Input Information" << std::endl;
122 if (!using_serial_id)
124 std::cout <<
" Serial id: unused (first device found.)" << std::endl;
128 std::cout <<
" Serial id: " << serial_id << std::endl;
134 struct ftdi_context ftdi;
135 if (ftdi_init(&ftdi) < 0)
137 std::cerr <<
"ftdi_init failed" << std::endl;
140 if (!using_serial_id)
142 if (ftdi_usb_open(&ftdi, vendor_id, product_id) != 0)
144 std::cerr <<
"Couldn't find/open an ftdi device [" << ftdi.error_str <<
"]" << std::endl;
150 if (ftdi_usb_open_desc(&ftdi, vendor_id, product_id, NULL, serial_id.c_str()) < 0)
152 std::cerr <<
"Couldn't open the device with serial id string: " << serial_id << std::endl;
159 std::cout <<
"Eeprom Binary" << std::endl;
160 unsigned char eeprom_binary[512];
161 int size = ftdi_read_eeprom_getsize(&ftdi, eeprom_binary, 512);
164 std::cerr <<
"Error: Could not read the eeprom from the requested device." << std::endl;
167 std::cout <<
" Read binary [" << size <<
" bytes]." << std::endl;
168 std::cout <<
" Write binary [eeprom.req]." << std::endl;
169 FILE *fp = fopen (
"eeprom.req",
"wb");
170 fwrite (&eeprom_binary, 1, size, fp);
173 if ( !
decode(eeprom_binary, size) ) {
174 std::cerr <<
"Error: Could not write raw binary eeprom into the eeprom structure." << std::endl;
178 #if REQUEST_EEPROM_SIZE
184 int result = ftdi_read_eeprom(&ftdi,eeprom_binary);
186 std::cerr <<
"Error: Could not read the eeprom from the requested device." << std::endl;
189 fp = fopen (
"eeprom.fix",
"wb");
190 fwrite (&eeprom_binary, 1, size, fp);
192 std::cout <<
" Write binary [eeprom.fix]." << std::endl;
194 if ( !
decode(eeprom_binary, size) ) {
195 std::cerr <<
"Error: Could not write raw binary eeprom into the eeprom structure." << std::endl;
199 std::cout <<
"Done." << std::endl;