t2n-0.7.src/0000755001311200041100000000000014605730440013116 5ustar raymondpsynchront2n-0.7.src/README0000644001311200041100000000372614607236353014014 0ustar raymondpsynchron Remarks/advices (updated july 2015) ------------------------------------ - Compile the tool: Even if binaries are available, it is strongly recommanded to (re)compile the tool on your machine from the source distribution. You need: g++ libusb-dev then run "make" - Usb rights: When you run t2n, you will probaby get the message: Error : usbnxt: usbmisc: fails to set config, errno=-1, usberr="could not set config 1: Operation not permitted" (cf=1 vendor=0x0694 product=0x0002) it meens that "normal" users cannot access the usb device. In order to set the rights, your system must run "udev" service: which is the case if the folder "/etc/udev/rules.d/" exists. Copy (as root) the file "71-lego.rules"(*) in this folder: sudo cp udev/71-lego.rules /etc/udev/rules.d/ Just in case, restart the service: sudo service udev restart sudo udevadm control --reload-rules (*) The udev syntax has changed several times, the file "71-lego.rules" should be ok for recent debian or ubuntu systems. Archives -------- The folowing remark corresponds to older versions of debian/ubuntu, and is probably obsolete. However if you encounters problems you can check if you fall in this case: - Get rid of "cdc-acm" This problem may appear in firmware-loading mode, a serial-device driver called "cdc-acm" captures the nxt, e.g. dmesg gives: usb 4-2: new full speed USB device using uhci_hcd and address 2 usb 4-2: New USB device found, idVendor=03eb, idProduct=6124 usb 4-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0 cdc_acm 4-2:1.0: This device cannot do calls on its own. It is not a modem. cdc_acm 4-2:1.0: ttyACM0: USB ACM device usbcore: registered new interface driver cdc_acm cdc_acm: v0.26:USB Abstract Control Model driver for USB modems and ISDN adapters Kick and DIRTY solution, as root: 1) black-list cdc-acm: add the line: blacklist cdc-acm to the file: /etc/modprobe.d/blacklist 2) kill cdc-acm (if running): modprobe -r cdc-acm t2n-0.7.src/COPYING0000644001311200041100000010451314607236353014163 0ustar raymondpsynchron GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . t2n-0.7.src/COPYING.LESSER0000644001311200041100000001672714607236353015170 0ustar raymondpsynchron GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. t2n-0.7.src/Makefile0000644001311200041100000000550514607236353014571 0ustar raymondpsynchron# Talk2Ntx (t2n) # # 1) libusb is required (http://libusb.sourceforge.net/) # 2) define ARCHI var if several architecture are targeted # (e.g. linux, sparc, cygwin etc ...) # # N.B. tested on : # - pc/linux with g++ 3.4 # - sparc/solaris with g++ 3.4 # # options for debian packaging hardening # include /usr/share/hardening-includes/hardening.make # CFLAGS=$(shell dpkg-buildflags --get CFLAGS) # LDFLAGS=$(shell dpkg-buildflags --get LDFLAGS) # CFLAGS+=$(HARDENING_CFLAGS) # LDFLAGS+=$(HARDENING_LDFLAGS) MAIN=t2n OBJDIR=./obj$(ARCHI) SRCDIR=./src all: dynamic static dynamic : $(OBJDIR) $(OBJDIR)/$(MAIN) $(OBJDIR)/usbscan static : $(OBJDIR)/$(MAIN).static CC=g++ LK=g++ CFLAGS+= -I$(SRCDIR) -I$(OBJDIR) -g -Wall -fPIE -Wno-int-to-pointer-cast LDFLAGS+= LIBS=-lusb -lstdc++ OBJS=$(OBJDIR)/$(MAIN).o \ $(OBJDIR)/usbmisc.o \ $(OBJDIR)/usbnxt.o \ $(OBJDIR)/errors.o \ $(OBJDIR)/errormng.o \ $(OBJDIR)/ezargs.o $(OBJDIR)/usbscan: $(SRCDIR)/usbscan.c gcc $(CFLAGS) -Wno-unused-but-set-variable $(LDFLAGS) $(SRCDIR)/usbscan.c $(LIBS) -o $(OBJDIR)/usbscan $(OBJDIR)/$(MAIN) : $(OBJS) $(LK) $(LDFLAGS) $(OBJS) $(LIBS) -o $(OBJDIR)/$(MAIN) $(OBJDIR)/$(MAIN).static : $(OBJS) $(LK) -static $(LDFLAGS) $(OBJS) $(LIBS) -o $(OBJDIR)/$(MAIN).static $(OBJDIR)/%.o : $(SRCDIR)/%.cc $(CC) -c $(CFLAGS) $(SRCDIR)/$*.cc -o $(OBJDIR)/$*.o $(OBJDIR)/usbmisc.o : $(SRCDIR)/usbmisc.h $(SRCDIR)/errormng.h $(SRCDIR)/errors.h $(OBJDIR)/usbnxt.o : $(SRCDIR)/usbnxt.h $(SRCDIR)/usbmisc.h $(SRCDIR)/errormng.h \ $(SRCDIR)/errors.h $(OBJDIR)/$(MAIN).o : $(SRCDIR)/usbnxt.h $(SRCDIR)/usbmisc.h $(SRCDIR)/errormng.h \ $(SRCDIR)/errors.h $(SRCDIR)/ezargs.h $(SRCDIR)/version.h $(OBJDIR) : mkdir $(OBJDIR) clean: rm -f $(OBJDIR)/*.o distclean: rm -rf $(OBJDIR) distrib: all static ddir=t2n-`$(OBJDIR)/$(MAIN) -version`-$(ARCHI) ; \ echo $$ddir ; \ if [ ! -d $$ddir ] ; then mkdir $$ddir ; fi ; \ cp $(OBJDIR)/$(MAIN) $$ddir ; strip $(OBJDIR)/$(MAIN) ; \ cp $(OBJDIR)/$(MAIN).static $$ddir ; strip $(OBJDIR)/$(MAIN).static ; \ # cp -r hotplug $$ddir ; \ # cp -r udev $$ddir ; \ tar zcvf $$ddir.tgz $$ddir ; \ mkdir -p publish/files ; \ cp ,htaccess publish/files/.htaccess ; \ mv $$ddir.tgz publish/files ; \ sddir=t2n-`$(OBJDIR)/$(MAIN) -version`.src ; \ echo $$sddir ; \ if [ ! -d $$sddir ] ; then mkdir $$sddir ; fi ; \ cp README $$sddir ; \ cp COPYING $$sddir ; \ cp COPYING.LESSER $$sddir ; \ cp Makefile $$sddir ; \ cp -r $(SRCDIR) $$sddir ; \ cp -r udev $$sddir ; \ zedate=`date +"%Y.%m.%d"`; \ cat publish/in.index.html | \ sed -e s/BINDIST/$$ddir.tgz/g | \ sed -e s/SRCDIST/$$sddir.tgz/g -e s/ZEDATE/$$zedate/ > publish/index.html ; \ tar zcvf $$sddir.tgz $$sddir ; mv $$sddir.tgz publish/files rsync -avz publish/ /import/www-people/PEOPLE/raymondp/files/t2n t2n-0.7.src/src/0000755001311200041100000000000014605730440013705 5ustar raymondpsynchront2n-0.7.src/src/Makefile.save0000644001311200041100000000535614607227617016324 0ustar raymondpsynchron# Talk2Ntx (t2n) # # 1) libusb is required (http://libusb.sourceforge.net/) # install it and check the USBROOT var # 2) define CPU var if several architecture are targeted # (e.g. linux, sparc, cygwin etc ...) # # N.B. tested on : # - pc/linux with g++ 3.4 # - sparc/solaris with g++ 3.4 # MAIN=t2n OBJDIR=./obj$(CPU) SRCDIR=./src # ou trouver les .h et les lib usb/usbpp USBROOT=$(HOME) all : $(OBJDIR) $(OBJDIR)/$(MAIN) $(OBJDIR)/usbscan static : $(OBJDIR)/$(MAIN).static CC=g++ LK=g++ CFLAGS=-I$(USBROOT)/include -I$(SRCDIR) -I$(OBJDIR) -g LFLAGS=-L$(USBROOT)/lib LIBS=-lusb -lstdc++ OBJS=$(OBJDIR)/$(MAIN).o \ $(OBJDIR)/usbmisc.o \ $(OBJDIR)/usbnxt.o \ $(OBJDIR)/errors.o \ $(OBJDIR)/errormng.o \ $(OBJDIR)/ezargs.o $(OBJDIR)/usbscan: $(SRCDIR)/usbscan.c gcc $(CFLAGS) $(LFLAGS) $(SRCDIR)/usbscan.c $(LIBS) -o $(OBJDIR)/usbscan $(OBJDIR)/$(MAIN) : $(OBJS) $(LK) $(LFLAGS) $(OBJS) $(LIBS) -o $(OBJDIR)/$(MAIN) $(OBJDIR)/$(MAIN).static : $(OBJS) $(LK) -static $(LFLAGS) $(OBJS) $(LIBS) -o $(OBJDIR)/$(MAIN).static $(OBJDIR)/%.o : $(SRCDIR)/%.cc $(CC) -c $(CFLAGS) $(SRCDIR)/$*.cc -o $(OBJDIR)/$*.o $(OBJDIR)/version.h : talk2nxt.prj (grep Project-Version talk2nxt.prj | sed -e \ "s/(\([^ ]*\) \([^ ]*\) \([^ ]*\) \([^ ]*\))/\/\/\1\n#define TOOLNAME \"\2\"\n#define MAJOR \"\3\"\n#define MINOR \"\4\"\n#define VERSION \"\3.\4\"/" \ > $(OBJDIR)/version.h) $(OBJDIR)/usbmisc.o : $(SRCDIR)/usbmisc.h $(SRCDIR)/errormng.h $(SRCDIR)/errors.h $(OBJDIR)/usbnxt.o : $(SRCDIR)/usbnxt.h $(SRCDIR)/usbmisc.h $(SRCDIR)/errormng.h \ $(SRCDIR)/errors.h $(OBJDIR)/$(MAIN).o : $(SRCDIR)/usbnxt.h $(SRCDIR)/usbmisc.h $(SRCDIR)/errormng.h \ $(SRCDIR)/errors.h $(SRCDIR)/ezargs.h $(OBJDIR)/version.h $(OBJDIR) : mkdir $(OBJDIR) clean: rm -f $(OBJDIR)/*.o distrib: all static ddir=t2n-`$(OBJDIR)/$(MAIN) -version` ; \ echo $$ddir ; \ if [ ! -d $$ddir ] ; then mkdir $$ddir ; fi ; \ cp $(OBJDIR)/$(MAIN) $$ddir ; strip $(OBJDIR)/$(MAIN) ; \ cp $(OBJDIR)/$(MAIN).static $$ddir ; strip $(OBJDIR)/$(MAIN).static ; \ cp -r hotplug $$ddir ; \ cp -r udev $$ddir ; \ tar zcvf $$ddir.tgz $$ddir ; mv $$ddir.tgz publish ; \ sddir=t2n-`$(OBJDIR)/$(MAIN) -version`.src ; \ echo $$sddir ; \ if [ ! -d $$sddir ] ; then mkdir $$sddir ; fi ; \ cp ALIRE $$sddir ; \ cp COPYING $$sddir ; \ cp COPYING.LESSER $$sddir ; \ cp talk2nxt.prj $$sddir ; \ cp $(SRCDIR)/Makefile $$sddir ; \ cp -r $(SRCDIR) $$sddir ; \ cp -r hotplug $$sddir ; \ cp -r udev $$sddir ; \ cat publish/in.index.html | sed -e s/BINDIST/$$ddir.tgz/g | sed -e s/SRCDIST/$$sddir.tgz/g > publish/index.html ; \ tar zcvf $$sddir.tgz $$sddir ; mv $$sddir.tgz publish cp -r publish/* /usr/local/www/PEOPLE/raymond/edu/lego/t2n/ t2n-0.7.src/src/errormng.cc0000644001311200041100000000325314607236353016060 0ustar raymondpsynchron/*------------------------------------------------------------------------- Copyright 2005 CNRS (VERIMAG) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- VERIMAG - Synchrone TOOLBOX --------------------------------------------------------------------------- module : errormng.cc date : 30/08/2005 auteurs : Pascal Raymond modif : ---------------------------------------------------------------------------- Juste une petite couche pour récupérer propement les messages d'erreurs système ... --------------------------------------------------------------------------*/ #include "errormng.h" ErrorMng::ErrorMng(const char* c){ int l = sprintf(&_buff[0], "%s", c); _msg = &_buff[l]; } void ErrorMng::set(const char* fmt ...){ va_list args; va_start(args,fmt); vsprintf(_msg, fmt, args); } const char* ErrorMng::get(){ return &_buff[0]; } t2n-0.7.src/src/errormng.h0000644001311200041100000000327114607236353015722 0ustar raymondpsynchron /*------------------------------------------------------------------------- Copyright 2005 CNRS (VERIMAG) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- VERIMAG - Synchrone TOOLBOX --------------------------------------------------------------------------- module : errormng.h date : 30/08/2005 auteurs : Pascal Raymond modif : ---------------------------------------------------------------------------- Juste une petite couche pour récupérer propement les messages d'erreurs système ... --------------------------------------------------------------------------*/ #include #include #include #include #define ErrorMngBuffSize 512 class ErrorMng { char _buff[ErrorMngBuffSize]; char* _msg; int _msgsz; char* _class; public: ErrorMng(const char* c); void set(const char* fmt ...); const char* get(); }; t2n-0.7.src/src/errors.cc0000644001311200041100000001145214607236353015541 0ustar raymondpsynchron /*------------------------------------------------------------------------- Copyright 1996,2005 CNRS (VERIMAG) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- module : errors.h date : 25/11/1996 auteurs : Pascal Raymond ---------------------------------------------------------------------------- nature : Gestion des erreurs et des messages (sur stderr) : ---------------------------------------------------------------------------- -------------------------------------------------------------------------*/ #include #include #include #include #include #include #include "errors.h" /******************************************************************** Error, Warning, Verbose *********************************************************************/ static int VERBOSE = 0; static int PIPE = 0; static char TOOL_NAME_DFLT[] = " "; static const char* TOOL_NAME = TOOL_NAME_DFLT; void set_verbose_mode(){ VERBOSE = 1; } void set_pipe_mode(){ PIPE = 1; } void set_verbose_mode(int i){ VERBOSE = i; } void set_errors_tool_name(const char* tn){ TOOL_NAME = tn;} int Verbose(const char* fmt ...){ va_list args; va_start(args,fmt); if(VERBOSE){ if ( PIPE && (fmt[0] == '\r')){ fprintf(stderr, " \n^R" ); vfprintf(stderr, &fmt[1], args); } else if ( PIPE && (fmt[0] == '\b' )){ fprintf(stderr, "\n^B" ); vfprintf(stderr, &fmt[1], args); } else { vfprintf(stderr,fmt,args); } fflush(stderr); } return VERBOSE; } int Verbose(int i, const char* fmt ...){ va_list args; va_start(args,fmt); if(i <= VERBOSE){ if ( PIPE && (fmt[0] == '\r')){ fprintf(stderr, " \n^R" ); vfprintf(stderr, &fmt[1], args); } else if ( PIPE && (fmt[0] == '\b' )){ fprintf(stderr, "\n^B" ); vfprintf(stderr, &fmt[1], args); } else { vfprintf(stderr,fmt,args); } fflush(stderr); } return VERBOSE; } int Verbose(){ return VERBOSE; } /******************************************************************** A "turning wheel" which makes a quarter cycle each "step" time teh proc is called (only in verbose mode) *********************************************************************/ static char WHEEL[] = { '|', '/', '-', '\\' }; static int WHEEL_INDEX = 0; static int WHEEL_STEP = 1; int VerboseWheel(int step){ if((VERBOSE) && isatty(2)){ if(WHEEL_STEP >= step){ WHEEL_STEP = 0; fprintf(stderr,"%c\b", WHEEL[WHEEL_INDEX]); fflush(stderr); WHEEL_INDEX = (WHEEL_INDEX+1)%4; } else { WHEEL_STEP++; } } return VERBOSE; } void IError(const char* fmt ...){ va_list args; va_start(args,fmt); fprintf(stderr,"Sorry, Internal Error :\n"); vfprintf(stderr,fmt,args); fprintf(stderr,"\n"); exit(1); } void Error(const char* fmt ...){ va_list args; va_start(args,fmt); fprintf(stderr,"%s Error :\n", TOOL_NAME); vfprintf(stderr,fmt,args); fprintf(stderr,"\n"); exit(1); } void Warning(const char* fmt ...){ va_list args; va_start(args,fmt); fprintf(stderr,"%s Warning :\n", TOOL_NAME); vfprintf(stderr,fmt,args); fprintf(stderr,"\n"); } int AskYesNo(const char* fmt ...){ va_list args; va_start(args,fmt); char prompt[1024]; vsprintf(&prompt[0],fmt,args); char* b; size_t bsz; //char c; int r = 0; int s = 1; do { fprintf(stderr, "%s (y/n) ? ", prompt); fflush(stdout); b=NULL; bsz=0; int bl = getline(&b, &bsz, stdin); //remove ending "spaces" (thus newline) char* p = &b[bl]; do { p--; } while ((p != b) && (isspace(*p))); *(++p) = '\0'; //printf("\n\"%s\"\n%d\n\"", b, bl); r = -1; if(! strcmp(b, "y")) r = 1; else if (! strcmp(b, "n")) r = 0; else fprintf(stderr, "please answer y or n\n"); } while ((s != 1) || (r == -1)); return r; } static int nb_global_error = 0; void GErrorRecover(){ if(nb_global_error){ fprintf(stderr,"*** %d Errors stop\n", nb_global_error); exit(1); } } int GErrors(){ return nb_global_error; } void GError(const char* fmt ...){ va_list args; va_start(args,fmt); vfprintf(stderr,fmt,args); nb_global_error++; } t2n-0.7.src/src/errors.h0000644001311200041100000000573514607236353015412 0ustar raymondpsynchron/*------------------------------------------------------------------------- Copyright 1996,2005 CNRS (VERIMAG) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- module : errors.h date : 25/11/1996 auteurs : Pascal Raymond ---------------------------------------------------------------------------- nature : Gestion des erreurs et des messages (sur stderr) : ---------------------------------------------------------------------------- (C = constructeur, M = methode, F = fonction) ----------------------------------------------------- F set_errors_tool_name(char*) Definit un prefixe aux messages d'erreur F IError(char* fmt, ...) 'internal error' et exit F Error(char* fmt, ...) 'error' et exit F GError(char* fmt, ...) 'error' sans exit F GErrors() Le nombre d'appel de GError F GErrorRecover() Exit si GError avant F Warning(char* fmt, ...) 'warning' (sans exit) F set_verbose_mode() Passe en mode verbeux niveau 1 F set_verbose_mode(int i) Passe en mode verbeux niveau i (0 pour non-verbeux) F int Verbose() Le mode verbeux courant F Verbose(char* fmt, ...) Affiche message si mode verbeux >= 1 F Verbose(int i, char* fmt, ...) Affiche message si mode verbeux >= i ---------------------------------------------------------------------------- modifs : --------------------------------------------------------------------------*/ #ifndef __PR_ERRORS_H #define __PR_ERRORS_H extern void IError(const char* fmt, ...); extern void Error(const char* fmt, ...); extern void GError(const char* fmt, ...); extern int GErrors(); extern void GErrorRecover(); extern void Warning(const char* fmt, ...); extern void set_errors_tool_name(const char* tn); extern void set_verbose_mode(); extern void set_pipe_mode(); extern void set_verbose_mode(int i); extern int Verbose(const char* fmt, ...); extern int Verbose(int i, const char* fmt, ...); extern int Verbose(); extern int AskYesNo(const char* fmt, ...); #define VERBOSE(X,Y) {if(Verbose() >= X) { Y; }} extern int VerboseWheel(int step); #endif t2n-0.7.src/src/ezargs.h0000644001311200041100000001230314607236353015356 0ustar raymondpsynchron/*------------------------------------------------------------------------- Copyright 2005 CNRS (VERIMAG) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- VERIMAG - Synchrone TOOLBOX --------------------------------------------------------------------------- module : ezargs.h date : 30/08/2005 auteurs : Pascal Raymond modif : ---------------------------------------------------------------------------- nature : Classe EzArgs, pour faciliter la gestion des arguments de commande (argc, argv). - gère un numéro de version (fourni par l'utilisateur) - gère un nom d'outil (déduit du argv[0] standard) - gère les options avec clés classiques du style : . . . (n.b. les clés peuvent ne pas commencer par -) - gère aussi les arguments extras, non introduit par une clé dans ce cas, c'est l'ordre d'apparition qui est significatif - imprime des messages d'usage standard - gère des options par défaut : -help, -version ---------------------------------------------------------------------------- (C = constructeur, M = methode, F = fonction) ----------------------------------------------------- On peut utiliser directement la classe EzArgs ou, plus proprement, dériver sa propre classe. Voir plus bas "MyArgs" pour un exemple simple de dérivation. Sion, l'utilisation directe se fait en 3 temps : 1- création C) EzArgs::EzArgs(char* vers) 2- déclaration des options M) add_bool(char* key, char* man, bool* r) M) add_int(char* key, char* par, char* man, int* r, int dflt) M) add_int(char* key, char* par, char* man, int* r, bool* rset) M) add_string(char* key, char* par, char* man, char** r, char* dflt) M) add_extra(char* par, char* man, char** r, char* dflt) key : la clé (sauf pour extra) param : un texte explicatif pour l'argument (sauf pour les bool) man : un texte explicatif r : pointeur sur le résultat (suivant le type attendu) dflt : valeur par défaut pour *r rset : pointeur sur un booléen qui indique si l'option à été parsée (int uniquement) 3- parsing M) parse(int argc, char* argv[]) argc, argv: paramètres de la ligne de commande, Y COMPRIS le nom de la commande (argv[0]) Les arguments argv[1..argc-1] sont parsés selon les déclaration précédentes. Si une option apparaît plusieurs fois, c'est la dernière qui "gagne". Les extras sont traités dans l'ordre où ils ont été déclarés : la première chaîne sans clés est associée au premier extra déclaré, le deuxième au deuxième etc. S'il y a plus de chaînes sans clé que d'extra déclaré, on lève une erreur. ---------------------------------------------------------------------------- Exemple de classe dérivée : class MesArgs:public EzArgs { bool _t; int _opt; char* _outfile; char* _infile; char* _mainproc; public: MesArgs(int argc, char* argv[]):EzArgs("0.0"){ add_bool("-t", "test only", &_t); add_int("-opt", "", "optimisation level", &_opt, -1); add_string("-o", "", "set output name", &_outfile, NULL); add_extra("", "input file", &_infile, NULL); add_extra("
", "main procedure", &_mainproc, NULL); parse(argc, argv); } }; int main(int argc, char* argv[]){ MesArgs* args = new MesArgs(argc, argv); } --------------------------------------------------------------------------*/ #ifndef __PR_EZARGS_H #define __PR_EZARGS_H typedef const char* cstring; //restons abstrait ! class EzArgsToken ; class EzArgs { int _argc; const char** _argv; int _cur_arg; const char* _toolname; const char* _version; //option predefs : bool _givehelp; bool _giveversion; protected: //les tokens avec clé... EzArgsToken* _tokens; //les xtras (sans clé); int _nb_extras; EzArgsToken* _extras; public: EzArgs(const char* ver); bool add_bool(cstring key, cstring man, bool* r); bool add_int(cstring key, cstring par, cstring man, int* r, int dflt); bool add_int(cstring key, cstring par, cstring man, int* r, bool* rset); bool add_string(cstring key, cstring par, cstring man, cstring* r, cstring dflt); bool add_extra(cstring par, cstring man, cstring* r, cstring dflt); bool parse(int ac, cstring av[]); //usage par défaut ... void usage(); //Les options prédéfinies cstring version(); cstring toolname(); void giveoptions(); void givehelp(){ usage(); giveoptions(); } }; #endif t2n-0.7.src/src/usbmisc.cc0000644001311200041100000002030714607236353015671 0ustar raymondpsynchron /* ----- Copyright 2007 CNRS (VERIMAG) ------------------------------------- -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- * Projet Talk to NXT * ------------------------------------------------------------------------- * module : usbmisc.cc * * date : 2007-03-07 * auteurs : Pascal Raymond *-------------------------------------------------------------------------- * nature : Couche orienté-objet au dessus le de la libusb * *-------------------------------------------------------------------------- * Modifs : * -----------------------------------------------------------------------*/ #include #include #include #include "errors.h" #include "errormng.h" #include "usb.h" #include "usbmisc.h" //toujours vrai ??? #define USB_INTERFACE 0 #define USB_CONFIG 1 //Messages d'erreur de la lib. static ErrorMng _usbmisc_error("usbmisc: "); const char* usbmisc_error(){ return _usbmisc_error.get(); } void UsbHandle::_init(){ _dev = NULL; _handle = NULL; _bbuff = NULL; } //extern int print_device(struct usb_device *dev, int level); int UsbHandle::init(u_int16_t vendor, u_int16_t product){ _dev = UsbHandle::_find_usb_dev(vendor, product); if(_dev == NULL) { _usbmisc_error.set("no usb device found (vendor=0x%04x product=0x%04x)", vendor, product ); return -1; } //print_device(_dev, 0); _handle = usb_open(_dev); if (!_handle) { _usbmisc_error.set("fails to open device handle (vendor=0x%04x product=0x%04x)", vendor, product ); return -1; } //reset ? usb_reset(_handle); int err; //set config err = usb_set_configuration(_handle, USB_CONFIG); if(err != 0){ //printf( "usb_strerror = %s\n", usb_strerror( )); _usbmisc_error.set( "fails to set config, errno=%d, usberr=\"%s\" (cf=%d vendor=0x%04x product=0x%04x)", err, usb_strerror(), USB_CONFIG, vendor, product ); return -1; } //demande d'interface ... err = usb_claim_interface(_handle, USB_INTERFACE); if(err != 0){ _usbmisc_error.set( "fails to optain usb interface (erno=%d id=%d vendor=0x%04x product=0x%04x)", err, USB_INTERFACE, vendor, product ); return -1; } return 0; } UsbHandle::~UsbHandle(){ //fermeture propre ... if(_handle) usb_close(_handle); } struct usb_device* UsbHandle::_find_usb_dev( u_int16_t vendor, u_int16_t product ){ struct usb_bus *busses, *bus; struct usb_device *devs, *d; u_int16_t v, p; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for(bus = busses; bus; bus = bus->next){ Verbose(2, "(usb scan) bus dirname=%s\n", bus->dirname); devs = bus->devices; for(d=devs; d; d=d->next){ v = d->descriptor.idVendor; p = d->descriptor.idProduct; Verbose(2, "(usb scan) dev filename=%s, vendor=0x%04x, product=0x%04x\n", d->filename, v, p ); if((v == vendor) && (p==product)) return d; } } return NULL; } void UsbHandle::init_bulk(int wep, int wto, int rep, int rto){ if (_bbuff == NULL) _bbuff = new UsbBulkBuff(); _bbuff->init(_handle, wep, wto, rep, rto); } UsbBulkBuff::UsbBulkBuff(){ _init(); } // ----------------------------------------- // écriture de base dans un buffer (s,v) // règles : // s < 0 : v est un entier immédiat sur (-s) octets // qu'on écrit en le // s > 0 : v est un char* qui pointe // NULL-TERM-STRING // si s=2n : sur une null-terminated string // auquel cas on écrit la chaîne en la // tronquant ou en l'étendant avec des 0 // si besoin. // RAW-COPY // - si s=2n+1 : sur un tableau brut d'octets // qu'on écrit tel-quel // ----------------------------------------- int UsbBulkBuff::put(int s, void* v){ if(s ==0) return 0; if(s < 0) { //DIRECT, little-endian int nbytes = -s; //corrige la taille unsigned char *p = (unsigned char *) &v; for(int cpt=0; cpt chaîne de caractère int nbytes = s >> 1; int rawcopy = s & 1; //écrit s, tronque/complète avec des '\0' si besoin char* p = (char*)v; char c = -1; int cpt; for(cpt=0; cpt < nbytes; cpt++){ if(c || rawcopy) c = *p++; if(_write_buff.put (c) != 1) { _usbmisc_error.set("UsbBulkBuff::put failed"); return -1; } } return 0; } } // ----------------------------------------- // lecture de base dans un buffer (s,p) // ----------------------------------------- int UsbBulkBuff::get(int s, void* p){ if(s == 0) return 0; if(s < 0) { //entier little endian unsigned int* r = (unsigned int*)p; char c; *r = 0; int cpt; int nbytes = -s; for(cpt=0; cpt= 3){ Verbose(3,"UsbBulkBuff::usb_bulk_write(0x%02x, 0x%02x, 0x%x, %d, %d)\n", _devh, _write_ep, _write_buff.data(), _write_buff.len(), _write_to); _write_buff.dump(stderr); } r = usb_bulk_write(_devh, _write_ep, _write_buff.data(), _write_buff.len(), _write_to); Verbose(2, "%s usb_bulk_write %d bytes on %d bytes\n", (vprolog)?vprolog:"", r, _write_buff.len()); if(r != _write_buff.len()) { _usbmisc_error.set("usb_bulk_write failed (%d bytes instead of %d)\n", r, _write_buff.len() ); return -1; } r = usb_bulk_read(_devh, _read_ep, _read_buff.data(), _read_buff.maxsz(), _read_to); Verbose(2, "%s usb_bulk_read -> %d bytes\n", (vprolog)?vprolog:"", r); if(r < 0) { _usbmisc_error.set("usb_bulk_read failed\n"); return -1; } _read_buff.set_len(r); return 0; } // Send monobloc int UsbHandle::send( const char* vprolog, int s0, void *v0, int s1, void *v1, int s2, void *v2, int s3, void *v3, int s4, void *v4 ) { _bbuff->reset(); if(_bbuff->put(s0, v0)) goto BUFF_ERROR; if(_bbuff->put(s1, v1)) goto BUFF_ERROR; if(_bbuff->put(s2, v2)) goto BUFF_ERROR; if(_bbuff->put(s3, v3)) goto BUFF_ERROR; if(_bbuff->put(s4, v4)) goto BUFF_ERROR; if(_bbuff->write_read(vprolog)) goto SEND_ERROR; return 0; BUFF_ERROR : _usbmisc_error.set("internal buffer error"); return -1; SEND_ERROR : //message déjà mis ... return -1; } // Receive monobloc (7 items max) int UsbHandle::receive( int s0, void* p0, int s1, void* p1, int s2, void* p2, int s3, void* p3, int s4, void* p4, int s5, void* p5, int s6, void* p6 ) { if(_bbuff->get(s0, p0)) goto BUFF_ERROR; if(_bbuff->get(s1, p1)) goto BUFF_ERROR; if(_bbuff->get(s2, p2)) goto BUFF_ERROR; if(_bbuff->get(s3, p3)) goto BUFF_ERROR; if(_bbuff->get(s4, p4)) goto BUFF_ERROR; if(_bbuff->get(s5, p5)) goto BUFF_ERROR; if(_bbuff->get(s6, p6)) goto BUFF_ERROR; return 0; BUFF_ERROR : printf( "usb_strerror = %s\n", usb_strerror( )); _usbmisc_error.set("internal buffer error"); return -1; } t2n-0.7.src/src/usbmisc.h0000644001311200041100000001360314607236353015534 0ustar raymondpsynchron /* ----- Copyright 2007 CNRS (VERIMAG) ------------------------------------- -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- * Projet Talk to NXT * ------------------------------------------------------------------------- * module : usbmisc.h * * date : 2007-03-07 * auteurs : Pascal Raymond *-------------------------------------------------------------------------- * nature : Couche orienté-objet au dessus le de la libusb * *-------------------------------------------------------------------------- * Modifs : * -----------------------------------------------------------------------*/ // Message d'erreurs de la lib ... extern const char* usbmisc_error(); //-------------------------------------------------------------- //Codage des params (s,v) pour l'écriture ds buffer //-------------------------------------------------------------- //s > 0 => v est un pointeur char* // NTS MODE // si "s=2n" -> v est une "null-terminated string, // qui sera forcée à n caractères // RAW MODE // si "s=2n+1" -> v est un tableau brut de taille exactement n //s < 0 => v est une valeur immédiate sur 's' bytes little-endian //s = 0 => fini //(Remarque : les char sont traités comme des entiers) // macros pour le send monobloc //-------------------------------------------------------------- #define InC(x) -1, (void*)x #define InS(x) -2, (void*)x #define InL(x) -4, (void*)x #define InNTS(s,x) (s<<1), (void*)x #define InRAW(s,x) ((s<<1)|1), (void*)x //-------------------------------------------------------------- //Codage des params (s,p) pour la lecture ds buffer //-------------------------------------------------------------- //s > 0 => v est un char* sur 's' bytes //s < 0 => v est un pointeur sur sur 's' bytes little-endian //s = 0 => fini // Remarque : les char sont traités comme des tableaux de longueur 1 // Remarque : pas de cas NTS -> que des tableaux bruts // macros pour le get monobloc //-------------------------------------------------------------- #define OutS(x) -2, (void*)x #define OutL(x) -4, (void*)x #define OutC(x) 1, (void*)x #define OutRAW(s,x) s, (void*)x class UsbBulkBuff; class UsbHandle { struct usb_device* _dev; struct usb_dev_handle* _handle; UsbBulkBuff* _bbuff; static struct usb_device* _find_usb_dev( u_int16_t vendor, u_int16_t product ); void _init(); public: UsbHandle(){ _init(); } int init(u_int16_t vendor, u_int16_t product); void init_bulk(int wep, int wto, int rep, int rto); //taille max buffer in int max_buff_sz(); ~UsbHandle(); // send monobloc => utiliser les macros InXX // ex : send(InC('a'), InS(42), InZ(10, "hello")); int send( const char* vprolog, //verbose prologue int s0 = 0, void* v0 = 0, int s1 = 0, void* v1 = 0, int s2 = 0, void* v2 = 0, int s3 = 0, void* v3 = 0, int s4 = 0, void* v4 = 0 ); // receive monobloc => utiliser les macros OutXX // ex : send(OuC(&c), InS(&n), InZ(10, ptr)); int receive( int s0 = 0, void* p0 = NULL, int s1 = 0, void* p1 = NULL, int s2 = 0, void* p2 = NULL, int s3 = 0, void* p3 = NULL, int s4 = 0, void* p4 = NULL, int s5 = 0, void* p5 = NULL, int s6 = 0, void* p6 = NULL ); }; // buffer pour communication ``bulk'' #define BFSZ 64 class Buff { unsigned char _data[BFSZ]; int _len; int _rindex; public: void dump(FILE* os); void reset(){ memset((void*)_data, '\0', BFSZ); _len=0; _rindex = 0; } Buff(){ reset(); } //force la longeur ... void set_len(int l) { _len = l; } //accès : de l'extérieur // il vaut mieux voir un char* ... char* data(){ return (char*)(&_data[0]); } int len(){ return _len; } static int maxsz(){ return BFSZ; } //écriture ... int put(char c){ if(_len < BFSZ) { _data[_len] = c; _len++; return 1; } else { return 0; } } int get(char* r){ if(_rindex >= _len) return -1; *r = _data[_rindex++]; return 1; } }; class UsbBulkBuff { struct usb_dev_handle* _devh; unsigned int _write_ep; unsigned int _write_to; unsigned int _read_ep; unsigned int _read_to; Buff _read_buff; Buff _write_buff; void _init(); friend class UsbHandle; protected: //Création, initialisations UsbBulkBuff(); inline void init(struct usb_dev_handle* dh, int wep, int wto, int rep, int rto); //reset des buffers void reset(); //put basique (s,v) => voir macros send monobloc int put(int s, void* v); //écrit le buffer in, lit dans le buffer out int write_read( const char* vprolog); //get basique (s,p) => voir macros receive monobloc int get(int s, void* v); // Erreurs de la classe ... static ErrorMng error; //taille max buffer in static int maxsz(){ return Buff::maxsz(); } }; inline void UsbBulkBuff::reset(){ _read_buff.reset(); _write_buff.reset(); } inline void UsbBulkBuff::_init(){ _devh = NULL; _write_ep = _write_to = _read_ep = _read_to = 0; reset(); } inline void UsbBulkBuff::init(struct usb_dev_handle* dh, int wep, int wto, int rep, int rto){ _devh = dh; _write_ep = wep; _write_to = wto; _read_ep = rep; _read_to = rto; reset(); } inline int UsbHandle::max_buff_sz(){ return _bbuff->maxsz(); } t2n-0.7.src/src/usbnxt.h0000644001311200041100000000404614607236353015413 0ustar raymondpsynchron /* ----- Copyright 2007 CNRS (VERIMAG) ------------------------------------- -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- * Projet Talk to NXT * ------------------------------------------------------------------------- * module : usbnxt.h * * date : 2007-03-07 * auteurs : Pascal Raymond *-------------------------------------------------------------------------- * nature : Classe dérivée de UsbHandle, spécialement dédiée à la brique nxt. *-------------------------------------------------------------------------- * Modifs : * -----------------------------------------------------------------------*/ // Message d'erreurs de la lib ... extern const char* usbnxt_error(); class UsbNxt : public UsbHandle { int _fails(const char* c); //utile : récupère un descripteur de fichier int _unpack_filedesc( const char* fmsg, char* pstatus, char* pcmdhdl, char* pfnme, int* pfsz ); //utile: teste l'existence d'un fichier bool _file_exists(const char* nme); int _file_delete(const char* nme); public : UsbNxt(); int init(); // Informations : int battery_level(); int print_infos(); int list_files(); int upload(const char* fname); int download(const char* fname); int remove(const char* fname); }; t2n-0.7.src/src/usbscan.c0000644001311200041100000000416114607236354015520 0ustar raymondpsynchron/*------------------------------------------------------------------------- Copyright 2005 CNRS (VERIMAG) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- VERIMAG - Synchrone TOOLBOX --------------------------------------------------------------------------- module : usbscan.cc date : 30/08/2005 auteurs : Pascal Raymond modif : ---------------------------------------------------------------------------- test de scan sur un port usb ... --------------------------------------------------------------------------*/ #include "usb.h" #include #include // USB Générique : recherche d'un device particulier struct usb_device* find_usb_dev( u_int16_t vendor, u_int16_t product ){ struct usb_bus *busses, *bus; struct usb_device *devs, *d; u_int16_t v, p; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for(bus = busses; bus; bus = bus->next){ printf("bus dirname=%s\n", bus->dirname); devs = bus->devices; for(d=devs; d; d=d->next){ v = d->descriptor.idVendor; p = d->descriptor.idProduct; printf(" dev filename=%s, vendor=0x%04x, product=0x%04x\n", d->filename, v, p ); if((v == vendor) && (p==product)) return d; } } return NULL; } int main(){ struct usb_device *d; d = find_usb_dev(-1,-1); return 0; } t2n-0.7.src/src/t2n.cc0000644001311200041100000000640014607236353014725 0ustar raymondpsynchron /* ----- Copyright 2007 CNRS (VERIMAG) ------------------------------------- -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- * Projet Talk to NXT * ------------------------------------------------------------------------- * module : t2n.cc * * date : 2007-03-07 * auteurs : Pascal Raymond *-------------------------------------------------------------------------- * nature : command-line pour accéder au port USB de la brique NXT * utilise la librairie libusb (http://libusb.sourceforge.net) *-------------------------------------------------------------------------- * Modifs : * -----------------------------------------------------------------------*/ #include #include #include "version.h" #include "errors.h" #include "ezargs.h" #include "errormng.h" #include "usb.h" #include "usbmisc.h" #include "usbnxt.h" int main(int argc, const char* argv[]){ //set_verbose_mode(2); //Récup des arguments ... EzArgs myargs(VERSION); bool do_battery, do_info, do_ls; bool v1, v2, v3; const char* ulfname; const char* dlfname; const char* rmfname; myargs.add_bool("-b", "check battery level", &do_battery); myargs.add_bool("-i", "print nxt info", &do_info); myargs.add_bool("-ls", "list files", &do_ls); myargs.add_string("-put", "", "upload file", &ulfname, NULL); myargs.add_string("-get", "", "download file", &dlfname, NULL); myargs.add_string("-rm", "", "remove remote file", &rmfname, NULL); myargs.add_bool("-v", "verbose", &v1); myargs.add_bool("-vv", "more verbose", &v2); myargs.add_bool("-vvv", "gossipy", &v3); myargs.parse(argc, argv); if(v1) set_verbose_mode(); if(v2) set_verbose_mode(2); if(v3) set_verbose_mode(3); // Init brique UsbNxt zebrick; if (zebrick.init() != 0){ Error(usbnxt_error()); } Verbose("nxt brick found, usb initialized\n"); if (do_battery) { int b = zebrick.battery_level(); if (b < 0) Error(usbnxt_error()); printf("battery level = %dmV\n", b); } if (do_info) { int r = zebrick.print_infos(); if (r < 0) Error(usbnxt_error()); } if (do_ls) { int r = zebrick.list_files(); if (r < 0) Error(usbnxt_error()); } if (ulfname) { int r = zebrick.upload(ulfname); if (r < 0) Error(usbnxt_error()); } if (dlfname) { int r = zebrick.download(dlfname); if (r < 0) Error(usbnxt_error()); } if (rmfname) { int r = zebrick.remove(rmfname); if (r < 0) Error(usbnxt_error()); } Verbose("that's all folks...\n"); } t2n-0.7.src/src/version.h0000644001311200041100000000333014607236353015550 0ustar raymondpsynchron/* ----- Copyright 2007 CNRS (VERIMAG) ------------------------------------- -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- * Projet Talk to NXT * ------------------------------------------------------------------------- * module : version.h * * date : 2012-01-03 * rev : 2024-04-11 * auteurs : Pascal Raymond * *-------------------------------------------------------------------------- * nature : current version of the tool * *-------------------------------------------------------------------------- * Modifs : * -----------------------------------------------------------------------*/ //Project-Version #define TOOLNAME "talk2nxt" #define MAJOR "0" #define MINOR "7" //0.3 -> some bugs, -rm option //0.4 -> compile on linux 64 //0.5 -> patch by Petter Reinholdtsen //0.6 -> bug argv with static/64 bits //0.7 -> cleanup+compliance with (recent) gcc #define VERSION "0.7" t2n-0.7.src/src/usbnxt.cc0000644001311200041100000003473714607236353015563 0ustar raymondpsynchron /* ----- Copyright 2007 CNRS (VERIMAG) ------------------------------------- -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- * Projet Talk to NXT * ------------------------------------------------------------------------- * module : usbnxt.cc * * date : 2007-03-07 * auteurs : Pascal Raymond *-------------------------------------------------------------------------- * nature : Classe dérivée de UsbHandle, spécialement dédiée à la brique nxt. *-------------------------------------------------------------------------- * Modifs : * -----------------------------------------------------------------------*/ #include #include #include #include #include "errors.h" #include "errormng.h" #include "usb.h" #include "usbmisc.h" #include "usbnxt.h" //Les identifiants universels de la brique ... #define LEGO_VENDOR_ID 0x0694 #define LEGO_NXT_PRODUCT_ID 0x0002 //Les codes connus et exploités ... #define NXT_WRITE_EP 0x01 #define NXT_READ_EP 0x82 #define NXT_WRITE_TIMEOUT 1000 #define NXT_READ_TIMEOUT 1000 #define DIRECT_COMMAND 0x00 #define SYSTEM_COMMAND 0x01 #define GET_BATTERY_LEVEL 0x0B #define GET_DEVICE_INFO 0x9B #define OPEN_READ 0x80 #define READ_COMMAND 0x82 #define WRITE_COMMAND 0x83 #define CLOSE_COMMAND 0x84 #define DELETE_FILE 0x85 #define FIND_FIRST_FILE 0x86 #define FIND_NEXT_FILE 0x87 #define GET_FIRMWARE_VERSION 0x88 //#define OPEN_WRITE 0x8B //#define OPEN_WRITE 0x89 #define OPEN_WRITE 0x81 // Pour récupérer proprement // les message d'erreurs de la libusb ... static ErrorMng _usbnxt_error("usbnxt: "); const char* usbnxt_error(){ return _usbnxt_error.get(); } UsbNxt::UsbNxt(){} int UsbNxt::init(){ int r = UsbHandle::init(LEGO_VENDOR_ID, LEGO_NXT_PRODUCT_ID); if(r < 0) { _usbnxt_error.set(usbmisc_error()); return r; } UsbHandle::init_bulk( NXT_WRITE_EP, NXT_WRITE_TIMEOUT, NXT_READ_EP, NXT_READ_TIMEOUT ); return r; } int UsbNxt::_fails(const char* msg){ _usbnxt_error.set("%s - %s", usbmisc_error(), (char*)msg); return -1; } int UsbNxt::battery_level(){ //commande ... int res; char reply, command, status; char fmsg[] = "battery_level failed"; //Commande : res = send( "UsbNxt::battery_level", //prologue pour le verbose InC(DIRECT_COMMAND), InC(GET_BATTERY_LEVEL) ); if (res) return _fails(fmsg); int mV; // on récupère 3 chars, 1 short = 5 bytes res = receive ( OutC(&reply), OutC(&command), OutC(&status), OutS(&mV) ); if (res) return _fails(fmsg); Verbose(1, "battery_level reply=0x%02x command=0x%02x status=0x%02x mV=%d\n", reply, command, status, mV ); return mV; } int UsbNxt::print_infos(){ int res; char fmsg[] = "print_infos failed"; //--------------- //Firmware infos ... //--------------- res = send( "UsbNxt::print_infos", InC(SYSTEM_COMMAND), InC(GET_FIRMWARE_VERSION) ); if (res) return _fails(fmsg); // on récupère 3 + 4 bytes = 7 char reply, command, status; char pmv, pMv, fmv, fMv; res = receive ( OutC(&reply), OutC(&command), OutC(&status), OutC(&pmv), OutC(&pMv), OutC(&fmv), OutC(&fMv) ); if (res) return _fails(fmsg); printf("#### NXT INFOS ###############\n"); printf("protocol version=%d.%d firmware version=%d.%d\n", pMv, pmv, fMv, fmv); //--------------- //Device infos ... //--------------- res = send( "UsbNxt::print_infos", InC(SYSTEM_COMMAND), InC(GET_DEVICE_INFO) ); if (res) return _fails(fmsg); char nme[15]; char bt[6]; int btsignal; int freeflash; res = receive ( OutC(&reply), OutC(&command), OutC(&status), OutRAW(16, &nme[0]), OutRAW(6, &bt[0]), OutL(&btsignal), OutL(&freeflash) ); if (res) return _fails(fmsg); printf("NXT Name: %s\n", nme); printf("Blutooth address: "); int k; for(k=0; k<6; k++){ if(k) printf(":"); printf("%02x", bt[k]); } printf("\n"); printf("Blutooth signal: %d\n", btsignal); printf("Free user flash: %d\n", freeflash); return 0; } //utile : récupère un descripteur de fichier int UsbNxt::_unpack_filedesc( const char* fmsg, char* pstatus, //important: dernier si <> 0 char* pcmdhdl, //important: handle de l'iterateur char* pfnme, int* pfsz ){ int res; // retour : 3 + 1 + 20 + 1x4 = 28 // on récupère les 3 bytes habituels ... char reply, command; res = receive ( OutC(&reply), OutC(&command), OutC(pstatus), OutC(pcmdhdl), // le byte "handle" OutRAW(20, pfnme), // nom de fichier sur 21 char (y compris le '\0') OutL(pfsz) // taille du fichier sur un long ); if (res) return -1; return 0; } int UsbNxt::list_files(){ int res; char fmsg[] = "list_files failed"; //--------------- //On recherche le premier ... //--------------- res = send( "UsbNxt::list_files (first file)", InC(SYSTEM_COMMAND), InC(FIND_FIRST_FILE), InNTS(20, "*.*") ); if (res) return _fails(fmsg); char fnme[20]; int fsz; char status, cmdhdl; if(_unpack_filedesc(fmsg, &status, &cmdhdl, &fnme[0], &fsz) < 0) return _fails(fmsg); Verbose(2, "list_files command handler=%d\n", (int)cmdhdl); // affichons ... printf("FILE:\"%s\" SIZE:%d\n", fnme, fsz); //---------------- //puis les suivants ... //---------------- while(status == 0){ res = send( "UsbNxt::list_files (next file)", InC(SYSTEM_COMMAND), InC(FIND_NEXT_FILE), InC((int)cmdhdl) ); if (res) return _fails(fmsg); if(_unpack_filedesc(fmsg, &status, &cmdhdl, &fnme[0], &fsz) < 0) return _fails(fmsg); Verbose(2, "list_files command handler=%d\n", cmdhdl); printf("FILE:\"%s\" SIZE:%d\n", fnme, fsz); } //---------------- //puis on ferme la commande //---------------- res = send( "UsbNxt::print_infos", InC(SYSTEM_COMMAND), InC(CLOSE_COMMAND), InC((int)cmdhdl) ); if (res) return _fails(fmsg); return 0; } int filesize(const char* fname){ // Un peu bourrin, mais évite de faire appel // à des lib systèmes (portage vers windows) FILE* inf = fopen(fname, "r"); if(! inf) return -1; int fno = fileno(inf); //on lit à fond la caisse ... int n, size; char* buff[1024]; size = 0; do { n = read(fno, &buff[0], 1024); if(n > 0) size += n; } while(n > 0); fclose(inf); if(n < 0) return -1; return size; } int UsbNxt::download(const char* fname){ char fmsg[] = "download failed"; int res; if(strlen(fname) >= 20){ _usbnxt_error.set("download: filename must be less than 15 chars"); return -1; } //--------------- //Le fichier existe-t-il ? //--------------- res = send( "UsbNxt::dowload (search remote file)", InC(SYSTEM_COMMAND), InC(FIND_FIRST_FILE), InNTS(20, fname) ); if (res) return _fails(fmsg); char dummy[20]; int fsz; char status, cmdhdl; if(_unpack_filedesc(fmsg, &status, &cmdhdl, &dummy[0], &fsz) < 0) return _fails(fmsg); if(status) { _usbnxt_error.set("download: can't find remote file (status=0x%02x)", status); return -1; } res = send( "UsbNxt::download", InC(SYSTEM_COMMAND), InC(CLOSE_COMMAND), InC((int)cmdhdl) ); if (res) return _fails(fmsg); //--------------- //Ouverture du local //--------------- FILE* localf = fopen(fname, "w"); if(! localf) { _usbnxt_error.set("download: can't open local file (%s)", strerror(errno)); return -1; } int fno = fileno(localf); //--------------- //Ouverture du remote //--------------- res = send( "UsbNxt::dowload (search remote file)", InC(SYSTEM_COMMAND), InC(OPEN_READ), InNTS(20, fname) ); if (res) return _fails(fmsg); char reply, command, fhandler; int fsize; res = receive ( OutC(&reply), OutC(&command), OutC(&status), OutC(&fhandler), OutS(&fsize) ); if (res) return _fails(fmsg); if (status){ _usbnxt_error.set("download: can't open remote file (status=0x%02x)", status); return -1; } //------------ // lecture par gros paquets // max buff -4 bytes -1*2 (short) //------------ int maxpiece = max_buff_sz() - 6; char buff[maxpiece]; Verbose("start to download %s (%d bytes)\n", fname, fsize); int remain = fsize; while (remain) { int to_do = (remain >= maxpiece)? maxpiece : remain; int res = send( "UsbNxt::download", InC(SYSTEM_COMMAND), InC(READ_COMMAND), InC((int)fhandler), InS(to_do) ); if (res) return _fails(fmsg); int nbread; res = receive( OutC(&reply), OutC(&command), OutC(&status), OutC(&fhandler), OutS(&nbread), OutRAW(to_do, buff) ); if (res) return _fails(fmsg); res = write(fno, &buff[0], nbread); if (res != nbread) { _usbnxt_error.set("download: write local file failed (%s)", strerror(errno)); return -1; } remain -= nbread; } fclose(localf); //---------------- //puis on ferme la commande //---------------- res = send( "UsbNxt::download(close)", InC(SYSTEM_COMMAND), InC(CLOSE_COMMAND), InC((int)fhandler) ); if(status) { _usbnxt_error.set("download: error while writing (status=%02x)", status); return -1; } return 0; } //Teste si un fichier existe dans la brique ... bool UsbNxt::_file_exists(const char* nme){ //--------------- //Le fichier existe déjà ? //--------------- char fmsg[] = "file_exists failed"; Verbose("testing for existing file \"%s\"\n", nme); int res = send( "_file_exists", InC(SYSTEM_COMMAND), InC(FIND_FIRST_FILE), InNTS(20, nme) ); if (res) return _fails(fmsg); char fnme[20]; int fsz; char status, cmdhdl; if(_unpack_filedesc(fmsg, &status, &cmdhdl, &fnme[0], &fsz) < 0) return _fails(fmsg); //Un nom de fichier vide -> il n'existe pas return (fnme[0] != '\0'); } int UsbNxt::_file_delete(const char* nme){ //Commande simple : on lui passe le nom char fmsg[] = "file_delete failed"; Verbose("deleting for existing file \"%s\"\n", nme); int res = send( "_file_delete", InC(SYSTEM_COMMAND), InC(DELETE_FILE), InNTS(20, nme) ); if (res) return _fails(fmsg); //Retour simple : juste le status char reply, command, status ; res = receive ( OutC(&reply), OutC(&command), OutC(&status) ); if (res) return _fails(fmsg); return 0; } int UsbNxt::remove(const char* fname){ //char fmsg[] = "remove failed"; //int res; if (_file_exists(fname)){ if ( AskYesNo("delete file \"%s\"", fname)){ //Fermer le fichier ? //Détruire le fichier ... if (_file_delete(fname)) return -1; } else { Verbose("delete aborted by user\n"); return 0; } } else { return -1; } return 0; } int UsbNxt::upload(const char* fname){ char fmsg[] = "upload failed"; int res; //-------- // Vérif du nom //-------- char *dirc, *basec, *bname, *dname; dirc = strdup(fname); basec = strdup(fname); dname = dirname(dirc); bname = basename(basec); char* ext = strrchr(bname, '.'); Verbose(2,"upload dir=%s file=%s ext=%s\n", dname, bname, ext); /* if(strcmp(ext, ".rxe")){ _usbnxt_error.set("upload: .rxe extention required"); return -1; } */ if(strlen(bname) >= 20){ _usbnxt_error.set("upload: filename must be less than 15 chars"); return -1; } //--------------- //Le fichier existe déjà ? //--------------- if (_file_exists(bname)){ if ( AskYesNo("overwrite existing file \"%s\"", bname)){ //Fermer le fichier ? //Détruire le fichier ... if (_file_delete(bname)) return -1; } else { Verbose("upload aborted by user\n"); return 0; } } //-------- // Portable : on compte le nbre de bits .... //-------- int fsize = filesize(fname); if(fsize < 0){ _usbnxt_error.set("upload: can't load file (%s)", strerror(errno)); return -1; } Verbose("upload %s (%d bytes) from %s\n", bname, fsize, dname); //---- // Ouverture de la session d'écriture // !! c'est le basename qui donne le nom local !! // sc + ow + bname (20) + fsz (4) //---- res = send( "UsbNxt::upload (open)", InC(SYSTEM_COMMAND), InC(OPEN_WRITE), InNTS(20, bname), InL(fsize) ); if (res) return _fails(fmsg); char reply = '\0'; char command = '\0'; char status = '\0'; char fhandler = '\0'; res = receive ( OutC(&reply), OutC(&command), OutC(&status), OutC(&fhandler) ); if (res) return _fails(fmsg); if (status){ printf( "usb_strerror = %s\n", usb_strerror( )); _usbnxt_error.set( "upload: can't initiate upload (reply=0x%02x,status=0x%02x,error=0x%04x)", reply, status, res); return -1; } //--------------------- // Ecriture par paquets max : // max buff -3 bytes de début //--------------------- int maxpiece = max_buff_sz() - 3; char buff[maxpiece]; FILE* inf = fopen(fname,"r"); int fno = fileno(inf); int nbb; int berr=false; //erreur interne do { nbb = read(fno, &buff[0], maxpiece); if (nbb) { berr = send( "UsbNxt::upload(sending block)", InC(SYSTEM_COMMAND), InC(WRITE_COMMAND), InC((int)fhandler), InRAW(nbb, &buff[0]) ); int sbytes; berr = receive ( OutC(&reply), OutC(&command), OutC(&status), OutC(&fhandler), OutS(&sbytes) ); } } while (nbb && !berr && !status); fclose(inf); if(berr) return _fails(fmsg); //---------------- //puis on ferme la commande //---------------- res = send( "UsbNxt::upload(close)", InC(SYSTEM_COMMAND), InC(CLOSE_COMMAND), InC((int)fhandler) ); if(status) { _usbnxt_error.set("upload: error while writing (status=%02x)", status); return -1; } return 0; } /* int nxt_battery(usb_dev_handle* dev){ int r; buffer com; buffer res; char reply_c; char command_c; char status_c; unsigned int mV; com[0] = DIRECT_COMMAND; com[1] = GET_BATTERY_LEVEL; r = do_nxt_command(dev, &com[0], 2, &res[0]); // retour : byte, byte, byte, short (le) if (r != 5) { fprintf(stderr, "nxt_battery: bad response (%d bytes)\n", r); return -1; } reply_c = res[0]; command_c = res[1]; status_c = res[2]; mV = ((unsigned int)res[3] << 8) & (unsigned int)res[4]; return (int)mV; } int main(){ struct usb_dev_handle *nxt; nxt = find_nxt(); if(nxt) { printf ("TROUVÉ !!!\n"); } else { printf ("pas trouvé ...\n"); return 1; } usb_reset(nxt); CleanReturn: if(nxt) { usb_close(nxt); } } */ t2n-0.7.src/src/ezargs.cc0000644001311200041100000001716414607236354015527 0ustar raymondpsynchron/*------------------------------------------------------------------------- Copyright 2005 CNRS (VERIMAG) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- VERIMAG - Synchrone TOOLBOX --------------------------------------------------------------------------- module : ezargs.cc date : 30/08/2005 auteurs : Pascal Raymond ---------------------------------------------------------------------------- nature : Classe EzArgss, pour faciliter la gestion des arguments de commande (argc, argv). --------------------------------------------------------------------------*/ #include #include #include #include #include #include #include "errors.h" #include "ezargs.h" //LES LISTES NE SE CONSTRUISENT QUE PAR //DES APPEND !! class EzArgsToken { protected: const char* _key; const char* _param; const char* _man; EzArgsToken* _next; EzArgsToken* _last_known; EzArgsToken* last(){ while(_last_known->_next){ _last_known = _last_known->_last_known; } return _last_known; } public: EzArgsToken* next(){ return _next; } EzArgsToken( const char* key, const char* par, const char* man ){ _key = key; _param = par; _man = man; _next = NULL; _last_known = this; } friend EzArgsToken* append(EzArgsToken* self, EzArgsToken* a){ if(self){ self->last()->_next = a; self->_last_known = a; return self; } else { return a; } } virtual const char** local_accept(const char** av){ Error("EzArgsToken::local_accept purely virtual"); return NULL; } //accept récursif en commencant par le début const char** accept(const char** av){ const char** res = local_accept(av); if (res) return res; else if(_next) return _next->accept(av); else return NULL; } void dump(){ int prec = -10+strlen(_key); if(prec > 0) prec = 0; printf(" %s %*s : %s\n", _key, prec, (_param)? _param : (char*)"", (_man)? _man : (char*)"" ); if(_next) _next->dump(); } //juste les params sur la même ligne ... friend void dump_param(EzArgsToken* self){ if(! self) return; if(self->_param) printf("%s ", self->_param); if(self->_next) dump_param(self->_next); } }; class EzArgsTokenBool: public EzArgsToken { bool* _ptr; public: EzArgsTokenBool(const char* key, const char* man,bool* r) :EzArgsToken(key,NULL,man) { _ptr = r; *r = false; } const char** local_accept(const char** av){ if(! av) return NULL; if(!strcmp(*av, _key)){ *_ptr = true; return av; } else { return NULL; } } }; class EzArgsTokenString: public EzArgsToken { const char** _ptr; public: EzArgsTokenString( const char* key, const char* par, const char* man, const char** r, const char* dflt) : EzArgsToken(key,par,man) { _ptr = r; *_ptr = dflt; } const char** local_accept(const char** av){ if(! av) return NULL; if(!strcmp(*av, _key)){ av++; if(*av ) { *_ptr = *av; return av; } Error("EzArgs: string expected after '%s' option\n", _key); return NULL; } else { return NULL; } } }; typedef const char* cstring; //Les "extra" stockent des args sans clé class EzArgsExtra : public EzArgsToken { const char** _ptr; bool _used; public: EzArgsExtra( const char* par, const char* man, //const char** r, const char** r, const char* dflt ) :EzArgsToken("", par, man) { _ptr = r; *r = dflt; _used = false; } //accepte uniquement s'il est le premier libre ! const char** local_accept(const char** av){ if(!av) return NULL; if(_used) return NULL; else { *_ptr = *av; _used = true; return av; } } }; inline bool myatoi(const char* src, int* ptr){ long x; char* e; x = strtol(src, &e, 10); *ptr = (int)x; return (*e == '\0'); } class EzArgsTokenInt: public EzArgsToken { int* _ptr; bool* _sptr; public: EzArgsTokenInt( const char* key, const char* par, const char* man, int* r, bool* rset, int dflt ) : EzArgsToken(key,par,man) { _ptr = r; _sptr = rset; if(_sptr) *_sptr = false; *r = dflt; } const char** local_accept(const char** av){ if(! av) return NULL; if(!strcmp(*av, _key)){ av++; if(*av && myatoi(*av, _ptr)) { if(_sptr) *_sptr = true; return av; } Error("EzArgs: integer expected after '%s' option\n", _key); return NULL; } else { return NULL; } } }; bool EzArgs::add_bool(const char* key, const char* man, bool* r){ _tokens = append(_tokens, new EzArgsTokenBool(key, man, r)); return true; } bool EzArgs::add_int(const char* key, const char* par, const char* man, int* r, int dflt){ _tokens = append(_tokens, new EzArgsTokenInt(key, par, man, r, NULL, dflt)); return true; } bool EzArgs::add_int(const char* key, const char* par, const char* man, int* r, bool* rset){ _tokens = append(_tokens, new EzArgsTokenInt(key, par, man, r, rset, 0)); return true; } bool EzArgs::add_string( const char* key, const char* par, const char* man, const char** r, const char* dflt ){ _tokens = append(_tokens, new EzArgsTokenString(key, par, man, r, dflt)); return true; } //Les extra string sont dans une liste à part ! bool EzArgs::add_extra(const char* par, const char* man, const char** r, const char* dflt){ _extras = append(_extras, new EzArgsExtra(par, man, r, dflt)); _nb_extras++; return true; } //usage par défaut ... void EzArgs::usage(){ char* tn = basename((char*)_toolname); printf("%s version %s\n", tn, _version); printf("usage: %s [options] ", tn); dump_param(_extras); printf("| %s -help\n", tn); } void EzArgs::giveoptions(){ printf("recognized options:\n"); _tokens->dump(); } const char* EzArgs::version(){ return _version; } const char* EzArgs::toolname(){ return basename((char*)_toolname); } EzArgs::EzArgs(const char* vers){ _version = vers; _nb_extras = 0; _tokens = NULL; _extras = NULL; } bool EzArgs::parse(int ac, const char* av[]){ //PROLOGUE: options prédéfinies add_bool("-help", "print help and return", &_givehelp); add_bool("-version", "print version and return", &_giveversion); //PROLOGUE: gestions des extras //on les mets dans une table et dans le bon ordre ... /* USELESS ... EzArgsToken* extras_tab[_nb_extras]; int k = _nb_extras; EzArgsToken* l = _extras; while(k--) { extras_tab[k] = l; l = l->next(); } */ _argc = ac; //on décale les args et ont met //un NULL à la fin _argv = new const char*[ac]; _toolname = av[0]; int i; for(i=1; i< ac; i++){ _argv[i-1] = av[i]; } _argv[i-1] = NULL; const char** a; for(a = &_argv[0]; *a; a++){ const char** nwa = _tokens->accept(a); //option avec clé ? if(nwa) { a = nwa; } else { //on le met dans les extra s'il reste de la place !! if((_extras) && (_extras->accept(a))){ //ok .. } else { Error("EzArgs: unrecognized option '%s'", *a); } } } if(_givehelp){ givehelp(); exit(0); } if(_giveversion){ printf("%s", version()); exit(0); } return true; } t2n-0.7.src/udev/0000755001311200041100000000000014605730440014061 5ustar raymondpsynchront2n-0.7.src/udev/72-lego.rules0000644001311200041100000000051214607236354016316 0ustar raymondpsynchron# Lego NXT # To be put in /etc/udev/rules.d/ # New syntax, lsb_release -a # Debian GNU/Linux 6.0.4 (squeeze) SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0694", ATTRS{idProduct}=="0002", MODE:="0666" SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="6124", MODE:="0666"