83 int write(
const std::string &new_id_) {
86 int ret_val =
write(
"", new_id_,
"",
"");
99 int write(
const std::string &old_id_,
const std::string &new_id_)
102 int ret_val =
write(old_id_, new_id_,
"",
"");
117 int write(
const std::string &old_id_,
const std::string &new_id_,
const std::string &manufacturer_,
const std::string &product_)
121 struct ftdi_context ftdic;
129 if (ftdi_init(&ftdic) < 0)
131 std::cerr <<
"ftdi_init failed" << std::endl;
151 if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128)) < 0)
153 std::cerr <<
"ftdi_usb_get_strings failed: " << ftdi_get_error_string(&ftdic) <<
"." << std::endl;
163 std::cout <<
" Manufacturer: " << manufacturer << std::endl;
164 std::cout <<
" Description : " << description << std::endl;
165 std::cout <<
" Serial Id : " << serial << std::endl;
166 std::cout << std::endl;
169 std::cout <<
"It is not intedend target." << std::endl;
170 std::cout <<
"target: " << old_id_ <<
", current: " << serial << std::endl;
171 curdev = curdev->next;
179 std::cerr <<
"Couldn't find/open a ftdi device." << std::endl;
185 std::cerr <<
"Couldn't open the device with serial id string " << old_id_ << std::endl;
193 unsigned char eeprom_binary[512];
194 int result = ftdi_read_eeprom(&ftdic, eeprom_binary);
195 int size = FTDI_DEFAULT_EEPROM_SIZE;
200 std::cerr <<
"Error: Could not read the eeprom from the requested device." << std::endl;
203 std::cout <<
"Read eeprom binary [" << size <<
" bytes]." << std::endl;
205 std::cout <<
"Decoding into eeprom structure." << std::endl;
207 if ( ftdi_eeprom_decode(&eeprom, eeprom_binary, size) != 0 ) {
208 std::cerr <<
"Error: Could not write raw binary eeprom into the eeprom structure." << std::endl;
212 std::string new_manufacturer = manufacturer_;
213 std::string new_product = product_;
214 std::string new_id = new_id_;
217 eeprom.chip_type = TYPE_R;
220 eeprom.serial = (
char*)malloc(new_id.size() + 1);
221 std::strcpy(eeprom.serial, new_id.c_str());
223 free(eeprom.manufacturer);
224 eeprom.manufacturer = (
char*)malloc(new_manufacturer.size() + 1);
225 std::strcpy(eeprom.manufacturer, new_manufacturer.c_str());
226 free(eeprom.product);
227 eeprom.product = (
char*)malloc(new_product.size() + 1);
228 std::strcpy(eeprom.product, new_product.c_str());
232 std::cout <<
"Building new eeprom binary." << std::endl;
233 int eeprom_binary_length = ftdi_eeprom_build(&eeprom, eeprom_binary);
234 if (eeprom_binary_length == -1)
236 std::cerr <<
"Eeprom binary exceeded 128 bytes, reduce the size of your strings." << std::endl;
241 else if (eeprom_binary_length == -2)
243 std::cerr <<
"Eeprom structure not valid." << std::endl;
249 std::cout <<
"Flashing eeprom binary." << std::endl;
250 result = ftdi_write_eeprom(&ftdic, eeprom_binary);
253 std::cerr <<
" Could not rewrite the eeprom." << std::endl;
257 std::cout <<
" Flashed " << ftdic.eeprom_size <<
" bytes" << std::endl;
261 if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128)) < 0)
263 std::cerr <<
"ftdi_usb_get_strings failed: " << ftdi_get_error_string(&ftdic) <<
"." << std::endl;
266 std::cout <<
"Verify Device #" << i << std::endl;
267 std::cout <<
" Manufacturer: " << manufacturer << std::endl;
268 std::cout <<
" Description : " << description << std::endl;
269 std::cout <<
" Serial Id : " << serial << std::endl;
270 std::cout << std::endl;
272 std::cout <<
"Done." << std::endl;
const unsigned short product_id
int write(const std::string &new_id_)
int write(const std::string &old_id_, const std::string &new_id_)
const unsigned short vendor_id
int write(const std::string &old_id_, const std::string &new_id_, const std::string &manufacturer_, const std::string &product_)