Add fr languages (for test)
[barry/progweb.git] / tools / breset.cc
blobd394d33897aae2f97a1c4fda79a0d4de0394e849
1 ///
2 /// \file breset.cc
3 /// Attempt to reset all connected Blackberry devices via software
4 ///
5 /// This file is part of the Barry project:
6 ///
7 /// http://www.netdirect.ca/software/packages/barry
8 /// http://sourceforge.net/projects/barry
9 ///
10 /// Compile with the following command (needs libusb):
11 ///
12 /// g++ -o breset breset.cc -lusb
13 ///
16 Copyright (C) 2007-2009, Net Direct Inc. (http://www.netdirect.ca/)
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 See the GNU General Public License in the COPYING file at the
28 root directory of this project for more details.
31 #include <usb.h>
32 #include <stdio.h>
33 #include <unistd.h>
34 #include <config.h>
35 #include <locale.h>
36 #include <libintl.h>
38 #define _(String) gettext (String)
39 #define N_(String) String
41 #define VENDOR_RIM 0x0fca
42 #define PRODUCT_RIM_BLACKBERRY 0x0001
43 #define PRODUCT_RIM_PEARL_DUAL 0x0004
44 #define PRODUCT_RIM_PEARL_8120 0x8004
45 #define PRODUCT_RIM_PEARL 0x0006
47 #define BLACKBERRY_INTERFACE 0
48 #define BLACKBERRY_CONFIGURATION 1
50 bool reset(struct usb_device *dev)
52 usb_dev_handle *handle = usb_open(dev);
53 if( !handle )
54 return false;
56 bool ret = usb_reset(handle) == 0;
57 usb_close(handle);
58 return ret;
61 int main()
63 struct usb_bus *busses;
65 setlocale (LC_ALL, "");
66 bindtextdomain (PACKAGE, LOCALEDIR);
67 textdomain (PACKAGE);
69 usb_init();
70 usb_find_busses();
71 usb_find_devices();
72 busses = usb_get_busses();
74 printf(_("Scanning for Blackberry devices...\n"));
75 int found = 0;
77 struct usb_bus *bus;
78 for( bus = busses; bus; bus = bus->next ) {
79 struct usb_device *dev;
81 for (dev = bus->devices; dev; dev = dev->next) {
82 // Is this a blackberry?
83 if( dev->descriptor.idVendor == VENDOR_RIM &&
84 (dev->descriptor.idProduct == PRODUCT_RIM_BLACKBERRY ||
85 dev->descriptor.idProduct == PRODUCT_RIM_PEARL ||
86 dev->descriptor.idProduct == PRODUCT_RIM_PEARL_8120 ||
87 dev->descriptor.idProduct == PRODUCT_RIM_PEARL_DUAL ) ) {
88 printf(_("Found..."));
89 printf(_("attempting to reset.\n"));
90 if( reset(dev) )
91 found++;
92 else
93 printf(_("Can't reset device on bus %s, devnum %u\n"), bus->dirname, (unsigned int) dev->devnum);
98 printf(_("%d device%s reset.\n"), found, found > 1 ? "s" : "");