diff options
author | Scott Fritzinger <scottf@unr.edu> | 2001-01-22 19:19:02 +0000 |
---|---|---|
committer | Scott Fritzinger <scottf@unr.edu> | 2001-01-22 19:19:02 +0000 |
commit | 3dd042f1501e97af442c34310b50423b11e01312 (patch) | |
tree | e484a9422ef2e92d6ecdaeca1dbd9221c31e2837 /libgphoto2_port | |
parent | 00b15183476d549bbafe9cb6999bf93dd0ca4009 (diff) | |
download | libgphoto2-3dd042f1501e97af442c34310b50423b11e01312.tar.gz |
added libgphoto2_port into tree. ouch.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@1526 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2_port')
46 files changed, 3995 insertions, 0 deletions
diff --git a/libgphoto2_port/AUTHORS b/libgphoto2_port/AUTHORS new file mode 100644 index 000000000..89e6db8dd --- /dev/null +++ b/libgphoto2_port/AUTHORS @@ -0,0 +1,5 @@ +Scott Fritzinger <scottf@unr.edu> +Johannes Erdfelt <jerdfelt@valinux.com> (USB support) + +Based on work by: +Beat Christen <spiff@longstreet.ch> diff --git a/libgphoto2_port/COPYING.LIB b/libgphoto2_port/COPYING.LIB new file mode 100644 index 000000000..eb685a5ec --- /dev/null +++ b/libgphoto2_port/COPYING.LIB @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. 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 not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library 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 +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/libgphoto2_port/ChangeLog b/libgphoto2_port/ChangeLog new file mode 100644 index 000000000..a862db38d --- /dev/null +++ b/libgphoto2_port/ChangeLog @@ -0,0 +1,23 @@ +2000-07-15 Fabrice Bellet <Fabrice.Bellet@creatis.insa-lyon.fr> + + * gpio-usb.c : removed useless call to usb_release_interface() + because the usbdev close ioctl already does the job for us. + Compilation warning fix. + +2000-07-09 Fabrice Bellet <Fabrice.Bellet@creatis.insa-lyon.fr> + + * Makefile.am : fixed typo. + * gpio-usb.c : cosmetic namespace changes. + * gpio.c : fixed compilation warnings. + +2000-01-07 Ole Aamot <oka@ifi.uio.no> + + * Added USB patch from Johannes Erdfelt <jerdfelt@valinux.com> + +1999-12-28 Ole Aamot <oka@ifi.uio.no> + + * libgpio.spec.in: added + +1999-12-27 Ole Aamot <oka@ifi.uio.no> + + * Added auto* build scripts. diff --git a/libgphoto2_port/Makefile.am b/libgphoto2_port/Makefile.am new file mode 100644 index 000000000..1a70d55c6 --- /dev/null +++ b/libgphoto2_port/Makefile.am @@ -0,0 +1,35 @@ +## Process this file with automake to produce Makefile.in + +## Specify some includes and versioning +INCLUDES = -I@srcdir@ $(VERSION_FLAGS) +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" -DHAVE_TERMIOS_H + +## Executable files +bin_SCRIPTS = gphoto2-port-config + +SUBDIRS = libgphoto2_port include @IOLIB_SUBDIRS@ + +## GNOME configuration script +confexecdir=$(libdir) +confexec_DATA = gphoto2portConf.sh + +## Extra files +CLEANFILES=gphoto2portConf.sh +EXTRA_DIST = \ + AUTHORS \ + ChangeLog \ + COPYING.LIB \ + NEWS \ + README \ + libgphoto2_port.spec \ + gphoto2-port-config.in \ + gphoto2portConf.sh.in + +gphoto2portConf.sh: gphoto2portConf.sh.in Makefile +## Use sed and then mv to avoid problems if the user interrupts. + sed -e 's?\@GPPORT_LIBDIR\@?$(GPPORT_LIBDIR)?g' \ + -e 's?\@GPPORT_INCLUDEDIR\@?$(GPPORT_INCLUDEDIR)?g' \ + -e 's?\@GPPORT_LIBS\@?$(GPPORT_LIBS)?g' \ + -e 's?\@LIBGPPORT_VERSION\@?$(LIBGPPORT_VERSION)?g' \ + < $(srcdir)/gphoto2portConf.sh.in > gphoto2portConf.tmp \ + && mv gphoto2portConf.tmp gphoto2portConf.sh diff --git a/libgphoto2_port/NEWS b/libgphoto2_port/NEWS new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/libgphoto2_port/NEWS diff --git a/libgphoto2_port/README b/libgphoto2_port/README new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/libgphoto2_port/README diff --git a/libgphoto2_port/acconfig.h b/libgphoto2_port/acconfig.h new file mode 100644 index 000000000..e86bb4129 --- /dev/null +++ b/libgphoto2_port/acconfig.h @@ -0,0 +1,5 @@ +#undef HAVE_TERMIOS_H +#undef HAVE_STRFTIME +#undef HAVE_LOCALTIME +#undef HAVE_FCNTL_H +#undef HAVE_RTS_IOCTL diff --git a/libgphoto2_port/autogen.sh b/libgphoto2_port/autogen.sh new file mode 100755 index 000000000..733d1fba0 --- /dev/null +++ b/libgphoto2_port/autogen.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. +# This was lifted from the Gimp, and adapted slightly by +# Raph Levien <raph@acm.org>. + +DIE=0 +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +PROJECT=libgphoto2_port + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +# Do we really need libtool? +(libtool --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have libtool installed to compile $PROJECT." + echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 +} + +(automake --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have automake installed to compile $PROJECT." + echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." +fi + +case $CC in +xlc ) + am_opt=--include-deps;; +esac + +for dir in $srcdir +do + echo processing $dir + (cd $dir; \ + aclocalinclude="$ACLOCAL_FLAGS"; \ + aclocal $aclocalinclude; \ + autoheader; automake --add-missing --gnu $am_opt; autoconf) +done + +$srcdir/configure "$@" + +echo +echo "Now type 'make' to compile $PROJECT." diff --git a/libgphoto2_port/configure.in b/libgphoto2_port/configure.in new file mode 100644 index 000000000..a0bc99daa --- /dev/null +++ b/libgphoto2_port/configure.in @@ -0,0 +1,120 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_INIT(libgphoto2_port/gp_port.c) +AM_CONFIG_HEADER(config.h) + +LIBGPPORT_MAJOR_VERSION=0 +LIBGPPORT_MINOR_VERSION=0 +LIBGPPORT_MICRO_VERSION=3 +LIBGPPORT_VERSION=$LIBGPPORT_MAJOR_VERSION.$LIBGPPORT_MINOR_VERSION.$LIBGPPORT_MICRO_VERSION +LIBGPPORT_VERSION_INFO=`expr $LIBGPPORT_MAJOR_VERSION + $LIBGPPORT_MINOR_VERSION`:$LIBGPPORT_MICRO_VERSION:$LIBGPPORT_MINOR_VERSION + +AC_SUBST(LIBGPPORT_MAJOR_VERSION) +AC_SUBST(LIBGPPORT_MINOR_VERSION) +AC_SUBST(LIBGPPORT_MICRO_VERSION) +AC_SUBST(LIBGPPORT_VERSION) +AC_SUBST(LIBGPPORT_VERSION_INFO) + +VERSION=$LIBGPPORT_VERSION + +AM_INIT_AUTOMAKE(libgphoto2_port, $VERSION) +AM_MAINTAINER_MODE + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_CPP +AM_PROG_LIBTOOL + +dnl Turn on debugging and catch GNU features incompatible with ANSI C. +CFLAGS="$CFLAGS -g -Wall -ansi" +LDFLAGS="$LDFLAGS -g -Wall -ansi" + +dnl Checks for header files. +AC_HEADER_DIRENT +AC_HEADER_STDC + +AC_CHECK_HEADERS(stdlib.h unistd.h stdio.h fcntl.h errno.h sys/time.h) +AC_CHECK_HEADERS(sys/param.h termios.h sgetty.h ttold.h ioctl-types.h \ + fcntl.h sgtty.h sys/ioctl.h sys/time.h termio.h unistd.h \ + endian.h byteswap.h asm/io.h) + +dnl Checks for library functions. +AC_FUNC_STRFTIME +AC_CHECK_FUNCS(strdup strndup strerror snprintf) +AC_CHECK_FUNCS(strftime localtime) + +dnl Check if TIOCM_RTS is included in one of several possible files +AC_TRY_COMPILE([#include <termios.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) +AC_TRY_COMPILE([#include <termio.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) +AC_TRY_COMPILE([#include <ioctl-types.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) +AC_TRY_COMPILE([#include <sys/ioctl.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) + +GPPORT_LIBDIR='-L${libdir}' +GPPORT_INCLUDEDIR='-I${includedir}' +GPPORT_LIBS="-lgphoto2_port" + +dnl Compile in serial support +IOLIB_SUBDIRS="serial" +IOLIB_LDFLAGS="-Lserial -lgphoto2_port_serial" +IOLIB_CFLAGS="-DGP_PORT_SUPPORTED_SERIAL" + +dnl Compile in usb support +AC_PATH_PROG(LIBUSB_CONFIG,libusb-config) +if test -n "${LIBUSB_CONFIG}"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS usb" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS `libusb-config --libs` -lgphoto2_port_usb" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_USB `libusb-config --cflags`" +else + AC_MSG_WARN([ + +*** You need Johannes Erdfelt's libusb library for USB support +*** http://download.sourceforge.net/libusb/libusb-0.1.2.tar.gz +]) +fi + +dnl Compile in parallel support +GP_PORT_PARALLEL=0 +if test "$GPPORT_PARALLEL" = "1"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS parallel" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_PARALLEL" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS -Lparallel -lgphoto2_port_parallel" +fi + +dnl Compile in network support +GP_PORT_NETWORK=0 +if test "$GPPORT_NETWORK" = "1"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS network" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_NETWORK" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS -Lnetwork -lgphoto2_port_network" +fi + +dnl Compile in firewire (oops, i said the word) support +GP_PORT_IEEE1394=0 +if test "$GPPORT_IEEE1394" = "1"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS ieee1394" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_IEEE1394" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS -Lieee1394 -lgphoto2_port_ieee1394" +fi + +AC_SUBST(GPPORT_LIBDIR) +AC_SUBST(GPPORT_LIBS) +AC_SUBST(GPPORT_INCLUDEDIR) +AC_SUBST(IOLIB_SUBDIRS) +AC_SUBST(IOLIB_LDFLAGS) +AC_SUBST(IOLIB_CFLAGS) + +AC_OUTPUT( \ +libgphoto2_port.spec \ +Makefile \ +libgphoto2_port/Makefile \ +serial/Makefile \ +parallel/Makefile \ +usb/Makefile \ +ieee1394/Makefile \ +network/Makefile \ +include/Makefile \ +gphoto2-port-config) diff --git a/libgphoto2_port/doc/Makefile.am b/libgphoto2_port/doc/Makefile.am new file mode 100644 index 000000000..f4f9ac278 --- /dev/null +++ b/libgphoto2_port/doc/Makefile.am @@ -0,0 +1,61 @@ +## Process this file with automake to produce Makefile.in + +# The name of the module. +DOC_MODULE=libgpio + +# The top-level SGML file. +DOC_MAIN_SGML_FILE=libgpio.sgml + +# The directory containing the source code (if it contains documentation). +DOC_SOURCE_DIR=.. + +HTML_DIR=$(prefix)/share/doc/libgpio$(LIBGPIO_MAJOR_VERSION).$(LIBGPIO_MINOR_VERSION)-dev/html + +TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) + + +scan: + gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="acconfig.h config.h examples/jmtransfer.h src/libgpio-private.h src/ftp.h" + +templates: scan + gtkdoc-mktmpl --module=$(DOC_MODULE) + +sgml: + gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) + +html: + if ! test -d html ; then mkdir html ; fi + -cd html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) + +clean-local: + rm -f *~ *.bak *.hierarchy *.signals *-unused.txt + +maintainer-clean-local: clean + rm -rf sgml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt + +libgpio-decl-list.txt : templates + +libgpio-sections.txt : scan + cp libgpio-decl-list.txt libgpio-sections.txt + +rebuild: libgpio-sections.txt templates sgml html + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR) + -@INSTALL@ -m 0644 $(srcdir)/html/*.html $(DESTDIR)$(TARGET_DIR) + -@INSTALL@ -m 0644 $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) + -(cd $(DESTDIR); gtkdoc-fixxref --module=$(DOC_MODULE) --html-dir=$(HTML_DIR)) + -mv $(HTML_DIR)/$(DOC_MODULE)/* $(HTML_DIR) + -rm -rf $(HTML_DIR)/$(DOC_MODULE) + -(cd $(HTML_DIR); ln -s book1.html index.html) + +dist-hook: + (cd $(srcdir) ; tar cvf - html/*.html html/*.sgml) | (cd $(distdir); tar xf -) + +copyweb: + rm -rf $(HOME)/public_html/libgpio/docs/* + cp -f html/*.html $(HOME)/public_html/libgpio/docs + cp -f $(HOME)/public_html/libgpio/docs/book1.html $(HOME)/public_html/libgpio/docs/index.html + chmod -R a+rX $(HOME)/public_html/libgpio/docs + +.PHONY : html sgml templates scan diff --git a/libgphoto2_port/doc/libgphoto2-port-sections.txt b/libgphoto2_port/doc/libgphoto2-port-sections.txt new file mode 100644 index 000000000..ab3342bf1 --- /dev/null +++ b/libgphoto2_port/doc/libgphoto2-port-sections.txt @@ -0,0 +1,136 @@ +<SECTION> +<FILE>gpio-ieee1394</FILE> +gpio_ieee1394_settings +</SECTION> + +<SECTION> +<FILE>gpio-network</FILE> +GPIO_NETWORK +gpio_network_settings +</SECTION> + +<SECTION> +<FILE>gpio-parallel</FILE> +GPIO_PARALLEL +GPIO_PARALLEL_PREFIX +GPIO_PARALLEL_RANGE_LOW +GPIO_PARALLEL_RANGE_HIGH +gpio_parallel_settings +</SECTION> + +<SECTION> +<FILE>gpio-serial</FILE> +GPIO_SERIAL +GPIO_SERIAL_PREFIX +GPIO_SERIAL_RANGE_LOW +GPIO_SERIAL_RANGE_HIGH +gpio_serial_settings +PIN_RTS +PIN_DTR +PIN_CTS +PIN_DSR +PIN_CD +PIN_RING +</SECTION> + +<SECTION> +<FILE>gpio-usb</FILE> +gpio_usb_settings +</SECTION> + +<SECTION> +<FILE>gpioos2</FILE> +CBAUD +B0 +B50 +B75 +B110 +B134 +B150 +B200 +B300 +B600 +B1200 +B1800 +B2400 +B4800 +B9600 +B19200 +B38400 +EXTA +EXTB +CSIZE +CS5 +CS6 +CS7 +CS8 +CSTOPB +CREAD +PARENB +PARODD +HUPCL +CLOCAL +CBAUDEX +B57600 +B115200 +B230400 +B460800 +B76800 +B153600 +B307200 +B614400 +B921600 +B500000 +B576000 +B1000000 +B1152000 +B1500000 +B2000000 +CIBAUD +CMSPAR +CRTSCTS +TIOCM_LE +TIOCM_DTR +TIOCM_RTS +TIOCM_ST +TIOCM_SR +TIOCM_CTS +TIOCM_CAR +TIOCM_RNG +TIOCM_DSR +TIOCM_CD +TIOCM_RI +TIOCMBIC +TIOCMBIS +TIOCMGET +</SECTION> + +<SECTION> +<FILE>gpio</FILE> +GPIO_USB +GPIO_IEEE1394 +GPIO_MAX_BUF_LEN +GPIO_OK +GPIO_ERROR +GPIO_TIMEOUT +gpio_device_type +gpio_device_info +gpio_init +gpio_get_device_count +gpio_get_device_info +gpio_new +gpio_new_by_number +gpio_new_by_port +gpio_free +gpio_open +gpio_close +gpio_set_timeout +gpio_get_timeout +gpio_set_settings +gpio_get_settings +gpio_write +gpio_read +gpio_get_pin +gpio_set_pin +</SECTION> + diff --git a/libgphoto2_port/doc/libgphoto2-port.sgml b/libgphoto2_port/doc/libgphoto2-port.sgml new file mode 100644 index 000000000..ab76b0dd0 --- /dev/null +++ b/libgphoto2_port/doc/libgphoto2-port.sgml @@ -0,0 +1,56 @@ +<!DOCTYPE BOOK PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [ +<!entity libgpio-gpio-ieee1394 SYSTEM "sgml/gpio-ieee1394.sgml"> +<!entity libgpio-gpio-network SYSTEM "sgml/gpio-network.sgml"> +<!entity libgpio-gpio-parallel SYSTEM "sgml/gpio-parallel.sgml"> +<!entity libgpio-gpio-serial SYSTEM "sgml/gpio-serial.sgml"> +<!entity libgpio-gpio-usb SYSTEM "sgml/gpio-usb.sgml"> +<!entity libgpio-gpioos2 SYSTEM "sgml/gpioos2.sgml"> +<!entity libgpio-gpio SYSTEM "sgml/gpio.sgml"> +]> + +<book> + <bookinfo> + <title>GPIO (gPhoto I/O) Library Reference Manual</title> + <abstract> + <para> + This manual documents the GPIO, the GPhoto I/O library. + It gives an overview of GPIO, discusses examples that + come with GPIO and includes detailed documentation of + the GPIO API. + </para> + </abstract> + </bookinfo> + + <chapter id="gpio-overview"> + <title>GPIO Overview</title> + + <para> + GPIO is the GPhoto I/O library. + </para> + + <para> + The benefit to using this library would be that all communications can be + done quickly and without worry for device specific functions; all devices + are abstracted to a point, allowing you to read/write to a device using + the same interface. For example, you can set all the options on the + serial port easily, and then read/write to that device. Additionally, + you could easily switch over to a USB device, and read/write without + having to learn the USB internals. + </para> + + <para> + The whole idea behind this is simplicity. It should be easy to write a + program that uses any sort of serial-based device. This will take the + hassle out of playing with low-level configurations and actually just + get on to writing the core of the application. + </para> + + &libgpio-gpio; + &libgpio-gpio-usb; + &libgpio-gpio-serial; + &libgpio-gpio-network; + &libgpio-gpio-parallel; + &libgpio-gpio-ieee1394; + &libgpio-gpioos2; + </chapter> +</book> diff --git a/libgphoto2_port/gphoto2-port-config.in b/libgphoto2_port/gphoto2-port-config.in new file mode 100644 index 000000000..1f1b008d0 --- /dev/null +++ b/libgphoto2_port/gphoto2-port-config.in @@ -0,0 +1,71 @@ +#! /bin/sh + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +includedir=@includedir@ + +usage() +{ + cat <<EOF +Usage: gphoto2-port-config [OPTION] + +Known values for OPTION are: + + --prefix=DIR change libgphoto2-port prefix [default $prefix] + --libs print library linking information + --cflags print pre-processor and compiler flags + --help display this help and exit + --version output version information +EOF + + exit $1 +} + +if test $# -eq 0; then + usage 1 +fi + +cflags=false +libs=false + +while test $# -gt 0; do + case "$1" in + -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + case "$1" in + --prefix=*) + prefix=$optarg + ;; + + --prefix) + echo $prefix + ;; + + --version) + echo @PACKAGE@ @VERSION@ + exit 0 + ;; + + --help) + usage 0 + ;; + + --cflags) + echo -I${includedir}/gphoto2-port @GPPORT_INCLUDEDIR@ @IOLIB_CFLAGS@ + ;; + + --libs) + echo -L@libdir@ @GPPORT_LIBS@ @LIBS@ + ;; + + *) + usage + exit 1 + ;; + esac + shift +done + +exit 0 diff --git a/libgphoto2_port/gphoto2portConf.sh.in b/libgphoto2_port/gphoto2portConf.sh.in new file mode 100644 index 000000000..2b921935f --- /dev/null +++ b/libgphoto2_port/gphoto2portConf.sh.in @@ -0,0 +1,7 @@ +# +# Configuration file for using the GPHOTO-PORT library +# +GPPORT_LIBDIR="@GPPORT_LIBDIR@" +GPPORT_LIBS="@GPPORT_LIBS@" +GPPORT_INCLUDEDIR="@GPPORT_INCLUDEDIR@" +MODULE_VERSION="gphoto2-port-@LIBGPPORT_VERSION@" diff --git a/libgphoto2_port/ieee1394/Makefile.am b/libgphoto2_port/ieee1394/Makefile.am new file mode 100644 index 000000000..a927483df --- /dev/null +++ b/libgphoto2_port/ieee1394/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gphoto2_port +iolib_LTLIBRARIES = libgphoto2_port_ieee1394.la +libgphoto2_port_ieee1394_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ -DHAVE_TERMIOS_H +libgphoto2_port_ieee1394_la_SOURCES = linux-raw.c gphoto2-port-ieee1394.h diff --git a/libgphoto2_port/ieee1394/linux-raw.c b/libgphoto2_port/ieee1394/linux-raw.c new file mode 100644 index 000000000..dc95d15d5 --- /dev/null +++ b/libgphoto2_port/ieee1394/linux-raw.c @@ -0,0 +1,119 @@ +/* -*- Mode: C { indent-tabs-mode: t { c-basic-offset: 8 { tab-width: 8 -*- */ +/* gphoto2-port-ieee1394.c - ieee1394 IO functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software { you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation { either version 2 of the + License, or (at your option) any later version. + + The GPIO Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library { see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include "gphoto2-port.h" + +/* IEEE1394 prototypes + ------------------------------------------------------------------ */ +int gp_port_ieee1394_list(gp_port_info *list, int *count); + +int gp_port_ieee1394_init(gp_port *dev); +int gp_port_ieee1394_exit(gp_port *dev); + +int gp_port_ieee1394_open(gp_port *dev); +int gp_port_ieee1394_close(gp_port *dev); + +int gp_port_ieee1394_read(gp_port *dev, char *bytes, int size); +int gp_port_ieee1394_write(gp_port *dev, char *bytes, int size); + +int gp_port_ieee1394_get_pin(gp_port *dev, int pin); +int gp_port_ieee1394_set_pin(gp_port *dev, int pin, int level); + +int gp_port_ieee1394_update (gp_port *dev); + +int gp_port_ieee1394_set_baudrate(gp_port *dev); + + +/* Dynamic library functions + ------------------------------------------------------------------ */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_IEEE1394); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_ieee1394_init; + ops->exit = gp_port_ieee1394_exit; + ops->open = gp_port_ieee1394_open; + ops->close = gp_port_ieee1394_close; + ops->read = gp_port_ieee1394_read; + ops->write = gp_port_ieee1394_write; + ops->update = gp_port_ieee1394_update; + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) { + + list[*count].type = GP_PORT_IEEE1394; + strcpy(list[*count].name, "IEEE1394 (Firewire(tm))"); + strcpy(list[*count].path, "ieee1394"); + list[*count].argument_needed = 0; + *count += 1; + + return (GP_OK); + +} + +/* IEEE1394 API functions + ------------------------------------------------------------------ */ + +int gp_port_ieee1394_init(gp_port *dev) { + +} + +int gp_port_ieee1394_exit(gp_port *dev) { + +} + +int gp_port_ieee1394_open(gp_port *dev) { + +} + +int gp_port_ieee1394_close(gp_port *dev) { + +} +int gp_port_ieee1394_read(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_ieee1394_write(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_ieee1394_get_pin(gp_port *dev, int pin) { + +} + +int gp_port_ieee1394_set_pin(gp_port *dev, int pin, int level) { + +} + +int gp_port_ieee1394_update (gp_port *dev) { + +} diff --git a/libgphoto2_port/include/Makefile.am b/libgphoto2_port/include/Makefile.am new file mode 100644 index 000000000..9cd7a83e2 --- /dev/null +++ b/libgphoto2_port/include/Makefile.am @@ -0,0 +1,8 @@ +gphoto2_port_incdir = $(includedir)/gphoto2-port +gphoto2_port_inc_HEADERS = gphoto2-port.h \ + gphoto2-portability.h \ + gphoto2-port-serial.h \ + gphoto2-port-parallel.h \ + gphoto2-port-usb.h \ + gphoto2-port-ieee1394.h \ + gphoto2-port-network.h diff --git a/libgphoto2_port/include/gphoto2-port-ieee1394.h b/libgphoto2_port/include/gphoto2-port-ieee1394.h new file mode 100644 index 000000000..35bd34fee --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-ieee1394.h @@ -0,0 +1,11 @@ +#ifndef _GP_PORT_IEEE1394_H_ +#define _GP_PORT_IEEE1394_H_ + +/* ieee1394 port specific settings */ +typedef struct { + int blah; +} gp_port_ieee1394_settings; + +extern struct gp_port_operations gp_port_ieee1394_operations; + +#endif /* _GP_PORT_IEEE1394_H_ */ diff --git a/libgphoto2_port/include/gphoto2-port-network.h b/libgphoto2_port/include/gphoto2-port-network.h new file mode 100644 index 000000000..026301ae0 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-network.h @@ -0,0 +1,15 @@ +#ifndef _GP_PORT_NETWORK_H_ +#define _GP_PORT_NETWORK_H_ + +/* socket specific settings */ +typedef struct { + char address[20]; +} gp_port_network_settings; + +extern struct gp_port_operations gp_port_network_operations; + +#endif /* _GP_PORT_NETWORK_H_ */ + + + + diff --git a/libgphoto2_port/include/gphoto2-port-parallel.h b/libgphoto2_port/include/gphoto2-port-parallel.h new file mode 100644 index 000000000..8136aacb2 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-parallel.h @@ -0,0 +1,75 @@ +#ifndef _GP_PORT_PARALLEL_H_ +#define _GP_PORT_PARALLEL_H_ + +/* PARALLEL port prefix for enumeration */ + +/* Linux */ +#ifdef __linux +#define GP_PORT_PARALLEL_PREFIX "/dev/lp%i" +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 16 +#endif + +/* BSD */ +#if defined(__FreeBSD__) || defined(__NetBSD__) +#define GP_PORT_PARALLEL_PREFIX NULL +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 0 +#endif + +/* Solaris */ +#ifdef sun +# ifdef i386 +# define GP_PORT_PARALLEL_PREFIX "/dev/lp%i" /* x86 parallel port prefix*/ +# define GP_PORT_PARALLEL_RANGE_LOW 1 +# define GP_PORT_PARALLEL_RANGE_HIGH 16 +# else +# define GP_PORT_PARALLEL_PREFIX "/dev/bpp%02i" /* Sparc parallel port prefix*/ +# define GP_PORT_PARALLEL_RANGE_LOW 0 +# define GP_PORT_PARALLEL_RANGE_HIGH 16 +# endif +#endif + + +/* BeOS */ +#ifdef beos +/* ????????????? */ +#define GP_PORT_PARALLEL_PREFIX NULL +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 0 +#endif + +/* Windows */ +#ifdef WIN +#define GP_PORT_PARALLEL_PREFIX "LPT%i:" +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 16 +#endif + +/* OS/2 */ +#ifdef OS2 +#define GP_PORT_PARALLEL_PREFIX "LPT%i" +#define GP_PORT_PARALLEL_RANGE_LOW 1 +#define GP_PORT_PARALLEL_RANGE_HIGH 4 +#endif + +/* Others? */ + +/* Default */ +#ifndef GP_PORT_PARALLEL_PREFIX +#warning GP_PORT_PARALLEL_PREFIX not defined. Enumeration will fail +#define GP_PORT_PARALLEL_PREFIX NULL +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 0 +#endif + +/* PARALLEL port specific settings */ +typedef struct { + char port[128]; +} gp_port_parallel_settings; + +extern struct gp_port_operations gp_port_parallel_operations; + +#endif /* _GP_PORT_PARALLEL_H_ */ + + diff --git a/libgphoto2_port/include/gphoto2-port-serial.h b/libgphoto2_port/include/gphoto2-port-serial.h new file mode 100644 index 000000000..e23b819d0 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-serial.h @@ -0,0 +1,79 @@ +#ifndef _GP_PORT_SERIAL_H_ +#define _GP_PORT_SERIAL_H_ + +/* Serial port prefix for enumeration */ +/* %i for numbers, %c for letters */ +/* also define the low and high values of the range to check for devices */ + + +/* Linux */ +#ifdef __linux +/* devfs is accounted for in the implementation */ +#define GP_PORT_SERIAL_PREFIX "/dev/ttyS%i" +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 32 +#endif + +/* BSD */ +#if defined(__FreeBSD__) || defined(__NetBSD__) +#define GP_PORT_SERIAL_PREFIX "/dev/tty0%i" +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 32 +#endif + +/* Solaris */ +#ifdef sun +#define GP_PORT_SERIAL_PREFIX "/dev/tty%c" +#define GP_PORT_SERIAL_RANGE_LOW 'a' +#define GP_PORT_SERIAL_RANGE_HIGH 'z' +#endif + +/* BeOS */ +#ifdef beos +/* ????????????? */ +#define GP_PORT_SERIAL_PREFIX NULL +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 0 +#endif + +/* Windows */ +#ifdef WIN32 +#define GP_PORT_SERIAL_PREFIX "COM%i:" +#define GP_PORT_SERIAL_RANGE_LOW 1 +#define GP_PORT_SERIAL_RANGE_HIGH 4 +#endif + +#ifdef OS2 +#define GP_PORT_SERIAL_PREFIX "COM%i" +#define GP_PORT_SERIAL_RANGE_LOW 1 +#define GP_PORT_SERIAL_RANGE_HIGH 4 +#endif + +/* Others? */ + +/* Default */ +#ifndef GP_PORT_SERIAL_PREFIX +#define GP_PORT_SERIAL_PREFIX "/dev/cua%i" +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 0 +#endif + +/* Serial port specific settings */ +typedef struct { + char port[128]; + int speed; + int bits; + int parity; + int stopbits; +} gp_port_serial_settings; + +extern struct gp_port_operations gp_port_serial_operations; + +#define PIN_RTS 0 +#define PIN_DTR 1 +#define PIN_CTS 2 +#define PIN_DSR 3 +#define PIN_CD 4 +#define PIN_RING 5 + +#endif /* _GP_PORT_SERIAL_H_ */ diff --git a/libgphoto2_port/include/gphoto2-port-usb.h b/libgphoto2_port/include/gphoto2-port-usb.h new file mode 100644 index 000000000..08912bf53 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-usb.h @@ -0,0 +1,15 @@ +#ifndef _GP_PORT_USB_H_ +#define _GP_PORT_USB_H_ + +/* USB port specific settings */ +typedef struct { + int inep; + int outep; + int config; + int interface; + int altsetting; +} gp_port_usb_settings; + +extern struct gp_port_operations gp_port_usb_operations; + +#endif /* _GP_PORT_USB_H_ */ diff --git a/libgphoto2_port/include/gphoto2-port.h b/libgphoto2_port/include/gphoto2-port.h new file mode 100644 index 000000000..b0101e7ee --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port.h @@ -0,0 +1,294 @@ +#ifndef _GP_PORT_H_ +#define _GP_PORT_H_ + +#ifdef OS2 +#include <gphoto2-portability-os2.h> +#include <os2.h> +#endif + +/* Include the portability layer */ +#include "gphoto2-portability.h" + +/* Include the various headers for other devices */ +#include "gphoto2-port-serial.h" +#include "gphoto2-port-parallel.h" +#include "gphoto2-port-network.h" +#include "gphoto2-port-usb.h" +#include "gphoto2-port-ieee1394.h" + +#ifndef TRUE +#define TRUE (0==0) +#endif + +#ifndef FALSE +#define FALSE (1==0) +#endif + +/* Defines and enums + -------------------------------------------------------------- + Note: this is a base set of return values. */ + +/* Return values */ +/* Note: This lib should be allocated return values of 0 to -99 */ + +#define GP_OK 0 + +#define GP_ERROR -1 +#define GP_ERROR_TIMEOUT -2 + + +/* Debugging definitions for init */ +#define GP_DEBUG_NONE 0 +#define GP_DEBUG_LOW 1 +#define GP_DEBUG_MEDIUM 2 +#define GP_DEBUG_HIGH 3 + +#define GP_PORT_MAX_BUF_LEN 4096 /* max length of receive buffer */ + +/* Specify the types of devices */ +typedef enum { + GP_PORT_NONE = 0, + GP_PORT_SERIAL = 1 << 0, + GP_PORT_PARALLEL = 1 << 1, /* <- Not supported yet */ + GP_PORT_USB = 1 << 2, + GP_PORT_IEEE1394 = 1 << 3, /* <- Not supported yet */ + GP_PORT_NETWORK = 1 << 4, /* <- Not supported yet */ +} gp_port_type; + + +/* Device struct + -------------------------------------------------------------- */ + +typedef struct { + gp_port_type type; + char name[64]; + char path[64]; + + /* not used yet */ + int argument_needed; + char argument_description[128]; + char argument[128]; + + /* don't touch */ + char library_filename[1024]; +} gp_port_info; + + +/* Put the settings together in a union */ +typedef union { + gp_port_serial_settings serial; + gp_port_parallel_settings parallel; + gp_port_network_settings network; + gp_port_usb_settings usb; + gp_port_ieee1394_settings ieee1394; +} gp_port_settings; + +enum { + GP_PORT_USB_IN_ENDPOINT, + GP_PORT_USB_OUT_ENDPOINT +}; + +struct gp_port; +typedef struct gp_port gp_port; +struct gp_port_operations { + int (*init) (gp_port *); + int (*exit) (gp_port *); + int (*open) (gp_port *); + int (*close) (gp_port *); + int (*read) (gp_port *, char *, int); + int (*write) (gp_port *, char *, int); + int (*update) (gp_port *); + + /* Pointers to devices. Please note these are stubbed so there is + no need to #ifdef GP_PORT_* anymore. */ + + /* for serial and parallel devices */ + int (*get_pin) (gp_port *, int); + int (*set_pin) (gp_port *, int, int); + int (*send_break)(gp_port *, int); + + /* for USB devices */ + int (*find_device)(gp_port * dev, int idvendor, int idproduct); + int (*clear_halt) (gp_port * dev, int ep); + int (*msg_write) (gp_port * dev, int value, char *bytes, int size); + int (*msg_read) (gp_port * dev, int value, char *bytes, int size); + +}; + +typedef struct gp_port_operations gp_port_operations; + +/* Function pointers for the dynamic libraries */ +typedef int (*gp_port_ptr_type) (); +typedef int (*gp_port_ptr_list) (gp_port_info*, int *); +typedef gp_port_operations* (*gp_port_ptr_operations) (); + +/* Specify the device information */ +struct gp_port { + /* This struct is available via wrappers. don't modify + directly. */ + gp_port_type type; + + gp_port_operations *ops; + + gp_port_settings settings; + gp_port_settings settings_pending; + + gp_port_settings settings_saved; + + int device_fd; +#ifdef WIN32 + HANDLE device_handle; +#else + void *device_handle; +#endif + int timeout; /* in milli seconds */ + + void *library_handle; + + int debug_level; +}; + +/* Core functions + -------------------------------------------------------------- */ + + void gp_port_debug_printf (int target_debug_level, int debug_level, char *format, ...); + /* issues debugging messages */ + + int gp_port_init (int debug_level); + /* Initializes the library. + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_get_count (); + /* Get a count of available devices + return values: + successful: valid gp_port_list struct + unsuccessful: GP_ERROR + */ + + int gp_port_get_info (int device_number, gp_port_info *info); + /* Get information about a device + return values: + successful: valid gp_port_list struct + unsuccessful: GP_ERROR + */ + +gp_port *gp_port_new (gp_port_type type); + /* Create a new device of type "type" + return values: + successful: valid gp_port struct + unsuccessful: GP_ERROR + */ + + int gp_port_free (gp_port *dev); + /* Frees an IO device from memory + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_set_debug (gp_port *dev, int debug_level); + /* + Set the debugging level specific to a device + */ + + int gp_port_open (gp_port *dev); + /* Open the device for reading and writing + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_close (gp_port *dev); + /* Close the device to prevent reading and writing + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_set_timeout (gp_port *dev, int millisec_timeout); + /* Sets the read/write timeout + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_get_timeout (gp_port *dev, int *millisec_timeout); + /* Sets the read/write timeout + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_set_settings (gp_port *dev, + gp_port_settings settings); + /* Sets the settings + successful: GP_OK + unsuccessful: GP_ERROR + */ + + + int gp_port_get_settings (gp_port *dev, + gp_port_settings *settings); + /* Returns settings in "settings" + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_write (gp_port *dev, char *bytes, int size); + /* Writes "bytes" of size "size" to the device + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_read (gp_port *dev, char *bytes, int size); + /* Reads "size" bytes in to "bytes" from the device + return values: + successful: number of bytes read + unsuccessful: GP_ERROR + */ + + +/* Serial and Parallel specific functions + -------------------------------------------------------------- */ + + int gp_port_get_pin (gp_port *dev, int pin); + /* Give the status of pin from dev + pin values: + see PIN_ constants in the various .h files + return values: + successful: status + unsuccessful: GP_ERROR + */ + + int gp_port_set_pin (gp_port *dev, int pin, int level); + /* set the status of pin from dev to level + pin values: + see PIN_ constants in the various .h files + level values: + 0 for off + 1 for on + return values: + successful: status + unsuccessful: GP_ERROR + */ + + int gp_port_send_break (gp_port *dev, int duration); + /* send a break (duration is in seconds) */ + +/* USB specific functions + -------------------------------------------------------------- */ + + /* must port libusb to other platforms for this to drop-in */ + int gp_port_usb_find_device (gp_port * dev, int idvendor, int idproduct); + int gp_port_usb_clear_halt (gp_port * dev, int ep); + int gp_port_usb_msg_write (gp_port * dev, int value, char *bytes, int size); + int gp_port_usb_msg_read (gp_port * dev, int value, char *bytes, int size); + + + + +#endif /* _GP_PORT_H_ */ + + diff --git a/libgphoto2_port/include/gphoto2-portability-os2.h b/libgphoto2_port/include/gphoto2-portability-os2.h new file mode 100644 index 000000000..0c2b7863a --- /dev/null +++ b/libgphoto2_port/include/gphoto2-portability-os2.h @@ -0,0 +1,77 @@ +#ifndef GPIO_OS2_INCLUDED +#define GPIO_OS2_INCLUDED +#define IOLIBS getenv("IOLIBS") +#define RTLD_LAZY 0x001 +#ifndef HAVE_TERMIOS_H +/* c_cflag bit meaning */ +#define CBAUD 0x0000100f +#define B0 0x00000000 /* hang up */ +#define B50 0x00000001 +#define B75 0x00000002 +#define B110 0x00000003 +#define B134 0x00000004 +#define B150 0x00000005 +#define B200 0x00000006 +#define B300 0x00000007 +#define B600 0x00000008 +#define B1200 0x00000009 +#define B1800 0x0000000a +#define B2400 0x0000000b +#define B4800 0x0000000c +#define B9600 0x0000000d +#define B19200 0x0000000e +#define B38400 0x0000000f +#define EXTA B19200 +#define EXTB B38400 +#define CSIZE 0x00000030 +#define CS5 0x00000000 +#define CS6 0x00000010 +#define CS7 0x00000020 +#define CS8 0x00000030 +#define CSTOPB 0x00000040 +#define CREAD 0x00000080 +#define PARENB 0x00000100 +#define PARODD 0x00000200 +#define HUPCL 0x00000400 +#define CLOCAL 0x00000800 +#define CBAUDEX 0x00001000 +#define B57600 0x00001001 +#define B115200 0x00001002 +#define B230400 0x00001003 +#define B460800 0x00001004 +#define B76800 0x00001005 +#define B153600 0x00001006 +#define B307200 0x00001007 +#define B614400 0x00001008 +#define B921600 0x00001009 +#define B500000 0x0000100a +#define B576000 0x0000100b +#define B1000000 0x0000100c +#define B1152000 0x0000100d +#define B1500000 0x0000100e +#define B2000000 0x0000100f + +#endif + +#define CIBAUD 0x100f0000 /* input baud rate (not used) */ +#define CMSPAR 0x40000000 /* mark or space (stick) parity */ +//#define CRTSCTS 0x80000000 /* flow control */ + +/* modem lines */ +#define TIOCM_LE 0x001 +#define TIOCM_DTR 0x002 +#define TIOCM_RTS 0x004 +#define TIOCM_ST 0x008 +#define TIOCM_SR 0x010 +#define TIOCM_CTS 0x020 +#define TIOCM_CAR 0x040 +#define TIOCM_RNG 0x080 +#define TIOCM_DSR 0x100 +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RI TIOCM_RNG + +#define TIOCMBIC 0x06C +#define TIOCMBIS 0x06B +#define TIOCMGET 0x06E + +#endif diff --git a/libgphoto2_port/include/gphoto2-portability.h b/libgphoto2_port/include/gphoto2-portability.h new file mode 100644 index 000000000..c52504c19 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-portability.h @@ -0,0 +1,84 @@ + +/* Windows Portability + ------------------------------------------------------------------ */ + +#ifdef WIN32 + +#include <windows.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdio.h> +#include <direct.h> + +#define IOLIBS "." +#define strcasecmp _stricmp +#define snprintf _snprintf + +/* Work-around for readdir() */ +typedef struct { + HANDLE handle; + int got_first; + WIN32_FIND_DATA search; + char dir[1024]; + char drive[32][2]; + int drive_count; + int drive_index; +} GPPORTWINDIR; + +/* Sleep functionality */ +#define GP_SYSTEM_SLEEP(_ms) Sleep(_ms) + +/* Dynamic library functions */ +#define GP_SYSTEM_DLOPEN(_filename) LoadLibrary(_filename) +#define GP_SYSTEM_DLSYM(_handle, _funcname) GetProcAddress(_handle, _funcname) +#define GP_SYSTEM_DLCLOSE(_handle) FreeLibrary(_handle) +#define GP_SYSTEM_DLERROR() "Windows Error" + +/* Directory-oriented functions */ +#define GP_SYSTEM_DIR GPPORTWINDIR * +#define GP_SYSTEM_DIRENT WIN32_FIND_DATA * +#define GP_SYSTEM_DIR_DELIM '\\' + + +#else + +/* POSIX Portability + ------------------------------------------------------------------ */ + +/* yummy. :) */ + +#include <dirent.h> +#include <dlfcn.h> +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +/* Sleep functionality */ +#define GP_SYSTEM_SLEEP(_ms) usleep(_ms*1000) + +/* Dynamic library functions */ +#define GP_SYSTEM_DLOPEN(_filename) dlopen(_filename, RTLD_LAZY) +#define GP_SYSTEM_DLSYM(_handle, _funcname) dlsym(_handle, _funcname) +#define GP_SYSTEM_DLCLOSE(_handle) dlclose(_handle) +#define GP_SYSTEM_DLERROR() dlerror() + +/* Directory-oriented functions */ +#define GP_SYSTEM_DIR DIR * +#define GP_SYSTEM_DIRENT struct dirent * +#ifdef OS2 +#define GP_SYSTEM_DIR_DELIM '\\' +#else +#define GP_SYSTEM_DIR_DELIM '/' +#endif /* OS2 */ + +#endif /* else */ + +int GP_SYSTEM_MKDIR (char *dirname); +GP_SYSTEM_DIR GP_SYSTEM_OPENDIR (char *dirname); +GP_SYSTEM_DIRENT GP_SYSTEM_READDIR (GP_SYSTEM_DIR d); +char* GP_SYSTEM_FILENAME (GP_SYSTEM_DIRENT de); +int GP_SYSTEM_CLOSEDIR (GP_SYSTEM_DIR dir); +int GP_SYSTEM_IS_FILE (char *filename); +int GP_SYSTEM_IS_DIR (char *dirname); diff --git a/libgphoto2_port/libgphoto2_port.spec.in b/libgphoto2_port/libgphoto2_port.spec.in new file mode 100644 index 000000000..c93287036 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port.spec.in @@ -0,0 +1,66 @@ +%define ver @VERSION@ +%define rel 1 +%define prefix /usr + +Summary: Portable I/O library +Name: libgphoto2-port +Version: %ver +Release: %rel +Copyright: LGPL +Group: System Environment/Libraries +Source: http://www.gphoto.net/dist/libgphoto2-port-%{ver}.tar.gz +BuildRoot: /var/tmp/libgphoto2-port-%{PACKAGE_VERSION}-root +URL: http://www.gphoto.net/ +Docdir: %{prefix}/doc +Requires: libusb + +%description +The benefit to using this library would be that all communications can be +done quickly and without worry for device specific functions; all devices +are abstracted to a point, allowing you to read/write to a device using +the same interface. For example, you can set all the options on the serial +port easily, and then read/write to that device. Additionally, you could +easily switch over to a USB device, and read/write without having to learn +the USB internals. + +%package devel +Summary: Libraries, includes, etc to develop applications using libgpio +Group: System Environment/Libraries +Requires: libgphoto2-port + +%description devel +Libraries, include files, etc you need to develop applications with libgphoto2-port + +%prep +%setup + +%build +CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%prefix +make + +%install +rm -rf $RPM_BUILD_ROOT + +make prefix=$RPM_BUILD_ROOT%{prefix} install + +%clean +rm -rf $RPM_BUILD_ROOT + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%defattr(-, root, root) + +%doc AUTHORS ChangeLog NEWS README COPYING COPYING.LIB TODO +%{prefix}/lib/lib*.so.* +%{prefix}/bin/gpio-config + +%files devel +%defattr(-, root, root) + +%{prefix}/lib/lib*.so +%{prefix}/lib/*a +%{prefix}/lib/*.sh +%{prefix}/include/* diff --git a/libgphoto2_port/libgphoto2_port/Makefile.am b/libgphoto2_port/libgphoto2_port/Makefile.am new file mode 100644 index 000000000..cbca96023 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/Makefile.am @@ -0,0 +1,15 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ \ + -DIOLIBS=\"$(prefix)/lib/gphoto2_port\" \ + -g +LDFLAGS = @LDFLAGS@ -g -ldl + +## Compile the IO library into a shared library +lib_LTLIBRARIES = libgphoto2_port.la +libgphoto2_port_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ +libgphoto2_port_la_SOURCES = \ + gp_port.c \ + library.c library.h \ + portability.c diff --git a/libgphoto2_port/libgphoto2_port/gp_port.c b/libgphoto2_port/libgphoto2_port/gp_port.c new file mode 100644 index 000000000..41f97d6f5 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/gp_port.c @@ -0,0 +1,432 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* gpio.c - Core IO library functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GPIO Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "../include/gphoto2-port.h" +#include "library.h" + +gp_port_info device_list[256]; +int device_count; + +/* Toggle to turn on/off debugging */ +int glob_debug_level=0; + +void gp_port_debug_printf (int target_debug_level, int debug_level, char *format, ...) +{ + va_list arg; + + if ((debug_level > 0)&&(debug_level >= target_debug_level)) { + fprintf(stderr, "gpio: "); + va_start(arg, format); + vfprintf(stderr, format, arg); + va_end(arg); + fprintf(stderr, "\n"); + } +} + +/* + Required library functions + ---------------------------------------------------------------- + */ + +int gp_port_init(int debug) +{ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Initializing..."); + /* Enumerate all the available devices */ + device_count = 0; + glob_debug_level = debug; + return (gp_port_library_list(device_list, &device_count)); +} + +int gp_port_get_count(void) +{ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Device count: %i", device_count); + return device_count; +} + +int gp_port_get_info(int device_number, gp_port_info *info) +{ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Getting device info..."); + + memcpy(info, &device_list[device_number], sizeof(device_list[device_number])); + + return GP_OK; +} + +gp_port *gp_port_new(gp_port_type type) + /* Create a new IO device */ +{ + gp_port *dev; + gp_port_settings settings; + char buf[1024]; + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Creating new device... "); + + dev = (gp_port *) malloc(sizeof(gp_port)); + if (!dev) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Can not allocate device!"); + return NULL; + } + memset(dev, 0, sizeof(gp_port)); + + if (gp_port_library_load(dev, type)) { + /* whoops! that type of device isn't supported */ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Device type not supported! (%i)", type); + free(dev); + return NULL; + } + + dev->debug_level = glob_debug_level; + + dev->type = type; + dev->device_fd = 0; + dev->ops->init(dev); + + switch (dev->type) { + case GP_PORT_SERIAL: + sprintf(buf, GP_PORT_SERIAL_PREFIX, GP_PORT_SERIAL_RANGE_LOW); + strcpy(settings.serial.port, buf); + /* set some defaults */ + settings.serial.speed = 9600; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + gp_port_set_settings(dev, settings); + gp_port_set_timeout(dev, 500); + break; + case GP_PORT_PARALLEL: +#ifdef GP_PORT_PARALLEL + sprintf(buf, GP_PORT_SERIAL_PREFIX, GP_PORT_SERIAL_RANGE_LOW); + strcpy(settings.parallel.port, buf); +#endif + break; + case GP_PORT_NETWORK: +#ifdef GP_PORT_NETWORK + gp_port_set_timeout(dev, 50000); +#endif + break; + case GP_PORT_USB: +#ifdef GP_PORT_USB + gp_port_set_timeout(dev, 5000); +#endif + break; + case GP_PORT_IEEE1394: +#ifdef GP_PORT_IEEE1394 + /* blah ? */ +#endif + break; + default: + /* ERROR! */ + break; + } + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Created device successfully..."); + + return (dev); +} + +int gp_port_set_debug (gp_port *dev, int debug_level) +{ + dev->debug_level = debug_level; + + return (GP_OK); +} + +int gp_port_open(gp_port *dev) + /* Open a device for reading/writing */ +{ + int retval = 0; + + /* Try to open device */ + retval = dev->ops->open(dev); + if (retval == GP_OK) { + /* Now update the settings */ + retval = dev->ops->update(dev); + if (retval != GP_OK) { + dev->device_fd = 0; + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_open: update error"); + return GP_ERROR; + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_open: OK"); + return GP_OK; + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_open: open error"); + return GP_ERROR; +} + +int gp_port_close(gp_port *dev) + /* Close the device to prevent reading/writing */ +{ + int retval = 0; + + if (!dev) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_close: bad device"); + return GP_ERROR; + } + if (dev->type == GP_PORT_SERIAL && dev->device_fd == 0) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_close: OK"); + return GP_OK; + } + + retval = dev->ops->close(dev); + dev->device_fd = 0; + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_close: close %s", retval == GP_OK? "ok":"error"); + return retval; +} + +int gp_port_free(gp_port *dev) + /* Frees a device struct */ +{ + int retval = dev->ops->exit(dev); + + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_free: exit %s", retval < 0? "error":"ok"); + + gp_port_library_close(dev); + free(dev); + + return GP_OK; +} + +int gp_port_write(gp_port *dev, char *bytes, int size) + /* Called to write "bytes" to the IO device */ +{ + int x, retval; + char t[8]; + char *buf; + + if (glob_debug_level == GP_DEBUG_HIGH) { + buf = (char *)malloc(sizeof(char)*(4*size+64)); + buf[0] = 0; + for (x=0; x<size; x++) { + sprintf(t, "%02x ", (unsigned char)bytes[x]); + strcat(buf, t); + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_write: (size=%05i) DATA: %s", size, buf); + free(buf); + } + retval = dev->ops->write(dev, bytes, size); + + if (retval == GP_ERROR_TIMEOUT) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_write: write timeout"); + if (retval == GP_ERROR) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_write: write error"); + + return (retval); +} + +int gp_port_read(gp_port *dev, char *bytes, int size) + /* Reads data from the device into the "bytes" buffer. + "bytes" should be large enough to hold all the data. + */ +{ + int x, retval; + char t[8]; + char *buf; + + retval = dev->ops->read(dev, bytes, size); + + if ((retval > 0)&&(glob_debug_level == GP_DEBUG_HIGH)) { + buf = (char *)malloc(sizeof(char)*(4*retval+64)); + buf[0] = 0; + for (x=0; x<retval; x++) { + sprintf(t, "%02x ", (unsigned char)bytes[x]); + strcat(buf, t); + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_read: (size=%05i) DATA: %s", retval, buf); + free(buf); + } + + if (retval == GP_ERROR_TIMEOUT) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_read: read timeout"); + if (retval == GP_ERROR) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_read: read error"); + + return (retval); +} + +int gp_port_set_timeout(gp_port *dev, int millisec_timeout) +{ + dev->timeout = millisec_timeout; + + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_set_timeout: value=%ims", millisec_timeout); + + return GP_OK; +} + +int gp_port_get_timeout(gp_port *dev, int *millisec_timeout) +{ + *millisec_timeout = dev->timeout; + + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_get_timeout: value=%ims", *millisec_timeout); + + return GP_OK; +} + +int gp_port_set_settings(gp_port *dev, gp_port_settings settings) +{ + int retval; + + /* need to memcpy() settings to dev->settings */ + memcpy(&dev->settings_pending, &settings, sizeof(dev->settings_pending)); + + retval = dev->ops->update(dev); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_set_settings: update %s", retval < 0? "error":"ok"); + return (retval); +} + + +int gp_port_get_settings(gp_port *dev, gp_port_settings * settings) +{ + memcpy(settings, &dev->settings, sizeof(gp_port_settings)); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_get_settings: ok"); + + return GP_OK; +} + +/* Serial and Parallel-specific functions */ +/* ------------------------------------------------------------------ */ + +int gp_port_get_pin(gp_port *dev, int pin) +{ + int retval; + + if (!dev->ops->get_pin) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_get_pin: get_pin NULL"); + return (GP_ERROR); + } + + retval = dev->ops->get_pin(dev, pin); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_get_pin: get_pin %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_set_pin(gp_port *dev, int pin, int level) +{ + int retval; + + if (!dev->ops->get_pin) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_set_pin: set_pin NULL"); + return (GP_ERROR); + } + + retval = dev->ops->set_pin(dev, pin, level); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_set_pin: set_pin %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_send_break (gp_port *dev, int duration) +{ + int retval; + + if (!dev->ops->send_break) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_break: gp_port_break NULL"); + return (GP_ERROR); + } + + retval = dev->ops->send_break(dev, duration); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_send_break: send_break %s", retval < 0? "error":"ok"); + return (retval); +} + +/* USB-specific functions */ +/* ------------------------------------------------------------------ */ + +#ifdef GP_PORT_USB + +int gp_port_usb_find_device (gp_port * dev, int idvendor, int idproduct) +{ + int retval; + + if (!dev->ops->find_device) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_find_device: find_device NULL"); + return (GP_ERROR); + } + + retval = dev->ops->find_device(dev, idvendor, idproduct); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_find_device: find_device (0x%04x 0x%04x) %s", + idvendor, idproduct, retval < 0? "error":"ok"); + return (retval); +} +int gp_port_usb_clear_halt (gp_port * dev, int ep) +{ + int retval; + + if (!dev->ops->clear_halt) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_clear_halt: clear_halt NULL"); + return (GP_ERROR); + } + + retval = dev->ops->clear_halt(dev, ep); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_clear_halt: clear_halt %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_usb_msg_write (gp_port * dev, int value, char *bytes, int size) +{ + int retval; + + if (!dev->ops->msg_write) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_write: msg_write NULL"); + return (GP_ERROR); + } + + retval = dev->ops->msg_write(dev, value, bytes, size); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_write: msg_write %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_usb_msg_read (gp_port * dev, int value, char *bytes, int size) +{ + int retval; + + if (!dev->ops->msg_read) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_read: msg_read NULL"); + return (GP_ERROR); + } + + retval = dev->ops->msg_read(dev, value, bytes, size); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_read: msg_read %s", retval < 0? "error":"ok"); + return (retval); +} +#endif diff --git a/libgphoto2_port/libgphoto2_port/library.c b/libgphoto2_port/libgphoto2_port/library.c new file mode 100644 index 000000000..1fed9d826 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/library.c @@ -0,0 +1,154 @@ +#include <sys/types.h> +#include <stdio.h> + +#include "gphoto2-port.h" +#include "library.h" + +extern int device_count; +extern int glob_debug_level; +extern gp_port_info device_list[]; +void *device_lh; + +int gp_port_library_is_valid (char *filename) { + + void *lh; + + if ((lh = GP_SYSTEM_DLOPEN(filename))==NULL) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "%s is not a library (%s) ", filename, GP_SYSTEM_DLERROR()); + return (GP_ERROR); + } + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "%s is a library ", filename); + GP_SYSTEM_DLCLOSE(lh); + + return (GP_OK); +} + +int gp_port_library_list_load(char *filename, int loaded[], gp_port_info *list, int *count) { + + void *lh; + int type, x; + gp_port_ptr_type lib_type; + gp_port_ptr_list lib_list; + int old_count = *count; + + if ((lh = GP_SYSTEM_DLOPEN(filename))==NULL) + return (GP_ERROR); + + lib_type = (gp_port_ptr_type)GP_SYSTEM_DLSYM(lh, "gp_port_library_type"); + lib_list = (gp_port_ptr_list)GP_SYSTEM_DLSYM(lh, "gp_port_library_list"); + + if ((!list) || (!lib_type)) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "could not find type/list symbols: %s ", GP_SYSTEM_DLERROR()); + GP_SYSTEM_DLCLOSE(lh); + return (GP_ERROR); + } + + type = lib_type(); + + if (loaded[type] == 1) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "%s (%i) already loaded ", filename, type); + GP_SYSTEM_DLCLOSE(lh); + return (GP_ERROR); + } else { + loaded[type] = 1; + } + + if (lib_list(list, count)==GP_ERROR) + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "%s could not list devices ", filename); + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "Loaded these devices from %s:", filename); + /* copy in the library path */ + for (x=old_count; x<(*count); x++) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "\t%s path=\"%s\"", list[x].name, list[x].path); + strcpy(list[x].library_filename, filename); + } + + GP_SYSTEM_DLCLOSE(lh); + return (GP_OK); +} + +int gp_port_library_list (gp_port_info *list, int *count) { + + GP_SYSTEM_DIR d; + GP_SYSTEM_DIRENT de; + int loaded[256]; + int x; + char buf[1024]; + + *count = 0; + + for (x=0;x<256; x++) + loaded[x]=0; + + /* Look for available camera libraries */ + d = GP_SYSTEM_OPENDIR(IOLIBS); + if (!d) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "couldn't open %s ", IOLIBS); + return GP_ERROR; + } + + do { + /* Read each entry */ + de = GP_SYSTEM_READDIR(d); + if (de) { +#if defined(OS2) || defined(WIN32) + sprintf(buf, "%s\\%s", IOLIBS, GP_SYSTEM_FILENAME(de)); +#else + sprintf(buf, "%s/%s", IOLIBS, GP_SYSTEM_FILENAME(de)); +#endif + if (gp_port_library_is_valid(buf) == GP_OK) + gp_port_library_list_load(buf, loaded, list, count); + } + } while (de); + + GP_SYSTEM_CLOSEDIR(d); + + return (GP_OK); +} + +int gp_port_library_load (gp_port *device, gp_port_type type) { + + int x=0; + gp_port_ptr_operations ops_func; + + for (x=0; x<device_count; x++) { + if (device_list[x].type == type) { + /* Open the correct library */ + device->library_handle = GP_SYSTEM_DLOPEN(device_list[x].library_filename); + if (!device->library_handle) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "bad handle: %s %s ", + device_list[x].library_filename, GP_SYSTEM_DLERROR()); + return (GP_ERROR); + } + + /* Load the operations */ + ops_func = (gp_port_ptr_operations)GP_SYSTEM_DLSYM(device->library_handle, "gp_port_library_operations"); + if (!ops_func) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "can't load ops: %s %s ", + device_list[x].library_filename, GP_SYSTEM_DLERROR()); + GP_SYSTEM_DLCLOSE(device->library_handle); + return (GP_ERROR); + } + device->ops = ops_func(); + return (GP_OK); + } + } + return (GP_ERROR); +} + +int gp_port_library_close (gp_port *device) { + + GP_SYSTEM_DLCLOSE(device->library_handle); + + return (GP_OK); +} diff --git a/libgphoto2_port/libgphoto2_port/library.h b/libgphoto2_port/libgphoto2_port/library.h new file mode 100644 index 000000000..c14e773a2 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/library.h @@ -0,0 +1,3 @@ +int gp_port_library_list(gp_port_info *list, int *count); +int gp_port_library_load(gp_port *device, gp_port_type type); +int gp_port_library_close(gp_port *device); diff --git a/libgphoto2_port/libgphoto2_port/portability.c b/libgphoto2_port/libgphoto2_port/portability.c new file mode 100644 index 000000000..a862fd4c5 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/portability.c @@ -0,0 +1,172 @@ +#include <stdio.h> +#include <gphoto2-port.h> + +/* Windows Portability + ------------------------------------------------------------------ */ +#ifdef WIN32 + +void gp_port_win_convert_path (char *path) { + + int x; + + if (strchr(path, '\\')) + /* already converted */ + return; + + if (path[0] != '.') { + path[0] = path[1]; + path[1] = ':'; + path[2] = '\\'; + } + + for (x=0; x<strlen(path); x++) + if (path[x] == '/') + path[x] = '\\'; +} + +int GP_SYSTEM_MKDIR (char *dirname) { + + if (_mkdir(dirname) < 0) + return (GP_ERROR); + return (GP_OK); +} + +GP_SYSTEM_DIR GP_SYSTEM_OPENDIR (char *dirname) { + + GPIOWINDIR *d; + DWORD dr; + int x; + + d = (GPIOWINDIR*)malloc(sizeof(GPIOWINDIR)); + d->handle = INVALID_HANDLE_VALUE; + d->got_first = 0; + strcpy(d->dir, dirname); + d->drive_count = 0; + d->drive_index = 0; + + dr = GetLogicalDrives(); + + for (x=0; x<32; x++) { + if ((dr >> x) & 0x0001) { + sprintf(d->drive[d->drive_count], "%c", 'A' + x); + d->drive_count += 1; + } + } + + return (d); +} + +GP_SYSTEM_DIRENT GP_SYSTEM_READDIR (GP_SYSTEM_DIR d) { + + char dirn[1024]; + + if (strcmp(d->dir, "/")==0) { + if (d->drive_index == d->drive_count) + return (NULL); + strcpy(d->search.cFileName, d->drive[d->drive_index]); + d->drive_index += 1; + return (&(d->search)); + } + + + /* Append the wildcard */ + + strcpy(dirn, d->dir); + gp_port_win_convert_path(dirn); + + if (dirn[strlen(dirn)-1] != '\\') + strcat(dirn, "\\"); + strcat(dirn, "*"); + + + if (d->handle == INVALID_HANDLE_VALUE) { + d->handle = FindFirstFile(dirn, &(d->search)); + if (d->handle == INVALID_HANDLE_VALUE) + return NULL; + } else { + if (!FindNextFile(d->handle, &(d->search))) + return NULL; + } + + return (&(d->search)); +} + +char *GP_SYSTEM_FILENAME (GP_SYSTEM_DIRENT de) { + + return (de->cFileName); +} + +int GP_SYSTEM_CLOSEDIR (GP_SYSTEM_DIR d) { + FindClose(d->handle); + free(d); + return (1); +} + +int GP_SYSTEM_IS_FILE (char *filename) { + + struct stat st; + + gp_port_win_convert_path(filename); + + if (stat(filename, &st)!=0) + return 0; + return (st.st_mode & _S_IFREG); +} + +int GP_SYSTEM_IS_DIR (char *dirname) { + + struct stat st; + + if (strlen(dirname) <= 3) + return 1; + + gp_port_win_convert_path(dirname); + + if (stat(dirname, &st)!=0) + return 0; + return (st.st_mode & _S_IFDIR); +} + + +#else + +int GP_SYSTEM_MKDIR (char *dirname) { + + if (mkdir(dirname, 0700)<0) + return (GP_ERROR); + return (GP_OK); +} + +GP_SYSTEM_DIR GP_SYSTEM_OPENDIR (char *dirname) { + return (opendir(dirname)); +} + +GP_SYSTEM_DIRENT GP_SYSTEM_READDIR (GP_SYSTEM_DIR d) { + return (readdir(d)); +} + +char *GP_SYSTEM_FILENAME (GP_SYSTEM_DIRENT de) { + return (de->d_name); +} + +int GP_SYSTEM_CLOSEDIR (GP_SYSTEM_DIR dir) { + closedir(dir); + return (GP_OK); +} + +int GP_SYSTEM_IS_FILE (char *filename) { + struct stat st; + + if (stat(filename, &st)!=0) + return 0; + return (!S_ISDIR(st.st_mode)); +} + +int GP_SYSTEM_IS_DIR (char *dirname) { + struct stat st; + + if (stat(dirname, &st)!=0) + return 0; + return (S_ISDIR(st.st_mode)); +} +#endif diff --git a/libgphoto2_port/makefile.os2 b/libgphoto2_port/makefile.os2 new file mode 100644 index 000000000..6873b97fa --- /dev/null +++ b/libgphoto2_port/makefile.os2 @@ -0,0 +1,52 @@ +CCFLAGS=-O2 -c -I.. -I..\include -Zmtd -Zcrtdll -Zbin-files -D__ST_MT_ERRNO_ -I. -DOS2 -DHAVE_TERMIOS_H -Iinclude +CC=gcc +MKLIB=ar r + + +all: start \ + lib \ + serial\ + parallel\ + end + +start: + @echo **** + @echo Entering: $(MAKEDIR) + @echo using CCFLAGS: $(CCFLAGS) + @echo **** + @if not exist obj md obj + +end: + @echo **** + @echo Done: $(MAKEDIR) + @echo **** + + +serial: + @cd serial + @nmake /nologo -f makefile.os2 + @cd.. + +parallel: + @cd parallel + @nmake /nologo -f makefile.os2 + @cd.. + +#network: +# @cd network +# @nmake /nologo -f makefile.os2 +# @cd.. + +lib: ..\lib\libgpio.a + +obj\gpio.o: libgpio\gpio.c + @$(CC) -o $@ $** $(CCFLAGS) + +obj\port.o: libgpio\port.c + @$(CC) -o $@ $** $(CCFLAGS) + +obj\library.o: libgpio\library.c + @$(CC) -o $@ $** $(CCFLAGS) + +..\lib\libgpio.a: obj\gpio.o obj\library.o obj\port.o + @$(MKLIB) $@ $** diff --git a/libgphoto2_port/network/Makefile.am b/libgphoto2_port/network/Makefile.am new file mode 100644 index 000000000..20d46a0e5 --- /dev/null +++ b/libgphoto2_port/network/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPIO_VERSION=\"@LIBGPIO_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gpio +iolib_LTLIBRARIES = libgpio_network.la +libgpio_network_la_LDFLAGS = -version-info @LIBGPIO_VERSION_INFO@ -DHAVE_TERMIOS_H +libgpio_network_la_SOURCES = bsdsocket.c gpio-network.h diff --git a/libgphoto2_port/network/bsdsocket.c b/libgphoto2_port/network/bsdsocket.c new file mode 100644 index 000000000..e0633e144 --- /dev/null +++ b/libgphoto2_port/network/bsdsocket.c @@ -0,0 +1,124 @@ +/* -*- Mode: C { indent-tabs-mode: t { c-basic-offset: 8 { tab-width: 8 -*- */ +/* gphoto2-port-network.c - network IO functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software { you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation { either version 2 of the + License, or (at your option) any later version. + + The GPIO Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library { see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include "gphoto2-port.h" + +/* network prototypes + --------------------------------------------------------------------- */ +int gp_port_network_list(gp_port_info *list, int *count); + +int gp_port_network_init(gp_port *dev); +int gp_port_network_exit(gp_port *dev); + +int gp_port_network_open(gp_port *dev); +int gp_port_network_close(gp_port *dev); + +int gp_port_network_read(gp_port *dev, char *bytes, int size); +int gp_port_network_write(gp_port *dev, char *bytes, int size); + +int gp_port_network_get_pin(gp_port *dev, int pin); +int gp_port_network_set_pin(gp_port *dev, int pin, int level); + +int gp_port_network_update (gp_port *dev); + +int gp_port_network_set_baudrate(gp_port *dev); + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_NETWORK); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_network_init; + ops->exit = gp_port_network_exit; + ops->open = gp_port_network_open; + ops->close = gp_port_network_close; + ops->read = gp_port_network_read; + ops->write = gp_port_network_write; + ops->update = gp_port_network_update; + ops->get_pin = NULL; + ops->set_pin = NULL; + ops->clear_halt = NULL; + ops->msg_write = NULL; + ops->msg_read = NULL; + + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) { + + list[*count].type = GP_PORT_NETWORK; + strcpy(list[*count].name, "Network connection"); + strcpy(list[*count].path, "network"); + list[*count].argument_needed = 1; + strcpy(list[*count].argument_description, "host"); + *count += 1; + + return (GP_OK); +} + +/* Network API functions + --------------------------------------------------------------------- */ + +int gp_port_network_init(gp_port *dev) { + +} + +int gp_port_network_exit(gp_port *dev) { + +} + +int gp_port_network_open(gp_port *dev) { + +} + +int gp_port_network_close(gp_port *dev) { + +} +int gp_port_network_read(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_network_write(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_network_get_pin(gp_port *dev, int pin) { + +} + +int gp_port_network_set_pin(gp_port *dev, int pin, int level) { + +} + +int gp_port_network_update (gp_port *dev) { + +} diff --git a/libgphoto2_port/parallel/Makefile.am b/libgphoto2_port/parallel/Makefile.am new file mode 100644 index 000000000..ce564afb6 --- /dev/null +++ b/libgphoto2_port/parallel/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPIO_VERSION=\"@LIBGPIO_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gpio +iolib_LTLIBRARIES = libgpio_parallel.la +libgpio_parallel_la_LDFLAGS = -version-info @LIBGPIO_VERSION_INFO@ -DHAVE_TERMIOS_H +libgpio_parallel_la_SOURCES = unix.c gpio-parallel.h diff --git a/libgphoto2_port/parallel/makefile.os2 b/libgphoto2_port/parallel/makefile.os2 new file mode 100644 index 000000000..8bb76fb29 --- /dev/null +++ b/libgphoto2_port/parallel/makefile.os2 @@ -0,0 +1,36 @@ +CCFLAGS=-O2 -c -I.. -I..\..\include -I..\..\libgpio\include -Zmtd -Zcrtdll -Zbin-files -D__ST_MT_ERRNO_ -I. -DOS2 -DHAVE_TERMIOS_H -DEBUG +CC=gcc + +all: start \ + dll \ + lib \ + end + +start: + @echo **** + @echo Entering: $(MAKEDIR) + @echo using CCFLAGS: $(CCFLAGS) + @echo **** + +end: + @echo **** + @echo Done: $(MAKEDIR) + @echo **** + +dll: ..\giparall.dll + +..\obj\parallel.o : unix.c + @$(CC) -o $@ $** $(CCFLAGS) + +lib: ..\..\lib\giparall.a + +..\..\lib\giparall.a: + @implib giparall.lib ..\giparall.dll + @emximp -o ..\..\lib\giparall.a giparall.lib + +parallel.def: ..\obj\parallel.o + @copy parallel.df parallel.def + @emxexp $** >> parallel.def + +..\giparall.dll: ..\obj\parallel.o parallel.def + @$(CC) -Wall -Zdll -Zcrtdll -o $@ $** -lwrap -lgcc -L..\..\LIB -llibgphoto2 -llibgpio -ldllib diff --git a/libgphoto2_port/parallel/parallel.df b/libgphoto2_port/parallel/parallel.df new file mode 100644 index 000000000..52952357e --- /dev/null +++ b/libgphoto2_port/parallel/parallel.df @@ -0,0 +1,2 @@ +LIBRARY GIPARALL +EXPORTS diff --git a/libgphoto2_port/parallel/unix.c b/libgphoto2_port/parallel/unix.c new file mode 100644 index 000000000..8c03902ef --- /dev/null +++ b/libgphoto2_port/parallel/unix.c @@ -0,0 +1,167 @@ +/* -*- Mode: C { indent-tabs-mode: t { c-basic-offset: 8 { tab-width: 8 -*- */ +/* gphoto2-port-parallel.c - parallel IO functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software { you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation { either version 2 of the + License, or (at your option) any later version. + + The GPIO Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library { see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#include "gphoto2-port-parallel.h" +#include "gphoto2-port.h" + +/* Parallel prototypes + --------------------------------------------------------------------- */ +int gp_port_parallel_list(gp_port_info *list, int *count); + +int gp_port_parallel_init(gp_port *dev); +int gp_port_parallel_exit(gp_port *dev); + +int gp_port_parallel_open(gp_port *dev); +int gp_port_parallel_close(gp_port *dev); + +int gp_port_parallel_read(gp_port *dev, char *bytes, int size); +int gp_port_parallel_write(gp_port *dev, char *bytes, int size); + +int gp_port_parallel_get_pin(gp_port *dev, int pin); +int gp_port_parallel_set_pin(gp_port *dev, int pin, int level); + +int gp_port_parallel_update (gp_port *dev); + + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_PARALLEL); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_parallel_init; + ops->exit = gp_port_parallel_exit; + ops->open = gp_port_parallel_open; + ops->close = gp_port_parallel_close; + ops->read = gp_port_parallel_read; + ops->write = gp_port_parallel_write; + ops->update = gp_port_parallel_update; + ops->get_pin = gp_port_parallel_get_pin; + ops->set_pin = gp_port_parallel_set_pin; + + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) { + + char buf[1024], prefix[1024]; + int x, fd, use_int=0, use_char=0; +#ifdef __linux + /* devfs */ + struct stat s; +#endif + +#ifdef OS2 + int rc,fh,option; +#endif + + strcpy(prefix, GP_PORT_PARALLEL_PREFIX); + +#ifdef __linux + /* devfs */ + if (stat("/dev/parports", &s) == 0) + strcpy(prefix, "/dev/parports/%i"); +#endif + + for (x=GP_PORT_PARALLEL_RANGE_LOW; x<=GP_PORT_PARALLEL_RANGE_HIGH; x++) { + sprintf(buf, prefix, x); + #ifdef OS2 + rc = DosOpen(buf,&fh,&option,0,0,1,OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYREADWRITE,0); + if(rc==0) + { + #endif + + fd = open (buf, O_RDONLY | O_NDELAY); + if (fd != -1) { + close(fd); + list[*count].type = GP_PORT_PARALLEL; + strcpy(list[*count].path, buf); + sprintf(buf, "Parallel Port %i", x); + strcpy(list[*count].name, buf); + list[*count].argument_needed = 0; + *count += 1; + } + #ifdef OS2 + } + #endif + } + + return (GP_OK); +} + +/* Parallel API functions + --------------------------------------------------------------------- */ + +int gp_port_parallel_init(gp_port *dev) { + +} + +int gp_port_parallel_exit(gp_port *dev) { + +} + +int gp_port_parallel_open(gp_port *dev) { + +} + +int gp_port_parallel_close(gp_port *dev) { + +} +int gp_port_parallel_read(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_parallel_write(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_parallel_get_pin(gp_port *dev, int pin) { + +} + +int gp_port_parallel_set_pin(gp_port *dev, int pin, int level) { + +} + +int gp_port_parallel_update (gp_port *dev) { + +} diff --git a/libgphoto2_port/serial/Makefile.am b/libgphoto2_port/serial/Makefile.am new file mode 100644 index 000000000..893ceeefb --- /dev/null +++ b/libgphoto2_port/serial/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" -DHAVE_TERMIOS_H +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gphoto2_port +iolib_LTLIBRARIES = libgphoto2_port_serial.la +libgphoto2_port_serial_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ -DHAVE_TERMIOS_H +libgphoto2_port_serial_la_SOURCES = unix.c diff --git a/libgphoto2_port/serial/makefile.os2 b/libgphoto2_port/serial/makefile.os2 new file mode 100644 index 000000000..da0aa615a --- /dev/null +++ b/libgphoto2_port/serial/makefile.os2 @@ -0,0 +1,36 @@ +CCFLAGS=-O2 -c -I.. -I..\..\include -I..\..\libgpio\include -Zmtd -Zcrtdll -Zbin-files -D__ST_MT_ERRNO_ -I. -DOS2 -DHAVE_TERMIOS_H -DEBUG +CC=gcc + +all: start \ + dll \ + lib \ + end + +start: + @echo **** + @echo Entering: $(MAKEDIR) + @echo using CCFLAGS: $(CCFLAGS) + @echo **** + +end: + @echo **** + @echo Done: $(MAKEDIR) + @echo **** + +dll: ..\giserial.dll + +..\obj\serial.o : unix.c + @$(CC) -o $@ $** $(CCFLAGS) + +lib: ..\..\lib\giserial.a + +..\..\lib\giserial.a: + @implib giserial.lib ..\giserial.dll + @emximp -o ..\..\lib\giserial.a giserial.lib + +serial.def: ..\obj\serial.o + @copy serial.df serial.def + @emxexp $** >> serial.def + +..\giserial.dll: ..\obj\serial.o serial.def + @$(CC) -Wall -Zdll -Zcrtdll -o $@ $** -lwrap -lgcc -L..\..\lib -llibgphoto2 -llibgpio -ldllib diff --git a/libgphoto2_port/serial/serial.df b/libgphoto2_port/serial/serial.df new file mode 100644 index 000000000..3e9350913 --- /dev/null +++ b/libgphoto2_port/serial/serial.df @@ -0,0 +1,2 @@ +LIBRARY GISERIAL +EXPORTS diff --git a/libgphoto2_port/serial/unix.c b/libgphoto2_port/serial/unix.c new file mode 100644 index 000000000..37f871291 --- /dev/null +++ b/libgphoto2_port/serial/unix.c @@ -0,0 +1,529 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* gphoto2-port-serial.c - Serial IO functions + + Modifications: + Copyright (C) 2000 Philippe Marzouk <pmarzouk@bigfoot.com> + Copyright (C) 2000 Edouard Lafargue <Edouard.Lafargue@bigfoot.com> + Copyright (C) 1999 Johannes Erdfelt <johannes@erdfelt.com> + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + Based on work by: + Copyright (C) 1999 Beat Christen <spiff@longstreet.ch> + for the toshiba gPhoto library. + + The GPIO Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GPIO Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#if HAVE_TERMIOS_H +#include <termios.h> +#define CRTSCTS 020000000000 +#else +#if HAVE_SYS_IOCTL_H +#include <sys/ioctl.h> +#endif +#include <sgtty.h> +#endif + +#include "../include/gphoto2-port-serial.h" +#include "../include/gphoto2-port.h" + +#ifdef HAVE_TERMIOS_H +static struct termios term_old; +#else +static struct sgttyb term_old; +#endif + +/* Serial prototypes + ------------------------------------------------------------------ */ +int gp_port_serial_init(gp_port *dev); +int gp_port_serial_exit(gp_port *dev); + +int gp_port_serial_open(gp_port *dev); +int gp_port_serial_close(gp_port *dev); + +int gp_port_serial_read(gp_port *dev, char *bytes, int size); +int gp_port_serial_write(gp_port *dev, char *bytes, int size); + +int gp_port_serial_update (gp_port *dev); + +/* Specific */ +int gp_port_serial_get_pin(gp_port *dev, int pin); +int gp_port_serial_set_pin(gp_port *dev, int pin, int level); +int gp_port_serial_send_break (gp_port *dev, int duration); + + +/* private */ +int gp_port_serial_set_baudrate(gp_port *dev); +static speed_t gp_port_serial_baudconv(int rate); + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_SERIAL); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_serial_init; + ops->exit = gp_port_serial_exit; + ops->open = gp_port_serial_open; + ops->close = gp_port_serial_close; + ops->read = gp_port_serial_read; + ops->write = gp_port_serial_write; + ops->update = gp_port_serial_update; + ops->get_pin = gp_port_serial_get_pin; + ops->set_pin = gp_port_serial_set_pin; + ops->send_break = gp_port_serial_send_break; + + return (ops); +} + +int gp_port_library_list (gp_port_info *list, int *count) { + + + char buf[1024], prefix[1024]; + int x, fd; +#ifdef __linux + /* devfs */ + struct stat s; +#endif +#ifdef OS2 + int rc,fh,option; +#endif + + /* Copy in the serial port prefix */ + strcpy(prefix, GP_PORT_SERIAL_PREFIX); + +#ifdef __linux + /* devfs */ + if (stat("/dev/tts", &s)==0) + strcpy(prefix, "/dev/tts/%i"); +#endif + for (x=GP_PORT_SERIAL_RANGE_LOW; x<=GP_PORT_SERIAL_RANGE_HIGH; x++) { + sprintf(buf, prefix, x); +#ifdef OS2 + rc = DosOpen(buf,&fh,&option,0,0,1,OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYREADWRITE,0); + DosClose(fh); + if(rc==0) { +#endif + fd = open (buf, O_RDONLY | O_NDELAY); + if (fd != -1) { + close(fd); + list[*count].type = GP_PORT_SERIAL; + strcpy(list[*count].path, buf); + sprintf(buf, "Serial Port %i", x); + strcpy(list[*count].name, buf); + list[*count].argument_needed = 0; + *count += 1; + } +#ifdef OS2 + } +#endif + } + + return (GP_OK); +} + +/* Serial API functions + ------------------------------------------------------------------ */ + +int gp_port_serial_init (gp_port *dev) { + /* save previous setttings in to dev->settings_saved */ +#if HAVE_TERMIOS_H + if (tcgetattr(dev->device_fd, &term_old) < 0) { + perror("tcgetattr"); + return GP_ERROR; + } +#else + if (ioctl(dev->device_fd, TIOCGETP, &term_old) < 0) { + perror("ioctl(TIOCGETP)"); + return GP_ERROR; + } +#endif + return GP_OK; +} + +int gp_port_serial_exit (gp_port *dev) { + /* ... */ + return GP_OK; +} + +int gp_port_serial_open(gp_port * dev) +{ + +#ifdef __FreeBSD__ + dev->device_fd = open(dev->settings.serial.port, O_RDWR | O_NOCTTY | O_NONBLOCK); +#else + dev->device_fd = open(dev->settings.serial.port, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK); +#endif + if (dev->device_fd == -1) { + fprintf(stderr, "gp_port_serial_open: failed to open "); + perror(dev->settings.serial.port); + return GP_ERROR; + } + +/* if (ioctl (dev->device_fd, TIOCMBIC, &RTS) <0) { + perror("ioctl(TIOCMBIC)"); + return GP_ERROR; + } */ + return GP_OK; +} + +int gp_port_serial_close(gp_port * dev) +{ + if (close(dev->device_fd) == -1) { + perror("gp_port_serial_close: tried closing device file descriptor"); + return GP_ERROR; + } + return GP_OK; +} + +int gp_port_serial_write(gp_port * dev, char *bytes, int size) +{ + int len, ret; + + len = 0; + while (len < size) { /* Make sure we write all data while handling */ + /* the harmless errors */ + if ((ret = write(dev->device_fd, bytes, size - len)) == -1) + switch (errno) { + case EAGAIN: + case EINTR: + ret = 0; + break; + default: + perror("gp_port_serial_write"); + return GP_ERROR; + } + len += ret; + } + + /* wait till all bytes are really sent */ +#ifndef OS2 +#if HAVE_TERMIOS_H + tcdrain(dev->device_fd); +#else + ioctl(dev->device_fd, TCDRAIN, 0); +#endif +#endif + return GP_OK; +} + + +int gp_port_serial_read(gp_port * dev, char *bytes, int size) +{ + struct timeval timeout; + fd_set readfs; /* file descriptor set */ + int readen = 0; + int rc; + + FD_ZERO(&readfs); + FD_SET(dev->device_fd, &readfs); + + while (readen < size) { + /* set timeout value within input loop */ + timeout.tv_usec = (dev->timeout % 1000) * 1000; + timeout.tv_sec = (dev->timeout / 1000); /* = 0 + * if dev->timeout < 1000 + */ + + + rc = select(dev->device_fd + 1, &readfs, NULL, NULL, &timeout); +/* if ( (rc == 0) && (readen == 0)) { */ + /* Timeout before reading anything */ +/* printf("gp_port_serial_read (timeout)\n"); */ +/* return GP_ERROR_TIMEOUT; */ +/* } */ + if (0 == rc) { + return GP_ERROR_TIMEOUT; + } + if (FD_ISSET(dev->device_fd, &readfs)) { + int now = read(dev->device_fd, bytes, size - readen); + + if (now < 0) { + perror("gp_port_serial_read (read fails)"); + return GP_ERROR; + } else { + bytes += now; + readen += now; + } + } else { + perror("gp_port_serial_read (tty timeout)"); + return GP_ERROR; + } + } + return readen; +} + +/* + * Get the status of the lines of the serial port + * + */ +int gp_port_serial_get_pin(gp_port * dev, int pin) +{ + int j, bit; + + switch(pin) { + case PIN_RTS: + bit = TIOCM_RTS; + break; + case PIN_DTR: + bit = TIOCM_DTR; + break; + case PIN_CTS: + bit = TIOCM_CTS; + break; + case PIN_DSR: + bit = TIOCM_DSR; + break; + case PIN_CD: + bit = TIOCM_CD; + break; + case PIN_RING: + bit = TIOCM_RNG; + break; + default: + return GP_ERROR; + } + + if (ioctl(dev->device_fd, TIOCMGET, &j) < 0) { + perror("gp_port_serial_status (Getting hardware status bits)"); + return GP_ERROR; + } + return (j & bit); +} + +/* +* Set the status of lines in the serial port +* +* level is 0 for off and 1 for on +* +*/ +int gp_port_serial_set_pin(gp_port * dev, int pin, int level) +{ + int bit,request; + + switch(pin) { + case PIN_RTS: + bit = TIOCM_RTS; + break; + case PIN_DTR: + bit = TIOCM_DTR; + break; + case PIN_CTS: + bit = TIOCM_CTS; + break; + case PIN_DSR: + bit = TIOCM_DSR; + break; + case PIN_CD: + bit = TIOCM_CD; + break; + case PIN_RING: + bit = TIOCM_RNG; + break; + default: + return GP_ERROR; + } + + switch(level) { + case 0: + request = TIOCMBIS; + break; + case 1: + request = TIOCMBIC; + break; + default: + return GP_ERROR; + } + + if (ioctl (dev->device_fd, request, &bit) <0) { + perror("ioctl(TIOCMBI[CS])"); + return GP_ERROR; + } + + return GP_OK; +} + +/* + * This function will apply the settings to + * the device. The device has to be opened + */ +int gp_port_serial_update(gp_port * dev) +{ + memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings)); + + if (dev->device_fd != 0) { + if (gp_port_serial_close(dev) == GP_ERROR) + return GP_ERROR; + if (gp_port_serial_open(dev) == GP_ERROR) + return GP_ERROR; + + return gp_port_serial_set_baudrate(dev); + } + return GP_OK; +} + +/* + Serial port specific helper functions + ---------------------------------------------------------------- + */ + +/* Called to set the baud rate */ +int gp_port_serial_set_baudrate(gp_port * dev) +{ +#if HAVE_TERMIOS_H + struct termios tio; + + if (tcgetattr(dev->device_fd, &tio) < 0) { + perror("tcgetattr"); + return GP_ERROR; + } + tio.c_cflag = (tio.c_cflag & ~CSIZE) | CS8; + + /* Set into raw, no echo mode */ +#if defined(__FreeBSD__) || defined(__NetBSD__) + tio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | + IXANY | IXON | IXOFF | INPCK | ISTRIP); +#else + tio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC | + IXANY | IXON | IXOFF | INPCK | ISTRIP); +#endif + tio.c_iflag |= (BRKINT | IGNPAR); + tio.c_oflag &= ~OPOST; + tio.c_lflag &= ~(ICANON | ISIG | ECHO | ECHONL | ECHOE | + ECHOK | IEXTEN); + tio.c_cflag &= ~(CRTSCTS | PARENB | PARODD); + tio.c_cflag |= CLOCAL | CREAD; + + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 0; + + cfsetispeed(&tio, gp_port_serial_baudconv(dev->settings.serial.speed)); + cfsetospeed(&tio, gp_port_serial_baudconv(dev->settings.serial.speed)); + + if (tcsetattr(dev->device_fd, TCSANOW, &tio) < 0) { + perror("tcsetattr"); + return GP_ERROR; + } + if (fcntl(dev->device_fd, F_SETFL, 0) < 0) { /* clear O_NONBLOCK */ + perror("fcntl F_SETFL"); + return -1; + } +#else + struct sgttyb ttyb; + + if (ioctl(dev->device_fd, TIOCGETP, &ttyb) < 0) { + perror("ioctl(TIOCGETP)"); + return GP_ERROR; + } + ttyb.sg_ispeed = dev->settings.serial.speed; + ttyb.sg_ospeed = dev->settings.serial.speed; + ttyb.sg_flags = 0; + + if (ioctl(dev->device_fd, TIOCSETP, &ttyb) < 0) { + perror("ioctl(TIOCSETP)"); + return GP_ERROR; + } +#endif + + return GP_OK; +} + +/* Called to convert a int baud to the POSIX enum value */ +static speed_t gp_port_serial_baudconv(int baud) +{ +#define BAUDCASE(x) case (x): { ret = B##x; break; } + speed_t ret; + + ret = (speed_t) baud; + switch (baud) { + /* POSIX defined baudrates */ + BAUDCASE(0); + BAUDCASE(50); + BAUDCASE(75); + BAUDCASE(110); + BAUDCASE(134); + BAUDCASE(150); + BAUDCASE(200); + BAUDCASE(300); + BAUDCASE(600); + BAUDCASE(1200); + BAUDCASE(1800); + BAUDCASE(2400); + BAUDCASE(4800); + BAUDCASE(9600); + BAUDCASE(19200); + BAUDCASE(38400); + + /* non POSIX values */ +#ifdef B7200 + BAUDCASE(7200); +#endif +#ifdef B14400 + BAUDCASE(14400); +#endif +#ifdef B28800 + BAUDCASE(28800); +#endif +#ifdef B57600 + BAUDCASE(57600); +#endif +#ifdef B115200 + BAUDCASE(115200); +#endif +#ifdef B230400 + BAUDCASE(230400); +#endif + + default: + fprintf(stderr, "baudconv: baudrate %d is undefined; using as is\n", baud); + } + + return ret; +#undef BAUDCASE +} + +int gp_port_serial_send_break (gp_port *dev, int duration) { + + /* Duration is in seconds */ + +#if HAVE_TERMIOS_H + tcsendbreak(dev->device_fd, duration / 3); + tcdrain(dev->device_fd); +#else + /* ioctl */ +#endif + return 0; +} diff --git a/libgphoto2_port/stamp-h.in b/libgphoto2_port/stamp-h.in new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/libgphoto2_port/stamp-h.in diff --git a/libgphoto2_port/test/gphoto2-port-test.c b/libgphoto2_port/test/gphoto2-port-test.c new file mode 100644 index 000000000..9656e8b30 --- /dev/null +++ b/libgphoto2_port/test/gphoto2-port-test.c @@ -0,0 +1,50 @@ + +#include <stdio.h> +#include <string.h> +#include "gpio.h" + +void dump(gp_port * dev) +{ + +} + +int main(int argc, char **argv) +{ + gp_port *dev; /* declare the device */ + gp_port_settings settings; + char buf[32]; + + dev = gp_port_new(0); + /* create a new serial device */ + gp_port_set_timeout(dev, 500); + + strcpy(settings.serial.port, "/dev/modem"); + settings.serial.speed = 19200; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + + gp_port_set_settings(dev, settings); + gp_port_open(dev); /* open the device */ + dump(dev); + + gp_port_get_settings(dev, &settings); + settings.serial.speed = 57600; + gp_port_set_settings(dev, settings); + + dump(dev); + + printf("CTS: %i", gp_port_get_pin(dev,PIN_CTS)); + + gp_port_write(dev, "AT\n", 3); /* write bytes to the device */ + + gp_port_read(dev, buf, 3); /* read bytes from the device */ + buf[3] = 0; + printf("recv: %s\n", buf); + + gp_port_close(dev); /* close the device */ + + gp_port_free(dev); + + return 0; +} diff --git a/libgphoto2_port/usb/Makefile.am b/libgphoto2_port/usb/Makefile.am new file mode 100644 index 000000000..9fdca54a3 --- /dev/null +++ b/libgphoto2_port/usb/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g `libusb-config --cflags` +LDFLAGS = @LDFLAGS@ -g `libusb-config --libs` + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gphoto2_port +iolib_LTLIBRARIES = libgphoto2_port_usb.la +libgphoto2_port_usb_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ +libgphoto2_port_usb_la_SOURCES = libusb.c diff --git a/libgphoto2_port/usb/libusb.c b/libgphoto2_port/usb/libusb.c new file mode 100644 index 000000000..054b36337 --- /dev/null +++ b/libgphoto2_port/usb/libusb.c @@ -0,0 +1,260 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* gphoto2-port-usb.c - USB transport functions + + Copyright (C) 1999-2000 Johannes Erdfelt <johannes@erdfelt.com> + + The GPIO Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GPIO Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/time.h> +#include <sys/param.h> +#include <dirent.h> +#include <string.h> + +#include <usb.h> +#include "gphoto2-port.h" + +#define GP_PORT_USB_DEBUG 1 + +int gp_port_usb_list(gp_port_info *list, int *count); +int gp_port_usb_init(gp_port *dev); +int gp_port_usb_exit(gp_port *dev); +int gp_port_usb_open(gp_port *dev); +int gp_port_usb_close(gp_port *dev); +int gp_port_usb_reset(gp_port *dev); +int gp_port_usb_write(gp_port * dev, char *bytes, int size); +int gp_port_usb_read(gp_port * dev, char *bytes, int size); +int gp_port_usb_update(gp_port * dev); + +int gp_port_usb_clear_halt_lib(gp_port * dev, int ep); +int gp_port_usb_msg_read_lib(gp_port * dev, int value, char *bytes, int size); +int gp_port_usb_msg_write_lib(gp_port * dev, int value, char *bytes, int size); +int gp_port_usb_find_device_lib(gp_port *dev, int idvendor, int idproduct); + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_USB); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_usb_init; + ops->exit = gp_port_usb_exit; + ops->open = gp_port_usb_open; + ops->close = gp_port_usb_close; + ops->read = gp_port_usb_read; + ops->write = gp_port_usb_write; + ops->update = gp_port_usb_update; + ops->clear_halt = gp_port_usb_clear_halt_lib; + ops->msg_write = gp_port_usb_msg_write_lib; + ops->msg_read = gp_port_usb_msg_read_lib; + ops->find_device = gp_port_usb_find_device_lib; + + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) +{ + + list[*count].type = GP_PORT_USB; + strcpy(list[*count].name, "Universal Serial Bus"); + strcpy(list[*count].path, "usb"); + list[*count].argument_needed = 0; + *count += 1; + + return GP_OK; +} + +int gp_port_usb_init(gp_port *dev) +{ + usb_init(); + usb_find_busses(); + usb_find_devices(); + return (GP_OK); +} + +int gp_port_usb_exit(gp_port *dev) +{ + return (GP_OK); +} + +int gp_port_usb_open(gp_port *dev) +{ + int ret; + void *udev; + + if (GP_PORT_USB_DEBUG) + printf ("gp_port_usb_open() called\n"); + + /* Open the device using the previous usb_handle returned by find_device */ + udev = dev->device_handle; + dev->device_handle = usb_open(udev); + if (!dev->device_handle) + return GP_ERROR; + + ret = usb_set_configuration(dev->device_handle, dev->settings.usb.config); + if (ret < 0) { + fprintf(stderr, "gp_port_usb_open: could not set config %d: %s\n", + dev->settings.usb.config, strerror(errno)); + return GP_ERROR; + } + + ret = usb_claim_interface(dev->device_handle, dev->settings.usb.interface); + if (ret < 0) { + fprintf(stderr, "gp_port_usb_open: could not claim intf %d: %s\n", + dev->settings.usb.interface, strerror(errno)); + return GP_ERROR; + } + + ret = usb_set_altinterface(dev->device_handle, dev->settings.usb.altsetting); + if (ret < 0) { + fprintf(stderr, "gp_port_usb_open: could not set intf %d/%d: %s\n", + dev->settings.usb.interface, + dev->settings.usb.altsetting, strerror(errno)); + return GP_ERROR; + } + + return GP_OK; +} + +int gp_port_usb_close(gp_port *dev) +{ + if (GP_PORT_USB_DEBUG) + printf ("gp_port_usb_close() called\n"); + + if (usb_close(dev->device_handle) < 0) + fprintf(stderr, "gp_port_usb_close: %s\n", + strerror(errno)); + + dev->device_handle = NULL; + + return GP_OK; +} + +int gp_port_usb_reset(gp_port *dev) +{ + gp_port_usb_close(dev); + return gp_port_usb_open(dev); +} + +int gp_port_usb_clear_halt_lib(gp_port * dev, int ep) +{ + int ret=0; + + switch (ep) { + case GP_PORT_USB_IN_ENDPOINT : + ret=usb_clear_halt(dev->device_handle, dev->settings.usb.inep); + break; + case GP_PORT_USB_OUT_ENDPOINT : + ret=usb_clear_halt(dev->device_handle, dev->settings.usb.outep); + break; + default: + fprintf(stderr,"gp_port_usb_clear_halt: bad EndPoint argument\n"); + return GP_ERROR; + } + return (ret ? GP_ERROR : GP_OK); +} + +int gp_port_usb_write(gp_port * dev, char *bytes, int size) +{ + if (GP_PORT_USB_DEBUG) { + int i; + + printf("gp_port_usb_write(): "); + for (i = 0; i < size; i++) + printf("%02x ",(unsigned char)bytes[i]); + printf("\n"); + } + + return usb_bulk_write(dev->device_handle, dev->settings.usb.outep, + bytes, size, dev->timeout); +} + +int gp_port_usb_read(gp_port * dev, char *bytes, int size) +{ + int ret; + + ret = usb_bulk_read(dev->device_handle, dev->settings.usb.inep, + bytes, size, dev->timeout); + if (ret < 0) + return GP_ERROR; + + if (GP_PORT_USB_DEBUG) { + int i; + + printf("gp_port_usb_read(timeout=%d): ", dev->timeout); + for (i = 0; i < ret; i++) + printf("%02x ",(unsigned char)(bytes[i])); + printf("\n"); + } + + return ret; +} + +int gp_port_usb_msg_write_lib(gp_port * dev, int value, char *bytes, int size) +{ + return usb_control_msg(dev->device_handle, + USB_TYPE_VENDOR | USB_RECIP_DEVICE, + size > 1 ? 0x04 : 0x0c, value, 0, bytes, size, dev->timeout); +} + +int gp_port_usb_msg_read_lib(gp_port * dev, int value, char *bytes, int size) +{ + return usb_control_msg(dev->device_handle, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | 0x80, + size > 1 ? 0x04 : 0x0c, value, 0, bytes, size, dev->timeout); +} + +/* + * This function applys changes to the device + * (At this time it does nothing) + */ +int gp_port_usb_update(gp_port * dev) +{ + memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings)); + + return GP_OK; +} + +int gp_port_usb_find_device_lib(gp_port * d, int idvendor, int idproduct) +{ + struct usb_bus *bus; + struct usb_device *dev; + for (bus = usb_busses; bus; bus = bus->next) { + for (dev = bus->devices; dev; dev = dev->next) { + if ((dev->descriptor.idVendor == idvendor) && + (dev->descriptor.idProduct == idproduct)) { + d->device_handle = dev; + return GP_OK; + } + } + } + + return GP_ERROR; +} |