81 int write(
const std::string &new_id_) {
84 int ret_val =
write(
"", new_id_,
"",
"");
97 int write(
const std::string &old_id_,
const std::string &new_id_)
100 int ret_val =
write(old_id_, new_id_,
"",
"");
115 int write(
const std::string &old_id_,
const std::string &new_id_,
const std::string &manufacturer_,
const std::string &product_)
119 struct ftdi_context ftdic;
127 if (ftdi_init(&ftdic) < 0)
129 std::cerr <<
"ftdi_init failed" << std::endl;
149 if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128)) < 0)
151 std::cerr <<
"ftdi_usb_get_strings failed: " << ftdi_get_error_string(&ftdic) <<
"." << std::endl;
161 std::cout <<
" Manufacturer: " << manufacturer << std::endl;
162 std::cout <<
" Description : " << description << std::endl;
163 std::cout <<
" Serial Id : " << serial << std::endl;
164 std::cout << std::endl;
167 std::cout <<
"It is not intedend target." << std::endl;
168 std::cout <<
"target: " << old_id_ <<
", current: " << serial << std::endl;
169 curdev = curdev->next;
177 std::cerr <<
"Couldn't find/open a ftdi device." << std::endl;
183 std::cerr <<
"Couldn't open the device with serial id string " << old_id_ << std::endl;
191 unsigned char eeprom_binary[512];
192 int result = ftdi_read_eeprom(&ftdic, eeprom_binary);
193 int size = FTDI_DEFAULT_EEPROM_SIZE;
198 std::cerr <<
"Error: Could not read the eeprom from the requested device." << std::endl;
201 std::cout <<
"Read eeprom binary [" << size <<
" bytes]." << std::endl;
203 std::cout <<
"Decoding into eeprom structure." << std::endl;
205 if ( ftdi_eeprom_decode(&eeprom, eeprom_binary, size) != 0 ) {
206 std::cerr <<
"Error: Could not write raw binary eeprom into the eeprom structure." << std::endl;
210 std::string new_manufacturer = manufacturer_;
211 std::string new_product = product_;
212 std::string new_id = new_id_;
215 eeprom.chip_type = TYPE_R;
218 eeprom.serial = (
char*)malloc(new_id.size() + 1);
219 std::strcpy(eeprom.serial, new_id.c_str());
221 free(eeprom.manufacturer);
222 eeprom.manufacturer = (
char*)malloc(new_manufacturer.size() + 1);
223 std::strcpy(eeprom.manufacturer, new_manufacturer.c_str());
224 free(eeprom.product);
225 eeprom.product = (
char*)malloc(new_product.size() + 1);
226 std::strcpy(eeprom.product, new_product.c_str());
230 std::cout <<
"Building new eeprom binary." << std::endl;
231 int eeprom_binary_length = ftdi_eeprom_build(&eeprom, eeprom_binary);
232 if (eeprom_binary_length == -1)
234 std::cerr <<
"Eeprom binary exceeded 128 bytes, reduce the size of your strings." << std::endl;
239 else if (eeprom_binary_length == -2)
241 std::cerr <<
"Eeprom structure not valid." << std::endl;
247 std::cout <<
"Flashing eeprom binary." << std::endl;
248 result = ftdi_write_eeprom(&ftdic, eeprom_binary);
251 std::cerr <<
" Could not rewrite the eeprom." << std::endl;
255 std::cout <<
" Flashed " << ftdic.eeprom_size <<
" bytes" << std::endl;
259 if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128)) < 0)
261 std::cerr <<
"ftdi_usb_get_strings failed: " << ftdi_get_error_string(&ftdic) <<
"." << std::endl;
264 std::cout <<
"Verify Device #" << i << std::endl;
265 std::cout <<
" Manufacturer: " << manufacturer << std::endl;
266 std::cout <<
" Description : " << description << std::endl;
267 std::cout <<
" Serial Id : " << serial << std::endl;
268 std::cout << std::endl;
270 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_)