From be2d0f54b3a0d4c8e7f39660f9b0406795db3afa Mon Sep 17 00:00:00 2001 From: Scott Fritzinger Date: Tue, 25 Jul 2000 18:02:48 +0000 Subject: [PATCH] added canon lib\!\! git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@753 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/canon/Makefile | 356 +++++++ camlibs/canon/Makefile.am | 11 + camlibs/canon/Makefile.in | 356 +++++++ camlibs/canon/Protocol | 957 +++++++++++++++++ camlibs/canon/README | 114 ++ camlibs/canon/canon.c | 1408 +++++++++++++++++++++++++ camlibs/canon/canon.h | 49 + camlibs/canon/crc.c | 233 +++++ camlibs/canon/crc.h | 7 + camlibs/canon/mkpatch | 33 + camlibs/canon/ps350/COPYING | 339 ++++++ camlibs/canon/ps350/README | 20 + camlibs/canon/ps350/SerialIn | Bin 0 -> 1201 bytes camlibs/canon/ps350/compu1 | Bin 0 -> 6 bytes camlibs/canon/ps350/compu3 | Bin 0 -> 300 bytes camlibs/canon/ps350/compu3c | Bin 0 -> 1 bytes camlibs/canon/ps350/compu3d | 1 + camlibs/canon/ps350/compu3e-4 | 1 + camlibs/canon/ps350/compu3f | 1 + camlibs/canon/ps350/compu5 | Bin 0 -> 300 bytes camlibs/canon/ps350/compu6 | Bin 0 -> 300 bytes camlibs/canon/ps350/notes.txt | 13 + camlibs/canon/ps350/ps350chk.c | 157 +++ camlibs/canon/ps350/ps350init | 50 + camlibs/canon/ps350/ps350proto.txt | 740 +++++++++++++ camlibs/canon/ps350/renamejpg.c | 75 ++ camlibs/canon/psa50.c | 1554 ++++++++++++++++++++++++++++ camlibs/canon/psa50.h | 123 +++ camlibs/canon/serial.c | 316 ++++++ camlibs/canon/serial.h | 33 + camlibs/canon/util.c | 124 +++ camlibs/canon/util.h | 26 + 32 files changed, 7097 insertions(+) create mode 100644 camlibs/canon/Makefile create mode 100644 camlibs/canon/Makefile.am create mode 100644 camlibs/canon/Makefile.in create mode 100644 camlibs/canon/Protocol create mode 100644 camlibs/canon/README create mode 100644 camlibs/canon/canon.c create mode 100644 camlibs/canon/canon.h create mode 100644 camlibs/canon/crc.c create mode 100644 camlibs/canon/crc.h create mode 100644 camlibs/canon/mkpatch create mode 100644 camlibs/canon/ps350/COPYING create mode 100644 camlibs/canon/ps350/README create mode 100644 camlibs/canon/ps350/SerialIn create mode 100644 camlibs/canon/ps350/compu1 create mode 100644 camlibs/canon/ps350/compu3 create mode 100644 camlibs/canon/ps350/compu3c create mode 100644 camlibs/canon/ps350/compu3d create mode 100644 camlibs/canon/ps350/compu3e-4 create mode 100644 camlibs/canon/ps350/compu3f create mode 100644 camlibs/canon/ps350/compu5 create mode 100644 camlibs/canon/ps350/compu6 create mode 100644 camlibs/canon/ps350/notes.txt create mode 100644 camlibs/canon/ps350/ps350chk.c create mode 100755 camlibs/canon/ps350/ps350init create mode 100644 camlibs/canon/ps350/ps350proto.txt create mode 100644 camlibs/canon/ps350/renamejpg.c create mode 100644 camlibs/canon/psa50.c create mode 100644 camlibs/canon/psa50.h create mode 100644 camlibs/canon/serial.c create mode 100644 camlibs/canon/serial.h create mode 100644 camlibs/canon/util.c create mode 100644 camlibs/canon/util.h diff --git a/camlibs/canon/Makefile b/camlibs/canon/Makefile new file mode 100644 index 000000000..a376ffd33 --- /dev/null +++ b/camlibs/canon/Makefile @@ -0,0 +1,356 @@ +# Generated automatically from Makefile.in by configure. +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = /bin/sh + +srcdir = . +top_srcdir = ../.. +prefix = /usr/local +exec_prefix = ${prefix} + +bindir = ${exec_prefix}/bin +sbindir = ${exec_prefix}/sbin +libexecdir = ${exec_prefix}/libexec +datadir = ${prefix}/share +sysconfdir = ${prefix}/etc +sharedstatedir = ${prefix}/com +localstatedir = ${prefix}/var +libdir = ${exec_prefix}/lib +infodir = ${prefix}/info +mandir = ${prefix}/man +includedir = ${prefix}/include +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/gphoto2 +pkglibdir = $(libdir)/gphoto2 +pkgincludedir = $(includedir)/gphoto2 + +top_builddir = ../.. + +ACLOCAL = aclocal +AUTOCONF = autoconf +AUTOMAKE = automake +AUTOHEADER = autoheader + +INSTALL = /usr/bin/install -c +INSTALL_PROGRAM = ${INSTALL} $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_SCRIPT = ${INSTALL_PROGRAM} +transform = s,x,x, + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = i586-pc-linux-gnu +host_triplet = i586-pc-linux-gnu +AS = @AS@ +CC = gcc +CPP = gcc -E +DLLTOOL = @DLLTOOL@ +LD = /usr/bin/ld +LIBGPHOTO2_INCLUDEDIR = -I${includedir} +LIBGPHOTO2_LIBDIR = -L${libdir} +LIBGPHOTO2_LIBS = -lgphoto2 +LIBGPHOTO2_VERSION = 1.90 +LIBGPIO_CONFIG = /usr/bin/gpio-config +LIBS = -ldl -L/usr/local/lib -lgpio +LIBTOOL = $(SHELL) $(top_builddir)/libtool +LN_S = ln -s +MAINT = # +MAKEINFO = makeinfo +NM = /usr/bin/nm -B +OBJDUMP = @OBJDUMP@ +PACKAGE = gphoto2 +RANLIB = ranlib +SUBDIRS_CAMLIBS = +VERSION = 1.90 + +camlibdir = $(prefix)/lib/gphoto2 +camlib_LTLIBRARIES = libgphoto2_canon.la + +CFLAGS = -g -O2 -I/usr/local/include/gpio `gtk-config --cflags` `gpio-config --cflags` -g -Wall +LDFLAGS = -g `gpio-config --libs` +INCLUDES = -I$(top_srcdir)/include + +libgphoto2_canon_la_SOURCES = canon.c canon.h psa50.c psa50.h serial.c serial.h crc.c crc.h util.c util.h + + +libgphoto_canon_la_LDFLAGS = -version-info 0:0:0 `gpio-config --libs` +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(camlib_LTLIBRARIES) + + +DEFS = -DHAVE_CONFIG_H -I. -I$(srcdir) -I../.. +CPPFLAGS = +libgphoto2_canon_la_LDFLAGS = +libgphoto2_canon_la_LIBADD = +libgphoto2_canon_la_OBJECTS = canon.lo psa50.lo serial.lo crc.lo \ +util.lo +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = README Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = tar +GZIP_ENV = --best +DEP_FILES = .deps/canon.P .deps/crc.P .deps/psa50.P .deps/serial.P \ +.deps/util.P +SOURCES = $(libgphoto2_canon_la_SOURCES) +OBJECTS = $(libgphoto2_canon_la_OBJECTS) + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .s +$(srcdir)/Makefile.in: # Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu camlibs/canon/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-camlibLTLIBRARIES: + +clean-camlibLTLIBRARIES: + -test -z "$(camlib_LTLIBRARIES)" || rm -f $(camlib_LTLIBRARIES) + +distclean-camlibLTLIBRARIES: + +maintainer-clean-camlibLTLIBRARIES: + +install-camlibLTLIBRARIES: $(camlib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(camlibdir) + @list='$(camlib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(camlibdir)/$$p"; \ + $(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(camlibdir)/$$p; \ + else :; fi; \ + done + +uninstall-camlibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + list='$(camlib_LTLIBRARIES)'; for p in $$list; do \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(camlibdir)/$$p; \ + done + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +libgphoto2_canon.la: $(libgphoto2_canon_la_OBJECTS) $(libgphoto2_canon_la_DEPENDENCIES) + $(LINK) -rpath $(camlibdir) $(libgphoto2_canon_la_LDFLAGS) $(libgphoto2_canon_la_OBJECTS) $(libgphoto2_canon_la_LIBADD) $(LIBS) + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = camlibs/canon + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu camlibs/canon/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: +install-exec: install-exec-am + +install-data-am: install-camlibLTLIBRARIES +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-camlibLTLIBRARIES +uninstall: uninstall-am +all-am: Makefile $(LTLIBRARIES) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + $(mkinstalldirs) $(DESTDIR)$(camlibdir) + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-camlibLTLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ + mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-camlibLTLIBRARIES clean-compile clean-libtool \ + clean-tags clean-depend clean-generic mostlyclean-am + +clean: clean-am + +distclean-am: distclean-camlibLTLIBRARIES distclean-compile \ + distclean-libtool distclean-tags distclean-depend \ + distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-camlibLTLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-tags maintainer-clean-depend \ + maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-camlibLTLIBRARIES distclean-camlibLTLIBRARIES \ +clean-camlibLTLIBRARIES maintainer-clean-camlibLTLIBRARIES \ +uninstall-camlibLTLIBRARIES install-camlibLTLIBRARIES \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile mostlyclean-libtool distclean-libtool \ +clean-libtool maintainer-clean-libtool tags mostlyclean-tags \ +distclean-tags clean-tags maintainer-clean-tags distdir \ +mostlyclean-depend distclean-depend clean-depend \ +maintainer-clean-depend info-am info dvi-am dvi check check-am \ +installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/camlibs/canon/Makefile.am b/camlibs/canon/Makefile.am new file mode 100644 index 000000000..ec21b86ee --- /dev/null +++ b/camlibs/canon/Makefile.am @@ -0,0 +1,11 @@ +camlibdir = $(prefix)/lib/gphoto2 +camlib_LTLIBRARIES = libgphoto2_canon.la + +CFLAGS = @CFLAGS@ `gtk-config --cflags` `gpio-config --cflags` -g -Wall +LDFLAGS = @LDFLAGS@ -g `gpio-config --libs` +INCLUDES = -I$(top_srcdir)/include + +libgphoto2_canon_la_SOURCES = canon.c canon.h psa50.c psa50.h serial.c serial.h \ + crc.c crc.h util.c util.h + +libgphoto_canon_la_LDFLAGS = -version-info 0:0:0 `gpio-config --libs` diff --git a/camlibs/canon/Makefile.in b/camlibs/canon/Makefile.in new file mode 100644 index 000000000..4a452e4cb --- /dev/null +++ b/camlibs/canon/Makefile.in @@ -0,0 +1,356 @@ +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AS = @AS@ +CC = @CC@ +CPP = @CPP@ +DLLTOOL = @DLLTOOL@ +LD = @LD@ +LIBGPHOTO2_INCLUDEDIR = @LIBGPHOTO2_INCLUDEDIR@ +LIBGPHOTO2_LIBDIR = @LIBGPHOTO2_LIBDIR@ +LIBGPHOTO2_LIBS = @LIBGPHOTO2_LIBS@ +LIBGPHOTO2_VERSION = @LIBGPHOTO2_VERSION@ +LIBGPIO_CONFIG = @LIBGPIO_CONFIG@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +NM = @NM@ +OBJDUMP = @OBJDUMP@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +SUBDIRS_CAMLIBS = @SUBDIRS_CAMLIBS@ +VERSION = @VERSION@ + +camlibdir = $(prefix)/lib/gphoto2 +camlib_LTLIBRARIES = libgphoto2_canon.la + +CFLAGS = @CFLAGS@ `gtk-config --cflags` `gpio-config --cflags` -g -Wall +LDFLAGS = @LDFLAGS@ -g `gpio-config --libs` +INCLUDES = -I$(top_srcdir)/include + +libgphoto2_canon_la_SOURCES = canon.c canon.h psa50.c psa50.h serial.c serial.h crc.c crc.h util.c util.h + + +libgphoto_canon_la_LDFLAGS = -version-info 0:0:0 `gpio-config --libs` +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(camlib_LTLIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) -I../.. +CPPFLAGS = @CPPFLAGS@ +libgphoto2_canon_la_LDFLAGS = +libgphoto2_canon_la_LIBADD = +libgphoto2_canon_la_OBJECTS = canon.lo psa50.lo serial.lo crc.lo \ +util.lo +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = README Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = tar +GZIP_ENV = --best +DEP_FILES = .deps/canon.P .deps/crc.P .deps/psa50.P .deps/serial.P \ +.deps/util.P +SOURCES = $(libgphoto2_canon_la_SOURCES) +OBJECTS = $(libgphoto2_canon_la_OBJECTS) + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .s +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu camlibs/canon/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-camlibLTLIBRARIES: + +clean-camlibLTLIBRARIES: + -test -z "$(camlib_LTLIBRARIES)" || rm -f $(camlib_LTLIBRARIES) + +distclean-camlibLTLIBRARIES: + +maintainer-clean-camlibLTLIBRARIES: + +install-camlibLTLIBRARIES: $(camlib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(camlibdir) + @list='$(camlib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(camlibdir)/$$p"; \ + $(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(camlibdir)/$$p; \ + else :; fi; \ + done + +uninstall-camlibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + list='$(camlib_LTLIBRARIES)'; for p in $$list; do \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(camlibdir)/$$p; \ + done + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +libgphoto2_canon.la: $(libgphoto2_canon_la_OBJECTS) $(libgphoto2_canon_la_DEPENDENCIES) + $(LINK) -rpath $(camlibdir) $(libgphoto2_canon_la_LDFLAGS) $(libgphoto2_canon_la_OBJECTS) $(libgphoto2_canon_la_LIBADD) $(LIBS) + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = camlibs/canon + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu camlibs/canon/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: +install-exec: install-exec-am + +install-data-am: install-camlibLTLIBRARIES +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-camlibLTLIBRARIES +uninstall: uninstall-am +all-am: Makefile $(LTLIBRARIES) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + $(mkinstalldirs) $(DESTDIR)$(camlibdir) + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-camlibLTLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ + mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-camlibLTLIBRARIES clean-compile clean-libtool \ + clean-tags clean-depend clean-generic mostlyclean-am + +clean: clean-am + +distclean-am: distclean-camlibLTLIBRARIES distclean-compile \ + distclean-libtool distclean-tags distclean-depend \ + distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-camlibLTLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-tags maintainer-clean-depend \ + maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-camlibLTLIBRARIES distclean-camlibLTLIBRARIES \ +clean-camlibLTLIBRARIES maintainer-clean-camlibLTLIBRARIES \ +uninstall-camlibLTLIBRARIES install-camlibLTLIBRARIES \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile mostlyclean-libtool distclean-libtool \ +clean-libtool maintainer-clean-libtool tags mostlyclean-tags \ +distclean-tags clean-tags maintainer-clean-tags distdir \ +mostlyclean-depend distclean-depend clean-depend \ +maintainer-clean-depend info-am info dvi-am dvi check check-am \ +installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/camlibs/canon/Protocol b/camlibs/canon/Protocol new file mode 100644 index 000000000..d4e3cb046 --- /dev/null +++ b/camlibs/canon/Protocol @@ -0,0 +1,957 @@ +(read/print this document with a non-proportional font such as courier) + +============================================ +====== Canon Powershot Series ====== +==== Transfer Protocol Specifications ===== +============================================ + +* About this document + +The following document is an overview of the Canon Powershot serial +and USB transfer protocols. It should be a valid reference for models +ranging from Powershot A5 to S20. + +No information present in this document was obtained from Canon. +Everything is the result of observations and logical analysis. It is +by no means guaranteed to be accurate, nor even right. Nevertheless, a +lot of people have managed to communicate with their Powershot cameras +using these commands, so they cannot be completely wrong either ! + +An implementation of this communication protocol was made for the +GPhoto digital camera software, available at www.gphoto.org. + +* Contributors: + + This document was written thanks to the efforts of: + + Wolfgang G. Reissnegger, Werner Almesberger, Philippe Marzouk, Mikael + Nyström, Edouard Lafargue. + + +* Copyright : + + The Canon Protocol information. Copyright (c) 2000 by its respective + authors (see the Contrinutors section). + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the: + + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, + USA. + +* To Do : + + (send updates to Edouard.Lafargue@bigfoot.com or to the + gphoto-devel mailing-list) + + - Serial: + + Update get_directory description to match what was discovered in USB. + Describe the structure of the initial ID packet. + Find out what the real meaning of the "fffb" command is. + Describe error recovery protocol. + Describe format of low batt condition. + Find out the rest of the commands that were discovered in USB: + - Make dir + - Delete dir + - Change attribute + - etc. + Describe File upload. + Describe each command in detail. + + - USB: + + Describe the generic get_directory reply packet with the location of + the error code offset. + + - General: + + Rewrite this document in XML (LinuxDoc). + +* Changelog: + + 09 May 2000: first version with both USB and serial protocols + described in the same document. + + + + + +========================================================================= + + + + + +============================================ +== Serial Protocol == +=== Specifications === +============================================ + + +Introduction +============ + + We have chosen to describe the Canon Serial Protocol as successive +layers. I used OSI-like names but the protocol is not really a network +protocol. + + a. Data link layer: + Responsible for framing, escaping and checksuming messages + + b. Transport (packet) layer: + Responsible for dividing messages into packets of known length. + This layer also handles handshaking, retries, etc. + + c. Session (message) layer: + Last layer, carrying whole messages, such as download requests, + image data, and such information. + + Currently, all these layers are documented, but we still lack + information on how to handle protocol retries, and errors in general. + + +Data link layer +===================== + +The following figure illustrates the lower layers of the protocol +used by some Canon PowerShot cameras: + +[ Upper layers ] Example: payload "00 C0 01" + | ^ + | | 00 C0 01 + + | | 00 C0 01 12 34 (fictious CRC) + + | | 00 7E E0 01 12 34 + + | | C0 00 7E E0 01 12 34 C1 + v | +[ Wire format ] + +The upper layers are described later in this file. + + +0) Serial timing +---------------- + +Initialization: PC sends sequences of "U" bytes at 9600 bps until the +camera responds by sending its ID. Each sequence has a length of 2-8 +bytes. The interval to wait between sequences is 0.9-1.04 sec +(measured for 8 bytes). + +When the camera sends its ID, the computer can ask it to change to a +higher speed. The speed can go up to 115200 bps. + +Afterwards, a one/two seconds command timeout should be set. +E.g. retrieving a directory with 1200 files takes several +seconds. Opening a large capacity flash card takes time as well. + + +1) Framing +---------- + +Each message begins with the byte C0 and ends with the byte C1. The +length of a message including the framing bytes and any escape bytes +(see below) never exceeds 1024 bytes. + + +2) Escaping +----------- + +The value 7E is used to XOR the following byte with the value 0x20. This +is used for the following three combinations: + 7E 5E -> 7E + 7E E0 -> C0 + 7E E1 -> C1 + + +3) CRC +------ + +The last two bytes of a message (without framing and escaping) contain +a 16-bit "CCITT" CRC in little-endian order. The CRC is calculated +over the entire message, without framing and escaping, and without +including the CRC bytes. The CRC generator [1] is initialized to a +length-dependent value. The algorithim for the initial value is not +known. However, a table of values emitted by the camera has been +compiled and is in crc.c:crc_init. It is indexed by the length, +i.e. the number of bytes over which the CRC is taken. + + +[1] Assuming the use of + http://www.cse.fau.edu/~sam/course/dc_htm/src_dir/crc_att.c, + generator polynom 0102010 (octal), the initial value of "crc" is + the CRC generator's initial value (in the original code always + zero). + + + +Transport layer +===================== + +Communication is done through messages, which may be split into +several fragments, which are then sent as individual packets. Packets +are framed as described earlier in this file. + + +Packet level +------------ + +Each packet consists of the following two-byte header: + + + +There are two sequence numbers: the message sequence number and +the fragment sequence number . They are counted independently +and start at zero. is reset at the beginning of a session, +while is reset at the beginning of each message. + +The following packet types are known: + 00 Message fragment + 03 Speed message from computer + 04 EOT + 05 ACK + 06 Compatibility? + +A packet with type 03 is sent once, early in the initialization for +the computer to ask the camera to switch to a higher speed. + +Each message ends with an EOT packet, which is then confirmed by an +ACK packet. + + +EOT has the following format: +xx 04 xx 00 00 00 +| | +| indication of the message length. Known values: + 00 empty message (no fragments) + 01 short message (one fragment) + ff maximum length data packet, more to follow + else data packet, at end (observed values: 0f, 7f) + +ACK has the following format: +xx 05 xx 00 00 00 +| | +| error code + 00 No error, acknowledged + 01 Not acknowledged + FF retransmit last sequence + else other values not known + + +A packet with type 06 is sent once, as the first packet coming from +the camera. It contains a length, just like a normal message fragment, +but the message structure is different. + +An empty message can be used to test if the camera is still responding. +If yes, it will respond with an ACK. Example: +PC->CAM xx 04 00 00 00 00 +CAM->PC xx 05 00 00 00 00 + + +Message fragment level +---------------------- + +Message fragments have the following structure: + +xx 00 xx xx ... +| | | | +| | | fragment data +| | data length, MSB +| data length, LSB + + +The data length is the length (in bytes) of the fragment data that +follows the length. Fragment data is simply concatenated to form the +complete message. + + +Session (message) Layer +======================= + +All messages (except the one with type 03) have the following structure: + +00 02 00 00 xx 00 00 xx xx xx 00 00 ... + | | | | | + | | | | message payload + | | | message length, MSB + | | message length, LSB + | direction code + message type + +The message length is the length of the entire message, including the +header shown above. + + + +The first four bytes of the message payload seem to depend on +the message type. The following combinations have been sighted: + + Operation + +01 12 14 f7 8a 00 Identify camera request +01 22 14 f7 8a 00 Identify camera response +01 11 6a 08 79 04 Download image request +01 11 aa 06 79 04 Download "thumbnail" request (see below) +01 21 6a 08 79 04 Image data +01 21 aa 06 79 04 "Thumbnail" data +03 12 78 f3 64 01 Get Date +04 12 08 d3 9d 00 Set date +05 12 fc d2 9d 00 Change Owner name +09 11 d8 f7 8a 00 Disk info request +09 21 d8 f7 8a 00 Disk info response +0a 11 dc f7 8a 00 Get disk(s) request +0a 21 dc f7 8a 00 Get disk(s) response +0a 12 70 f6 8a 00 Power Supply Status +0a 22 70 f6 8a 00 Power Supply Status response +0b 11 94 f6 8a 00 List without date request +0b 21 94 f6 8a 00 List without date response +0b 11 a8 f6 8a 00 List with date request +0b 21 a8 f6 8a 00 List with date response +0d 11 8c f4 7b 00 Delete image request +0d 21 8c f4 7b 00 Delete image response +0e 11 -- -- -- -- Set file attributes. + +Important note : it seems that the "fffb" part can be set to 0 in +every case, and the commands will still work. The exact meaning of +this part of the packet is unknwown. It is probably used as a unique +ID for each transaction and can be chosen at random each time. + + +Identify camera +--------------- + +The identify camera request has no data. + +The identify camera response has the following structure: +00 00 00 00 00 02 00 00 00 00 00 01 00 (more 00s) + +On the S10, the response has the following structure: +00 00 00 00 00 04 00 00 00 00 00 01 and then: + (32 bit word) (offset: 0x08) + (C string) (offset: 12 / 0x0c) + (C string) (offset: 44 / 0x2c) + + Firmware version: 04 03 02 01 is version 1.2.3.4 + 01 00 00 01 is version 1.0.0.1 + +Example (full packet): for a PowerShot S10 with firmware 1.0.0.0 + +RECV: (98 bytes) +00000000: 00 00 5C 00 02 00 00 00 01 00 00 22 5C 00 00 00 - ..\........"\... +00000010: 14 F7 8A 00 00 00 00 00 00 04 00 00 00 00 00 01 - ................ +00000020: 43 61 6E 6F 6E 20 50 6F 77 65 72 53 68 6F 74 20 - Canon PowerShot +00000030: 53 31 30 00 00 00 00 00 00 00 00 00 00 00 00 00 - S10............. +00000040: 45 64 6F 75 61 72 64 20 4C 61 66 61 72 67 75 65 - Edouard Lafargue +00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - ................ +00000060: 9C EA - .. + + +Get Power Status +---------------- + +Offsets in the payload: + + 0x04 contains a byte with power status: 0x6=good, 0x4=bad + 0x07 contains a byte with powertype: 0x10=ac-adaptor, 0x30=battery + +Example (full packet): +RECV: (30 bytes) +00000000: 00 00 18 00 02 00 00 00 0A 00 00 22 18 00 00 00 - ...........".... +00000010: 70 F6 8A 00 00 00 00 00 06 00 00 30 B5 5A - p..........0.Z + + + +Change Owner Name +---------------- + +The name (payload) can be 30 characters max. + + +Set Date +-------- + +The payload of this message is 4 bytes, it must be the same unix +format as in the directory with date request, for example the +01/01/2000 is 80 43 6D 38. + + +Get disk(s) +----------- + +The get disk(s) request has no data. + +The get disk response has the following structure: +00 00 00 00 00 + +Disk name example: "C:" + + +Disk info +--------- + +Disk info requests have the following structure: + 00 + +Disk info responses have the following structure: +00 00 00 00 xx xx xx xx xx xx xx xx + | | + | Free space (in bytes) + Total capacity (in bytes) + +Root name example: "C:\" (The trailing slash is required.) + + +List (show directory contents) +------------------------------ + +Note: It seems that directory listing as described in the USB part is +more accurate, when it comes to the meaning of the first byte ( +"date/withtout date"). + +List requests have the following structure: +xx 00 00 00 +| +00 if with date, 02 if without date + +Directory name example: "C:\PWRSHOT", "D:", or "D:\.", but not +"D:\" (trailing slash), or "D:\.\FOO" (dot not allowed in path ?) + +List responses have the following structure: +Failure: +00 00 00 00 01 00 00 00 00 00 00 00 + +Success: +00 00 00 00 xx 80 00 00 00 00 00 00 00 00 00 00 + | + 01 if last message, 00 if more + 00 + 00 00 +... + 00 00 (many 00s) + + is one byte containing the file attributes: +File attributes: + bit0 (1= write protected, 0=NOT write protected) + bit4 (1=directory contains item but not recursived entered) + (NOT used with the attrib command) + bit5 (1=NOT downloaded, 0=downloaded) + (must be manually switched) + bit7 (1=recurively entered directory) + (NOT used with the attrib command) + + + is the size in bytes. Directory size is always 0. + +Entry name example: "AUT_1201.JPG" or "MISC" + +The date is a four bytes Unix-style date. The list without date responses +also contains the four data bytes, but sets them to zero. + +Note: it's unclear if the list with/without date commands differ in any +other way than the inclusion of the date. + +If the directory is so large that additional messages are needed, they +have the following structure: +00 00 00 00 xx + | + 1 if last message, 00 if more + +The boundary between messages is always chosen such that the terminating +00 of an entry is the last byte in the earlier message. + + +Download and Data +----------------- + +Download requests have the following structure: +00 00 00 00 00 xx 00 00 00 + | + Length of name (including terminating \0) + +Data messages have the following structure: +00 00 00 00 xx xx xx xx xx xx xx xx xx xx xx xx xx 00 00 00 ... + | | | | | + | | | | data + | | | 00 if more, 01 at end + | | data size in this message + | current offset + total length + +All lengths are measured in bytes. + +The camera only sends the 10813 first bytes from the image for the thumbnail +download request. However it is not a valid thumbnail image, the first part +is the Exif header, the second part is the thumbnail itself between a FF D8 +and a FF D9, the remaining is the beginning of the picture. + + +The camera always sends 8 messages then waits for an ACK from the computer, +if the computer has not received everything, it sends an ACK with an error +value asking to retransmit one of the eight packet sent. These error values +are not yet known. + + +Switch Camera off +----------------- + +In order to switch the camera off, you need to send the following +characters (directly, without extra framing) : + + C0 00 02 55 2C C1 + C0 00 04 01 00 00 00 24 C6 C1 + + +Low Battery warning +------------------- + +If the camera batteries run too low during a transfer and the camera +needs to switch itself off, it will send a special packet just before +going down. You can see how it is handled in psa50.c + + + +=============================================== += += USB Interface += +=============================================== + +Nota: + When mentioning word, 32bit word little_endian is implied. + +References to usb11.pdf (Chaper 9.3 page 199): +http://www.usb.org/developers/data/usbspec.zip (1.8Mb) + +bmRequestType is 0xC0 during read and 0x40 during write. +bRequest is 0x4 if length of data is >1, 0x0c otherwise (length > 1 ? 0x04 : 0x0C) +wValue differs between operations. +wIndex is always 0x00 +wLength is simply the length of data + +In linux sending/reciving commands is using usb_control_msg (in usb.c). + + usb11.pdf name | usb.c name) +-------------------------------- + bmRequestType | requesttype + bRequest | request + wValue | value + wIndex | index + wLength | length + +================================================================================ +Init of camera: +================================================================================ + +1. Control_transfer_read requesttype=0xC0 value=0x55 length=1 + +Camera responds with following data (single char): +"A" = Camera was already active +"C" = Camera was woken up +"I" = Unknown (some kind of error) +"E" = Unknown (some kind of error) + +2. Control_transfer_read requesttype=0xC0 value=0x1 length=0x58 + +The first 0x48 bytes can be trashed, save the last 0x10 byte and us it as +data in next step. +Example: +00000000 18 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 01 00 02 00 43 30 A9 04-00 08 00 00 FF FF FF FF ....C0.......... +00000050 00 FD 00 00 00 FD 00 00 ........ + +3. Control_transfer_write requesttype=0x40 value=0x11 length=0x10 data=[from step 2] + +4. PC sign should now appear on the LCD + +5. Receive 0x44 bytes from bulk_in and throw it away. +Example: +00000000 04 00 00 00 02 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 00 00 00 00 .... + +================================================================================ +USB Commands +================================================================================ + +1. Structure of a command block + +Example: + +* Command block sent in general: (Example:Disk info request) + 0000000: 14 00 00 00 01 02 00 00-00 00 00 00 00 00 00 00 ................ + 0000010: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ + 0000020: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ + 0000030: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ + 0000040: 02 00 00 00 09 00 00 11-14 00 00 00 78 56 34 12 ............xV4. + 0000050: 44 3A 5C 00 D:\. + +USB arguments: + - value is always 0x10 + - length is TOTAL length (0x54 in example above) + +* Generic format of block sent: + +0000000: xx xx xx xx yy yy yy yy - 00 00 00 00 00 00 00 00 +0000010: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 +0000020: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 +0000030: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 +0000040: 02 00 00 00 UU 00 00 VV - xx xx xx xx SS SS SS SS +0000050: ... (payload/arguments) + + xx xx xx xx : Length (word) + yy yy yy yy : cmd3 (word) + UU : cmd1 (byte) + VV : cmd2 (byte) + xx xx xx xx : Length (again) + SS SS SS SS : serial number (word) + + - 'length' is the length of the block, excluding the first 0x40 bytes + in block, and is never less than 0x10. + - cmd1 and cmd2 are a single byte + - cmd3 is a word + - Serial number is a word, sent back in command reply. + +2. Summary of available (known) commands: + +cmd1 | cmd2 | cmd3 | Argument(eg.) Response Length | Operation +----------------------------------------------------------------------------------------------- +0x01 0x11 0x202 | 0x00000000 0x00001400 "D:\DCIM\100CANON\IMG_0100.JPG" 0x00 L | Get picture +0x01 0x11 0x202 | 0x00000001 0x00001400 "D:\DCIM\100CANON\IMG_0100.JPG" 0x00 L | Get thumbnail +0x01 0x12 0x201 | none 0x9c | Identify camera request +0x03 0x12 0x201 | none 0x60 | Get time +0x04 0x12 0x201 | 0x390873f0 0x00000000 0x00000000 0x54 | Set time (0x390873f0) (UNIX-type) +0x05 0x11 0x201 | "D:\DCIM" 0x00 0x54 | Make directory +0x05 0x12 0x201 | "Donald Duck" 0x00 0x54 | Change owner +0x06 0x11 0x201 | "D:\DCIM" 0x00 0x54 | Remove directory +0x09 0x11 0x201 | "D:\" 0x00 0x5c | Disk info request +0x0A 0x11 0x202 | none L | Flash device identification +0x0A 0x12 0x201 | none 0x58 | Power supply status +0x0b 0x11 0x202 | 0x1 "D:\DCIM" 0x00 0x00 0x00 L | Get directory (0x1 = max depth of recursion) +0x0d 0x11 0x201 | "D:\DCIM\100CANON" 0x00 "IMG_0002.JPG" 0x00 0x54 | Delete file +0x0E 0x11 0x201 | 0x00000021 "D:\DCIM\100CANON" 0x00 "IMG_0002.JPG" 0x00 0x54 | Set file attribute + +L means that the program reads 0x40 from bulk in, checks for a word at +position 0x6 for the length (0xd1fcf in this case), and then reads the +rest in 0x1400 buffers. (long bulk in read) + +00000000 00 00 00 00 02 03 CF 1F-0D 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ + +**** +** Disk Info Request: +**** + +* Argument structure: + + Null-terminated string containing the name of the disk. + +* Camera response block: + +Data received via bulk in after a command block: (Disk info request) +0000000: 00 00 00 00 01 03 00 00 00 00 00 00 00 00 00 00 ................ +0000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000040: 02 00 00 00 09 00 00 21 1C 00 00 00 78 56 34 12 .......!....xV4. +0000050: 00 00 00 00 00 80 E8 03 00 A0 AF 03 ............ + + First 0x40 bytes is throwable. + 0x54 contains a word with totalbytes on flash. + 0x58 contains a word with bytes free. + +**** +** Delete directory +**** +Data received via bulk in after a command block: (Delete directory) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 06 00 00 21-14 00 00 00 78 56 34 12 .......!....xV4. +00000050 00 00 00 00 .... + +**** +** Make directory +**** +Data received via bulk in after a command block: (Make directory) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 05 00 00 21-14 00 00 00 78 56 34 12 .......!....xV4. +00000050 00 00 00 00 .... + + +**** +** Get time +**** + +Data received via bulk_in after a command block: (Get time) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 03 00 00 22-20 00 00 00 78 56 34 12 ......." ...xV4. +00000050 00 00 00 00 8D 1D 12 39-00 00 00 00 00 00 00 00 .......9........ + + First 0x40 bytes is throwable. + 0x54 contains a UNIX time + +**** +** Power supply status +**** + +Data received via bulk_in after a command block: (Power supply status) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 0A 00 00 22-18 00 00 00 78 56 34 12 ......."....xV4. +00000050 00 00 00 00 06 00 00 10- ........ + + First 0x40 bytes is throwable. + 0x54 contains a byte with power status: 0x6=good, 0x4=bad + 0x57 contains a byte with powertype: 0x10=ac-adaptor, 0x30=battery + +**** +** Identify Camera request +**** + +Data received via bulk_in after a command block: (Identify camera request) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 01 00 00 22-5C 00 00 00 78 56 34 12 ......."\...xV4. +00000050 00 00 00 00 00 04 00 00-01 00 00 01 43 61 6E 6F ............Cano +00000060 6E 20 50 6F 77 65 72 53-68 6F 74 20 53 32 30 00 n PowerShot S20. +00000070 00 00 00 00 00 00 00 00-00 00 00 00 44 6F 6E 61 ............Dona +00000080 6C 64 20 44 75 63 6B 00-00 00 00 00 00 00 00 00 ld Duck......... +00000090 00 00 00 00 00 00 00 00-00 00 00 00 ............ + + First 0x40 bytes is throwable (as usual) + At 0x5c a string with camera type exist + At 0x7c a string with owner name exist. + 0x58-0x5b is firmware version (04 03 02 01 is version 1.2.3.4; 01 00 00 01 is version 1.0.0.1) + Data at 0x54-0x57 has unknown purpose. + +**** +** Flash device identification +**** + +Data received via a long_bulk_in_read: (Flash device identification) +00000000 44 3A 00 00 D:.. + +**** +** Set File Attribute +**** + +Data received via bulk_in after a command block: (Set file attribute) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 0E 00 00 21-14 00 00 00 78 56 34 12 .......!....xV4. +00000050 00 00 00 00 .... + +Data received via bulk_in after a command block: (Set file attribute) (file did not exist). +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 0E 00 00 21-14 00 00 00 78 56 34 12 .......!....xV4. +00000050 22 00 00 02 "... + + +File attributes: + bit0 (1= write protected, 0=NOT write protected) + bit4 (1=directory contains item but not recursived entered) + (NOT used with the attrib command) + bit5 (1=NOT downloaded, 0=downloaded) + (must be manually switched) + bit7 (1=recurively entered directory) + (NOT used with the attrib command) + +Example: 0x21 file is NOT downloaded but deleteprotected + + +**** +** Delete file +**** + +Data received via bulk_in after a command block: (Delete file) (file did not exist). +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 0D 00 00 21-14 00 00 00 78 56 34 12 .......!....xV4. +00000050 22 00 00 02 "... + +Data received via bulk_in after a command block: (Delete file) (file was protected) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 0D 00 00 21-14 00 00 00 78 56 34 12 .......!....xV4. +00000050 29 00 00 02 )... + +Data received via bulk_in after a command block: (Delete file) (successful) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 0D 00 00 21-14 00 00 00 78 56 34 12 .......!....xV4. +00000050 00 00 00 00 .... + + +**** +** Change Owner +**** + +Data received via bulk_in after a command block: (Change owner) (no errorcodes) +00000000 00 00 00 00 01 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 05 00 00 22-14 00 00 00 78 56 34 12 ......."....xV4. +00000050 00 00 00 00 .... + +**** +** Directory Listing +**** + +Errorcodes: +0x02000022 File not found +0x00000000 No errors +0x02000086 Path not found +0x02000029 File was protected + +File attributes: +bit1 (1=deleteprotected, 0=NOT deleteprotected) +bit4 (1=directory contains item but not recursived entered) (NOT used with the attrib command) +bit5 (1=NOT downloaded, 0=downloaded) (must be manually switched) +bit8 (1=recurively entered directory) (NOT used with the attrib command) + +Example: 0x21 file is NOT downloaded but deleteprotected + +Directory handling: +Thu May 4 00:11:40 2000 D:\DCIM\100CANON\IMG_0001.JPG 778435 +Thu May 4 00:28:32 2000 D:\DCIM\100CANON\IMG_0002.JPG 44409 +Thu May 4 00:28:32 2000 D:\DCIM\CANONMSC\100.CTG 2634 +Thu May 4 00:28:32 2000 D:\DCIM\CANONMSC\D.CTG 383 + +Directory contents: "D:" (recurse =0x0) +00000000 80 00 00 00 00 00 00 00-00 00 44 3A 00 10 00 00 ..........D:.... +00000010 00 00 00 C6 B5 10 39 44-43 49 4D 00 00 00 00 00 ......9DCIM..... +00000020 00 00 00 00 00 00 00 ....... + +Directory contents: "D:" (recurse =0x1) +00000000 80 00 00 00 00 00 00 00-00 00 44 3A 00 80 00 00 ..........D:.... +00000010 00 00 00 36 C0 10 39 2E-5C 44 43 49 4D 00 10 00 ...6..9.\DCIM... +00000020 00 00 00 00 36 C0 10 39-31 30 30 43 41 4E 4F 4E ....6..9100CANON +00000030 00 10 00 00 00 00 00 CC-B5 10 39 43 41 4E 4F 4E ..........9CANON +00000040 4D 53 43 00 80 00 00 00-00 00 00 00 00 00 2E 2E MSC............. +00000050 00 00 00 00 00 00 00 00-00 00 00 00 ............ + +Directory contents: "D:" (recurse =0x2) +00000000 80 00 00 00 00 00 00 00-00 00 44 3A 00 80 00 00 ..........D:.... +00000010 00 00 00 36 C0 10 39 2E-5C 44 43 49 4D 00 80 00 ...6..9.\DCIM... +00000020 00 00 00 00 3C C0 10 39-2E 5C 31 30 30 43 41 4E ....<..9.\100CAN +00000030 4F 4E 00 20 00 C3 E0 0B-00 3C C0 10 39 49 4D 47 ON. .....<..9IMG +00000040 5F 30 30 30 31 2E 4A 50-47 00 20 00 79 AD 00 00 _0001.JPG. .y... +00000050 30 C4 10 39 49 4D 47 5F-30 30 30 32 2E 4A 50 47 0..9IMG_0002.JPG +00000060 00 80 00 00 00 00 00 00-00 00 00 2E 2E 00 80 00 ................ +00000070 00 00 00 00 30 C4 10 39-2E 5C 43 41 4E 4F 4E 4D ....0..9.\CANONM +00000080 53 43 00 20 00 4A 0A 00-00 30 C4 10 39 31 30 30 SC. .J...0..9100 +00000090 2E 43 54 47 00 20 00 7F-01 00 00 30 C4 10 39 44 .CTG. ....0..9D +000000A0 2E 43 54 47 00 80 00 00-00 00 00 00 00 00 00 2E .CTG............ +000000B0 2E 00 80 00 00 00 00 00-00 00 00 00 2E 2E 00 00 ................ +000000C0 00 00 00 00 00 00 00 00-00 00 .......... + +Directory contents: +attribute 0x00 size date "name" 0x00 +attribute is a byte describe little earlier in this document + (0 in attribute, date, length and name means end of direntry, ".." in name means "leave directory". +size is a word (filesize in byte) +time is a word (UNIX time) + + +**** +** Upload (a little bit special): +**** + +Control_transfer_write + requesttype=0x40 + value=0x10 + length=0x40 + data=0x00000000 0x0203 0x40+len1[explained later] [0x00 repeated 0x38] + +Example: +00000000 00 00 00 00 03 02 7A 14-00 00 00 00 00 00 00 00 ......z......... +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ + +bulk_in_read [0x40 bytes] +Example: +00000000 00 00 00 00 03 03 00 00-00 00 00 00 00 00 00 00 ................ +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ + +bulk_write [data below] + +len1[explained later] 0x00 0x00 0x00000403 0x00000000 0x00000000 +[0x00 repeated 0x30 times] +0x00000002 0x03 0x00 0x00 0x11 len1 0x00 0x00 serial (this line looks very similar to "ordinary" commands) +0x00000002 offs len2 filename 0x00 datablock + +bulk_in_read [0x5c bytes] + +This is repeated until the whole file is transmitted: + +- offs is a word that starts at 0 and increments with blocksize each time. + +- len1 is the length of the "bulk_write_data" block above, minus 0x40 (the + first length and padded zeros is not counted as in all other commands). + len1 is typically 0x143A using a standard 0x1400 (ms-windows) block + using the filename below (29 chars), last block is shorter. + +- len2 is length of datablock (0x1400 is used in ms-windows), last + block is shorter serial is a random word that is returned as a reply. + +- filname is "D:\DCIM\100CANON\IMG_0002.JPG" for example (file cannot + be created in nonexisting directory.) + +- datablock is the datablock itself (the fragment of the JPG file). + +Example of beginning of a block (first one): +00000000 3A 14 00 00 03 04 00 00-00 00 00 00 00 00 00 00 :............... +00000010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ +00000040 02 00 00 00 03 00 00 11-3A 14 00 00 78 56 34 12 ........:...xV4. +00000050 02 00 00 00 00 00 00 00-00 14 00 00 44 3A 5C 44 ............D:\D +00000060 43 49 4D 5C 31 30 30 43-41 4E 4F 4E 5C 49 4D 47 CIM\100CANON\IMG +00000070 5F 30 30 30 32 2E 4A 50-47 00 FF D8 FF E1 17 FE _0002.JPG....... +00000080 45 78 69 66 00 00 49 49-2A 00 08 00 00 00 09 00 Exif..II*....... +00000090 0F 01 02 00 06 00 00 00-7A 00 00 00 10 01 02 00 ........z....... diff --git a/camlibs/canon/README b/camlibs/canon/README new file mode 100644 index 000000000..7259709a8 --- /dev/null +++ b/camlibs/canon/README @@ -0,0 +1,114 @@ +This driver is for the Canon PowerShot series. It works with the +following models: + + - Powershot A5 + - Powershot A5 Zoom + - Powershot A50 + - Powershot S10 + - Powershot S20 + + It doesn't work with the PowerShot 350. However, the PS350 uses a +vaguely similar protocol, so some parts of the sources can probably be +shared. + +The driver caches a lot of information. If the camera status changes +during a session or if the driver gets stuck for some other reason, +the caches can be manually flushed using "Configure camera". + + +Change history +============== + +Version 6 (19-MAY-2000) +--------- + +- Included USB support in the driver +- More options in the configuration file +- Debug output can be mostly disabled +- The driver now sets the "downloaded" bit on downloaded images + +Version 5 (09-MAY-2000) +--------- + +- Support for full-speed transfers (115200) +- Most protocol commands are implemented, or at least discovered (see + the 'Protocol' file) +- USB protocol description +- Get/Set owner name +- Get date +- Get firmware rev. +- Get battery status +- Use libgpio for serial transfers +- More reliable error recovery +- Better configuration dialog +- Support for all current powershot models (A5 to S20) +- Low battery condition detection + + +Version 4 (3-SEP-1999) +--------- + + - changed uint16_t to unsigned short and removed inclusion of stdint.h, for + compatibility :-( + + +Version 3 (1-SEP-1999) +--------- + + - lowered number of tries when initializing from 50 to 10 (50 was for + experiments) + - increased camera ID buffer to be large enough for PS350 responses + - serial input is now flushed before testing or attempting synchronization + - directories are now sorted alphabetically, implicitly ordering images by + date + - fixed a few memory leaks in directory handling + - added arbitrary file download to Configure/Configure Camera (experimental; + very fragile) + + +Version 2 (29-AUG-1999) +--------- + + - integrated into gphoto-2.3.5 (from CVS) + - added support for large directories (listing occupies > 1 message) + - receive timeout is now raised from 1 to 10 seconds after first response + - renamed a50_select_disk to a50_disk_info. It now returns disk capacity + and available space. + - completed CRC table + - properly integrated into gPhoto + - lots of cleanups + + +Version 1 (27-AUG-1999) +--------- + + - a little bit of code cleanup, added a50.h, doc/, full recursive download + in canon.c, and fixed a few documentation bugs, adjusted send/receive + buffers + - a50_send_msg incremented seq_tx when skipping retransissions while waiting + for ACK + + +Version 0 (27-AUG-1999) +--------- + + - initial release which demonstrates most functions in a way that's + completely useless for gPhoto + + +To do +===== + +- code structure is still pretty ugly. Things that absolutely need fixing: + - command codes and fffbs are spread all over the place + - "ping" (empty message) should probably be merged into normal message + handling; perhaps also 03 message -> wait_for_ack can be merged too + - psa50.c must not invoke GUI functions + - change many fprintf(stderr,... to GUI calls or callbacks +- improve error handling: distinguish between severe and harmless errors + (e.g. duplicate EOT vs. ten timeouts in a row) +- find out how error recovery works (need traces) +- get traces for other operations: + - idle period/restart (keepalive ?) + - upload file, create directory +- find out how to avoid blocking gPhoto during transfer diff --git a/camlibs/canon/canon.c b/camlibs/canon/canon.c new file mode 100644 index 000000000..9c9935dc5 --- /dev/null +++ b/camlibs/canon/canon.c @@ -0,0 +1,1408 @@ +/**************************************************************************** + * + * canon.c + * + * Canon Camera library for the gphoto project, + * (c) 1999 Wolfgang G. Reissnegger + * Developed for the Canon PowerShot A50 + * Additions for PowerShot A5 by Ole W. Saastad + * (c) 2000 : Other additions by Edouard Lafargue, Philippe Marzouk. + * + ****************************************************************************/ + + +/**************************************************************************** + * + * include files + * + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "util.h" +#include "serial.h" +#include "psa50.h" +#include "canon.h" + +/* + * Directory access may be rather expensive, so we cache some information. + * The first variable in each block indicates whether the block is valid. + */ + +static int cached_ready = 0; + +static int cached_disk = 0; +static char cached_drive[10]; /* usually something like C: */ +static int cached_capacity,cached_available; + +static int cached_dir = 0; +static struct psa50_dir *cached_tree; +static int cached_images; + +static char **cached_paths; /* only used by A5 */ + +/* Global variable to set debug level. */ +/* Defined levels so far : */ +/* 0 : no debug output */ +/* 1 : debug actions */ +/* 9 : debug everything, including hex dumps of the packets */ + +int canon_debug_driver = 0; +int gphoto2_debug = 0; + +/* DO NOT FORGET to update the NUM_ constants after adding a camera */ + +#define NUM_SERIAL 4 +#define NUM_USB 2 +#define NUM_SERIAL_USB 2 + +char *models_serial[] = { + "Canon PowerShot A5", + "Canon PowerShot A5 Zoom", + "Canon PowerShot A50", + "Canon PowerShot Pro70", + NULL +}; +char *models_USB[] = { + "Canon PowerShot IXUS", + "Canon PowerShot S100", + NULL +}; +char *models_serialandUSB[] = { + "Canon PowerShot S10", + "Canon PowerShot S20", + NULL +}; + +int camera_id(char *id) +{ + strcpy(id, "canon"); + + return GP_OK; +} + +int camera_manual(CameraText *manual) +{ + strcpy(manual->text, "Manual Not Available"); + + return GP_OK; +} + +int camera_abilities(CameraAbilities *abilities, int *count) +{ + int x=0; + int i; + CameraAbilities a; + + strcpy(a.model, ""); + a.serial = 1; + a.parallel = 0; + a.usb = 1; + a.ieee1394 = 0; + a.speed[0] = 9600; + a.speed[1] = 19200; + a.speed[2] = 38400; + a.speed[3] = 57600; + a.speed[4] = 115200; + a.speed[5] = 0; + a.capture = 0; + a.config = 0; + a.file_delete = 1; + a.file_preview = 1; + a.file_put = 0; + + i=0; + while (iname; walk++) + if (walk->size && is_image(walk->name)) count++; + cached_paths = realloc(cached_paths,sizeof(char *)*(cached_images+count+1)); + memset(cached_paths+cached_images+1,0,sizeof(char *)*count); + if (!cached_paths) { + perror("realloc"); + return 0; + } + curr = cached_images; + cached_images += count; + for (walk = dir; walk->name; walk++) { + sprintf(buffer,"%s\\%s",name,walk->name); + if (!walk->size) { + if (!recurse(buffer)) return 0; + } + else { + if (!is_image(walk->name)) continue; + curr++; + cached_paths[curr] = strdup(buffer); + if (!cached_paths[curr]) { + perror("strdup"); + return 0; + } + } + } + free(dir); + return 1; +} + + +static int comp_dir(const void *a,const void *b) +{ + return strcmp(((const struct psa50_dir *) a)->name, + ((const struct psa50_dir *) b)->name); +} + + +/* This function is only used by A50 */ + +static struct psa50_dir *dir_tree(const char *path) +{ + struct psa50_dir *dir,*walk; + char buffer[300]; /* longest path, etc. */ + + dir = psa50_list_directory(path); + if (!dir) return NULL; /* assume it's empty @@@ */ + for (walk = dir; walk->name; walk++) { + if (walk->is_file) { + if (is_image(walk->name)) cached_images++; + } + else { + sprintf(buffer,"%s\\%s",path,walk->name); + walk->user = dir_tree(buffer); + } + } + qsort(dir,walk-dir,sizeof(*dir),comp_dir); + return dir; +} + + +static void clear_dir_cache(void) +{ + psa50_free_dir(cached_tree); +} + + +/* A5 only: sort THB_ and AUT_ into their proper arrangement. */ +static int compare_a5_paths (const void * p1, const void * p2) +{ + const char * s1 = *((const char **)p1); + const char * s2 = *((const char **)p2); + const char * ptr, * base1, * base2; + int n1 = 0, n2 = 0; + + printf("Comparing %s to %s\n", s1, s2); + + ptr = strrchr(s1, '_'); + if (ptr) + n1 = strtol(ptr+1, 0, 10); + ptr = strrchr(s2, '_'); + if (ptr) + n2 = strtol(ptr+1, 0, 10); + + printf("Numbers are %d and %d\n", n1, n2); + + if (n1 < n2) + return -1; + else if (n1 > n2) + return 1; + else { + base1 = strrchr(s1, '\\'); + base2 = strrchr(s2, '\\'); + printf("Base 1 is %s and base 2 is %s\n", base1, base2); + return strcmp(base1, base2); + } +} + + +static int update_dir_cache(void) +{ + int i; + if (cached_dir) return 1; + if (!update_disk_cache()) return 0; + if (!check_readiness()) return 0; + cached_images = 0; + switch (camera.model) { + case CANON_PS_A5: + case CANON_PS_A5_ZOOM: + if (recurse(cached_drive)) { + printf("Before sort:\n"); + for (i = 1; i < cached_images; i++) { + printf("%d: %s\n", i, cached_paths[i]); + } + qsort(cached_paths+1, cached_images, sizeof(char *), compare_a5_paths); + printf("After sort:\n"); + for (i = 1; i < cached_images; i++) { + printf("%d: %s\n", i, cached_paths[i]); + } + cached_dir = 1; + return 1; + } + clear_dir_cache(); + return 0; + break; + + default: /* A50 or S10 or other */ + cached_tree = dir_tree(cached_drive); + if (!cached_tree) return 0; + cached_dir = 1; + return 1; + break; + } +} + +/** + * setPathName was borrowed from the konica driver + */ +static void setPathName(char *fname) +{ + char *sp; + int flen; + sp = getenv("HOME"); + if (!sp) + sp = "."; + strcpy(fname, sp); + flen = strlen(fname); + while (fname[flen-1] == '/') + { + fname[flen-1] = '\0'; + flen--; + } + if (!strstr(fname, "/.gphoto")) + strcat(fname, "/.gphoto"); +} +/** + * setFileName was borrowed from the Konica driver + */ +static void setFileName(char *fname) +{ + setPathName(fname); + strcat(fname, "/powershotrc"); +} + + + +/**************************************************************************** + * + * gphoto library interface calls + * + ****************************************************************************/ + + +static int _entry_path(const struct psa50_dir *tree, + const struct psa50_dir *entry,char *path) +{ + path = strchr(path,0); + while (tree->name) { + *path = '\\'; + strcpy(path+1,tree->name); + if (tree == entry) return 1; + if (!tree->is_file && tree->user) + if (_entry_path(tree->user,entry,path)) return 1; + tree++; + } + return 0; +} + + +static char *entry_path(const struct psa50_dir *tree, + const struct psa50_dir *entry) +{ + static char path[300]; + + strcpy(path,cached_drive); + (void) _entry_path(cached_tree,entry,path); + return path; +} + + +static void cb_select(GtkItem *item,struct psa50_dir *entry) +{ + char *path; + unsigned char *file; + int length,size; + int fd; + + if (!entry || !entry->is_file) { + gtk_item_deselect(item); + return; + } + path = entry_path(cached_tree,entry); + gp_interface_status(path); + file = psa50_get_file(path,&length); + if (!file) return; + fd = creat(entry->name,0644); + if (fd < 0) { + perror("creat"); + free(file); + return; + } + size = write(fd,file,length); + if (size < 0) perror("write"); + else if (size < length) debug_message("short write: %d/%d\n",size,length); + if (close(fd) < 0) perror("close"); + free(file); + gp_interface_status("File saved"); +} + +static int get_all(struct psa50_dir *entry) { + + if ( entry->is_file) { + cb_select(NULL, entry); + return 1; + } + entry = entry->user; + if (!entry) return 1; + for (; entry->name; entry++) + if (!get_all(entry)) return 0; + return 1; + +} + +static void cb_get_all(GtkItem *item) { + + get_all(cached_tree); + +} + + +static int populate(struct psa50_dir *entry,GtkWidget *branch) +{ + GtkWidget *item,*subtree; + + item = gtk_tree_item_new_with_label(entry ? (char *) entry->name : + cached_drive); + if (!item) return 0; + gtk_tree_append(GTK_TREE(branch),item); + gtk_widget_show(item); + gtk_signal_connect(GTK_OBJECT(item),"select",GTK_SIGNAL_FUNC(cb_select), + entry); + if (entry && entry->is_file) { + entry->user = item; + return 1; + } + entry = entry ? entry->user : cached_tree; + if (!entry) return 1; + subtree = gtk_tree_new(); + if (!subtree) return 0; + gtk_tree_item_set_subtree(GTK_TREE_ITEM(item),subtree); + gtk_tree_item_expand(GTK_TREE_ITEM(item)); + for (; entry->name; entry++) + if (!populate(entry,subtree)) return 0; + return 1; +} + + +static void cb_clear(GtkWidget *widget,GtkWidget *window) +{ + // gtk_widget_destroy(window); + + cached_ready = 0; + cached_disk = 0; + if (cached_dir) clear_dir_cache(); + cached_dir = 0; +} + + +/** + * Save current driver setup into a settings file (~/.gphoto/powershotrc) + */ +void save_rcfile(void) { + char fname[128]; + FILE *fd; + + setFileName(fname); + fd = fopen(fname, "w"); + if (!fd) { + char cmd[140]; + setPathName(fname); + sprintf(cmd, "mkdir %s", fname); + system(cmd); + setFileName(fname); + fd = fopen(fname, "w"); + } + if (fd) { + struct tm *tp; + time_t mytime; + char *speed; + mytime = time(NULL); + tp = localtime(&mytime); + fprintf(fd, "# Canon Powershot configuration - saved on %4.4d/%2.2d/%2.2d at %2.2d:%2.2d\n\n", + tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday, + tp->tm_hour, tp->tm_min); + switch (camera.speed) { + case 19200: + speed = "19200"; break; + case 38400: + speed = "38400"; break; + case 57600: + speed = "57600"; break; + case 115200: + speed = "115200"; break; + default: + speed = "9600"; + } + fprintf(fd, "# Serial port speed\n"); + fprintf(fd, "%-12.12s %s\n", "Speed", speed); + fprintf(fd, "\n\n# Debug level:\n" + "# 0: no debug at all\n" + "# 1: debug functions\n" + "# 9: debug everything, including hex. dumps of packets\n\n"); + fprintf(fd, "%-12.12s %i\n", "Debug", canon_debug_driver); + + fclose(fd); + gp_interface_status("Saved configuration"); + } else + debug_message("Unable to open/create %s - configuration not saved\n", + fname); +} + +/** + * Configuration dialog for Canon cameras. + * + * This dialog tries to get information from the camera, but in case + * the camera does not answer, it should show anyway. + * + * Main settings available there: + * + * - Compact Flash card contents with download + * - Speed select + * - Date get/set + * - Owner name get/set + * - AC status (battery/AC) + * - Firmware revision + */ + +static int canon_configure(void) +{ + + // GtkWidget *window,*box,*scrolled_win,*tree,*clear,*done; + GtkWidget *dialog, *hbox, *vbox, *label, *tree, *vseparator; + GtkWidget *file_list, *button, *cbutton, *clear,*set_button; + GtkWidget *combo, *swoff, *sync, *linkCombo; + GtkWidget *owner_entry, *ga; + GList *list; + + char cam_model[80]; + char cam_date[34]; + char firmwrev[48]; + char power_stats[48]; + struct tm *camtm; + time_t camtime; + char *csp; + int pwr_status, pwr_source; + + + + // First create the dialog window, with title, position and size: + dialog = gtk_dialog_new(); + gtk_window_set_title(GTK_WINDOW(dialog), "Camera Setup"); + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); + gtk_container_border_width(GTK_CONTAINER(dialog), 5); + gtk_widget_set_usize(dialog, 500, 350); + + + /* Box going across the dialog... */ + hbox = gtk_hbox_new(FALSE, 5); + gtk_widget_show(hbox); + gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), + hbox); + + /* Vertical box holding the file browser */ + vbox = gtk_vbox_new(FALSE, 0); + gtk_widget_show(vbox); + gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox); + + label = gtk_label_new("CF card file browser:"); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + file_list = gtk_scrolled_window_new(NULL,NULL); + if (!file_list) { + gtk_widget_destroy(dialog); + return 0; + } + gtk_container_border_width(GTK_CONTAINER(file_list), 5); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(file_list), + GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); + gtk_widget_set_usize(file_list,200,400); + gtk_widget_show(file_list); + gtk_box_pack_start(GTK_BOX(vbox),file_list,TRUE,TRUE,FALSE); + + + clear = gtk_button_new_with_label("Clear list"); + if (!clear) { + gtk_widget_destroy(dialog); + return 0; + } + + gtk_signal_connect(GTK_OBJECT(clear),"clicked",GTK_SIGNAL_FUNC(cb_clear), + dialog); + gtk_widget_show(clear); + gtk_box_pack_start(GTK_BOX(vbox),clear,FALSE,FALSE,5); + + ga = gtk_button_new_with_label("Get All"); + if (!ga) { + gtk_widget_destroy(dialog); + return 0; + } + + gtk_signal_connect(GTK_OBJECT(ga),"clicked",GTK_SIGNAL_FUNC(cb_get_all), + dialog); + gtk_widget_show(ga); + gtk_box_pack_start(GTK_BOX(vbox),ga,FALSE,FALSE,5); + + /* Create the tree object that will hold the directory + * contents, and fill it. + */ + tree = gtk_tree_new(); + if (!tree) { + gtk_widget_destroy(dialog); + return 0; + } + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(file_list), + tree); + gtk_widget_show(tree); + populate(NULL,tree); + + + /* The the second half of the dialog: camera model, date and time, + * etc... + */ + vseparator = gtk_vseparator_new(); + gtk_widget_show(vseparator); + gtk_box_pack_start(GTK_BOX(hbox), vseparator, FALSE, FALSE, 2); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_widget_show(vbox); + gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 2); + + /* Get the camera model string. This will initiate serial traffic + * if the user did not get the index before. */ + strcpy(cam_model,"Camera model: "); + strncat(cam_model, camera_model_string(),60); + label = gtk_label_new(cam_model); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + /** + * Get the owner name, and put it in a text field. + */ + hbox = gtk_hbox_new(FALSE, 2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); + label = gtk_label_new("Owner name: "); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + owner_entry = gtk_entry_new_with_max_length(30); + gtk_entry_set_text(GTK_ENTRY(owner_entry),camera.owner); + gtk_box_pack_start(GTK_BOX(hbox), owner_entry, FALSE, FALSE, 0); + gtk_widget_show(owner_entry); + + set_button = gtk_button_new_with_label("Set"); + gtk_box_pack_start(GTK_BOX(hbox), set_button, FALSE, FALSE, 1); + gtk_widget_show(set_button); + gtk_signal_connect(GTK_OBJECT(set_button),"clicked",GTK_SIGNAL_FUNC(canon_set_owner), + owner_entry); + gtk_widget_show(label); + + label = gtk_label_new(" "); + // gtk_misc_set_alignment (GTK_MISC (label), 0, 0); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1); + + if (cached_ready) { + strcpy(cam_date,"Date: "); + camtime = psa50_get_time(); + camtm = gmtime(&camtime); + strncat(cam_date, asctime(camtm),26); + } + else + strcpy(cam_date,"Date: camera unavailable"); + label = gtk_label_new(cam_date); + + gtk_misc_set_alignment (GTK_MISC (label), 0, 0); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1); + + sprintf(firmwrev,"Firmware revision: %i.%i.%i.%i", + camera.firmwrev[3],camera.firmwrev[2], + camera.firmwrev[1],camera.firmwrev[0] ); + label = gtk_label_new(firmwrev); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1); + + + if (cached_ready) { + strcpy(power_stats,"Power: "); + canon_get_batt_status(&pwr_status,&pwr_source); + switch (pwr_source) { + case CAMERA_ON_AC: + strcat(power_stats, "AC adapter "); + break; + case CAMERA_ON_BATTERY: + strcat(power_stats, "on battery "); + break; + default: + sprintf(power_stats,"Power: unknown (%i",pwr_source); + break; + } + switch (pwr_status) { + char cde[16]; + case CAMERA_POWER_OK: + strcat(power_stats, "(power OK)"); + break; + case CAMERA_POWER_BAD: + strcat(power_stats, "(power low)"); + break; + default: + sprintf(cde," - %i)",pwr_status); + strcat(power_stats,cde); + break; + } + } + else + strcpy(power_stats,"Power: camera unavailable"); + label = gtk_label_new(power_stats); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1); + + label = gtk_label_new(" "); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1); + + /** + * Then, speed settings. We need to save these to a file... + */ + + /* Make a small horizontal box for speed selection: */ + hbox = gtk_hbox_new(FALSE, 2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5); + + label = gtk_label_new("Speed: "); + gtk_widget_show(label); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2); + + list = NULL; + combo = gtk_combo_new(); + gtk_widget_show(combo); + gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 1); + + list = g_list_append(list, "9600"); + list = g_list_append(list, "19200"); + list = g_list_append(list, "38400"); + list = g_list_append(list, "57600"); + list = g_list_append(list, "115200"); + + gtk_combo_set_popdown_strings(GTK_COMBO(combo), list); + switch (camera.speed) { + case 9600: csp = "9600"; break; + case 19200: csp = "19200"; break; + case 38400: csp = "38400"; break; + case 57600: csp = "57600"; break; + case 115200: csp = "115200"; break; + default: csp = "Choose speed"; + } + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), + csp); + gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(combo)->entry),FALSE); + + + // SYNCH TIME Button + + sync = gtk_button_new_with_label("Synchronize Camera Time"); + gtk_widget_show(sync); + gtk_box_pack_start(GTK_BOX(vbox), sync, FALSE, FALSE, 5); + gtk_signal_connect(GTK_OBJECT(sync),"clicked",GTK_SIGNAL_FUNC(psa50_sync_time), + dialog); + + + /* Add a last button to switch off the camera if we want: */ + swoff = gtk_button_new_with_label("Switch Camera Off"); + gtk_widget_show(swoff); + gtk_box_pack_start(GTK_BOX(vbox), swoff, FALSE, FALSE, 5); + gtk_signal_connect(GTK_OBJECT(swoff),"clicked",GTK_SIGNAL_FUNC(switch_camera_off), + dialog); + + /* Buttons at the bottom of the dialog: OK/Save and Cancel */ + + button = gtk_button_new_with_label("Save"); + gtk_widget_show(button); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), + button, TRUE, TRUE, 0); + + cbutton = gtk_button_new_with_label("Cancel"); + gtk_widget_show(cbutton); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), + cbutton, TRUE, TRUE, 0); + + if (wait_for_hide(dialog, button, cbutton) == 0) + return 1; + + /* If we're there, it's because the user pressed "OK". We should + * save the settings now... + */ + csp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); + if (strncmp(csp, "115200", 6) == 0) + camera.speed = 115200; + else if (strncmp(csp, "57600", 5) == 0) + camera.speed = 57600; + else if (strncmp(csp, "38400", 5) == 0) + camera.speed = 38400; + else if (strncmp(csp, "19200", 5) == 0) + camera.speed = 19200; + else + camera.speed = 9600; + + save_rcfile(); + + return 1; + +} + +/****************************************************************************/ + +static int _pick_nth(struct psa50_dir *tree, int n, char *path, char *attr) { + + int i=0; + + if (tree == NULL) + return 0; + + path = strchr(path, 0); + *path = '\\'; + + while (iname) { + strcpy(path+1, tree->name); + if (is_image(tree->name)) { + *attr = tree->attrs; + i++; + } else if (!tree->is_file) + i += _pick_nth(tree->user, n-i, path, attr); + tree++; + } + return i; +} + + +static void pick_nth(int n,char *path, char *attr) +{ + (void) _pick_nth(cached_tree,n,path,attr); +} + + +#define JPEG_END 0xFFFFFFD9 +#define JPEG_ESC 0xFFFFFFFF + +static char *canon_get_picture(int picture_number, int thumbnail, int *size) +{ + char *image; + char path[300]; + char attribs; + char file[300], dir[300]; + int size2,j; + void *ptr; + + + if (!check_readiness()) { + return NULL; + } + + switch (camera.model) { + case CANON_PS_A5: + case CANON_PS_A5_ZOOM: + + picture_number=picture_number*2-1; + if (thumbnail) picture_number+=1; + debug_message("Picture number %d\n",picture_number); + + image = malloc(sizeof(*image)); + if (!image) { + perror("malloc"); + return NULL; + } + memset(image,0,sizeof(*image)); + if (!picture_number || picture_number > cached_images) { + gp_interface_status("Invalid index"); + free(image); + return NULL; + } + gp_interface_status(cached_paths[picture_number]); + if (!check_readiness()) { + free(image); + return NULL; + } + image = psa50_get_file(cached_paths[picture_number], size); + if (image) return image; + free(image); + return NULL; + break; + default: + /* For A50 or others */ + /* clear_readiness(); */ + if (!update_dir_cache()) { + gp_interface_status("Could not obtain directory listing"); + return 0; + } + image = malloc(sizeof(*image)); + if (!image) { + perror("malloc"); + return NULL; + } + memset(image,0,sizeof(*image)); + if (!picture_number || picture_number > cached_images) { + gp_interface_status("Invalid index"); + free(image); +/* if (command_line_mode==1) + psa50_end(); */ + return NULL; + } + strcpy(path,cached_drive); + attribs = 0; + pick_nth(picture_number,path,&attribs); + gp_interface_status(path); + if (!check_readiness()) { + free(image); + return NULL; + } + if (thumbnail) { + ptr=image; + if ( (image = psa50_get_thumbnail(path,size)) == NULL) { +/* if (command_line_mode == 1) + psa50_end(); */ + free(ptr); + return NULL; + } + /* we count the byte returned until the end of the jpeg data + which is FF D9 */ + + /* 24/07/2000 (pm) I've commented out following code + do we really need that now that we use exif to parse data ? + */ + +/* for(size2=1;size2data = data; + strcpy(file->type, "image/jpeg"); + file->size = buflen; + + pick_nth(index,path,&attribs); + j = strrchr(path, '\\') - path; + + i=0; + while(path[j+1] != '\0') { + filename[i] = tolower(path[j+1]); + i++; + j++; + } + filename[i]='\0'; + + snprintf(file->name, sizeof(file->name), "%s", + filename); + + return GP_OK; +} +int camera_file_get_preview(int index, CameraFile *preview) +{ + char *data; + int buflen,j,i; + char attribs=0; + char path[300], filename[300]; + + index++; + data = canon_get_picture(index, 1, &buflen); + if (!data) + return GP_ERROR; + + preview->data = data; + strcpy(preview->type, "image/jpeg"); + preview->size = buflen; + + pick_nth(index,path,&attribs); + j = strrchr(path, '\\') - path; + + i=0; + while(path[j+1] != '\0') { + filename[i] = tolower(path[j+1]); + i++; + j++; + } + filename[i]='\0'; + + snprintf(preview->name, sizeof(preview->name), "%s", + filename); + + return GP_OK; +} +/****************************************************************************/ + + +int camera_file_count(void) +{ + /* clear_readiness(); */ + if (!update_dir_cache()) { + gp_interface_status("Could not obtain directory listing"); + return 0; + } + switch (camera.model) { + case CANON_PS_A5: + case CANON_PS_A5_ZOOM: + return cached_images/2; /* Odd is pictures even is thumbs */ + default: +/* if (command_line_mode==1) + psa50_end(); */ + return cached_images; + } +}; + +/** + * This routine initializes the serial port and also load the + * camera settings. Right now it is only the speed that is + * saved. + */ +int camera_init(CameraInit *init) +{ + char fname[1024]; + FILE *conf; + + gphoto2_debug = init->debug; + fprintf(stderr,"canon_initialize()\n"); + /* Default speed */ + camera.speed = 9600; + + setFileName(fname); + if ((conf = fopen(fname, "r"))) { + char buf[256]; + char *sp, *vp; + while ((sp = fgets(buf, sizeof(buf)-1, conf)) != NULL) + { + if (*sp == '#' || *sp == '*') + continue; + sp = strtok(buf, " \t\r\n"); + if (!sp) + continue; /* skip blank lines */ + vp = strtok(NULL, " \t\r\n"); + if (!vp) + { + printf("No value for %s - ignored\n", sp); + continue; + } + if (strcasecmp(sp, "Speed") == 0) { + if (strncmp(vp, "115200", 6) == 0) + camera.speed = 115200; + else if (strncmp(vp, "57600", 5) == 0) + camera.speed = 57600; + else if (strncmp(vp, "38400", 5) == 0) + camera.speed = 38400; + else if (strncmp(vp, "19200", 5) == 0) + camera.speed = 19200; + else if (strncmp(vp, "9600", 5) == 0) + camera.speed = 9600; + } + + /* This is just an option in the file, that's why we initialize + the variable before */ + if (strcasecmp(sp, "Debug") == 0) { + if (strncmp(vp,"0",1) == 0) + canon_debug_driver = 0; + if (strncmp(vp,"1",1) == 0) + canon_debug_driver = 1; + if (strncmp(vp,"1",1) == 0) + canon_debug_driver = 1; + if (strncmp(vp,"2",1) == 0) + canon_debug_driver = 2; + if (strncmp(vp,"3",1) == 0) + canon_debug_driver = 3; + if (strncmp(vp,"4",1) == 0) + canon_debug_driver = 4; + if (strncmp(vp,"5",1) == 0) + canon_debug_driver = 5; + if (strncmp(vp,"6",1) == 0) + canon_debug_driver = 6; + if (strncmp(vp,"7",1) == 0) + canon_debug_driver = 7; + if (strncmp(vp,"8",1) == 0) + canon_debug_driver = 8; + if (strncmp(vp,"9",1) == 0) + canon_debug_driver = 9; + fprintf(stderr,"Debug level: %i\n",canon_debug_driver); + } + } + fclose(conf); + } +//FIXME: How to know the link type ? +/* switch () { // is a gphoto global variable + case GP_PORT_USB: + debug_message("GPhoto tells us tha we should use a USB link.\n"); + canon_comm_method = CANON_USB; + break; + case GP_PORT_SERIAL: + default: + debug_message("GPhoto tells us tha we should use a RS232 link.\n"); + canon_comm_method = CANON_SERIAL_RS232; + break; + } +*/ + + canon_comm_method = CANON_SERIAL_RS232; + + if (canon_comm_method == CANON_SERIAL_RS232) + debug_message("Camera transmission speed : %i\n", camera.speed); + + return !canon_serial_init(init->port_settings.path); +} + + +/****************************************************************************/ + + +static void pretty_number(int number,char *buffer) +{ + int len,tmp,digits; + char *pos; + + len = 0; + tmp = number; + do { + len++; + tmp /= 10; + } + while (tmp); + len += (len-1)/3; + pos = buffer+len; + *pos = 0; + digits = 0; + do { + *--pos = (number % 10)+'0'; + number /= 10; + if (++digits == 3) { + *--pos = '\''; + digits = 0; + } + } + while (number); +} + +int camera_summary(CameraText *summary) +{ + char a[20],b[20]; + char *model; + + /*clear_readiness();*/ + if (!update_disk_cache()) return GP_ERROR; + pretty_number(cached_capacity,a); + pretty_number(cached_available,b); + model = "Canon Powershot"; + switch (camera.model) { + case CANON_PS_A5: model = "Canon Powershot A5"; break; + case CANON_PS_A5_ZOOM: model = "Canon Powershot A5 Zoom"; break; + case CANON_PS_A50: model = "Canon Powershot A50"; break; + case CANON_PS_A70: model = "Canon Powershot A70"; break; + case CANON_PS_S10: model = "Canon Powershot S10"; break; + case CANON_PS_S20: model = "Canon Powershot S20"; break; + } + sprintf(summary->text,"%s\nDrive %s\n%11s bytes total\n%11s bytes available\n", + model,cached_drive,a,b); +/* if (!(camera.model == CANON_PS_A5 + || camera.model == CANON_PS_A5_ZOOM) && command_line_mode==1) psa50_end(); */ + return GP_OK; +} + +/****************************************************************************/ + +int camera_about(CameraText *about) +{ + strcpy(about->text, "Canon PowerShot series driver by\n" + "Wolfgang G. Reissnegger,\n" + "Werner Almesberger,\n" + "Edouard Lafargue,\n" + "Philippe Marzouk,\n" + "A5 additions by Ole W. Saastad\n" + ); + + return GP_OK; +} + +/****************************************************************************/ + +int camera_file_delete(int picture_number) +{ + char path[300]; + char file[300], dir[300], atrs; + int j; + + /*clear_readiness();*/ + if (!check_readiness()) { + return 0; + } + if (!(camera.model == CANON_PS_A5 || + camera.model == CANON_PS_A5_ZOOM)) { /* this is tested only on powershot A50 */ + + if (!update_dir_cache()) { + gp_interface_status("Could not obtain directory listing"); + return 0; + } + /* gphoto2 numbering starts at 0 but we start at 1 */ + picture_number++; + if (!picture_number || picture_number > cached_images) { + gp_interface_status("Invalid index"); + /* psa50_end(); */ + return 0; + } + strcpy(path,cached_drive); + atrs=0; + pick_nth(picture_number,path,&atrs); + gp_interface_status(path); + + j = strrchr(path, '\\') - path; + strncpy(dir,path,j); + dir[j]='\0'; + strcpy(file, path+j+1); + + if (psa50_delete_file(file,dir)) { + gp_interface_status("error deleting file"); + /* psa50_end(); */ + return -1; + } + else { + /* psa50_end(); */ + cached_ready = 0; /*RAA: do smarter!*/ + cached_disk = 0; + if (cached_dir) clear_dir_cache(); + cached_dir = 0; + return 1; + } + } + return 0; +} + +/****************************************************************************/ +/* +static struct Image *canon_get_preview(void) { return NULL; } +static int canon_take_picture(void) { return 0; }; + +struct _Camera canon = +{ + canon_initialize, + canon_get_picture, + canon_get_preview, + canon_delete_image, + canon_take_picture, + canon_number_of_pictures, + canon_configure, + canon_summary, + canon_description +}; +*/ diff --git a/camlibs/canon/canon.h b/camlibs/canon/canon.h new file mode 100644 index 000000000..d997306fc --- /dev/null +++ b/camlibs/canon/canon.h @@ -0,0 +1,49 @@ +/**************************************************************************** + * + * File: canon.h + * + ****************************************************************************/ + +#ifndef _CANON_H +#define _CANON_H + +/**************************************************************************** + * + * global info structure + * + * Not much here yet... + * + ****************************************************************************/ + + + + + + + +/**************************************************************************** + * + * These are defines for packet command codes collected from several + * sources. There's no guarantee, that they are correct... + * + * The same is true for the ident string offset + * + ****************************************************************************/ + +#define CANON_IDENT_OFFSET 0x1a + +#define CANON_CMD_ACK 0x04 +#define CANON_CMD_PING 0x10 + +#define CANON_PCK_SOT 0x05 +#define CANON_PCK_EOT 0x04 +#define CANON_PCK_CMD 0x00 +#define CANON_PCK_IDENT 0x06 + +#endif /* _CANON_H */ + +/**************************************************************************** + * + * End of file: canon.h + * + ****************************************************************************/ diff --git a/camlibs/canon/crc.c b/camlibs/canon/crc.c new file mode 100644 index 000000000..f5adb8cc2 --- /dev/null +++ b/camlibs/canon/crc.c @@ -0,0 +1,233 @@ +#include +#include + +#include "crc.h" + + +/* + * CRC 0102010 + */ +static unsigned short crc_table[256] = { + 0x0, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, + 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, + 0x1081, 0x108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, + 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, + 0x2102, 0x308b, 0x210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, + 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, + 0x3183, 0x200a, 0x1291, 0x318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, + 0x4204, 0x538d, 0x6116, 0x709f, 0x420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, + 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x528, 0x37b3, 0x263a, + 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, + 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x630, 0x17b9, + 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x738, + 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, + 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, + 0x840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, + 0x18c1, 0x948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, + 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0xa50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, + 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, + 0x39c3, 0x284a, 0x1ad1, 0xb58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, + 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, + 0x4a44, 0x5bcd, 0x6956, 0x78df, 0xc60, 0x1de9, 0x2f72, 0x3efb, + 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0xd68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, + 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0xe70, 0x1ff9, + 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, + 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0xf78, +}; + + +/* + * Initial CRC values. Determined by looking at CRCs sent by the camera. + */ + +static int crc_init[1024] = { + -1, -1, -1, -1, -1, 0x83a4, 0x5b70, 0x724e, + 0x0ee6, 0x5969, 0x7b6c, 0x647f, 0x8e90, 0x07ad, 0x5af0, 0xfa5f, + 0x77aa, 0xc2b3, 0x5003, 0x59f5, 0xe76c, 0xad67, 0xe2af, 0x4632, + 0xd983, 0xb9a8, 0x8cfb, 0x7c8f, 0xbf08, 0x1c9d, 0xb35b, 0x2f51, + 0xec49, 0xd0dc, 0xae31, 0xac9c, 0x11be, 0xf886, 0xbe88, 0x948c, + 0xca17, 0xb48b, 0xc726, 0xed56, 0xc7cd, 0x0656, 0xa9e1, 0x44eb, + 0x10a1, 0xef97, 0x16ef, 0x91f1, 0x9f42, 0x5cac, 0x9639, 0x6f35, + 0x9c2b, 0x2d9f, 0x326b, 0x3f84, 0xb859, 0x75ea, 0x9291, 0xe771, + 0xb067, 0x0b62, 0xf53c, 0x6c55, 0xe418, 0xc154, 0xaf30, 0xa58d, + 0x4827, 0xbc6d, 0x61ae, 0x77c5, 0xadb3, 0x36af, 0xdbc0, 0xea8a, + 0x23ba, 0x6785, 0x6ca3, 0x1218, 0x46b5, 0x5e83, 0xa91b, 0xbeeb, + 0xf78c, 0xcc77, 0xe4ed, 0x3454, 0x30e2, 0xa6a6, 0x7b14, 0x1c7f, + 0x515b, 0x09e4, 0x631e, 0xd7e7, 0xad46, 0xc3af, 0x4412, 0xe9a1, + 0x1089, 0xc797, 0x5c56, 0x6c39, 0x8818, 0xbfcb, 0xdf9d, 0x97ce, + 0x9024, 0x4253, 0x98c7, 0xe1db, 0x2a01, 0x941c, 0x5a17, 0x1d5f, + 0x794a, 0x525d, 0x17d7, 0xa1e0, 0x0563, 0x84d2, 0x1507, 0x61c2, + 0x1bc5, 0xd32c, 0x4602, 0xe983, 0x3289, 0xdd84, 0x9eec, 0xfabd, + 0x95aa, 0xe406, 0xdf54, 0x5ece, 0xe41b, 0xc254, 0xb703, 0x5715, + 0x7782, 0xeab3, 0x1aba, 0xa43d, 0xf036, 0x4e00, 0xab0b, 0xbec9, + 0xd58c, 0xd664, 0x2657, 0xa2d0, 0x2d50, 0xfd6b, 0x7bdd, 0xd57f, + 0x2564, 0x89e3, 0x4cda, 0x6129, 0xf0c5, 0xbd00, 0x04bf, 0x50c3, + 0x99f5, 0xdbca, 0xe08a, 0x7310, 0x58f7, 0xed7d, 0xeccd, 0x54dc, + 0xa6b1, 0x6c14, 0xa518, 0xdd27, 0x3dec, 0xc07b, 0x8821, 0x86cb, + 0x1c25, 0x0b5b, 0xcc3c, 0xafed, 0x788d, 0x9d4c, 0x428e, 0x45c7, + 0x34b0, 0xd4e2, 0xb075, 0x1962, 0x640e, 0xff90, 0x90ff, 0x9953, + 0x7dca, 0xf219, 0x7122, 0x7ad5, 0xd56e, 0x3464, 0x00e2, 0x2d87, + 0x2a6b, 0xfe1c, 0x14ee, 0x80d3, 0x3443, 0x27e2, 0x1fc1, 0xf768, + 0x2877, 0xf23e, 0x5622, 0x4893, 0x086d, 0xe20f, 0xe632, 0xfb76, + 0x56bb, 0xd193, 0xe920, 0x9189, 0xe742, 0x8367, 0x9870, 0x56db, + 0xb193, 0xf773, 0x3377, 0x2b95, 0x080d, 0x820f, 0xf861, 0x5988, + 0x9a6c, 0x5af9, 0xf35f, 0x3f33, 0x0f59, 0xee78, 0xf1fe, 0x8e11, + 0x86ad, 0x7a25, 0x256e, 0x83e3, 0x1c70, 0x5e5b, 0x711b, 0x43d5, + 0x16d6, 0xa8f1, 0x5cfa, 0xc039, 0xca21, 0x828b, 0x7c61, 0x5108, + 0x5ae4, 0xee5f, 0xd6fe, 0xbc57, 0x5bae, 0xac4e, 0xc3be, 0x5512, + 0x60a0, 0x71d4, 0x8cd5, 0x528f, 0xc5d7, 0x0c74, 0xdb4b, 0x618a, + 0x53c5, 0x87c6, 0x1934, 0x320e, 0x5a84, 0x8e5f, 0xc8ad, 0x1ea9, + 0x9779, 0x2724, 0xd9c1, 0xfba8, 0x88bb, 0x1ccb, 0xe55b, 0x8a45, + 0xf2e9, 0x8122, 0xcd52, 0xc9fc, 0x47b8, 0x5b92, 0x904e, 0x2853, + 0xd63e, 0x7c57, 0x6708, 0xe1a3, 0x5201, 0x4bd7, 0x545e, 0x24b1, + 0x54f2, 0x88b1, 0x16cb, 0xb5f1, 0xb537, 0x7337, 0x7ff7, 0xdf3b, + 0x31ce, 0x82b7, 0x4061, 0xbae5, 0xd9c8, 0xf2a8, 0xc022, 0xd121, + 0x5b20, 0x224e, 0x9b94, 0xaae8, 0x55d8, 0xaaa0, 0x1dd8, 0xfe4a, + 0x42ee, 0x25c7, 0x2ae3, 0x761c, 0x7ca2, 0x9208, 0x7e71, 0x512a, + 0x78e4, 0xf44c, 0x1444, 0x2ad3, 0x461c, 0xf783, 0xc377, 0x9c12, + 0x149f, 0xf1d3, 0xa311, 0xe441, 0x9854, 0x72db, 0x9be6, 0xd8e8, + 0xdab9, 0x9b9b, 0xa5e8, 0x2d27, 0x8a6b, 0xdce9, 0xfbfd, 0xddbb, + 0xa1ec, 0x0963, 0xe41e, 0xc754, 0x9f56, 0x48ac, 0x376d, 0x11d1, + 0x9786, 0xd824, 0x16b9, 0xc7f1, 0x3a56, 0x420c, 0xc7c7, 0x0c56, + 0xf94b, 0x7b99, 0x917f, 0x1142, 0x0486, 0x69c3, 0x5a4d, 0x475f, + 0xbc92, 0x9eae, 0xb8bd, 0x91ea, 0x8442, 0x8507, 0xc816, 0xa5a9, + 0x6c27, 0x9618, 0x4e35, 0x9e0b, 0x1dbd, 0x9b4a, 0x74e8, 0x9880, + 0xa6db, 0x0614, 0xebe1, 0x40ab, 0x70e5, 0xb5c4, 0x8037, 0xd043, + 0x3131, 0x7db7, 0x8f19, 0x86bc, 0x6b25, 0xac6f, 0xe2be, 0x5732, + 0x5082, 0xd8f5, 0xc7b9, 0x7256, 0x16e6, 0x98f1, 0xd7db, 0x9146, + 0x2842, 0xc73e, 0xf556, 0x0655, 0xaae1, 0x5cd8, 0xe239, 0xd032, + 0x4031, 0xeae5, 0x4cba, 0x0129, 0xee96, 0x1ffe, 0xc868, 0xdba9, + 0x838a, 0x7570, 0x0891, 0x1e0f, 0x3179, 0x35b7, 0xdbf3, 0xd98a, + 0xb0a8, 0xc462, 0xb165, 0x0173, 0xb496, 0xda26, 0x049b, 0x74c3, + 0xb380, 0xf451, 0x0944, 0xc31e, 0xf512, 0x4255, 0x9ec7, 0xd1bd, + 0xc720, 0xeb56, 0xf7ab, 0xeb77, 0xd6ab, 0xe957, 0xe689, 0x4076, + 0xade5, 0x60af, 0x7ed4, 0xf42a, 0x7244, 0x04e6, 0x09c3, 0x441e, + 0xe5a1, 0x7045, 0x15c4, 0xa2c2, 0x3f50, 0x6c59, 0xe818, 0xa198, + 0x7d63, 0x5b19, 0x1b4e, 0x582c, 0x367d, 0x09c0, 0x471e, 0xfd92, + 0x82dd, 0x2a61, 0xf41c, 0x4444, 0xbfa1, 0xb59d, 0xd937, 0x0da8, + 0x0f5a, 0xed78, 0xe9cd, 0x7c89, 0xb908, 0x2cfb, 0x5e7a, 0x501b, + 0x41f5, 0x26f4, 0x01d0, 0x1796, 0xe0e0, 0x1910, 0x160e, 0x70f1, + 0xa1c4, 0x2163, 0xaea7, 0x3a9c, 0x880c, 0xabcb, 0x7ec9, 0xe92a, + 0x9b89, 0xb7e8, 0xbc15, 0x19ae, 0xa80e, 0xa3fa, 0x0f41, 0xf678, + 0x3066, 0x22a6, 0x7394, 0xdcf7, 0xe5fd, 0x2c45, 0xe07a, 0x8310, + 0xef70, 0xf1ef, 0x9f11, 0x0fac, 0x1b78, 0x6e2c, 0x8d3a, 0xb59e, + 0xda37, 0x159b, 0xfdc2, 0xd2dd, 0xbf13, 0x079d, 0x6af0, 0x717e, + 0x26d5, 0x20d0, 0x15b6, 0xd0c2, 0xb031, 0x5d62, 0x5028, 0x72f5, + 0xb5e6, 0xa237, 0xca50, 0xf38b, 0xeb33, 0x92ab, 0xdd71, 0x6bec, + 0x656f, 0x9681, 0xd735, 0x7f46, 0x6e3b, 0x9a3a, 0x0cf9, 0x564b, + 0x2193, 0x5ea7, 0x8d1b, 0x949e, 0xd817, 0x25b9, 0x54e3, 0x99b1, + 0x9fca, 0xd4ac, 0xfe75, 0x7dee, 0xd619, 0x5b57, 0x554e, 0x3ca0, + 0x846a, 0xad07, 0x82af, 0x5861, 0x7b7d, 0x757f, 0x0791, 0x66f0, + 0x11b2, 0xf486, 0xde44, 0x46df, 0x3483, 0xe7e2, 0x2367, 0xba85, + 0xb9c8, 0xecfb, 0x62dc, 0x1df6, 0xd04a, 0x3831, 0x352e, 0x42f3, + 0x38c7, 0xc32e, 0xc512, 0xc974, 0xcfb8, 0x33de, 0x8295, 0x6261, + 0xa0f6, 0x1b72, 0x642c, 0xdd90, 0x8aec, 0x5be9, 0xeb4e, 0xefab, + 0x2aef, 0x7a1c, 0x1c6e, 0x405b, 0x80e5, 0x0243, 0x9ca5, 0xa39f, + 0x6a41, 0xc07e, 0x8d21, 0xae9e, 0x039c, 0x4bb4, 0x375e, 0x22d1, + 0x0494, 0x7bc3, 0xcb7f, 0xd49a, 0xc875, 0xc6a9, 0x6a47, 0xc67e, + 0xbd47, 0x43bf, 0x7cd6, 0xe608, 0xc176, 0x8d30, 0xbf9e, 0x8a9d, + 0x2ae9, 0x7c1c, 0x2c08, 0xad7a, 0xffaf, 0xafff, 0x6a8d, 0x0c7e, + 0xd14b, 0x3120, 0x6cb7, 0x0618, 0xe7e1, 0x2067, 0xa2b6, 0x4b50, + 0xd35e, 0x3402, 0x66e2, 0x03b2, 0x65b4, 0x4d81, 0x3238, 0x6c84, + 0x3518, 0x74f3, 0x8380, 0x7f70, 0x583b, 0x217d, 0xb0a7, 0xcb62, + 0xc99a, 0x21b8, 0x75a7, 0xdf91, 0x9bce, 0xf0e8, 0x9000, 0x6653, + 0xb2b2, 0xce40, 0xc3cf, 0x2412, 0xf7f2, 0xb277, 0x0b40, 0xd73c, + 0x7646, 0x26a2, 0x57d0, 0xb282, 0xfe40, 0x48ee, 0x756d, 0x1591, + 0xf7c2, 0x8277, 0x8061, 0x8643, 0x9425, 0x6317, 0xdee7, 0xe5df, + 0x0e45, 0xfa69, 0x41aa, 0x79f4, 0xec5d, 0xc4dc, 0x0f65, 0xd278, + 0x1a13, 0x0d3d, 0x9a5a, 0x6cf9, 0x4818, 0x836d, 0x9270, 0x0671, + 0x8ee1, 0x76ad, 0xcda2, 0x39fc, 0xf03f, 0x4700, 0xe392, 0x7323, + 0x6bf7, 0x7e6f, 0x4f2a, 0x891a, 0xb5da, 0x9e37, 0x21bd, 0x70a7, + 0xf7c4, 0x8477, 0xb007, 0x6b62, 0xeb6f, 0xceab, 0x28cf, 0x4a3e, + 0xb54f, 0x0b37, 0xa03c, 0xd172, 0x0820, 0xaf0f, 0x9a8d, 0xbbf9, + 0xcdd9, 0x42fc, 0x37c7, 0xbbd1, 0xe5d9, 0x0845, 0xca0f, 0xac8b, + 0x06be, 0x41e1, 0x32f4, 0xa084, 0x6972, 0xeb4d, 0xecab, 0x32dc, + 0x8884, 0x23cb, 0x1685, 0xfbf1, 0xd1bb, 0xc120, 0xdb30, 0x1a8a, + 0x943d, 0x7b17, 0x1f7f, 0x4968, 0xfb7c, 0x5cbb, 0x8139, 0xd652, + 0x1057, 0x1997, 0x910e, 0x6042, 0x93d4, 0xaa60, 0xddd8, 0xc2ec, + 0x0f03, 0xb478, 0x3426, 0x42e2, 0x29c7, 0x4a2f, 0xa44f, 0x8236, + 0xc161, 0x9a30, 0x06f9, 0x06e1, 0x1ee1, 0xdf79, 0x73ce, 0x86f7, + 0x2025, 0xe0b6, 0x4f10, 0xb31a, 0x6e51, 0xf03a, 0x4200, 0xcbc7, + 0x6c9a, 0x2b18, 0x850d, 0xc216, 0xf503, 0x5355, 0x17c6, 0xb0e0, + 0x8c62, 0xe58f, 0x5e45, 0x6f1b, 0xb22b, 0x5740, 0x2282, 0x5794, + 0xf682, 0xca66, 0xc58b, 0x5074, 0x2ef5, 0x4058, 0x83e5, 0x1a70, + 0x6e3d, 0x9c3a, 0x3c9f, 0xbb6a, 0x5ed9, 0xf31b, 0x7b33, 0x3b7f, + 0x631d, 0xd4e7, 0xb575, 0x3137, 0x7bb7, 0xbf7f, 0x6b9d, 0x146f, + 0x01d3, 0x1496, 0xf8d3, 0xeb88, 0x29ab, 0x262f, 0xdad0, 0xf29b, + 0xf322, 0x4233, 0xf8c7, 0xff88, 0x88ff, 0x58cb, 0xd17d, 0x0720, + 0xd7f0, 0xba46, 0x7ac8, 0xc86e, 0xdda9, 0xb3ec, 0x9851, 0x77db, + 0xb3b3, 0xc751, 0x9a56, 0x60f9, 0x28d4, 0x513e, 0x6ce4, 0x5518, + 0x6aa0, 0x217e, 0xb3a7, 0xd351, 0x3b02, 0x1e1d, 0x2379, 0xa485, + 0x4836, 0xad6d, 0xe8af, 0x1698, 0xe6f1, 0x3876, 0x722e, 0x6ee6, + 0x473a, 0xd992, 0xa8a8, 0x05fa, 0x1dd2, 0xf44a, 0x1244, 0x1ab5, + 0xab3d, 0x88c9, 0x6ecb, 0x6a3a, 0xbb7e, 0x4ad9, 0x524f, 0x05d7, + 0x30d2, 0x96a6, 0xf035, 0x4d00, 0xb338, 0x4c51, 0xea29, 0x80ba, + 0x5d43, 0x7128, 0x70d5, 0x85c4, 0x0b16, 0x813c, 0xd352, 0x3802, + 0x062e, 0xd1e1, 0x9b20, 0x1ee8, 0xd679, 0x3b57, 0x4b1d, 0x9e5e, + 0x48bd, 0x266d, 0x98d0, 0xf6db, 0x9366, 0x1860, 0x6e1f, 0xbe3a, + 0x268c, 0x79d0, 0xc85d, 0xeea9, 0x20fe, 0x3bb6, 0xaa1d, 0xa0d8, + 0x3572, 0x1ef3, 0xcd79, 0xe2fc, 0x1532, 0x54c2, 0xb8b1, 0x9dea, + 0xe48e, 0x5754, 0x3682, 0xf6c0, 0x8866, 0xc1cb, 0x3030, 0x74a6, + 0xd680, 0xc257, 0xb403, 0x4f26, 0x851a, -1, -1, -1 +}; + + +static unsigned short chksum(unsigned short init,unsigned n, + const unsigned char *s) +{ + unsigned short crc; + + for (crc = init; n > 0; n--) + crc = crc_table[(crc ^ *s++) & 0xff] ^ (crc >> 8); + return crc; +} + + +static int find_init(int len) +{ + return len < 1024 ? crc_init[len] : -1; +} + + +unsigned short canon_psa50_gen_crc(const unsigned char *pkt,int len) +{ + int init; + + init = find_init(len); + if (init != -1) return chksum(init,len,pkt); + fprintf(stderr,"FATAL ERROR: initial CRC value for length %d " + "unknown\n",len); + exit(1); +} + + +static int guess(const unsigned char *m,int len,int crc) +{ + int i; + + for (i = 0; i < 0x10000; i++) + if (chksum(i,len,m) == crc) return i; + fprintf(stderr,"unable to guess initial CRC value\n"); + exit(1); +} + + +int canon_psa50_chk_crc(const unsigned char *pkt,int len,unsigned short crc) +{ + unsigned short this; + int init; + + init = find_init(len); + if (init != -1) return chksum(init,len,pkt) == crc; + this = guess(pkt,len,crc); + fprintf(stderr,"warning: CRC not checked (add len %d, value 0x%04x) #########################\n", + len,this); + return 1; +} diff --git a/camlibs/canon/crc.h b/camlibs/canon/crc.h new file mode 100644 index 000000000..6fa2fd7c8 --- /dev/null +++ b/camlibs/canon/crc.h @@ -0,0 +1,7 @@ +#ifndef CRC_H +#define CRC_H + +unsigned short canon_psa50_gen_crc(const unsigned char *pkt,int len); +int canon_psa50_chk_crc(const unsigned char *pkt,int len,unsigned short crc); + +#endif diff --git a/camlibs/canon/mkpatch b/camlibs/canon/mkpatch new file mode 100644 index 000000000..a04de5c01 --- /dev/null +++ b/camlibs/canon/mkpatch @@ -0,0 +1,33 @@ +#!/bin/sh +cd ../.. +ref=${1:-gphoto.ref} +work=${2:-gphoto.work} +[ -d $ref ] || { echo $ref/ is missing; exit; } +[ -d $work ] || { echo $work/ is missing; exit; } +for n in `awk '$1 !~ /^#/ {print$1}' < + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/camlibs/canon/ps350/README b/camlibs/canon/ps350/README new file mode 100644 index 000000000..bc8ca099e --- /dev/null +++ b/camlibs/canon/ps350/README @@ -0,0 +1,20 @@ +Contents: + + ps350proto.txt Description of the PS 350 protocol + + pd350chk.c C program to calculate checksum of PS 350 packets + + notes.txt Some other notes + + ps350init Script to initialize the PS350 and get it to 115200 at + once. Needs system-dependent modifications! + camera* Files used by ps350init + SerialIn Sample camera-returned data, created in /tmp by ps350init + + renamejpg.c C program that automatically renames PS350 AUT/THM + files (given as arguments) to a `recording-time' format + that is much easier to interpret than the original + name, like + AUT_0365.JPG => aut_19990626-124040.jpg + If the destination name already exists, names with + appended `-2', `-3' etc. are tried. diff --git a/camlibs/canon/ps350/SerialIn b/camlibs/canon/ps350/SerialIn new file mode 100644 index 0000000000000000000000000000000000000000..41b04608c412cf2bae73a5c98e712a418de5d9e6 GIT binary patch literal 1201 zcmX@Wz?Q<0#NguW=@P@hz`zJXjIUT2feZ!)-~5!+9KXceRNH|3^3jQkP>V^aeK z1s%7{qTKStqEv;l)S}|d{5)F&Ln{L#9pA*f(zL|nlG38oB3tLgy!<=`&%9(k1qB6= zaYGu+N;!CdftdvqLZg5{2<%*Pkl_G>fB`tLI2o8346tZm0g8_T28Q^T2M;igCM=?o IfTJ4&F1fCT$N0JbIqTL1t6 literal 0 HcmV?d00001 diff --git a/camlibs/canon/ps350/compu6 b/camlibs/canon/ps350/compu6 new file mode 100644 index 0000000000000000000000000000000000000000..fd5f564e95cc40b980c7f37b120c39d11f9cf2a0 GIT binary patch literal 300 TcmX@W$il)f3J8b5MAm}X<----------------------------------------------------------------. + | | + +--------------------+---------------------------. | + | | | | + | v v | + `->T-->T-->T-->T-->T-X>T-->T-->T-->T-->T-->T-->T-X>T-->T-->T-->T--' + 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + + The three X's are XOR gates; T's are 1-bit memory elements and the rest + are wires with arrows indicating the direction of the logic signals. + Bits are fed into the input (`In') LSBit first. When all bytes are + fed in, the T's hold the checksum (bit numbers 15 through 0 as + indicated). Only the 296 `real data' bytes are fed in (thus excluding + the 0xC0 header) and initialization is 0x0000. + + In other words: this is just a standard CRC-CCITT algorithm. But I + only saw that when I drew the schematic. There are quite a few + programs available that calculate this CRC, but I didn't understand + most of them, so I wrote my own version for some experiments. (And most + implementations that I've seen didn't have a clear copyright...) + + I implemented the 16-stage shift register in a `long' variable + that is shifted and XOR'd when necessary. + + Note that this is only a sample implementation that is probably very + slow. However, it should be fast enough to use it with 300-byte + packets at 115200 baud. + + This program uses hard-coded data for easy experimentation. Two sample + packets are provided. Of course, this must be made into a proper + function to be usable. + */ + +#include + +void +main (void) +{ + long datalen = 296; /* number of data bytes. Always 296. */ + + char data[] = + {0x05, 0x03, 0x04, 0x00, 0x01, +/* this is a EOT packet, count=5. The checksum is "87 3F" (LSByte-first!) */ + +/* a few 0's to fill up the packet (far too much 0's actually, but that's + no problem) */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + + +/* from a serial snoop: jut some arbitrary packet from a JPG download. */ +/* rename this to `data' and the original `data' to `data1' to try it. */ + char data1[] = + { + /* 0x3f1e *//* 0xC0, */ 0x05, + /* 0x3f20 */ 0x10, 0x24, 0x81, 0x4d, 0xf6, 0xa7, 0x52, 0xbd, + /* 0x3f28 */ 0x83, 0xec, 0xe9, 0x88, 0xbc, 0xcc, 0x0f, 0x90, + /* 0x3f30 */ 0xf4, 0x99, 0x97, 0xb0, 0xf6, 0xae, 0xa3, 0x9b, + /* 0x3f38 */ 0x99, 0x98, 0xb6, 0xf7, 0xfb, 0x55, 0x8b, 0xbe, + /* 0x3f40 */ 0x23, 0x68, 0xf3, 0xc7, 0xad, 0x72, 0xe6, 0xf2, + /* 0x3f48 */ 0x1b, 0x88, 0xdf, 0x9c, 0x1e, 0xb4, 0xa3, 0x1d, + /* 0x3f50 */ 0x59, 0xac, 0xe5, 0xa9, 0xdd, 0xe8, 0x97, 0x65, + /* 0x3f58 */ 0x63, 0xd9, 0xe6, 0x7c, 0xb8, 0xad, 0x2b, 0x8b, + /* 0x3f60 */ 0xce, 0x3f, 0xa5, 0x73, 0x3d, 0xcd, 0x8c, 0xc9, + /* 0x3f68 */ 0x65, 0xbb, 0xfb, 0x3f, 0x99, 0x1d, 0xc4, 0xa0, + /* 0x3f70 */ 0x15, 0x3c, 0x29, 0xf4, 0xc7, 0xbf, 0xbd, 0x32, + /* 0x3f78 */ 0xfa, 0xd6, 0xf6, 0xde, 0x29, 0x0f, 0xf6, 0x9d, + /* 0x3f80 */ 0xe4, 0xbf, 0x7b, 0xfd, 0x58, 0x27, 0xa2, 0xb3, + /* 0x3f88 */ 0x7f, 0x7b, 0xfd, 0x9f, 0xd6, 0xb7, 0x80, 0x4a, + /* 0x3f90 */ 0x71, 0xb6, 0xa8, 0xdd, 0xd1, 0xe0, 0x31, 0xe8, + /* 0x3f98 */ 0x0c, 0xc3, 0xed, 0xb7, 0x33, 0xc2, 0x0b, 0x71, + /* 0x3fa0 */ 0xbb, 0xe6, 0xff, 0x00, 0x67, 0x83, 0xd6, 0x9d, + /* 0x3fa8 */ 0xb0, 0xde, 0x68, 0xcf, 0x25, 0xd5, 0xbd, 0xf5, + /* 0x3fb0 */ 0x85, 0xc4, 0xaa, 0x53, 0x6c, 0x9b, 0xb3, 0x1f, + /* 0x3fb8 */ 0xd7, 0x35, 0xc9, 0x3d, 0x64, 0xf5, 0x34, 0x53, + /* 0x3fc0 */ 0x56, 0x5a, 0x1c, 0xb4, 0x30, 0x6a, 0x37, 0x1c, + /* 0x3fc8 */ 0x0d, 0x52, 0xfa, 0x3c, 0x7f, 0x7f, 0x23, 0xbb, + /* 0x3fd0 */ 0x8f, 0xef, 0x7f, 0xb2, 0x7f, 0xef, 0xaa, 0x82, + /* 0x3fd8 */ 0xe1, 0x6f, 0xfc, 0xdb, 0x88, 0x5f, 0x52, 0xbb, + /* 0x3fe0 */ 0xf9, 0x37, 0x7c, 0xcc, 0x4e, 0x1b, 0x0e, 0x57, + /* 0x3fe8 */ 0xfb, 0xde, 0xd5, 0xe8, 0x9c, 0x7e, 0xd2, 0x1d, + /* 0x3ff0 */ 0x8e, 0x46, 0x6b, 0xc9, 0x3e, 0x62, 0x64, 0xce, + /* 0x3ff8 */ 0x17, 0xb9, 0xed, 0x5c, 0xaa, 0xdc, 0xb8, 0x47, + /* 0x4000 */ 0x22, 0xba, 0x60, 0x8c, 0x31, 0x0e, 0xcc, 0xf4, + /* 0x4008 */ 0x5d, 0x2e, 0xf0, 0x06, 0x45, 0xdd, 0xc7, 0x7a, + /* 0x4010 */ 0xda, 0xbb, 0xbb, 0xc4, 0x13, 0x30, 0x2c, 0xc5, + /* 0x4018 */ 0x57, 0x27, 0x00, 0xf1, 0x9e, 0x95, 0xc1, 0x34, + /* 0x4020 */ 0x74, 0xa6, 0x32, 0xea, 0xfa, 0xca, 0x4d, 0x21, + /* 0x4028 */ 0x55, 0x65, 0x5f, 0x33, 0x04, 0x00, 0x47, 0x5e, + /* 0x4030 */ 0x63, 0xcf, 0x24, 0x7b, 0x51, 0xa8, 0x6b, 0x16, + /* 0x4038 */ 0xf7, 0x31, 0x4b, 0x1d, 0xad, 0xc2, 0x33, 0x37, + /* 0x4040 */ 0x98, 0xa7, 0x2c, 0x07, 0x58, 0x9c, 0x77, 0x6e, + /* 0x4048 */ 0xc7, 0xc1}; +/* note: last 3 bytes are chksum and trailer */ + + char bits[] = + {1, 2, 4, 8, 16, 32, 64, 128}; + long chksum = 0; + long i, j; + int inputbit, lastbit, xorbit; + +/* calculate checksum */ + for (i = 0; i < datalen; i++) + for (j = 0; j <= 7; j++) + { + lastbit = chksum & 0x0001; /* remember if last bit was 1 */ + chksum >>= 1; /* shift 1 place */ + inputbit = data[i] & bits[j] ? 1 : 0; /* the In bit */ + xorbit = inputbit ^ lastbit; /* output of upper XOR gate */ + if (xorbit) /* XOR if needed */ + chksum ^= 0x8408; + } + +/* display checksum */ + printf ("Checksum: 0x%lX\n", chksum); +} diff --git a/camlibs/canon/ps350/ps350init b/camlibs/canon/ps350/ps350init new file mode 100755 index 000000000..bae3b0829 --- /dev/null +++ b/camlibs/canon/ps350/ps350init @@ -0,0 +1,50 @@ +#! /bin/sh + +# The tty to use +tty=/dev/ttyS1 + +# Make the tty completely `raw' -- even more than `stty raw' does. +# Works For Me [tm] on a Debian 2.1 system (kernel 2.0.36) +stty sane < "$tty" +stty -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok echonl -echoctl -echoke < "$tty" +stty intr undef quit undef erase undef kill undef eof undef eol undef eol2 undef start undef stop undef susp undef rprnt undef werase undef lnext undef flush undef < "$tty" + +stty 9600 < "$tty" + +# Capture incoming signals to a file +cat < "$tty" > /tmp/SerialIn & +catpid=$! + +cat compu1 > "$tty" +sleep 1s +# This lets camera answer + +cat compu3 > "$tty" +sleep 1s + +# Imitate a serial break +stty 50 < "$tty" +cat compu3c > "$tty" +sleep 1s + +stty 9600 < "$tty" + +cat compu3d > "$tty" +sleep 1s +cat compu3e-4 > "$tty" +sleep 1s + +stty 115200 < "$tty" + +cat compu3c > "$tty" +sleep 1s +cat compu3f > "$tty" +sleep 1s + +cat compu5 > "$tty" +sleep 1s + +cat compu6 > "$tty" +sleep 2s + +kill $catpid diff --git a/camlibs/canon/ps350/ps350proto.txt b/camlibs/canon/ps350/ps350proto.txt new file mode 100644 index 000000000..53f2e7171 --- /dev/null +++ b/camlibs/canon/ps350/ps350proto.txt @@ -0,0 +1,740 @@ + + Canon Powershot 350 / A5 Protocol Notes + + J.A. Bezemer + 5 July 1999 + + + +GENERAL +======= + +This document tries to describe the protocol that is observed in the +serial communication between the Canon Powershot 350 and A5 (Zoom) cameras +and a computer (or any other device equipped with a serial port). Only RX, +TX and GND pins are used, with speeds of up to 115200 baud. + +Please read this document at least twice before complaining you don't +understand anything at all. + +This document is likely to contain errors. USE THIS DOCUMENT AT YOUR OWN +RISK. NO WARRANTY WHATSOEVER. + +This document is copyright (C) 1999 J.A. Bezemer. It may be modified/ +distributed according to the terms of the GNU General Public License. More +details in the file COPYING, or on the GNU website (http://www.gnu.org). + + +At this moment, this document only describes the protocol of the PS 350. +The A5 protocol is believed to be very similar to the 350 protocol. +Please inform me if there are notable differences in the A5 protocol. + + +PACKETS +======= + +After (and also during) initialization, communication between camera and +computer is organized in 300-byte packets. All packets start with 0xC0 and +end with 0xC1. The last two bytes are a checksum, so one packet looks like +this: + + 0xC0 ---296 data bytes--- ---2 byte checksum--- 0xC1 + + +The method of checksumming is a 16-bit CRC calculation. The file +ps350chk.c contains more info and a sample implementation. + +A packet contains a `length' field which indicates the length of the +valid data in the packet. Non-valid extra bytes are sent as 0x00, but I +don't know if that specific value is required. + + +COMMUNICATION STRUCTURE +======================= + +The communication is organized as follows: + + 1. Computer sends command (always 1 packet) + 2. Camera sends reply (1 or more packets) + 3. Camera sends End-Of-Transmission packet + 4. Computer sends ACKnowledge packet + +A `command-counter' is used that is incremented with each command. +Computer and camera seem to increment the counter independently; there may +be a possibility of getting out-of-sync (this may be corrected with a +"ping" command, see below). It is an 8-bit value that warps from 255 to 0 +(assumption!). + +This `count' is transmitted in every first packet of steps 1 through 4 +(i.e. not in the "extra" packets of a "long" camera-reply), except steps 1 +and 2 of a "ping" command. + + +PACKET STRUCTURES +================= + +In the following, a large number of packets will be described. The 0xC0 +header byte will be omitted. In the diagrams, all numbers are in hex, +unless otherwise stated. Multi-byte values are transmitted LSByte-first. + + +"ping" command (sent by computer) +-------------- + + 00 10 0C 00 | 00 00 00 00 | 31 00 01 60 | 0C 00 00 00 + comm <---totlen---> + <--------------------0C bytes----------------------> + +`len' is length of this packet; `totlen' is total length of complete +packet sequence. totlen != len only in multi-packet replies from camera. + +The length starts counting from the 5th byte of the "real" data (the 0xC0 +excluded). + +`comm' is the command number (at least, that's what I call it). + +Note that there are a lot of 0x00 bytes, a checksum and 0xC1 trailer after +the bytes specified above (always 300 bytes in a packet). + +The "ping" command and reply are identical in all cases (no command count +number). + +This command is sent every few seconds when the system is otherwise idle. +If there is no reply, the camera is assumed to be disconnected or turned +off (possibly due to empty batteries). + + +"ping" reply (sent by camera) +------------ + + 00 10 30 00 | 01 00 00 00 | 09 00 03 00 | 30 00 00 00 + comm <---totlen---> + 00 00 00 00 | 00 00 00 00 | 00 00 00 00 | 00 00 00 00 + 04 00 03 00 | 00 00 00 00 | 00 00 00 00 | 00 00 00 00 + 00 00 00 00 + +Normally the `comm' bytes are equal in command and reply, except here. + +The 5th byte is 00 in computer packets and 01 in camera packets. + + +EOT packet (sent by camera) +---------- + + xx 03 04 00 | 01 00 00 00 + count + + +ACK packet (sent by computer) +---------- + + xx 04 04 00 | 00 00 00 00 + count + + +"unknown1" command ("get settings"???) +------------------ + + 00 10 10 00 | 00 00 00 00 | 1E 00 01 60 | 10 00 00 00 + comm <---totlen---> + xx 00 00 00 + count + +The M$Win driver sends this when count=07. + + +"unknown1" reply +---------------- + + 00 10 18 00 | 01 00 00 00 | 1E 00 02 60 | 18 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | 00 00 00 00 + count + +After this, the usual EOT/ACK packets follow. + + +"get disks" command +------------------- + + 00 10 14 00 | 00 00 00 00 | 18 00 01 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | 1E 00 00 00 + count + +The M$Win driver sends this when count=08. + + +"get disks" reply +----------------- + + 00 10 23 00 | 01 00 00 00 | 18 00 22 A0 | 23 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | 52 45 4D 4F | 56 41 42 4C + count R E M O V A B L + 45 5F 31 3A | 2F 00 00 + E _ 1 : / + +Normally, a string is 0-terminated. I think the second terminating zero +indicates the end of a (possible) list of strings. + +After this, the usual EOT/ACK packets follow. I won't indicate this again +below. + + +"use disk" command +------------------ + + 00 10 21 00 | 00 00 00 00 | 14 00 21 A0 | 21 00 00 00 + comm <---totlen---> + xx 00 00 00 | 52 45 4D 4F | 56 41 42 4C | 45 5F 31 3A + count R E M O V A B L E _ 1 : + 00 00 00 00 | 00 + +I don't know what those extra 00's mean. + +The M$Win driver sends this when count=09. + + +"use disk" reply +---------------- + + 00 10 1C 00 | 01 00 00 00 | 14 00 02 60 | 1C 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | 00 60 1E 00 | 00 xx xx 00 + count ?????? + +`?????' is different each time. + + +"name for dir" command +---------------------- + + 00 10 xx xx | 00 00 00 00 | 02 00 21 A0 | xx xx xx xx + comm <---totlen---> + xx 00 00 00 | xx xx xx... ...xx 00 + count dirname (string) termination + +E.g. "REMOVABLE_1:\DC97" has len=0x22 + + +"name for dir" reply for existing directory +-------------------- + + 00 10 18 00 | 01 00 00 00 | 02 00 02 60 | 18 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | xx xx xx xx + count <---sector---> + +I call the returned number `sector' because I don't know what it is ;-) +This `sector' is used in further communications. + + +"name for dir" reply for non-existing (maybe also empty??) directory +-------------------- + + 00 10 18 00 | 01 00 00 00 | 02 00 02 60 | 18 00 00 00 + comm <---totlen---> + xx 00 00 00 | 02 00 00 20 | 02 00 00 20 + count | + | +This 0x02 may indicate that something is wrong. But I only have one +occurrence, so I'm not sure. + + +"forget dir" command +-------------------- + + 00 10 14 00 | 00 00 00 00 | 03 00 01 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | xx xx xx xx + count <---sector---> + +This command is used after a "name for dir" to check for dir existence and +also after a full dir download. + +sector is the number that was sent in the "name for dir" reply. In case of +a non-existent dir, sector is here 00 00 00 00. + + +"forget dir" reply +------------------ + + 00 10 14 00 | 01 00 00 00 | 03 00 02 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 + count + + +"prepare for dir download" command +---------------------------------- + + 00 10 14 00 | 00 00 00 00 | 04 00 01 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | xx xx xx xx + count <---sector---> + +This command is sent to indicate that a dir download will follow. + +(I speak of "download" because I see the camera as "information server".) + + +"prepare for dir download" reply +-------------------------------- + + 00 10 14 00 | 01 00 00 00 | 04 00 02 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 + count + + +"dir download" command +---------------------- + + 00 10 1C 00 | 00 00 00 00 | 2A 00 81 A0 | 1C 00 00 00 + comm <---totlen---> + xx 00 00 00 | xx xx xx xx | E8 03 00 00 | 00 00 00 00 + count <---sector---> + +I don't know what the E8 03 means, but it's there always. + + +"dir download" reply +-------------------- +This is possibly a multi-packet sequence. The first (or only) packet: + + 00 10 xx xx | 01 00 00 00 | 2A 00 42 A0 | xx xx xx xx + num comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | xx xx xx xx | xx... ...xx + count <#files> <----dir data-------- - - + +All next packets (if any): + + xx 10 xx xx | xx xx... ...xx + num <----dir data---- - - + +(The following applies to all "sequenced packets":) + +num is the serial number of the packet in the sequence. The first packet +has num=00, second 01, etc. + +len is the number of valid data bytes in every individual packet, _always_ +starting with the fifth byte (0xC0 header excluded). totlen is the sum of +all len's in the sequence. + +Note that there's no need for len to be 300-8=292=0x0124. Notably +directory entries are not split across packets, so there's always some +empty space at the end of directory-download packets. + +The MSBit of len is 1 in all not-last packets, and 0 only in the last +packet. So the first packet may have a len=12 81 (LSByte first)=0x8112. + +The EOT packet following a multi-packet sequence has non-zero values for +bytes 5,6,7,8. I don't know what they mean. But the ACK packet is still +`normal', so there shouldn't be a problem. + +(This is only for "dir download":) + +#files is the number of files in the directory; I don't know if that +includes erased files. See below for more on the directory entries. + +The dir data is not terminated (unlike 0-terminated strings). + +After a dir download, a "forget dir" command follows. + + +"name for file" command +----------------------- + + 00 10 xx xx | 00 00 00 00 | 01 00 41 A0 | xx xx xx xx + comm <---totlen---> + xx 00 00 00 | 01 00 00 00 | xx xx... ...xx 00 + count filename (string) termination + +E.g. "REMOVABLE_1:\DC97\CTG_0001\THM_0073.JPG" has len=0x3C + + +"name for file" reply for existing file +--------------------- + + 00 10 18 00 | 01 00 00 00 | 01 00 02 60 | 18 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | xx xx xx xx + count <---sector---> + +I don't know what is returned for a non-existing file. + + +"prepare for file download" command +----------------------------------- + + 00 10 14 00 | 00 00 00 00 | 17 00 01 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | xx xx xx xx + count <---sector---> + +sector as returned in the "name for file" reply. + + +"prepare for file download" reply +--------------------------------- + + 00 10 18 00 | 01 00 00 00 | 17 00 02 60 | 18 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | xx xx xx xx + count <--file len--> + +`file len' is the length of the file that is to be downloaded. + + +"file download" command +----------------------- + + 00 10 18 00 | 00 00 00 00 | 12 00 01 60 | 18 00 00 00 + comm <---totlen---> + xx 00 00 00 | xx xx xx xx | xx xx xx xx + count <---sector---> <-len2Bdownl-> + +`len2Bdownl' is the length of the piece of the file that should be sent to +the computer in the reply packet-sequence. The M$Win driver limits this to +0x245C (which (if I'm correct) nicely fills up 0x20 packets). If the reply +packet-sequence has been received, another identical "file download" +command is sent, and transmission will continue. The last "file download" +command should have a len2Bdownl that exactly matches the length of the +remainder of the file. + +Note that the "start point for download" is not specified; the camera +remembers this. + + +"file download" reply +--------------------- +This is possibly a multi-packet sequence. The first (or only) packet: + + 00 10 xx xx | 01 00 00 00 | 12 00 C2 A0 | xx xx xx xx + num comm <---totlen---> + xx 00 00 00 | 00 00 00 00 | xx xx xx xx | xx xx xx xx + count <---sector---> <---offset---> + xx xx xx xx | xx 00 00 00 | xx xx... ...xx + <-len2Bdownl-> last <----file data--- - - + +All next packets have same structure as those of "dir download" reply +(see above). Everything mentioned there for "sequenced packets" applies +here as well. + +This packet format is repeated for every "resumed download". + +`offset' is the number of bytes of the file that have been transmitted +before this sequence (so starts at 0 at the first sequence). + +`last' is 0x01 only in the last sequence, and 0x00 in non-last sequences. + +Like dirs, the file data is not terminated (unlike 0-terminated strings). + +After a completed file download, a "forget file" command follows. + + +"forget file" command +--------------------- + + 00 10 14 00 | 00 00 00 00 | 11 00 01 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | xx xx xx xx + count <---sector---> + + +"forget file" reply +------------------- + + 00 10 14 00 | 01 00 00 00 | 11 00 02 60 | 14 00 00 00 + comm <---totlen---> + xx 00 00 00 | 00 00 00 00 + count + + +"turn off" command +------------------ + + 00 01 00 00 + + +This tells the camera to turn itself off. This seems the only way of +getting out of the computer-controlled mode. The M$Win driver issues this +command upon exitting it. + + +"turn off" reply +---------------- + + 00 10 10 00 | 01 00 00 00 | 39 00 02 60 | 10 00 00 00 + comm <---totlen---> + 00 00 00 00 +(count) + +count seems to be 0x00 in all cases. + +After this, a regular EOT packet (with the correct `count' number) is +sent, after which the camera turns itself off. The computer does not send +an ACK packet. + + +Other packets +------------- + +There are also packets for file/all-files deletion, getting battery status +and getting/setting owner's name, but I don't have information on these at +this moment. + + +INITIALIZATION +============== + +Below is the initialization procedure that the M$Win driver uses. Most +numbers are in hex. + +Connection check: + +1. Speed = 9600 baud +2. Computer sends 00 53 55 55 55 55 +3. Camera returns "identicifation" reply packet: + + 00 06 64 00 | 62 00 44 43 | 49 44 5C 00 | 00 00 01 00 + + 00 01 00 01 | EA 04 01 01 | 00 00 00 00 | 4D 6F 64 65 +count? M o d e + 6C 4E 61 6D | 65 3D 50 6F | 77 65 72 53 | 68 6F 74 20 + l N a m e = P o w e r S h o t + 33 35 30 20 | 20 2C 46 69 | 72 6D 77 61 | 72 65 20 76 + 3 5 0 , F i r m w a r e v + 65 72 73 69 | 6F 6E 3D 30 | 31 3A 30 32 | 2C 4D 61 6E + e r s i o n = 0 1 : 0 2 , M a n + 75 66 61 63 | 74 75 72 65 | 72 3D 43 61 | 6E 6F 6E 20 + u f a c t u r e r = C a n o n + 49 6E 63 2E | 20 20 20 00 + I n c . + +4. Camera sends regular EOT packet with count=00 +5. Computer sends ACK + +Try possible speeds: + +6. Computer sends serial break signal; a 00 at 50 baud also works +7. Camera answers with serial break +8. Speed = 9600 +9. Computer sends 42 00 (42 0x = speed change) +10. Speed = 9600 +11. Computer sends 00 53 +12. Computer sends "ping" packet +13. Camera returns "ping" reply +14. Camera sends EOT packet with count=01 +15. Computer sends ACK packet with count=01 + +16. Computer sends serial break signal +17. Camera answers with serial break +18. Speed = 9600 +19. Computer sends 42 01 +20. Speed = 19200 +21. Computer sends 00 53 +22. Computer sends "ping" packet +23. Camera returns "ping" reply +24. Camera sends EOT packet with count=02 +25. Computer sends ACK packet with count=02 + +26. Computer sends serial break signal +27. Camera answers with serial break +28. Speed = 9600 +29. Computer sends 42 02 +30. Speed = 38400 +31. Computer sends 00 53 +32. Computer sends "ping" packet +33. Camera returns "ping" reply +34. Camera sends EOT packet with count=03 +35. Computer sends ACK packet with count=03 + +36. Computer sends serial break signal +37. Camera answers with serial break +38. Speed = 9600 +39. Computer sends 42 03 +40. Speed = 57600 +41. Computer sends 00 53 +42. Computer sends "ping" packet +43. Camera returns "ping" reply +44. Camera sends EOT packet with count=04 +45. Computer sends ACK packet with count=04 + +46. Computer sends serial break signal +47. Camera answers with serial break +48. Speed = 9600 +49. Computer sends 42 04 +50. Speed = 115200 +51. Computer sends 00 53 +52. Computer sends "ping" packet +53. Camera returns "ping" reply +54. Camera sends EOT packet with count=05 +55. Computer sends ACK packet with count=05 + +Resume communication at chosen speed: + +56. Computer sends serial break signal +57. Camera answers with serial break +58. Speed = 9600 +59. Computer sends 42 04 +60. Speed = 115200 +61. Computer sends 00 53 +62. Computer sends "ping" packet +63. Camera returns "ping" reply +64. Camera sends EOT packet with count=06 +65. Computer sends ACK packet with count=06 + +After this, communication is as described in the next section. + +It's not needed to try all speeds. The following sequence has been tried +succesfully: 1, 2, 3, 4, 5, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65 (but +then 64 and 65 with count=01). + + +MORE COMMUNICATION +================== + +After initialization, the following communication takes place: + +66. Computer sends "unknown1" command (see above), camera returns reply, + EOT, ACK (count=07) +67. Computer sends "get disks" command, camera returns reply, EOT, ACK + (count=08) +68. Computer sends "use disk" command, camera returns reply, EOT, ACK + (count=09) +69. Computer sends "name for dir" command to check if "REMOVABLE_1:\DC97" + is present, camera returns reply (`exists'), EOT, ACK (count=0A) +70. Computer sends "forget dir" command, camera returns reply, EOT, ACK + (count=0B) +71. Computer sends "name for dir" command to check if + "REMOVABLE_1:\PWRSHOT" is present, camera returns reply (`does not + exist'), EOT, ACK (count=0C) +72. Computer sends "forget dir" command, camera returns reply, EOT, ACK + (count=0D) +73. Computer sends "name for dir" command for download of + "REMOVABLE_1:\DC97", camera returns reply, EOT, ACK (count=0E) +74. Computer sends "prepare for dir download" command, camera returns + reply, EOT, ACK (count=0F) +75. Computer sends "dir download" command, camera returns reply, EOT, ACK + (count=10) + The dir info returns + . + .. + CTG_0000 + CTG_0001 + and possibly more CTG's. These CTG's are `catalogs'; there may only be + a limited number of files in a CTG subdir, and a new subdir is added + when needed. +76. Computer sends "forget dir" command, camera returns reply, EOT, ACK + (count=11) + +Now the computer gets each CTG_* directory with "name for dir", "prepare +for dir download", "dir download" and "forget dir" commands. Dir names are +"REMOVABLE_1:\DC97\CTG_0000" etc. + +In the CTG directories, there are two files for each picture: a thumbnail +file (e.g. THM_0021.JPG) and a `real picture' file (e.g. AUT_0021.JPG). + +The M$Win driver first gets up to 9 thumbnail files (more don't fit in the +driver's window), using commands "name for file", "prepare for file +download", "file download" and "forget file". Sample file name: +"REMOVABLE_1:\DC97\CTG_0001\THM_0073.JPG" + +More thumbnails are loaded when a scroll button is pressed. During `idle +time', "ping" packets are sent every second. + +When a picture is selected, the `Aquire' button initiates a communication +just like a thumbnail download, only there may be repeated "file +download" commands. And in the file name it's "AUT" instead of "THM". + +When the driver is exitted, a "turn off" command is sent. + + +DIRECTORY ENTRIES +================= + +The directory information (as sent over the serial link) has 21=0x15 bytes +of information per file. Example entry (numbers in hex): + + 20 2A 08 00 00 AA 28 3B 37 54 48 4D 5F 30 30 37 33 2E 4A 50 47 + type <--size---> <--time---> T H M _ 0 0 7 3 . J P G + <---------------name--------------> + +type is 0x20 for a regular file, 0x10 for a directory. + +size is the file size in bytes, also returned in the "prepare for file +download" reply. + +time is the standard UNIX time_t-format time of file/dir creation. + +name seems to be left-aligned; e.g. a ".." directory entry has in the name +field ".." followed by ten 00-bytes. + +Erased files have 0xE5 as first byte of the file name. + +Directories have a size 00 00 00 00. + +On the Compact Flash memory card, there is a normal FAT12 filesystem. The +CF card behaves like a hard disk (has a partition table), of which +the first (and only) partition spans the entire disk=memory. The PCMCIA +kernel modules recognize it as an `ide' card. + + +JPG FILE +======== + +The header of all JPG files has some interesting fields. Example: + + + FF D8 FF E0 | 00 10 4A 46 | 49 46 00 01 | 02 01 00 B4 + J F I F + 00 B4 00 00 | FF E0 00 A0 | 49 49 1A 00 | 00 00 48 45 + H E + 41 50 4A 50 | 47 4D 02 00 | 01 00 00 00 | 00 00 00 00 + A P J P G M + 00 00 44 F8 | 4F 37 00 00 | 00 00 00 00 | 00 00 43 61 + <-----time------> C a + 6E 6F 6E 20 | 49 6E 63 2E | 20 20 20 00 | 50 6F 77 65 + n o n I n c . P o w e + 72 53 68 6F | 74 20 33 35 | 30 20 20 00 | 46 69 72 6D + r S h o t 3 5 0 F i r m + 77 61 72 65 | 20 76 65 72 | 73 69 6F 6E | 20 31 2E 30 + w a r e v e r s i o n 1 . 0 + 32 00 01 00 | 0B 08 16 00 | 00 00 00 00 | 00 00 16 00 + 2 + 00 00 02 00 | 0A 08 1E 00 | 00 00 00 00 | 00 00 04 30 + + +The time field is exactly the same as in the directory. + +Except for the time field, this piece of the header (and possibly more) +seems to be identical for all JPG files (THM_* and AUT_*). + +THM and AUT files are numbered, starting from {THM,AUT}_0000.JPG when the +camera is new (and possibly when the batteries have been out a few days) +and incremented for each picture. Incrementing is normally not interrupted +by a CF card swap (i.e. if you place a new card after AUT_0168, then +AUT_0169 will be the first picture on the new card). However, I have seen +one occurrence of the same file name on two cards. The "right" method of +ordering the files is by using the `time' field that is returned in the +directory info. (Note that the time of AUT and THM files may be a few +seconds apart.) + + +For the PS 350, the THM files are 80 x 60 and AUT 640 x 480 pixels. There +are three quality modes for the AUT files (recording-time choice), "Fine", +"Normal" and "Economy", which correspond to JPEG quality factors of about +90%, 75% and 50%. THM files are about 2.5 kB and AUT files about 150 kB, +70 kB and 32 kB depending on the quality mode. + + +CONTACT INFORMATION +=================== + +I'm reachable preferably as . If that +shouldn't work, try or else . +In the latter case, please indicate that you're trying to send a message +to me (and not to my brother ;-) + diff --git a/camlibs/canon/ps350/renamejpg.c b/camlibs/canon/ps350/renamejpg.c new file mode 100644 index 000000000..c46fe450e --- /dev/null +++ b/camlibs/canon/ps350/renamejpg.c @@ -0,0 +1,75 @@ +/* RenameJPG Copyright (C) 1999 J.A. Bezemer GPL'd */ + +#include +#include +#include +#include +#include + +void main (int argc, char **argv) +{ + FILE *jpgfile; + time_t time; + struct tm *temptm; + unsigned char buffer[4]; + char timestring[200]; + char tempstring[300]; + char newname[300]; + int i; + struct stat statbuf; + struct stat statbuf2; + int newnamecounter; + + if (argc < 2) + { + fprintf (stderr, "Usage: renamejpg [filename(s)]\n\n"); + exit(1); + } + + for (i=1; i %s\n", argv[i], statbuf.st_size, + timestring, newname); + + fclose(jpgfile); + + rename(argv[i], newname); + } +} diff --git a/camlibs/canon/psa50.c b/camlibs/canon/psa50.c new file mode 100644 index 000000000..22ca28609 --- /dev/null +++ b/camlibs/canon/psa50.c @@ -0,0 +1,1554 @@ +/* + * psa50.c - Canon PowerShot "native" operations. + * + * Written 1999 by Wolfgang G. Reissnegger and Werner Almesberger + * Additions 2000 by Philippe Marzouk and Edouard Lafargue + * USB support, 2000, by Mikael Nyström + */ + +/** + * This file now includes both USB and serial support. This is + * experimental and not guaranteed to work 100%. Maybe a better + * design would be to make serial and USB support completely separate, + * but at the same time, both protocols/busses work almost the same + * way. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../../libgphoto2/exif.h" + +#include "serial.h" +#include "util.h" +#include "crc.h" +#include "psa50.h" + +/************ new stuff ********/ +#include +gpio_device *iodev; +gpio_device_settings settings; +int gpio_usb_msg_write(gpio_device *dev, int value, char *bytes, int size); +int gpio_usb_msg_read(gpio_device *dev, int value, char *bytes, int size); +int gpio_usb_read(gpio_device *dev, char *bytes, int size); +int gpio_usb_write(gpio_device *dev, char *bytes, int size); +/************ new stuff ********/ + +#define MAX_TRIES 10 + +#define USLEEP1 0 +#define USLEEP2 1 + +static unsigned char psa50_eot[8]; + +/* ------------------------- Frame-level processing ------------------------- */ + + +#define CANON_FBEG 0xc0 +#define CANON_FEND 0xc1 +#define CANON_ESC 0x7e +#define CANON_XOR 0x20 + +int psa50_send_frame(const unsigned char *pkt,int len) +{ + static unsigned char buffer[2100]; + /* worst case: two maximum-sized packets (~1020 bytes, full of data + that needs to be escaped */ + unsigned char *p; + + p = buffer; + *p++ = CANON_FBEG; + while (len--) { + if (p-buffer >= sizeof(buffer)-1) { + debug_message("FATAL ERROR: send buffer overflow\n"); + exit(1); + } + if (*pkt != CANON_FBEG && *pkt != CANON_FEND && *pkt != CANON_ESC) + *p++ = *pkt++; + else { + *p++ = CANON_ESC; + *p++ = *pkt++ ^ CANON_XOR; + } + } + *p++ = CANON_FEND; + return !canon_serial_send(buffer,p-buffer,USLEEP2); +} + + +unsigned char *psa50_recv_frame(int *len) +{ + static unsigned char buffer[5000]; + /* more than enough :-) (allow for a few run-together packets) */ + unsigned char *p = buffer; + int c; + + while ((c = canon_serial_get_byte()) != CANON_FBEG) + if (c == -1) return NULL; + while ((c = canon_serial_get_byte()) != CANON_FEND) { + if (c < 0) return NULL; + if (c == CANON_ESC) c = canon_serial_get_byte() ^ CANON_XOR; + if (p-buffer >= sizeof(buffer)) { + debug_message("FATAL ERROR: receive buffer overflow\n"); + exit(1); + } + *p++ = c; + } + dump_hex("RECV",buffer,p-buffer); + if (len) *len = p-buffer; + return buffer; +} + + +/* ------------------------ Packet-level processing ------------------------- */ + + +#define MAX_PKT_PAYLOAD 65535 +#define MAX_PKT_SIZE (MAX_PKT_PAYLOAD+4) + +#define PKT_HDR_LEN 4 + +#define PKT_SEQ 0 +#define PKT_TYPE 1 +#define PKT_LEN_LSB 2 +#define PKT_LEN_MSB 3 + +#define PKT_MSG 0 +#define PKT_EOT 4 +#define PKT_ACK 5 +#define PKT_NACK 255 +#define PKTACK_NACK 0x01 + +static unsigned char seq_tx = 1; +static unsigned char seq_rx = 1; + + +static int psa50_send_packet(unsigned char type,unsigned char seq, + unsigned char *pkt,int len) +{ + unsigned char *hdr = pkt-PKT_HDR_LEN; + unsigned short crc; + + + hdr[PKT_TYPE] = type; + hdr[PKT_SEQ] = seq; + hdr[PKT_LEN_LSB] = len & 0xff; + hdr[PKT_LEN_MSB] = len >> 8; + if (type == PKT_NACK) { + hdr[PKT_TYPE] = PKT_ACK; + hdr[PKT_TYPE+1] = '\xff';/* PKTACK_NACK; */ + } + if (type == PKT_EOT || type == PKT_ACK || type == PKT_NACK) len = 2; /* @@@ hack */ + crc = canon_psa50_gen_crc(hdr,len+PKT_HDR_LEN); + pkt[len] = crc & 0xff; + pkt[len+1] = crc >> 8; + return psa50_send_frame(hdr,len+PKT_HDR_LEN+2); +} + + +static unsigned char *psa50_recv_packet(unsigned char *type,unsigned char *seq, + int *len) +{ + unsigned char *pkt; + unsigned short crc; + int raw_length,length=0; + + pkt = psa50_recv_frame(&raw_length); + if (!pkt) return NULL; + if (raw_length < PKT_HDR_LEN) { + debug_message("ERROR: packet truncated\n"); + return NULL; + } + if (pkt[PKT_TYPE] == PKT_MSG) { + length = pkt[PKT_LEN_LSB] | (pkt[PKT_LEN_MSB] << 8); + if (length+PKT_HDR_LEN > raw_length-2) { + debug_message("ERROR: invalid length\n"); + /*fprintf(stderr,"Sending NACK\n"); + psa50_send_packet(PKT_NACK,seq_rx++,psa50_eot+PKT_HDR_LEN,0); */ + receive_error = ERROR_RECEIVED; + return NULL; + } + } + crc = pkt[raw_length-2] | (pkt[raw_length-1] << 8); + if (!canon_psa50_chk_crc(pkt,raw_length-2,crc)) { + debug_message("ERROR: CRC error\n"); + return NULL; + } + if (type) *type = pkt[PKT_TYPE]; + if (seq) *seq = pkt[PKT_SEQ]; + if (len) *len = length; + if (*type == PKT_ACK || *type == PKT_EOT) return pkt; + return pkt+PKT_HDR_LEN; +} + + +/* ----------------------- Message-level processing ------------------------ */ + + +#define MAX_MSG_SIZE (MAX_PKT_PAYLOAD-12) + +#define FRAG_NUM 0 +#define FRAG_LEN_LSB 2 +#define FRAG_LEN_MSB 3 + +#define MSG_HDR_LEN 16 +#define MSG_02 0 +#define MSG_MTYPE 4 +#define MSG_DIR 7 +#define MSG_LEN_LSB 8 +#define MSG_LEN_MSB 9 + +// #define MSG_FFFB 12 + + + +#define DIR_REVERSE 0x30 + + + + +/** + * Waits for an "ACK" from the camera. + * + * Return values: + * 1 : ACK received + * 0 : communication error (no reply received for example) + * -1 : NACK received. + */ +static int psa50_wait_for_ack(void) +{ + unsigned char *pkt; + unsigned char type,seq,old_seq; + int len; + + while (1) { + pkt = psa50_recv_packet(&type,&seq,&len); + if (!pkt) return 0; + if (seq == seq_tx && type == PKT_ACK) { + if (pkt[2] == PKTACK_NACK) { + debug_message("ERROR: NACK received\n"); + return -1; + } + seq_tx++; + return 1; + } + old_seq='\0'; + if (type == PKT_EOT) { + old_seq=pkt[0]; + if (receive_error == NOERROR) { + debug_message("Old EOT received, sending corresponding ACK\n"); + if (!psa50_send_packet(PKT_ACK,old_seq,psa50_eot+PKT_HDR_LEN,0)) return 0; + pkt = psa50_recv_packet(&type,&seq,&len); + if (!pkt) return 0; + if (seq == old_seq && type == PKT_ACK) { + if (pkt[2] == PKTACK_NACK) { + debug_message("Old EOT acknowledged\n"); + return -1; + } + return 1; + } + } + } + /* error already aknowledged, we skip the following ones */ + if (receive_error == ERROR_RECEIVED) { + if (!psa50_send_packet(PKT_NACK,old_seq,psa50_eot+PKT_HDR_LEN,0)) return 0; + return 1; + } + + debug_message("ERROR: ACK format or sequence error, retrying\n"); + debug_message("Sending NACK\n"); + psa50_send_packet(PKT_NACK,seq_rx++,psa50_eot+PKT_HDR_LEN,0); + receive_error = ERROR_RECEIVED; + +/* + * just keep on trying. protocol seems to retransmit EOTs, so we may get + * some old EOTs when we're actually expecting ACKs. + */ + } +} + +/** + * Sends a message to the camera. + * + * See the "Protocol" file for an explanation of the various + * elements needed to create a message. + * + * Arguments: + * mtype : message type. + * dir : direction. + * ap : message payload (list of arguments, see 'man va_start' + */ +static int psa50_send_msg(unsigned char mtype,unsigned char dir, + va_list *ap) +{ + unsigned char buffer[MAX_PKT_PAYLOAD+2]; /* allow space for CRC */ + unsigned char *pkt,*pos; + int total, good_ack, try; + + memset(buffer,0,PKT_HDR_LEN+MSG_HDR_LEN); + pkt = buffer+PKT_HDR_LEN; + pkt[MSG_02] = 2; + pkt[MSG_MTYPE] = mtype; + pkt[MSG_DIR] = dir; + pos = pkt+MSG_HDR_LEN; + total = 0; + while (1) { + const char *str; + int len; + + str = va_arg(*ap,unsigned char *); + if (!str) break; + len = va_arg(*ap,int); + if (pos+len-pkt > MAX_MSG_SIZE) { + debug_message("FATAL ERROR: message too big (%i)\n",pos+len-pkt); + exit(1); + } + memcpy(pos,str,len); + pos += len; + } + total = pos-pkt; + pkt[MSG_LEN_LSB] = total & 0xff; + pkt[MSG_LEN_MSB] = total >> 8; + for (try=1; try < MAX_TRIES; try++) { + if (!psa50_send_packet(PKT_MSG,0,pkt,total)) return 0; + if (!psa50_send_packet(PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,1)) return 0; + good_ack = psa50_wait_for_ack(); + if (good_ack == -1) { + debug_message("NACK received, retrying command\n"); + } + else if (good_ack==1) { + return good_ack; + } + else { + debug_message("No ACK received, retrying command\n"); + if (try==2) { + //is the camera still there? + if (!psa50_send_packet(PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0)) return 0; + good_ack = psa50_wait_for_ack(); + if (good_ack==0) { + receive_error = FATAL_ERROR; + debug_message("ERROR: FATAL ERROR\n"); + return -1; + } + } + } + } + return -1; +} + + +/** + * Receive a message from the camera. + * + * See the "Protocol" file for an explanation of the various + * elements needed to handle a message. + * + * Arguments: + * mtype : message type. + * dir : direction. + * total : payload length (set by this function). + * + * Returns: + * char* : pointer to the message payload. + */ +static unsigned char *psa50_recv_msg(unsigned char mtype,unsigned char dir, + int *total) +{ + static unsigned char *msg = NULL; + static int msg_size = 512; /* initial allocation/2 */ + unsigned char *frag; + unsigned char type,seq; + int len,length = 0,msg_pos = 0; + + while (1) { + frag = psa50_recv_packet(&type,NULL,&len); + if (!frag) return NULL; + if (type == PKT_MSG) break; + if (type == PKT_EOT) { + debug_message("Old EOT received sending corresponding ACK\n"); + psa50_send_packet(PKT_ACK,frag[0],psa50_eot+PKT_HDR_LEN,0); + } + debug_message("ERROR: protocol error, retrying\n"); + } + /* we keep the fragment only if there was no error */ + if (receive_error == NOERROR) { + length = frag[MSG_LEN_LSB] | (frag[MSG_LEN_MSB] << 8); + if (len < MSG_HDR_LEN || frag[MSG_02] != 2) { + debug_message("ERROR: message format error\n"); + return NULL; + } + + if (frag[MSG_MTYPE] != mtype || frag[MSG_DIR] != dir) { + if(frag[MSG_MTYPE] =='\x01' && frag[MSG_DIR] == '\x00' && + memcmp(frag+12,"\x30\x00\x00\x30",4)) { + debug_message("ERROR: Battery exhausted, camera off"); + gp_interface_status("Battery exhausted, camera off."); + receive_error=ERROR_LOWBATT; + } + else { + debug_message("ERROR: unexpected message.\n"); + gp_interface_status("ERROR: unexpected message"); + } + return NULL; + } + frag += MSG_HDR_LEN; + len -= MSG_HDR_LEN; + } + while (1) { + if (receive_error == NOERROR) { + if (msg_pos+len > length) { + debug_message("ERROR: message overrun\n"); + gp_interface_status("ERROR: message overrun"); + return NULL; + } + if (msg_pos+len > msg_size || !msg) { + msg_size *= 2; + msg = realloc(msg,msg_size); + if (!msg) { + perror("realloc"); + exit(1); + } + } + memcpy(msg+msg_pos,frag,len); + msg_pos += len; + } + frag = psa50_recv_packet(&type,&seq,&len); + if (!frag) return NULL; + if (type == PKT_EOT) { + /* in case of error we don't want to stop as the camera will send + the 1st packet of the sequence again */ + if (receive_error == ERROR_RECEIVED) { + seq_rx = seq; + psa50_send_packet(PKT_NACK,seq_rx,psa50_eot+PKT_HDR_LEN,0); + receive_error = ERROR_ADDRESSED; + } else { + if (seq == seq_rx) break; + debug_message("ERROR: out of sequence\n"); + gp_interface_status("ERROR: out of sequence."); + return NULL; + } + } + if (type != PKT_MSG && receive_error == NOERROR) { + debug_message("ERROR: unexpected packet type\n"); + gp_interface_status("ERROR: unexpected packet type."); + return NULL; + } + if (type == PKT_EOT && receive_error == ERROR_RECEIVED) { + receive_error = ERROR_ADDRESSED; + } + if (type == PKT_MSG && receive_error == ERROR_ADDRESSED) { + msg_pos =0; + length = frag[MSG_LEN_LSB] | (frag[MSG_LEN_MSB] << 8); + if (len < MSG_HDR_LEN || frag[MSG_02] != 2) { + debug_message("ERROR: message format error\n"); + gp_interface_status("ERROR: message format error."); + return NULL; + } + + if (frag[MSG_MTYPE] != mtype || frag[MSG_DIR] != dir) { + if(frag[MSG_MTYPE] =='\x01' && frag[MSG_DIR] == '\x00' && + memcmp(frag+12,"\x30\x00\x00\x30",4)) { + debug_message("ERROR: Battery exhausted, camera off"); + gp_interface_status("Battery exhausted, camera off."); + receive_error=ERROR_LOWBATT; + } + else { + debug_message("ERROR: unexpected message2\n"); + gp_interface_status("ERROR: unexpected message2."); + } + return NULL; + } + frag += MSG_HDR_LEN; + len -= MSG_HDR_LEN; + receive_error = NOERROR; + } + } + if (receive_error == ERROR_ADDRESSED) { + receive_error = NOERROR; + } + if (receive_error == NOERROR) { + if (!psa50_send_packet(PKT_ACK,seq_rx++,psa50_eot+PKT_HDR_LEN,0)) + return NULL; + if (total) *total = msg_pos; + return msg; + } + + return NULL; +} + +/** + * Higher level function: sends a message and waits for a + * reply from the camera. + * + * Arguments: + * mtype : type + * dir : direction + * len : length of the received payload + * ... : The rest of the arguments will be put together to + * fill up the payload of the request message. + * + * + * Payload: each argument after "len" goes by 2: the variable itself, + * and the next argument has to be its length. You also have to finish + * the list by a "NULL". + * + * Example: To send a string called "name" : + * psa50_serial_dialogue(0x05,0x12,&len,name,strlen(name)+1,NULL); + * + */ +static unsigned char *psa50_serial_dialogue(unsigned char mtype,unsigned char dir, + int *len,...) +{ + va_list ap; + int okay,try; + unsigned char *good_ack; + + for ( try = 1; try < MAX_TRIES; try++) { + va_start(ap,len); + okay = psa50_send_msg(mtype,dir,&ap); + va_end(ap); + if (!okay) return NULL; + good_ack = psa50_recv_msg(mtype,dir ^ DIR_REVERSE,len); + + if (good_ack) return good_ack; + if (receive_error == NOERROR) { + debug_message("Resending message\n"); + seq_tx--; + } + if (receive_error == FATAL_ERROR) break; + } + return NULL; +} + + +/** + * Utility function used by psa50_usb_dialogue + */ +void intatpos(unsigned char *block, int pos, int integer ) +{ + *(unsigned *)(block+pos)=integer; +} + +/** + * USB version of the dialogue function. + */ +static unsigned char *psa50_usb_dialogue(char cmd1, char cmd2, int cmd3, int *retlen, const char *payload, int pay_length) +{ +#ifdef GPIO_USB + int msgsize; + char packet[0x3000]; + static char buffer[0x3000]; + int i; + int lonlen; + + memset(packet,0x00,0x3000); /* zero block */ + packet[0x40]=0x2; + packet[0x44]=cmd1; + packet[0x47]=cmd2; + intatpos(packet,0x04,cmd3); /* cmd3 */ + intatpos(packet,0x4c,0x12345678); + if (pay_length!=0) + memcpy (packet+0x50,payload, pay_length); + intatpos(packet,0x0,0x10+pay_length); + intatpos(packet,0x48,0x10+pay_length); + /* fprintf(stderr,"%s\n",payload); */ + msgsize=0x50+pay_length; + /* for (i=0;i<0x54;i++) + * { + * fprintf (stderr,"%x %x\n",i,packet[i]); + * } + */ + + gpio_usb_msg_write(iodev,0x10,packet,msgsize); + if (cmd3==0x202) + { + gpio_read(iodev, buffer, 0x40); + lonlen=*(unsigned *)(buffer+0x6); + //fprintf(stderr,"Internal lonlen: %x\n",lonlen); + if (lonlen>0x3000) + gpio_read(iodev,buffer,0x2000); + else + gpio_read(iodev,buffer,lonlen); + *retlen=lonlen; + return buffer; + } + else + { + //fprintf(stderr,"Internal retlen: %x\n",*retlen); + gpio_read(iodev, buffer, *retlen+0x50); + return buffer+0x50; + } + +#else + fprintf(stderr,"There is not USB support on this computer. Try 'serial', please.\n"); + return 0; +#endif + +} + + +/* ----------------------- Command-level processing ------------------------ */ + + + + +#define JPEG_ESC 0xFF +#define JPEG_BEG 0xD8 +#define JPEG_SOS 0xDB +#define JPEG_A50_SOS 0xC4 +#define JPEG_END 0xD9 + +#define SPEED_9600 "\x00\x03\x02\x02\x01\x10\x00\x00\x00\x00\xc0\x39" +#define SPEED_19200 "\x00\x03\x08\x02\x01\x10\x00\x00\x00\x00\x13\x1f" +#define SPEED_38400 "\x00\x03\x20\x02\x01\x10\x00\x00\x00\x00\x5f\x84" +#define SPEED_57600 "\x00\x03\x40\x02\x01\x10\x00\x00\x00\x00\x5e\x57" +#define SPEED_115200 "\x00\x03\x80\x02\x01\x10\x00\x00\x00\x00\x4d\xf9" + +char psa50_id[200]; /* some models may have a lot to report */ +struct canon_info camera; + + + +static unsigned int get_int(const unsigned char *p) +{ + return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); +} + + +/** + * Switches the camera off, closes the serial driver and restores + * the serial port to its previous settings. + */ +int psa50_end() +{ + canon_serial_send("\xC0\x00\x02\x55\x2C\xC1",6,USLEEP2); + canon_serial_send("\xC0\x00\x04\x01\x00\x00\x00\x24\xC6\xC1",8,USLEEP2); + canon_serial_restore(); + return 0; +} + +/** + * Switches the camera off, and resets the serial driver to 9600 bauds, + * in order to be ready to switch the camera back on again if wanted. + */ +int psa50_off() +{ + canon_serial_send("\xC0\x00\x02\x55\x2C\xC1",6,USLEEP2); + canon_serial_send("\xC0\x00\x04\x01\x00\x00\x00\x24\xC6\xC1",8,USLEEP2); + canon_serial_change_speed(9600); + return 0; +} + + +/** + * Synchronize camera time to Unix time. + */ +int psa50_sync_time() +{ + + + return 0; +} + +/** + * Gets the camera identification string, usually the owner + * name. This information is stored in the "camera" structure, which + * is a global variable for the driver. + * This function also gets the firmware revision in the camera struct. + * + */ +int psa50_get_owner_name(void) +{ + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + len=0x4c; + msg = psa50_usb_dialogue(0x01,0x12,0x201,&len,0,0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0x01,0x12,&len,NULL); + break; + + } + + if (!msg) { + psa50_error_type(); + return 0; + } + /* Store these values in our "camera" structure: */ + memcpy(camera.firmwrev,(char *) msg+8,4); + strncpy(camera.ident,(char *) msg+12,30); + strncpy(camera.owner,(char *) msg+44,30); + + return 0; +} + +/** + * Get battery status. + */ +int psa50_get_battery( int *pwr_status, int *pwr_source) { + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + len=0x8; + msg = psa50_usb_dialogue(0x0A,0x12,0x201,&len,0,0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0x0a,0x12,&len,NULL); + break; + } + + if (!msg) { + psa50_error_type(); + return -1; + } + + if (pwr_status) *pwr_status = msg[4]; + if (pwr_source) *pwr_source = msg[7]; + debug_message("Status: %i / Source: %i\n",*pwr_status,*pwr_source); + return 0; +} + + +/** + * Sets a file's attributes. See the 'Protocol' file for details. + */ +int psa50_set_file_attributes(const char *file, const char *dir, char attrs) { + unsigned char buf[300]; + unsigned char *msg; + unsigned char attr[4]; + int len,name_len; + + attr[0] = attr[1] = attr[2] = 0; + attr[3] = attrs; + + switch (canon_comm_method) { + case CANON_USB: + memcpy(buf,attr,4); + memcpy(buf+4,dir,strlen(dir)+1); + memcpy(buf+4+strlen(dir)+1,file,strlen(file)+1); + name_len=strlen(dir)+strlen(file)+2+4; + len=0x4; + msg = psa50_usb_dialogue(0x0e,0x11,0x201,&len,buf,name_len); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0xe,0x11,&len,attr,4,dir,strlen(dir)+1, + file,strlen(file)+1,NULL); + break; + } + + if (!msg) { + psa50_error_type(); + return -1; + } + + return 0; +} + +/** + * Sets the camera owner name. The string should + * not be more than 30 characters long. We call get_owner_name + * afterwards in order to check that everything went fine. + * + */ +int psa50_set_owner_name(const char *name) +{ + unsigned char *msg; + int len; + + if (strlen(name) > 30) { + debug_message("Name too long (%i chars), could not store it !", strlen(name)); + gp_interface_status("Name too long, could not store it !"); + return 0; + } + debug_message("New owner: %s\n",name); + + switch (canon_comm_method) { + case CANON_USB: + len=0x4; + msg = psa50_usb_dialogue(0x05,0x12,0x201,&len,name,strlen(name)+1); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0x05,0x12,&len,name,strlen(name)+1,NULL); + break; + } + + if (!msg) { + psa50_error_type(); + return 0; + } + return psa50_get_owner_name(); +} + + +/** + * Get camera's current time. + * + * The camera gives time in little endian format, therefore we need + * to swap the 4 bytes on big-endian machines. + * + * Nota: the time returned is not GMT but local time. Therefore, + * if you use functions like "ctime", it will be translated to local + * time _a second time_, and the result will be wrong. Only use functions + * that don't translate the date into localtime, like "gmtime". + */ +time_t psa50_get_time(void) +{ + unsigned char *msg; + int len; + time_t date; + + + switch (canon_comm_method) { + case CANON_USB: + len=0x10; + msg = psa50_usb_dialogue(0x03,0x12,0x201,&len,0,0); + break; + case CANON_SERIAL_RS232: + default: + msg=psa50_serial_dialogue(0x03,0x12,&len,NULL); + break; + } + + if (!msg) { + psa50_error_type(); + return 0; + } + + /* Beware, this is very dirty, and might fail one day, if time_t + is not a 4-byte value anymore. */ + memcpy(&date,msg+4,4); + + return byteswap32(date); +} + + +/** + * Switches the camera on, detects the model and sets its speed. + */ +int psa50_ready() +{ + unsigned char type,seq; + char *pkt; + int try,len,speed,good_ack,res,cts; + + switch (canon_comm_method) { + case CANON_USB: + psa50_get_owner_name(); + psa50_get_time(); + if (!strcmp("Canon PowerShot S20",camera.ident)) { + gp_interface_status("Detected a Powershot S20"); + camera.model = CANON_PS_S20; + A5 = 0; + return 1; + } + else if (!strcmp("Canon PowerShot S10",camera.ident)) { + gp_interface_status("Detected a Powershot S10"); + camera.model = CANON_PS_S10; + A5 = 0; + return 1; + } + else + { + printf ("Unknown camera!\n"); + return 0; + } + break; + case CANON_SERIAL_RS232: + default: + + serial_set_timeout(1000); // 1 second is the delay for awakening the camera + serial_flush_input(); + serial_flush_output(); + + receive_error=NOERROR; + + /* First of all, we must check if the camera is already on */ + cts=canon_serial_get_cts(); + debug_message("cts : %i\n",cts); + if (cts==1) { // CTS > 0 when the camera is on. + + gp_interface_status("Camera already on..."); + /* First case, the serial speed of the camera is the same as + * ours, so let's try to send a ping packet : */ + if (!psa50_send_packet(PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0)) + return 0; + good_ack=psa50_wait_for_ack(); + debug_message("good_ack = %i\n",good_ack); + if (good_ack==0) { + /* no answer from the camera, let's try + * at the speed saved in the settings... */ + speed=camera.speed; + if (speed!=9600) { + if(!canon_serial_change_speed(speed)) { + gp_interface_status("Error changing speed."); + debug_message("speed changed.\n"); + } + } + if (!psa50_send_packet(PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0)) + return 0; + good_ack=psa50_wait_for_ack(); + if (good_ack==0) { + gp_interface_status("Resetting protocol..."); + psa50_off(); + sleep(3); /* The camera takes a while to switch off */ + return psa50_ready(); + } + if (good_ack==-1) { + debug_message("Received a NACK !\n"); + return 0; + } + gp_interface_status("Camera OK.\n"); + return 1; + } + if (good_ack==-1) { + debug_message("Received a NACK !\n"); + return 0; + } + debug_message("Camera replied to ping, proceed.\n"); + return 1; + } + + /* Camera was off... */ + + gp_interface_status("Looking for camera ..."); + gp_interface_progress(0); + if(receive_error==FATAL_ERROR) { + /* we try to recover from an error + we go back to 9600bps */ + if(!canon_serial_change_speed(9600 )) { + debug_message("ERROR: Error changing speed"); + return 0; + } + receive_error=NOERROR; + } + for (try = 1; try < MAX_TRIES; try++) { + gp_interface_progress(try/(float) MAX_TRIES); + if (canon_serial_send("\x55\x55\x55\x55\x55\x55\x55\x55",8,USLEEP1) < 0) { + gp_interface_status("Communication error"); + return 0; + } + pkt = psa50_recv_frame(&len); + if (pkt) break; + } + if (try == MAX_TRIES) { + gp_interface_status("No response from camera"); + return 0; + } + if (!pkt) { + gp_interface_status("No response from camera"); + return 0; + } + if (len < 40 && strncmp(pkt+26,"Canon",5)) { + gp_interface_status("Unrecognized response"); + return 0; + } + strcpy(psa50_id,pkt+26); /* @@@ check size */ + + debug_message("psa50_id : '%s'\n",psa50_id); + + if (!strcmp("DE300 Canon Inc.",psa50_id)) { + gp_interface_status("Powershot A5"); + camera.model = CANON_PS_A5; + A5 = 1; + } else if (!strcmp("Canon PowerShot A5 Zoom",psa50_id)) { + gp_interface_status("Powershot A5 Zoom"); + camera.model = CANON_PS_A5_ZOOM; + A5 = 1; + } else if (!strcmp("Canon PowerShot A50",psa50_id)) { + gp_interface_status("Detected a Powershot A50"); + camera.model = CANON_PS_A50; + A5 = 0; + } else if (!strcmp("Canon PowerShot S20",psa50_id)) { + gp_interface_status("Detected a Powershot S20"); + camera.model = CANON_PS_S20; + A5 = 0; + } else { + gp_interface_status("Detected a Powershot S10"); + camera.model = CANON_PS_S10; + A5 = 0; + } + + // 5 seconds delay should be enough for big flash cards. By + // experience, one or two seconds is too little, as a large flash + // card needs more access time. + serial_set_timeout(5000); + (void) psa50_recv_packet(&type,&seq,NULL); + if (type != PKT_EOT || seq) { + gp_interface_status("Bad EOT"); + return 0; + } + seq_tx = 0; + seq_rx = 1; + if (!psa50_send_frame("\x00\x05\x00\x00\x00\x00\xdb\xd1",8)) + { gp_interface_status("Communication error"); + return 0; + } + res=0; + switch (camera.speed) { + case 9600: res=psa50_send_frame(SPEED_9600,12); break; + case 19200: res=psa50_send_frame(SPEED_19200,12); break; + case 38400: res=psa50_send_frame(SPEED_38400,12); break; + case 57600: res=psa50_send_frame(SPEED_57600,12); break; + case 115200: res=psa50_send_frame(SPEED_115200,12); break; + } + + if( !res || !psa50_send_frame("\x00\x04\x01\x00\x00\x00\x24\xc6",8)) { + gp_interface_status("Communication error"); + return 0; + } + speed=camera.speed; + gp_interface_status("Changing speed... wait..."); + if (!psa50_wait_for_ack()) return 0; + if (speed!=9600) { + if(!canon_serial_change_speed(speed)) { + gp_interface_status("Error changing speed"); + debug_message("ERROR: Error changing speed"); + } + else { + debug_message("speed changed\n"); + } + + } + for (try=1; try < MAX_TRIES; try++) { + psa50_send_packet(PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0); + if (!psa50_wait_for_ack()) { + gp_interface_status("Error waiting ACK during initialization retrying"); + } + else { + break; + } + } + if (try==MAX_TRIES) { + gp_interface_status("Error waiting ACK during initialization"); + return 0; + } + gp_interface_status("Connected to camera"); + /* Now is a good time to ask the camera for its owner + * name (and Model String as well) */ + psa50_get_owner_name(); + psa50_get_time(); + return 1; + } +} + +/** + * Ask the camera for the name of the flash storage + * device. Usually "D:" or somehting like that. + */ +char *psa50_get_disk(void) +{ + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + msg = psa50_usb_dialogue(0x0A,0x11,0x202,&len,0,0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0x0a,0x11,&len,NULL); + break; + } + + if (!msg) { + psa50_error_type(); + return NULL; + } + if (canon_comm_method == CANON_SERIAL_RS232) { + msg = strdup((char *) msg+4); /* @@@ should check length */ + if (!msg) perror("strdup"); + } + return msg; +} + +/** + * Gets available room and max capacity of a given disk. + */ +int psa50_disk_info(const char *name,int *capacity,int *available) +{ + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + len=0xc; + msg = psa50_usb_dialogue(0x09,0x11,0x201,&len,name,strlen(name)+1); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0x09,0x11,&len,name,strlen(name)+1,NULL); + break; + } + + if (!msg) { + psa50_error_type(); + return 0; + } + if (len < 12) { + debug_message("ERROR: truncated message\n"); + return 0; + } + if (capacity) *capacity = get_int(msg+4); + if (available) *available = get_int(msg+8); + return 1; +} + + +void psa50_free_dir(struct psa50_dir *list) +{ + struct psa50_dir *walk; + + for (walk = list; walk->name; walk++) free((char *) walk->name); + free(list); +} + + +/** + * Get the directory tree of a given flash device. + */ +struct psa50_dir *psa50_list_directory(const char *name) +{ + struct psa50_dir *dir = NULL; + int entries = 0; + unsigned char *msg,*p; + int len,namlen; + char attributes; + char newstr[100]; + + /* Ask the camera for a full directory listing */ + switch (canon_comm_method) { + case CANON_USB: + // fprintf(stderr,"Path: %s\n",name); + newstr[0] = 1; + newstr[1] = 0; + strcat(newstr,name); + namlen=strlen(newstr)+3; + newstr[0] = 0; + + msg = psa50_usb_dialogue(0x0b,0x11,0x202,&len,newstr,namlen); + // fprintf(stderr,"Dir length: %x\n",len); + + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0xb,0x11,&len,"",1,name,strlen(name)+1, + "\x00",2,NULL); + break; + } + + if (!msg) { + psa50_error_type(); + return NULL; + } + if (len < 16) { + return NULL; + } + + switch (canon_comm_method) { + case CANON_USB: + p=msg-1; + if (p >= msg+len) goto error; + break; + case CANON_SERIAL_RS232: + default: + if (!msg[5]) return NULL; + p = msg+15; + if (p >= msg+len) goto error; + for (; *p; p++) + if (p >= msg+len) goto error; + break; + } + + /* This is the main loop, for every entry in the structure */ + while (p[0xb] != 0x00) { + unsigned char *start; + int is_file; + + //fprintf(stderr,"p %p msg+len %p len %d\n",p,msg+len,len); + if (p == msg+len-1) { + if (msg[4]) break; + if (canon_comm_method == CANON_SERIAL_RS232) + msg = psa50_recv_msg(0xb,0x21,&len); + else + debug_message("USB Driver: this message (psa50.c line 1126) should never be printed"); + if (!msg) goto error; + if (len < 5) goto error; + p = msg+4; + } + if (p+2 >= msg+len) goto error; + attributes = p[1]; + is_file = !((p[1] & 0x10) == 0x10); + if (p[1] == 0x10 || is_file) p += 11; + else break; + if (p >= msg+len) goto error; + for (start = p; *p; p++) + if (p >= msg+len) goto error; + dir = realloc(dir,sizeof(*dir)*(entries+2)); + if (!dir) { + perror("realloc"); + exit(1); + } + dir[entries].name = strdup(start); + if (!dir[entries].name) { + perror("strdup"); + exit(1); + } + + memcpy((unsigned char *) &dir[entries].size,start-8,4); + dir[entries].size = byteswap32(dir[entries].size); /* re-order little/big endian */ + memcpy((unsigned char *) &dir[entries].date,start-4,4); + dir[entries].date = byteswap32(dir[entries].date); /* re-order little/big endian */ + dir[entries].is_file = is_file; + dir[entries].attrs = attributes; + // Every directory contains a "null" file entry, so we skip it + if (strlen(dir[entries].name) > 0) { + // Debug output: + if (is_file) debug_message("-"); else debug_message("d"); + if ((dir[entries].attrs & 0x1) == 0x1) debug_message("r- "); else debug_message("rw "); + if ((dir[entries].attrs & 0x20) == 0x20) debug_message(" new "); else debug_message("saved "); + debug_message("%#2x - %8i %.24s %s\n",dir[entries].attrs, dir[entries].size, + asctime(gmtime(&dir[entries].date)), dir[entries].name); + entries++; + } + } + if (dir) dir[entries].name = NULL; + return dir; +error: + debug_message("ERROR: truncated message\n"); + if (dir) psa50_free_dir(dir); + return NULL; +} + + +unsigned char *psa50_get_file_serial(const char *name,int *length) { + unsigned char *file = NULL; + unsigned char *msg; + unsigned char name_len; + unsigned int total = 0,expect = 0,size; + int len,maxfilesize; + + gp_interface_progress(0); + if(receive_error==FATAL_ERROR) { + debug_message("ERROR: can't continue a fatal error condition detected\n"); + return NULL; + } + name_len = strlen(name)+1; + msg = psa50_serial_dialogue(0x1,0x11,&len,"\x00\x00\x00\x00",5, + &name_len,1,"\x00",2,name,strlen(name)+1,NULL); + if (!msg) { + psa50_error_type(); + return NULL; + } + while (msg) { + if (len < 20 || get_int(msg)) { + break; + } + if (!file) { + total = get_int(msg+4); + if(camera.model == CANON_PS_S20) { + maxfilesize=3000000; + } + else { + maxfilesize=2000000; + } + + if (total > maxfilesize) { + debug_message("ERROR: %d is too big\n",total); + break; + } + file = malloc(total); + if (!file) { + perror("malloc"); + break; + } + if (length) *length = total; + } + size = get_int(msg+12); + if (get_int(msg+8) != expect || expect+size > total || size > len-20) { + debug_message("ERROR: doesn't fit\n"); + break; + } + memcpy(file+expect,msg+20,size); + expect += size; + gp_interface_progress(total ? expect/(float) total : 1); + if ((expect == total) != get_int(msg+16)) { + debug_message("ERROR: end mark != end of data\n"); + break; + } + if (expect == total) return file; + msg = psa50_recv_msg(0x1,0x21,&len); + } + free(file); + return NULL; +} + +unsigned char *psa50_get_file_usb(const char *name,int *length) { +#ifdef GPIO_USB + unsigned char *file = NULL; + unsigned char msg[0x3000]; + unsigned char *msgg; + char newstr[100]; + unsigned char *namn; + unsigned int total = 0,expect = 0,size; + int name_len,len,maxfilesize; + + gp_interface_progress(0); + if(receive_error==FATAL_ERROR) { + debug_message("ERROR: can't continue a fatal error condition detected\n"); + return NULL; + } + // *newstr="12345678"; + newstr[0]=0x31; + newstr[1]=0x32; + newstr[2]=0x31; + newstr[3]=0x31; + newstr[4]=0x31; + newstr[5]=0x31; + newstr[6]=0x31; + newstr[7]=0x31; + newstr[8]=0x0; + size=0x2000; + strcat(newstr,name); + debug_message("%s\n",newstr); + name_len=strlen(newstr)+1; + intatpos(newstr,0x0,0x0); // get picture + intatpos(newstr,0x4,size); + msgg = psa50_usb_dialogue(0x01,0x11,0x202,&len,newstr,name_len); + memcpy(msg,msgg,size); + *length=len; + + while (1) { + + if (!file) { + total=len; + if(camera.model == CANON_PS_S20) { + maxfilesize=3000000; + } + else { + maxfilesize=2000000; + } + + if (total > maxfilesize) { + debug_message("ERROR: %d is too big\n",total); + break; + } + file = malloc(total); + if (!file) { + debug_message("ERROR: Alloc problems!\n"); + perror("malloc"); + break; + } + } + + memcpy(file+expect,msg,size); + + expect += size; + + gp_interface_progress(total ? expect/(float) total : 1); + if (expect == total) return file; + + if ((total-expect) <= 0x2000) + size=total-expect; + else + size=0x2000; + + gpio_read(iodev,msg,size); + } + free(file); + return NULL; +#else + debug_message("This computer does not support USB. Please use the RS-232 serial link.\n"); + return NULL; +#endif +} + +unsigned char *psa50_get_file(const char *name,int *length) { + + switch (canon_comm_method) { + case CANON_USB: + return psa50_get_file_usb(name,length); + break; + case CANON_SERIAL_RS232: + default: + return psa50_get_file_serial(name,length); + break; + } +} + +/** + * Returns the thumbnail of a picture. + */ +unsigned char *psa50_get_thumbnail(const char *name,int *length) +{ + unsigned char *file = NULL; + unsigned char *msg; + char newstr[100]; + exifparser exifdat; + unsigned char name_len; + unsigned int total = 0,expect = 0,size; + int len; + + + gp_interface_progress(0); + if(receive_error==FATAL_ERROR) { + debug_message("ERROR: can't continue a fatal error condition detected\n"); + return NULL; + } + + switch (canon_comm_method) { + case CANON_USB: + newstr[0]=0x31; + newstr[1]=0x31; + newstr[2]=0x31; + newstr[3]=0x31; + newstr[4]=0x31; + newstr[5]=0x31; + newstr[6]=0x31; + newstr[7]=0x31; + newstr[8]=0x0; + + strcat(newstr,name); + debug_message("%s\n",newstr); + name_len=strlen(newstr)+1; + intatpos(newstr,0x0,0x1); // get picturethumbnail + intatpos(newstr,0x4,0x3000); + msg = psa50_usb_dialogue(0x01,0x11,0x202,&len,newstr,name_len); + debug_message("File length: %x\n",len); + file = malloc(len); + memcpy(file,msg,len); + *length=len; + break; + case CANON_SERIAL_RS232: + default: + name_len = strlen(name)+1; + msg = psa50_serial_dialogue(0x1,0x11,&len, + "\x01\x00\x00\x00\x00",5, + &name_len,1,"\x00",2,name,strlen(name)+1,NULL); + if (!msg) { + psa50_error_type(); + return NULL; + } + while (msg) { + if (len < 20 || get_int(msg)) { + return NULL; + } + if (!file) { + total = get_int(msg+4); + if (total > 2000000) { /* 2 MB thumbnails ? unlikely ... */ + debug_message("ERROR: %d is too big\n",total); + return NULL; + } + file = malloc(total); + if (!file) { + perror("malloc"); + return NULL; + } + if (length) *length = total; + } + size = get_int(msg+12); + if (get_int(msg+8) != expect || expect+size > total || size > len-20) { + debug_message("ERROR: doesn't fit\n"); + return NULL; + } + memcpy(file+expect,msg+20,size); + expect += size; + gp_interface_progress(total ? expect/(float) total : 1); + if ((expect == total) != get_int(msg+16)) { + debug_message("ERROR: end mark != end of data\n"); + return NULL; + } + if (expect == total) { + /* We finished receiving the file. Parse the header and + return just the thumbnail */ + break; + } + msg = psa50_recv_msg(0x1,0x21,&len); + } + break; + } + + exifdat.header=file; + exifdat.data=file+12; + + debug_message("Got thumbnail, extracting it with the EXIF lib.\n"); + if (exif_parse_data(&exifdat)>0){ + debug_message("Parsed exif data.\n"); + file = exif_get_thumbnail(&exifdat); // Extract Thumbnail + if (file==NULL) { + FILE *fp; + + debug_message("Thumbnail conversion error, saving data to \ +canon-death-dump.dat\n"); + if ((fp=fopen("canon-death-dump.dat","w"))!=NULL){ + fwrite(file,1,total,fp); + fclose(fp); + } + free(file); + return NULL; + } + return file; + } + return NULL; +} + +int psa50_delete_file(const char *name, const char *dir) +{ + unsigned char buf[300]; + unsigned char *msg; + int len,name_len; + + switch (canon_comm_method) { + case CANON_USB: + memcpy(buf,dir,strlen(dir)+1); + memcpy(buf+strlen(dir)+1,name,strlen(name)+1); + name_len=strlen(dir)+strlen(name)+2; + len=0x4; + msg = psa50_usb_dialogue(0x0d,0x11,0x201,&len,buf,name_len); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue(0xd,0x11,&len,dir,strlen(dir)+1, + name,strlen(name)+1,NULL); + break; + } + if (!msg) { + psa50_error_type(); + return -1; + } + return 0; +} + +/* + * return to the calling function a number corresponding + * to the error encountered + */ + +void psa50_error_type() +{ + switch(receive_error) { + case ERROR_LOWBATT: + debug_message("ERROR: no battery left, Bailing out!\n"); + break; + case FATAL_ERROR: + debug_message("ERROR: camera connection lost!\n"); + break; + default: + debug_message("ERROR: malformed message\n"); + break; + } +} diff --git a/camlibs/canon/psa50.h b/camlibs/canon/psa50.h new file mode 100644 index 000000000..39b85df6e --- /dev/null +++ b/camlibs/canon/psa50.h @@ -0,0 +1,123 @@ +/* + * psa50.h - Canon PowerShot A50 "native" operations. + * + * Written 1999 by Wolfgang G. Reissnegger and Werner Almesberger + */ + +#ifndef PSA50_H +#define PSA50_H + +/* Globals for error handling */ +#define NOERROR 0 +#define ERROR_RECEIVED 1 +#define ERROR_ADDRESSED 2 +#define FATAL_ERROR 3 +#define ERROR_LOWBATT 4 + +int receive_error; + +/* Battery status values: */ +#define CAMERA_ON_AC 16 +#define CAMERA_ON_BATTERY 48 +#define CAMERA_POWER_OK 6 +#define CAMERA_POWER_BAD 4 + +/* @@@ change this to canon_dir when merging with other models */ +struct psa50_dir { + const char *name; /* NULL if at end */ + unsigned int size; + time_t date; + char attrs; /* File attributes, see "Protocols" for details */ + int is_file; + void *user; /* user-specific data */ +}; + + +/** + * Various Powershot camera types + */ +typedef enum { + CANON_PS_A5, + CANON_PS_A5_ZOOM, + CANON_PS_A50, + CANON_PS_S10, + CANON_PS_S20, + CANON_PS_A70 +} canonCamModel; + + +struct canon_info +{ + canonCamModel model; + int speed; /* The speed we're using for this camera */ + char ident[32]; /* Model ID string given by the camera */ + char owner[32]; /* Owner name */ + char firmwrev[4]; /* Firmware revision */ +}; + + +extern struct canon_info camera; +extern char psa50_id[]; /* ditto @@@ */ +int A5; + +/* + * Our driver now supports both USB and serial communications + */ +#define CANON_SERIAL_RS232 0 +#define CANON_USB 1 +int canon_comm_method; + + +typedef unsigned long u32; +#ifndef byteswap32 +#ifdef __sparc +#define byteswap32(val) ({ u32 x = val; x = (x << 24) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | (x >> 24); x; }) +#else +#define byteswap32(val) val +#endif +#endif + + +/* + * All functions returning a pointer have malloc'ed the data. The caller must + * free() it when done. + */ + +/** + * Switches the camera on, detects the model and sets its speed + */ +int psa50_ready(void); + +/** + * + */ +char *psa50_get_disk(void); + +/** + * + */ +int psa50_get_battery(int *pwr_status, int *pwr_source); + +/** + * + */ +int psa50_disk_info(const char *name,int *capacity,int *available); + +/** + * + */ +struct psa50_dir *psa50_list_directory(const char *name); +void psa50_free_dir(struct psa50_dir *list); +unsigned char *psa50_get_file(const char *name,int *length); +unsigned char *psa50_get_thumbnail(const char *name,int *length); +int psa50_set_file_attributes(const char *file, const char *dir, char attrs); +int psa50_delete_file(const char *name, const char *dir); +int psa50_end(void); +int psa50_off(void); +int psa50_sync_time(void); +time_t psa50_get_time(void); +int psa50_get_owner_name(void); +int psa50_set_owner_name(const char *name); +void psa50_error_type(void); + +#endif diff --git a/camlibs/canon/serial.c b/camlibs/canon/serial.c new file mode 100644 index 000000000..f9b7b98a8 --- /dev/null +++ b/camlibs/canon/serial.c @@ -0,0 +1,316 @@ +/**************************************************************************** + * + * File: serial.c + * + * Serial communication layer. + * + ****************************************************************************/ + +/**************************************************************************** + * + * include files + * + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "util.h" +#include "psa50.h" + + +/**** new stuff ********/ +#include +extern struct Model *Camera; +int gpio_usb_find_device(int idvendor, int idproduct, struct usb_device **device); +int gpio_usb_msg_write(gpio_device *dev, int value, char *bytes, int size); +int gpio_usb_msg_read(gpio_device *dev, int value, char *bytes, int size); +int gpio_usb_read(gpio_device *dev, char *bytes, int size); +int gpio_usb_write(gpio_device *dev, char *bytes, int size); +/******* new stuff *********/ + + +/**************************************************************************** + * + * static global storage area + * + ****************************************************************************/ + +gpio_device *iodev; +gpio_device_settings settings; + + +void serial_flush_input(void) +{ +} + +void serial_flush_output(void) +{ +} + +/***************************************************************************** + * + * canon_serial_change_speed + * + * change the speed of the communication. + * + * speed - the new speed + * + * Returns 1 on success. + * Returns 0 on any error. + * + ****************************************************************************/ + +int canon_serial_change_speed(int speed) +{ + /* set speed */ + gpio_get_settings(iodev, &settings); + settings.serial.speed = speed; + gpio_set_settings(iodev, settings); + + usleep(70000); + + return 1; +} + + +/***************************************************************************** + * + * canon_serial_get_cts + * + * Gets the status of the CTS (Clear To Send) line on the serial port. + * + * CTS is "1" when the camera is ON, and "0" when it is OFF. + * + * Returns 1 on CTS high. + * Returns 0 on CTS low. + * + ****************************************************************************/ +int canon_serial_get_cts(void) +{ + return gpio_get_pin(iodev,PIN_CTS); +} + + +/***************************************************************************** + * + * canon_serial_init + * + * Initializes the given serial or USB device. + * + * devname - the name of the device to open + * + * Returns 0 on success. + * Returns -1 on any error. + * + ****************************************************************************/ + +int canon_serial_init(const char *devname) +{ +#ifdef GPIO_USB + char msg[65536]; + char mem; + char buffer[65536]; + gpio_device_settings settings; + struct usb_device *udev; +#endif + + debug_message("Initializing the camera.\n"); + + switch (canon_comm_method) { + case CANON_USB: +#ifdef GPIO_USB + + if (gpio_usb_find_device(Camera->idVendor, + Camera->idProduct, &udev)) { + printf("found '%s' @ %d/%d\n", Camera->name, + udev->bus->busnum, udev->devicenum); + } + else + { + printf("Found no camera!\n"); + exit(1); + } + iodev = gpio_new(GPIO_DEVICE_USB); + if (!iodev) + { + return -1; + } + + + settings.usb.udev = udev; + + settings.usb.inep = 0x81; + settings.usb.outep = 0x02; + settings.usb.config = 1; + settings.usb.interface = 0; + settings.usb.altsetting = 0; + + /* canon_send = canon_usb_send; + canon_read = canon_usb_read; */ + + gpio_set_settings(iodev, settings); + if (gpio_open(iodev) < 0) { + fprintf(stderr,"Camera used by other USB device!\n"); + exit(1); + /* return -1; */ + } + + gpio_usb_msg_read(iodev,0x55,msg,1); + // fprintf(stderr,"%c\n",msg[0]); + gpio_usb_msg_read(iodev,0x1,msg,0x58); + gpio_usb_msg_write(iodev,0x11,msg+0x48,0x10); + gpio_read(iodev, buffer, 0x44); + // fprintf(stderr,"Antal b: %x\n",buffer[0]); + if (buffer[0]==0x54) + gpio_read(iodev, buffer, 0x40); + return 0; + /* #else + return -1;*/ +#else + fprintf(stderr,"This computer does not support USB, please try to select 'RS-232'\n" + " in the configuration panel (Configure/Configure camera...).\n"); + return -1; +#endif + break; + case CANON_SERIAL_RS232: + default: + + if (!devname) + { + fprintf(stderr, "INVALID device string (NULL)\n"); + return -1; + } + + debug_message("canon_init_serial(): Using serial port on %s\n", devname); + + iodev = gpio_new(GPIO_DEVICE_SERIAL); + + strcpy(settings.serial.port, devname); + settings.serial.speed = 9600; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + + gpio_set_settings(iodev, settings); /* Sets the serial device name */ + if ( gpio_open(iodev) == GPIO_ERROR) { /* open the device */ + perror("Unable to open the serial port"); + return -1; + } + + return 0; + } +} + +/***************************************************************************** + * + * canon_serial_restore + * + * Restores the saved settings for the serial device + * + * Returns 0 on success. + * Returns -1 on any error. + * + ****************************************************************************/ + +int canon_serial_restore() +{ + + gpio_close(iodev); + + return 0; +} + +/***************************************************************************** + * + * canon_serial_send + * + * Send the given buffer with given length over the serial line. + * + * buf - the raw data buffer to send + * len - the length of the buffer + * sleep - time in usec to wait between characters + * + * Returns 0 on success, -1 on error. + * + ****************************************************************************/ + +int canon_serial_send(const unsigned char *buf, int len, int sleep) +{ + int i; + dump_hex("canon_serial_send()", buf, len); + + if (sleep>0) { + for(i=0;i +#include + +/***************************************************************************** + * + * dump_hex + * + * Dumps a memory area as hex on the screen. + * + * msg - Info message for the dump + * buf - the memory buffer to dump + * len - length of the buffer + * + ****************************************************************************/ + +extern int canon_debug_driver; + +#define NIBBLE(_i) (((_i) < 10) ? '0' + (_i) : 'A' + (_i) - 10) + +void dump_hex(const char *msg, const unsigned char *buf, int len) +{ + int i; + int nlocal; + const unsigned char *pc; + char *out; + const unsigned char *start; + char c; + char line[100]; + + if (canon_debug_driver > 8) { // Only printout with max. debug level (9) + start = buf; + +#if 0 + if (len > 160) + { + fprintf(stderr,"dump n:%d --> 160\n", len); + len = 160; + } +#endif + + fprintf(stderr,"%s: (%d bytes)\n", msg, len); + while (len > 0) + { + sprintf(line, "%08x: ", buf - start); + out = line + 10; + + for (i = 0, pc = buf, nlocal = len; i < 16; i++, pc++) + { + if (nlocal > 0) + { + c = *pc; + + *out++ = NIBBLE((c >> 4) & 0xF); + *out++ = NIBBLE(c & 0xF); + + nlocal--; + } + else + { + *out++ = ' '; + *out++ = ' '; + } /* end else */ + + *out++ = ' '; + } /* end for */ + + *out++ = '-'; + *out++ = ' '; + + for (i = 0, pc = buf, nlocal = len; + (i < 16) && (nlocal > 0); + i++, pc++, nlocal--) + { + c = *pc; + + if ((c < ' ') || (c >= 126)) + { + c = '.'; + } + + *out++ = c; + } /* end for */ + + *out++ = 0; + + fprintf(stderr,"%s\n", line); + + buf += 16; + len -= 16; + } /* end while */ + } /* end 'if debug' */ +} /* end dump */ + +void debug_message(const char * msg, ...) +{ + va_list ap; + + + if (canon_debug_driver) { + va_start(ap, msg); + vfprintf(stderr,msg, ap); + va_end(ap); + } +} + +/**************************************************************************** + * + * End of file: util.c + * + ****************************************************************************/ diff --git a/camlibs/canon/util.h b/camlibs/canon/util.h new file mode 100644 index 000000000..062445d2c --- /dev/null +++ b/camlibs/canon/util.h @@ -0,0 +1,26 @@ +/**************************************************************************** + * + * File: util.h + * + ****************************************************************************/ + +#ifndef _CANON_UTIL_H +#define _CANON_UTIL_H + +/**************************************************************************** + * + * prototypes + * + ****************************************************************************/ + +void dump_hex(const char *msg, const unsigned char *buf, int len); +void debug_message(const char * msg, ...); + + +#endif /* _CANON_UTIL_H */ + +/**************************************************************************** + * + * End of file: util.h + * + ****************************************************************************/