summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTaeksu Shin <taeksu.shin@samsung.com>2012-08-21 18:39:39 +0900
committerTaeksu Shin <taeksu.shin@samsung.com>2012-08-21 18:39:39 +0900
commit2742d6ca5da37180225fab6ef8bf55467956d25c (patch)
treec850c3679b282551927505d3162e6c60118d0609 /lib
parentb5dc236b1575fe5846d01881893b3aaef43ecbcc (diff)
downloadepson-inkjet-printer-escpr-2742d6ca5da37180225fab6ef8bf55467956d25c.tar.gz
epson-inkjet-printer-escpr-2742d6ca5da37180225fab6ef8bf55467956d25c.tar.bz2
epson-inkjet-printer-escpr-2742d6ca5da37180225fab6ef8bf55467956d25c.zip
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am58
-rw-r--r--lib/Makefile.in699
-rw-r--r--lib/epson-cbt.c3004
-rw-r--r--lib/epson-cbt.h218
-rw-r--r--lib/epson-escpage-color.c1210
-rw-r--r--lib/epson-escpage-color.h55
-rw-r--r--lib/epson-escpage-comp.c581
-rw-r--r--lib/epson-escpage-comp.h72
-rw-r--r--lib/epson-escpage-mono.c1551
-rw-r--r--lib/epson-escpage-mono.h54
-rw-r--r--lib/epson-escpage.c1025
-rw-r--r--lib/epson-escpage.h123
-rw-r--r--lib/epson-escpr-api.c5687
-rw-r--r--lib/epson-escpr-api.h114
-rw-r--r--lib/epson-escpr-dbg.c461
-rw-r--r--lib/epson-escpr-dbg.h183
-rw-r--r--lib/epson-escpr-def.h630
-rw-r--r--lib/epson-escpr-err.h333
-rw-r--r--lib/epson-escpr-media.h480
-rw-r--r--lib/epson-escpr-mem.c439
-rw-r--r--lib/epson-escpr-mem.h141
-rw-r--r--lib/epson-escpr-pvt.h400
-rw-r--r--lib/epson-escpr-services.c2376
-rw-r--r--lib/epson-escpr-services.h204
-rw-r--r--lib/epson-layout.c223
-rw-r--r--lib/epson-layout.h63
-rw-r--r--lib/epson-net-lpr.c1091
-rw-r--r--lib/epson-net-lpr.h75
-rw-r--r--lib/epson-net-raw.c937
-rw-r--r--lib/epson-net-raw.h74
-rw-r--r--lib/epson-net-snmp.c2776
-rw-r--r--lib/epson-net-snmp.h77
-rw-r--r--lib/epson-protocol.c1766
-rw-r--r--lib/epson-protocol.h171
-rw-r--r--lib/epson-typedefs.h121
-rw-r--r--lib/epson-usb.c1732
-rw-r--r--lib/epson-usb.h71
-rw-r--r--lib/escpr_def.h218
-rw-r--r--lib/escpr_osdep.h74
39 files changed, 29567 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..3a87ff3
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,58 @@
+################################################################
+# Protocol set for esc/p-r lib
+################################################################
+DEFINES =
+DEFINES += -DGCOMSW_PRT_USE_USB
+DEFINES += -DGCOMSW_PRT_USE_LPR
+DEFINES += -DGCOMSW_PRT_USE_RAW
+
+################################################################
+# Extend function
+################################################################
+DEFINES += -DGCOMSW_CMD_ESCPAGE
+DEFINES += -DGCOMSW_EL_CDLABEL
+DEFINES += -DGCOMSW_EF_MAINTE
+
+################################################################
+# Language
+################################################################
+DEFINES += -DGCOMSW_CMD_ESCPAGE
+DEFINES += -DEPS_FILTER
+
+################################################################
+# Use Async job process
+DEFINES += -DGCOMSW_ASYNCJOB_SUPPORT
+# Use raw file print
+DEFINES += -DGCOMSW_RAWFILE_SUPPORT
+
+
+lib_LTLIBRARIES = libescpr.la
+libescpr_la_CFLAGS = -Wall $(DEFINES)
+## Make sure these will be cleaned even when they're not built by
+## default.
+CLEANFILES = libescpr.la
+libescpr_la_SOURCES = \
+ epson-cbt.c epson-cbt.h \
+ epson-escpage.c epson-escpage.h \
+ epson-escpage-color.c epson-escpage-color.h \
+ epson-escpage-comp.c epson-escpage-comp.h \
+ epson-escpage-mono.c epson-escpage-mono.h \
+ epson-escpr-api.c epson-escpr-api.h \
+ epson-escpr-dbg.c epson-escpr-dbg.h \
+ epson-escpr-def.h \
+ epson-escpr-err.h \
+ epson-escpr-media.h \
+ epson-escpr-mem.c epson-escpr-mem.h \
+ epson-escpr-pvt.h \
+ epson-escpr-services.c epson-escpr-services.h \
+ epson-layout.c epson-layout.h \
+ epson-net-lpr.c epson-net-lpr.h \
+ epson-net-raw.c epson-net-raw.h \
+ epson-net-snmp.c epson-net-snmp.h \
+ epson-protocol.c epson-protocol.h \
+ epson-typedefs.h \
+ epson-usb.c epson-usb.h \
+ escpr_def.h \
+ escpr_osdep.h
+libescpr_la_LDFLAGS = -O2 -version-info 1:0:0
+
diff --git a/lib/Makefile.in b/lib/Makefile.in
new file mode 100644
index 0000000..7748821
--- /dev/null
+++ b/lib/Makefile.in
@@ -0,0 +1,699 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 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.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = lib
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libdir)"
+LTLIBRARIES = $(lib_LTLIBRARIES)
+libescpr_la_LIBADD =
+am_libescpr_la_OBJECTS = libescpr_la-epson-cbt.lo \
+ libescpr_la-epson-escpage.lo \
+ libescpr_la-epson-escpage-color.lo \
+ libescpr_la-epson-escpage-comp.lo \
+ libescpr_la-epson-escpage-mono.lo \
+ libescpr_la-epson-escpr-api.lo libescpr_la-epson-escpr-dbg.lo \
+ libescpr_la-epson-escpr-mem.lo \
+ libescpr_la-epson-escpr-services.lo \
+ libescpr_la-epson-layout.lo libescpr_la-epson-net-lpr.lo \
+ libescpr_la-epson-net-raw.lo libescpr_la-epson-net-snmp.lo \
+ libescpr_la-epson-protocol.lo libescpr_la-epson-usb.lo
+libescpr_la_OBJECTS = $(am_libescpr_la_OBJECTS)
+libescpr_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libescpr_la_CFLAGS) \
+ $(CFLAGS) $(libescpr_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(libescpr_la_SOURCES)
+DIST_SOURCES = $(libescpr_la_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CUPS_FILTER_DIR = @CUPS_FILTER_DIR@
+CUPS_PPD_DIR = @CUPS_PPD_DIR@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LSB_VER = @LSB_VER@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_RELEASE = @PACKAGE_RELEASE@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VENDOR_NAME = @VENDOR_NAME@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+have_cups_config = @have_cups_config@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+################################################################
+# Protocol set for esc/p-r lib
+################################################################
+
+################################################################
+# Extend function
+################################################################
+
+################################################################
+# Language
+################################################################
+
+################################################################
+# Use Async job process
+# Use raw file print
+DEFINES = -DGCOMSW_PRT_USE_USB -DGCOMSW_PRT_USE_LPR \
+ -DGCOMSW_PRT_USE_RAW -DGCOMSW_CMD_ESCPAGE -DGCOMSW_EL_CDLABEL \
+ -DGCOMSW_EF_MAINTE -DGCOMSW_CMD_ESCPAGE -DEPS_FILTER \
+ -DGCOMSW_ASYNCJOB_SUPPORT -DGCOMSW_RAWFILE_SUPPORT
+lib_LTLIBRARIES = libescpr.la
+libescpr_la_CFLAGS = -Wall $(DEFINES)
+CLEANFILES = libescpr.la
+libescpr_la_SOURCES = \
+ epson-cbt.c epson-cbt.h \
+ epson-escpage.c epson-escpage.h \
+ epson-escpage-color.c epson-escpage-color.h \
+ epson-escpage-comp.c epson-escpage-comp.h \
+ epson-escpage-mono.c epson-escpage-mono.h \
+ epson-escpr-api.c epson-escpr-api.h \
+ epson-escpr-dbg.c epson-escpr-dbg.h \
+ epson-escpr-def.h \
+ epson-escpr-err.h \
+ epson-escpr-media.h \
+ epson-escpr-mem.c epson-escpr-mem.h \
+ epson-escpr-pvt.h \
+ epson-escpr-services.c epson-escpr-services.h \
+ epson-layout.c epson-layout.h \
+ epson-net-lpr.c epson-net-lpr.h \
+ epson-net-raw.c epson-net-raw.h \
+ epson-net-snmp.c epson-net-snmp.h \
+ epson-protocol.c epson-protocol.h \
+ epson-typedefs.h \
+ epson-usb.c epson-usb.h \
+ escpr_def.h \
+ escpr_osdep.h
+
+libescpr_la_LDFLAGS = -O2 -version-info 1:0:0
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu lib/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --gnu lib/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ list2=; for p in $$list; do \
+ if test -f $$p; then \
+ list2="$$list2 $$p"; \
+ else :; fi; \
+ done; \
+ test -z "$$list2" || { \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+ }
+
+uninstall-libLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
+ done
+
+clean-libLTLIBRARIES:
+ -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libescpr.la: $(libescpr_la_OBJECTS) $(libescpr_la_DEPENDENCIES)
+ $(libescpr_la_LINK) -rpath $(libdir) $(libescpr_la_OBJECTS) $(libescpr_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-cbt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpage-color.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpage-comp.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpage-mono.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpage.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpr-api.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpr-dbg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpr-mem.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-escpr-services.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-layout.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-net-lpr.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-net-raw.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-net-snmp.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-protocol.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libescpr_la-epson-usb.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+libescpr_la-epson-cbt.lo: epson-cbt.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-cbt.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-cbt.Tpo -c -o libescpr_la-epson-cbt.lo `test -f 'epson-cbt.c' || echo '$(srcdir)/'`epson-cbt.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-cbt.Tpo $(DEPDIR)/libescpr_la-epson-cbt.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-cbt.c' object='libescpr_la-epson-cbt.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-cbt.lo `test -f 'epson-cbt.c' || echo '$(srcdir)/'`epson-cbt.c
+
+libescpr_la-epson-escpage.lo: epson-escpage.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpage.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpage.Tpo -c -o libescpr_la-epson-escpage.lo `test -f 'epson-escpage.c' || echo '$(srcdir)/'`epson-escpage.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpage.Tpo $(DEPDIR)/libescpr_la-epson-escpage.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpage.c' object='libescpr_la-epson-escpage.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpage.lo `test -f 'epson-escpage.c' || echo '$(srcdir)/'`epson-escpage.c
+
+libescpr_la-epson-escpage-color.lo: epson-escpage-color.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpage-color.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpage-color.Tpo -c -o libescpr_la-epson-escpage-color.lo `test -f 'epson-escpage-color.c' || echo '$(srcdir)/'`epson-escpage-color.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpage-color.Tpo $(DEPDIR)/libescpr_la-epson-escpage-color.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpage-color.c' object='libescpr_la-epson-escpage-color.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpage-color.lo `test -f 'epson-escpage-color.c' || echo '$(srcdir)/'`epson-escpage-color.c
+
+libescpr_la-epson-escpage-comp.lo: epson-escpage-comp.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpage-comp.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpage-comp.Tpo -c -o libescpr_la-epson-escpage-comp.lo `test -f 'epson-escpage-comp.c' || echo '$(srcdir)/'`epson-escpage-comp.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpage-comp.Tpo $(DEPDIR)/libescpr_la-epson-escpage-comp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpage-comp.c' object='libescpr_la-epson-escpage-comp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpage-comp.lo `test -f 'epson-escpage-comp.c' || echo '$(srcdir)/'`epson-escpage-comp.c
+
+libescpr_la-epson-escpage-mono.lo: epson-escpage-mono.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpage-mono.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpage-mono.Tpo -c -o libescpr_la-epson-escpage-mono.lo `test -f 'epson-escpage-mono.c' || echo '$(srcdir)/'`epson-escpage-mono.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpage-mono.Tpo $(DEPDIR)/libescpr_la-epson-escpage-mono.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpage-mono.c' object='libescpr_la-epson-escpage-mono.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpage-mono.lo `test -f 'epson-escpage-mono.c' || echo '$(srcdir)/'`epson-escpage-mono.c
+
+libescpr_la-epson-escpr-api.lo: epson-escpr-api.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpr-api.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpr-api.Tpo -c -o libescpr_la-epson-escpr-api.lo `test -f 'epson-escpr-api.c' || echo '$(srcdir)/'`epson-escpr-api.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpr-api.Tpo $(DEPDIR)/libescpr_la-epson-escpr-api.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpr-api.c' object='libescpr_la-epson-escpr-api.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpr-api.lo `test -f 'epson-escpr-api.c' || echo '$(srcdir)/'`epson-escpr-api.c
+
+libescpr_la-epson-escpr-dbg.lo: epson-escpr-dbg.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpr-dbg.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpr-dbg.Tpo -c -o libescpr_la-epson-escpr-dbg.lo `test -f 'epson-escpr-dbg.c' || echo '$(srcdir)/'`epson-escpr-dbg.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpr-dbg.Tpo $(DEPDIR)/libescpr_la-epson-escpr-dbg.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpr-dbg.c' object='libescpr_la-epson-escpr-dbg.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpr-dbg.lo `test -f 'epson-escpr-dbg.c' || echo '$(srcdir)/'`epson-escpr-dbg.c
+
+libescpr_la-epson-escpr-mem.lo: epson-escpr-mem.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpr-mem.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpr-mem.Tpo -c -o libescpr_la-epson-escpr-mem.lo `test -f 'epson-escpr-mem.c' || echo '$(srcdir)/'`epson-escpr-mem.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpr-mem.Tpo $(DEPDIR)/libescpr_la-epson-escpr-mem.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpr-mem.c' object='libescpr_la-epson-escpr-mem.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpr-mem.lo `test -f 'epson-escpr-mem.c' || echo '$(srcdir)/'`epson-escpr-mem.c
+
+libescpr_la-epson-escpr-services.lo: epson-escpr-services.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-escpr-services.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-escpr-services.Tpo -c -o libescpr_la-epson-escpr-services.lo `test -f 'epson-escpr-services.c' || echo '$(srcdir)/'`epson-escpr-services.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-escpr-services.Tpo $(DEPDIR)/libescpr_la-epson-escpr-services.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-escpr-services.c' object='libescpr_la-epson-escpr-services.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-escpr-services.lo `test -f 'epson-escpr-services.c' || echo '$(srcdir)/'`epson-escpr-services.c
+
+libescpr_la-epson-layout.lo: epson-layout.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-layout.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-layout.Tpo -c -o libescpr_la-epson-layout.lo `test -f 'epson-layout.c' || echo '$(srcdir)/'`epson-layout.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-layout.Tpo $(DEPDIR)/libescpr_la-epson-layout.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-layout.c' object='libescpr_la-epson-layout.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-layout.lo `test -f 'epson-layout.c' || echo '$(srcdir)/'`epson-layout.c
+
+libescpr_la-epson-net-lpr.lo: epson-net-lpr.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-net-lpr.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-net-lpr.Tpo -c -o libescpr_la-epson-net-lpr.lo `test -f 'epson-net-lpr.c' || echo '$(srcdir)/'`epson-net-lpr.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-net-lpr.Tpo $(DEPDIR)/libescpr_la-epson-net-lpr.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-net-lpr.c' object='libescpr_la-epson-net-lpr.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-net-lpr.lo `test -f 'epson-net-lpr.c' || echo '$(srcdir)/'`epson-net-lpr.c
+
+libescpr_la-epson-net-raw.lo: epson-net-raw.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-net-raw.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-net-raw.Tpo -c -o libescpr_la-epson-net-raw.lo `test -f 'epson-net-raw.c' || echo '$(srcdir)/'`epson-net-raw.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-net-raw.Tpo $(DEPDIR)/libescpr_la-epson-net-raw.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-net-raw.c' object='libescpr_la-epson-net-raw.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-net-raw.lo `test -f 'epson-net-raw.c' || echo '$(srcdir)/'`epson-net-raw.c
+
+libescpr_la-epson-net-snmp.lo: epson-net-snmp.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-net-snmp.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-net-snmp.Tpo -c -o libescpr_la-epson-net-snmp.lo `test -f 'epson-net-snmp.c' || echo '$(srcdir)/'`epson-net-snmp.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-net-snmp.Tpo $(DEPDIR)/libescpr_la-epson-net-snmp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-net-snmp.c' object='libescpr_la-epson-net-snmp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-net-snmp.lo `test -f 'epson-net-snmp.c' || echo '$(srcdir)/'`epson-net-snmp.c
+
+libescpr_la-epson-protocol.lo: epson-protocol.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-protocol.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-protocol.Tpo -c -o libescpr_la-epson-protocol.lo `test -f 'epson-protocol.c' || echo '$(srcdir)/'`epson-protocol.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-protocol.Tpo $(DEPDIR)/libescpr_la-epson-protocol.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-protocol.c' object='libescpr_la-epson-protocol.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-protocol.lo `test -f 'epson-protocol.c' || echo '$(srcdir)/'`epson-protocol.c
+
+libescpr_la-epson-usb.lo: epson-usb.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -MT libescpr_la-epson-usb.lo -MD -MP -MF $(DEPDIR)/libescpr_la-epson-usb.Tpo -c -o libescpr_la-epson-usb.lo `test -f 'epson-usb.c' || echo '$(srcdir)/'`epson-usb.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libescpr_la-epson-usb.Tpo $(DEPDIR)/libescpr_la-epson-usb.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson-usb.c' object='libescpr_la-epson-usb.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libescpr_la_CFLAGS) $(CFLAGS) -c -o libescpr_la-epson-usb.lo `test -f 'epson-usb.c' || echo '$(srcdir)/'`epson-usb.c
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+ for dir in "$(DESTDIR)$(libdir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-libLTLIBRARIES
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-libLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libLTLIBRARIES clean-libtool ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am \
+ install-libLTLIBRARIES install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-libLTLIBRARIES
+
+
+# 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/lib/epson-cbt.c b/lib/epson-cbt.c
new file mode 100644
index 0000000..e65bd5c
--- /dev/null
+++ b/lib/epson-cbt.c
@@ -0,0 +1,3004 @@
+/*___________________________________ epson-cbt.c ___________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of copyrightable
+ * material and information now allowed by statutory or judicial law or hereinafter
+ * granted, including without limitation, material generated from the software
+ * programs which are displayed on the screen such as icons, screen display looks,
+ * etc.
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson CBT Module */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE cbtCommOpen (void ); */
+/* EPS_INT32 cbtCommClose (void ); */
+/* EPS_ERR_CODE cbtCommChannelOpen (Channel, bRetry ); */
+/* EPS_INT32 cbtCommChannelClose (Channel ); */
+/* EPS_INT32 cbtCommReadData (Channel, Buffer, BuffLen, Size); */
+/* EPS_INT32 cbtCommWriteData (Channel, Buffer, BuffLen, Size); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpr-services.h"
+#include "epson-cbt.h"
+
+/*------------------------------------ Definition -----------------------------------*/
+/*******************************************|********************************************/
+#define CBT_OPENCH_WAIT (50)
+#define CBT_OPENCH_RETRY (50)
+
+/*------------------------------- Local Compiler Switch --------------------------------*/
+/*******************************************|********************************************/
+#define LCOMSW_CBT_SOCKETFUNC_ON 1 /* the socket ID mode (0:OFF 1:ON(Default))*/
+
+#define LCOMSW_CBT_ALLOC_MEM 1 /* Use static memory */
+ /* 0 -> Use static memory */
+ /* 1 -> Use epsFnc.memAlloc() (Default) */
+
+#ifdef EPS_LOG_MODULE_CBT
+#define EPS_LOG_MODULE EPS_LOG_MODULE_CBT
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Print Job/Page Struct */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_PRINT_JOB printJob;
+
+ /*** System Dependent Function (USB Communication) */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_USB_FUNC epsUsbFnc;
+extern EPS_CMN_FUNC epsCmnFnc;
+
+ /*** I/O Channel */
+ /*** -------------------------------------------------------------------------------*/
+EPS_BOOL ioOpenState = EPS_IO_NOT_OPEN; /* Open state of I/O port (Bi-Directional) */
+EPS_BOOL ioDataChState = EPS_IO_NOT_OPEN; /* Open state of Data Channel */
+EPS_BOOL ioControlChState= EPS_IO_NOT_OPEN; /* Open state of Control Channel */
+EPS_BOOL ioOpenUniDirect = EPS_IO_NOT_OPEN; /* Open state of I/O port (Uni-Directional) */
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+/*------------------------ Epson CBT Module Global Variables -------------------------*/
+/*******************************************|********************************************/
+static CBTS_PRNINFO *gpCbtPrnInfo = NULL; /* Printer Information */
+
+/*-------------------------------- Local Definition ---------------------------------*/
+/*******************************************|********************************************/
+#define CBT_DUMYREAD_MAX (128) /* dummy read try max */
+
+/*--------------------- Memory allocation for Epson CBT Module ------------------------*/
+/*******************************************|********************************************/
+#if LCOMSW_CBT_ALLOC_MEM == 0
+static CBTS_PRNINFO sgcbtprninfo;
+static EPS_UINT8 sgreadbuff[CBT_MAX_CH][CBT_MAX_RTMP];
+static EPS_UINT8 sgrtmpbuff[CBT_MAX_CH][CBT_MAX_RTMP];
+static EPS_UINT8 sgwritebuff[CBT_TXPSIZE];
+static EPS_UINT8 sgcbtreadrtnbuff[CBT_MAX_RTMP];
+static EPS_UINT8 sgcbtdatareadbuff[CBT_MAX_RTMP];
+#endif /* LCOMSW_CBT_ALLOC_MEM */
+
+/*------------------------------------ Debug Dump -----------------------------------*/
+/*******************************************|********************************************/
+ /*** ALL Debug Dump Switch for <epson-cbt.> */
+ /*** -------------------------------------------------------------------------------*/
+#define _COMM_DEBUG 0 /* 0: OFF 1: ON */
+#define _CBTDEBUG_ 0 /* 0: OFF 1: ON */
+#define CBT_DBG_ERROR 0 /* 0: OFF 1: ON */
+
+ /*** _COMM_DEBUG --- Communication Module Debug */
+ /***--------------------------------------------------------------------------------*/
+#if _COMM_DEBUG
+#define COMM_DBG_ERROR
+#define CBTDebugPrintf(a) printf a
+#else /* def _COMM_DEBUG */
+#define CBTDebugPrintf(a)
+#endif /* def _COMM_DEBUG */
+
+ /*** _CBTDEBUG_ --- CBT Debug */
+ /***--------------------------------------------------------------------------------*/
+#if _CBTDEBUG_
+#define CBT_DBG_IO
+
+static EPS_INT8 debMsgWork[512];
+static void DebMsgOut(EPS_INT8 *buf)
+{
+#ifdef _WINCE32_TEST_
+ HANDLE fh_Alloc;
+ DWORD wb;
+
+ fh_Alloc = CreateFile(L"\\CBT_LOG.TXT",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
+ OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
+ SetFilePointer(fh_Alloc,0,NULL,FILE_END);
+ WriteFile(fh_Alloc, buf, strlen(buf), &wb, NULL);
+ CloseHandle(fh_Alloc);
+#else /* def _WINCE32_TEST_ */
+ fprintf(stderr,buf);
+#endif /* def _WINCE32_TEST_ */
+}
+#endif /* def _CBTDEBUG_ */
+
+/*-------------------------------- Local Functions ----------------------------------*/
+/*******************************************|********************************************/
+ /*** Communication Module */
+ /*** -------------------------------------------------------------------------------*/
+static EPS_INT32 commOpen (const EPS_USB_DEVICE*, EPS_FILEDSC* );
+static EPS_INT32 commClose (EPS_FILEDSC );
+static EPS_INT32 commOpenChannel (EPS_FILEDSC, EPS_INT32, EPS_BOOL );
+static EPS_INT32 commCloseChannel (EPS_FILEDSC, EPS_INT32 );
+static EPS_INT32 commChChange (EPS_INT32, EPS_UINT8* );
+
+ /*** Mini CBT Engine */
+ /*** -------------------------------------------------------------------------------*/
+static EPS_INT16 EPCBT_Open (EPS_FILEDSC, void*, EPS_WritePortal, EPS_ReadPortal);
+static EPS_INT16 EPCBT_Close (EPS_FILEDSC );
+static EPS_INT16 EPCBT_OpenChannel (EPS_FILEDSC, EPS_UINT8, EPS_BOOL );
+static EPS_INT16 EPCBT_CloseChannel (EPS_FILEDSC, EPS_UINT8 );
+static EPS_INT16 EPCBT_Write (EPS_FILEDSC, EPS_UINT8, const EPS_UINT8*, EPS_INT32*);
+static EPS_INT16 EPCBT_Read (EPS_FILEDSC, EPS_UINT8, EPS_UINT8*, EPS_INT32* );
+#if LCOMSW_CBT_SOCKETFUNC_ON
+static EPS_INT16 EPCBT_GetSocketID (EPS_FILEDSC, EPS_UINT8*, EPS_UINT8*, EPS_INT32 );
+#endif
+static EPS_INT16 CbtWriteRtn (EPS_FILEDSC, CBTS_PRNINFO*, const EPS_UINT8*, EPS_INT32, EPS_INT32*);
+static EPS_INT16 CbtReadRtn (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT8*, EPS_INT32, EPS_INT32*, EPS_UINT8);
+static void CbtDummyRead (EPS_FILEDSC, CBTS_PRNINFO* );
+static void CbtChDummyRead (EPS_FILEDSC, CBTS_PRNINFO*, CBTS_CHINFO* );
+static EPS_INT16 CbtReplyCheck (EPS_UINT8*, EPS_INT32, EPS_UINT8 );
+static EPS_INT16 CbtEpsonPacking (EPS_FILEDSC, CBTS_PRNINFO* );
+static EPS_INT16 CbtInitCommand (EPS_FILEDSC, CBTS_PRNINFO* );
+static EPS_INT32 CbtOpenChannelCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT32*, EPS_UINT32*, EPS_UINT32, EPS_UINT32);
+static EPS_INT16 CbtCloseChannelCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8 );
+static EPS_INT32 CbtCreditReqCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT32, EPS_UINT32);
+static EPS_INT16 CbtCreditCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT32 );
+#if LCOMSW_CBT_SOCKETFUNC_ON
+static EPS_INT16 CbtGetSocketIDCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8*, EPS_INT32, EPS_UINT8*);
+#endif
+static EPS_INT32 CbtDataWrite (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, const EPS_UINT8*, EPS_INT32);
+static EPS_INT16 CbtDataRead (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT8*, EPS_INT32*);
+static EPS_INT16 CbtMemAlloc (void );
+static void CbtMemFree (void );
+static void CbtPutBigEndianByte2 (EPS_UINT32, EPS_UINT8* );
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: cbtCommOpen() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* devinfo EPS_USB_DEVICE I: Pointer to a usb device infomation */
+/* fd EPS_FILEDSC* O: file discripter */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Opened Communication) */
+/* EPSCBT_ERR_2NDOPEN - CBT channels are already opened */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPCBT_ERR_CBT2NDOPEN - CBT channels are already opened */
+/* EPCBT_ERR_MEMORY - Fail to memory allocation */
+/* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
+/* EPCBT_ERR_VERSION - Incompatible version */
+/* EPCBT_ERR_INITFAILED - Not used by EPSON */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
+/* service */
+/* */
+/* Description: */
+/* Opens the communication on the specified. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 cbtCommOpen (
+
+ const EPS_USB_DEVICE* devinfo,
+ EPS_FILEDSC* fd
+){
+
+ EPS_INT32 Ret; /* Return status of internal calls */
+
+ EPS_LOG_FUNCIN;
+
+/*** Open Communication */
+ if ((Ret = commOpen(devinfo, fd)) != EPCBT_ERR_NONE){
+ CBTDebugPrintf(("EPS CBT: Open Failed [%d]\r\n",Ret));
+ EPS_RETURN( Ret );
+ }
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: cbtCommClose() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Closed Communication */
+/* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* */
+/* Description: */
+/* Closes the communication on the active printer. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 cbtCommClose (
+
+ EPS_FILEDSC fd
+
+){
+ EPS_INT32 Ret;
+
+ EPS_LOG_FUNCIN;
+
+ CBTDebugPrintf(("EPS CBT:CLOSE --> Closing Communication on the device\r\n"));
+
+ Ret = commClose(fd);
+
+ if (Ret != EPCBT_ERR_NONE){
+ CBTDebugPrintf(("EPS CBT: Close failed\r\n"));
+ EPS_RETURN( Ret );
+ }
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: cbtCommChannelOpen() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* Channel EPS_INT32 I: Communication Channel */
+/* bRetry EPS_BOOL I: If TRUE, retry open */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Opened Communication) */
+/* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CH2NDOPEN - Channel is already open */
+/* EPCBT_ERR_RPLYPSIZE - Size of packet from OpenChannel is invalid */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* EPCBT_ERR_RESOURCE - Insufficient printer resources for */
+/* OpenChannel */
+/* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
+/* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
+/* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
+/* (0x0001 ? 0x0005 bytes) */
+/* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
+/* No data can be transferred. Channel was */
+/* not opened */
+/* */
+/* Description: */
+/* Open the communication channel. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 cbtCommChannelOpen (
+
+ EPS_FILEDSC fd,
+ EPS_INT32 Channel,
+ EPS_BOOL bRetry
+
+){
+ EPS_INT32 Ret;
+
+ EPS_LOG_FUNCIN;
+
+ if ((Ret = commOpenChannel(fd, Channel, bRetry)) != EPCBT_ERR_NONE){
+
+ if (Channel == EPS_CBTCHANNEL_CTRL) {
+ CBTDebugPrintf(("EPS CBT: Control Channel Open Failed\r\n"));
+ EPS_RETURN( Ret );
+ } else if (Channel == EPS_CBTCHANNEL_DATA) {
+ CBTDebugPrintf(("EPS CBT: Data Channel Open Failed\r\n"));
+ EPS_RETURN( Ret );
+ }
+
+ }
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: cbtCommChannelClose() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* Channel EPS_INT32 I: Communication Channel */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Closed Communication) */
+/* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* */
+/* Description: */
+/* Close the communication channel. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 cbtCommChannelClose (
+
+ EPS_FILEDSC fd,
+ EPS_INT32 Channel
+
+){
+ EPS_INT32 Ret;
+
+ EPS_LOG_FUNCIN;
+
+ if ((Ret = commCloseChannel(fd, Channel)) != EPCBT_ERR_NONE){
+ CBTDebugPrintf(("EPS CBT: Channel Close Failed\r\n"));
+ EPS_RETURN( Ret );
+ }
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: cbtCommReadData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* Channel EPS_INT32 I: Channel-Select */
+/* 00: Data Channel */
+/* 01: Control Channel */
+/* Buffer EPS_UINT8* I: Buffer Pointer for Read Data */
+/* BuffLen EPS_INT32 I: Read Data Buffer Length (bytes) */
+/* Size EPS_INT32* O: Actuall Read Size */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CREDITOVF - Credit over flow */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* EPCBT_ERR_READERROR - Data read error */
+/* */
+/* Description: */
+/* Read the data from printer. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 cbtCommReadData (
+
+ EPS_FILEDSC fd,
+ EPS_INT32 Channel,
+ EPS_UINT8* Buffer,
+ EPS_INT32 BuffLen,
+ EPS_INT32* Size
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 InLen = 0;
+ EPS_UINT8 CBTCh = 0;
+
+ EPS_LOG_FUNCIN;
+
+ if ( ioOpenState == EPS_IO_NOT_OPEN ) /* Open check */
+ Ret = EPSCBT_ERR_NOTOPEN;
+ else
+ {
+ Ret = commChChange( Channel, &CBTCh ); /* channel change */
+ if( Ret == EPCBT_ERR_NONE )
+ {
+ *Size = 0; /* size clear */
+ Ret = EPCBT_Read( fd, CBTCh, NULL, &InLen ); /* Size Get */
+ if ( Ret == EPCBT_ERR_NONE )
+ {
+ if ( InLen > BuffLen ) /* small buffer size ? */
+ InLen = BuffLen;
+ Ret = EPCBT_Read( fd, CBTCh, Buffer, &InLen ); /* Data Get */
+ *Size = InLen;
+ }
+ }
+ }
+
+#ifdef COMM_DBG_ERROR
+ if ( Ret != EPCBT_ERR_NONE )
+ CBTDebugPrintf(("<< ReadData Ret[%d] Size[%d]\r\n", Ret, *Size));
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: cbtCommWriteData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* Channel EPS_INT32 I: Channel-Select */
+/* 00: Data Channel */
+/* 01: Control Channel */
+/* Buffer const EPS_UINT8* I: Buffer Pointer for Write Data */
+/* BuffLen EPS_INT32 I: Write Data Buffer Length (bytes) */
+/* Size EPS_INT32* O: Actuall Write Size */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
+/* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_FNCDISABLE - Function is disable to be completely finished */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_WRITEERROR - Failed to write */
+/* */
+/* Description: */
+/* Write the data to printer. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 cbtCommWriteData (
+
+ EPS_FILEDSC fd,
+ EPS_INT32 Channel,
+ const EPS_UINT8* Buffer,
+ EPS_INT32 BuffLen,
+ EPS_INT32* Size
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 Written;
+ EPS_INT32 RestSize;
+ EPS_UINT8 CBTCh = 0;
+
+ EPS_LOG_FUNCIN;
+
+ CBTDebugPrintf(("EPS CBT : cbtCommWriteData -> ioOpenState == %s\r\n", ioOpenState == EPS_IO_OPEN ? "ON" : "OFF"));
+
+ if ( ioOpenState == EPS_IO_NOT_OPEN ) { /* Open check */
+ Ret = EPSCBT_ERR_NOTOPEN;
+ }
+ else
+ {
+ /* Send Data */
+ Ret = commChChange( Channel, &CBTCh ); /* channel change */
+ if( Ret == EPCBT_ERR_NONE )
+ {
+ *Size = 0; /* size clear */
+ RestSize = BuffLen;
+
+ while ( RestSize > 0 )
+ {
+ Written = RestSize;
+ Ret = EPCBT_Write(fd, CBTCh, &Buffer[*Size], &Written ); /* Write */
+ *Size += Written; /* Set Write Length */
+ RestSize -= Written;
+
+ if( Ret != EPCBT_ERR_NONE )
+ break;
+ }
+ }
+ }
+
+#ifdef COMM_DBG_ERROR
+ if ( Ret != EPCBT_ERR_NONE )
+ CBTDebugPrintf(("<< WriteData Ret[%d] Size[%d]\r\n", Ret, *Size));
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: commOpen() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* devinfo EPS_USB_DEVICE I: Pointer to a usb device infomation */
+/* fd EPS_FILEDSC* O: file discripter */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPSCBT_ERR_2NDOPEN - CBT channels are already opened */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPCBT_ERR_CBT2NDOPEN - CBT channels are already opened */
+/* EPCBT_ERR_MEMORY - Fail to memory allocation */
+/* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
+/* EPCBT_ERR_VERSION - Incompatible version */
+/* EPCBT_ERR_INITFAILED - Not used by EPSON */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
+/* service */
+/* */
+/* Description: */
+/* Opens the communication. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 commOpen (
+
+ const EPS_USB_DEVICE* devinfo,
+ EPS_FILEDSC* fd
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_UINT8 Sid = 0;
+
+ EPS_LOG_FUNCIN;
+
+ if ( ioOpenState == EPS_IO_OPEN ) { /* Open check */
+ Ret = EPSCBT_ERR_2NDOPEN;
+ } else {
+ if ( (*fd = epsUsbFnc.openPortal(devinfo)) == EPS_INVALID_FILEDSC)
+ EPS_RETURN( EPS_ERR_NOT_OPEN_IO );
+
+ /* Open process */
+ Ret = EPCBT_Open(*fd, NULL, epsUsbFnc.writePortal, epsUsbFnc.readPortal); /* Open */
+
+ if ( Ret == EPCBT_ERR_NONE ) {
+ /* channel confirm */
+ Ret = EPCBT_GetSocketID( *fd, &Sid, (EPS_UINT8*)"EPSON-DATA", 10 );
+ if ( Ret == EPCBT_ERR_NONE )
+ Ret = EPCBT_GetSocketID( *fd, &Sid, (EPS_UINT8*)"EPSON-CTRL", 10 );
+
+ if(EPCBT_ERR_NONE != Ret ){
+ EPCBT_Close(*fd);
+ }
+ } else if(EPS_INVALID_FILEDSC != *fd){
+ epsUsbFnc.closePortal(*fd);
+ *fd = EPS_INVALID_FILEDSC;
+ }
+ }
+
+ if ( Ret == EPCBT_ERR_NONE )
+ ioOpenState = EPS_IO_OPEN; /* Open flag On */
+
+ CBTDebugPrintf(("EPS CBT : commOpen -> ioOpenState == %s\r\n", ioOpenState == EPS_IO_OPEN ? "ON" : "OFF"));
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: commClose() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* */
+/* Description: */
+/* Close the communication. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 commClose (
+
+ EPS_FILEDSC fd
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 closePtlState = 0;
+
+ EPS_LOG_FUNCIN;
+
+ if ( ioOpenState == EPS_IO_NOT_OPEN ) /* Open check */
+ Ret = EPSCBT_ERR_NOTOPEN;
+ else
+ {
+ Ret = EPCBT_Close(fd); /* Channel close & cbt exit */
+
+ closePtlState = epsUsbFnc.closePortal(fd);
+
+ ioOpenState = EPS_IO_NOT_OPEN; /* Open flag Off */
+ }
+
+#ifdef COMM_DBG_ERROR
+ if ( Ret != EPCBT_ERR_NONE )
+ CBTDebugPrintf(("<< Close Ret[%d] Close Portal[%d]\r\n", Ret, closePtlState));
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: commOpenChannel() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* Channel EPS_INT32 I: channel number */
+/* bRetry EPS_BOOL I: If TRUE, retry open */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CH2NDOPEN - Channel is already open */
+/* EPCBT_ERR_RPLYPSIZE - Size of packet from OpenChannel is invalid */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* EPCBT_ERR_RESOURCE - Insufficient printer resources for */
+/* OpenChannel */
+/* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
+/* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
+/* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
+/* (0x0001 ? 0x0005 bytes) */
+/* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
+/* No data can be transferred. Channel was */
+/* not opened */
+/* */
+/* Description: */
+/* Opens the communication channel. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 commOpenChannel (
+
+ EPS_FILEDSC fd,
+ EPS_INT32 Channel,
+ EPS_BOOL bRetry
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_UINT8 CBTCh = 0;
+
+ EPS_LOG_FUNCIN;
+
+ if ( ioOpenState == EPS_IO_NOT_OPEN ) { /* Open check */
+ Ret = EPSCBT_ERR_NOTOPEN;
+ } else{
+ Ret = commChChange( Channel, &CBTCh ); /* Channel Change */
+
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ((CBTCh == CBT_CBTCH_DATA) && (ioDataChState == EPS_IO_NOT_OPEN)) {
+ Ret = (EPS_INT16)EPCBT_OpenChannel(fd, CBTCh, bRetry); /* Open Data Channel */
+ if (Ret == EPCBT_ERR_NONE)
+ ioDataChState = EPS_IO_OPEN;
+ }
+
+ if ((CBTCh == CBT_CBTCH_CTRL) && (ioControlChState == EPS_IO_NOT_OPEN)) {
+ Ret = (EPS_INT16)EPCBT_OpenChannel(fd, CBTCh, bRetry); /* Open Control Channel */
+ if (Ret == EPCBT_ERR_NONE)
+ ioControlChState = EPS_IO_OPEN;
+ }
+ }
+ }
+
+#ifdef COMM_DBG_ERROR
+ CBTDebugPrintf(("EPS CBT : commOpenChannel(%x)->%d\r\n", CBTCh, Ret));
+ CBTDebugPrintf(("EPS CBT : commOpenChannel-> ioOpenState == %s\r\n", ioOpenState == EPS_IO_OPEN ? "ON" : "OFF"));
+ if ( Ret != EPCBT_ERR_NONE )
+ CBTDebugPrintf(("<< Close Channel Ret[%d]\r\n", Ret));
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: commCloseChannel() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* Channel EPS_INT32 I: channel number */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* */
+/* Description: */
+/* Close the communication channel. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 commCloseChannel (
+
+ EPS_FILEDSC fd,
+ EPS_INT32 Channel
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_UINT8 CBTCh = 0;
+
+ EPS_LOG_FUNCIN;
+
+ if ( ioOpenState == EPS_IO_NOT_OPEN ) /* Open check */
+ Ret = EPSCBT_ERR_NOTOPEN;
+ else
+ {
+ /* Channel close */
+ Ret = commChChange( Channel, &CBTCh ); /* Channel Change */
+
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ((CBTCh == CBT_CBTCH_DATA) && (ioDataChState == EPS_IO_OPEN)) {
+ Ret = (EPS_INT16)EPCBT_CloseChannel(fd, CBTCh); /* Close Data Channel */
+ /*if (Ret == EPCBT_ERR_NONE) Force reset */
+ ioDataChState = EPS_IO_NOT_OPEN;
+ }
+
+ if ((CBTCh == CBT_CBTCH_CTRL) && (ioControlChState == EPS_IO_OPEN)) {
+ Ret = (EPS_INT16)EPCBT_CloseChannel(fd, CBTCh); /* Close Control Channel */
+ /*if (Ret == EPCBT_ERR_NONE) Force reset */
+ ioControlChState = EPS_IO_NOT_OPEN;
+ }
+ }
+ }
+
+#ifdef COMM_DBG_ERROR
+ if ( Ret != EPCBT_ERR_NONE )
+ CBTDebugPrintf(("<< Close Channel Ret[%d]\r\n", Ret));
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: commChChange() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Channel EPS_INT32 I: Channel number definition */
+/* 00: Data Channel */
+/* 01: Control Channel */
+/* CBTCh EPS_UINT8* O: Pointer to the channel number */
+/* 40: Data Channel */
+/* 02: Control Channel */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* */
+/* Description: */
+/* Set the channel number. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 commChChange (
+
+ EPS_INT32 Channel,
+ EPS_UINT8 *CBTCh
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+
+ EPS_LOG_FUNCIN;
+
+ switch (Channel)
+ {
+ case EPS_CBTCHANNEL_DATA: /* Data Channel */
+ *CBTCh = CBT_CBTCH_DATA;
+ break;
+ case EPS_CBTCHANNEL_CTRL: /* Control Channel */
+ *CBTCh = CBT_CBTCH_CTRL;
+ break;
+ default: /* Error */
+ Ret = EPSCBT_ERR_PARAM;
+ break;
+ }
+
+ EPS_RETURN( Ret );
+}
+
+
+/*******************************************|********************************************/
+/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
+/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
+/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Mini CBT Engine vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
+/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
+/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
+/*******************************************|********************************************/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EPCBT_Open */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pvPortInfo void * I: Port information */
+/* lpWriteFunc EPS_WritePortal I: Pointer to write function */
+/* lpReadFunc EPS_ReadPortal I: Pointer to read functiont information */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_CBT2NDOPEN - CBT channels are already opened */
+/* EPCBT_ERR_MEMORY - Fail to memory allocation */
+/* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
+/* EPCBT_ERR_VERSION - Incompatible version */
+/* EPCBT_ERR_INITFAILED - Not used by EPSON */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* */
+/* Description: */
+/* Opens the CBT communication */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 EPCBT_Open (
+
+ EPS_FILEDSC fd,
+ void* pvPortInfo,
+ EPS_WritePortal lpWriteFunc,
+ EPS_ReadPortal lpReadFunc
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Open (S)\r\n");
+ DebMsgOut(debMsgWork);
+#endif
+
+ if( gpCbtPrnInfo != NULL) {
+ Ret = EPCBT_ERR_CBT2NDOPEN;
+ } else {
+ Ret = CbtMemAlloc( );
+ }
+
+ if ( Ret == EPCBT_ERR_NONE ) {
+ gpCbtPrnInfo->pPortInfo = pvPortInfo;
+ gpCbtPrnInfo->pCbtWRtnFnc = lpWriteFunc;
+ gpCbtPrnInfo->pCbtRRtnFnc = lpReadFunc;
+ gpCbtPrnInfo->Mode = CBT_MODE_CBTOFF;
+
+ CbtDummyRead( fd, gpCbtPrnInfo ); /* Dummy read */
+ Ret = CbtEpsonPacking( fd, gpCbtPrnInfo ); /* send EpsonPackingCommand */
+ if ( Ret == EPCBT_ERR_NONE )
+ Ret = CbtInitCommand( fd, gpCbtPrnInfo ); /* send InitCommand */
+ }
+
+ if ( Ret == EPCBT_ERR_NONE ) { /* OK ? */
+ gpCbtPrnInfo->Mode = CBT_MODE_CBTON;
+ } else {
+ if(Ret != EPCBT_ERR_CBT2NDOPEN)
+ CbtMemFree( );
+ }
+
+#if CBT_DBG_ERROR
+ if( Ret != EPCBT_ERR_NONE ) {
+ sprintf(debMsgWork," <- CBT_Open Ret[%d]\r\n",Ret);
+ DebMsgOut(debMsgWork);
+ }
+#endif
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Open (E)\r\n");
+ DebMsgOut(debMsgWork);
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EPCBT_Close() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* */
+/* Description: */
+/* End CBT mode. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 EPCBT_Close (
+
+ EPS_FILEDSC fd
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 lp1;
+ CBTS_CHINFO* ChPtr;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Close (S)\r\n");
+ DebMsgOut(debMsgWork);
+#endif
+
+ if( gpCbtPrnInfo == NULL) {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ } else {
+ gpCbtPrnInfo->Mode = CBT_MODE_REQOFF;
+
+ for ( lp1 = 1; lp1 < CBT_MAX_CH ; lp1++ ) {
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+
+ if ( ChPtr->No != 0 ) {
+ Ret = CbtCloseChannelCommand( fd, gpCbtPrnInfo, ChPtr->No ); /* Channel Close */
+ }
+ }
+
+ for ( lp1 = 0; lp1 < CBT_MAX_CH ; lp1++ ) {
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+ ChPtr->No = 0;
+ ChPtr->PtSsize = 0;
+ ChPtr->StPsize = 0;
+ ChPtr->CreditP = 0;
+ ChPtr->CreditH = 0;
+ ChPtr->ReadSize = 0;
+ ChPtr->RTmpTop = 0;
+ ChPtr->RTmpEnd = 0;
+ ChPtr->RTmpCnt = 0;
+ }
+
+ gpCbtPrnInfo->Mode = CBT_MODE_CBTOFF;
+ }
+ CbtMemFree( );
+
+#if CBT_DBG_ERROR
+ if( Ret != EPCBT_ERR_NONE ) {
+ sprintf(debMsgWork, " <- CBT_Close Error! Ret[%d]\r\n",Ret);
+ DebMsgOut(debMsgWork);
+ }
+#endif
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Close (E)\r\n");
+ DebMsgOut(debMsgWork);
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EPCBT_OpenChannel */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* SID EPS_UINT8 I: socket id */
+/* bRetry EPS_BOOL I: If TRUE, retry open */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Port is not open */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CH2NDOPEN - Channel is already open */
+/* EPCBT_ERR_RPLYPSIZE - Size of packet from OpenChannel is invalid */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* EPCBT_ERR_RESOURCE - Insufficient printer resources for */
+/* OpenChannel */
+/* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
+/* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
+/* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
+/* (0x0001 ? 0x0005 bytes) */
+/* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
+/* No data can be transferred. Channel was */
+/* not opened */
+/* */
+/* Description: */
+/* Opens the CBT communication. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 EPCBT_OpenChannel (
+
+ EPS_FILEDSC fd,
+ EPS_UINT8 SID,
+ EPS_BOOL bRetry
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_UINT32 PtSsize = 0;
+ EPS_UINT32 StPsize = 0;
+ EPS_INT32 iCredit = 0;
+ EPS_INT32 nOpenRetry = 0;
+ EPS_INT32 lp1;
+ CBTS_CHINFO *ChPtr;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_OpenChannel (S) 0x%02x\r\n", SID);
+ DebMsgOut(debMsgWork);
+#endif
+
+ if( gpCbtPrnInfo == NULL) {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ } else {
+ if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
+ if ( (SID == 0x00) || (SID == 0xff) )
+ Ret = EPCBT_ERR_PARAM;
+ else {
+ for ( lp1 = 1; lp1 < CBT_MAX_CH ; lp1++ ) {
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+ if ( ChPtr->No == SID ) { /* channel open ? */
+ Ret = EPCBT_ERR_CH2NDOPEN;
+ break;
+ }
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( gpCbtPrnInfo->Chinfo[lp1-1].No != 0 ) /* Over flow */
+ Ret = EPCBT_ERR_PARAM;
+ }
+ }
+ } else {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ }
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( SID == CBT_SID_DATA ) {
+ PtSsize = CBT_TXPSIZE;
+ StPsize = CBT_RXPSIZE;
+ } else {
+ PtSsize = CBT_RXPSIZE;
+ StPsize = CBT_RXPSIZE;
+ }
+
+ if(bRetry){
+ for( ; EPCBT_ERR_RESOURCE == (iCredit = CbtOpenChannelCommand(fd, gpCbtPrnInfo, SID, &PtSsize, &StPsize, 0, 0) )
+ && nOpenRetry < CBT_OPENCH_RETRY; nOpenRetry++){
+
+ serDelayThread(CBT_OPENCH_WAIT, &epsCmnFnc);
+ }
+ } else{
+ iCredit = CbtOpenChannelCommand(fd, gpCbtPrnInfo, SID, &PtSsize, &StPsize, 0, 0);
+ }
+
+ if ( iCredit < 0 )
+ Ret = (EPS_INT16)iCredit;
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+
+ if ( ( PtSsize == 0 ) && ( StPsize == 0 ) )
+ Ret = EPCBT_ERR_RPLYPSIZE;
+ else {
+ if ( (0 < PtSsize) && (PtSsize < 6) )
+ Ret = EPCBT_ERR_RPLYPSIZE;
+ else {
+ if ( (0 < StPsize) && (StPsize < 6) )
+ Ret = EPCBT_ERR_RPLYPSIZE;
+ }
+ }
+ }
+
+ if ( Ret == EPCBT_ERR_NONE ) {
+ for ( lp1 = 1; ; lp1++ ) {
+ if ( lp1 >= CBT_MAX_CH ) {
+ Ret = EPCBT_ERR_PARAM;
+ break;
+ }
+
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+
+ if ( ChPtr->No == 0 ) {
+ ChPtr->No = SID;
+ ChPtr->PtSsize = (EPS_INT32)PtSsize;
+ ChPtr->StPsize = (EPS_INT32)StPsize;
+ ChPtr->CreditP = iCredit;
+ ChPtr->CreditH = 0;
+ ChPtr->ReadSize = 0;
+ ChPtr->RTmpTop = 0;
+ ChPtr->RTmpEnd = 0;
+ ChPtr->RTmpCnt = 0;
+ if ( SID == CBT_SID_CTRL ) {
+ CbtChDummyRead( fd, gpCbtPrnInfo, ChPtr ); /* Dummy Read */
+ }
+ break;
+ }
+ }
+ }
+
+#if CBT_DBG_ERROR
+ if( Ret != EPCBT_ERR_NONE ) {
+ sprintf(debMsgWork, " <- EPCBT_OpenChannel Ret[%d] CH[%x]\r\n", Ret,SID);
+ DebMsgOut(debMsgWork);
+ }
+#endif
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_OpenChannel (E) 0x%02x\r\n", SID);
+ DebMsgOut(debMsgWork);
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EPCBT_CloseChannel() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* SID EPS_UINT8 I: Socket ID */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Port is not open */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* */
+/* Description: */
+/* Close the communication channel. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 EPCBT_CloseChannel (
+
+ EPS_FILEDSC fd,
+ EPS_UINT8 SID
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 lp1;
+ CBTS_CHINFO* ChPtr = NULL;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_CloseChannel (S) 0x%02x\r\n", SID);
+ DebMsgOut(debMsgWork);
+#endif
+
+ if( gpCbtPrnInfo == NULL) {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ } else {
+ if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
+ if ( (SID == 0x00) || (SID == 0xff) )
+ Ret = EPCBT_ERR_PARAM;
+ else {
+ for ( lp1 = 1; ; lp1++ ) {
+ if ( lp1 >= CBT_MAX_CH ) {
+ Ret = EPCBT_ERR_CHNOTOPEN;
+ break;
+ }
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+ if ( ChPtr->No == SID )
+ break;
+ }
+ }
+ } else {
+ EPS_RETURN( Ret ); /* return normal end */
+ }
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+ Ret = CbtCloseChannelCommand( fd, gpCbtPrnInfo, SID );
+ /*if ( Ret == EPCBT_ERR_NONE ) { Force reset */
+ ChPtr->No = 0;
+ ChPtr->PtSsize = 0;
+ ChPtr->StPsize = 0;
+ ChPtr->CreditP = 0;
+ ChPtr->CreditH = 0;
+ ChPtr->ReadSize = 0;
+ ChPtr->RTmpTop = 0;
+ ChPtr->RTmpEnd = 0;
+ ChPtr->RTmpCnt = 0;
+ /*} Force reset */
+ }
+
+#if CBT_DBG_ERROR
+ if( Ret != EPCBT_ERR_NONE ) {
+ sprintf(debMsgWork, " <- CBT_CloseChannel Ret[%d] CH[%x]\r\n",Ret,SID);
+ DebMsgOut(debMsgWork);
+ }
+#endif
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_CloseChannel (E) 0x%02x\r\n", SID);
+ DebMsgOut(debMsgWork);
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EPCBT_Write() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* SID EPS_UINT8 I: Channel-Select */
+/* lpBuffer const EPS_UINT8* I: Buffer Pointer for Write Data */
+/* lpSize EPS_INT32* O: Write Data Buffer Length (bytes) */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
+/* EPSCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_FNCDISABLE - Function is disable to be completely finished */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_WRITEERROR - Failed to write */
+/* */
+/* Description: */
+/* Write the data to printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 EPCBT_Write (
+
+ EPS_FILEDSC fd,
+ EPS_UINT8 SID,
+ const EPS_UINT8* lpBuffer,
+ EPS_INT32* lpSize
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 Credit;
+ EPS_INT32 Size;
+ EPS_INT32 Count;
+ EPS_INT32 lp1;
+ EPS_INT32 loopSize;
+ EPS_INT32 SendMaxSize;
+ CBTS_CHINFO* ChPtr = NULL;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Write (S) 0x%02x(%04d)\r\n", SID, *lpSize);
+ DebMsgOut(debMsgWork);
+#endif
+
+ if( gpCbtPrnInfo == NULL) {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ } else {
+ if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
+ if ( (SID == 0x00) || (SID == 0xff) ) {
+ Ret = EPCBT_ERR_PARAM;
+ } else {
+ for ( lp1 = 1; ; lp1++ ) {
+ if ( lp1 >= CBT_MAX_CH ) {
+ Ret = EPCBT_ERR_CHNOTOPEN;
+ break;
+ }
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+ if ( ChPtr->No == SID )
+ break;
+ }
+ }
+ } else {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ }
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if( (ChPtr->PtSsize - 6) < *lpSize)
+ SendMaxSize = ChPtr->PtSsize - 6;
+ else
+ SendMaxSize = *lpSize;
+ loopSize = *lpSize;
+ *lpSize = 0;
+ while(loopSize) {
+
+ if ( ChPtr->CreditP == 0 ) {
+ Credit = CbtCreditReqCommand(fd, gpCbtPrnInfo, SID, CBT_CREDIT_LPT, 0xffff);
+ if ( Credit < 0 )
+ Ret = (EPS_INT16)Credit;
+ else if ( Credit == 0 )
+ Ret = EPCBT_ERR_FNCDISABLE;
+ else
+ ChPtr->CreditP = Credit;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE )
+ break;
+
+ if(SendMaxSize < loopSize)
+ Size = SendMaxSize;
+ else
+ Size = loopSize;
+ Count = CbtDataWrite( fd, gpCbtPrnInfo, SID, &lpBuffer[*lpSize], Size );
+ ChPtr->CreditP -= 1;
+ if ( Count >= 0 ) {
+ *lpSize += Count;
+ loopSize -= Count;
+ } else {
+ Ret = (EPS_INT16)Count;
+ break;
+ }
+ }
+ }
+
+#if CBT_DBG_ERROR
+ if( Ret != EPCBT_ERR_NONE ) {
+ sprintf(debMsgWork, " <- CBT_Write Ret[%d] CH[%x] Size[%d]\r\n",Ret,SID,*lpSize);
+ DebMsgOut(debMsgWork);
+ }
+#endif
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Write (E) 0x%02x(%04d)\r\n", SID, *lpSize);
+ DebMsgOut(debMsgWork);
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EPCBT_Read */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* SID EPS_UINT8 I: Socket ID */
+/* lpBuffer EPS_UINT8* O: Pointer to buffer for read data */
+/* lpSize EPS_INT32* O: Pointer to variable for read data size */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CREDITOVF - Credit over flow */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* EPCBT_ERR_READERROR - Data read error */
+/* */
+/* Description: */
+/* Receive the data from printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 EPCBT_Read (
+
+ EPS_FILEDSC fd,
+ EPS_UINT8 SID,
+ EPS_UINT8* lpBuffer,
+ EPS_INT32* lpSize
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 Size = 0;
+ EPS_INT32 lp1;
+ CBTS_CHINFO* ChPtr = NULL;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Read (S) 0x%02x(%04d)\r\n", SID, *lpSize);
+ DebMsgOut(debMsgWork);
+#endif
+
+ if( gpCbtPrnInfo == NULL) {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ } else {
+ if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
+ if ( (SID == 0x00) || (SID == 0xff) ) {
+ Ret = EPCBT_ERR_PARAM;
+ } else {
+ for ( lp1 = 1; ; lp1++ ) {
+ if ( lp1 >= CBT_MAX_CH ) {
+ Ret = EPCBT_ERR_CHNOTOPEN;
+ break;
+ }
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+ if ( ChPtr->No == SID )
+ break;
+ }
+ }
+ } else {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ }
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( lpBuffer == NULL ) {
+ if ( ChPtr->CreditH == 0 ) {
+ Ret = CbtCreditCommand( fd, gpCbtPrnInfo, SID, 1 );
+ if ( Ret == EPCBT_ERR_NONE )
+ ChPtr->CreditH += 1;
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+ Ret = CbtDataRead( fd, gpCbtPrnInfo, SID, NULL, &Size );
+ *lpSize = Size;
+ }
+ } else {
+ Size = *lpSize;
+ Ret = CbtDataRead( fd, gpCbtPrnInfo, SID, lpBuffer, &Size );
+ *lpSize = Size;
+ }
+ }
+
+#if CBT_DBG_ERROR
+ if( Ret != EPCBT_ERR_NONE ) {
+ sprintf(debMsgWork, " <- CBT_Read Ret[%d] CH[%x] Size[%d]\r\n",Ret,SID,*lpSize);
+ DebMsgOut(debMsgWork);
+ }
+#endif
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_Read (E) 0x%02x(%04d)\r\n", SID, *lpSize);
+ DebMsgOut(debMsgWork);
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EPCBT_GetSocketID */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pSID EPS_UINT8 * I: Socket ID */
+/* pName EPS_UINT8 * I: Parameter Name */
+/* Size EPS_INT32 I: Size of socket ID */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_CBTNOTOPEN - Port is not open */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
+/* service */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* */
+/* Description: */
+/* Gets the socket ID. */
+/* */
+/*******************************************|********************************************/
+#if LCOMSW_CBT_SOCKETFUNC_ON
+static EPS_INT16 EPCBT_GetSocketID (
+
+ EPS_FILEDSC fd,
+ EPS_UINT8* pSID,
+ EPS_UINT8* pName,
+ EPS_INT32 Size
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_UINT8 SocketID = 0;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_GetSocketID (S)\r\n");
+ DebMsgOut(debMsgWork);
+#endif
+
+ if( gpCbtPrnInfo == NULL) {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ } else {
+ if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
+ if ( (pSID == NULL) || (pName == NULL) ) {
+ Ret = EPCBT_ERR_PARAM;
+ }
+ } else {
+ Ret = EPCBT_ERR_CBTNOTOPEN;
+ }
+ }
+ if ( Ret == EPCBT_ERR_NONE ) {
+ Ret = CbtGetSocketIDCommand( fd, gpCbtPrnInfo, pName, Size, &SocketID );
+ if ( Ret == EPCBT_ERR_NONE )
+ *pSID = SocketID;
+ }
+
+#if CBT_DBG_ERROR
+ if( Ret != EPCBT_ERR_NONE ) {
+ sprintf(debMsgWork, " <- CBT_GetSocketID Ret[%d] SID[%02x]\r\n", Ret,*pSID);
+ DebMsgOut(debMsgWork);
+ }
+#endif
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork,"EPCBT_GetSocketID (E)\r\n");
+ DebMsgOut(debMsgWork);
+#endif
+
+ EPS_RETURN( Ret );
+}
+#endif /* def LCOMSW_CBT_SOCKETFUNC_ON */
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtWriteRtn */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* Buff const EPS_UINT8* I: Pointer to the write data buffer */
+/* BuffLen EPS_INT32 I: Size of the write data buffer */
+/* Cnt EPS_INT32* O: Write data size */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_WRITEERROR - Write error */
+/* */
+/* Description: */
+/* Sends the data to the printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtWriteRtn (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ const EPS_UINT8* Buff,
+ EPS_INT32 BuffLen,
+ EPS_INT32* Cnt
+
+){
+ EPS_INT32 Ans;
+#ifdef CBT_DBG_IO
+ EPS_INT32 lp1;
+#endif
+
+ EPS_LOG_FUNCIN;
+
+ Ans = ( pCbtPrnInfo->pCbtWRtnFnc )( fd, (EPS_UINT8 *)Buff, BuffLen, Cnt );
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork," * Write * Size=%4d(%4d) Data= ",BuffLen, *Cnt);
+ DebMsgOut(debMsgWork);
+ for (lp1 = 0; (lp1 < *Cnt); lp1++) {
+ sprintf(debMsgWork,"%02X ",Buff[lp1]);
+ DebMsgOut(debMsgWork);
+ }
+ DebMsgOut("\r\n");
+#endif
+
+ if ( Ans == 0 ){
+ EPS_RETURN( EPCBT_ERR_NONE );
+ }else{
+ EPS_RETURN( EPCBT_ERR_WRITEERROR );
+ }
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtReadRtn */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* SID EPS_UINT8 I: Socket ID */
+/* lpBuffer EPS_UINT8* I: Pointer to the receive data buffer */
+/* BuffSize EPS_INT32 I: Receive data buffer size */
+/* Cnt EPS_INT32 * O: Receive data size */
+/* DummyRead EPS_UINT8 I: Flag for the dummy read */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_PARAM - Parameter error */
+/* EPCBT_ERR_READERROR - Read data error */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* */
+/* Description: */
+/* Recives the data from printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtReadRtn (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8 SID,
+ EPS_UINT8* lpBuffer,
+ EPS_INT32 BuffSize,
+ EPS_INT32* Cnt,
+ EPS_UINT8 DummyRead
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT32 Ans;
+ EPS_INT32 Count = 0;
+ EPS_INT32 lp1;
+ EPS_INT32 PSize = 0;
+ EPS_INT32 Top;
+ EPS_UINT8 RxSID;
+ CBTS_CHINFO *ChSer = NULL;
+ CBTS_CHINFO *ChPtr = NULL;
+ EPS_UINT8 *wRBuff;
+ EPS_INT32 nDlySpan = 10; /* first 10 ms */
+ EPS_INT32 nDlyTotal = 2000; /* total 2000 ms */
+
+ EPS_LOG_FUNCIN;
+
+ wRBuff = pCbtPrnInfo->pCbtReadRtnBuff;
+ if ( DummyRead == CBT_READ_DMY ) {
+ Ans = ( pCbtPrnInfo->pCbtRRtnFnc )( fd, wRBuff, CBT_MAX_RTMP, &Count );
+
+ *Cnt = Count;
+ if ( Ans != 0 ) {
+ Ret = EPCBT_ERR_READERROR;
+ }
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork," * Read * Size=%4d(%4d) Data= ",CBT_MAX_RTMP, Count);
+ DebMsgOut(debMsgWork);
+ for (lp1 = 0; (lp1 < Count); lp1++) {
+ sprintf(debMsgWork,"%02X ",wRBuff[lp1]);
+ DebMsgOut(debMsgWork);
+ }
+ DebMsgOut("\r\n");
+#endif
+
+#ifdef CBT_DBG_READ
+ sprintf(debMsgWork,"<CBT Dummy CbtReadRtn> Req-SID[%02x] Size[%d]\r\n",SID, *Cnt);
+ DebMsgOut(debMsgWork);
+ for (lp1 = 0; lp1 < *Cnt; lp1++) {
+ sprintf(debMsgWork,"%02X ",wRBuff[lp1]);
+ DebMsgOut(debMsgWork);
+ }
+ DebMsgOut("\r\n");
+#endif
+ EPS_RETURN( Ret );
+ }
+
+
+ for ( lp1 = 0; ; lp1++ ) {
+ if ( lp1 >= CBT_MAX_CH ){
+ EPS_RETURN( EPCBT_ERR_PARAM );
+ }
+
+ ChSer = &pCbtPrnInfo->Chinfo[lp1];
+ if ( ChSer->No == SID )
+ break;
+ }
+
+ while(nDlyTotal > 0){
+ if ( ChSer->RTmpCnt > 0 ) {
+ PSize = ChSer->RTmpBuff[(ChSer->RTmpTop+3) % CBT_MAX_RTMP]
+ + (ChSer->RTmpBuff[(ChSer->RTmpTop+2) % CBT_MAX_RTMP] << 8);
+
+ if ( BuffSize < PSize ) {
+ Ret = EPCBT_ERR_PARAM;
+ break;
+ }
+ for ( lp1 = 0; lp1 < PSize; lp1++ ) {
+ lpBuffer[lp1] = ChSer->RTmpBuff[ChSer->RTmpTop];
+ ChSer->RTmpTop = (ChSer->RTmpTop+1) % CBT_MAX_RTMP;
+ ChSer->RTmpCnt = (ChSer->RTmpCnt-1);
+ }
+ *Cnt = PSize;
+ break;
+ }
+
+
+ Ans = ( pCbtPrnInfo->pCbtRRtnFnc )( fd, wRBuff, CBT_MAX_RTMP, &Count );
+
+#ifdef CBT_DBG_IO
+ sprintf(debMsgWork," * Read * Size=%4d(%4d) Data= ",CBT_MAX_RTMP, Count);
+ DebMsgOut(debMsgWork);
+ for (lp1 = 0; (lp1 < Count); lp1++) {
+ sprintf(debMsgWork,"%02X ",wRBuff[lp1]);
+ DebMsgOut(debMsgWork);
+ }
+ DebMsgOut("\r\n");
+#endif
+
+ if ( Count != 0 ) {
+ Top = 0;
+ for ( ;; ) {
+ PSize = wRBuff[Top+3] + (wRBuff[Top+2] << 8);
+ if ( ( Count - Top < 4 ) || ( PSize == 0 ) || ( PSize > Count - Top ) ) {
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ break;
+ }
+ RxSID = wRBuff[Top];
+
+ for ( lp1 = 0; ; lp1++ ) {
+ if ( lp1 >= CBT_MAX_CH ) {
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+ }
+ ChPtr = &pCbtPrnInfo->Chinfo[lp1];
+
+ /* Match channel ? */
+ if ( ChPtr->No == RxSID )
+ break;
+ }
+
+ if ( Ret == EPCBT_ERR_NONE ) {
+
+ ChPtr->CreditH -= 1;
+
+ for ( lp1 = 0; lp1 < PSize; lp1++ ) {
+ ChPtr->RTmpBuff[ChPtr->RTmpEnd] = wRBuff[Top+lp1];
+ ChPtr->RTmpEnd = (ChPtr->RTmpEnd+1) % CBT_MAX_RTMP;
+ ChPtr->RTmpCnt = (ChPtr->RTmpCnt+1);
+ }
+
+ Top += PSize;
+ if ( Top >= Count )
+ break;
+ } else {
+ break;
+ }
+ }
+ continue;
+ } else {
+ if ( Ans != 0 ) {
+ Ret = EPCBT_ERR_READERROR;
+ break;
+ }
+ }
+
+ /* Wait */
+ serDelayThread(nDlySpan, &epsCmnFnc);
+
+ nDlyTotal -= nDlySpan;
+ if(nDlySpan < 200){
+ nDlySpan += nDlySpan/2;
+ if(nDlySpan > 200){
+ nDlySpan = 200; /* max 200ms */
+ }
+ }
+ }
+
+ if ( nDlyTotal < 0 )
+ Ret = EPCBT_ERR_READERROR;
+
+#ifdef CBT_DBG_READ
+ sprintf(debMsgWork,"<CBT CbtReadRtn> Req-SID[%02x] Size[%d]\r\n",SID, *Cnt);
+ DebMsgOut(debMsgWork);
+ for (lp1 = 0; lp1 < *Cnt; lp1++) {
+ sprintf(debMsgWork,"%02X ",lpBuffer[lp1]);
+ DebMsgOut(debMsgWork);
+ }
+ DebMsgOut("\r\n");
+#endif
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtDummyRead */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Try to read data from printer. */
+/* */
+/*******************************************|********************************************/
+static void CbtDummyRead (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo
+
+){
+ EPS_INT32 i = 0;
+ EPS_INT32 Cnt = 0;
+
+ EPS_LOG_FUNCIN;
+
+ for ( i = 0; i < CBT_DUMYREAD_MAX ;i++ ) {
+ if ( CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, NULL, 0, &Cnt, CBT_READ_DMY ) == EPCBT_ERR_NONE ) {
+ if ( Cnt == 0 )
+ break;
+ } else {
+ break;
+ }
+ }
+
+ EPS_RETURN_VOID;
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtChDummyRead */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* ChPtr CBTS_CHINFO* I: Channel */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Try to read by using <ChPtr>. */
+/* */
+/*******************************************|********************************************/
+static void CbtChDummyRead (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ CBTS_CHINFO* ChPtr
+
+){
+ EPS_INT16 Ret;
+ EPS_INT32 Size;
+
+ EPS_LOG_FUNCIN;
+
+ do {
+ Size = 0;
+ if ( ChPtr->CreditH == 0 ) {
+ Ret = CbtCreditCommand( fd, pCbtPrnInfo, ChPtr->No, 1 );
+ if ( Ret == EPCBT_ERR_NONE )
+ ChPtr->CreditH += 1;
+ else
+ break;
+ }
+ Ret = CbtReadRtn( fd, pCbtPrnInfo, ChPtr->No, NULL, 0, &Size, CBT_READ_DMY );
+ if(Size)
+ ChPtr->CreditH -= 1;
+ Size -= 6;
+ } while(Size > 0);
+
+ EPS_RETURN_VOID;
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtReplyCheck */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Reply EPS_UINT8* I: Reply data */
+/* ReplySz EPS_INT32 I: Reply data size */
+/* RpyType EPS_UINT8 I: Reply data type */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* */
+/* Description: */
+/* Checks the CBT command replys. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtReplyCheck (
+
+ EPS_UINT8* Reply,
+ EPS_INT32 ReplySz,
+ EPS_UINT8 RpyType
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+
+ EPS_LOG_FUNCIN;
+
+ if ( ReplySz == 0 ){
+ EPS_RETURN( EPCBT_ERR_NOREPLY );
+ }
+
+ if( ( Reply[0] != 0x00 ) || ( Reply[1] != 0x00 ) || ( Reply[2] != 0x00 ) ){
+ EPS_RETURN( EPCBT_ERR_MULFORMEDPACKET );
+ }
+
+ switch ( Reply[6] ){
+ case CBT_RPY_INIT:
+ if (Reply[3] != CBT_RPY_SIZE_INIT)
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RpyType != CBT_CMD_INIT )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ case CBT_RPY_OPENCHANNEL:
+ if (Reply[3] != CBT_RPY_SIZE_OPENCHANNEL)
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RpyType != CBT_CMD_OPENCHANNEL )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ case CBT_RPY_CLOSECHANNEL:
+ if (Reply[3] != CBT_RPY_SIZE_CLOSECHANNEL)
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RpyType != CBT_CMD_CLOSECHANNEL )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ case CBT_RPY_CREDIT:
+ if (Reply[3] != CBT_RPY_SIZE_CREDIT)
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RpyType != CBT_CMD_CREDIT )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ case CBT_RPY_CREDITREQUEST:
+ if (Reply[3] != CBT_RPY_SIZE_CREDITREQUEST)
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RpyType != CBT_CMD_CREDITREQUEST )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ case CBT_RPY_DEBIT:
+ case CBT_RPY_DEBITREQUEST:
+ case CBT_RPY_CONFIGSOCKET:
+ break;
+
+ case CBT_RPY_EXIT:
+ if (Reply[3] != CBT_RPY_SIZE_EXIT)
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RpyType != CBT_CMD_EXIT )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ case CBT_RPY_GETSOCKETID:
+ if ( RpyType != CBT_CMD_GETSOCKETID )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ case CBT_RPY_GETSERVICENAME:
+ break;
+
+ case CBT_RPY_EPSONPACKING:
+ if (Reply[3] != CBT_RPY_SIZE_EPSONPACKING)
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RpyType != CBT_CMD_EPSONPACKING )
+ Ret = EPCBT_ERR_UEREPLY;
+ break;
+
+ default:
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ }
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtEpsonPacking */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
+/* */
+/* Description: */
+/* Sends EpsonPackingCommand and receives reply. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtEpsonPacking (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 BuffLen = CBT_CMD_SIZE_EPSONPACKING;
+ EPS_INT32 RSize = 0;
+ static const EPS_UINT8 Buff[] = {
+ 0x00,0x00,0x00,0x1b,0x01,0x40,0x45,0x4a,0x4c,0x20,
+ 0x31,0x32,0x38,0x34,0x2e,0x34,0x0a,0x40,0x45,0x4a,
+ 0x4c,0x0a,0x40,0x45,0x4a,0x4c,0x0a
+ };
+ EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
+
+ EPS_LOG_FUNCIN;
+
+ memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
+
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_CBTDISABLE;
+ else {
+ if ( Cnt != BuffLen )
+ Ret = EPCBT_ERR_CBTDISABLE;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* return error end */
+ }
+
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_CBTDISABLE; /* no receive */
+ else {
+ Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_EPSONPACKING );
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if( ( RBuff[7] != 0x00 ) && ( RBuff[7] != 0x02 ) )
+ Ret = EPCBT_ERR_CBTDISABLE;
+ }
+ }
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtInitCommand */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
+/* EPCBT_ERR_VERSION - Incompatible version */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* */
+/* Description: */
+/* Sends init command and receives reply. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtInitCommand (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 BuffLen = CBT_CMD_SIZE_INIT;
+ EPS_INT32 RSize = 0;
+ static const EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_INIT,0x01,0x00,0x00,0x10};
+ EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
+
+ EPS_LOG_FUNCIN;
+
+ memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
+
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL;
+ else {
+ if ( Cnt != BuffLen )
+ Ret = EPCBT_ERR_FATAL;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE )
+ EPS_RETURN( Ret ); /* return error end */
+
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL; /* No receive */
+ else {
+ Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_INIT );
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( RBuff[7] != 0x00 ) {
+ if ( RBuff[7] == 0x01 )
+ Ret = EPCBT_ERR_INITDENIED;
+ else if ( RBuff[7] == 0x02 )
+ Ret = EPCBT_ERR_VERSION;
+ else if ( RBuff[7] == 0x0b )
+ Ret = EPCBT_ERR_INITFAILED;
+ else
+ Ret = EPCBT_ERR_UERESULT;
+ }
+ }
+ }
+
+ EPS_RETURN( Ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtOpenChannelCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Port information */
+/* SID EPS_UINT8 I: Socket ID */
+/* pPtSsz EPS_INT32* O: Primary to secondary packet size */
+/* pStPsz EPS_INT32* O: Secondary to primary packet size */
+/* CreditReq EPS_INT32 I: Credit Requested */
+/* CreditMax EPS_INT32 I: Maximum Outstanding Credit */
+/* */
+/* Return value: */
+/* Credit number - Data packet number that is able to recieve */
+/* by throughing <SID>. */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* EPCBT_ERR_RESOURCE - Insufficient printer resources for OpenChannel*/
+/* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
+/* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
+/* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
+/* (0x0001 ? 0x0005 bytes) */
+/* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
+/* No data can be transferred. Channel was */
+/* not opened */
+/* */
+/* Description: */
+/* Sends the open channel command and receives the reply. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 CbtOpenChannelCommand (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8 SID,
+ EPS_UINT32* pPtSsz,
+ EPS_UINT32* pStPsz,
+ EPS_UINT32 CreditReq,
+ EPS_UINT32 CreditMax
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 BuffLen = CBT_CMD_SIZE_OPENCHANNEL;
+ EPS_INT32 RSize = 0;
+ static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_OPENCHANNEL,0x01,0x00,0x01,0x00,0x00,0,0,0,0,0,0,0,0};
+ EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
+
+ EPS_LOG_FUNCIN;
+
+ memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
+
+ Buff[7] = SID;
+ Buff[8] = SID;
+
+ CbtPutBigEndianByte2(*pPtSsz,&Buff[9]);
+ CbtPutBigEndianByte2(*pStPsz,&Buff[11]);
+ CbtPutBigEndianByte2(CreditReq,&Buff[13]);
+ CbtPutBigEndianByte2(CreditMax,&Buff[15]);
+
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL;
+ else {
+ if ( Cnt != BuffLen )
+ Ret = EPCBT_ERR_FATAL;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* return error end */
+ }
+
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL; /* No receive */
+ else {
+ Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_OPENCHANNEL );
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( (RBuff[7] != 0x00) && (RBuff[7] != 0x06) ) {
+ if ( RBuff[7] == 0x04 )
+ Ret = EPCBT_ERR_RESOURCE;
+ else if ( RBuff[7] == 0x05 )
+ Ret = EPCBT_ERR_OPENCHANNEL;
+ else if ( RBuff[7] == 0x09 )
+ Ret = EPCBT_ERR_CHNOTSUPPORT;
+ else if ( RBuff[7] == 0x0C )
+ Ret = EPCBT_ERR_PACKETSIZE;
+ else if ( RBuff[7] == 0x0D )
+ Ret = EPCBT_ERR_NULLPACKETSZ;
+ else
+ Ret = EPCBT_ERR_UERESULT;
+ }
+ }
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* error end */
+ }
+
+ *pPtSsz = (EPS_UINT32)((RBuff[10] << 8) + RBuff[11]);
+ *pStPsz = (EPS_UINT32)((RBuff[12] << 8) + RBuff[13]);
+ Ret = (RBuff[14] << 8) + RBuff[15];
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtCloseChannelCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Port information */
+/* SID EPS_UINT8 I: Socket ID */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* */
+/* Description: */
+/* Send CloseChannel and receive reply. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtCloseChannelCommand (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8 SID
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 BuffLen = CBT_CMD_SIZE_CLOSECHANNEL;
+ EPS_INT32 RSize = 0;
+ static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_CLOSECHANNEL,0x01,0x00,0x02,0x00,0x00,0x00};
+ EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
+
+ EPS_LOG_FUNCIN;
+
+ memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
+
+ Buff[7] = SID;
+ Buff[8] = SID;
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL;
+ else {
+ if ( Cnt != BuffLen )
+ Ret = EPCBT_ERR_FATAL;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* return error end */
+ }
+
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL; /* No receive */
+ else{
+ Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_CLOSECHANNEL );
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( RBuff[7] != 0x00 ) {
+ if ( RBuff[7] == 0x03 )
+ Ret = EPCBT_ERR_CLOSEDENIED;
+ else if ( RBuff[7] == 0x08 )
+ Ret = EPCBT_ERR_CMDDENIED;
+ else
+ Ret = EPCBT_ERR_UERESULT;
+ }
+ }
+ }
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtCreditReqCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* SID EPS_UINT8 I: SocketID */
+/* CreditReq EPS_INT32 I: Credit Requested */
+/* MaxCredit EPS_INT32 I: Maximum OutStanding Credit */
+/* */
+/* Return value: */
+/* Credit - Success */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* */
+/* Description: */
+/* Request credits and return credit number. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 CbtCreditReqCommand (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8 SID,
+ EPS_UINT32 CreditReq,
+ EPS_UINT32 MaxCredit
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 BuffLen = CBT_CMD_SIZE_CREDITREQUEST;
+ EPS_INT32 RSize = 0;
+ static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_CREDITREQUEST,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00};
+ EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
+
+ EPS_LOG_FUNCIN;
+
+ memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
+
+ Buff[7] = SID;
+ Buff[8] = SID;
+
+ CbtPutBigEndianByte2(CreditReq,&Buff[9]);
+ CbtPutBigEndianByte2(MaxCredit,&Buff[11]);
+
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL;
+ else {
+ if ( Cnt != BuffLen )
+ Ret = EPCBT_ERR_FATAL;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* return error end */
+ }
+
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL; /* No receive */
+ else {
+ Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_CREDITREQUEST );
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( RBuff[7] != 0x00 ) {
+ if ( RBuff[7] == 0x08 )
+ Ret = EPCBT_ERR_CMDDENIED;
+ else
+ Ret = EPCBT_ERR_UERESULT;
+ }
+ }
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* return error end */
+ }
+
+ Ret = ( RBuff[11] + (RBuff[10] << 8) );
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtCreditCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* SID EPS_UINT8 I: SocketID */
+/* Credit EPS_INT32 I: Credit */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_CREDITOVF - Credit over flow */
+/* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* EPCBT_ERR_NOREPLY - No reply from printer */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
+/* */
+/* Description: */
+/* Open the communication channel. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtCreditCommand (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8 SID,
+ EPS_UINT32 Credit
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 BuffLen = CBT_CMD_SIZE_CREDIT;
+ EPS_INT32 RSize = 0;
+ static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_CREDIT,0x01,0x00,0x03,0x00,0x00,0x00,0x00};
+ EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
+
+ EPS_LOG_FUNCIN;
+
+ memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
+
+ Buff[7] = SID;
+ Buff[8] = SID;
+
+ CbtPutBigEndianByte2(Credit,&Buff[9]);
+
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL;
+ else {
+ if ( Cnt != BuffLen )
+ Ret = EPCBT_ERR_FATAL;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* return error end */
+ }
+
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
+
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL; /* No receive */
+ else {
+ Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_CREDIT );
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( RBuff[7] != 0x00 ) {
+ if ( RBuff[7] == 0x07 )
+ Ret = EPCBT_ERR_CREDITOVF;
+ else if ( RBuff[7] == 0x08 )
+ Ret = EPCBT_ERR_CMDDENIED;
+ else
+ Ret = EPCBT_ERR_UERESULT;
+ }
+ }
+ }
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtGetSocketIDCommand */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* lpNamepName EPS_UINT8 * I: Parameter Name */
+/* Size EPS_INT32 I: Size of socket ID */
+/* SocketID EPS_UINT8 * O: SocketID */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_FATAL - Fatal communication error */
+/* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
+/* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
+/* service */
+/* EPCBT_ERR_UERESULT - Undefined result value */
+/* */
+/* Description: */
+/* Sends GetSocketID and receives reply. */
+/* */
+/*******************************************|********************************************/
+#if LCOMSW_CBT_SOCKETFUNC_ON
+static EPS_INT16 CbtGetSocketIDCommand (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8* lpName,
+ EPS_INT32 Size,
+ EPS_UINT8* SocketID
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 BuffLen;
+ EPS_INT32 lp1;
+ EPS_INT32 RSize = 0;
+ EPS_UINT8 Buff[CBT_CMD_SIZE_GETSOCKETID + 40];
+ EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
+
+ EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ memset(Buff, 0, CBT_CMD_SIZE_GETSOCKETID + 40);
+ memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
+
+ BuffLen = CBT_CMD_SIZE_GETSOCKETID + Size;
+
+ Buff[0] = 0x00;
+ Buff[1] = 0x00;
+ Buff[2] = 0x00;
+ Buff[3] = (EPS_UINT8)BuffLen;
+ Buff[4] = 0x01;
+ Buff[5] = 0x00;
+ Buff[6] = 0x09;
+
+/*** Sends GetSocketID and receives reply */
+ for ( lp1 = 0; lp1 < Size; lp1++ )
+ Buff[7+lp1] = lpName[lp1];
+
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
+
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL;
+ else {
+ if (Cnt != BuffLen)
+ Ret = EPCBT_ERR_FATAL;
+ }
+
+ if ( Ret != EPCBT_ERR_NONE ){
+ EPS_RETURN( Ret ); /* return error end */
+ }
+
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_FATAL; /* No receive */
+ else {
+ Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_GETSOCKETID );
+ if ( Ret == EPCBT_ERR_NONE ) {
+ if ( RBuff[3] != (Size + CBT_RPY_SIZE_GETSOCKETID) )
+ Ret = EPCBT_ERR_MULFORMEDPACKET;
+ else if ( RBuff[7] != 0x00 ) {
+ if ( RBuff[7] == 0x0A )
+ Ret = EPCBT_ERR_NOSERVICE;
+ else
+ Ret = EPCBT_ERR_UERESULT;
+ } else {
+ *SocketID = RBuff[8];
+ }
+ }
+ }
+
+ EPS_RETURN( Ret );
+}
+#endif /* def LCOMSW_CBT_SOCKETFUNC_ON */
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtDataWrite() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* SID EPS_UINT8 I: SocketID */
+/* lpBuffer const EPS_UINT8* I: Pointer to the write data buffer */
+/* Size EPS_INT32 I: Size of the write data buffer */
+/* */
+/* Return value: */
+/* Actually Write Size - Success */
+/* EPCBT_ERR_WRITEERROR - Failed to write */
+/* */
+/* Description: */
+/* Send data to printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 CbtDataWrite (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8 SID,
+ const EPS_UINT8* lpBuffer,
+ EPS_INT32 Size
+
+){
+ EPS_INT32 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_UINT32 BuffLen;
+ EPS_UINT32 lp1;
+ EPS_UINT8* Buff;
+
+ EPS_LOG_FUNCIN;
+
+ Buff = pCbtPrnInfo->pWriteBuff;
+ *(Buff + 0) = SID;
+ *(Buff + 1) = SID;
+
+ /* check packet size and Control */
+ if( (Size+6) > CBT_TXPSIZE)
+ BuffLen = CBT_TXPSIZE;
+ else
+ BuffLen = (EPS_UINT32)(Size + 6);
+
+ CbtPutBigEndianByte2(BuffLen, (Buff+2));
+ *(Buff + 4) = 0;
+ *(Buff + 5) = 0x01; /* end data */
+
+ Buff += 6;
+ for ( lp1=6; lp1<BuffLen; lp1++ )
+ *Buff++ = *lpBuffer++;
+
+ Ans = CbtWriteRtn( fd, pCbtPrnInfo, pCbtPrnInfo->pWriteBuff, (EPS_INT32)BuffLen, &Cnt );
+
+ Ret = Cnt - 6;
+ if (Ret < 0)
+ Ret = EPCBT_ERR_WRITEERROR;
+ else
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_WRITEERROR;
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtDataRead */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
+/* SID EPS_UINT8 I: Socket ID */
+/* lpBuffer EPS_UINT8* O: Pointer to buffer for read data */
+/* Size EPS_INT32* O: Pointer to variable for read data size */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
+/* EPCBT_ERR_READERROR - Data read error */
+/* */
+/* Description: */
+/* Read data from printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtDataRead (
+
+ EPS_FILEDSC fd,
+ CBTS_PRNINFO* pCbtPrnInfo,
+ EPS_UINT8 SID,
+ EPS_UINT8* lpBuffer,
+ EPS_INT32* Size
+
+){
+ EPS_INT16 Ret = EPCBT_ERR_NONE;
+ EPS_INT16 Ans;
+ EPS_INT32 Cnt = 0;
+ EPS_INT32 lp1;
+ CBTS_CHINFO* ChPtr = NULL;
+ EPS_UINT8* RBuff;
+ EPS_UINT8* SBuff;
+
+ EPS_LOG_FUNCIN;
+
+ for ( lp1 = 0; ; lp1++ ) {
+ if ( lp1 >= CBT_MAX_CH ){
+ EPS_RETURN( EPCBT_ERR_CHNOTOPEN );
+ }
+
+ ChPtr = &pCbtPrnInfo->Chinfo[lp1];
+ if ( ChPtr->No == SID ) /* channel open ? */
+ break;
+ }
+
+ SBuff = ChPtr->ReadBuff;
+ if ( lpBuffer == NULL ) {
+ RBuff = pCbtPrnInfo->pCbtDataReadBuff;
+ Ans = CbtReadRtn( fd, pCbtPrnInfo, SID, RBuff, CBT_MAX_RTMP, &Cnt, CBT_READ_NORMAL );
+ if ( Cnt > 6 ) {
+ Cnt -= 6;
+ RBuff += 6;
+ SBuff += ChPtr->ReadSize;
+ for ( lp1 = 0; lp1 < Cnt; lp1++ )
+ *SBuff++ = *RBuff++;
+
+ ChPtr->ReadSize += Cnt;
+ } else {
+ if ( Ans != EPCBT_ERR_NONE )
+ Ret = EPCBT_ERR_READERROR;
+ }
+ *Size = ChPtr->ReadSize;
+ } else {
+ RBuff = lpBuffer;
+ /* Buffer Size Check */
+ if ( *Size > ChPtr->ReadSize )
+ *Size = ChPtr->ReadSize;
+ for ( lp1 = 0; lp1 < *Size; lp1++ )
+ *RBuff++ = *SBuff++;
+ ChPtr->ReadSize = 0;
+ }
+
+ EPS_RETURN( Ret );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtMemAlloc */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* - void - */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPCBT_ERR_MEMORY - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocates the memory for CBT modules. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 CbtMemAlloc (
+
+ void
+
+){
+ EPS_INT32 lp1;
+ CBTS_CHINFO *ChPtr;
+
+#if LCOMSW_CBT_ALLOC_MEM
+ gpCbtPrnInfo = (CBTS_PRNINFO*)EPS_ALLOC(sizeof(CBTS_PRNINFO));
+ if(!gpCbtPrnInfo)
+ return EPCBT_ERR_MEMORY;
+ memset(gpCbtPrnInfo, 0, sizeof(CBTS_PRNINFO));
+#else /* LCOMSW_CBT_ALLOC_MEM */
+ gpCbtPrnInfo = &sgcbtprninfo;
+#endif /* LCOMSW_CBT_ALLOC_MEM */
+
+ /* clear */
+ gpCbtPrnInfo->pPortInfo = NULL;
+ gpCbtPrnInfo->pWriteBuff = NULL;
+ gpCbtPrnInfo->pCbtReadRtnBuff = NULL;
+ gpCbtPrnInfo->pCbtDataReadBuff = NULL;
+ for ( lp1 = 0; lp1 < CBT_MAX_CH; lp1++ ) {
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+ ChPtr->No = (EPS_UINT8)(lp1 == 0 ? CBT_SID_MAIN : 0);
+ ChPtr->PtSsize = 0;
+ ChPtr->StPsize = 0;
+ ChPtr->CreditP = 0;
+ ChPtr->CreditH = 0;
+ ChPtr->ReadSize = 0;
+ ChPtr->ReadBuff = NULL;
+ ChPtr->RTmpBuff = NULL;
+ ChPtr->RTmpTop = 0;
+ ChPtr->RTmpEnd = 0;
+ ChPtr->RTmpCnt = 0;
+ }
+
+#if LCOMSW_CBT_ALLOC_MEM
+ gpCbtPrnInfo->pWriteBuff = (EPS_UINT8*)EPS_ALLOC(CBT_TXPSIZE);
+ if(!gpCbtPrnInfo->pWriteBuff)
+ return EPCBT_ERR_MEMORY;
+ gpCbtPrnInfo->pCbtReadRtnBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
+ if(!gpCbtPrnInfo->pCbtReadRtnBuff)
+ return EPCBT_ERR_MEMORY;
+ gpCbtPrnInfo->pCbtDataReadBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
+ if(!gpCbtPrnInfo->pCbtDataReadBuff)
+ return EPCBT_ERR_MEMORY;
+#else /* LCOMSW_CBT_ALLOC_MEM */
+ gpCbtPrnInfo->pWriteBuff = (EPS_UINT8*)&sgwritebuff[0];
+ gpCbtPrnInfo->pCbtReadRtnBuff = (EPS_UINT8*)&sgcbtreadrtnbuff[0];
+ gpCbtPrnInfo->pCbtDataReadBuff = (EPS_UINT8*)&sgcbtdatareadbuff[0];
+#endif /* LCOMSW_CBT_ALLOC_MEM */
+
+ for ( lp1 = 0; lp1 < CBT_MAX_CH; lp1++ ) {
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+
+#if LCOMSW_CBT_ALLOC_MEM
+ ChPtr->ReadBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
+ if(!ChPtr->ReadBuff)
+ return EPCBT_ERR_MEMORY;
+ ChPtr->RTmpBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
+ if(!ChPtr->RTmpBuff)
+ return EPCBT_ERR_MEMORY;
+#else /* LCOMSW_CBT_ALLOC_MEM */
+ ChPtr->ReadBuff = (EPS_UINT8*)&sgreadbuff[lp1][0];
+ ChPtr->RTmpBuff = (EPS_UINT8*)&sgrtmpbuff[lp1][0];
+#endif /* LCOMSW_CBT_ALLOC_MEM */
+
+ }
+
+ return EPCBT_ERR_NONE;
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtMemFree */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* - void - */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Frees the memory for CBT modules. */
+/* */
+/*******************************************|********************************************/
+static void CbtMemFree (
+
+ void
+
+){
+ EPS_INT32 lp1;
+ CBTS_CHINFO *ChPtr;
+
+ if(!gpCbtPrnInfo) {
+ return;
+ }
+
+ for ( lp1 = 0; lp1 < CBT_MAX_CH; lp1++ ) {
+ ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
+#if LCOMSW_CBT_ALLOC_MEM
+ EPS_SAFE_RELEASE(ChPtr->ReadBuff);
+ EPS_SAFE_RELEASE(ChPtr->RTmpBuff);
+#else /* LCOMSW_CBT_ALLOC_MEM */
+ ChPtr->ReadBuff = NULL;
+ ChPtr->RTmpBuff = NULL;
+#endif /* LCOMSW_CBT_ALLOC_MEM */
+
+ }
+
+#if LCOMSW_CBT_ALLOC_MEM
+ EPS_SAFE_RELEASE(gpCbtPrnInfo->pWriteBuff);
+ EPS_SAFE_RELEASE(gpCbtPrnInfo->pCbtReadRtnBuff);
+ EPS_SAFE_RELEASE(gpCbtPrnInfo->pCbtDataReadBuff);
+ EPS_SAFE_RELEASE(gpCbtPrnInfo);
+#else /* LCOMSW_CBT_ALLOC_MEM */
+ gpCbtPrnInfo->pWriteBuff = NULL;
+ gpCbtPrnInfo->pCbtReadRtnBuff = NULL;
+ gpCbtPrnInfo->pCbtDataReadBuff = NULL;
+ gpCbtPrnInfo = NULL;
+#endif /* LCOMSW_CBT_ALLOC_MEM */
+
+ return;
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CbtPutBigEndianByte2() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* value EPS_INT32 I: same value */
+/* buf[2] EPS_UINT8 I/O: Big endian value */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Change input value to the big endian value. */
+/* */
+/*******************************************|********************************************/
+static void CbtPutBigEndianByte2 (
+
+ EPS_UINT32 value,
+ EPS_UINT8 *buf
+
+){
+
+/*** Change 2 bytes value to the big endianness */
+ EPS_UINT16 value2byte = (EPS_UINT16)value;
+
+ buf[0] = (EPS_UINT8)((value2byte >> 8) & 0x00ff);
+ buf[1] = (EPS_UINT8)((value2byte ) & 0x00ff);
+
+}
+
+/*___________________________________ epson-cbt.c ____________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
diff --git a/lib/epson-cbt.h b/lib/epson-cbt.h
new file mode 100644
index 0000000..936ae02
--- /dev/null
+++ b/lib/epson-cbt.h
@@ -0,0 +1,218 @@
+/*___________________________________ epson-cbt.h ___________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson CBT Module Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef _EPSON_CBT_H_
+#define _EPSON_CBT_H_
+#ifdef __cplusplus
+extern "C" {
+#endif /* def __cplusplus */
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+#include "epson-escpr-def.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+ /*** Socket ID */
+ /*** -------------------------------------------------------------------------------*/
+#define CBT_CBTCH_DATA 0x40 /* CBT Data Channel */
+#define CBT_CBTCH_CTRL 0x02 /* CBT Control Channel */
+
+ /*** CBT Module Global Variables */
+ /*** -------------------------------------------------------------------------------*/
+#define CBT_MAX_CH 3 /* Channel Count */
+#define CBT_MAX_RTMP 512 /* receive data work buffer size */
+
+#define CBT_SID_MAIN 0x00 /* Main Channel */
+#define CBT_SID_CTRL 0x02 /* Control Channel */
+#define CBT_SID_DATA 0x40 /* data channel (40H) */
+
+#define CBT_TXPSIZE 4096 /* JOB data packet size (4090+6) */
+#define CBT_RXPSIZE 512 /* ReverseData packet size */
+
+#define CBT_CREDIT_LPT 0x0080 /* Printer credit */
+#define CBT_CREDIT_DEF 0x0008 /* Host Credit */
+
+#define CBT_CMDREPLY_BUFFSZ 64 /* Command Reply Data Buffer size */
+
+#define CBT_READ_DMY 0 /* Read Option: Dummy Read */
+#define CBT_READ_NORMAL 1 /* Read Option: Normal Read */
+
+ /*** CBT Mode */
+ /*** -------------------------------------------------------------------------------*/
+#define CBT_MODE_CBTOFF 0 /* CBT Mode Off */
+#define CBT_MODE_CBTON 1 /* CBT Mode On */
+#define CBT_MODE_REQOFF 2 /* Request Off */
+#define CBT_MODE_CBTERR 3 /* CBT Error */
+
+ /*** Command Packet Length */
+ /*** -------------------------------------------------------------------------------*/
+#define CBT_CMD_SIZE_INIT 0x08 /* Init Command */
+#define CBT_CMD_SIZE_OPENCHANNEL 0x11 /* OpenChannel Command */
+#define CBT_CMD_SIZE_CLOSECHANNEL 0x0A /* CloseChannel Command */
+#define CBT_CMD_SIZE_CREDIT 0x0B /* Credit Command */
+#define CBT_CMD_SIZE_CREDITREQUEST 0x0D /* CreditRequest Command */
+#define CBT_CMD_SIZE_EXIT 0x07 /* Exit Command */
+#define CBT_CMD_SIZE_GETSOCKETID 0x07 /* GetSoketID Command (7-47) */
+#define CBT_CMD_SIZE_GETSERVICENAME 0x08 /* GetServiceName Command */
+#define CBT_CMD_SIZE_ERROR 0x0A /* Error Command */
+#define CBT_CMD_SIZE_EPSONPACKING 0x1B /* EpsonPackingCommand Command */
+
+#define CBT_RPY_SIZE_INIT 0x09 /* InitReply */
+#define CBT_RPY_SIZE_OPENCHANNEL 0x10 /* OpenChannelReply */
+#define CBT_RPY_SIZE_CLOSECHANNEL 0x0A /* CloseChannelReply */
+#define CBT_RPY_SIZE_CREDIT 0x0A /* CreditReply */
+#define CBT_RPY_SIZE_CREDITREQUEST 0x0C /* CreditRequestReply */
+#define CBT_RPY_SIZE_EXIT 0x08 /* ExitReply */
+#define CBT_RPY_SIZE_GETSOCKETID 0x09 /* GetSoketIDReply */
+#define CBT_RPY_SIZE_GETSERVICENAME 0x09 /* GetServiceNameReply */
+#define CBT_RPY_SIZE_EPSONPACKING 0x08 /* EpsonPackingCommandReply */
+
+ /*** CBT Command */
+ /*** -------------------------------------------------------------------------------*/
+#define CBT_CMD_INIT 0x00
+#define CBT_CMD_OPENCHANNEL 0x01
+#define CBT_CMD_CLOSECHANNEL 0x02
+#define CBT_CMD_CREDIT 0x03
+#define CBT_CMD_CREDITREQUEST 0x04
+#define CBT_CMD_DEBIT 0x05
+#define CBT_CMD_DEBITREQUEST 0x06
+#define CBT_CMD_CONFIGSOCKET 0x07
+#define CBT_CMD_EXIT 0x08
+#define CBT_CMD_GETSOCKETID 0x09
+#define CBT_CMD_GETSERVICENAME 0x0A
+#define CBT_CMD_EPSONPACKING 0x45
+#define CBT_CMD_CBT_ERROR 0x7F
+#define CBT_CMD_CBT_NONE 0xFF
+
+ /*** Reply Command */
+ /*** -------------------------------------------------------------------------------*/
+#define CBT_RPY_INIT 0x80
+#define CBT_RPY_OPENCHANNEL 0x81
+#define CBT_RPY_CLOSECHANNEL 0x82
+#define CBT_RPY_CREDIT 0x83
+#define CBT_RPY_CREDITREQUEST 0x84
+#define CBT_RPY_DEBIT 0x85
+#define CBT_RPY_DEBITREQUEST 0x86
+#define CBT_RPY_CONFIGSOCKET 0x87
+#define CBT_RPY_EXIT 0x88
+#define CBT_RPY_GETSOCKETID 0x89
+#define CBT_RPY_GETSERVICENAME 0x8A
+#define CBT_RPY_EPSONPACKING 0xC5
+
+/*----------------------------------- Error Code -------------------------------------*/
+/*******************************************|********************************************/
+#define EPCBT_ERR_INITDENIED -1 /* Printer Result=0x01 */
+#define EPCBT_ERR_VERSION -2 /* Printer Result=0x02 */
+#define EPCBT_ERR_CLOSEDENIED -3 /* Printer Result=0x03 */
+#define EPCBT_ERR_RESOURCE -4 /* Printer Result=0x04 */
+#define EPCBT_ERR_OPENCHANNEL -5 /* Printer Result=0x05 */
+#define EPCBT_ERR_CHOPENDED -6 /* Printer Result=0x06 */
+#define EPCBT_ERR_CREDITOVF -7 /* Printer Result=0x07 */
+#define EPCBT_ERR_CMDDENIED -8 /* Printer Result=0x08 */
+#define EPCBT_ERR_CHNOTSUPPORT -9 /* Printer Result=0x09 */
+#define EPCBT_ERR_NOSERVICE -10 /* Printer Result=0x0A */
+#define EPCBT_ERR_INITFAILED -11 /* Printer Result=0x0B */
+#define EPCBT_ERR_PACKETSIZE -12 /* Printer Result=0x0C */
+#define EPCBT_ERR_NULLPACKETSZ -13 /* Printer Result=0x0D */
+
+#define EPCBT_ERR_PARAM -20 /* Parameter Error */
+#define EPCBT_ERR_MEMORY -21 /* Memory Error */
+#define EPCBT_ERR_CBTNOTOPEN -22 /* Port Not Open */
+#define EPCBT_ERR_CBT2NDOPEN -23 /* Port end Open error */
+#define EPCBT_ERR_CHNOTOPEN -24 /* Channel Not Open or Close */
+#define EPCBT_ERR_CH2NDOPEN -25 /* Channel end Open */
+#define EPCBT_ERR_RPLYPSIZE -28 /* OpenChannel return Paket Size Fail */
+#define EPCBT_ERR_WRITEERROR -31 /* Write Error */
+#define EPCBT_ERR_READERROR -32 /* Read Error */
+#define EPCBT_ERR_FNCDISABLE -33 /* Not send or receive */
+
+#define EPCBT_ERR_FATAL -50 /* FATAL Error */
+#define EPCBT_ERR_CBTDISABLE -52 /* EpsonPackingCommand Fail */
+#define EPCBT_ERR_NOREPLY -55 /* Reply Time out */
+
+#define EPCBT_ERR_MULFORMEDPACKET -80 /* receibe paket data Fail */
+#define EPCBT_ERR_UEREPLY -82 /* miss match Reply */
+#define EPCBT_ERR_UERESULT -85 /* no define Result value */
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+ /*** Channel Information */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagCBTS_CHINFO_ {
+ EPS_UINT8 No; /* Channel No */
+ EPS_INT32 PtSsize; /* Packet Size (PC -> Printer) */
+ EPS_INT32 StPsize; /* Packet Size (Printer -> PC) */
+ EPS_INT32 CreditP; /* receive credit from printer */
+ EPS_INT32 CreditH; /* send credit from host */
+ EPS_INT32 ReadSize; /* receive packet data size */
+ EPS_UINT8* ReadBuff; /* receive packet data buffer */
+ EPS_UINT8* RTmpBuff; /* receive data work buffer */
+ EPS_INT32 RTmpTop; /* receive data work buffer, start data point */
+ EPS_INT32 RTmpEnd; /* receive data work buffer, end data point */
+ EPS_INT32 RTmpCnt; /* receive data work buffer, data size */
+} CBTS_CHINFO;
+
+ /*** Printer Status */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagCBTS_PRNINFO_ {
+ EPS_INT16 Mode; /* CBT Mode */
+ void* pPortInfo; /* Port Info */
+ EPS_WritePortal pCbtWRtnFnc; /* Write Func */
+ EPS_ReadPortal pCbtRRtnFnc; /* Read Func */
+ EPS_UINT8* pWriteBuff; /* Write Work */
+ EPS_UINT8* pCbtReadRtnBuff; /* Read Work 1 */
+ EPS_UINT8* pCbtDataReadBuff; /* Read Work 2 */
+ CBTS_CHINFO Chinfo[CBT_MAX_CH]; /* Channel information */
+} CBTS_PRNINFO;
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern EPS_INT32 cbtCommOpen (const EPS_USB_DEVICE*, EPS_FILEDSC* );
+extern EPS_INT32 cbtCommClose (EPS_FILEDSC );
+extern EPS_INT32 cbtCommChannelOpen (EPS_FILEDSC, EPS_INT32, EPS_BOOL );
+extern EPS_INT32 cbtCommChannelClose (EPS_FILEDSC, EPS_INT32 );
+extern EPS_INT32 cbtCommReadData (EPS_FILEDSC, EPS_INT32, EPS_UINT8*, EPS_INT32, EPS_INT32*);
+extern EPS_INT32 cbtCommWriteData (EPS_FILEDSC, EPS_INT32, const EPS_UINT8*, EPS_INT32, EPS_INT32* );
+
+
+#ifdef __cplusplus
+}
+#endif /* def __cplusplus */
+
+#endif /* def _EPSON_CBT_H_ */
+
+/*___________________________________ epson-cbt.h ____________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage-color.c b/lib/epson-escpage-color.c
new file mode 100644
index 0000000..c162739
--- /dev/null
+++ b/lib/epson-escpage-color.c
@@ -0,0 +1,1210 @@
+/*______________________________ epson-escpage-color.c ______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-err.h"
+#include "epson-escpr-media.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpage.h"
+#include "epson-escpage-comp.h"
+#include "epson-escpage-color.h"
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_PAGE
+#define EPS_LOG_MODULE EPS_LOG_MODULE_PAGE
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+
+/*----------------------------- ESC/PAGE-Color commands -------------------------------*/
+/*******************************************|********************************************/
+const static EPS_UINT8 sbCR[] = {0x0D}; /* Carriage return "CR" */
+const static EPS_UINT8 sbFF[] = {0x0C}; /* Form Feed "FF" */
+const static EPS_UINT8 sbIP[] = {0x1D, 'r', 'h', 'E'}; /* Initialize printer */
+const static EPS_UINT8 sbSU150[] = {0x1D, '0', ';', '.', '4', '8', 'm', 'u', 'E'}; /* Set unit to 150 */
+const static EPS_UINT8 sbSU300[] = {0x1D, '0', ';', '.', '2', '4', 'm', 'u', 'E'}; /* Set unit to 300 */
+const static EPS_UINT8 sbSU600[] = {0x1D, '0', ';', '.', '1', '2', 'm', 'u', 'E'}; /* Set unit to 600 */
+
+const static EPS_UINT8 sbPSSL[] = {0x1D, '3', '0', 'p', 's', 'E'}; /* Set Letter paper */
+const static EPS_UINT8 sbPSSA4[] = {0x1D, '1', '4', 'p', 's', 'E'}; /* Set A4 paper */
+const static EPS_UINT8 sbPSSB5[] = {0x1D, '2', '5', 'p', 's', 'E'}; /* Set B5 paper */
+const static EPS_UINT8 sbPSSLE[] = {0x1D, '3', '2', 'p', 's', 'E'}; /* Set Legal paper */
+const static EPS_UINT8 sbPSSA3[] = {0x1D, '1', '3', 'p', 's', 'E'}; /* Set A3 paper */
+const static EPS_UINT8 sbPSSB4[] = {0x1D, '2', '4', 'p', 's', 'E'}; /* Set B4 paper */
+const static EPS_UINT8 sbPSSPS[] = {0x1D, '3', '8', 'p', 's', 'E'}; /* Set B4 paper */
+
+const static EPS_UINT8 sbPTE0[] = {0x1D, '0', 'p', 't', 'E'}; /* select paper type 0:other */
+const static EPS_UINT8 sbPTE1[] = {0x1D, '1', 'p', 't', 'E'}; /* select paper type 1:plane */
+
+const static EPS_UINT8 sbCMS[] = {0x1D, '1', 'c', 'm', 'E'}; /* Clip Mode Set */
+const static EPS_UINT8 sbSDS600_0[] = {0x1D, '0', ';', '6', '0', '0', ';', '6', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(600) 0:image */
+const static EPS_UINT8 sbSDS600_1[] = {0x1D, '1', ';', '6', '0', '0', ';', '6', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(600) 1:font */
+const static EPS_UINT8 sbSDS600_2[] = {0x1D, '2', ';', '6', '0', '0', ';', '6', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(600) 2:binary format pattern */
+const static EPS_UINT8 sbSDS600_3[] = {0x1D, '3', ';', '6', '0', '0', ';', '6', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(600) 3:color pattern */
+const static EPS_UINT8 sbSDS300_0[] = {0x1D, '0', ';', '3', '0', '0', ';', '3', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(300) 0:image */
+const static EPS_UINT8 sbSDS300_1[] = {0x1D, '1', ';', '3', '0', '0', ';', '3', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(300) 1:font */
+const static EPS_UINT8 sbSDS300_2[] = {0x1D, '2', ';', '3', '0', '0', ';', '3', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(300) 2:binary format pattern */
+const static EPS_UINT8 sbSDS300_3[] = {0x1D, '3', ';', '3', '0', '0', ';', '3', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(300) 3:color pattern */
+const static EPS_UINT8 sbSDS150_0[] = {0x1D, '0', ';', '1', '5', '0', ';', '1', '5', '0', 'd', 'r', 'E'}; /* Select Dot Size(150) 0:image */
+const static EPS_UINT8 sbSDS150_1[] = {0x1D, '1', ';', '1', '5', '0', ';', '1', '5', '0', 'd', 'r', 'E'}; /* Select Dot Size(150) 1:font */
+const static EPS_UINT8 sbSDS150_2[] = {0x1D, '2', ';', '1', '5', '0', ';', '1', '5', '0', 'd', 'r', 'E'}; /* Select Dot Size(150) 2:binary format pattern */
+const static EPS_UINT8 sbSDS150_3[] = {0x1D, '3', ';', '1', '5', '0', ';', '1', '5', '0', 'd', 'r', 'E'}; /* Select Dot Size(150) 3:color pattern */
+
+const static EPS_UINT8 sbMMS[] = {0x1D, '0', 'm', 'm', 'E'}; /* Select Page memory mode */
+const static EPS_UINT8 sbPDS[] = {0x1D, '0', 'p', 'o', 'E'}; /* Set paper direction to normal */
+const static EPS_UINT8 sbACRLFS[] = {0x1D, '0', 'a', 'l', 'f', 'P'}; /* Does not perform auto carriage return */
+const static EPS_UINT8 sbAFFS[] = {0x1D, '0', 'a', 'f', 'f', 'P'}; /* Does not perform auto Form Feed */
+const static EPS_UINT8 sbABPS[] = {0x1D, '1', 'a', 'b', 'P'}; /* Set current position to 0 after bit image draw */
+const static EPS_UINT8 sbSARGAS[] = {0x1D, '2', 's', 'a', 'r', 'G'}; /* Set Absolute Graph Coordinate mode */
+const static EPS_UINT8 sbPMPPS[] = {0x1D, '0', 'p', 'm', 'P'}; /* Set current move mode to print pitch mode */
+const static EPS_UINT8 sbCSE[] = {0x1D, '2', 'c', 's', 'E'}; /* Select color space */
+const static EPS_UINT8 sbPDDO[] = {0x1D, '0', 'p', 'd', 'd', 'O'}; /* Select Imaging device 0:CPGI 1:PGI */
+const static EPS_UINT8 sbCCME[] = {0x1D, '0', ';', '2', ';', '4', 'c', 'c', 'm', 'E'}; /* Select color collect */
+const static EPS_UINT8 sbCAME[] = {0x1D, '7', ';', '0', ';', '2', ';', '3', 'c', 'a', 'm', '{', 'E'};
+const static EPS_UINT8 sbRAE_1[] = {0x1D, '1', ';', '1', 'r', 'a', 'E'};
+const static EPS_UINT8 sbRAE_2[] = {0x1D, '2', ';', '1', 'r', 'a', 'E'};
+const static EPS_UINT8 sbRAE_3[] = {0x1D, '3', ';', '2', 'r', 'a', 'E'};
+const static EPS_UINT8 sbCMME_0[] = {0x1D, '0', 'c', 'm', 'm', 'E'};
+const static EPS_UINT8 sbCMME_1[] = {0x1D, '1', 'c', 'm', 'm', 'E'};
+const static EPS_UINT8 sbCLFP[] = {0x1D, '0', ';', '0', ';', '0', 'c', 'l', 'f', 'P'};
+const static EPS_UINT8 sbWFE[] = {0x1D, '5', ';', '2', '0', '4', 'w', 'f', 'E'};
+
+const static EPS_UINT8 sbBCTI20[] = {0x1D, '2', ';', '2', '0', 'b', 'c', 't', '{', 'I'};
+const static EPS_UINT8 sbC20[] = {0x1, 0x2};
+
+const static EPS_INT8 sbSCRI[] = "scrI";
+const static EPS_INT8 sbCRI[] = "\x1D%d;%dcr{I";
+const static EPS_INT8 sbCUI[] = "cu{I";
+const static EPS_UINT8 sbECRI[] = {0x1D, 'e', 'c', 'r', 'I'};
+
+const static EPS_INT8 sbplrBE[] = "\x1D%d;0;2;256;256plr{E";
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#define EPS_PAGE_RASTER (64) /* number of scanning rasters */
+#define EPS_PAGE_CMDBUFF_SIZE EPS_EJL_LINEMAX
+
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagEPS_PAGE_BAND_
+{
+ EPS_INT32 compressType; /* compless mode */
+ EPS_INT32 widthInPixels;
+ EPS_INT32 currentWidthInPixels;
+ EPS_INT32 rasterRow;
+ EPS_INT32 encDataSize; /* Compless data size */
+ EPS_UINT8 *pEncData; /* Compless data */
+ EPS_INT32 scanLineSize; /* Source data line size */
+ EPS_INT32 scanBuffSize; /* Source data buffer size */
+ EPS_INT32 scanDataSize; /* Source data size */
+ EPS_UINT8 *pScanData; /* Source data */
+ EPS_BOOL emited;
+ EPS_BOOL dataSent;
+}EPS_PAGE_BAND;
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+extern EPS_CMN_FUNC epsCmnFnc;
+extern EPS_PRINT_JOB printJob;
+
+/*---------------------------------- Local Variables --------------------------------*/
+/*******************************************|********************************************/
+static EPS_PAGE_BAND band;
+static EPS_COMMAND_BUFFER cmdBuf;
+static EPS_INT32 pageCount = 0;
+static EPS_INT32 emitRowCount = 0;
+
+
+/*-------------------------- Local Functions Declaration ----------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE CmdBuffInit (EPS_COMMAND_BUFFER *pCmdBuff, EPS_PAGE_BAND *pBand);
+static EPS_ERR_CODE CmdBuffGrow (EPS_COMMAND_BUFFER *pCmdBuff, EPS_INT32 addSize);
+static void CmdBuffTerm (EPS_COMMAND_BUFFER *pCmdBuff);
+
+static EPS_ERR_CODE RegisterPalette (EPS_UINT16, EPS_UINT8*, EPS_COMMAND_BUFFER *pCmdBuff);
+
+static EPS_BOOL BandInit (EPS_PAGE_BAND* pBand);
+static void BandTerm (EPS_PAGE_BAND* pBand);
+static EPS_BOOL BandEmit (EPS_PAGE_BAND* pBand);
+static EPS_ERR_CODE BandSetScanData (EPS_PAGE_BAND* pBand, const EPS_UINT8 *Row, EPS_UINT32 DeltaByte);
+static EPS_ERR_CODE BandCompress (EPS_PAGE_BAND* pBand, EPS_INT32);
+static void BandClear (EPS_PAGE_BAND* pBand);
+
+static EPS_INT32 GetEncodeMode(EPS_INT32 bpp);
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageAllocBuffer_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocate buffer for ESC/Page Job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageAllocBuffer_C(void)
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+ ret = BandInit(&band);
+
+ if ( EPS_ERR_NONE == ret ) {
+ ret = CmdBuffInit(&cmdBuf, &band);
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageRelaseBuffer_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* Free buffer for ESC/Page Job. */
+/* */
+/*******************************************|********************************************/
+void pageRelaseBuffer_C(void)
+{
+ /*** Clear Memory */
+ CmdBuffTerm(&cmdBuf);
+ BandTerm(&band);
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageStartJob_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page start job commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageStartJob_C(void)
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+#define pgStartJob_ADDCMD(CMD) { \
+ ret = CmdBuffGrow(&cmdBuf, sizeof(CMD) ); \
+ if( EPS_ERR_NONE != ret){EPS_RETURN( ret )} \
+ memcpy(cmdBuf.p + cmdBuf.len, CMD, sizeof(CMD)); \
+ cmdBuf.len += sizeof(CMD); \
+ }
+
+ cmdBuf.len = 0; /* reset */
+
+ /*** Make EJL Command ***/
+ ret = ejlStart(&cmdBuf, CmdBuffGrow);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ /* Initialize the printer. */
+ pgStartJob_ADDCMD(sbIP)
+
+ /* Set the minimum Unit Setting (600 or 300 resolution) */
+ /* Dot Pattern Resolution Selection */
+ if( EPS_IR_600X600 == printJob.attr.inputResolution) {
+ pgStartJob_ADDCMD(sbSU600);
+ pgStartJob_ADDCMD(sbSDS600_3);
+ pgStartJob_ADDCMD(sbSDS600_2);
+ pgStartJob_ADDCMD(sbSDS600_1);
+ pgStartJob_ADDCMD(sbSDS600_0);
+ } else if(EPS_IR_300X300 == printJob.attr.inputResolution) {
+ pgStartJob_ADDCMD(sbSU300);
+ pgStartJob_ADDCMD(sbSDS300_3);
+ pgStartJob_ADDCMD(sbSDS300_2);
+ pgStartJob_ADDCMD(sbSDS300_1);
+ pgStartJob_ADDCMD(sbSDS300_0);
+ }
+ else{
+ pgStartJob_ADDCMD(sbSU150);
+ pgStartJob_ADDCMD(sbSDS150_3);
+ pgStartJob_ADDCMD(sbSDS150_2);
+ pgStartJob_ADDCMD(sbSDS150_1);
+ pgStartJob_ADDCMD(sbSDS150_0);
+ }
+
+ /* Set Memory Mode Selection to Page memory mode */
+ pgStartJob_ADDCMD(sbMMS);
+
+ /* Set Paper Size */
+ switch ( printJob.attr.mediaSizeIdx ) {
+ case EPS_MSID_A4: pgStartJob_ADDCMD(sbPSSA4); break;
+ case EPS_MSID_B5: pgStartJob_ADDCMD(sbPSSB5); break;
+ case EPS_MSID_B4: pgStartJob_ADDCMD(sbPSSB4); break;
+ case EPS_MSID_A3: pgStartJob_ADDCMD(sbPSSA3); break;
+ case EPS_MSID_LETTER: pgStartJob_ADDCMD(sbPSSL); break;
+ case EPS_MSID_LEGAL: pgStartJob_ADDCMD(sbPSSLE); break;
+ case EPS_MSID_POSTCARD: pgStartJob_ADDCMD(sbPSSPS); break;
+ default: pgStartJob_ADDCMD(sbPSSA4); break;
+ }
+
+ ret = ejlPageEsc(&cmdBuf, CmdBuffGrow);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ /* Set Clip Mode */
+ pgStartJob_ADDCMD(sbCMS);
+
+ /* Does not perform automatic carriage return line feed */
+ pgStartJob_ADDCMD(sbACRLFS);
+
+ /* Does not perform automatic Form Feed */
+ pgStartJob_ADDCMD(sbAFFS);
+
+ /* Set current position to 0 after Bit image draw */
+ pgStartJob_ADDCMD(sbABPS);
+
+ /* Step 4 - Adjust Vertical Print Position (if necessary) */
+ /* CR */
+ pgStartJob_ADDCMD(sbCR);
+
+ /* Set Absolute graph coordinate mode */
+ pgStartJob_ADDCMD(sbSARGAS);
+
+ /* Set current position move mode to print pitch */
+ pgStartJob_ADDCMD(sbPMPPS);
+
+ /* select paper type */
+ if(printJob.attr.mediaTypeIdx == EPS_MTID_PLAIN){
+ pgStartJob_ADDCMD(sbPTE1);
+ } else{
+ pgStartJob_ADDCMD(sbPTE0);
+ }
+
+ /* Set paper direction */
+ pgStartJob_ADDCMD(sbPDS);
+
+ /* Select Imaging device */
+ pgStartJob_ADDCMD(sbPDDO);
+
+ /* Select color space */
+ pgStartJob_ADDCMD(sbCSE);
+
+ /* cancel color controle */
+ pgStartJob_ADDCMD(sbCMME_0);
+
+ /* Select color collect */
+ pgStartJob_ADDCMD(sbCCME);
+
+ /* Select color condition */
+ pgStartJob_ADDCMD(sbCAME);
+
+ /* Select screening */
+ pgStartJob_ADDCMD(sbRAE_1);
+ pgStartJob_ADDCMD(sbRAE_2);
+ pgStartJob_ADDCMD(sbRAE_3);
+
+ /* set color controle */
+ pgStartJob_ADDCMD(sbCMME_1);
+
+ pgStartJob_ADDCMD(sbCLFP);
+
+ /* set logical operation */
+ pgStartJob_ADDCMD(sbWFE);
+
+ switch( band.compressType )
+ {
+ case EP_COMPRESS20:
+ pgStartJob_ADDCMD(sbBCTI20); /* set compless table */
+ pgStartJob_ADDCMD(sbC20); /* set data format */
+ break;
+ default:/* for 8bpp */
+ break;
+ }
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, cmdBuf.len, &retBufSize, TRUE);
+
+ pageCount = 0;
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageEndJob_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page end job commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageEndJob_C()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ cmdBuf.len = 0; /* reset */
+
+ /* end color image drawing */
+ memcpy((EPS_INT8*)cmdBuf.p, sbECRI, sizeof(sbECRI));
+ cmdBuf.len += sizeof(sbECRI);
+
+ /*** Make EJL Command ***/
+ ret = ejlEnd(&cmdBuf, CmdBuffGrow, pageCount);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, cmdBuf.len, &retBufSize, TRUE);
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageStartPage_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page start page commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageStartPage_C()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ cmdBuf.len = 0; /* reset */
+ if( 0 == pageCount ){
+ if (printJob.attr.colorPlane == EPS_CP_256COLOR){
+ ret = RegisterPalette(printJob.attr.paletteSize, printJob.attr.paletteData,
+ &cmdBuf);
+ }
+ } else{
+ memcpy(cmdBuf.p, sbFF, sizeof(sbFF));
+ cmdBuf.len += sizeof(sbFF);
+
+ ret = ejlPageEsc(&cmdBuf, CmdBuffGrow);
+ }
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ if(cmdBuf.len > 0){
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, cmdBuf.len, &retBufSize, TRUE);
+ }
+
+ emitRowCount = 0;
+ pageCount++;
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageEndPage_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page end page commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageEndPage_C()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+ if( EP_COMPRESS0 != band.compressType ){
+ BandCompress(&band, printJob.bpp*8);
+ if( band.encDataSize > 0 ) {
+ ret = BandEmit(&band);
+ }
+ } else{
+ if( band.scanDataSize > 0 ){
+ ret = BandEmit(&band);
+ }
+ }
+
+ if( EPS_ERR_NONE == ret){
+ BandClear(&band);
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageColorRow_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page raster commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageColorRow_C(
+
+ const EPS_BANDBMP* pInBmp,
+ EPS_RECT* pBandRec
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT16 linePixelSize;
+ EPS_UINT16 widthBytes;
+
+ EPS_LOG_FUNCIN
+
+ if( (EPS_UINT32)(pBandRec->right - pBandRec->left) <= printJob.printableAreaWidth){
+ linePixelSize = (EPS_UINT16)(pBandRec->right - pBandRec->left);
+ } else{
+ linePixelSize = (EPS_UINT16) printJob.printableAreaWidth;
+ }
+ widthBytes = linePixelSize * printJob.bpp;
+ band.currentWidthInPixels = linePixelSize;
+ /* reset scan size from current line size */
+ band.scanLineSize = widthBytes;
+ if( band.scanLineSize & 3 ){
+ /* 4bite align */
+ band.scanLineSize = (band.scanLineSize & ~3) + 4;
+ }
+
+ BandSetScanData(&band, pInBmp->bits, widthBytes);
+
+ if(EP_COMPRESS0 != band.compressType){
+ if( (band.rasterRow >= EPS_PAGE_RASTER )) {
+ BandCompress(&band, printJob.bpp*8);
+ if( band.encDataSize > 0 ) {
+ ret = BandEmit(&band);
+ }
+
+ emitRowCount += band.rasterRow;
+ if( EPS_ERR_NONE == ret){
+ BandClear(&band); /* reset */
+ }
+ }
+ } else{
+ ret = BandEmit(&band);
+ emitRowCount += band.rasterRow;
+ if( EPS_ERR_NONE == ret){
+ BandClear(&band); /* reset */
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageSendLeftovers_C() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_INVALID_CALL - This call was unnecessary */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* send leftovers data. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageSendLeftovers_C(
+
+ void
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL != printJob.contData.sendData && 0 < printJob.contData.sendDataSize){
+ /* send command */
+ ret = SendCommand(printJob.contData.sendData,
+ printJob.contData.sendDataSize, &retBufSize, TRUE);
+
+ if( EPS_ERR_NONE == ret ){
+ if( band.dataSent ){
+ /* send encode data */
+ if( EP_COMPRESS0 != band.compressType ){
+ ret = SendCommand(band.pEncData, band.encDataSize, &retBufSize, TRUE);
+ } else{
+ ret = SendCommand(band.pScanData, band.scanDataSize, &retBufSize, TRUE);
+ }
+
+ band.dataSent = FALSE;
+ }
+ if( EPS_ERR_NONE == ret){
+ BandClear(&band);
+ }
+ }
+ } else{
+ ret = EPS_ERR_INVALID_CALL;
+ }
+
+ EPS_RETURN( ret )
+}
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CmdBuffInit() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocate command buffer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE CmdBuffInit(
+
+ EPS_COMMAND_BUFFER* pCmdBuff,
+ EPS_PAGE_BAND* pBand
+
+){
+ pCmdBuff->pExtent = pBand;
+
+ if(EP_COMPRESS0 == pBand->compressType){
+ pCmdBuff->size = EPS_EJL_LINEMAX;
+ pCmdBuff->p = EPS_ALLOC(pCmdBuff->size);
+ if( NULL == pCmdBuff->p){
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+
+ } else{
+ /* use scan-buffer as command-buffer */
+ pCmdBuff->size = pBand->scanBuffSize;
+ pCmdBuff->p = (EPS_INT8*)pBand->pScanData;
+ }
+
+ pCmdBuff->len = 0;
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CmdBuffGrow() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* addSize EPS_INT32 I: growing size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* ReAllocate command buffer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE CmdBuffGrow(
+
+ EPS_COMMAND_BUFFER* pCmdBuff,
+ EPS_INT32 addSize
+
+){
+ EPS_INT32 block, sizeNew;
+ EPS_PAGE_BAND *pBand = (EPS_PAGE_BAND*)pCmdBuff->pExtent;
+
+ if(pCmdBuff->size < pCmdBuff->len + addSize){
+ block = (((pCmdBuff->len+addSize) / EPS_PAGE_CMDBUFF_SIZE) + 1);
+ sizeNew = block * EPS_PAGE_CMDBUFF_SIZE;
+ pCmdBuff->p = memRealloc(pCmdBuff->p, pCmdBuff->size, sizeNew);
+ if( NULL == pCmdBuff->p){
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+ pCmdBuff->size = sizeNew;
+
+ if(EP_COMPRESS0 != pBand->compressType){
+ pBand->scanBuffSize = cmdBuf.size;
+ pBand->pScanData = (EPS_UINT8*)cmdBuf.p;
+ }
+ }
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CmdBuffTerm() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* Free command buffer. */
+/* */
+/*******************************************|********************************************/
+static void CmdBuffTerm (
+
+ EPS_COMMAND_BUFFER* pCmdBuff
+
+){
+ EPS_PAGE_BAND* pBand = (EPS_PAGE_BAND*)pCmdBuff->pExtent;
+
+ if( NULL != pBand ){
+ if(EP_COMPRESS0 == pBand->compressType){
+ EPS_SAFE_RELEASE(pCmdBuff->p);
+ } else{
+ pCmdBuff->p = NULL;
+ }
+ }
+
+ pCmdBuff->len = 0;
+ pCmdBuff->size = 0;
+ pCmdBuff->pExtent = NULL;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: RegisterPalette() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* paletteSize EPS_UINT16 I: Palette Size */
+/* paletteData EPS_UINT8* I: Palette Size */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Register the palette for Printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE RegisterPalette(
+
+ EPS_UINT16 paletteSize,
+ EPS_UINT8* paletteData,
+ EPS_COMMAND_BUFFER* pCmdBuff
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 *p = NULL;
+ EPS_UINT16 entryNum = paletteSize / 3; /* 3 = RGB */
+ EPS_INT32 i = 0;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_DEBUG
+ if(pCmdBuff->len+EPS_EJL_LINEMAX > pCmdBuff->size){EPS_DBGPRINT(("Command buffer not enough!\r\n"))}
+#endif
+ p = pCmdBuff->p + pCmdBuff->len;
+
+ sprintf(p, sbplrBE, entryNum*4); /* 4 = RGBA */
+ pCmdBuff->len += (EPS_UINT32)strlen(p);
+
+ /* expand for palette data */
+ ret = CmdBuffGrow(pCmdBuff, entryNum*4);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+ p = pCmdBuff->p + pCmdBuff->len;
+
+ /* set palette */
+ for(i = 0; i < paletteSize; i+=3){
+ *p++ = paletteData[i+2]; /* B */
+ *p++ = paletteData[i+1]; /* G */
+ *p++ = paletteData[i]; /* R */
+ *p++ = 0; /* dummy */
+ }
+ pCmdBuff->len = (EPS_INT32)(p - pCmdBuff->p);
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandInit() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocate band data buffers. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE BandInit(
+
+ EPS_PAGE_BAND* pBand
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+ memset(pBand, 0, sizeof(EPS_PAGE_BAND));
+ pBand->compressType = GetEncodeMode( printJob.attr.colorPlane ); /* Set compless mode */
+ pBand->widthInPixels = printJob.printableAreaWidth;
+ pBand->scanDataSize = 0;
+ pBand->encDataSize = 0;
+ pBand->emited = FALSE;
+ pBand->dataSent = FALSE;
+
+ if(EP_COMPRESS0 == pBand->compressType){
+ pBand->scanLineSize = pBand->widthInPixels * printJob.bpp;
+ pBand->scanBuffSize = pBand->scanLineSize; /* one line buffering */
+ } else{
+ pBand->scanLineSize = (pBand->widthInPixels * printJob.bpp);
+ if( pBand->scanLineSize & 3 ){
+ /* 4bite align */
+ pBand->scanLineSize = (pBand->scanLineSize & ~3) + 4;
+ }
+ pBand->scanBuffSize = pBand->scanLineSize * EPS_PAGE_RASTER;
+ }
+ pBand->pScanData = (EPS_UINT8*)EPS_ALLOC( pBand->scanBuffSize );
+ if( NULL == pBand->pScanData ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandTerm() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* free band data buffers. */
+/* */
+/*******************************************|********************************************/
+static void BandTerm(
+
+ EPS_PAGE_BAND* pBand
+
+){
+ EPS_LOG_FUNCIN
+
+ EPS_SAFE_RELEASE(pBand->pScanData);
+ BandClear(pBand);
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandEmit() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Emit data to printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE BandEmit(
+
+ EPS_PAGE_BAND* pBand
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 *p = NULL;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ cmdBuf.len = 0; /* reset */
+ p = (EPS_INT8*)cmdBuf.p;
+
+ if( pBand->emited ){
+ /* end color image drawing for previous data */
+ memcpy(p, sbECRI, sizeof(sbECRI));
+ p += sizeof(sbECRI);
+ } else{
+ pBand->emited = TRUE;
+ }
+
+ /* Reset the current absolute position */
+ strcpy(p, "\x1D""0X");
+ p += strlen(p);
+
+ EPS_DBGPRINT(("Emit Y pos = %d \r\n", emitRowCount));
+ sprintf(p, "\x1D%dY", emitRowCount);
+ p += strlen(p);
+
+ /* ----- stretch color image ----- */
+ if(printJob.attr.colorPlane == EPS_CP_256COLOR){
+ strcpy(p, "\x1D""2;204;0;"); /* Indirectly RGB8, palett=0 */
+ } else{
+ strcpy(p, "\x1D""2;102;0;"); /* RGB888 */
+ }
+ p += strlen(p);
+
+ switch(pBand->compressType){
+ case EP_COMPRESS20:
+ strcpy(p, "20;");
+ break;
+ case EP_COMPRESS0:
+ default:
+ strcpy(p, "0;");
+ break;
+ }
+ p += strlen(p);
+
+ sprintf(p, "%d;%d;%d;%d;0%s", pBand->currentWidthInPixels, pBand->rasterRow,
+ pBand->currentWidthInPixels, pBand->rasterRow, sbSCRI);
+ p += strlen(p);
+
+ /*** Draw color image ***/
+ if(EP_COMPRESS20 == pBand->compressType){
+ /* Number of data bytes */
+ /* Bit image width */
+ sprintf(p, sbCRI, pBand->encDataSize, pBand->rasterRow);
+ p += strlen(p);
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, (EPS_INT32)(p - (EPS_INT8*)cmdBuf.p), &retBufSize, TRUE);
+
+ pBand->dataSent = TRUE; /* encode date until send */
+ if( EPS_ERR_NONE == ret){
+ ret = SendCommand(pBand->pEncData, pBand->encDataSize, &retBufSize, TRUE);
+ pBand->dataSent = FALSE; /* encode date has sent */
+ }
+
+ } else{ /* non compless */
+ /* Number of data bytes */
+ /* Bit image width */
+ sprintf(p, "\x1D""%d;%d%s", pBand->scanDataSize, pBand->rasterRow, sbCUI);
+ p += strlen(p);
+
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, (EPS_INT32)(p - (EPS_INT8*)cmdBuf.p), &retBufSize, TRUE);
+
+ pBand->dataSent = TRUE; /* encode date until send */
+ if( EPS_ERR_NONE == ret){
+ ret = SendCommand(pBand->pScanData, pBand->scanDataSize, &retBufSize, TRUE);
+ pBand->dataSent = FALSE; /* encode date has sent */
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandSetScanData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* Row const EPS_UINT8* I: band data */
+/* DeltaByte EPS_UINT32 I: number of data bytes */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* */
+/* Description: */
+/* save band data. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE BandSetScanData(
+
+ EPS_PAGE_BAND* pBand,
+ const EPS_UINT8* Row,
+ EPS_UINT32 DeltaByte
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+ pBand->rasterRow++;
+
+ if(EP_COMPRESS0 != pBand->compressType){
+ memcpy(pBand->pScanData + (pBand->scanLineSize * (EPS_PAGE_RASTER - pBand->rasterRow)), Row, DeltaByte);
+ } else{
+ memcpy(pBand->pScanData, Row, DeltaByte);
+ }
+ pBand->scanDataSize += DeltaByte;
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandCompress() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* WidthBytes EPS_INT32 I: data length */
+/* bitCount EPS_INT32 I: image bit count */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* */
+/* Description: */
+/* Data is compressed. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE BandCompress(
+
+ EPS_PAGE_BAND* pBand,
+ EPS_INT32 bitCount
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_BITMAPINFO BitMapInfo;
+ EPS_UINT32 lCompressType;
+ EPS_UINT32 lImageSize = 0;
+ EPS_RECT rect;
+ EPS_UINT8* pRealBits;
+
+ EPS_LOG_FUNCIN
+
+ memset(&BitMapInfo, 0, sizeof(EPS_BITMAPINFO));
+
+ BitMapInfo.biWidth = pBand->currentWidthInPixels;
+ BitMapInfo.biHeight = pBand->rasterRow;
+ BitMapInfo.biBitCount = bitCount;
+
+ rect.left = rect.top = 0;
+ rect.bottom = pBand->rasterRow;
+ rect.right = pBand->currentWidthInPixels;
+
+ pRealBits = pBand->pScanData + (pBand->scanLineSize * (EPS_PAGE_RASTER - pBand->rasterRow));
+
+ pBand->pEncData = CompressBitImage(
+ &rect,
+ &BitMapInfo,
+ pRealBits,
+ pBand->compressType,
+ &lCompressType,
+ &lImageSize
+ );
+ pBand->encDataSize = lImageSize;
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandClear() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* */
+/* Description: */
+/* Reset band data. */
+/* */
+/*******************************************|********************************************/
+static void BandClear(
+
+ EPS_PAGE_BAND *pBand
+
+){
+ EPS_LOG_FUNCIN
+ EPS_SAFE_RELEASE(pBand->pEncData);
+ pBand->scanDataSize = 0;
+ pBand->encDataSize = 0;
+ pBand->rasterRow = 0;
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: GetEncodeMode() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND* I: band data strcture */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE compless mode */
+/* */
+/* Description: */
+/* choose compless mode. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 GetEncodeMode(
+
+ EPS_INT32 bpp
+
+){
+ if(bpp == EPS_CP_256COLOR){
+ return EP_COMPRESS0;
+ } else{ /* if EPS_CP_FULLCOLOR */
+ return EP_COMPRESS20;
+ }
+}
+
+/*______________________________ epson-escpage-color.c ______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage-color.h b/lib/epson-escpage-color.h
new file mode 100644
index 0000000..50e5246
--- /dev/null
+++ b/lib/epson-escpage-color.h
@@ -0,0 +1,55 @@
+/*______________________________ epson-escpage-color.h ______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/Page-Color command Functions */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPAGE_COLOR_H__
+#define __EPSON_ESCPAGE_COLOR_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern EPS_ERR_CODE pageAllocBuffer_C (void);
+extern void pageRelaseBuffer_C (void);
+extern EPS_ERR_CODE pageStartJob_C (void);
+extern EPS_ERR_CODE pageEndJob_C (void);
+extern EPS_ERR_CODE pageStartPage_C (void);
+extern EPS_ERR_CODE pageEndPage_C (void);
+extern EPS_ERR_CODE pageColorRow_C (const EPS_BANDBMP*, EPS_RECT*);
+extern EPS_ERR_CODE pageSendLeftovers_C (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPAGE_COLOR_H__ */
+
+/*______________________________ epson-escpage-color.h ______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage-comp.c b/lib/epson-escpage-comp.c
new file mode 100644
index 0000000..cb458ee
--- /dev/null
+++ b/lib/epson-escpage-comp.c
@@ -0,0 +1,581 @@
+/*_______________________________ epson-escpage-comp.c _____________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-mem.h"
+#include "epson-escpage-comp.h"
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+#ifdef EPS_LOG_MODULE_PAGE
+#define EPS_LOG_MODULE EPS_LOG_MODULE_PAGE
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+/* Define Bitmap Format */
+#define EP_BGR 0
+#define EP_RGB 1
+
+#define ConvertEndianWord(w) ((EPS_UINT16) ((((w) >> 8) & 0xFF) | (((w) << 8) & 0xFF00)))
+#define ConvertEndianDWORD(d) (((EPS_UINT32) (d) << 24) | (((EPS_UINT32) (d) << 8) & 0x00FF0000) | (((EPS_UINT32) (d) >> 8) & 0x0000FF00) | ((EPS_UINT32) (d) >> 24))
+#define GetCompressMode(d) ((EPS_UINT16) ((d) >> 16))
+#define GetCompressQuality(d) ((EPS_UINT16) ((d) & 0xFFFF))
+
+#define BAND_PIXEL 4
+#define MakeCompress20Mode(q) (0x20 + (q))
+#define MakeUncompress20Mode(q) (0x00 + (q))
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct tagCODINGDATA {
+ EPS_UINT16 hufCode[256] ;
+ EPS_UINT8 hufCodeLen[256] ;
+ EPS_UINT8* lpCurPtr ;
+ EPS_UINT32 leftCount ;
+ EPS_UINT32 code ;
+ EPS_UINT16 codeBits ;
+} CODINGDATA ;
+
+typedef struct tagCOMPRESSBUFFER {
+ EPS_UINT16 wMode ; /* Compress Mode */
+ EPS_UINT16 wQuality ; /* Compress Quality */
+ EPS_UINT8* lpBuffer ; /* Output Buffer */
+ EPS_UINT32 sizeBuffer ; /* Output Buffer Size */
+ EPS_UINT32 dwWidth ;
+ EPS_UINT32 dwHeight ;
+ EPS_UINT32 format ; /* Align Format */
+ EPS_UINT16 biBitCount ; /* Bitmap Bit Count */
+ EPS_INT32 nextLine ;
+ EPS_BOOL bInvertX ; /* Invert Image X */
+ EPS_UINT8* lpBitsOrg ; /* Start Address */
+ EPS_UINT32 ySrc ;
+} COMPRESSBUFFER ;
+
+typedef struct tagBLOCKHEADER20 {
+ EPS_UINT32 size ; /* 0 */
+ EPS_UINT16 width ; /* 4 */
+ EPS_UINT16 bandPixel ; /* 6 */
+ EPS_UINT16 mode ; /* 8 */
+} BLOCKHEADER20 ;
+#define SIZEOF_BLOCKHEADER20 (4+2+2+2)
+
+typedef struct tagCOMPBUFFER20 {
+ COMPRESSBUFFER cbuf ;
+ BLOCKHEADER20 bh ;
+ CODINGDATA cd ;
+ EPS_UINT32 bandLimit ;
+ EPS_UINT8 mode[4] ;
+} COMPBUFFER20 ;
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+extern EPS_CMN_FUNC epsCmnFnc;
+
+/*------------------------------ Local Global Variables ------------------------------*/
+/*******************************************|********************************************/
+static const EPS_UINT16 HufmanDefTable2[]
+ = {0, 0, 1, 2, 2, 4, 4, 7, 9, 14, 17, 24, 172} ;
+static const EPS_UINT16 HufmanDefTable3[][2]
+ = { 0x00, 2, 0x02, 2, 0x01, 2, 0x03, 4, 0x0b, 4,
+ 0x07, 5, 0x17, 5, 0x0f, 5, 0x1f, 5,
+ } ;
+
+/*-------------------------- Private Functions Declaration --------------------------*/
+/*******************************************|********************************************/
+static EPS_UINT32 EPGetCompressBufferSize(EPS_UINT32 dwMode) ;
+static EPS_UINT32 EPCompressImage(
+ EPS_UINT32 dwMode,
+ EPS_UINT32 xSrc, EPS_UINT32 ySrc, EPS_UINT32 dwWidth, EPS_UINT32 dwHeight,
+ EPS_BITMAPINFO *lpbmi, EPS_UINT32 biFormat, EPS_UINT8* lpBits,
+ EPS_UINT8* lpBuf, EPS_UINT32 sizeBuf,
+ EPS_UINT8* lpWorkBuf ) ;
+static EPS_UINT32 Compress20(COMPBUFFER20* lpC20Buf) ;
+static EPS_BOOL MakeHufmanCodeTable(EPS_UINT16 wMode, EPS_UINT16 wQuality, CODINGDATA* lpcd) ;
+static EPS_BOOL WriteBandData20(EPS_INT32 band, EPS_INT32 incptr, EPS_UINT8* lpSrc, COMPBUFFER20* lpC20Buf) ;
+static EPS_UINT8 GetByteBLOCKHEADER20(BLOCKHEADER20 *p, EPS_INT32 n);
+static void MakeHufmanTable1(const EPS_UINT16 cdn[], CODINGDATA* lpcd) ;
+static void CodeHufmanData(const EPS_UINT8 d, CODINGDATA* const lpcd);
+static void WriteDataToBuffer(CODINGDATA* const lpcd);
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+EPS_UINT8* CompressBitImage(
+
+ EPS_RECT *pRec,
+ EPS_BITMAPINFO *pBitMapInfo,
+ EPS_UINT8* pRealBits,
+ EPS_UINT32 ulDataFormat,
+ EPS_UINT32 *pulCompressType,
+ EPS_UINT32 *pulImageSize
+
+){
+ EPS_BITMAPINFO bmi;
+ EPS_UINT32 dwComMode = 0;
+ EPS_UINT32 dwwkBufferSize;
+ EPS_UINT8* pwkBuffer = NULL;
+ EPS_UINT32 dwBuffer;
+ EPS_UINT8* pTmp = NULL;
+ EPS_UINT32 dwCompressedSize;
+
+ EPS_INT32 ulSrcleft, ulSrcright, ulSrcbottom, ulSrctop;
+
+ ulSrcleft = pRec->left;
+ ulSrcright= pRec->right;
+ ulSrcbottom = pRec->bottom;
+ ulSrctop= pRec->top;
+
+ bmi = *pBitMapInfo;
+
+ dwComMode = ulDataFormat;
+
+ *pulCompressType = dwComMode;
+ dwComMode = dwComMode << 16;
+
+ dwwkBufferSize = EPGetCompressBufferSize( dwComMode);
+
+ if(dwwkBufferSize == 0){
+ *pulCompressType = 0;
+ return NULL;
+ }
+
+ if(!(pwkBuffer = (EPS_UINT8*)EPS_ALLOC( dwwkBufferSize ))){
+ *pulCompressType = 0;
+ return NULL;
+ }
+
+ dwBuffer = (((ulSrcright - ulSrcleft ) * 24 + 31) / 32) * 4 * (ulSrcbottom - ulSrctop );
+ if(!(pTmp = (EPS_UINT8*)EPS_ALLOC( dwBuffer ))){
+ EPS_FREE(pwkBuffer );
+ *pulCompressType = 0;
+ return NULL;
+ }
+
+ dwCompressedSize = EPCompressImage( dwComMode,
+ ulSrcleft,
+ ulSrctop,
+ ulSrcright - ulSrcleft ,
+ ulSrcbottom - ulSrctop ,
+ &bmi,
+ EP_RGB,
+ pRealBits,
+ pTmp,
+ dwBuffer,
+ pwkBuffer );
+
+ EPS_FREE(pwkBuffer);
+ if(dwCompressedSize == 0){
+ EPS_FREE(pTmp);
+ *pulCompressType = 0;
+ return NULL;
+ }
+
+ *pulImageSize = dwCompressedSize;
+
+ return pTmp;
+}
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+static EPS_UINT32 EPGetCompressBufferSize (EPS_UINT32 dwMode)
+{
+ EPS_UINT16 mode;
+
+ EPS_LOG_FUNCIN
+
+ mode = GetCompressMode(dwMode) ;
+
+ switch (mode) {
+
+ case EP_COMPRESS20 :
+ EPS_RETURN( sizeof(COMPBUFFER20) )
+ default:
+ break;
+ }
+
+ EPS_RETURN( 0 )
+}
+
+
+static EPS_UINT32 EPCompressImage (
+ EPS_UINT32 dwMode,
+ EPS_UINT32 xSrc,
+ EPS_UINT32 ySrc,
+ EPS_UINT32 dwWidth,
+ EPS_UINT32 dwHeight,
+ EPS_BITMAPINFO *lpbmi,
+ EPS_UINT32 biFormat,
+ EPS_UINT8* lpBits,
+ EPS_UINT8* lpBuf,
+ EPS_UINT32 sizeBuf,
+ EPS_UINT8* lpWorkBuf )
+{
+ COMPRESSBUFFER* lpCBuf ;
+ EPS_UINT32 height ;
+
+ EPS_LOG_FUNCIN
+
+ if (dwWidth == 0 || dwHeight == 0) {
+ EPS_RETURN( 0 )
+ }
+ if (lpWorkBuf == NULL) {
+ EPS_RETURN( 0 )
+ }
+
+ lpCBuf = (COMPRESSBUFFER*) lpWorkBuf ;
+
+ /* Check Width and calculate Scan Size */
+
+ if (lpbmi->biWidth <= 0 || (EPS_UINT32) lpbmi->biWidth < xSrc + dwWidth) {
+ EPS_RETURN( 0 )
+ }
+
+ lpCBuf->dwWidth = dwWidth ;
+ lpCBuf->biBitCount = lpbmi->biBitCount ;
+ lpCBuf->format = biFormat ;
+
+ lpCBuf->nextLine = ((lpbmi->biWidth * lpCBuf->biBitCount + 7) / 8 + 3) & 0xFFFFFFFC ;
+ lpCBuf->lpBitsOrg = lpBits + (xSrc*lpCBuf->biBitCount / 8) ;
+ /*lpCBuf->bitOffset = (EPS_INT16) (xSrc*lpCBuf->biBitCount % 8) ;*/
+
+ /* Check Height and calculate start addr */
+
+ lpCBuf->dwHeight = dwHeight ;
+ if (lpbmi->biHeight > 0) {
+ /* bottom up bitmap */
+ height = (EPS_UINT32) lpbmi->biHeight ;
+ lpCBuf->lpBitsOrg += lpCBuf->nextLine * (ySrc + dwHeight - 1);
+ lpCBuf->nextLine = -lpCBuf->nextLine ;
+ }
+ else {
+ /* top down bitmap */
+ height = (EPS_UINT32) -lpbmi->biHeight;
+ lpCBuf->lpBitsOrg += lpCBuf->nextLine * ySrc;
+ }
+ if (height == 0 || height < ySrc + dwHeight) {
+ EPS_RETURN( 0 )
+ }
+
+ /* Fill Other fields */
+ lpCBuf->wMode = GetCompressMode(dwMode) ;
+ lpCBuf->wQuality = GetCompressQuality(dwMode) ;
+ lpCBuf->lpBuffer = lpBuf ;
+ lpCBuf->sizeBuffer = sizeBuf ;
+ lpCBuf->bInvertX = FALSE ;
+
+ switch (lpCBuf->wMode) {
+ case EP_COMPRESS20 :
+ EPS_RETURN( Compress20((COMPBUFFER20*) lpCBuf) )
+ default:
+ break;
+ }
+
+ EPS_RETURN( 0 )
+}
+
+/* 24BPP Image Compress Mode 20 */
+static EPS_UINT32 Compress20(COMPBUFFER20* lpC20Buf)
+{
+ EPS_UINT8* lpSrc ;
+ EPS_INT32 nextBand ;
+ EPS_UINT32 y, yblock, ymod ;
+ EPS_INT32 incptr ;
+
+ EPS_LOG_FUNCIN
+
+ if (lpC20Buf->cbuf.biBitCount == 24) {
+ incptr = 3 ;
+ }
+ else if (lpC20Buf->cbuf.biBitCount == 32) {
+ incptr = 4 ;
+ }
+ else {
+ EPS_RETURN( 0 )
+ }
+
+ if (lpC20Buf->cbuf.bInvertX) {
+ /* invert image */
+ lpSrc = lpC20Buf->cbuf.lpBitsOrg + (lpC20Buf->cbuf.dwWidth - 1) * incptr ;
+ incptr = -incptr ;
+ }
+ else {
+ lpSrc = lpC20Buf->cbuf.lpBitsOrg ;
+ }
+
+ if (lpC20Buf->cbuf.format == EP_RGB) {
+ lpC20Buf->mode[0] = 2 ;
+ lpC20Buf->mode[1] = 1 ;
+ lpC20Buf->mode[2] = 0 ;
+ }
+ else {
+ lpC20Buf->mode[0] = 0 ;
+ lpC20Buf->mode[1] = 1 ;
+ lpC20Buf->mode[2] = 2 ;
+ }
+
+ /* Make Hufman Code Table */
+ MakeHufmanCodeTable(lpC20Buf->cbuf.wMode, lpC20Buf->cbuf.wQuality, &lpC20Buf->cd) ;
+
+ /* Make Block Header */
+ lpC20Buf->bh.width = ConvertEndianWord(lpC20Buf->cbuf.dwWidth) ;
+ lpC20Buf->bh.bandPixel = ConvertEndianWord(BAND_PIXEL) ;
+
+ /* Initialize */
+ lpC20Buf->cd.lpCurPtr = lpC20Buf->cbuf.lpBuffer ;
+ lpC20Buf->cd.leftCount = lpC20Buf->cbuf.sizeBuffer ;
+
+ yblock = lpC20Buf->cbuf.dwHeight / BAND_PIXEL ;
+ ymod = lpC20Buf->cbuf.dwHeight % BAND_PIXEL ;
+
+ nextBand = lpC20Buf->cbuf.nextLine * BAND_PIXEL ;
+
+ lpC20Buf->bandLimit = SIZEOF_BLOCKHEADER20 + lpC20Buf->cbuf.dwWidth * BAND_PIXEL ;
+
+ for (y = 0 ; y < yblock ; y++) {
+ if (! WriteBandData20(BAND_PIXEL, incptr, lpSrc, lpC20Buf)) {
+ EPS_RETURN( 0 )
+ }
+ lpSrc += nextBand ;
+ }
+ if (ymod) {
+ lpC20Buf->bh.bandPixel = ConvertEndianWord(ymod) ;
+ lpC20Buf->bandLimit = SIZEOF_BLOCKHEADER20 + lpC20Buf->cbuf.dwWidth * ymod ;
+
+ if (! WriteBandData20((EPS_UINT16) ymod, incptr, lpSrc, lpC20Buf)) {
+ EPS_RETURN( 0 )
+ }
+ }
+
+ if (lpC20Buf->cd.leftCount == 0) {
+ EPS_RETURN( 0 )
+ }
+
+ EPS_RETURN( lpC20Buf->cbuf.sizeBuffer - lpC20Buf->cd.leftCount )
+}
+
+
+static EPS_BOOL WriteBandData20(EPS_INT32 band, EPS_INT32 incptr, EPS_UINT8* lpSrc, COMPBUFFER20* lpC20Buf)
+{
+ EPS_UINT32 sizeBlockData ;
+ EPS_UINT8* lpBandStart ;
+ EPS_UINT32 countBandStart ;
+ EPS_UINT8 *lpBand, *lpPt, *lpPrePt;
+ EPS_UINT8 left ;
+
+ EPS_INT32 i, j ;
+ EPS_UINT32 x ;
+
+ EPS_LOG_FUNCIN
+
+ for (i = 0 ; i <= 2 ; i++) {
+ if (lpC20Buf->cd.leftCount <= SIZEOF_BLOCKHEADER20) {
+ EPS_RETURN( FALSE )
+ }
+
+ lpBandStart = lpC20Buf->cd.lpCurPtr ;
+ countBandStart = lpC20Buf->cd.leftCount ;
+
+ lpC20Buf->cd.lpCurPtr += SIZEOF_BLOCKHEADER20;
+ lpC20Buf->cd.leftCount -= SIZEOF_BLOCKHEADER20;
+ lpC20Buf->cd.code = 0 ;
+ lpC20Buf->cd.codeBits = 0 ;
+
+ lpBand = lpSrc + i ;
+ lpPt = lpBand ;
+ left = 0 ;
+
+ for (x = 0 ; x < lpC20Buf->cbuf.dwWidth ; x++) {
+ CodeHufmanData((EPS_UINT8) (*lpPt-left), &lpC20Buf->cd) ;
+ left = *lpPt ;
+ lpPt += incptr ;
+ }
+
+ for (j = 1 ; j < band ; j++) {
+ lpPrePt = lpBand ;
+ lpBand += lpC20Buf->cbuf.nextLine ;
+ lpPt = lpBand ;
+ left = 0 ;
+
+ for (x = 0 ; x < lpC20Buf->cbuf.dwWidth ; x++) {
+ CodeHufmanData((EPS_UINT8) (*lpPt-((left+*lpPrePt)>>1)), &lpC20Buf->cd) ;
+ left = *lpPt ;
+ lpPt += incptr ;
+ lpPrePt += incptr ;
+ }
+ }
+ if (lpC20Buf->cd.codeBits) WriteDataToBuffer(&lpC20Buf->cd) ;
+
+ if (countBandStart <= lpC20Buf->cd.leftCount + lpC20Buf->bandLimit) {
+ /* Write Block Header */
+ sizeBlockData = countBandStart - lpC20Buf->cd.leftCount ;
+ lpC20Buf->bh.size = ConvertEndianDWORD(sizeBlockData) ;
+ lpC20Buf->bh.mode = ConvertEndianWord(MakeCompress20Mode(lpC20Buf->mode[i])) ;
+
+ for (x = 0 ; x < SIZEOF_BLOCKHEADER20 ; x++) {
+ *lpBandStart++ = GetByteBLOCKHEADER20(&lpC20Buf->bh, x);
+ }
+ }
+ else {
+ /* Output Un-Compress Data */
+ if (countBandStart < lpC20Buf->bandLimit) {
+ EPS_RETURN( FALSE )
+ }
+
+ sizeBlockData = lpC20Buf->bandLimit ;
+ lpC20Buf->bh.size = ConvertEndianDWORD(sizeBlockData) ;
+ lpC20Buf->bh.mode = ConvertEndianWord(MakeUncompress20Mode(lpC20Buf->mode[i])) ;
+
+ for (x = 0 ; x < SIZEOF_BLOCKHEADER20; x++) {
+ *lpBandStart++ = GetByteBLOCKHEADER20(&lpC20Buf->bh, x);
+ }
+
+ lpBand = lpSrc + i ;
+ for (j = 0 ; j < band ; j++) {
+ lpPt = lpBand ;
+ lpBand += lpC20Buf->cbuf.nextLine ;
+ for (x = 0 ; x < lpC20Buf->cbuf.dwWidth ; x++) {
+ *lpBandStart++ = *lpPt ;
+ lpPt += incptr ;
+ }
+ }
+
+ lpC20Buf->cd.lpCurPtr = lpBandStart ;
+ lpC20Buf->cd.leftCount = countBandStart - lpC20Buf->bandLimit ;
+ }
+ }
+
+ EPS_RETURN( TRUE )
+}
+
+
+static EPS_UINT8 GetByteBLOCKHEADER20(BLOCKHEADER20 *p, EPS_INT32 n)
+{
+ EPS_UINT8 b = 0;
+ switch(n){
+ case 0: b = (EPS_UINT8)(p->size) & 0x000000FF; break;
+ case 1: b = (EPS_UINT8)(p->size >> 8) & 0x000000FF; break;
+ case 2: b = (EPS_UINT8)(p->size >> 16) & 0x000000FF; break;
+ case 3: b = (EPS_UINT8)(p->size >> 24) & 0x000000FF; break;
+
+ case 4: b = (EPS_UINT8)(p->width) & 0x00FF; break;
+ case 5: b = (EPS_UINT8)(p->width >> 8) & 0x00FF; break;
+
+ case 6: b = (EPS_UINT8)(p->bandPixel) & 0x00FF; break;
+ case 7: b = (EPS_UINT8)(p->bandPixel >> 8) & 0x00FF; break;
+
+ case 8: b = (EPS_UINT8)(p->mode) & 0x00FF; break;
+ case 9: b = (unsigned char)(p->mode >> 8) & 0x00FF; break;
+
+ default: b = 0;
+ }
+ return b;
+}
+
+
+static void WriteDataToBuffer(CODINGDATA* const lpcd)
+{
+ if (lpcd->leftCount) {
+ *lpcd->lpCurPtr++ = (EPS_UINT8) lpcd->code ;
+ lpcd->leftCount-- ;
+ lpcd->code >>= 8 ;
+ }
+ lpcd->codeBits -= 8 ;
+}
+
+
+static void CodeHufmanData(const EPS_UINT8 d, CODINGDATA* const lpcd)
+{
+ lpcd->code |= ((EPS_UINT32) lpcd->hufCode[d]) << (lpcd->codeBits) ;
+ lpcd->codeBits += lpcd->hufCodeLen[d] ;
+
+ while (lpcd->codeBits >= 8) WriteDataToBuffer(lpcd) ;
+}
+
+
+static EPS_BOOL MakeHufmanCodeTable(EPS_UINT16 wMode, EPS_UINT16 wQuality, CODINGDATA* lpcd)
+{
+ switch (wMode) {
+ case EP_COMPRESS20 :
+ MakeHufmanTable1(HufmanDefTable2, lpcd) ;
+ return TRUE ;
+ }
+
+ return FALSE ;
+}
+
+
+static void MakeHufmanTable1(const EPS_UINT16 cdn[], CODINGDATA* lpcd)
+{
+
+ EPS_UINT16 huf, rhuf, temp, i ;
+ EPS_INT32 len, num, j ;
+
+ huf = 0 ;
+ num = 0 ;
+
+ for(len = 1 ; len <= 12; len++) {
+ huf <<= 1;
+
+ for(i = 0; i < cdn[len] ; i++) {
+ rhuf = 0 ;
+ temp = huf ;
+
+ for (j = 0 ; j < len ; j++) {
+ rhuf = (rhuf << 1) | (temp & 1) ;
+ temp >>= 1 ;
+ }
+
+ if (num) {
+ j = (num+1) >> 1 ;
+ if ((num & 0x1) == 0) j = 256 - j ;
+ }
+ else {
+ j = 0 ;
+ }
+
+ lpcd->hufCode[j] = rhuf ;
+ lpcd->hufCodeLen[j] = (EPS_UINT8) len ;
+
+ huf ++ ;
+ num ++ ;
+ }
+ }
+}
+
+
+/*_______________________________ epson-escpage-comp.c _____________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage-comp.h b/lib/epson-escpage-comp.h
new file mode 100644
index 0000000..9036210
--- /dev/null
+++ b/lib/epson-escpage-comp.h
@@ -0,0 +1,72 @@
+/*________________________________ epson-escpage-cmp.h ______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/Page Compless Functions */
+/* */
+/*******************************************|********************************************/
+
+#ifndef _EPSON_ESCPAGE_COMP_H_
+#define _EPSON_ESCPAGE_COMP_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+/* Define Compress Mode Constant */
+#define EP_COMPRESS0 0 /* not commpress */
+#define EP_COMPRESS20 20
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct tagEPS_BITMAPINFO{
+ EPS_INT32 biWidth;
+ EPS_INT32 biHeight;
+ EPS_UINT16 biBitCount;
+} EPS_BITMAPINFO;
+
+
+/*--------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern EPS_UINT8* CompressBitImage(
+ EPS_RECT *pRec,
+ EPS_BITMAPINFO *pBitMapInfo,
+ EPS_UINT8 *pRealBits,
+ EPS_UINT32 ulDataFormat,
+ EPS_UINT32 *pulCompressType,
+ EPS_UINT32 *pulImageSize
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _EPSON_ESCPAGE_COMP_H_ */
+
+/*________________________________ epson-escpage-cmp.h ______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage-mono.c b/lib/epson-escpage-mono.c
new file mode 100644
index 0000000..beb9246
--- /dev/null
+++ b/lib/epson-escpage-mono.c
@@ -0,0 +1,1551 @@
+/*_______________________________ epson-escpage-mono.c ______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-err.h"
+#include "epson-escpr-media.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpage.h"
+#include "epson-escpage-mono.h"
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_PAGE
+#define EPS_LOG_MODULE EPS_LOG_MODULE_PAGE
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+/*-------------------------------- ESC/PAGE commands ----------------------------------*/
+/*******************************************|********************************************/
+const static EPS_UINT8 sbCR[] = {0x0D}; /* Carriage return "CR" */
+const static EPS_UINT8 sbFF[] = {0x0C}; /* Form Feed "FF" */
+const static EPS_UINT8 sbIP[] = {0x1D, 'r', 'h', 'E'}; /* Initialize printer */
+const static EPS_UINT8 sbSU150[] = {0x1D, '0', ';', '.', '4', '8', 'm', 'u', 'E'}; /* Set unit to 150 */
+const static EPS_UINT8 sbSU300[] = {0x1D, '0', ';', '.', '2', '4', 'm', 'u', 'E'}; /* Set unit to 300 */
+const static EPS_UINT8 sbSU600[] = {0x1D, '0', ';', '.', '1', '2', 'm', 'u', 'E'}; /* Set unit to 600 */
+
+const static EPS_UINT8 sbPSSL[] = {0x1D, '3', '0', 'p', 's', 'E'}; /* Set Letter paper */
+const static EPS_UINT8 sbPSSA4[] = {0x1D, '1', '4', 'p', 's', 'E'}; /* Set A4 paper */
+const static EPS_UINT8 sbPSSB5[] = {0x1D, '2', '5', 'p', 's', 'E'}; /* Set B5 paper */
+const static EPS_UINT8 sbPSSLE[] = {0x1D, '3', '2', 'p', 's', 'E'}; /* Set Legal paper */
+const static EPS_UINT8 sbPSSA3[] = {0x1D, '1', '3', 'p', 's', 'E'}; /* Set A3 paper */
+const static EPS_UINT8 sbPSSB4[] = {0x1D, '2', '4', 'p', 's', 'E'}; /* Set B4 paper */
+const static EPS_UINT8 sbPSSPS[] = {0x1D, '3', '8', 'p', 's', 'E'}; /* Set B4 paper */
+
+const static EPS_UINT8 sbPTE0[] = {0x1D, '0', 'p', 't', 'E'}; /* select paper type 0:other */
+const static EPS_UINT8 sbPTE1[] = {0x1D, '1', 'p', 't', 'E'}; /* select paper type 1:plane */
+
+const static EPS_UINT8 sbCMS[] = {0x1D, '1', 'c', 'm', 'E'}; /* Clip Mode Set */
+const static EPS_UINT8 sbSDS150[] = {0x1D, '0', ';', '1', '5', '0', ';', '1', '5', '0', 'd', 'r', 'E'}; /* Select Dot Size(150) */
+const static EPS_UINT8 sbSDS300[] = {0x1D, '0', ';', '3', '0', '0', ';', '3', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(300) */
+const static EPS_UINT8 sbSDS600[] = {0x1D, '0', ';', '6', '0', '0', ';', '6', '0', '0', 'd', 'r', 'E'}; /* Select Dot Size(600) */
+
+const static EPS_UINT8 sbMMS[] = {0x1D, '0', 'm', 'm', 'E'}; /* Select Page memory mode */
+const static EPS_UINT8 sbPDS[] = {0x1D, '0', 'p', 'o', 'E'}; /* Set paper direction to normal */
+const static EPS_UINT8 sbACRLFS[] = {0x1D, '0', 'a', 'l', 'f', 'P'}; /* Does not perform auto carriage return */
+const static EPS_UINT8 sbAFFS[] = {0x1D, '0', 'a', 'f', 'f', 'P'}; /* Does not perform auto Form Feed */
+const static EPS_UINT8 sbABPS[] = {0x1D, '0', 'a', 'b', 'P'}; /* Set current position to 0 after bit image draw */
+const static EPS_UINT8 sbSARGAS[] = {0x1D, '0', 's', 'a', 'r', 'G'}; /* Set Absolute Graph Coordinate mode */
+const static EPS_UINT8 sbPMPPS[] = {0x1D, '1', 'p', 'm', 'P'}; /* Set current move mode to print pitch mode */
+
+const static EPS_UINT8 sbSPRCS[] = {0x1D, '1', '6', '0', 'i', 's', 'E'}; /* Screen Pattern Record Count set to 160 */
+const static EPS_UINT8 sbFASCS[] = {0x1D, '7', 'i', 'a', 'F'}; /* Font Attribute Store Count set to 7 */
+const static EPS_UINT8 sbCPSCS[] = {0x1D, '5', 'i', 'p', 'P'}; /* Current Position Store Count set to 5 */
+const static EPS_UINT8 sbMRCS[] = {0x1D, '1', '6', '0', 'i', 'm', 'M'}; /* Macro Record Store Count set to 160 */
+const static EPS_UINT8 sbBIRCS[] = {0x1D, '2', '3', '2', '8', 'i', 'b', 'I'}; /* Bit Image Count Store Count set to 2328 */
+const static EPS_UINT8 sbBIOS[] = {0x1D, '0', 'b', 'o', 'P'}; /* Set the bit image drawing offset to 0 */
+const static EPS_UINT8 sbILGS[] = {0x1D, '1', '6', '0', 'i', 'l', 'G'}; /* Set line type record count to 160 */
+const static EPS_UINT8 sbTSESS[] = {0x1D, '1', 't', 's', 'E'}; /* Set Screen Mode */
+const static EPS_UINT8 sbSPES[] = {0x1D, '1', ';', '0', ';', '1', '0', '0', 's', 'p', 'E'}; /* Set Screen Pattern */
+const static EPS_UINT8 sbOWES[] = {0x1D, '2', 'o', 'w', 'E'}; /* Set Superimpose Mode */
+const static EPS_UINT8 sbBCI1S[] = {0x1D, '1', 'b', 'c', 'I'}; /* Select Data compression type #1 */
+const static EPS_INT8 sbBID[] = "\x1D""%d;%d;1;0bi{I"; /* Output data */
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#define EPS_EJL_LINEMAX (256)
+#define EPS_PAGE_CMDBUFF_SIZE EPS_EJL_LINEMAX
+
+#define EMIT_TIFF_REPEAT(n, x) \
+{ \
+ nRowTIFF += 3; \
+ if (RowTIFF) \
+ { \
+ *RowTIFF++ = x; \
+ *RowTIFF++ = x; \
+ *RowTIFF++ = (EPS_UINT8)n; \
+ } \
+}
+
+#define EMIT_TIFF_LITERAL(n, p) \
+{ \
+ nRowTIFF += n; \
+ if (RowTIFF) \
+ { \
+ memcpy(RowTIFF, p, n); \
+ RowTIFF += n; \
+ } \
+}
+
+#define TIFF_MAXIMUM_LITERAL 128
+#define TIFF_MAXIMUM_REPEAT 129
+
+#define CALCULATE_INTENSITY(r,g,b) (((((b)<<8) * 11)/100 + (((g)<<8) * 59)/100 + (((r)<<8) * 30)/100)/256)
+#define MAX_8 ((1 << 8) - 1)
+#define DOT_K 100
+#define E_MAX (1 << 13)
+#define E_MID (E_MAX >> 1)
+
+/* The following table is used to convert a from an intensity we desire */
+/* to an intensity to tell the device. It is calibrated for the */
+/* error-diffusion code. */
+const EPS_UINT8 Intensity2Intensity[256] =
+{
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7, 8,
+ 9, 9, 10, 10, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16,
+ 16, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20, 21, 21, 21, 22, 22,
+ 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27,
+ 27, 28, 28, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39,
+ 40, 41, 41, 42, 43, 44, 44, 45, 46, 47, 47, 48, 48, 49, 49, 49,
+ 50, 50, 50, 51, 51, 51, 52, 52, 52, 53, 53, 54, 54, 54, 55, 55,
+ 55, 56, 56, 56, 57, 57, 58, 59, 59, 60, 60, 61, 61, 62, 63, 64,
+ 64, 65, 65, 65, 66, 66, 67, 67, 68, 68, 69, 70, 70, 71, 72, 73,
+ 74, 75, 76, 76, 77, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
+ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,103,104,
+ 105,106,108,109,110,112,113,114,115,116,118,120,122,124,126,128,
+ 130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,159,
+ 160,162,164,165,166,168,170,172,173,174,176,178,180,182,184,186,
+ 188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,
+ 220,222,224,226,228,230,232,234,236,238,240,242,244,248,252,255
+};
+
+/* Used in color correction */
+const static EPS_INT32 BitMask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+/* Band data */
+typedef struct _tagEPS_PAGE_BAND_M_ {
+ EPS_INT32 WidthInBytes;
+ EPS_INT32 WidthInPixels;
+ EPS_INT32 currentWidthInPixels;
+ EPS_UINT8 *pRasterData;
+ EPS_UINT8 *pIntensity;
+ EPS_INT32 encDataSize;
+ EPS_UINT8 *pEncData;
+ EPS_UINT8 *pZeroRow;
+}EPS_PAGE_BAND_M;
+
+/* Error Diffusion */
+typedef struct tagHT_PARAM{
+ EPS_INT32 iDK;
+ EPS_INT16 *pEK;
+ EPS_INT32 iOrder;
+ EPS_INT32 iScanPels;
+} HT_PARAM;
+
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+extern EPS_CMN_FUNC epsCmnFnc;
+extern EPS_PRINT_JOB printJob;
+
+/*---------------------------------- Local Variables --------------------------------*/
+/*******************************************|********************************************/
+static EPS_PAGE_BAND_M band;
+static EPS_COMMAND_BUFFER cmdBuf;
+static EPS_UINT8* Palette2DeviceIntensity = NULL;
+static EPS_INT32 iRow = 0;
+static EPS_INT32 iNumBytes = 0;
+static EPS_INT32 iNumDots = 0;
+static EPS_INT32 pageCount = 0; /* Current Page number */
+
+#if EPS_PAGE_HT_ERR_DIFFUSION
+HT_PARAM htParam;
+#else
+EPS_UINT8 * pP = 0;
+EPS_INT32 iOrder;
+EPS_INT32 iScanPels;
+#endif
+
+/*-------------------------- Local Functions Declaration ----------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE CmdBuffInit (EPS_COMMAND_BUFFER *pCmdBuff);
+static EPS_ERR_CODE CmdBuffGrow (EPS_COMMAND_BUFFER *pCmdBuff, EPS_INT32 addSize);
+static void CmdBuffTerm (EPS_COMMAND_BUFFER *pCmdBuff);
+
+static void ConvertBYTE2Intensity (const EPS_BANDBMP* pInBmp, EPS_PAGE_BAND_M *pBand);
+static EPS_ERR_CODE ConvertPaletteToIntensity(EPS_UINT16 paletteSize, EPS_UINT8 *paletteData);
+
+static EPS_ERR_CODE BandInit (EPS_PAGE_BAND_M *pBand, EPS_INT32 widthInPixels);
+static void BandTerm (EPS_PAGE_BAND_M* pBand);
+static void BandEncode (EPS_PAGE_BAND_M* pBand);
+static EPS_ERR_CODE BandEmit (EPS_PAGE_BAND_M *pBand, EPS_INT32 iNByte, EPS_INT32 iNDot);
+
+static EPS_ERR_CODE HT_Init (EPS_INT32 WidthPixels);
+static void HT_End (void);
+static void HT_StartPage (void);
+static void HT_Scan (EPS_UINT8 *Con, EPS_UINT8 *Bin, EPS_INT32 widthInPixels);
+
+static EPS_INT32 DoDeltaRow (EPS_UINT8 *Row, EPS_INT32 nRow, EPS_UINT8 *RowDeltaRow, EPS_UINT8 *Seed);
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageAllocBuffer_M() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocate buffer for ESC/Page Job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageAllocBuffer_M(void)
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+ ret = BandInit(&band, printJob.printableAreaWidth);
+ if ( EPS_ERR_NONE != ret ) {
+ EPS_RETURN( ret )
+ }
+
+ if (printJob.attr.colorPlane == EPS_CP_256COLOR){
+ ret = ConvertPaletteToIntensity(printJob.attr.paletteSize, printJob.attr.paletteData);
+ if ( EPS_ERR_NONE != ret ) {
+ EPS_RETURN( ret )
+ }
+ }
+
+ /* Halftoning Initialization */
+ ret = HT_Init( printJob.printableAreaWidth );
+ if ( EPS_ERR_NONE != ret ) {
+ EPS_RETURN( ret )
+ }
+
+ ret = CmdBuffInit(&cmdBuf);
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageRelaseBuffer_M() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* Free buffer for ESC/Page Job. */
+/* */
+/*******************************************|********************************************/
+void pageRelaseBuffer_M(void)
+{
+ EPS_LOG_FUNCIN
+
+ BandTerm(&band);
+
+ EPS_SAFE_RELEASE( Palette2DeviceIntensity );
+
+ CmdBuffTerm(&cmdBuf);
+
+ /* Halftoning Ending process */
+ HT_End();
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageStartJob_M() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page start job commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageStartJob_M(void)
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+#define pgStartJob_ADDCMD(CMD) { \
+ ret = CmdBuffGrow(&cmdBuf, sizeof(CMD) ); \
+ if( EPS_ERR_NONE != ret){EPS_RETURN( ret )} \
+ memcpy(cmdBuf.p + cmdBuf.len, CMD, sizeof(CMD)); \
+ cmdBuf.len += sizeof(CMD); \
+ }
+
+ cmdBuf.len = 0; /* reset */
+
+ ret = ejlStart(&cmdBuf, CmdBuffGrow);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ /* Step 1 - Start Job */
+ /* Initialize the printer. */
+ pgStartJob_ADDCMD(sbIP)
+
+ /* Set the minimum Unit Setting (600 or 300 resolution) */
+ /* Dot Pattern Resolution Selection */
+ if( EPS_IR_600X600 == printJob.attr.inputResolution) {
+ pgStartJob_ADDCMD(sbSU600);
+ pgStartJob_ADDCMD(sbSDS600);
+ } else if(EPS_IR_300X300 == printJob.attr.inputResolution) {
+ pgStartJob_ADDCMD(sbSU300);
+ pgStartJob_ADDCMD(sbSDS300);
+ }else{
+ pgStartJob_ADDCMD(sbSU150);
+ pgStartJob_ADDCMD(sbSDS150);
+ }
+
+ /* Set Memory Mode Selection to Page memory mode */
+ pgStartJob_ADDCMD(sbMMS);
+
+ /* Set Screen Record Count */
+ pgStartJob_ADDCMD(sbSPRCS);
+
+ /* Set Font Attribute Store Count */
+ pgStartJob_ADDCMD(sbFASCS);
+
+ /* Set Current Position Store Count */
+ pgStartJob_ADDCMD(sbCPSCS);
+
+ /* Set Macro Record Store Count */
+ pgStartJob_ADDCMD(sbMRCS);
+
+ /* Set Bit Image Record Store Count */
+ pgStartJob_ADDCMD(sbBIRCS);
+
+ /* Set Paper Size */
+ switch ( printJob.attr.mediaSizeIdx ) {
+ case EPS_MSID_A4: pgStartJob_ADDCMD(sbPSSA4); break;
+ case EPS_MSID_B5: pgStartJob_ADDCMD(sbPSSB5); break;
+ case EPS_MSID_B4: pgStartJob_ADDCMD(sbPSSB4); break;
+ case EPS_MSID_A3: pgStartJob_ADDCMD(sbPSSA3); break;
+ case EPS_MSID_LETTER: pgStartJob_ADDCMD(sbPSSL); break;
+ case EPS_MSID_LEGAL: pgStartJob_ADDCMD(sbPSSLE); break;
+ case EPS_MSID_POSTCARD: pgStartJob_ADDCMD(sbPSSPS); break;
+ default: pgStartJob_ADDCMD(sbPSSA4); break;
+ }
+
+ /* select paper type */
+ if(printJob.attr.mediaTypeIdx == EPS_MTID_PLAIN){
+ pgStartJob_ADDCMD(sbPTE1);
+ }else{
+ pgStartJob_ADDCMD(sbPTE0);
+ }
+
+ /* Set paper direction */
+ pgStartJob_ADDCMD(sbPDS);
+
+ ret = ejlPageEsc(&cmdBuf, CmdBuffGrow);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ /* Set Clip Mode */
+ pgStartJob_ADDCMD(sbCMS);
+
+ /* Does not perform automatic carriage return line feed */
+ pgStartJob_ADDCMD(sbACRLFS);
+
+ /* Does not perform automatic Form Feed */
+ pgStartJob_ADDCMD(sbAFFS);
+
+ /* Set the bit image drawing offset to 0 */
+ pgStartJob_ADDCMD(sbBIOS);
+
+ /* Set current position to 0 after Bit image draw */
+ pgStartJob_ADDCMD(sbABPS);
+
+ /* Set line type record count to 160 */
+ pgStartJob_ADDCMD(sbILGS);
+
+ /* Step 4 - Adjust Vertical Print Position (if necessary) */
+ /* CR */
+ pgStartJob_ADDCMD(sbCR);
+
+ /* Select compression type */
+ pgStartJob_ADDCMD(sbBCI1S);
+
+ /* Set Absolute graph coordinate mode */
+ pgStartJob_ADDCMD(sbSARGAS);
+
+ /* Set current position move mode to print pitch */
+ pgStartJob_ADDCMD(sbPMPPS);
+
+ /* Set Screen Mode */
+ pgStartJob_ADDCMD(sbTSESS);
+
+ /* Set Screen Pattern */
+ pgStartJob_ADDCMD(sbSPES);
+
+ /* Set Screen Pattern */
+ pgStartJob_ADDCMD(sbOWES);
+
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, cmdBuf.len, &retBufSize, TRUE);
+
+ pageCount = 0;
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageEndJob_M() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page end job commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageEndJob_M()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ cmdBuf.len = 0; /* reset */
+
+ /* Check empty document */
+ if( iRow != 0 ) {
+ /* Formfeed (FF) */
+ memcpy((EPS_INT8*)cmdBuf.p, sbFF, sizeof(sbFF));
+ cmdBuf.len += sizeof(sbFF);
+
+ /* Send command to initialize the printer. */
+ memcpy((EPS_INT8*)cmdBuf.p+cmdBuf.len, sbIP, sizeof(sbIP));
+ cmdBuf.len += sizeof(sbIP);
+ }
+
+ /*** Make EJL Command ***/
+ ret = ejlEnd(&cmdBuf, CmdBuffGrow, pageCount);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, cmdBuf.len, &retBufSize, TRUE);
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageStartPage_M() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page start page commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageStartPage_M()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ HT_StartPage();
+ iRow = 0;
+
+ if (pageCount++) {
+
+ cmdBuf.len = 0; /* reset */
+
+ memcpy(cmdBuf.p, sbFF, sizeof(sbFF));
+ cmdBuf.len += sizeof(sbFF);
+
+ ret = ejlPageEsc(&cmdBuf, CmdBuffGrow);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, cmdBuf.len, &retBufSize, TRUE);
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageColorRow_M() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page raster commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageColorRow_M(
+
+ const EPS_BANDBMP* pInBmp,
+ EPS_RECT* pBandRec
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+ if( (EPS_UINT32)(pBandRec->right - pBandRec->left) <= printJob.printableAreaWidth){
+ band.currentWidthInPixels = (EPS_UINT16)(pBandRec->right - pBandRec->left);
+ } else{
+ band.currentWidthInPixels = (EPS_UINT16) printJob.printableAreaWidth;
+ }
+
+ ConvertBYTE2Intensity( pInBmp, &band );
+
+ memset( band.pRasterData, 0, band.WidthInBytes);
+ HT_Scan( band.pIntensity, (EPS_UINT8*)band.pRasterData, band.currentWidthInPixels);
+
+ iNumBytes = 0;
+ iNumDots = 0;
+
+ BandEncode(&band);
+
+ if( band.encDataSize ) {
+ ret = BandEmit(&band, iNumBytes, iNumDots);
+ }
+
+ iRow++;
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageSendLeftovers_M() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_INVALID_CALL - This call was unnecessary */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* send leftovers data. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageSendLeftovers_M(
+
+ void
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL != printJob.contData.sendData && 0 < printJob.contData.sendDataSize){
+ /* send command */
+ ret = SendCommand(printJob.contData.sendData,
+ printJob.contData.sendDataSize, &retBufSize, TRUE);
+ } else{
+ ret = EPS_ERR_INVALID_CALL;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CmdBuffInit() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocate command buffer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE CmdBuffInit(
+
+ EPS_COMMAND_BUFFER *pCmdBuff
+
+){
+ pCmdBuff->size = EPS_EJL_LINEMAX*2;
+ pCmdBuff->p = (EPS_INT8*)EPS_ALLOC(pCmdBuff->size);
+ if( NULL == pCmdBuff->p){
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+
+ pCmdBuff->len = 0;
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CmdBuffGrow() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* addSize EPS_INT32 I: growing size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* ReAllocate command buffer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE CmdBuffGrow(
+
+ EPS_COMMAND_BUFFER *pCmdBuff,
+ EPS_INT32 addSize
+
+){
+ EPS_INT32 block, sizeNew;
+
+ if(pCmdBuff->size < pCmdBuff->len + addSize){
+ block = (((pCmdBuff->len+addSize) / EPS_PAGE_CMDBUFF_SIZE) + 1);
+ sizeNew = block * EPS_PAGE_CMDBUFF_SIZE;
+ pCmdBuff->p = memRealloc(pCmdBuff->p, pCmdBuff->size, sizeNew);
+ if( NULL == pCmdBuff->p){
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+ pCmdBuff->size = sizeNew;
+ }
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CmdBuffTerm() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* Free command buffer. */
+/* */
+/*******************************************|********************************************/
+static void CmdBuffTerm (
+
+ EPS_COMMAND_BUFFER *pCmdBuff
+
+){
+ EPS_SAFE_RELEASE(pCmdBuff->p);
+ pCmdBuff->len = 0;
+ pCmdBuff->size = 0;
+ pCmdBuff->pExtent = NULL;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: ConvertBYTE2Intensity() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* paletteSize EPS_UINT16 I: Palette Size */
+/* paletteData EPS_UINT8* I: Palette Size */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* Convert palette to Intensity. */
+/* */
+/*******************************************|********************************************/
+static void ConvertBYTE2Intensity(
+
+ const EPS_BANDBMP* pInBmp,
+ EPS_PAGE_BAND_M *pBand
+
+){
+ EPS_UINT32 idx;
+ EPS_INT32 i, j, widthBytes;
+
+ EPS_LOG_FUNCIN;
+
+ widthBytes = pBand->currentWidthInPixels * printJob.bpp;
+ j = 0;
+ if(printJob.bpp == 3){
+ for (i = 0; i < widthBytes; i += printJob.bpp) {
+ /* idx = CALCULATE_INTENSITY(pInBmp->bits[i], pInBmp->bits[i+1], pInBmp->bits[i+2]);*/
+ idx = pInBmp->bits[i];
+ idx = 255 - idx;
+ if (idx > 255) idx = 255;
+
+ pBand->pIntensity[j++] = Intensity2Intensity[idx];
+
+ if(j >= pBand->WidthInPixels){
+ break;
+ }
+ }
+ } else{
+ for (i = 0; i < widthBytes; i += printJob.bpp) {
+ idx = pInBmp->bits[i];
+ pBand->pIntensity[j++] = Palette2DeviceIntensity[idx];
+ if(j >= pBand->WidthInPixels){
+ break;
+ }
+ }
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: ConvertPaletteToIntensity() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* paletteSize EPS_UINT16 I: Palette Size */
+/* paletteData EPS_UINT8* I: Palette Size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Convert palette to Intensity. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE ConvertPaletteToIntensity(
+
+ EPS_UINT16 paletteSize,
+ EPS_UINT8 *paletteData
+
+){
+ EPS_UINT32 idx;
+ EPS_UINT32 i, j;
+ EPS_LOG_FUNCIN;
+
+ Palette2DeviceIntensity = (EPS_UINT8*)EPS_ALLOC( (paletteSize/3)*sizeof(EPS_UINT8) );
+ if (!Palette2DeviceIntensity) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+ j = 0;
+ for (i = 0; i < paletteSize; i += 3) {
+ /* idx = CALCULATE_INTENSITY(paletteData[i], paletteData[i+1], paletteData[i+2]); */
+ idx = paletteData[i];
+ idx = 255 - idx;
+ if (idx > 255) idx = 255;
+ Palette2DeviceIntensity[j++] = Intensity2Intensity[idx];
+ }
+
+ EPS_RETURN( EPS_ERR_NONE )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandInit() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND_M* I: band data strcture */
+/* widthInPixels EPS_INT32 I: width in Pixels */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocate band data buffers. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE BandInit(
+
+ EPS_PAGE_BAND_M* pBand,
+ EPS_INT32 widthInPixels
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT32 maxEpsonEncodedData;
+
+ EPS_LOG_FUNCIN;
+
+ memset(pBand, 0, sizeof(pBand));
+
+ pBand->WidthInPixels = widthInPixels;
+ pBand->WidthInBytes = (pBand->WidthInPixels+7)/8;
+
+ /* We leave room for an entire TIFF literal -plus- room */
+ /* for the longest possible XFER header (3 bytes). */
+ maxEpsonEncodedData = 256 + 3 + pBand->WidthInBytes
+ + (pBand->WidthInBytes + TIFF_MAXIMUM_LITERAL - 1)/TIFF_MAXIMUM_LITERAL;
+
+ pBand->pRasterData = (EPS_UINT8*)EPS_ALLOC(pBand->WidthInBytes);
+ if (NULL == pBand->pRasterData) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ pBand->pEncData = (EPS_UINT8*)EPS_ALLOC(maxEpsonEncodedData);
+ if (NULL == pBand->pEncData) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ pBand->pZeroRow = (EPS_UINT8*)EPS_ALLOC(pBand->WidthInBytes);
+ if (NULL == pBand->pZeroRow) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+ memset(pBand->pZeroRow, 0, pBand->WidthInBytes);
+
+ pBand->pIntensity = (EPS_UINT8*)EPS_ALLOC(pBand->WidthInPixels);
+ if (!pBand->pIntensity){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ EPS_RETURN(ret)
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandTerm() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND_M* I: band data strcture */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* free band data buffers. */
+/* */
+/*******************************************|********************************************/
+static void BandTerm(
+
+ EPS_PAGE_BAND_M* pBand
+
+){
+ EPS_LOG_FUNCIN
+
+ EPS_SAFE_RELEASE( pBand->pRasterData );
+ EPS_SAFE_RELEASE( pBand->pEncData );
+ EPS_SAFE_RELEASE( pBand->pZeroRow );
+ EPS_SAFE_RELEASE( pBand->pIntensity );
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandEmit() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND_M* I: band data strcture */
+/* pCmdBuff EPS_COMMAND_BUFFER* I: command buffer strcture */
+/* iNByte EPS_INT32 I: number of data bytes */
+/* iNDot EPS_INT32 I: number of data dots */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Emit data to printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE BandEmit(
+
+ EPS_PAGE_BAND_M* pBand,
+ EPS_INT32 iNByte,
+ EPS_INT32 iNDot
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 *p;
+ EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ cmdBuf.len = 0; /* reset */
+ p = (EPS_INT8*)cmdBuf.p;
+
+ EPS_DBGPRINT(("Y = %d \r\n", iRow));
+ sprintf(p, "\x1D%dY", iRow);
+ p += strlen(p);
+
+ /* Number of data bytes */
+ /* Bit image width */
+ /* Bit image height */
+ /* Angle of rotation */
+ sprintf(p, sbBID, iNByte, iNDot);
+ p += strlen(p);
+
+ cmdBuf.len += (EPS_UINT32)(p - cmdBuf.p);
+ ret = CmdBuffGrow(&cmdBuf, pBand->encDataSize);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+ p = cmdBuf.p + cmdBuf.len;
+
+ memcpy(p, pBand->pEncData, pBand->encDataSize);
+ cmdBuf.len += pBand->encDataSize;
+
+ pBand->encDataSize = 0;
+
+ ret = SendCommand((EPS_UINT8*)cmdBuf.p, cmdBuf.len, &retBufSize, TRUE);
+
+ EPS_RETURN(ret)
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BandEncode() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBand EPS_PAGE_BAND_M* I: band data strcture */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* Do Compression. */
+/* */
+/*******************************************|********************************************/
+static void BandEncode(
+
+ EPS_PAGE_BAND_M* pBand
+
+){
+ EPS_BOOL isZero = FALSE;
+ EPS_INT32 widthInBytes = (pBand->currentWidthInPixels+7)/8;
+
+ EPS_LOG_FUNCIN
+
+ /* Check blank line */
+ isZero = (memcmp(pBand->pRasterData, pBand->pZeroRow, widthInBytes) == 0)?TRUE:FALSE;
+
+ /* No compression for blank line */
+ if( isZero ) {
+ pBand->encDataSize = 0;
+ } else{
+ pBand->encDataSize = DoDeltaRow( pBand->pRasterData,
+ widthInBytes,
+ pBand->pEncData,
+ pBand->pZeroRow
+ );
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* HT_Init */
+/* */
+/* Description: */
+/* */
+/* Halftoning initialization */
+/* */
+/*=========================================================*/
+static EPS_ERR_CODE HT_Init(EPS_INT32 WidthPixels)
+{
+ EPS_LOG_FUNCIN
+
+ srand(119);
+
+ htParam.pEK = NULL;
+ htParam.iScanPels = WidthPixels;
+ htParam.iOrder = 5;
+ htParam.iDK = DOT_K * E_MAX / 100;
+
+ htParam.pEK = (EPS_INT16*)EPS_ALLOC((htParam.iScanPels + 2)*sizeof(EPS_INT16));
+ if( NULL == htParam.pEK){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ EPS_RETURN( EPS_ERR_NONE )
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* HT_End */
+/* */
+/* Description: */
+/* */
+/* Halftoning Ending process */
+/* */
+/*=========================================================*/
+static void HT_End()
+{
+EPS_LOG_FUNCIN
+ EPS_SAFE_RELEASE( htParam.pEK );
+EPS_RETURN_VOID
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* HT_StartPage */
+/* */
+/* Description: */
+/* */
+/* Halftoning start page process */
+/* */
+/*=========================================================*/
+static void HT_StartPage()
+{
+ EPS_LOG_FUNCIN
+
+ if (htParam.pEK){
+ memset(htParam.pEK, 0, (htParam.iScanPels + 2) * sizeof(EPS_INT16));
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* HT_Scan */
+/* */
+/* Description: */
+/* */
+/* Check halftoning method */
+/* */
+/*=========================================================*/
+static void HT_Scan(EPS_UINT8 *Con, EPS_UINT8 *Bin, EPS_INT32 widthInPixels)
+{
+/* Error Diffusion */
+ EPS_INT32 i, j, k;
+ EPS_INT32 iE, iE1, iE3, iE5, iE7, iR;
+ EPS_INT32 iCon;
+ EPS_INT32 iDot;
+ EPS_INT32 iF;
+ EPS_INT16 *p;
+
+ EPS_LOG_FUNCIN
+
+ p = htParam.pEK + 1;
+ iDot = htParam.iDK;
+
+ iE1 = 0;
+ iE7 = 0;
+ iR = 0;
+
+ i = 0;
+ j = 1;
+
+ for (k = 0; k < widthInPixels; k++) {
+ if (Con[i] == 0) {
+ } else if (Con[i] == MAX_8) {
+ Bin[i >> 3] |= BitMask[i & 7];
+ } else {
+ iCon = Con[i] * (E_MAX / (MAX_8 + 1));
+
+ iE = rand() * (iCon - E_MID) / RAND_MAX;
+ if (((iR > 0) && (iE > 0)) || ((iR < 0) && (iE < 0))) {
+ iE = -iE;
+ }
+ iR = iE;
+
+ iCon += p[i] + iE7;
+
+ if (iCon + iR > E_MID) {
+ Bin[i >> 3] |= BitMask[i & 7];
+ iE = iCon - iDot;
+ } else {
+ iE = iCon;
+ }
+
+ iF = iE / 16;
+ iE3 = iF * 3;
+ iE5 = iF * 5;
+
+ p[i] = iE5 + iE1;
+ p[i - j] += iE3;
+
+ iE1 = iF;
+ iE7 = iE - iE1 - iE3 - iE5;
+ }
+
+ i += j;
+ }
+
+ p[i - j] += iE7 + iE1;
+
+ p[0] += p[-1];
+ p[htParam.iScanPels - 1] += p[htParam.iScanPels];
+
+ p[-1] = 0;
+ p[htParam.iScanPels] = 0;
+
+ EPS_RETURN_VOID
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* DoTIFF */
+/* */
+/* Description: */
+/* */
+/* Do TIFF compression */
+/* */
+/*=========================================================*/
+EPS_INT32 DoTIFF(EPS_UINT8 *Row, EPS_INT32 nRow, EPS_UINT8 *RowTIFF)
+{
+ EPS_INT32 nRowTIFF = 0; /* Total size of TIFF encoded row. */
+ EPS_INT32 nLiteral = 0; /* Count of literal bytes. */
+ EPS_INT32 nRepeat = 0; /* Count of repeated byte. */
+ EPS_UINT8 ch;
+ EPS_INT32 n;
+
+ /* Load first byte from row into parser. */
+ nRepeat++;
+ nLiteral++;
+ ch = *Row++;
+
+ for( ; nRow--; ch = *Row++ ) {
+ if( nLiteral > TIFF_MAXIMUM_LITERAL ) {
+ /* Literal part has grown too large, emit the largest literal pattern we can. */
+ EMIT_TIFF_LITERAL( TIFF_MAXIMUM_LITERAL, Row-nLiteral );
+ nLiteral -= TIFF_MAXIMUM_LITERAL;
+ } else if( nRepeat > TIFF_MAXIMUM_REPEAT ) {
+ /* Repeated part has grown too large, emit the literal (if present) and then */
+ /* emit the largest repeated pattern we can. */
+ EMIT_TIFF_REPEAT( TIFF_MAXIMUM_REPEAT, ch );
+ nRepeat -= TIFF_MAXIMUM_REPEAT;
+ }
+ if( ch == *Row ) {
+ if( nLiteral ) {
+ if( nLiteral >= 2 ) {
+ EMIT_TIFF_LITERAL( nLiteral-1, Row-nLiteral );
+ }
+ nLiteral = 1;
+ }
+ nRepeat++;
+ } else {
+ if( nRepeat >= 2 ) {
+ EMIT_TIFF_REPEAT( nRepeat, ch );
+ nRepeat = 1;
+ nLiteral = 0;
+ }
+ nLiteral++;
+ }
+ }
+ if( nRepeat == 1 ) {
+ nRepeat = 0;
+ }
+ if( nLiteral == 1 && nRepeat >= 2 ) {
+ nLiteral = 0;
+ }
+
+ while (nLiteral) {
+ n = nLiteral;
+ if (n > TIFF_MAXIMUM_LITERAL) {
+ n = TIFF_MAXIMUM_LITERAL;
+ }
+ if( nRepeat ) {
+ EMIT_TIFF_LITERAL(n-1, Row-nLiteral);
+ } else {
+ EMIT_TIFF_LITERAL(n-1, Row-nLiteral);
+ }
+ nLiteral -= n;
+ }
+
+ while (nRepeat) {
+ n = nRepeat;
+ if (n > TIFF_MAXIMUM_REPEAT) {
+ n = TIFF_MAXIMUM_REPEAT;
+ }
+ EMIT_TIFF_REPEAT(n, ch);
+ nRepeat -= n;
+ }
+
+ return nRowTIFF;
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* DeltaRowEmitXFER */
+/* */
+/* Description: */
+/* */
+/* Construct DeltaRow control code and data */
+/* */
+/*=========================================================*/
+void DeltaRowEmitXFER(EPS_UINT8 *Row, EPS_INT32 nXFER, EPS_INT32 nXFERTIFF, EPS_INT32 *nRowDeltaRow, EPS_UINT8 **RowDeltaRow)
+{
+ EPS_LOG_FUNCIN;
+
+ /* Get data length and send before all data of the current row */
+ iNumBytes += nXFERTIFF;
+ iNumDots += nXFER * 8;
+
+ /* TIFF data for XFER */
+ *nRowDeltaRow += nXFERTIFF;
+ if (*RowDeltaRow)
+ {
+ DoTIFF(Row, nXFER, *RowDeltaRow);
+ *RowDeltaRow += nXFERTIFF;
+ }
+
+ EPS_RETURN_VOID
+}
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* DeltaRowEmitMOVX */
+/* */
+/* Description: */
+/* */
+/* Construct DeltaRow horizontal position movement */
+/* */
+/*=========================================================*/
+void DeltaRowEmitMOVX(EPS_INT32 nSkip, EPS_INT32 *nRowDeltaRow, EPS_UINT8 **RowDeltaRow)
+{
+ EPS_UINT8 N;
+ EPS_INT32 num=0;
+ EPS_INT32 num1=0;
+
+ EPS_LOG_FUNCIN;
+
+ /* Send repeat "00" instead. Send 255 "00" the most each time */
+ if( nSkip == 0 ) {
+ EPS_RETURN_VOID
+ }
+
+ if( nSkip > 255 ) {
+ num1 = nSkip - 255;
+ num = 255;
+ } else {
+ num = nSkip;
+ }
+ *nRowDeltaRow += 3;
+ iNumBytes += 3;
+ iNumDots += num * 8;
+
+ if (*RowDeltaRow) {
+ N = num;
+ *((*RowDeltaRow)++) = 0x00;
+ *((*RowDeltaRow)++) = 0x00;
+ *((*RowDeltaRow)++) = N;
+ }
+ if( num1 > 255 ) {
+ /* Still have more than 255 "00" */
+ DeltaRowEmitMOVX(num1, nRowDeltaRow, RowDeltaRow);
+ } else {
+ if( num1 > 0 ) {
+ *nRowDeltaRow += 3;
+ iNumBytes += 3;
+ iNumDots += num1 * 8;
+ if (*RowDeltaRow)
+ {
+ N = num1;
+ *((*RowDeltaRow)++) = 0x00;
+ *((*RowDeltaRow)++) = 0x00;
+ *((*RowDeltaRow)++) = N;
+ }
+ }
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* DeltaRowEmitReduce */
+/* */
+/* Description: */
+/* */
+/* */
+/* */
+/*=========================================================*/
+void DeltaRowEmitReduce(EPS_UINT8 *Row, EPS_INT32 *nDelta0, EPS_INT32 *nSkip, EPS_INT32 *nDelta1, EPS_INT32 *nRowDeltaRow, EPS_UINT8 **RowDeltaRow)
+{
+ EPS_INT32 nDelta0TIFF, nDelta1TIFF, nDeltaTIFF, SizeofDSD, SizeofD;
+
+ EPS_LOG_FUNCIN;
+
+ if (*nDelta0) {
+ /* (DSD) state. */
+ nDelta0TIFF = DoTIFF(Row - *nDelta1 - *nSkip - *nDelta0, *nDelta0, 0);
+ nDelta1TIFF = DoTIFF(Row - *nDelta1, *nDelta1, 0);
+ nDeltaTIFF = DoTIFF(Row - *nDelta1 - *nSkip - *nDelta0, *nDelta0 + *nSkip + *nDelta1, 0);
+
+ SizeofDSD = nDelta0TIFF + nDelta1TIFF + (nDelta0TIFF>15?1:0)
+ + (nDelta0TIFF>255?1:0) + (nDelta1TIFF>15?1:0)
+ + (nDelta1TIFF>255?1:0) + (*nSkip>7?1:0) + (*nSkip>127?1:0) + 3;
+ SizeofD = nDeltaTIFF + (nDeltaTIFF>15?1:0) + (nDeltaTIFF>255?1:0) + 1;
+
+ } else {
+ /* (-SD) state. */
+ nDelta0TIFF = 0;
+ nDelta1TIFF = DoTIFF(Row - *nDelta1, *nDelta1, 0);
+ nDeltaTIFF = DoTIFF(Row - *nDelta1 - *nSkip, *nSkip + *nDelta1, 0);
+
+ SizeofDSD = nDelta1TIFF + (nDelta1TIFF>15?1:0)
+ + (nDelta1TIFF>255?1:0) + (*nSkip>7?1:0) + (*nSkip>127?1:0) + 2;
+ SizeofD = nDeltaTIFF + (nDeltaTIFF>15?1:0) + (nDeltaTIFF>255?1:0) + 1;
+ }
+
+ if (SizeofD <= SizeofDSD) {
+ /* Turn the delta/skip/delta into a single delta. */
+ *nDelta0 += *nSkip + *nDelta1;
+ *nSkip = 0;
+ *nDelta1 = 0;
+
+ } else {
+ /* Emit a delta, then a skip, and the shift the leftover delta. */
+ if (*nDelta0) {
+ DeltaRowEmitXFER(Row- *nDelta0 - *nSkip - *nDelta1, *nDelta0, nDelta0TIFF, nRowDeltaRow, RowDeltaRow);
+ }
+ DeltaRowEmitMOVX(*nSkip, nRowDeltaRow, RowDeltaRow);
+
+ /* Shift remaining delta */
+ *nDelta0 = *nDelta1;
+ *nSkip = 0;
+ *nDelta1 = 0;
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+/*=========================================================*/
+/* */
+/* Function: */
+/* */
+/* DoDeltaRow */
+/* */
+/* Description: */
+/* */
+/* Do DeltaRow compression */
+/* */
+/*=========================================================*/
+static EPS_INT32 DoDeltaRow(EPS_UINT8 *Row, EPS_INT32 nRow, EPS_UINT8 *RowDeltaRow, EPS_UINT8 *Seed)
+{
+ EPS_INT32 nRowDeltaRow = 0;
+ EPS_INT32 nSkip = 0;
+ EPS_INT32 nDelta1 = 0;
+ EPS_INT32 nDelta0 = 0;
+ EPS_INT32 nDelta0TIFF;
+
+ for ( ; nRow--; Row++, Seed++) {
+ if (*Row != *Seed) {
+ nDelta1++;
+ }
+ else
+ {
+ if (nDelta1)
+ {
+ if (nDelta0 == 0 && nSkip ==0)
+ {
+ nDelta0 = nDelta1;
+ nDelta1 = 0;
+ }
+ else
+ {
+ if (nSkip <= 3)
+ {
+ nDelta0 += nSkip + nDelta1;
+ nSkip = 0;
+ nDelta1 = 0;
+ }
+ else
+ {
+ DeltaRowEmitReduce(Row, &nDelta0, &nSkip, &nDelta1,
+ &nRowDeltaRow, &RowDeltaRow);
+ }
+ }
+ }
+ nSkip++;
+ }
+ }
+
+ /* Have reached the end of the line. */
+ if (nDelta0)
+ {
+ if (nDelta1)
+ {
+ DeltaRowEmitReduce(Row, &nDelta0, &nSkip, &nDelta1, &nRowDeltaRow, &RowDeltaRow);
+ nDelta0TIFF = DoTIFF(Row-nDelta0, nDelta0, 0);
+ DeltaRowEmitXFER(Row-nDelta0, nDelta0, nDelta0TIFF, &nRowDeltaRow, &RowDeltaRow);
+ }
+ else
+ {
+ nDelta0TIFF = DoTIFF(Row-nSkip-nDelta0, nDelta0, 0);
+ DeltaRowEmitXFER(Row-nDelta0-nSkip, nDelta0, nDelta0TIFF, &nRowDeltaRow, &RowDeltaRow);
+ }
+ }
+ else if (nDelta1)
+ {
+ if (nSkip)
+ {
+ DeltaRowEmitReduce(Row, &nDelta0, &nSkip, &nDelta1, &nRowDeltaRow, &RowDeltaRow);
+ nDelta0TIFF = DoTIFF(Row-nDelta0, nDelta0, 0);
+ DeltaRowEmitXFER(Row-nDelta0, nDelta0, nDelta0TIFF, &nRowDeltaRow, &RowDeltaRow);
+ }
+ else
+ {
+ nDelta0TIFF = DoTIFF(Row-nDelta1, nDelta1, 0);
+ DeltaRowEmitXFER(Row-nDelta1, nDelta1, nDelta0TIFF, &nRowDeltaRow, &RowDeltaRow);
+ }
+ }
+
+ return nRowDeltaRow;
+}
+
+/*_______________________________ epson-escpage-mono.c ______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage-mono.h b/lib/epson-escpage-mono.h
new file mode 100644
index 0000000..50c7d20
--- /dev/null
+++ b/lib/epson-escpage-mono.h
@@ -0,0 +1,54 @@
+/*______________________________ epson-escpage-color.h ______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/Page-Mono command Functions */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPAGE_MONO_H__
+#define __EPSON_ESCPAGE_MONO_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern EPS_ERR_CODE pageAllocBuffer_M (void);
+extern void pageRelaseBuffer_M (void);
+extern EPS_ERR_CODE pageStartJob_M (void);
+extern EPS_ERR_CODE pageEndJob_M (void);
+extern EPS_ERR_CODE pageStartPage_M (void);
+extern EPS_ERR_CODE pageColorRow_M (const EPS_BANDBMP*, EPS_RECT*);
+extern EPS_ERR_CODE pageSendLeftovers_M (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPAGE_MONO_H__ */
+
+/*_______________________________ epson-escpage-mono.h ______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage.c b/lib/epson-escpage.c
new file mode 100644
index 0000000..1635192
--- /dev/null
+++ b/lib/epson-escpage.c
@@ -0,0 +1,1025 @@
+/*__________________________________ epson-escpage.c ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-err.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpage-color.h"
+#include "epson-escpage-mono.h"
+#ifdef GCOMSW_CMD_ESCPAGE_S
+#include "epson-escpage-s.h"
+#endif
+#include "epson-escpage.h"
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_PAGE
+#define EPS_LOG_MODULE EPS_LOG_MODULE_PAGE
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+/*----------------------------------- EJL Commands ------------------------------------*/
+/*******************************************|********************************************/
+const static EPS_UINT8 sbEJL_ESC_SOH[] = "\x1B\x01"; /* Escape and start of heading <ESC><SOH> */
+const static EPS_UINT8 sbEJL[] = "@EJL"; /* EJL command */
+const static EPS_UINT8 sbEJL_SP[] = "\x20"; /* Space <SP> */
+const static EPS_UINT8 sbEJL_LF[] = "\x0A"; /* Line Feed <LF> */
+const static EPS_UINT8 sbEJL_EN[] = "@EJL""\x20""EN""\x20""LA=ESC/PAGE"; /* EJL ENTER command */
+const static EPS_UINT8 sbEJL_EN_C[] = "@EJL""\x20""EN""\x20""LA=ESC/PAGE-COLOR";/* EJL ENTER command */
+const static EPS_UINT8 sbEJL_SE[] = "@EJL""\x20""SE""\x20""LA=ESC/PAGE"; /* EJL SELECT command */
+const static EPS_UINT8 sbEJL_SET[] = "SET"; /* SET command */
+
+/*--------------------------------- ESC/Page Commands ---------------------------------*/
+/*******************************************|********************************************/
+const static EPS_INT8 sbLOS[] = "\x1D%d;%dloE"; /* Logical Origin setting for 300 dpi(0.2 inch) */
+const static EPS_UINT8 sbCHPAS[] = {0x1D, '0', 'X'}; /* Reset the current absolute X position */
+const static EPS_UINT8 sbCVPAS[] = {0x1D, '0', 'Y'}; /* Reset the current absolute Y position */
+const static EPS_INT8 sbCA[] = "\x1D""0;0;%d;%dcaE"; /* Set Clip Area */
+
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagEPS_PAGE_MEDIA_NAME_ {
+ EPS_INT32 id;
+ const EPS_INT8 *name;
+} EPS_PAGE_MEDIA_NAME;
+
+/*--------------------------- ESC/Page Media Declarations ---------------------------*/
+/*******************************************|********************************************/
+/* Type */
+const EPS_PAGE_MEDIA_NAME pageMediaType[] = {
+ { EPS_MTID_PLAIN, "NM" }
+};
+
+/* Paper Source */
+const EPS_PAGE_MEDIA_NAME pagePaperSource[] = {
+ { EPS_MPID_AUTO, "AU" },
+ { EPS_MPID_MPTRAY, "MP" },
+ { EPS_MPID_FRONT1, "LC1" },
+ { EPS_MPID_FRONT2, "LC2" },
+ { EPS_MPID_FRONT3, "LC3" },
+ { EPS_MPID_FRONT4, "LC4" }
+};
+
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+extern EPS_CMN_FUNC epsCmnFnc;
+extern EPS_PRINT_JOB printJob;
+
+#if 0
+#include "epsmp-make-img.h"
+static FILE *fp = NULL;
+#endif
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageInitJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* jobAttr const EPS_JOB_ATTRIB* I: Print Job Attribute */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_INVALID_VERSION - Invalid structure version */
+/* EPS_ERR_INV_COLOR_PLANE - Invalid Color Plane */
+/* EPS_ERR_INV_PALETTE_SIZE - Invalid Palette Size */
+/* EPS_ERR_INV_PALETTE_DATA - Invalid Palette Data */
+/* EPS_ERR_INV_MEDIA_SIZE - Invalid Media Size */
+/* EPS_ERR_INV_MEDIA_TYPE - Invalid Media Type */
+/* EPS_ERR_INV_BORDER_MODE - Invalid Border Mode */
+/* EPS_ERR_INV_PAPER_SOURCE - Invalid Paper source */
+/* EPS_ERR_INV_COLOR_MODE - Invalid Color Mode */
+/* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
+/* EPS_ERR_INV_DUPLEX - Invalid duplex */
+/* EPS_ERR_INV_FEED_DIRECTION - Invalid feed direction */
+/* */
+/* Description: */
+/* Called form epsStartJob. Confirm ESC/Page Job Attribute. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageInitJob(
+
+ const EPS_JOB_ATTRIB *jobAttr
+
+){
+ EPS_INT32 i;
+ const EPS_PAGE_MEDIASIZE *mediaSizeEnt = NULL;
+
+ EPS_LOG_FUNCIN
+
+/*** Validate input parameters */
+ /*** Structure version */
+ if(EPS_JOB_ATTRIB_VER_3 > jobAttr->version){
+ EPS_RETURN( EPS_ERR_INVALID_VERSION )
+ }
+
+ /*** Color Plane */
+ if (! ( (jobAttr->colorPlane == EPS_CP_FULLCOLOR ) ||
+ (jobAttr->colorPlane == EPS_CP_256COLOR ) ) ){
+ EPS_RETURN( EPS_ERR_INV_COLOR_PLANE )
+ }
+
+ /*** Media Type */
+ for( i=0; i < dim(pageMediaType); i++ ) {
+ if( jobAttr->mediaTypeIdx == pageMediaType[i].id ) {
+ break;
+ }
+ }
+ if(i >= dim(pageMediaType)){
+ EPS_RETURN( EPS_ERR_INV_MEDIA_TYPE )
+ }
+
+#if 0
+ /*** Print Quality */
+ if (! ( (jobAttr->printQuality == EPS_MQID_NORMAL ) ||
+ (jobAttr->printQuality == EPS_MQID_HIGH ) ) ){
+ EPS_RETURN( EPS_ERR_INV_PRINT_QUALITY )
+ }
+#endif
+ /*** Input Image Resolution */
+ if (! ( (jobAttr->inputResolution == EPS_IR_150X150 ) ||
+ (jobAttr->inputResolution == EPS_IR_300X300 )
+#if !EPS_PAGE_LOWRES_MODE
+ || (jobAttr->inputResolution == EPS_IR_600X600 )
+#endif
+ ) ){
+ EPS_RETURN( EPS_ERR_INV_INPUT_RESOLUTION )
+ }
+
+ /*** Paper Source */
+ for( i=0; i < dim(pagePaperSource); i++ ) {
+ if( jobAttr->paperSource == pagePaperSource[i].id ) {
+ break;
+ }
+ }
+ if(i >= dim(pagePaperSource)){
+ EPS_RETURN( EPS_ERR_INV_PAPER_SOURCE )
+ }
+
+ /*** Border Mode */
+ if( jobAttr->printLayout != EPS_MLID_BORDERS ){
+ EPS_RETURN( EPS_ERR_INV_BORDER_MODE )
+ }
+
+ /*** Color Mode */
+ if( !( (jobAttr->colorMode == EPS_CM_COLOR ) ||
+ (jobAttr->colorMode == EPS_CM_MONOCHROME ) ) ){
+ EPS_RETURN( EPS_ERR_INV_COLOR_MODE )
+ }
+ if( jobAttr->colorMode == EPS_CM_COLOR &&
+ printJob.printer->language == EPS_LANG_ESCPAGE){
+ EPS_RETURN( EPS_ERR_INV_COLOR_MODE )
+ }
+
+ /*** Pallette Data */
+ if (jobAttr->colorPlane == EPS_CP_256COLOR) {
+ if (! ((jobAttr->paletteSize >= 3 ) &&
+ (jobAttr->paletteSize <= 768/*765*/ ) ) ){
+ EPS_RETURN( EPS_ERR_INV_PALETTE_SIZE )
+ }
+
+ if ( jobAttr->paletteData == NULL ){
+ EPS_RETURN( EPS_ERR_INV_PALETTE_DATA )
+ }
+ }
+
+ /*** duplex */
+ if( !( (jobAttr->duplex == EPS_DUPLEX_NONE ) ||
+ (jobAttr->duplex == EPS_DUPLEX_LONG ) ||
+ (jobAttr->duplex == EPS_DUPLEX_SHORT ) ) ){
+ EPS_RETURN( EPS_ERR_INV_DUPLEX )
+ }
+
+ /*** Color Mode */
+ if( !( (jobAttr->feedDirection == EPS_FEEDDIR_PORTRAIT ) ||
+ (jobAttr->feedDirection == EPS_FEEDDIR_LANDSCAPE ) ) ){
+ EPS_RETURN( EPS_ERR_INV_FEED_DIRECTION )
+ }
+
+
+ memcpy(&printJob.attr, jobAttr, sizeof(printJob.attr));
+ if(jobAttr->copies < 0){
+ printJob.attr.copies = 1;
+ }
+
+ /*** Find the Media by ID */
+ for(i = 0; i < dim(pageMediaSize); i++){
+ if( jobAttr->mediaSizeIdx == pageMediaSize[i].id ){
+ mediaSizeEnt = &pageMediaSize[i];
+ break;
+ }
+ }
+ if( NULL != mediaSizeEnt){
+ printJob.printableAreaWidth = mediaSizeEnt->print_area_x_border;
+ printJob.printableAreaHeight = mediaSizeEnt->print_area_y_border;
+ printJob.topMargin = 120;
+ printJob.leftMargin = 120;
+ } else{
+ EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE )
+ }
+
+ if(EPS_IR_300X300 == jobAttr->inputResolution){
+ printJob.printableAreaWidth /= 2;
+ printJob.printableAreaHeight /= 2;
+ printJob.topMargin /= 2;
+ printJob.leftMargin /= 2;
+ } else if(EPS_IR_150X150 == jobAttr->inputResolution){
+ printJob.printableAreaWidth /= 4;
+ printJob.printableAreaHeight /= 4;
+ printJob.topMargin /= 4;
+ printJob.leftMargin /= 4;
+ }
+
+ printJob.bpp = (printJob.attr.colorPlane == EPS_CP_256COLOR)?1:3;
+ printJob.whiteColorValue = memSearchWhiteColorVal(printJob.attr.colorPlane,
+ printJob.attr.paletteData,
+ printJob.attr.paletteSize);
+
+ EPS_RETURN( EPS_ERR_NONE )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageAllocBuffer() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* */
+/* Description: */
+/* Allocate buffer for ESC/Page Job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageAllocBuffer(void)
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ ret = pageS_AllocBuffer();
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ ret = pageAllocBuffer_C();
+ } else{
+ /** ESC/Page **/
+ ret = pageAllocBuffer_M();
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageRelaseBuffer() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* N/A */
+/* */
+/* Description: */
+/* Free buffer for ESC/Page Job. */
+/* */
+/*******************************************|********************************************/
+void pageRelaseBuffer(void)
+{
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ pageS_RelaseBuffer();
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ pageRelaseBuffer_C();
+ } else{
+ /** ESC/Page **/
+ pageRelaseBuffer_M();
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageStartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page start job commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageStartJob(void)
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ ret = pageS_StartJob();
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ ret = pageStartJob_C();
+ } else{
+ /** ESC/Page **/
+ ret = pageStartJob_M();
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageEndJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page end job commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageEndJob()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ ret = pageS_EndJob();
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ ret = pageEndJob_C();
+ } else{
+ /** ESC/Page **/
+ ret = pageEndJob_M();
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageStartPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page start page commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageStartPage()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ ret = pageS_StartPage();
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ ret = pageStartPage_C();
+ } else{
+ /** ESC/Page **/
+ ret = pageStartPage_M();
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageEndPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page end page commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageEndPage()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ ret = pageS_EndPage();
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ ret = pageEndPage_C();
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageColorRow() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send ESC/Page raster commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageColorRow(
+
+ const EPS_BANDBMP* pInBmp,
+ EPS_RECT* pBandRec
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ ret = pageS_ColorRow(pInBmp, pBandRec);
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ ret = pageColorRow_C(pInBmp, pBandRec);
+ } else{
+ /** ESC/Page **/
+ ret = pageColorRow_M(pInBmp, pBandRec);
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: pageSendLeftovers() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_INVALID_CALL - This call was unnecessary */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* send leftovers data. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE pageSendLeftovers(
+
+ void
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ ret = pageS_SendLeftovers();
+ } else
+#endif
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ ret = pageSendLeftovers_C();
+ } else{
+ /** ESC/Page **/
+ ret = pageSendLeftovers_M();
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+EPS_ERR_CODE pageCreateMediaInfo (
+
+ EPS_PRINTER_INN* printer,
+ EPS_UINT8* pmString,
+ EPS_INT32 pmSize
+
+){
+ EPS_INT32 num_mSize = dim(pageMediaSize);
+ EPS_INT32 num_mType = dim(pageMediaType);
+ EPS_INT32 i, j, n;
+ EPS_MEDIA_SIZE* sizeList = NULL;
+ EPS_MEDIA_TYPE* typeList = NULL;
+ EPS_UINT32 paperSource = EPS_MPID_ALL_ESCPAGE;
+
+ EPS_LOG_FUNCIN
+
+ memset(&printer->supportedMedia, 0, sizeof(EPS_SUPPORTED_MEDIA));
+
+ /* Allocate memory for the media size list. */
+ sizeList = (EPS_MEDIA_SIZE*)EPS_ALLOC( sizeof(EPS_MEDIA_SIZE) * num_mSize );
+ if( sizeList == NULL ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ /* Allocate memory for the media type array. */
+ typeList = (EPS_MEDIA_TYPE*)EPS_ALLOC( sizeof(EPS_MEDIA_TYPE) * num_mSize * num_mType );
+ if (typeList == NULL) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ if( sizeof(EPS_UINT32) == pmSize ){
+ memcpy(&paperSource, pmString, sizeof(EPS_UINT32));
+ }
+
+ /* set media size property. */
+ for(i = 0; i < num_mSize; i++){
+ /* set media type property. */
+ for(j = 0; j < num_mType; j++){
+ n = i * num_mType + j;
+ typeList[n].mediaTypeID = pageMediaType[j].id;
+ typeList[n].paperSource = paperSource;
+ typeList[n].layout = EPS_MLID_BORDERS;
+#if EPS_PAGE_LOWRES_MODE
+ typeList[n].quality = EPS_MQID_DRAFT | EPS_MQID_NORMAL;
+#else
+ typeList[n].quality = EPS_MQID_DRAFT | EPS_MQID_NORMAL | EPS_MQID_HIGH;
+#endif
+
+ if(EPS_MSID_POSTCARD == pageMediaSize[i].id){
+ typeList[n].duplex = EPS_DUPLEX_DISABLE;
+ } else{
+ typeList[n].duplex = EPS_DUPLEX_ENABLE;
+ }
+ }
+
+ sizeList[i].mediaSizeID = pageMediaSize[i].id;
+ sizeList[i].numTypes = num_mType;
+ sizeList[i].typeList = &typeList[i];
+ }
+
+ printer->supportedMedia.sizeList = sizeList;
+ printer->supportedMedia.numSizes = num_mSize;
+
+#if EPS_PAGE_LOWRES_MODE
+ printer->supportedMedia.resolution = EPS_IR_150X150 | EPS_IR_300X300;
+#else
+ printer->supportedMedia.resolution = EPS_IR_150X150 | EPS_IR_300X300 | EPS_IR_600X600;
+#endif
+
+#if GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ pageS_UpdateSupportedMedia( &printer->supportedMedia );
+ }
+#endif
+
+ EPS_RETURN( EPS_ERR_NONE )
+}
+
+
+void pageClearSupportedMedia (
+
+ EPS_PRINTER_INN* printer
+
+){
+ EPS_LOG_FUNCIN
+
+ if( NULL != printer->supportedMedia.sizeList ){
+ EPS_SAFE_RELEASE(printer->supportedMedia.sizeList[0].typeList);
+ EPS_SAFE_RELEASE(printer->supportedMedia.sizeList);
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+EPS_ERR_CODE pageGetPrintableArea (
+
+ EPS_JOB_ATTRIB* jobAttr,
+ EPS_UINT32* printableWidth,
+ EPS_UINT32* printableHeight
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT32 num_mSize = dim(pageMediaSize);
+ EPS_INT32 sizeIdx = 0;
+
+ EPS_LOG_FUNCIN
+
+/*** Validate/Confirm Page Attribute Data */
+ /*** Media Size */
+ for(sizeIdx = 0; sizeIdx < num_mSize; sizeIdx++){
+ if(pageMediaSize[sizeIdx].id == jobAttr->mediaSizeIdx){
+ break;
+ }
+ }
+ if(sizeIdx >= num_mSize){
+ EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE )
+ }
+
+ /*** Border Mode */
+ if( jobAttr->printLayout != EPS_MLID_BORDERS ){
+ EPS_RETURN( EPS_ERR_INV_BORDER_MODE )
+ }
+
+ /*** Input Image Resolution */
+ if (! ( (jobAttr->inputResolution == EPS_IR_150X150 ) ||
+ (jobAttr->inputResolution == EPS_IR_300X300 ) ||
+ (jobAttr->inputResolution == EPS_IR_600X600 ) ) ){
+ EPS_RETURN( EPS_ERR_INV_INPUT_RESOLUTION )
+ }
+
+ *printableWidth = pageMediaSize[sizeIdx].print_area_x_border;
+ *printableHeight = pageMediaSize[sizeIdx].print_area_y_border;
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(printJob.printer && EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ pageS_FeedExchange(jobAttr, printableWidth, printableHeight);
+ }
+#endif
+
+ if(EPS_IR_300X300 == jobAttr->inputResolution){
+ *printableWidth /= 2;
+ *printableHeight /= 2;
+ } else if(EPS_IR_150X150 == jobAttr->inputResolution){
+ *printableWidth /= 4;
+ *printableHeight /= 4;
+ *printableHeight -= 2;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+EPS_ERR_CODE ejlStart (
+
+ EPS_COMMAND_BUFFER *pCmdBuff,
+ PAGE_CmdBuffGrow pfncGrow
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT32 i;
+ EPS_INT8 *p;
+
+ EPS_LOG_FUNCIN
+
+#define EJLStart_ADDSTR(b, p, v) \
+ { \
+ sprintf(b, " %s=%s", p, v); \
+ b += strlen(b); \
+ }
+#define EJLStart_ADDINT(b, p, v) \
+ { \
+ sprintf(b, " %s=%d", p, v); \
+ b += strlen(b); \
+ }
+
+#ifdef GCOMSW_DEBUG
+ if(pCmdBuff->len+EPS_EJL_LINEMAX > pCmdBuff->size){EPS_DBGPRINT(("Command buffer not enough!\r\n"))}
+#endif
+
+ p = pCmdBuff->p + pCmdBuff->len;
+
+ /*** EJL commands ***/
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ sprintf(p, "%s%s \x0A%s\x0A%s %s",
+ sbEJL_ESC_SOH, /* <ESC><SOH> */
+ sbEJL, /* @EJL */
+ sbEJL_SE, /* EJL SELECT command */
+ sbEJL, /* @EJL */
+ sbEJL_SET); /* SET command */
+ } else{
+ /** ESC/Page **/
+ sprintf(p, "%s%s \x0A%s\x0A%s%s \x0A%s\x0A%s %s",
+ sbEJL_ESC_SOH, /* <ESC><SOH> */
+ sbEJL, /* @EJL */
+ sbEJL_EN, /* EJL ENTER command */
+ sbEJL_ESC_SOH, /* <ESC><SOH> */
+ sbEJL, /* @EJL */
+ sbEJL_SE, /* EJL SELECT command */
+ sbEJL, /* @EJL */
+ sbEJL_SET); /* SET command */
+ }
+ p += strlen(p);
+
+ /* RS */
+ EJLStart_ADDSTR(p, "RS",
+ (EPS_IR_600X600 == printJob.attr.inputResolution)?"FN":"QK" );
+
+ /* PS */
+ for( i=0; i < dim(pageMediaSize); i++ ) {
+ if( printJob.attr.mediaSizeIdx == pageMediaSize[i].id ) {
+ break;
+ }
+ }
+ EJLStart_ADDSTR(p, "PS", pageMediaSize[i].name);
+
+ /* PK */
+ for( i=0; i < dim(pageMediaType); i++ ) {
+ if( printJob.attr.mediaTypeIdx == pageMediaType[i].id ) {
+ break;
+ }
+ }
+ EJLStart_ADDSTR(p, "PK", pageMediaType[i].name);
+
+ /* PU */
+ for( i=0; i < dim(pagePaperSource); i++ ) {
+ if( printJob.attr.paperSource == pagePaperSource[i].id ) {
+ break;
+ }
+ }
+ EJLStart_ADDSTR(p, "PU", pagePaperSource[i].name);
+
+ /* OU */
+#if EPS_PAGE_OUTUNIT_FACEDOWN
+ EJLStart_ADDSTR(p, "OU", "FD");
+#else
+ EJLStart_ADDSTR(p, "OU", "FU");
+#endif
+
+ /* DX */
+ EJLStart_ADDSTR(p, "DX", ( printJob.attr.duplex != EPS_DUPLEX_NONE )?"ON":"OFF");
+
+ if( printJob.attr.duplex != EPS_DUPLEX_NONE ) {
+ /* BD */
+ EJLStart_ADDSTR(p, "BD", ( printJob.attr.duplex == EPS_DUPLEX_LONG )?"LE":"SE");
+
+ /* TB/LB */
+ EJLStart_ADDSTR(p, "TB", "0");
+ EJLStart_ADDSTR(p, "LB", "0");
+ }
+
+ /* ZO */
+ EJLStart_ADDSTR(p, "ZO", "OFF");
+
+ /* EC */
+ EJLStart_ADDSTR(p, "EC", "ON" );
+
+ /* RI */
+#if EPS_PAGE_RIT
+ EJLStart_ADDSTR(p, "RI", "ON");
+#else
+ EJLStart_ADDSTR(p, "RI", "OFF");
+#endif
+
+ /* SN */
+#if EPS_PAGE_TONER_SAVE
+ EJLStart_ADDSTR(p, "SN", "ON");
+#else
+ EJLStart_ADDSTR(p, "SN", "OFF");
+#endif
+
+ /* Collate */
+#if 0
+ if( printJob.attr.collate ) {
+ /* CO */
+ EJLStart_ADDINT(p, "CO", 1);
+ /* QT */
+ EJLStart_ADDINT(p, "QT", printJob.attr.copies);
+ } else {
+#endif
+ /* CO */
+ EJLStart_ADDINT(p, "CO", printJob.attr.copies);
+ /* QT */
+ EJLStart_ADDINT(p, "QT", 1);
+/* }*/
+
+ /* Feed direction */
+ if( EPS_FEEDDIR_LANDSCAPE == printJob.attr.feedDirection ){
+ EJLStart_ADDSTR(p, "FE", "SE");
+ }
+
+ if( EPS_CM_COLOR == printJob.attr.colorMode ){
+ /** ESC/Page-Color **/
+ /* SZ */
+ EJLStart_ADDSTR(p, "SZ", "OFF");
+
+ /* GAMMAMODE */
+ EJLStart_ADDSTR(p, "GAMMAMODE", "NORMAL");
+
+ /* SL */
+ EJLStart_ADDSTR(p, "SL", "YES");
+
+ /* TO */
+ EJLStart_ADDSTR(p, "TO", "0");
+
+ /* LO */
+ EJLStart_ADDSTR(p, "LO", "0");
+
+ /* OR */
+ EJLStart_ADDSTR(p, "OR", "PO");
+
+ /* EJL ENTER command */
+ sprintf(p, " %s%s%s", sbEJL_LF, sbEJL_EN_C, sbEJL_LF);
+ } else{
+ /* FO */
+ EJLStart_ADDSTR(p, "FO", "OFF");
+
+ /* EJL ENTER command */
+ sprintf(p, " %s%s%s", sbEJL_LF, sbEJL_EN, sbEJL_LF);
+ }
+
+ p += strlen(p);
+ pCmdBuff->len += (EPS_INT32)(p - pCmdBuff->p);
+
+ EPS_RETURN( ret )
+}
+
+
+EPS_ERR_CODE ejlEnd (
+
+ EPS_COMMAND_BUFFER *pCmdBuff,
+ PAGE_CmdBuffGrow pfncGrow,
+ EPS_INT32 pageCount
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 dwPaperNum = pageCount;
+ EPS_INT8 *p;
+
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_DEBUG
+ if(pCmdBuff->len+EPS_EJL_LINEMAX > pCmdBuff->size){EPS_DBGPRINT(("Command buffer not enough!\r\n"))}
+#endif
+
+ p = pCmdBuff->p + pCmdBuff->len;
+
+ /* EJL commands -------- */
+ sprintf(p, "%s%s ",
+ sbEJL_ESC_SOH, /* <ESC><SOH> */
+ sbEJL); /* @EJL */
+ p += strlen(p);
+
+ /* Page */
+ if( printJob.attr.duplex != EPS_DUPLEX_NONE ){
+ dwPaperNum = (pageCount+1)/2;
+ }
+ sprintf(p, "JI PAGES=\"%d\"", dwPaperNum);
+ p += strlen(p);
+
+ /* @EJL */
+ sprintf(p, " %s%s %s", sbEJL_LF, sbEJL, sbEJL_LF);
+ p += strlen(p);
+
+ pCmdBuff->len = (EPS_INT32)(p - pCmdBuff->p);
+
+#ifdef GCOMSW_DEBUG
+ if(pCmdBuff->len > pCmdBuff->size){EPS_DBGPRINT(("Command buffer over flow!!\r\n"))}
+#endif
+
+ EPS_RETURN( ret )
+}
+
+
+EPS_ERR_CODE ejlPageEsc (
+
+ EPS_COMMAND_BUFFER *pCmdBuff,
+ PAGE_CmdBuffGrow pfncGrow
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 *p;
+
+ EPS_LOG_FUNCIN
+
+#define PageEscCommand_ADDCMD(b, CMD) { \
+ memcpy(b, CMD, sizeof(CMD)); \
+ b += sizeof(CMD); \
+ }
+
+ p = pCmdBuff->p + pCmdBuff->len;
+
+ /* Set Logical Origin Setting */
+ sprintf(p, sbLOS, printJob.leftMargin, printJob.topMargin);
+ p += strlen(p);
+
+ /* Reset the current absolute position */
+ PageEscCommand_ADDCMD(p, sbCHPAS);
+ PageEscCommand_ADDCMD(p, sbCVPAS);
+
+ /* Set Clip Area */
+ sprintf(p, sbCA, printJob.printableAreaWidth, printJob.printableAreaHeight);
+ p += strlen(p);
+
+ pCmdBuff->len = (EPS_INT32)(p - pCmdBuff->p);
+
+ EPS_RETURN( ret )
+}
+
+/*__________________________________ epson-escpage.c ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpage.h b/lib/epson-escpage.h
new file mode 100644
index 0000000..4711c50
--- /dev/null
+++ b/lib/epson-escpage.h
@@ -0,0 +1,123 @@
+/*__________________________________ epson-escpage.h ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/Page command Functions */
+/* */
+/*******************************************|********************************************/
+
+#ifndef __EPSON_ESCPAGE_H__
+#define __EPSON_ESCPAGE_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+#include "epson-escpr-media.h"
+
+/*------------------------------- Global Compiler Switch -------------------------------*/
+/*******************************************|********************************************/
+#define EPS_PAGE_RIT (1)
+#define EPS_PAGE_TONER_SAVE (0)
+#define EPS_PAGE_OUTUNIT_FACEDOWN (1)
+#define EPS_PAGE_LOWRES_MODE (1) /* OFF=0 / ON=1 */
+#define EPS_PAGE_HT_ERR_DIFFUSION (1) /* Halftoning mode */
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+#define dim(x) (sizeof(x) / sizeof(x[0]))
+#define EPS_EJL_LINEMAX (256)
+
+/*--------------------------- ESC/Page Media Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagEPS_PAGE_MEDIASIZE_ {
+ EPS_INT32 id;
+ EPS_INT32 paper_x;
+ EPS_INT32 paper_y;
+ EPS_INT32 print_area_x_border;
+ EPS_INT32 print_area_y_border;
+ const EPS_INT8 *name;
+} EPS_PAGE_MEDIASIZE;
+
+/* Size 600dpi */
+static const EPS_PAGE_MEDIASIZE pageMediaSize[] = {
+ { EPS_MSID_A4, 4960, 7016, 4720, 6776, "A4" },
+ { EPS_MSID_A3, 7016, 9920, 6776, 9680, "A3" },
+ { EPS_MSID_B4, 6072, 8600, 5832, 8360, "B4" },
+ { EPS_MSID_B5, 4300, 6072, 4060, 5832, "B5" },
+ { EPS_MSID_LETTER, 5100, 6600, 4860, 6360, "LT" },
+ { EPS_MSID_LEGAL, 5100, 8400, 4860, 8160, "LGL"},
+ { EPS_MSID_POSTCARD,2362, 3496, 2122, 3256, "PC" }
+};
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+/* command data buffer */
+typedef struct tagEPS_COMMAND_BUFFER
+{
+ EPS_UINT32 size; /* allocated buffer size */
+ EPS_UINT32 len; /* data size */
+ EPS_INT8* p;
+ void* pExtent;
+} EPS_COMMAND_BUFFER;
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern EPS_ERR_CODE pageInitJob (const EPS_JOB_ATTRIB *pJobAttr);
+extern EPS_ERR_CODE pageAllocBuffer (void);
+extern void pageRelaseBuffer (void);
+extern EPS_ERR_CODE pageStartJob (void);
+extern EPS_ERR_CODE pageEndJob (void);
+extern EPS_ERR_CODE pageStartPage (void);
+extern EPS_ERR_CODE pageEndPage (void);
+extern EPS_ERR_CODE pageColorRow (const EPS_BANDBMP*, EPS_RECT*);
+extern EPS_ERR_CODE pageSendLeftovers (void);
+
+ /*** Get Supported Media Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE pageCreateMediaInfo (EPS_PRINTER_INN* printer, EPS_UINT8* pmString,
+ EPS_INT32 pmSize );
+extern void pageClearSupportedMedia (EPS_PRINTER_INN* printer );
+
+ /*** Get Printable Area */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE pageGetPrintableArea (EPS_JOB_ATTRIB*, EPS_UINT32*, EPS_UINT32* );
+
+
+/*----------------------- ESC/Page Local Function Declarations ----------------------*/
+/*******************************************|********************************************/
+typedef EPS_ERR_CODE (*PAGE_CmdBuffGrow )(EPS_COMMAND_BUFFER *pCmdBuff, EPS_INT32 addSize);
+
+extern EPS_ERR_CODE ejlStart (EPS_COMMAND_BUFFER *pCmdBuff, PAGE_CmdBuffGrow pfncGrow);
+extern EPS_ERR_CODE ejlEnd (EPS_COMMAND_BUFFER *pCmdBuff, PAGE_CmdBuffGrow pfncGrow,
+ EPS_INT32 pageCount );
+extern EPS_ERR_CODE ejlPageEsc (EPS_COMMAND_BUFFER *pCmdBuff, PAGE_CmdBuffGrow pfncGrow);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPAGE_H__ */
+
+/*__________________________________ epson-escpage.h ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-api.c b/lib/epson-escpr-api.c
new file mode 100644
index 0000000..906c4e1
--- /dev/null
+++ b/lib/epson-escpr-api.c
@@ -0,0 +1,5687 @@
+/*_______________________________ epson-escpr-api.c ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/P-R Library APIs */
+/* */
+/* Core Function Calls */
+/* -------------------------- */
+/* API-0001 EPS_ERR_CODE epsInitDriver (commMode, usbFuncPtrs, */
+/* netFuncPtrs, cmnFuncPtrs); */
+/* API-0002 EPS_ERR_CODE epsReleaseDriver (); */
+/* API-0003 EPS_ERR_CODE epsFindPrinter (protocol, timeout); */
+/* API-0004 EPS_ERR_CODE epsProbePrinter (probeParam); */
+/* API-0005 EPS_ERR_CODE epsCancelFindPrinter (); */
+/* API-0006 EPS_ERR_CODE epsSetPrinter (printer); */
+/* API-0007 EPS_ERR_CODE epsStartJob (jobAttrib); */
+/* API-0008 EPS_ERR_CODE epsStartPage (pageAttrib); */
+/* API-0009 EPS_ERR_CODE epsPrintBand (imageData,width,,height); */
+/* API-0010 EPS_ERR_CODE epsSendData (prnData); */
+/* API-0011 EPS_ERR_CODE epsEndPage (); */
+/* API-0012 EPS_ERR_CODE epsEndJob (); */
+/* API-0013 EPS_ERR_CODE epsCancelJob (reserve); */
+/* API-0014 EPS_ERR_CODE epsContinueJob (); */
+/* API-0015 EPS_ERR_CODE epsGetStatus (status); */
+/* API-0016 EPS_ERR_CODE epsGetSupportedMedia (media); */
+/* API-0017 EPS_ERR_CODE epsGetPrintableArea (pageAttrib, */
+/* printableWidth, */
+/* printableHeight); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------ Local Compiler Switch -------------------------------*/
+/*******************************************|********************************************/
+
+ /*** 4KB Packet Data */
+ /***--------------------------------------------------------------------------------*/
+#define LCOMSW_PACKET_4KB 0 /* 0: Make any size packet */
+ /* 1: Make 4KB packet */
+#define LCOMSW_CANCEL_JOB 0
+
+#define LCOMSW_USE_720DPI 0 /* Not support 720dpi */
+
+#define ESCPR_DEBUG_IMAGE_LOG 0 /* 0: OFF 1: ON */
+
+#define LCOMSW_DUMMY_SEND 0 /* 1: Enable 0byte data sending */
+
+/*#define LCOMSW_JOBPARAM_CEHCK_OFF*/
+
+/* #define LCOMSW_CMDDMP */
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+#include "epson-escpr-services.h"
+#include "epson-escpr-mem.h"
+#include "epson-protocol.h"
+#include "epson-layout.h"
+#ifdef GCOMSW_CMD_ESCPAGE
+#include "epson-escpage.h"
+ #ifdef GCOMSW_CMD_ESCPAGE_S
+ #include "epson-escpage-s.h"
+ #endif
+#endif
+#include "epson-escpr-api.h"
+
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+DECRALE_DMP_FILE
+
+ /*** Extern Function */
+ /*** -------------------------------------------------------------------------------*/
+EPS_USB_FUNC epsUsbFnc;
+EPS_NET_FUNC epsNetFnc;
+EPS_CMN_FUNC epsCmnFnc;
+
+ /*** Print Job Structure */
+ /*** -------------------------------------------------------------------------------*/
+EPS_PRINT_JOB printJob;
+EPS_INT32 tonerSave;
+EPS_INT32 back_type;
+
+EPS_INT32 lWidth;
+EPS_INT32 lHeight;
+
+EPS_INT32 areaWidth;
+EPS_INT32 areaHeight;
+
+
+/*------------------------- Module "Local Global" Variables --------------------------*/
+/*******************************************|********************************************/
+ /*** internal stock */
+ /*** -------------------------------------------------------------------------------*/
+static EPS_SUPPORTED_MEDIA g_supportedMedia; /* Supported Media */
+
+ /*** Job function */
+ /*** -------------------------------------------------------------------------------*/
+EPS_JOB_FUNCS jobFnc;
+
+/*-------------------------------- Local Definition ---------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_API
+#define EPS_LOG_MODULE EPS_LOG_MODULE_API
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+ /*** Roop Count */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_ROOP_NUM 40 /* Send the data for "EPS_ROOP_NUM" */
+ /* times and get printer status */
+
+#define EPS_TIMEOUT_NUM 20 /* retry Send the data "EPS_TIMEOUT_NUM"*/
+#define EPS_TIMEOUT_SEC 1000 /* retry Send the data 1 sec */
+
+ /*** Packet Size (4KB) */
+ /*** -------------------------------------------------------------------------------*/
+#if LCOMSW_PACKET_4KB
+#define ESCPR_PACKET_SIZE_4KB 4090
+#endif
+
+ /*** ESC/PR Attributes not settable by developer */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_COMP_NON 0 /* Non compression */
+#define EPS_COMP_RLE 1 /* Runlength compression */
+
+#define EPS_END_PAGE 0 /* There is no next page */
+#define EPS_NEXT_PAGE 1 /* There is a next page */
+
+ /*** RLE Compression States */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_RLE_COMPRESS_NOT_DONE 0
+#define EPS_RLE_COMPRESS_DONE 1
+
+ /*** Borderless Mode */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_BORDER_3MM_MARGINE 0
+#define EPS_BORDER_CUSTOM 1
+#define EPS_BORDERLESS_NORMAL 2
+#define EPS_BORDERLESS_ZERO_MARGINE 3
+
+
+/*--------------------------------- ESC/P-R Commands ---------------------------------*/
+/*******************************************|********************************************/
+ /*** ESC/P-R Command Length */
+ /*** -------------------------------------------------------------------------------*/
+#define REMOTE_HEADER_LENGTH 5
+#define ESCPR_CLASS_LENGTH 2 /* ESC + CLASS */
+#define ESCPR_HEADER_LENGTH 10 /* ESC + CLASS + ParamLen + CmdName */
+#define ESCPR_PRINT_QUALITY_LENGTH 9
+#define ESCPR_SEND_DATA_LENGTH 7
+#define ESCPR_SEND_JPGDATA_LENGTH 2
+#define ESCPR_JPGHEAD_LENGTH (ESCPR_HEADER_LENGTH + ESCPR_SEND_JPGDATA_LENGTH)
+
+ /*** Escape Commands for Initialize/Colse Printer */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 ExitPacketMode[]= {
+ 0x00, 0x00, 0x00, 0x1B, 0x01, 0x40, 0x45, 0x4A, 0x4C, 0x20,
+ 0x31, 0x32, 0x38, 0x34, 0x2E, 0x34, 0x0A, 0x40, 0x45, 0x4A,
+ 0x4C, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A };
+
+static const EPS_UINT8 ESCPRMode[] = {
+/* 0x1B, 0x28, 0x52, 0x06, 0x00, 0x00, 0x45, 0x53, 0x43, 0x50, 0x52, };*/
+ 0x1B, '(', 'R', 0x06, 0x00, 0x00, 'E', 'S', 'C', 'P', 'R' };
+static const EPS_UINT8 ESCPRModeJpg[] = {
+ 0x1B, '(', 'R', 0x07, 0x00, 0x00, 'E', 'S', 'C', 'P', 'R', 'J' };
+
+static const EPS_UINT8 InitPrinter[] = {
+ 0x1B, 0x40, };
+
+static const EPS_UINT8 EnterRemoteMode[] = {
+ 0x1B, 0x28, 0x52, 0x08, 0x00, 0x00, 'R', 'E', 'M', 'O', 'T', 'E', '1', };
+
+static const EPS_UINT8 RemoteJS[] = {
+ 'J', 'S', 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00 };
+
+static const EPS_UINT8 RemoteTI[] = {
+ 'T', 'I', 0x08, 0x00, 0x00,
+ 0x00, 0x00, /* YYYY */
+ 0x00, /* MM */
+ 0x00, /* DD */
+ 0x00, /* hh */
+ 0x00, /* mm */
+ 0x00, /* ss */ };
+
+static const EPS_UINT8 RemoteHD[] = {
+ 'H', 'D', 0x03, 0x00, 0x00,
+ 0x03, 0xFF };
+
+static const EPS_UINT8 RemoteJH[] = {
+ 'J', 'H', 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x45, 0x53, 0x43, 0x50, 0x52, 0x4c, 0x69, 0x62 };
+
+static const EPS_UINT8 RemotePP[] = {
+ 'P', 'P', 0x03, 0x00, 0x00, 0x00, 0x00 };
+
+static const EPS_UINT8 RemoteDP[] = {
+ 'D', 'P', 0x02, 0x00, 0x00, 0x02 };
+
+static const EPS_UINT8 RemoteLD[] = {
+ 'L', 'D', 0x00, 0x00, };
+
+static const EPS_UINT8 RemoteJE[] = {
+ 'J', 'E', 0x01, 0x00, 0x00, };
+
+static const EPS_UINT8 ExitRemoteMode[] = {
+ 0x1B, 0x00, 0x00, 0x00, };
+#ifdef GCOMSW_EF_MAINTE
+static const EPS_UINT8 RemoteCH[] = {
+ 'C', 'H', 0x02, 0x00, 0x00, 0x00 };
+static const EPS_UINT8 RemoteNC[] = {
+ 'N', 'C', 0x02, 0x00, 0x00, 0x00 };
+static const EPS_UINT8 RemoteVI[] = {
+ 'V', 'I', 0x02, 0x00, 0x00, 0x00 };
+
+static const EPS_UINT8 DataCR[] = {0x0D };
+static const EPS_UINT8 DataLF[] = {0x0A };
+static const EPS_UINT8 DataFF[] = {0x0C };
+#endif
+
+ /*** ESC/P-R Commands (Print Quality) */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 PrintQualityCmd[] = {
+ 0x1B, 'q', 0x09, 0x00, 0x00, 0x00,
+ 's', 'e', 't', 'q',
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ /*** ESC/P-R Commands (APF setting) */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 APFSettingCmd[] = {
+ 0x1B, 'a', 0x04, 0x00, 0x00, 0x00,
+ 's', 'e', 't', 'a',
+ 0x00, 0x00, 0x00, 0x00};
+
+ /*** ESC/P-R Commands (Print Job) */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 JobCmd[] = {
+ 0x1B, 'j', 0x16, 0x00, 0x00, 0x00,
+ 's', 'e', 't', 'j',
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static const EPS_UINT8 JobCmdJpg[] = {
+ 0x1B, 'j', 0x05, 0x00, 0x00, 0x00,
+ 's', 'e', 't', 's',
+ 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+ /*** ESC/P-R Command (Start Page) */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 StartPage[] = {
+ 0x1B, 'p', 0x00, 0x00, 0x00, 0x00,
+ 's', 't', 't', 'p' };
+
+ /*** ESC/P-R Commands (Send Data) */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 SendDataCmd[2] = {0x1B, 'd' };
+static const EPS_UINT8 SendDataName[4] = {'d', 's', 'n', 'd' };
+static const EPS_UINT8 SendJpegDataName[4] = {'j', 's', 'n', 'd' };
+
+ /*** ESC/P-R Command (End Page) */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 EndPage[] = {
+ 0x1B, 'p', 0x01, 0x00, 0x00, 0x00,
+ 'e', 'n', 'd', 'p',
+ 0x00};
+
+ /*** ESC/P-R Command (End Job) */
+ /*** -------------------------------------------------------------------------------*/
+static const EPS_UINT8 EndJob[] = {
+ 0x1B, 'j', 0x00, 0x00, 0x00, 0x00,
+ 'e', 'n', 'd', 'j' };
+
+/*------------------------------- Definition of Macro --------------------------------*/
+/*******************************************|********************************************/
+
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+ /*** Generic Image Object */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_IMAGE_ {
+ const EPS_UINT8* data; /* Pointer to image/raster data */
+ EPS_RECT rect; /* Rect define position of image */
+ EPS_UINT32 bytesPerLine; /* Bytes-Per-Pixel for image/raster */
+} EPS_IMAGE;
+
+/*------------------------------ Local Global Variables ------------------------------*/
+/*******************************************|********************************************/
+ /*** ESC/P-R LIB Status State */
+ /*** -------------------------------------------------------------------------------*/
+EPS_INT32 libStatus; /* Library (epsInitDriver) status */
+
+ /*** Status counter */
+ /*** -------------------------------------------------------------------------------*/
+static EPS_INT32 gStatusCount; /* Variable for register the number of getting */
+ /* printer status */
+
+ /*** Buffer for Print Band */
+ /*** -------------------------------------------------------------------------------*/
+EPS_UINT32 sendDataBufSize = 0;
+EPS_UINT8* sendDataBuf; /* buffer of SendCommand(save) input */
+EPS_UINT32 tmpLineBufSize;
+EPS_UINT8* tmpLineBuf;
+
+/*-------------------------------- Local Functions ----------------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE MonitorStatus (EPS_STATUS_INFO * );
+static EPS_ERR_CODE SendLeftovers (void );
+static EPS_ERR_CODE SendBlankBand (void );
+EPS_ERR_CODE SetupJobAttrib (const EPS_JOB_ATTRIB* );
+static EPS_ERR_CODE SetupRGBAttrib (void );
+static EPS_ERR_CODE SetupJPGAttrib (void );
+EPS_ERR_CODE SendStartJob (EPS_BOOL );
+EPS_ERR_CODE SendEndJob (EPS_BOOL );
+
+EPS_ERR_CODE PrintBand (const EPS_UINT8*, EPS_UINT32, EPS_UINT32* );
+static EPS_ERR_CODE PrintChunk (const EPS_UINT8*, EPS_UINT32* );
+static void AdjustBasePoint (void );
+static EPS_ERR_CODE PrintLine (EPS_IMAGE* );
+static EPS_ERR_CODE SendLine (const EPS_BANDBMP*, EPS_RECT* );
+static EPS_UINT16 RunLengthEncode (const EPS_UINT8*, EPS_UINT8*, EPS_UINT16, EPS_UINT8, EPS_UINT8*);
+
+static void MakeRemoteTICmd (EPS_UINT8* );
+static void MakeQualityCmd (EPS_UINT8* );
+static void MakeAPFCmd (EPS_UINT8* );
+static void MakeJobCmd (EPS_UINT8* );
+static EPS_ERR_CODE AddCmdBuff (EPS_UINT8 **, EPS_UINT8 **, EPS_UINT32 *,
+ const EPS_UINT8 *, EPS_UINT32 );
+static EPS_ERR_CODE CreateMediaInfo (EPS_PRINTER_INN*, EPS_UINT8*, EPS_INT32 );
+static EPS_ERR_CODE DuplSupportedMedia (EPS_PRINTER_INN*, EPS_SUPPORTED_MEDIA* );
+static EPS_ERR_CODE GetPaperSource (EPS_PRINTER_INN* );
+static EPS_ERR_CODE GetJpgMax (EPS_PRINTER_INN* );
+static void ClearSupportedMedia (void );
+
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- ESC/P-R Library API ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsInitDriver() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* commMode EPS_INT8 I: Communication Mode */
+/* (Bi-Directional or Uni-Directional) */
+/* usbFuncPtrs EPS_USB_FUNC* I: Data structure containing function pointers to */
+/* external USB I/O functions. */
+/* netFuncPtrs EPS_NET_FUNC* I: Data structure containing function pointers to */
+/* external network socket I/O functions. */
+/* cmnFuncPtrs EPS_CMN_FUNC* I: Data structure containing function pointers to */
+/* external memory management functions. */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_LIB_INTIALIZED - Lib already initialized */
+/* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "commMode" */
+/* EPS_ERR_INV_FNCP_NULL - Invalid function pointer structure */
+/* EPS_ERR_INV_FNCP_FINDCALLBACK - Invalid function pointer "findCallback" */
+/* EPS_ERR_INV_FNCP_MEMALLOC - Invalid function pointer "memAlloc" */
+/* EPS_ERR_INV_FNCP_MEMFREE - Invalid function pointer "memFree" */
+/* EPS_ERR_INV_FNCP_SLEEP - Invalid function pointer "sleep" */
+/* EPS_ERR_INV_FNCP_OPENPORTAL - Invalid function pointer "openPortal" */
+/* EPS_ERR_INV_FNCP_CLOSEPORTAL - Invalid function pointer "closePortal" */
+/* EPS_ERR_INV_FNCP_READPORTAL - Invalid function pointer "readPortal" */
+/* EPS_ERR_INV_FNCP_WRITEPORTAL - Invalid function pointer "writePortal" */
+/* EPS_ERR_INV_FNCP_FINDFIRST - Invalid function pointer "findFirst" */
+/* EPS_ERR_INV_FNCP_FINDNEXT - Invalid function pointer "findNext" */
+/* EPS_ERR_INV_FNCP_FINDCLOSE - Invalid function pointer "findClose" */
+/* EPS_ERR_INV_FNCP_NETSOCKET - Invalid function pointer "socket" */
+/* EPS_ERR_INV_FNCP_NETCLOSE - Invalid function pointer "close" */
+/* EPS_ERR_INV_FNCP_NETCONNECT - Invalid function pointer "connect" */
+/* EPS_ERR_INV_FNCP_NETSHUTDOWN - Invalid function pointer "shutdown" */
+/* EPS_ERR_INV_FNCP_NETBIND - Invalid function pointer "bind" */
+/* EPS_ERR_INV_FNCP_NETLISTEN - Invalid function pointer "listen" */
+/* EPS_ERR_INV_FNCP_NETACCEPT - Invalid function pointer "accept" */
+/* EPS_ERR_INV_FNCP_NETSEND - Invalid function pointer "send" */
+/* EPS_ERR_INV_FNCP_NETSENDTO - Invalid function pointer "sendTo" */
+/* EPS_ERR_INV_FNCP_NETRECEIVE - Invalid function pointer "receive" */
+/* EPS_ERR_INV_FNCP_NETRECEIVEFROM - Invalid function pointer "receiveFrom" */
+/* EPS_ERR_INV_FNCP_NETGETSOCKNAME - Invalid function pointer "getsockname" */
+/* EPS_ERR_INV_FNCP_NETSETBROADCAST - Invalid function pointer "setBroadcast" */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Registers the external functions with the device driver. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsInitDriver (
+
+ EPS_INT32 commMode,
+ const EPS_USB_FUNC* usbFuncPtrs,
+ const EPS_NET_FUNC* netFuncPtrs,
+ const EPS_CMN_FUNC* cmnFuncPtrs
+
+){
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+
+EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_EPSON_SLEEP
+EPS_INT32 idx, tdx; /* General loop/index varaible */
+EPS_INT32 sleepTime;
+struct timeb sleepS, sleepE;
+#endif /* GCOMSW_EPSON_SLEEP */
+
+/*** Has a Lib been initialized */
+ if (libStatus != EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_INTIALIZED );
+ }
+
+/*** Validate input parameters */
+ if( EPS_ERR_NONE != (retStatus = prtFunctionCheck(commMode, usbFuncPtrs, netFuncPtrs, cmnFuncPtrs)) ){
+ EPS_RETURN( retStatus );
+ }
+
+/*** Register Functions */
+ if( commMode & EPS_PROTOCOL_USB ){
+ memcpy((void*)(&epsUsbFnc), (void*)usbFuncPtrs, sizeof(EPS_USB_FUNC));
+ } else{
+ memset((void*)(&epsUsbFnc), 0, sizeof(EPS_USB_FUNC));
+ }
+ if( commMode & EPS_PROTOCOL_NET ){
+ memcpy((void*)(&epsNetFnc), (void*)netFuncPtrs, sizeof(EPS_NET_FUNC));
+ } else{
+ memset((void*)(&epsNetFnc), 0, sizeof(EPS_NET_FUNC));
+ }
+ memcpy((void*)(&epsCmnFnc), (void*)cmnFuncPtrs, sizeof(EPS_CMN_FUNC));
+
+#ifdef GCOMSW_EPSON_SLEEP
+ if (epsCmnFnc.sleep == NULL)
+ epsCmnFnc.sleep = serSleep;
+#endif /* GCOMSW_EPSON_SLEEP */
+
+
+/*** Initialize ESC/P-R Lib and Local Global Variables */
+ gStatusCount = 0;
+
+ memset(&printJob, 0, sizeof(EPS_PRINT_JOB));
+
+ printJob.jobStatus = EPS_STATUS_NOT_INITIALIZED;
+ printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
+ printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
+ printJob.printer = NULL;
+ printJob.bComm = TRUE;
+ printJob.platform = 0x04; /* '0x04 = linux' is default */
+
+ libStatus = EPS_STATUS_NOT_INITIALIZED;
+ sendDataBufSize = 0;
+ sendDataBuf = NULL;
+ tmpLineBufSize = 0;
+ tmpLineBuf = NULL;
+
+/*** Initialize continue buffer */
+ printJob.contData.sendData = NULL;
+ printJob.contData.sendDataSize = 0;
+
+ /* DEL printJob.additional = EPS_ADDDATA_NONE;
+ printJob.qrcode.bits = NULL;
+ printJob.qrcode.cellNum = 0;
+ printJob.qrcode.dpc = 0; */
+
+ obsClear();
+
+/*** Set "Endian-ness" for the current cpu */
+ memInspectEndian();
+
+/*** Set Communication Mode */
+ printJob.commMode = commMode;
+
+/*** Change ESC/P-R Lib Status */
+ libStatus = EPS_STATUS_INITIALIZED;
+
+/*** Return to Caller */
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsReleaseDriver() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A void */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
+/* */
+/* Description: */
+/* Creanup Driver. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsReleaseDriver (
+
+ void
+
+){
+ EPS_LOG_FUNCIN;
+
+/*** Has a Lib been initialized */
+ if (libStatus == EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
+ }
+
+ epsEndJob();
+
+/*** Clear inside supported media list */
+ ClearSupportedMedia();
+
+/*** Clear inside printer list */
+ prtClearPrinterList();
+ printJob.printer = NULL;
+ obsClear();
+
+/*** Clear inside additional data buffer */
+ /* DEL EPS_SAFE_RELEASE( printJob.qrcode.bits ) */
+
+/*** Change ESC/P-R Lib Status */
+ libStatus = EPS_STATUS_NOT_INITIALIZED;
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsFindPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* protocol EPS_INT32 I: Protocol to be retrieved */
+/* timeout EPS_UINT32 I: Network pirinter find timeout */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (printer found) */
+/* EPS_ERR_LIB_NOT_INITIALIZED - not initialized */
+/* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* find USB and Network printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsFindPrinter (
+
+ EPS_INT32 protocol,
+ EPS_UINT32 timeout
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+
+ EPS_LOG_FUNCIN;
+
+/*** Has a Lib been initialized */
+ if (libStatus != EPS_STATUS_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
+ }
+
+/*** Is a Job already open */
+ if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
+ }
+
+/*** Clear inside printer list */
+ prtClearPrinterList();
+ printJob.printer = NULL;
+ obsClear();
+
+/*** find */
+ printJob.findStatus = EPS_STATUS_INITIALIZED;
+
+ retStatus = prtFindPrinter( protocol, timeout );
+
+ printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsProbePrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* probeParam EPS_PROBE* I: prober parameter structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (printer found) */
+/* EPS_ERR_LIB_NOT_INITIALIZED - not initialized */
+/* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_INV_ARG_PROBEINFO - Invalid argument probe infomation */
+/* EPS_ERR_INV_ARG_UNK_METHOD - Invalid value "method" */
+/* EPS_ERR_INV_ARG_PRINTER_ID - Invalid format "identify" */
+/* EPS_ERR_INV_ARG_PRINTER_ADDR - Invalid format "address" */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
+/* */
+/* Description: */
+/* printer specified by printerID or IP Address is retrieved. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsProbePrinter(
+
+ const EPS_PROBE* probeParam
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+
+ EPS_LOG_FUNCIN;
+
+/*** Validate input parameters */
+ if (NULL == probeParam) {
+ EPS_RETURN( EPS_ERR_INV_ARG_PROBEINFO );
+ }
+
+/*** Has a Lib been initialized */
+ if (libStatus != EPS_STATUS_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
+ }
+
+/*** Is a Job already open */
+ if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
+ }
+
+/*** Clear inside printer list */
+ prtClearPrinterList();
+ printJob.printer = NULL;
+ obsClear();
+
+/*** probe */
+ printJob.findStatus = EPS_STATUS_INITIALIZED;
+ switch( probeParam->method ){
+ case EPS_PRB_BYID:
+ retStatus = prtProbePrinterByID( probeParam );
+ break;
+
+ case EPS_PRB_BYADDR:
+ retStatus = prtProbePrinterByAddr( probeParam );
+ break;
+
+ default:
+ retStatus = EPS_ERR_INV_ARG_UNK_METHOD;
+ }
+ printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsCancelFindPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A void */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_LIB_NOT_INITIALIZED - not initialized */
+/* EPS_ERR_FIND_NOT_STARTED - find not started */
+/* EPS_ERR_INVALID_CALL - invalid called */
+/* */
+/* Description: */
+/* Cancel the epsFindPrinter(), epsProbePrinter() process. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsCancelFindPrinter (
+
+ void
+
+){
+ EPS_LOG_FUNCIN;
+
+ /*** Has a Lib been initialized */
+ if (libStatus != EPS_STATUS_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
+ }
+
+/*** Has a Find been started */
+ if (printJob.findStatus != EPS_STATUS_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_FIND_NOT_STARTED );
+ }
+
+ EPS_RETURN( prtCancelFindPrinter() );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsSetPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER* O: Pointer to a target printer */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
+/* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
+/* EPS_ERR_INV_ARG_PRINTER - Illegal printer was specified */
+/* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "printer.protocol" */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_INV_ARG_PRINTER_ADDR - Invalid format " printer.location" */
+/* EPS_ERR_INV_PRINT_LANGUAGE - Invalid argument "printer.language" */
+/* */
+/* Description: */
+/* Selects a printer to use from detected printers. */
+/* Register a user specified printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsSetPrinter (
+
+ const EPS_PRINTER* printer
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_PRINTER_INN* innerPrinter = NULL;
+
+EPS_LOG_FUNCIN;
+
+/*** Has a Lib been initialized */
+ if (libStatus != EPS_STATUS_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
+ }
+
+/*** Is a Job already open */
+ if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
+ }
+
+/*** Validate input parameters */
+ if (NULL == printer){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER );
+ }
+
+/*** convert internal structure */
+ innerPrinter = prtGetInnerPrinter(printer);
+ if( NULL == innerPrinter ){
+ ret = prtAddUsrPrinter(printer, &innerPrinter);
+ if( EPS_ERR_NONE != ret ){
+ EPS_RETURN( ret );
+ }
+ }
+
+/*** Set Job target printer */
+ printJob.printer = innerPrinter;
+ printJob.bComm = TRUE;
+ obsSetPrinter(innerPrinter);
+ prtSetupJobFunctions(printJob.printer, &jobFnc); /* Set Job functions */
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsStartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* jobAttr const EPS_JOB_ATTRIB* I: Print Job Attribute */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_INV_ARG_JOB_ATTRIB - Invalid argument "jobAttr" */
+/* EPS_ERR_INV_COLOR_PLANE - Invalid Color Plane */
+/* EPS_ERR_INV_PALETTE_SIZE - Invalid Palette Size */
+/* EPS_ERR_INV_PALETTE_DATA - Invalid Palette Data */
+/* EPS_ERR_INV_MEDIA_SIZE - Invalid Media Size */
+/* EPS_ERR_INV_MEDIA_TYPE - Invalid Media Type */
+/* EPS_ERR_INV_BORDER_MODE - Invalid Border Mode */
+/* EPS_ERR_INV_PRINT_QUALITY - Invalid Print Quality */
+/* EPS_ERR_INV_COLOR_MODE - Invalid Color Mode */
+/* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
+/* EPS_ERR_INV_PRINT_DIRECTION - Invalid Print Direction */
+/* EPS_ERR_INV_BRIGHTNESS - Invalid Brightness */
+/* EPS_ERR_INV_CONTRAST - Invalid Contrast */
+/* EPS_ERR_INV_SATURATION - Invalid Saturation */
+/* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
+/* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
+/* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
+/* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
+/* EPS_ERR_INV_PAPER_SOURCE - Invalid Paper source */
+/* EPS_ERR_INV_DUPLEX - Invalid duplex */
+/* EPS_ERR_INV_FEED_DIRECTION - Invalid feed direction */
+/* EPS_ERR_LANGUAGE_NOT_SUPPORTED - Unsupported function Error (language) */
+/* */
+/* EPS_ERR_INV_APF_FLT - Invalid APF Filter */
+/* EPS_ERR_INV_APF_ACT - Invalid APF Scene */
+/* EPS_ERR_INV_APF_SHP - Invalid APF Sharpness */
+/* EPS_ERR_INV_APF_RDE - Invalid APF Red Eye */
+/* */
+/* (Uni/Bi-Directional) */
+/* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
+/* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
+/* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* (Bi-Directional Only) */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+
+/* */
+/* Description: */
+/* Creates a new print job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsStartJob (
+
+ const EPS_JOB_ATTRIB* jobAttr /* Print Attributes for this Job */
+
+){
+
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+EPS_STATUS_INFO stInfo;
+
+EPS_LOG_FUNCIN;
+
+/*** Has a Lib been initialized */
+ if (libStatus != EPS_STATUS_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
+ }
+
+/*** Is a Job already open */
+ if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
+ }
+
+/*** Has a target printer specified */
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
+ }
+
+ if(EPS_CP_JPEG == jobAttr->colorPlane ){
+ if( !(EPS_SPF_JPGPRINT & printJob.printer->supportFunc) ){
+ EPS_RETURN( EPS_ERR_INV_COLOR_PLANE );
+ }
+ }
+
+/*======================================================================================*/
+/*** Setup Page Attribute */
+/*======================================================================================*/
+ if (jobAttr == NULL){
+ EPS_RETURN( EPS_ERR_INV_ARG_JOB_ATTRIB )
+ }
+
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+ /*** ESC/P-R ***/
+ retStatus = SetupJobAttrib(jobAttr);
+ } else{
+ /*** ESC/Page ***/
+#ifdef GCOMSW_CMD_ESCPAGE
+ retStatus = pageInitJob(jobAttr);
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+ }
+ if (EPS_ERR_NONE != retStatus){
+ EPS_RETURN( retStatus );
+ }
+
+/*** Change Job Status */
+ printJob.jobStatus = EPS_STATUS_INITIALIZED;
+ obsSetColorPlane( printJob.attr.colorPlane );
+
+/*======================================================================================*/
+/*** Check the printer status. (before session open) */
+/*======================================================================================*/
+ memset(&stInfo, 0, sizeof(stInfo));
+ if( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ retStatus = PRT_INVOKE_JOBFNC(jobFnc.GetStatus, (&stInfo, NULL, NULL));
+ if( EPS_ERR_NONE != retStatus ){
+ goto epsStartJob_END;
+ } else if(EPS_ST_IDLE != stInfo.nState){
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ goto epsStartJob_END;
+ } else if( EPS_PRNWARN_DISABLE_CLEAN & stInfo.nWarn &&
+ EPS_MNT_CLEANING == printJob.attr.cmdType ){
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ goto epsStartJob_END;
+ }
+ /* ignore color-ink-end warning
+ if color print done, will occuer EPS_PRNERR_INKOUT(0x47).
+ else if( EPS_PRNWARN_COLOR_INKOUT & stInfo.nWarn ){
+ if( !((EPS_CP_FULLCOLOR == printJob.attr.colorPlane || EPS_CP_256COLOR == printJob.attr.colorPlane)
+ && EPS_CM_MONOCHROME == printJob.attr.colorMode
+ && EPS_MTID_PLAIN == printJob.attr.mediaTypeIdx
+ && (EPS_MLID_BORDERS == printJob.attr.printLayout || EPS_MLID_CUSTOM == printJob.attr.printLayout)) ){
+ color printing is impossible. (Mono/Plain/Border is possible)
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ goto epsStartJob_END;
+ }
+ }*/
+ }
+
+/*======================================================================================*/
+/*** Prepar RGB buffer */
+/*======================================================================================*/
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+ /*** ESC/P-R ***/
+ if( EPS_CP_FULLCOLOR == printJob.attr.colorPlane ||
+ EPS_CP_256COLOR == printJob.attr.colorPlane){
+ /*** Allocate buffer for "Send Data" command */
+ EPS_SAFE_RELEASE(sendDataBuf );
+ EPS_SAFE_RELEASE(tmpLineBuf );
+
+ sendDataBufSize = (EPS_INT32)(ESCPR_HEADER_LENGTH +
+ ESCPR_SEND_DATA_LENGTH +
+ (printJob.printableAreaWidth * printJob.bpp));
+ sendDataBuf = (EPS_UINT8*)EPS_ALLOC(sendDataBufSize);
+ if(sendDataBuf == NULL){
+ sendDataBufSize = 0;
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+
+ memset(sendDataBuf, 0xFF, (EPS_UINT32)sendDataBufSize);
+
+ /*** Allocate buffer for RLE complession */
+ tmpLineBufSize = (EPS_INT32)(printJob.printableAreaWidth * printJob.bpp) + 256; /* 256 is temp buffer */
+ tmpLineBuf = (EPS_UINT8*)EPS_ALLOC(tmpLineBufSize);
+ if(tmpLineBuf == NULL){
+ tmpLineBufSize = 0;
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+ memset(tmpLineBuf, 0xFF, (EPS_UINT32)tmpLineBufSize);
+
+ } else if(EPS_CP_JPEG == printJob.attr.colorPlane){
+ if(0 == printJob.printer->JpgMax){
+ /*** get jpeg limit */
+ retStatus = GetJpgMax(printJob.printer);
+ if (retStatus != EPS_ERR_NONE) {
+ goto epsStartJob_END;
+ }
+ }
+ }
+ } else{
+#ifdef GCOMSW_CMD_ESCPAGE
+ /*** ESC/Page ***/
+ retStatus = pageAllocBuffer();
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+ if (retStatus != EPS_ERR_NONE) {
+ goto epsStartJob_END;
+ }
+ }
+
+/*======================================================================================*/
+/*** protocol depend StartJob */
+/*======================================================================================*/
+ retStatus = jobFnc.StartJob();
+ if (retStatus != EPS_ERR_NONE) {
+ goto epsStartJob_END;
+ }
+
+/*======================================================================================*/
+/*** Init flags */
+/*======================================================================================*/
+ printJob.transmittable = TRUE;
+ printJob.resetSent = EPS_RESET_NOT_SENT;
+ printJob.resetReq = FALSE;
+ printJob.bComm = TRUE;
+ printJob.sendJS = FALSE;
+ printJob.pageCount = 0;
+ gStatusCount = 0;
+
+ printJob.contData.savePoint = EPS_SAVEP_NONE;
+ printJob.contData.saveStep = 0;
+ printJob.contData.sendData = NULL;
+ printJob.contData.sendDataSize = 0;
+
+/*======================================================================================*/
+/*** Send StartJob Commands */
+/*======================================================================================*/
+#ifdef LCOMSW_CMDDMP
+{
+ EPS_INT8 fname[256];
+ sprintf(fname, "%s-%s-%s.prn", (printJob.printer->language == EPS_LANG_ESCPR)?"escpr":"page",
+ (printJob.attr.colorMode == EPS_CM_COLOR)?"color":"mono",
+ (printJob.attr.colorPlane == EPS_CP_FULLCOLOR)?"24":"8");
+ EPS_DF_OPEN(fname)
+}
+#endif
+
+ if( EPS_CP_PRINTCMD != printJob.attr.colorPlane ){
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+ /*** ESC/P-R ***/
+ if(EPS_PM_JOB != obsGetPageMode()){
+ retStatus = SendStartJob(FALSE);
+ }
+ } else{
+ /*** ESC/Page ***/
+#ifdef GCOMSW_CMD_ESCPAGE
+ retStatus = pageStartJob();
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+ }
+
+ if(EPS_ERR_NONE != retStatus){
+ goto epsStartJob_END;
+ }
+ } else{
+ printJob.pageStatus = EPS_STATUS_INITIALIZED;
+ }
+
+ printJob.jobStatus = EPS_STATUS_ESTABLISHED;
+
+epsStartJob_END:
+/*** Return to Caller */
+ if (EPS_ERR_NOT_OPEN_IO == retStatus || EPS_ERR_COMM_ERROR == retStatus) {
+ printJob.bComm = FALSE;
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ }
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsStartPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pageAttr const EPS_JOB_ATTRIB* I: This Page Attribute */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* << Error >> */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_PAGE_NOT_CLOSED - PAGE is NOT closed */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Starts the current page. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsStartPage (
+
+ const EPS_PAGE_ATTRIB* pageAttr
+
+){
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus; /* Return status of internal calls */
+EPS_UINT32 retBufSize = 0;
+EPS_STATUS_INFO stInfo;
+
+EPS_LOG_FUNCIN;
+
+ (void)pageAttr; /* unused now */
+
+/*** EPS_CP_PRINTCMD not necessary call epsStartPage() */
+ if (EPS_CP_PRINTCMD == printJob.attr.colorPlane) {
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+/*** Has a Job been initialized */
+ if (printJob.jobStatus != EPS_STATUS_ESTABLISHED) {
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+/*** Has the Page Status been un-initialized; indicating the last page was closed */
+ if (printJob.pageStatus != EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_PAGE_NOT_CLOSED );
+ }
+
+/*** Check the printer status and the stacker error. */
+ if ( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ retStatus = MonitorStatus(&stInfo);
+
+ if( EPS_ERR_NONE == retStatus ){
+ if( EPS_PREPARE_TRAYCLOSED == stInfo.nPrepare ){
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ } else if( EPS_PM_JOB == obsGetPageMode() &&
+ EPS_ST_IDLE != stInfo.nState ){
+ /* still printing */
+ EPS_DBGPRINT(("*** StarPage Wait ***\n"))
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ }
+ }
+ if( EPS_ERR_NONE != retStatus ){
+ if( EPS_ERR_COMM_ERROR != retStatus &&
+ EPS_PROTOCOL_USB != EPS_PRT_PROTOCOL(printJob.printer->protocol) )
+ { /* Ignore error, Make buffer full state. */
+ EPS_DBGPRINT(("*** Ignore error on StartPage ***\n"))
+ retStatus = EPS_ERR_NONE;
+ } else{
+ goto epsStartPage_END;
+ }
+ }
+ }
+
+ if( EPS_PM_JOB == obsGetPageMode() &&
+ EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol) ){
+ retStatus = PRT_INVOKE_JOBFNC(jobFnc.StartPage, ());
+ if (retStatus != EPS_ERR_NONE) {
+ goto epsStartPage_END;
+ }
+ }
+ if( EPS_RESET_SENT == printJob.resetSent ){
+ /* If CancelPage is done, restart Job. */
+ /*** protocol depend RestartJob */
+ retStatus = PRT_INVOKE_JOBFNC(jobFnc.RestartJob, ());
+ if (retStatus != EPS_ERR_NONE) {
+ goto epsStartPage_END;
+ }
+ }
+
+ if(0 == printJob.contData.saveStep){
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+ /*** ESC/P-R ***/
+ if( EPS_RESET_SENT == printJob.resetSent ){
+ /* If CancelPage is done, restart Job complete. */
+ printJob.resetSent = EPS_RESET_NOT_SENT;
+ /*** Send StartJob & StartPage Commands */
+ retStatus = SendStartJob(TRUE);
+ } else if( EPS_PM_JOB == obsGetPageMode() ){
+ /*** Send StartJob & StartPage Commands */
+ retStatus = SendStartJob(TRUE);
+ } else{
+ /*** Send StartPage Commands */
+ EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, sizeof(StartPage) )
+ if(NULL == sendDataBuf){
+ sendDataBufSize = 0;
+ retStatus = EPS_ERR_MEMORY_ALLOCATION;
+ goto epsStartPage_END;
+ }
+
+ memcpy(sendDataBuf, StartPage, sizeof(StartPage));
+ retStatus = SendCommand(sendDataBuf, sizeof(StartPage), &retBufSize, TRUE);
+ }
+ } else{
+ /*** ESC/Page ***/
+#ifdef GCOMSW_CMD_ESCPAGE
+ retStatus = pageStartPage();
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+ }
+ } else{
+ /* send command retry */
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){
+ retStatus = EPS_ERR_NONE;
+ }
+ }
+ if(EPS_ERR_NONE == retStatus){
+ printJob.contData.saveStep = 0;
+ } else{
+ printJob.contData.saveStep = 1;
+ }
+
+epsStartPage_END:
+ if(EPS_ERR_NONE == retStatus){
+ /*** Change Page Status */
+ printJob.pageStatus = EPS_STATUS_INITIALIZED;
+ printJob.contData.savePoint = EPS_SAVEP_NONE;
+
+ /*** Set Vertical Offset */
+ printJob.verticalOffset = 0;
+ printJob.contData.jpgSize = 0;
+ printJob.contData.epRetry = 0;
+ printJob.contData.skipLine = FALSE;
+ printJob.jpegSize = 0;
+ printJob.bJpgLimit = FALSE;
+ if( printJob.attr.duplex != EPS_DUPLEX_NONE ){
+ printJob.needBand = TRUE;
+ } else{
+ printJob.needBand = FALSE;
+ }
+
+ } else if(EPS_ERR_COMM_ERROR == retStatus){
+ printJob.bComm = FALSE;
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ } else{
+ printJob.contData.savePoint = EPS_SAVEP_START_PAGE;
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsPrintBand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* data EPS_UINT8* I: Pointer to image [RGB] data */
+/* widthPixels EPS_UINT32 I: The width of the raster band (in pixels) */
+/* heightPixels EPS_UINT32* I/O: In : Height of image (image lines) (in pixels)*/
+/* : Out: Sent Height */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* EPS_OUT_OF_BOUNDS - Print band is in out of printable area */
+/* << Error >> */
+/* EPS_ERR_PAGE_NOT_INITIALIZED - Page is NOT initialized */
+/* EPS_ERR_INV_ARG_DATA - Invalid argument "data" */
+/* EPS_ERR_INV_ARG_WIDTH_PIXELS - Invalid argument "widthPixels" */
+/* EPS_ERR_INV_ARG_HEIGHT_PIXELS - Invalid argument "heightPixels" */
+/* EPS_ERR_INV_ARG_DATASIZE - data size limit */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Prints a band of raster data or Jpeg file data. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsPrintBand (
+
+ const EPS_UINT8* data, /* Pointer to image [RGB] data */
+ EPS_UINT32 widthPixels, /* Width of image [ in pixels ] */
+ EPS_UINT32 *heightPixels /* Height of image (image lines) */
+
+) {
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus;
+ EPS_PRN_DATA prnData;
+
+ prnData.version = 1;
+ prnData.band.data = data;
+ prnData.band.widthPixels = widthPixels;
+ prnData.band.heightPixels = *heightPixels;
+
+ retStatus = epsSendData(&prnData);
+
+ *heightPixels = prnData.band.heightPixels;
+
+ return retStatus;
+}
+
+
+EPS_ERR_CODE epsSendData (
+
+ EPS_PRN_DATA* prnData /* Pointer to image [RGB, JPEG] data */
+
+) {
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+/*** Has a Page (which also means Job) been initialized */
+ if (printJob.pageStatus == EPS_STATUS_NOT_INITIALIZED) {
+ retStatus = EPS_ERR_PAGE_NOT_INITIALIZED;
+ }
+
+/* printJob.pageStatus = EPS_STATUS_PROCCESSING; */
+
+ if( FALSE == printJob.bComm ){
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ }
+
+/*** Validate input parameters */
+ if( NULL == prnData ){
+ EPS_RETURN( EPS_ERR_INV_ARG_DATA );
+ }
+
+ switch(printJob.attr.colorPlane){
+ case EPS_CP_JPEG:
+ if(EPS_ERR_NONE == retStatus){
+ retStatus = PrintChunk(prnData->chunk.data, &prnData->chunk.dataSize);
+ } else{
+ prnData->chunk.dataSize = 0;
+ }
+ break;
+
+ case EPS_CP_FULLCOLOR:
+ case EPS_CP_256COLOR:
+ if(EPS_ERR_NONE == retStatus){
+ retStatus = PrintBand(prnData->band.data, prnData->band.widthPixels, &prnData->band.heightPixels);
+ } else{
+ prnData->band.heightPixels = 0;
+ }
+ break;
+
+ case EPS_CP_PRINTCMD:
+ default:
+ if(EPS_ERR_NONE == retStatus){
+ retStatus = SendCommand(prnData->chunk.data, prnData->chunk.dataSize,
+ &prnData->chunk.dataSize, FALSE);
+ } else{
+ prnData->chunk.dataSize = 0;
+ }
+ break;
+ }
+
+ if(EPS_ERR_COMM_ERROR == retStatus){
+ printJob.bComm = FALSE;
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ }
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsEndPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nextPage EPS_BOOL Next page flag */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* << Error >> */
+/* EPS_ERR_PAGE_NOT_INITIALIZED - PAGE is NOT initialized */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* */
+/* Description: */
+/* Ends the current page. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsEndPage (
+
+ EPS_BOOL nextPage
+
+){
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus= EPS_ERR_NONE; /* Return status of internal calls */
+EPS_UINT32 retBufSize = 0;
+EPS_UINT8* pCmd = NULL;
+EPS_STATUS_INFO stInfo;
+
+EPS_LOG_FUNCIN;
+
+/*** EPS_CP_PRINTCMD not necessary call epsEndPage() */
+ if (EPS_CP_PRINTCMD == printJob.attr.colorPlane) {
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+/*** Has a Page (which also means Job) been initialized */
+ if (printJob.pageStatus == EPS_STATUS_NOT_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_PAGE_NOT_INITIALIZED );
+ }
+
+ if( FALSE == printJob.bComm ){
+ /*** Change the page status */
+ printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
+ /* Do not send "EndPage" commands */
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+/*======================================================================================*/
+/*** Check the printer status */
+/*======================================================================================*/
+ if ( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ /* Check the printer status */
+ retStatus = MonitorStatus(NULL);
+ if( EPS_JOB_CANCELED == retStatus ){
+ goto epsEndPage_END;
+ } else if(EPS_ERR_COMM_ERROR == retStatus ){
+ goto epsEndPage_END;
+ }
+ }
+
+ /* send command retry */
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){
+ retStatus = EPS_ERR_NONE;
+ }
+
+/*** Send EndPage */
+ /* step 1 : send dummy band for duplex */
+ if( EPS_ERR_NONE == retStatus && 0 == printJob.contData.saveStep ){
+ printJob.contData.saveStep++;
+ if( TRUE == printJob.needBand ){
+ retStatus = SendBlankBand();
+ printJob.needBand = FALSE;
+ }
+ }
+
+ /* step 2 : send end page command */
+ if( EPS_ERR_NONE == retStatus && 1 == printJob.contData.saveStep ){
+ printJob.contData.saveStep++;
+
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+ /*** ESC/P-R ***/
+ if( EPS_PM_JOB == obsGetPageMode() ){
+ /* EndPage & EndJob */
+ retStatus = SendEndJob(TRUE);
+ } else{
+ /* EndPage */
+ EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, sizeof(EndPage) )
+ if(NULL == sendDataBuf){
+ sendDataBufSize = 0;
+ retStatus = EPS_ERR_MEMORY_ALLOCATION;
+ goto epsEndPage_END;
+ }
+
+ pCmd = sendDataBuf;
+ memcpy(pCmd, EndPage, sizeof(EndPage));
+ if( FALSE == nextPage ){
+ if (EPS_DUPLEX_NONE != printJob.attr.duplex &&
+ 0 == (printJob.pageCount & 0x01)) {
+ nextPage = TRUE;
+ }
+ }
+ if(FALSE == nextPage
+ || EPS_IS_CDDVD( printJob.attr.mediaTypeIdx )){
+ pCmd[10] = EPS_END_PAGE;
+ } else{
+ pCmd[10] = EPS_NEXT_PAGE;
+ }
+
+ retStatus = SendCommand(sendDataBuf, sizeof(EndPage), &retBufSize, TRUE);
+ }
+ } else{
+ /*** ESC/Page ***/
+#ifdef GCOMSW_CMD_ESCPAGE
+ retStatus = pageEndPage();
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+ }
+ }
+
+
+epsEndPage_END:
+/*** Return to Caller */
+ if(EPS_ERR_NONE == retStatus){
+ /*** Change the page status */
+ printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
+ printJob.pageCount++;
+ printJob.contData.savePoint = EPS_SAVEP_NONE;
+ printJob.contData.saveStep = 0;
+
+ if( EPS_PM_JOB == obsGetPageMode() &&
+ EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol) &&
+ printJob.contData.epRetry < 10){
+ /* LPR JOB mode */
+ retStatus = PRT_INVOKE_JOBFNC(jobFnc.EndPage, ());
+ if(EPS_ERR_NONE == retStatus){
+ if(EPS_IS_BI_PROTOCOL(printJob.printer->protocol)){
+ MonitorStatus(&stInfo);
+ if( EPS_ST_IDLE == stInfo.nState ){
+ /* retry this function still idle */
+ serDelayThread(2*_SECOND_, &epsCmnFnc);
+ printJob.contData.epRetry++;
+ printJob.contData.savePoint = EPS_SAVEP_END_PAGE;
+ printJob.contData.saveStep = 2;
+ printJob.pageStatus = EPS_STATUS_INITIALIZED;
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ EPS_DBGPRINT(("*** EndPage Wait ***\n"))
+ }
+ }
+ } else if(EPS_ERR_COMM_ERROR == retStatus){
+ printJob.bComm = FALSE;
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ }
+ }
+ } else if(EPS_ERR_COMM_ERROR == retStatus){
+ printJob.bComm = FALSE;
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ } else{
+ printJob.contData.savePoint = EPS_SAVEP_END_PAGE;
+ printJob.contData.nextPage = nextPage;
+ }
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsEndJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A void N/A */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* */
+/* Description: */
+/* Ends the current print job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsEndJob (
+
+ void
+
+){
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus; /* Return status of internal calls */
+EPS_INT32 nRetry = 0;
+EPS_PRINT_JOB tempPrintJob;
+EPS_UINT32 retBufSize = 0;
+EPS_BOOL sendEndpage = FALSE;
+
+EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ retStatus = EPS_ERR_NONE;
+
+/*** Has a Job been initialized; indicate start job was called */
+ if (printJob.jobStatus == EPS_STATUS_NOT_INITIALIZED) {
+ retStatus = EPS_ERR_JOB_NOT_INITIALIZED;
+ goto JOBEND_END;
+ }
+
+ if (EPS_CP_PRINTCMD != printJob.attr.colorPlane) {
+ /*** If not invoked epsEndPage, invoke it */
+ if (printJob.pageStatus != EPS_STATUS_NOT_INITIALIZED) {
+ epsEndPage(FALSE);
+ }
+
+ /*** Send backside page for ESCPR duplex */
+ if(EPS_RESET_NOT_SENT == printJob.resetSent &&
+ EPS_DUPLEX_NONE != printJob.attr.duplex &&
+ EPS_LANG_ESCPR == printJob.printer->language &&
+ (printJob.pageCount & 0x01) )
+ {
+ memcpy(sendDataBuf, StartPage, sizeof(StartPage));
+ retStatus = SendCommand(sendDataBuf, sizeof(StartPage), &retBufSize, TRUE);
+ for(nRetry = 0; nRetry < 5 && printJob.bComm; nRetry++){
+ if(EPS_ERR_NONE == retStatus || EPS_JOB_CANCELED == retStatus){
+ break;
+ }
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){
+ retStatus = EPS_ERR_NONE;
+ }
+ }
+
+ retStatus = SendBlankBand();
+ for(nRetry = 0; nRetry < 5 && printJob.bComm; nRetry++){
+ if(EPS_ERR_NONE == retStatus || EPS_JOB_CANCELED == retStatus){
+ break;
+ }
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){
+ retStatus = EPS_ERR_NONE;
+ }
+ }
+
+ sendEndpage = TRUE;
+ }
+
+ /*** Send EndJob */
+ if (printJob.jobStatus == EPS_STATUS_ESTABLISHED &&
+ EPS_PM_JOB != obsGetPageMode() )
+ {
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+ /*** ESC/P-R ***/
+ retStatus = SendEndJob(sendEndpage);
+ } else{
+ /*** ESC/Page ***/
+#ifdef GCOMSW_CMD_ESCPAGE
+ retStatus = pageEndJob();
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+ }
+ }
+
+ for(nRetry = 0; nRetry < 5 && printJob.bComm; nRetry++){
+ if(EPS_ERR_NONE == retStatus){
+ break;
+ }
+
+ EPS_DBGPRINT(("retry ENDJOB\n"))
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){
+ retStatus = EPS_ERR_NONE;
+ }
+ }
+ }
+
+/*** protocol depend EndJob */
+ retStatus = jobFnc.EndJob();
+
+JOBEND_END:
+/*** Clear Memory */
+#ifdef GCOMSW_CMD_ESCPAGE
+ pageRelaseBuffer();
+#endif
+ EPS_SAFE_RELEASE(sendDataBuf );
+ EPS_SAFE_RELEASE(tmpLineBuf );
+ sendDataBufSize = 0;
+ tmpLineBufSize = 0;
+
+/*** Reset continue buffer */
+ printJob.contData.sendData = NULL;
+ printJob.contData.sendDataSize = 0;
+
+/*** Clear inside additional data buffer */
+ /* DEL EPS_SAFE_RELEASE( printJob.qrcode.bits );*/
+
+/*** Clear and Copy Print_Job struct */
+ memcpy(&tempPrintJob, &printJob, sizeof(EPS_PRINT_JOB));
+ memset(&printJob, 0, sizeof(EPS_PRINT_JOB));
+
+ printJob.pageStatus = tempPrintJob.pageStatus;
+ printJob.commMode = tempPrintJob.commMode;
+ printJob.printer = tempPrintJob.printer;
+ printJob.platform = tempPrintJob.platform;
+
+#ifdef GCOMSW_EPSON_SLEEP
+ printJob.sleepSteps = tempPrintJob.sleepSteps;
+#endif
+
+/*** Change the job status */
+ printJob.jobStatus = EPS_STATUS_NOT_INITIALIZED;
+ printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
+ printJob.bComm = TRUE;
+ printJob.resetReq = FALSE;
+
+#if 0
+ if(EPS_ERR_NOT_CLOSE_IO == retStatus || EPS_ERR_COMM_ERROR == retStatus){
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ }
+#else
+ if (EPS_ERR_NONE != retStatus) {
+ EPS_DBGPRINT(("epsEndJob failed (%d)\r\n", retStatus));
+ retStatus = EPS_ERR_NONE;
+ }
+#endif
+
+#ifdef LCOMSW_CMDDMP
+ EPS_DF_CLOSE
+#endif
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsCancelJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* reserve EPS_BOOL I:Call epsEndJob() */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
+/* EPS_ERR_CAN_NOT_RESET - Failed to reset printer */
+/* */
+/* Description: */
+/* Reset printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsCancelJob (
+
+ EPS_INT32 reserve
+
+){
+
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+EPS_ERR_CODE retTmp = EPS_ERR_NONE;
+
+EPS_LOG_FUNCIN;
+#if !LCOMSW_CANCEL_JOB
+ (void)reserve;
+#endif
+
+/*** Validate communication mode */
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_NONE/*EPS_ERR_PRINTER_NOT_SET*/ );
+ }
+
+ if ( !EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+ if (printJob.jobStatus == EPS_STATUS_ESTABLISHED) {
+ /*** Send the reset command to printer */
+ retStatus = PRT_INVOKE_JOBFNC(jobFnc.ResetPrinter, ());
+ printJob.resetSent = EPS_RESET_SENT;
+ printJob.resetReq = FALSE;
+ if(EPS_ERR_NONE != retStatus){
+ EPS_DBGPRINT(("ResetPrinter() failed (%d)\r\n", retStatus));
+ retStatus = EPS_ERR_CAN_NOT_RESET;
+ /* return retStatus; Force continue */
+ }
+
+ /*** Change the page status */
+ printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
+ }
+
+#if LCOMSW_CANCEL_JOB
+ if(0 == reserve){
+#endif
+ /*** Invoke epsEndJob() */
+ retTmp = epsEndJob();
+ if (retTmp != EPS_ERR_NONE) {
+ EPS_DBGPRINT(("epsEndJob() failed (%d)\r\n", retTmp));
+ /* return retStatus; Force continue */
+ }
+#if LCOMSW_CANCEL_JOB
+ }
+#endif
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsContinueJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A void N/A */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* << Error >> */
+/* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_PAGE_NOT_INITIALIZED - PAGR is NOT initialized */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Reset printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsContinueJob (
+
+ void
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_INT32 nCnt = 0;
+
+ EPS_LOG_FUNCIN;
+
+/*** Has a target printer specified */
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+/*** Has a Job been initialized */
+ if (printJob.jobStatus == EPS_STATUS_NOT_INITIALIZED){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+/*** Validate communication mode */
+ if( !EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+/*** Recovery command */
+ switch( printJob.contData.lastError ){
+ case EPS_PRNERR_PAPEROUT:
+ case EPS_PRNERR_NOTRAY:
+ /*case EPS_PRNERR_CDDVDCONFIG:*/
+ if( EPS_ERR_PRINTER_ERR_OCCUR == MonitorStatus(NULL)){
+ if( EPS_ERR_NONE != (retStatus = prtRecoverPE()) ){
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
+ }
+ /*serDelayThread(2*_SECOND_, &epsCmnFnc);*/
+
+ /* Status change is delayed the condition of LPR ASSIST */
+ if( EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol)
+ && EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ for(nCnt = 0; nCnt < 3; nCnt++){
+ serDelayThread(2*_SECOND_, &epsCmnFnc);
+ if( EPS_ERR_NONE == MonitorStatus(NULL) ){
+ break;
+ }
+ EPS_DBGPRINT(("*** Recover Wait ***\n"))
+ }
+ }
+ }
+ break;
+
+ case EPS_PRNERR_INTERFACE:
+ /*serDelayThread(5*_SECOND_, &epsCmnFnc);*/
+ break;
+ default:
+ break;
+ }
+
+/*** Check printer starus */
+ retStatus = MonitorStatus(NULL);
+ if(EPS_ERR_NONE != retStatus){
+ EPS_RETURN( retStatus );
+ }
+
+/*** Send leftovers data */
+ switch(printJob.contData.savePoint){
+ case EPS_SAVEP_START_PAGE:
+ retStatus = epsStartPage(NULL);
+ break;
+ case EPS_SAVEP_END_PAGE:
+ retStatus = epsEndPage(printJob.contData.nextPage);
+ break;
+
+ default:
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){
+ retStatus = EPS_ERR_NONE;
+ } else if(EPS_ERR_NONE == retStatus){
+ printJob.contData.skipLine = TRUE;
+ } else {
+ EPS_RETURN( retStatus );
+ }
+ break;
+ }
+
+/*** Return to Caller */
+ if(EPS_ERR_COMM_ERROR == retStatus){
+ printJob.bComm = FALSE;
+ retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
+ }
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsSetAdditionalData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* data EPS_ADD_DATA* I: pointer to Additional data */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_PAGE_NOT_CLOSED - PAGR is initialized */
+/* EPS_ERR_INV_ARG_VALIDMEMBER - Invalid argument "validMember" */
+/* EPS_ERR_INV_ARG_ADDDATA - Invalid argument "data" */
+/* EPS_ERR_INV_ARG_QRSOURCE - Invalid argument "data.qrcode.source" */
+/* EPS_ERR_INV_ARG_QRXPOS - Invalid argument "data.qrcode.xPos" */
+/* EPS_ERR_INV_ARG_QRYPOS - Invalid argument "data.qrcode.position.y" */
+/* EPS_ERR_QRSOURCE_TOO_LAGE - source is too lage to convert QR code */
+/* */
+/* Description: */
+/* Set additional data print image. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsSetAdditionalData (
+
+ EPS_UINT32 dataType,
+ const void* data
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_LOG_FUNCIN;
+ /* This Func is ineffective in the current version. */
+ EPS_RETURN( EPS_ERR_INVALID_CALL );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsRemAdditionalData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* member EPS_UINT32 I: pointer to Additional data */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_INV_ARG_VALIDMEMBER - Invalid argument "validMember" */
+/* */
+/* Description: */
+/* Release additional data setting by epsRemAdditionalData(). */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsRemAdditionalData (
+
+ EPS_UINT32 dataType
+
+){
+ EPS_LOG_FUNCIN;
+ /* This Func is ineffective in the current version. */
+ EPS_RETURN( EPS_ERR_INVALID_CALL );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsGetStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* status EPS_STATUS* Pointer to the printer status. */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
+/* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
+/* EPS_ERR_INV_ARG_STATUS - Invalid argument */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Gets the printer status. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsGetStatus (
+
+ EPS_STATUS *status
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_STATUS_INFO stInfo;
+ EPS_BOOL bIoStatus = FALSE;
+ EPS_BOOL bCanceling = FALSE;
+
+ EPS_LOG_FUNCIN;
+
+/*** Validate communication mode */
+ if( !EPS_IS_BI_PROTOCOL(printJob.commMode) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+/*** Has a target printer specified */
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
+ }
+
+/*** Validate input parameters */
+ if (status == NULL){
+ EPS_RETURN( EPS_ERR_INV_ARG_STATUS );
+ }
+
+ memset(status, 0, sizeof(EPS_STATUS));
+
+/*** Jpeg size limitation */
+ if( TRUE == printJob.bJpgLimit ){
+ status->printerStatus = EPS_PRNST_ERROR;
+ status->errorCode = EPS_PRNERR_JPG_LIMIT;
+ status->jobContinue = FALSE;
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+/*** Get printer status */
+ memset(&stInfo, 0, sizeof(stInfo));
+ if( TRUE == printJob.bComm ){
+ ret = PRT_INVOKE_JOBFNC(jobFnc.GetStatus,
+ (&stInfo, &bIoStatus, &bCanceling));
+
+ if(EPS_ERR_COMM_ERROR == ret &&
+ EPS_STATUS_NOT_INITIALIZED != printJob.jobStatus){
+ printJob.bComm = FALSE;
+ }
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ }
+
+// EPS_DBGPRINT((" State\t: %d\n Error\t: %d\n IoStatus\t: %d\n Canceling\t: %d\n Prepare\t: %d\n",
+// stInfo.nState, stInfo.nError, bIoStatus, bCanceling, stInfo.nPrepare))
+
+ if(EPS_ERR_COMM_ERROR == ret ||
+ EPS_ERR_NOT_OPEN_IO == ret ||
+ EPS_ERR_NOT_CLOSE_IO == ret ) {
+ status->printerStatus = EPS_PRNST_ERROR/*EPS_PRNST_OFFLINE*/;
+ status->errorCode = EPS_PRNERR_COMM;
+ status->jobContinue = FALSE;
+ EPS_RETURN( EPS_ERR_NONE );
+ } else if (EPS_ERR_NONE != ret){
+ EPS_RETURN( ret );
+ }
+
+ if(stInfo.nCancel == EPS_CAREQ_CANCEL) {
+ EPS_DBGPRINT(("EPS SER : CANCEL REQUEST by PRINTER\r\n"));
+ printJob.resetReq = TRUE;
+ }
+#if 0
+ if(TRUE == printJob.resetReq){
+ status->printerStatus = EPS_PRNST_ERROR/*EPS_PRNST_OFFLINE*/;
+ status->errorCode = EPS_PRNERR_COMM;
+ status->jobContinue = FALSE;
+ }
+#endif
+
+/*** Copy status data to input buffer */
+ status->errorCode= stInfo.nError;
+ printJob.contData.lastError = stInfo.nError;
+ switch(stInfo.nState) {
+ case EPS_ST_ERROR:
+ status->printerStatus = EPS_PRNST_ERROR;
+
+ switch(stInfo.nError){
+ case EPS_PRNERR_INKOUT:
+ /* Convert Ink error */
+ serGetInkError(&stInfo, &status->errorCode);
+ break;
+
+ case EPS_PRNERR_INTERFACE:
+ case EPS_PRNERR_BUSY:
+ if(EPS_STATUS_ESTABLISHED == printJob.jobStatus){
+ /* between multi page(job of EPS_PM_JOB), it becomes busy. */
+ status->printerStatus = EPS_PRNST_PRINTING;
+ status->errorCode = EPS_PRNERR_NOERROR;
+ } else{
+ status->printerStatus = EPS_PRNST_BUSY;
+ }
+
+ break;
+
+ case EPS_PRNERR_PAPERJAM:
+ printJob.transmittable = FALSE;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case EPS_ST_WAITING:
+ status->printerStatus = EPS_PRNST_PRINTING;
+ break;
+
+ case EPS_ST_IDLE:
+ /* If printer doesn't move, it becomes idle. */
+ if(EPS_STATUS_ESTABLISHED == printJob.jobStatus){
+ status->printerStatus = EPS_PRNST_PRINTING;
+ } else{
+ status->printerStatus = EPS_PRNST_IDLE;
+ }
+ break;
+
+ case EPS_ST_FACTORY_SHIPMENT:
+ status->printerStatus = EPS_PRNST_ERROR;
+ status->errorCode = EPS_PRNERR_FACTORY;
+ break;
+
+ case EPS_ST_CLEANING:
+ case EPS_ST_BUSY:
+ if(EPS_STATUS_ESTABLISHED == printJob.jobStatus){
+ /* The cleaning under the print is made "printing". */
+ status->printerStatus = EPS_PRNST_PRINTING;
+ status->errorCode = EPS_PRNERR_NOERROR;
+ } else{
+ status->errorCode = EPS_PRNERR_BUSY;
+ status->printerStatus = EPS_PRNST_BUSY;
+ }
+ break;
+
+ default: /* The others. */
+ /* EPS_ST_SELF_PRINTING */
+ /* EPS_ST_SHUTDOWN */
+ status->errorCode = EPS_PRNERR_BUSY;
+ status->printerStatus = EPS_PRNST_BUSY;
+ break;
+ }
+
+ if(EPS_PRNERR_NOERROR == status->errorCode){
+ /* If other errors have not occurred */
+ if(EPS_PREPARE_TRAYCLOSED == stInfo.nPrepare
+ && EPS_STATUS_ESTABLISHED == printJob.jobStatus
+ && EPS_STATUS_NOT_INITIALIZED == printJob.pageStatus){
+ /* between epsStartJob to epsStartPage complete */
+ status->errorCode = EPS_PRNERR_TRAYCLOSE;
+ status->printerStatus = EPS_PRNST_ERROR;
+
+ } else if(EPS_PRNWARN_DISABLE_CLEAN & stInfo.nWarn
+ && EPS_MNT_CLEANING == printJob.attr.cmdType
+ && EPS_STATUS_INITIALIZED == printJob.jobStatus){
+ /* GetStatus failed in epsStartJob() */
+ status->errorCode = EPS_PRNERR_DISABEL_CLEANING;
+ status->printerStatus = EPS_PRNST_ERROR;
+
+ } else if( bCanceling ){
+ /* Printing has been canceled by the cancel request which had been triggered
+ * by either the epsonPrintCancelJob/Page() API
+ * or a user operation on the printer panel. */
+ status->printerStatus = EPS_PRNST_CANCELLING;
+ if(EPS_PRNERR_NOERROR == status->errorCode){
+ status->errorCode = EPS_PRNERR_BUSY;
+ }
+ } else if( !bIoStatus ) {
+ /* ESC/P-R Library had sent all that is needed to print
+ * to the printer but the printer has not been completed printing yet. */
+ status->printerStatus = EPS_PRNST_BUSY;
+ if(EPS_PRNERR_NOERROR == status->errorCode){
+ status->errorCode = EPS_PRNERR_BUSY;
+ }
+ }
+ /* ignore color-ink-end warning
+ else if( EPS_PRNWARN_COLOR_INKOUT & stInfo.nWarn
+ && EPS_STATUS_ESTABLISHED != printJob.jobStatus ){
+ color ink out is error, when besides job.
+ status->errorCode = EPS_PRNERR_INKOUT;
+ status->printerStatus = EPS_PRNST_ERROR;
+ }*/
+ }
+
+/*** Set continue flag */
+ status->jobContinue = TRUE;
+ if( EPS_STATUS_ESTABLISHED != printJob.jobStatus ){
+ status->jobContinue = FALSE;
+ } else{
+ switch(status->errorCode){
+ /* The error that it can not continue the printing job */
+ case EPS_PRNERR_GENERAL:
+ case EPS_PRNERR_FATAL:
+ case EPS_PRNERR_PAPERJAM:
+ /*case EPS_PRNERR_SIZE_TYPE_PATH:*/
+ case EPS_PRNERR_SERVICEREQ:
+ case EPS_PRNERR_CARDLOADING:
+ case EPS_PRNERR_BATTERYVOLTAGE:
+ case EPS_PRNERR_BATTERYTEMPERATURE:
+ case EPS_PRNERR_BATTERYEMPTY:
+ case EPS_PRNERR_COMM:
+ status->jobContinue = FALSE;
+ break;
+
+ case EPS_PRNERR_BUSY:
+ if(EPS_PRNST_CANCELLING == status->printerStatus){
+ /* When last time page printing.
+ It's state EPS_PRNST_CANCELLING & EPS_PRNERR_BUSY.*/
+ status->jobContinue = TRUE;
+ } else{
+ status->jobContinue = FALSE;
+ }
+ break;
+ }
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsGetInkInfo() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* status EPS_STATUS* Pointer to the printer status. */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
+/* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
+/* EPS_ERR_INV_ARG_INKINFO - Invalid argument */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Gets the Ink Infomation. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsGetInkInfo (
+
+ EPS_INK_INFO *info
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+
+ EPS_LOG_FUNCIN;
+
+/*** Has a target printer specified */
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
+ }
+
+/*** Validate input parameters */
+ if (info == NULL){
+ EPS_RETURN( EPS_ERR_INV_ARG_INKINFO );
+ }
+
+ memset(info, 0, sizeof(EPS_INK_INFO));
+
+/*** protocol GetStatus */
+ ret = prtGetInkInfo(printJob.printer, info);
+
+/*** Return to Caller */
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsGetSupportedMedia() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* supportedMedia EPS_SUPPORTED_MEDIA* Pointer to Supported Media Structure */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
+/* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
+/* EPS_ERR_INV_ARG_SUPPORTED_MEDIA - Invalid argument */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPS_ERR_NOT_CLOSE_IO - Cannot Close I/O Portal */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Get supported media information from printer and save those data in */
+/* "g_supportedMedia" structure. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsGetSupportedMedia (
+
+ EPS_SUPPORTED_MEDIA* supportedMedia
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus, retGetPM; /* Return status of internal calls */
+ EPS_UINT8 pmString[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
+ EPS_INT32 pmSize = EPS_PM_MAXSIZE;
+
+ EPS_PRINTER_INN* innerPrinter = NULL;
+
+ EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ retStatus = retGetPM = EPS_ERR_NONE;
+
+/*** Validate communication mode */
+ if( !EPS_IS_BI_PROTOCOL(printJob.commMode) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+/*** Has a target printer specified */
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
+ }
+ innerPrinter = printJob.printer;
+
+ if( !EPS_IS_BI_PROTOCOL(innerPrinter->protocol) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+/*** Validate input parameters */
+ if (supportedMedia == NULL){
+ EPS_RETURN( EPS_ERR_INV_ARG_SUPPORTED_MEDIA );
+ }
+
+#if !_VALIDATE_SUPPORTED_MEDIA_DATA_
+/*** If already exist, return current value */
+ if(innerPrinter->supportedMedia.numSizes > 0
+ && NULL != innerPrinter->supportedMedia.sizeList){
+ EPS_RETURN( DuplSupportedMedia(innerPrinter, supportedMedia) );
+ }
+#endif
+
+ /* Clear the prev value */
+ prtClearSupportedMedia(innerPrinter);
+
+ /* Clear the Printer Model Information (Media data or "PM" data) */
+ memset(pmString,0,EPS_PM_MAXSIZE);
+
+ /*** Get PM from Printer */
+ retStatus = prtGetPMString(innerPrinter, 1, pmString, &pmSize);
+
+ /*** ESC/Page divergence ***/
+ if(EPS_LANG_ESCPR != innerPrinter->language ){
+#ifdef GCOMSW_CMD_ESCPAGE
+ if( EPS_ERR_NONE == retStatus ) {
+ /*** Create Media Infomation */
+ retStatus = pageCreateMediaInfo(innerPrinter, pmString, pmSize);
+ }
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+
+ } else {
+ if ( EPS_ERR_NONE == retStatus ){
+ /*** Create Media Infomation */
+ retStatus = CreateMediaInfo(innerPrinter, pmString, pmSize);
+ }
+ }
+
+/*** Copy the supproted media information from "printer" structure to input buffer */
+ if ( EPS_ERR_NONE == retStatus ){
+ /* Copy to input buffer */
+ retStatus = DuplSupportedMedia(innerPrinter, supportedMedia);
+ }
+/*** Return to Caller */
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsGetPrintableArea() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* jobAttr const EPS_JOB_ATTRIB* I: Print Job Attribute */
+/* printableWidth EPS_INT32* O: Printable area width. */
+/* printableHeight EPS_INT32* O: Printable area height. */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
+/* EPS_ERR_INV_ARG_JBO_ATTRIB - Invalid argument "jobAttr" */
+/* EPS_ERR_INV_ARG_PRINTABLE_WIDTH - Invalid argument "printableWidth" */
+/* EPS_ERR_INV_ARG_PRINTABLE_HEIGHT - Invalid argument "printableHeight" */
+/* EPS_ERR_INV_MEDIA_SIZE - Invalid Media Size */
+/* EPS_ERR_INV_BORDER_MODE - Invalid Border Mode */
+/* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
+/* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
+/* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
+/* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
+/* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* */
+/* Description: */
+/* Gets the printable area of the image. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsGetPrintableArea (
+
+ EPS_JOB_ATTRIB* jobAttr,
+ EPS_UINT32* printableWidth,
+ EPS_UINT32* printableHeight
+
+){
+
+/*** Declare Variable Local to Routine */
+EPS_INT32 idx; /* General loop/index varaible */
+EPS_ERR_CODE retStatus; /* Return status of internal calls */
+EPS_INT32 factor; /* Scaling factor for dpi */
+EPS_INT32 tempPrintableWidth;
+EPS_INT32 tempPrintableHeight;
+const EPS_MEDIA_INFO* pMI = NULL;
+EPS_INT16 minCustomBorder;
+
+EPS_LOG_FUNCIN;
+
+/*** Has a Lib been initialized */
+ if (libStatus != EPS_STATUS_INITIALIZED) {
+ EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
+ }
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
+ }
+
+/*** Validate input parameters */
+ if (jobAttr == NULL)
+ EPS_RETURN( EPS_ERR_INV_ARG_JOB_ATTRIB );
+
+ if (printableWidth == NULL)
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTABLE_WIDTH );
+
+ if (printableHeight == NULL)
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTABLE_HEIGHT );
+
+ /*** ESC/Page divergence ***/
+ if( EPS_LANG_ESCPR != printJob.printer->language ){
+#ifdef GCOMSW_CMD_ESCPAGE
+ retStatus = pageGetPrintableArea(jobAttr, printableWidth, printableHeight);
+#else
+ retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
+#endif
+ EPS_RETURN( retStatus );
+ }
+
+/*** Initialize Local Variables */
+ retStatus = EPS_ERR_NONE;
+
+/*** Validate/Confirm Page Attribute Data */
+ /*** Media Size */
+ if (! ( ( (jobAttr->mediaSizeIdx >= EPS_MSID_A4 ) &&
+ (jobAttr->mediaSizeIdx <= EPS_MSID_HIVISION ) ) ||
+ ( (jobAttr->mediaSizeIdx >= EPS_MSID_A3NOBI ) &&
+ (jobAttr->mediaSizeIdx <= EPS_MSID_12X12 ) ) ||
+ ( (jobAttr->mediaSizeIdx == EPS_MSID_USER ) ) ) )
+ EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE );
+
+#if 0 /* These parameter are not used in this function */
+ /*** Media Type */
+ if (! ( ( (jobAttr->mediaTypeIdx >= EPS_MTID_PLAIN ) &&
+/* (jobAttr->mediaTypeIdx <= EPS_MTID_GLOSSYHAGAKI ) ) ||*/
+ (jobAttr->mediaTypeIdx <= EPS_MTID_BUSINESSCOAT ) ) ||
+ ( (jobAttr->mediaTypeIdx >= EPS_MTID_CDDVD ) &&
+ (jobAttr->mediaTypeIdx <= EPS_MTID_CDDVDGLOSSY ) ) ||
+ ( (jobAttr->mediaTypeIdx == EPS_MTID_CLEANING ) ) ) )
+ EPS_RETURN( EPS_ERR_INV_MEDIA_TYPE );
+#endif
+
+ /*** Border Mode */
+ if (! ( (jobAttr->printLayout == EPS_MLID_BORDERLESS ) ||
+ (jobAttr->printLayout == EPS_MLID_BORDERS ) ||
+ (jobAttr->printLayout == EPS_MLID_CDLABEL ) ||
+ (jobAttr->printLayout == EPS_MLID_DIVIDE16 ) ||
+ (jobAttr->printLayout == EPS_MLID_CUSTOM ) ) )
+ EPS_RETURN( EPS_ERR_INV_BORDER_MODE );
+
+#if 0 /* These parameter are not used in this function */
+ /*** Print Quality */
+ if (! ( (jobAttr->printQuality == EPS_MQID_DRAFT ) ||
+ (jobAttr->printQuality == EPS_MQID_NORMAL ) ||
+ (jobAttr->printQuality == EPS_MQID_HIGH ) ) )
+ EPS_RETURN( EPS_ERR_INV_PRINT_QUALITY );
+
+ /*** Color Mode */
+ if (! ( (jobAttr->colorMode == EPS_CM_COLOR ) ||
+ (jobAttr->colorMode == EPS_CM_MONOCHROME ) ) )
+ EPS_RETURN( EPS_ERR_INV_COLOR_MODE );
+#endif
+
+ /*** Input Image Resolution */
+ /*** Select table and factor */
+ if(jobAttr->inputResolution == EPS_IR_360X360){
+ pMI = epsMediaSize;
+ factor = 1;
+ minCustomBorder = EPS_BORDERS_MARGIN_360;
+ } else if(jobAttr->inputResolution == EPS_IR_720X720){
+ pMI = epsMediaSize;
+ factor = 2;
+ minCustomBorder = EPS_BORDERS_MARGIN_360;
+ } else if(jobAttr->inputResolution == EPS_IR_300X300){
+ pMI = epsMediaSize300;
+ factor = 1;
+ minCustomBorder = EPS_BORDERS_MARGIN_300;
+ } else if(jobAttr->inputResolution == EPS_IR_600X600){
+ pMI = epsMediaSize300;
+ factor = 2;
+ minCustomBorder = EPS_BORDERS_MARGIN_300;
+ } else{
+ EPS_RETURN( EPS_ERR_INV_INPUT_RESOLUTION )
+ }
+
+#if 0 /* These parameter are not used in this function */
+ /*** Printing Direction */
+ if (! ( (jobAttr->printDirection == EPS_PD_BIDIREC ) ||
+ (jobAttr->printDirection == EPS_PD_UNIDIREC ) ) )
+ EPS_RETURN( EPS_ERR_INV_PRINT_DIRECTION );
+
+ /*** Color Plane */
+ if (! ( (jobAttr->colorPlane == EPS_CP_FULLCOLOR ) ||
+ (jobAttr->colorPlane == EPS_CP_256COLOR ) ) )
+ EPS_RETURN( EPS_ERR_INV_COLOR_PLANE );
+
+ /*** Pallette Data */
+ if (jobAttr->colorPlane == EPS_CP_256COLOR) {
+ if (! ((jobAttr->paletteSize >= 3 ) &&
+ (jobAttr->paletteSize <= 768/*765*/ ) ) )
+ EPS_RETURN( EPS_ERR_INV_PALETTE_SIZE );
+ if ( jobAttr->paletteData == NULL )
+ EPS_RETURN( EPS_ERR_INV_PALETTE_DATA );
+ }
+
+ /*** Brightness */
+ if (! ( (jobAttr->brightness >= -50 ) &&
+ (jobAttr->brightness <= 50 ) ) )
+ EPS_RETURN( EPS_ERR_INV_BRIGHTNESS );
+
+ /*** Contrast */
+ if (! ( (jobAttr->contrast >= -50 ) &&
+ (jobAttr->contrast <= 50 ) ) )
+ EPS_RETURN( EPS_ERR_INV_CONTRAST );
+
+ /*** Saturation */
+ if (! ( (jobAttr->saturation >= -50 ) &&
+ (jobAttr->saturation <= 50 ) ) )
+ EPS_RETURN( EPS_ERR_INV_SATURATION );
+#endif
+
+ /*** Margin */
+ if (jobAttr->printLayout == EPS_MLID_CUSTOM) {
+ if (jobAttr->topMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_TOP_MARGIN );
+ if (jobAttr->leftMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_LEFT_MARGIN );
+ if (jobAttr->bottomMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_BOTTOM_MARGIN );
+ if (jobAttr->rightMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_RIGHT_MARGIN );
+ }
+
+#if 0 /* Don't need this logic */
+ /*** If full-color mode, nullify the 256-color parameters */
+ printJob.bpp = 1;
+ if (jobAttr->colorPlane == EPS_CP_FULLCOLOR) {
+ jobAttr->paletteSize = 0;
+ jobAttr->paletteData = NULL;
+ printJob.bpp = 3;
+ }
+#endif
+
+/*** Get Printable Area */
+ /*** Find the Media by ID */
+ for (idx = 0; pMI[idx].id != -1; idx++) {
+ if (pMI[idx].id == jobAttr->mediaSizeIdx)
+ break;
+ }
+ if (pMI[idx].id == -1) {
+ EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE );
+ }
+
+ /*** Initialize Printable based on printLayout */
+ switch( jobAttr->printLayout ){
+ case EPS_MLID_BORDERLESS:
+ tempPrintableWidth = pMI[idx].print_area_x_borderless * factor;
+ tempPrintableHeight = pMI[idx].print_area_y_borderless * factor;
+ break;
+
+ case EPS_MLID_BORDERS:
+ case EPS_MLID_DIVIDE16: /* layout processing is not done. */
+ tempPrintableWidth = pMI[idx].print_area_x_border * factor;
+ tempPrintableHeight = pMI[idx].print_area_y_border * factor;
+ break;
+
+ case EPS_MLID_CDLABEL:
+ if( !( (jobAttr->cdDimOut >= EPS_CDDIM_IN_MIN )
+ && (jobAttr->cdDimOut <= EPS_CDDIM_OUT_MAX ) ) ){
+ EPS_RETURN( EPS_ERR_INV_CD_OUTDIM );
+ }
+
+ tempPrintableWidth =
+ tempPrintableHeight = elGetDots(jobAttr->inputResolution, jobAttr->cdDimOut);
+ break;
+
+ default: /* printLayout == EPS_MLID_CUSTOM */
+ tempPrintableWidth = pMI[idx].paper_x *factor -
+ jobAttr->leftMargin -
+ jobAttr->rightMargin;
+ tempPrintableHeight = pMI[idx].paper_y *factor -
+ jobAttr->topMargin -
+ jobAttr->bottomMargin;
+ }
+
+/*** Validate/Confirm Magin Setting */
+ if (jobAttr->printLayout == EPS_MLID_CUSTOM) {
+ if (tempPrintableWidth <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH );
+ if (tempPrintableHeight <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT );
+ }
+
+/*** Set Printable Area to input parameter */
+ if ((tempPrintableWidth > 0) && (tempPrintableHeight > 0)) {
+ *printableWidth = (EPS_UINT32)tempPrintableWidth;
+ *printableHeight = (EPS_UINT32)tempPrintableHeight;
+ } else{
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: epsMakeMainteCmd() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* cmd EPS_INT32 I:maintenance command type. */
+/* buffer EPS_UINT8* I:pointer to command buffer. */
+/* buffersize EPS_UINT32* I: buffer size. */
+/* O: need size. */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
+/* EPS_ERR_INV_ARG_CMDTYPE - Invalid argument "cmd" */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
+/* EPS_ERR_LANGUAGE_NOT_SUPPORTED - Unsupported function Error (language) */
+/* */
+/* Description: */
+/* Make maintenance command. */
+/* Call this function as specifying NULL to buffer, so that the memory size */
+/* necessary for executing the maintenance command is returned to buffersize. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE epsMakeMainteCmd (
+
+ EPS_INT32 cmd,
+ EPS_UINT8* buffer,
+ EPS_UINT32* buffersize
+
+){
+#ifdef GCOMSW_EF_MAINTE
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_UINT8 *pCmdBuf = NULL;
+ EPS_UINT8 *pCmdPos = NULL;
+ EPS_UINT32 cmdSize = 0;
+ EPS_UINT32 cmdBufSize = 0;
+
+ EPS_LOG_FUNCIN;
+
+/*** Has a target printer specified */
+ if(NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
+ }
+
+ if(EPS_LANG_ESCPR != printJob.printer->language ){
+ EPS_RETURN( EPS_ERR_LANGUAGE_NOT_SUPPORTED );
+ }
+
+
+ if(buffer){
+ cmdBufSize = 256;
+ pCmdBuf = (EPS_UINT8*)EPS_ALLOC(cmdBufSize);
+ pCmdPos = pCmdBuf;
+ }
+
+#define MakeMainteCmd_ADDCMD(CMD) { \
+ if(buffer){ \
+ retStatus = AddCmdBuff(&pCmdBuf, &pCmdPos, &cmdBufSize, CMD, sizeof(CMD)); \
+ if(EPS_ERR_NONE != retStatus){ \
+ goto epsMakeMainteCmd_END; \
+ } \
+ } \
+ cmdSize += sizeof(CMD); \
+ }
+
+ switch(cmd){
+ case EPS_MNT_NOZZLE: /* nozzle check */
+ MakeMainteCmd_ADDCMD(ExitPacketMode)
+ MakeMainteCmd_ADDCMD(InitPrinter)
+ MakeMainteCmd_ADDCMD(InitPrinter)
+
+ MakeMainteCmd_ADDCMD(EnterRemoteMode)
+ if(epsCmnFnc.getLocalTime){
+ MakeMainteCmd_ADDCMD(RemoteTI)
+ if( buffer ){
+ MakeRemoteTICmd(pCmdPos - sizeof(RemoteTI));
+ }
+ }
+ MakeMainteCmd_ADDCMD(RemoteJS)
+ MakeMainteCmd_ADDCMD(RemoteNC)
+ if(pCmdPos && obsIsA3Model(EPS_MDC_NOZZLE)){
+ *(pCmdPos - sizeof(RemoteNC) + 5) = 0x10;
+ }
+ MakeMainteCmd_ADDCMD(ExitRemoteMode)
+
+ MakeMainteCmd_ADDCMD(DataCR)
+ MakeMainteCmd_ADDCMD(DataLF)
+ MakeMainteCmd_ADDCMD(DataCR)
+ MakeMainteCmd_ADDCMD(DataLF)
+
+ MakeMainteCmd_ADDCMD(EnterRemoteMode)
+ MakeMainteCmd_ADDCMD(RemoteVI)
+ MakeMainteCmd_ADDCMD(RemoteLD)
+ MakeMainteCmd_ADDCMD(ExitRemoteMode)
+
+ MakeMainteCmd_ADDCMD(DataFF)
+ MakeMainteCmd_ADDCMD(InitPrinter)
+ MakeMainteCmd_ADDCMD(InitPrinter)
+
+ MakeMainteCmd_ADDCMD(EnterRemoteMode)
+ MakeMainteCmd_ADDCMD(RemoteJE)
+ MakeMainteCmd_ADDCMD(ExitRemoteMode)
+ break;
+
+ case EPS_MNT_CLEANING: /* head cleaning */
+ MakeMainteCmd_ADDCMD(ExitPacketMode)
+ MakeMainteCmd_ADDCMD(InitPrinter)
+ MakeMainteCmd_ADDCMD(InitPrinter)
+
+ MakeMainteCmd_ADDCMD(EnterRemoteMode)
+ if(epsCmnFnc.getLocalTime){
+ MakeMainteCmd_ADDCMD(RemoteTI)
+ if( buffer ){
+ MakeRemoteTICmd(pCmdPos - sizeof(RemoteTI));
+ }
+ }
+ MakeMainteCmd_ADDCMD(RemoteCH)
+ MakeMainteCmd_ADDCMD(ExitRemoteMode)
+
+ MakeMainteCmd_ADDCMD(InitPrinter)
+ MakeMainteCmd_ADDCMD(InitPrinter)
+
+ MakeMainteCmd_ADDCMD(EnterRemoteMode)
+ MakeMainteCmd_ADDCMD(RemoteJE)
+ MakeMainteCmd_ADDCMD(ExitRemoteMode)
+ break;
+
+ default:
+ retStatus = EPS_ERR_INV_CMDTYPE;
+ break;
+ }
+
+epsMakeMainteCmd_END:
+ if(EPS_ERR_NONE == retStatus){
+ if( buffer ){
+ if(*buffersize > 0){
+ memcpy(buffer, pCmdBuf, Min(*buffersize, cmdSize));
+ }
+ }
+ *buffersize = cmdSize;
+ }
+ EPS_SAFE_RELEASE(pCmdBuf);
+
+ EPS_RETURN( retStatus );
+#else
+ return EPS_ERR_INVALID_CALL;
+#endif
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Internal Processing ---------------------*/
+/*-------------------- for ---------------------*/
+/*-------------------- API ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: MonitorStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pStInfo EPS_STATUS_INFO I: pointer to status info strucutre */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Printer settled into one of the requested state(s) */
+/* EPS_JOB_CANCELED - Cancelled operation */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Monitor the status of the printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE MonitorStatus (
+
+ EPS_STATUS_INFO *pStInfo
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_INT32 retStatus;
+ EPS_STATUS_INFO StatInfo;
+
+ EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ retStatus = EPS_ERR_NONE;
+ memset(&StatInfo, -1, sizeof(EPS_STATUS_INFO));
+
+ retStatus = jobFnc.MonitorStatus(&StatInfo);
+ if ( retStatus != EPS_ERR_NONE) {
+ if(EPS_ERR_COMM_ERROR == retStatus &&
+ EPS_STATUS_NOT_INITIALIZED != printJob.jobStatus){
+ printJob.bComm = FALSE;
+ }
+
+ EPS_DBGPRINT(("EPS SER: STAT MON -> Status Retr Failed. [%d]\r\n", retStatus));
+ EPS_RETURN( retStatus );
+ }
+ if( pStInfo ){
+ memcpy(pStInfo, &StatInfo, sizeof(EPS_STATUS_INFO));
+ }
+
+ if(EPS_ST_ERROR == StatInfo.nState && EPS_PRNERR_PAPERJAM == StatInfo.nError){
+ printJob.transmittable = FALSE;
+ }
+
+ if(StatInfo.nCancel == EPS_CAREQ_CANCEL) {
+ EPS_DBGPRINT(("EPS SER : CANCEL REQUEST by PRINTER\r\n"));
+ printJob.resetReq = TRUE;
+ EPS_RETURN( EPS_JOB_CANCELED );
+ }
+
+/* EPS_DBGPRINT(("M State\t: %d\n Error\t: %d\n Prepare\t: %d\n",
+ StatInfo.nState, StatInfo.nError, StatInfo.nPrepare))
+*/
+ /* The error occurs in printer. */
+ printJob.contData.lastError = StatInfo.nError;
+
+ /*EPS_DBGPRINT(("EPS SER: STAT MON -> Printer State [0x%x]\r\n",StatInfo.nState));*/
+ if( StatInfo.nState & ( EPS_ST_IDLE |
+ EPS_ST_WAITING |
+ EPS_ST_SELF_PRINTING |
+ EPS_ST_CLEANING ) ){
+ /*EPS_DBGPRINT(("EPS SER: STAT MON -> SETTLING\r\n"));*/
+ EPS_RETURN( EPS_ERR_NONE );
+ }else{
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
+ }
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: PrintBand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* data EPS_UINT8* I: Pointer to image [RGB] data */
+/* widthPixels EPS_UINT32 I: The width of the raster band (in pixels) */
+/* heightPixels EPS_UINT32* I/O: In : Height of image (image lines) (in pixels)*/
+/* : Out: Sent Height */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* EPS_OUT_OF_BOUNDS - Print band is in out of printable area */
+/* << Error >> */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* EPS_ERR_INV_ARG_WIDTH_PIXELS - Invalid argument "widthPixels" */
+/* EPS_ERR_INV_ARG_HEIGHT_PIXELS - Invalid argument "heightPixels" */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Prints a band of raster data. */
+/* It must be noted that this function automatically positions the raster bands; */
+/* all subsequent raster bands after the first one are positioned directly */
+/* underneath the preceding band. */
+/* Horizontal orientation of the raster bands never changes. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE PrintBand (
+
+ const EPS_UINT8* data, /* Pointer to image [RGB] data */
+ EPS_UINT32 widthPixels, /* Width of image [ in pixels ] */
+ EPS_UINT32 *heightPixels /* Height of image (image lines) */
+
+) {
+
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus;
+EPS_UINT32 idx = 0; /* Generl loop/index variable */
+EPS_IMAGE line; /* Single line of image data */
+const EPS_UINT8* tmpImageData; /* Temporary image pointer */
+EPS_BOOL skipLine; /* Flag to skip or print current image line */
+EPS_UINT32 linePixels;
+EPS_UINT32 sendHeight;
+
+ EPS_LOG_FUNCIN;
+
+ if( NULL == data ){
+ EPS_RETURN( EPS_ERR_INV_ARG_DATA );
+ }
+ if(NULL == heightPixels){
+ EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
+ }
+ if(*heightPixels == 0){
+ EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
+ }
+ sendHeight = *heightPixels;
+ *heightPixels = 0;
+
+ if( widthPixels == 0 ){
+ EPS_RETURN( EPS_ERR_INV_ARG_WIDTH_PIXELS );
+ }
+
+/*** Initialize Local Variables */
+ retStatus = EPS_ERR_NONE;
+
+ if( printJob.printableAreaHeight <= (EPS_UINT32)printJob.verticalOffset ){
+ /*** Return to Caller */
+ EPS_RETURN( EPS_OUT_OF_BOUNDS );
+ }
+
+/*** Clip number is image lines if too many */
+ if (sendHeight > (printJob.printableAreaHeight - printJob.verticalOffset)){
+ sendHeight = printJob.printableAreaHeight - printJob.verticalOffset;
+ }
+
+/*** Send leftovers of last time And Skip first line of input data */
+ idx = 0; /* Initialize line counter */
+
+ /*** Send leftovers data */
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){ /* It was unnecessary */
+ retStatus = EPS_ERR_NONE;
+ if(printJob.contData.skipLine == TRUE){
+ idx++; /* skip first line of input data */
+ printJob.contData.skipLine = FALSE;
+ }
+ } else if(EPS_ERR_NONE == retStatus){ /* Sent leftovers */
+ idx++; /* skip first line of input data */
+ } else{
+ EPS_RETURN( retStatus );
+ }
+
+/*** The following section of code forces the core module to skip raster lines that are */
+/*** completely white in order to minimize data size. This function is compatible with */
+/*** 8-bit palettized and 24-bit RGB bitmaps. */
+/*** ---------------------------------------------------------------------------------- */
+
+ /*** Initialize variable */
+ line.bytesPerLine = printJob.bpp * widthPixels;
+ linePixels = Min(line.bytesPerLine, printJob.bpp * printJob.printableAreaWidth);
+
+ for (; idx < sendHeight; idx++) {
+ /* Calculate position of image line */
+ //if(idx == 1){
+ //idx = sendHeight;
+ //break;
+ //}
+ line.data = data + idx * line.bytesPerLine;
+
+ /*** Make new LineRect */
+ line.rect.top = (EPS_INT32)(printJob.verticalOffset + idx);
+ line.rect.left = 0;
+ line.rect.bottom = line.rect.top + 1;
+ line.rect.right = (EPS_INT32)(widthPixels);
+
+ /*** Test if current image data is completely white */
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+ skipLine = TRUE;
+ } else{
+ skipLine = FALSE; /* esc/page need anything band */
+ }
+
+ /* skip blank band for ESC/P-R */
+ /* check blank page for duplex */
+ if( EPS_LANG_ESCPR == printJob.printer->language ||
+ (EPS_DUPLEX_NONE != printJob.attr.duplex && printJob.needBand) )
+ {
+ for (tmpImageData = line.data;
+ tmpImageData < (line.data + linePixels);
+ tmpImageData++ ) {
+ if(*tmpImageData != printJob.whiteColorValue) {
+ skipLine = FALSE;
+ printJob.needBand = FALSE;
+ break;
+ }
+ }
+
+ if (skipLine == TRUE)continue;
+ }
+ /*** Image Data not completely white - print image data */
+ //idx = sendHeight;
+ //break;
+ retStatus = PrintLine(&line);
+
+ if (retStatus != EPS_ERR_NONE) {
+ break;
+ }
+ }
+
+/*** band positioning adds */
+ printJob.verticalOffset += idx;
+
+/*** Return to Caller */
+ *heightPixels = idx;
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: PrintChunk() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* data EPS_UINT8* I: Pointer to image [RGB] data */
+/* dataSize EPS_UINT32* I/O: In : size of image */
+/* : Out: Sent size */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* EPS_OUT_OF_BOUNDS - Print band is in out of printable area */
+/* << Error >> */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* EPS_ERR_INV_ARG_HEIGHT_PIXELS - Invalid argument "heightPixels" */
+/* EPS_ERR_INV_ARG_DATASIZE - data size limit */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Prints Jpeg file data. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE PrintChunk (
+
+ const EPS_UINT8* data, /* Pointer to image [JPEG] data */
+ EPS_UINT32* dataSize /* size of image (chunked data) */
+
+) {
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus = EPS_ERR_NONE;
+EPS_UINT32 sendSize = 0;
+EPS_UINT32 retBufSize = 0;
+EPS_INT32 cmdBuffSize = ESCPR_HEADER_LENGTH + ESCPR_SEND_JPGDATA_LENGTH;
+EPS_UINT8* bufPtr = NULL; /* Temporary buffer pointer */
+EPS_INT32 paramSize = 0; /* Size of command parameters only */
+
+EPS_INT32 i = 0;
+#define DUMMY_DATA_COUNT (1000)
+
+ EPS_LOG_FUNCIN;
+
+/*** Validate input parameters */
+ if(NULL == dataSize){
+ EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
+ }
+#if LCOMSW_DUMMY_SEND
+ if( *dataSize == 0 &&
+ (EPS_PROTOCOL_USB & printJob.printer->protocol) ){
+ /* USB not peform */
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+#else
+ if( NULL == data ){
+ EPS_RETURN( EPS_ERR_INV_ARG_DATA );
+ }
+ if(*dataSize == 0){
+ EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
+ }
+#endif
+
+ sendSize = *dataSize;
+ *dataSize = 0;
+
+#if !_VALIDATE_SUPPORTED_MEDIA_DATA_
+ if( EPS_JPEG_CHUNK_SIZE_MAX < sendSize){
+ *dataSize = 0;
+ EPS_RETURN( EPS_ERR_INV_ARG_DATASIZE );
+ }
+
+ if( (EPS_UINT32)printJob.printer->JpgMax < printJob.jpegSize + sendSize){
+ printJob.bJpgLimit = TRUE;
+ EPS_RETURN( EPS_ERR_INV_ARG_DATASIZE );
+ }
+#endif
+
+ /************************************************************************************/
+ /*** Send last time leftovers data */
+
+ /*** Header */
+ retStatus = SendLeftovers();
+ if(EPS_ERR_INVALID_CALL == retStatus){ /* It was unnecessary */
+ retStatus = EPS_ERR_NONE;
+ } else if(EPS_ERR_NONE != retStatus){
+ *dataSize = 0;
+ EPS_RETURN( retStatus );
+ }
+
+ /*** Data */
+ if(0 < printJob.contData.jpgSize){
+ retBufSize = 0;
+ retStatus = SendCommand(data,
+ Min(printJob.contData.jpgSize, sendSize),
+ &retBufSize, FALSE); /* not save Leftovers */
+ printJob.contData.jpgSize -= retBufSize;
+ *dataSize = retBufSize;
+ printJob.jpegSize += retBufSize; /* add total size */
+ if( EPS_ERR_NONE != retStatus ){
+ EPS_RETURN( retStatus );
+ }
+
+ sendSize -= retBufSize;
+ if(0 >= sendSize ){
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+ data += retBufSize;
+ }
+
+ /************************************************************************************/
+ /*** Send this time data */
+
+ /*** Header */
+ printJob.contData.jpgSize = sendSize;
+
+#if !LCOMSW_DUMMY_SEND
+ EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, ESCPR_JPGHEAD_LENGTH )
+#else
+ if(0 < sendSize){
+ EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, ESCPR_JPGHEAD_LENGTH )
+ } else{
+ EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, ESCPR_JPGHEAD_LENGTH * DUMMY_DATA_COUNT )
+ }
+#endif
+ if(NULL == sendDataBuf){
+ sendDataBufSize = 0;
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ bufPtr = sendDataBuf;
+ memcpy(bufPtr, SendDataCmd, sizeof(SendDataCmd));
+ bufPtr += sizeof(SendDataCmd);
+
+ paramSize = ESCPR_SEND_JPGDATA_LENGTH + sendSize;
+ memSetEndian(EPS_ENDIAN_LITTLE, EPS_4_BYTES, (EPS_UINT32)paramSize, bufPtr);
+ bufPtr += 4;
+ memcpy(bufPtr, SendJpegDataName, sizeof(SendJpegDataName));
+ bufPtr += sizeof(SendJpegDataName);
+
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, sendSize, bufPtr);
+
+ if(0 < sendSize){
+ retBufSize = 0;
+ retStatus = SendCommand(sendDataBuf, cmdBuffSize, &retBufSize, TRUE);/* save Leftovers */
+ if( EPS_ERR_NONE != retStatus ){
+ EPS_RETURN( retStatus );
+ }
+
+ /*** Data */
+ retBufSize = 0;
+ retStatus = SendCommand(data, sendSize, &retBufSize, FALSE); /* NOT save Leftovers */
+
+ *dataSize += retBufSize;
+ printJob.contData.jpgSize -= retBufSize;
+
+ printJob.jpegSize += retBufSize; /* add total size */
+ } else {
+ /*** dummy data */
+ bufPtr = sendDataBuf + cmdBuffSize;
+ for(i=1; i < DUMMY_DATA_COUNT; i++){ /* 12x1000 byte */
+ memcpy(bufPtr, sendDataBuf, cmdBuffSize);
+ bufPtr += cmdBuffSize;
+ }
+
+ retStatus = SendCommand(sendDataBuf, ESCPR_JPGHEAD_LENGTH * DUMMY_DATA_COUNT, &retBufSize, TRUE);/* save Leftovers */
+ }
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SendLeftovers() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nStartStep EPS_INT32 I: Step of Start Page comannds */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_INVALID_CALL - This call was unnecessary */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* << Error >> */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* send leftovers data. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE SendLeftovers (
+
+ void
+
+){
+EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+EPS_UINT32 retBufSize = 0;
+
+ EPS_LOG_FUNCIN;
+
+/*** send leftovers */
+#ifdef GCOMSW_CMD_ESCPAGE
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+#endif
+ /*** ESC/P-R ***/
+ if( NULL != printJob.contData.sendData && 0 < printJob.contData.sendDataSize){
+ retStatus = SendCommand(printJob.contData.sendData,
+ printJob.contData.sendDataSize, &retBufSize, TRUE);
+ } else{
+ retStatus = EPS_ERR_INVALID_CALL;
+ }
+#ifdef GCOMSW_CMD_ESCPAGE
+ } else{
+ /*** ESC/Page ***/
+ retStatus = pageSendLeftovers();
+ }
+#endif
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SendBlankBand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nStartStep EPS_INT32 I: Step of Start Page comannds */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* << Error >> */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* send leftovers data. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE SendBlankBand (
+
+ void
+
+){
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_UINT8 pix[3*16]; /* 16=ESC/Page24 minimum unit */
+ EPS_IMAGE line;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(EPS_LANG_ESCPAGE_S == printJob.printer->language){
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+#endif
+
+ if(EPS_CP_FULLCOLOR == printJob.attr.colorPlane){
+ memset(pix, 0xFF, sizeof(pix)); /* white */
+ if(EPS_LANG_ESCPAGE == printJob.printer->language ||
+ EPS_LANG_ESCPAGE_COLOR == printJob.printer->language)
+ {
+ memset(pix, 0x00, 3); /* black dot */
+ }
+ } else{
+ memset(pix, printJob.whiteColorValue, sizeof(pix));
+ if(EPS_LANG_ESCPAGE == printJob.printer->language ||
+ EPS_LANG_ESCPAGE_COLOR == printJob.printer->language)
+ {
+ if(printJob.whiteColorValue != 0){
+ memset(pix, 0, sizeof(pix));
+ } else{
+ memset(pix, 1, sizeof(pix));
+ }
+ }
+ }
+ line.data = pix;
+ line.bytesPerLine = printJob.bpp;
+ line.rect.top = 0;
+ line.rect.left = 0;
+ line.rect.bottom = 1;
+ if(EPS_LANG_ESCPR == printJob.printer->language ||
+ EPS_CP_256COLOR == printJob.attr.colorPlane ){
+ line.rect.right= 1;
+ } else{
+ line.rect.right= 16;
+ }
+
+ retStatus = PrintLine(&line);
+
+ EPS_RETURN( retStatus );
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SetupJobAttrib() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* jobAttr EPS_JOB_ATTRIB* I: Data structure containing job attribut settings */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_INV_COLOR_PLANE - Invalid Color Plane */
+/* EPS_ERR_INV_PALETTE_SIZE - Invalid Palette Size */
+/* EPS_ERR_INV_PALETTE_DATA - Invalid Palette Data */
+/* EPS_ERR_INV_MEDIA_SIZE - Invalid Media Size */
+/* EPS_ERR_INV_MEDIA_TYPE - Invalid Media Type */
+/* EPS_ERR_INV_BORDER_MODE - Invalid Border Mode */
+/* EPS_ERR_INV_PRINT_QUALITY - Invalid Print Quality */
+/* EPS_ERR_INV_PAPER_SOURCE - Invalid Paper source */
+/* EPS_ERR_INV_COLOR_MODE - Invalid Color Mode */
+/* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
+/* EPS_ERR_INV_PRINT_DIRECTION - Invalid Print Direction */
+/* EPS_ERR_INV_BRIGHTNESS - Invalid Brightness */
+/* EPS_ERR_INV_CONTRAST - Invalid Contrast */
+/* EPS_ERR_INV_SATURATION - Invalid Saturation */
+/* EPS_ERR_INV_APF_FLT - Invalid APF Filter */
+/* EPS_ERR_INV_APF_ACT - Invalid APF Scene */
+/* EPS_ERR_INV_APF_SHP - Invalid APF Sharpness */
+/* EPS_ERR_INV_APF_RDE - Invalid APF Redeye */
+/* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
+/* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
+/* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
+/* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
+/* */
+/* Description: */
+/* Confirm ESC/P-R Job Attribute. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE SetupJobAttrib (
+
+ const EPS_JOB_ATTRIB* jobAttr /* Print Attributes for this Page */
+
+){
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+
+EPS_LOG_FUNCIN;
+
+
+
+/*** Validate input parameters */
+#ifndef LCOMSW_JOBPARAM_CEHCK_OFF
+/*======================================================================================*/
+/*** Validate/Confirm Page Attribute Data */
+/*======================================================================================*/
+ /*** Color Plane */
+
+ if (! ( (jobAttr->colorPlane == EPS_CP_FULLCOLOR ) ||
+ (jobAttr->colorPlane == EPS_CP_256COLOR ) ||
+ (jobAttr->colorPlane == EPS_CP_JPEG ) ||
+ (jobAttr->colorPlane == EPS_CP_PRINTCMD ) ) ){
+ EPS_RETURN( EPS_ERR_INV_COLOR_PLANE )
+ }
+
+ if( EPS_CP_PRINTCMD == jobAttr->colorPlane ){ /* Print command */
+ /*** Structure version */
+ if(EPS_JOB_ATTRIB_VER_2 > jobAttr->version){
+ EPS_RETURN( EPS_ERR_INVALID_VERSION )
+ }
+
+ /*** Print command type */
+ if (! ( (jobAttr->cmdType == EPS_MNT_CUSTOM ) ||
+ (jobAttr->cmdType == EPS_MNT_CLEANING ) ||
+ (jobAttr->cmdType == EPS_MNT_NOZZLE ) ) ){
+ EPS_RETURN( EPS_ERR_INV_CMDTYPE )
+ }
+
+ } else{ /* Image(RGB, Jpeg) */
+ /*** Media Size */
+ if (! ( ( (jobAttr->mediaSizeIdx >= EPS_MSID_A4 ) &&
+ (jobAttr->mediaSizeIdx <= EPS_MSID_HIVISION ) ) ||
+ ( (jobAttr->mediaSizeIdx >= EPS_MSID_A3NOBI ) &&
+ (jobAttr->mediaSizeIdx <= EPS_MSID_12X12 ) ) ||
+ ( (jobAttr->mediaSizeIdx == EPS_MSID_USER ) ) ) ){
+ EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE )
+ }
+ /*** Media Type */
+ if (! ( ( (jobAttr->mediaTypeIdx >= EPS_MTID_PLAIN ) &&
+ /* (jobAttr->mediaTypeIdx <= EPS_MTID_GLOSSYHAGAKI ) ) ||*/
+ (jobAttr->mediaTypeIdx <= EPS_MTID_BUSINESSCOAT ) ) ||
+ ( (jobAttr->mediaTypeIdx >= EPS_MTID_CDDVD ) &&
+ (jobAttr->mediaTypeIdx <= EPS_MTID_CDDVDGLOSSY ) ) ||
+ ( (jobAttr->mediaTypeIdx == EPS_MTID_CLEANING ) ) ) ){
+ EPS_RETURN( EPS_ERR_INV_MEDIA_TYPE )
+ }
+ /*** Print Quality */
+ if (! ( (jobAttr->printQuality == EPS_MQID_DRAFT ) ||
+ (jobAttr->printQuality == EPS_MQID_NORMAL ) ||
+ (jobAttr->printQuality == EPS_MQID_HIGH ) ) ){
+ EPS_RETURN( EPS_ERR_INV_PRINT_QUALITY )
+ }
+ /*** duplex */
+ if( !( (jobAttr->duplex == EPS_DUPLEX_NONE ) ||
+ (jobAttr->duplex == EPS_DUPLEX_LONG ) ||
+ (jobAttr->duplex == EPS_DUPLEX_SHORT ) ) ){
+ EPS_RETURN( EPS_ERR_INV_DUPLEX )
+ }
+ /*** Brightness */
+ if (! ( (jobAttr->brightness >= -50 ) &&
+ (jobAttr->brightness <= 50 ) ) ){
+ EPS_RETURN( EPS_ERR_INV_BRIGHTNESS )
+ }
+ /*** Contrast */
+ if (! ( (jobAttr->contrast >= -50 ) &&
+ (jobAttr->contrast <= 50 ) ) ){
+ EPS_RETURN( EPS_ERR_INV_CONTRAST )
+ }
+ /*** Saturation */
+ if (! ( (jobAttr->saturation >= -50 ) &&
+ (jobAttr->saturation <= 50 ) ) ){
+ EPS_RETURN( EPS_ERR_INV_SATURATION )
+ }
+ /*** Paper Source */
+ if (! ( (jobAttr->paperSource == EPS_MPID_AUTO ) ||
+ (jobAttr->paperSource == EPS_MPID_REAR ) ||
+ (jobAttr->paperSource == EPS_MPID_FRONT1 ) ||
+ (jobAttr->paperSource == EPS_MPID_FRONT2 ) ||
+ (jobAttr->paperSource == EPS_MPID_FRONT3 ) ||
+ (jobAttr->paperSource == EPS_MPID_FRONT4 ) ||
+ (jobAttr->paperSource == EPS_MPID_CDTRAY ) ||
+
+ (jobAttr->paperSource == EPS_MPID_PAGE_S_MP_TRAY ) ||
+ (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE1 ) ||
+ (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE2 ) ||
+ (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE3 ) ||
+ (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE4 ) ||
+ (jobAttr->paperSource == EPS_MPID_PAGE_S_PARAM_MANUALFEED ) ||
+ (jobAttr->paperSource == EPS_MPID_PAGE_S_AUTO_TRAY )
+ ) ){
+ EPS_RETURN( EPS_ERR_INV_PAPER_SOURCE )
+ }
+
+ if(jobAttr->printLayout == EPS_MLID_CDLABEL){
+ /*** CD Inside Diameter */
+ if( !( (jobAttr->cdDimIn >= EPS_CDDIM_IN_MIN )
+ && (jobAttr->cdDimIn <= EPS_CDDIM_IN_MAX ) ) ){
+ EPS_RETURN( EPS_ERR_INV_CD_INDIM )
+ }
+ /*** CD Outside Diameter */
+ if( !( (jobAttr->cdDimOut >= EPS_CDDIM_OUT_MIN )
+ && (jobAttr->cdDimOut <= EPS_CDDIM_OUT_MAX ) ) ){
+ EPS_RETURN( EPS_ERR_INV_CD_OUTDIM )
+ }
+ }
+
+ if( EPS_CP_JPEG == jobAttr->colorPlane ){
+ if( jobAttr->duplex != EPS_DUPLEX_NONE ){
+ EPS_RETURN( EPS_ERR_INV_DUPLEX )
+ }
+ }
+ }
+#endif
+
+
+
+/*======================================================================================*/
+/*** Copy Input Page Attribute Data to Internal Variable */
+/*======================================================================================*/
+ switch( jobAttr->colorPlane ){
+ case EPS_CP_FULLCOLOR: /* RGB */
+ case EPS_CP_256COLOR:
+ memcpy((void*)(&printJob.attr), (void*)jobAttr, sizeof(EPS_JOB_ATTRIB));
+ retStatus = SetupRGBAttrib();
+ if(EPS_ERR_NONE == retStatus){
+ _SP_ChangeSpec_DraftOnly(printJob.printer, &printJob.attr);
+ /* Ignore the return value of this func */
+ }
+ break;
+
+ case EPS_CP_JPEG: /* Jpeg */
+ memcpy((void*)(&printJob.attr), (void*)jobAttr, sizeof(EPS_JOB_ATTRIB));
+ retStatus = SetupJPGAttrib();
+ if(EPS_ERR_NONE == retStatus){
+ _SP_ChangeSpec_DraftOnly(printJob.printer, &printJob.attr);
+ /* Ignore the return value of this func */
+ }
+ break;
+
+ case EPS_CP_PRINTCMD: /* Print command */
+ default:
+ memset((void*)(&printJob.attr), 0, sizeof(EPS_JOB_ATTRIB));
+ printJob.attr.colorPlane = jobAttr->colorPlane;
+ printJob.attr.cmdType = jobAttr->cmdType;
+ break;
+
+ }
+
+ EPS_RETURN( retStatus )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SetupRGBAttrib() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* jobAttr EPS_JOB_ATTRIB* I: Data structure containing page attribut settings */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_INV_COLOR_MODE - Invalid Color Mode */
+/* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
+/* EPS_ERR_INV_PRINT_DIRECTION - Invalid Print Direction */
+/* EPS_ERR_INV_PALETTE_SIZE - Invalid Palette Size */
+/* EPS_ERR_INV_PALETTE_DATA - Invalid Palette Data */
+/* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
+/* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
+/* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
+/* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
+/* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
+/* */
+/* Description: */
+/* Confirm RGB Attribute. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE SetupRGBAttrib (
+
+ void
+
+){
+/*** Declare Variable Local to Routine */
+EPS_INT32 factor; /* Scaling factor for dpi */
+EPS_INT32 idx; /* Paper size index */
+EPS_INT32 tempPrintableWidth; /* Temporary Variable */
+EPS_INT32 tempPrintableHeight; /* Temporary Variable */
+const EPS_MEDIA_INFO* pMI = NULL;
+EPS_INT16 borderPixels;
+
+ EPS_LOG_FUNCIN;
+
+/*** Initialize Global/Local Variables */
+ idx = -1;
+ tempPrintableWidth = 0;
+ tempPrintableHeight = 0;
+
+#ifndef LCOMSW_JOBPARAM_CEHCK_OFF
+/*** Validate input parameters */
+ /*** Border Mode */
+ if(! ((printJob.attr.printLayout == EPS_MLID_BORDERLESS ) ||
+ (printJob.attr.printLayout == EPS_MLID_BORDERS ) ||
+ (printJob.attr.printLayout == EPS_MLID_CDLABEL ) ||
+ (printJob.attr.printLayout == EPS_MLID_DIVIDE16 ) ||
+ (printJob.attr.printLayout == EPS_MLID_CUSTOM ) ) ){
+ EPS_RETURN( EPS_ERR_INV_BORDER_MODE )
+ }
+ /*** Color Mode */
+ if( !( (printJob.attr.colorMode == EPS_CM_COLOR ) ||
+ (printJob.attr.colorMode == EPS_CM_MONOCHROME ) /*||
+ (printJob.attr.colorMode == EPS_CM_SEPIA )*/ ) ){
+ EPS_RETURN( EPS_ERR_INV_COLOR_MODE )
+ }
+
+ /*** Input Image Resolution */
+ /*** Select table and factor */
+ if(printJob.attr.inputResolution == EPS_IR_360X360){
+ pMI = epsMediaSize;
+ factor = 1;
+ borderPixels = EPS_BORDERS_MARGIN_360;
+ } else if(printJob.attr.inputResolution == EPS_IR_720X720){
+ pMI = epsMediaSize;
+ factor = 2;
+ borderPixels = EPS_BORDERS_MARGIN_360;
+ } else if(printJob.attr.inputResolution == EPS_IR_300X300){
+ pMI = epsMediaSize300;
+ //pMI = epsMediaSize;
+ factor = 1;
+ borderPixels = EPS_BORDERS_MARGIN_300;
+ //borderPixels = EPS_BORDERS_MARGIN_360;
+ } else if(printJob.attr.inputResolution == EPS_IR_600X600){
+ pMI = epsMediaSize300;
+ factor = 2;
+ borderPixels = EPS_BORDERS_MARGIN_300;
+ } else{
+ EPS_RETURN( EPS_ERR_INV_INPUT_RESOLUTION )
+ }
+
+ /*** Printing Direction */
+ if (! ( (printJob.attr.printDirection == EPS_PD_BIDIREC ) ||
+ (printJob.attr.printDirection == EPS_PD_UNIDIREC ) ) ){
+ EPS_RETURN( EPS_ERR_INV_PRINT_DIRECTION )
+ }
+
+ /*** Pallette Data */
+ if (printJob.attr.colorPlane == EPS_CP_256COLOR) {
+ if (! ((printJob.attr.paletteSize >= 3 ) &&
+ (printJob.attr.paletteSize <= 768/*765*/ ) ) ){
+ EPS_RETURN( EPS_ERR_INV_PALETTE_SIZE )
+ }
+
+ if ( printJob.attr.paletteData == NULL ){
+ EPS_RETURN( EPS_ERR_INV_PALETTE_DATA )
+ }
+ }
+
+ /*** Margin */
+ if (printJob.attr.printLayout == EPS_MLID_CUSTOM) {
+ if (printJob.attr.topMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_TOP_MARGIN );
+ if (printJob.attr.leftMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_LEFT_MARGIN );
+ if (printJob.attr.bottomMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_BOTTOM_MARGIN );
+ if (printJob.attr.rightMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_RIGHT_MARGIN );
+ }
+#endif
+
+/*======================================================================================*/
+/*** Set the following parameter */
+/*** - printJob.topMargin */
+/*** - printJob.leftMargin */
+/*** - printJob.printableAreaWidth */
+/*** - printJob.printableAreaHeight */
+/*** - printJob.borderlessModeInternal */
+/*** - printJob.verticalOffset */
+/*======================================================================================*/
+ /*** Find the Media by ID */
+ for (idx = 0; pMI[idx].id != -1; idx++) {
+ if (pMI[idx].id == printJob.attr.mediaSizeIdx)
+ break;
+ }
+ if (pMI[idx].id == -1) {
+ EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE );
+ }
+
+ /*** Media Attributes */
+ printJob.paperWidth = pMI[idx].paper_x * factor;
+ printJob.paperHeight = pMI[idx].paper_y * factor;
+
+ /*** Initialize Printable based on border mode */
+ switch( printJob.attr.printLayout ){
+ case EPS_MLID_BORDERLESS:
+ printJob.topMargin = pMI[idx].top_margin_borderless * factor;
+ printJob.leftMargin = pMI[idx].left_margin_borderless * factor;
+ tempPrintableWidth = pMI[idx].print_area_x_borderless * factor;
+ tempPrintableHeight = pMI[idx].print_area_y_borderless * factor;
+ printJob.borderlessMode = EPS_BORDERLESS_NORMAL;
+ break;
+
+ case EPS_MLID_BORDERS:
+ case EPS_MLID_DIVIDE16:
+ printJob.topMargin = borderPixels * factor;
+ printJob.leftMargin = borderPixels * factor;
+
+ tempPrintableWidth = pMI[idx].print_area_x_border * factor;
+ tempPrintableHeight = pMI[idx].print_area_y_border * factor;
+ printJob.borderlessMode = EPS_BORDER_3MM_MARGINE;
+ break;
+
+ case EPS_MLID_CDLABEL:
+ tempPrintableWidth =
+ tempPrintableHeight = elGetDots(printJob.attr.inputResolution, printJob.attr.cdDimOut);
+ printJob.topMargin = CDDVD_OFFSET_Y(printJob.attr.inputResolution, printJob.attr.cdDimOut);
+ printJob.leftMargin = CDDVD_OFFSET_X(printJob.attr.inputResolution, printJob.attr.cdDimOut);
+ printJob.borderlessMode = EPS_BORDER_3MM_MARGINE; /* It's no meaning & no effect */
+
+ EPS_DBGPRINT(("dim: %d / top: %d / left: %d\n", printJob.attr.cdDimOut,
+ printJob.topMargin, printJob.leftMargin));
+ break;
+
+ default: /* printJob.attr.printLayout == EPS_MLID_CUSTOM */
+ printJob.topMargin = printJob.attr.topMargin;
+ printJob.leftMargin = printJob.attr.leftMargin;
+ tempPrintableWidth = pMI[idx].paper_x * factor -
+ printJob.attr.leftMargin -
+ printJob.attr.rightMargin;
+ tempPrintableHeight = pMI[idx].paper_y * factor -
+ printJob.attr.topMargin -
+ printJob.attr.bottomMargin;
+ printJob.borderlessMode = EPS_BORDER_CUSTOM;
+ }
+
+ /*** Validate/Confirm Magin Setting */
+ if (printJob.attr.printLayout == EPS_MLID_CUSTOM) {
+ if (tempPrintableWidth <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH );
+ if (tempPrintableHeight <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT );
+ }
+
+ /*** Set Printable Area */
+ EPS_INT32 lOffset = printJob.attr.inputResolution/30;
+ //printJob.printableAreaHeight = (EPS_UINT32)lWidth + lOffset*2;
+ //printJob.printableAreaWidth = (EPS_UINT32)lHeight + lOffset*2;
+
+ printJob.printableAreaWidth = (EPS_UINT32)tempPrintableWidth;
+ printJob.printableAreaHeight = (EPS_UINT32)tempPrintableHeight;
+ //printJob.printableAreaWidth = (EPS_UINT32)tempPrintableHeight;
+ //printJob.printableAreaHeight = (EPS_UINT32)tempPrintableWidth;
+ /*
+ areaWidth = tempPrintableHeight;
+ areaHeight = tempPrintableWidth;
+ EPS_INT32 lOffset = printJob.attr.inputResolution/30;
+ printJob.printableAreaHeight = (EPS_UINT32)lHeight + lOffset*2;
+ printJob.printableAreaWidth = (EPS_UINT32)lWidth + lOffset*2;
+ */
+ //printJob.printableAreaHeight = (EPS_UINT32)lHeight + lOffset*2;
+ //printJob.printableAreaWidth = (EPS_UINT32)lWidth + lOffset*2;
+
+
+ /*** Scan through palette for the index value of white and set the global white
+ value to this index for skipping white raster lines */
+ if( printJob.attr.colorPlane == EPS_CP_256COLOR ){
+ printJob.bpp = 1;
+ } else /* if(EPS_CP_FULLCOLOR) */{
+ printJob.bpp = 3;
+ printJob.attr.paletteSize = 0;
+ printJob.attr.paletteData = NULL;
+ }
+ printJob.whiteColorValue = memSearchWhiteColorVal(printJob.attr.colorPlane,
+ printJob.attr.paletteData,
+ printJob.attr.paletteSize);
+
+ /*** Set "Base Point" Data */
+ /*** BORDER */
+ printJob.border.top =
+ printJob.border.left =
+ printJob.border.bottom =
+ printJob.border.right = borderPixels * factor;
+
+ AdjustBasePoint();
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SetupJPGAttrib() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_INV_APF_FLT - Invalid APF Filter */
+/* EPS_ERR_INV_APF_ACT - Invalid APF Scene */
+/* EPS_ERR_INV_APF_SHP - Invalid APF Sharpness */
+/* EPS_ERR_INV_APF_RDE - Invalid APF Redeye */
+/* */
+/* Description: */
+/* Confirm APF Attribute. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE SetupJPGAttrib (
+
+ void
+
+){
+ EPS_LOG_FUNCIN;
+
+#ifndef LCOMSW_JOBPARAM_CEHCK_OFF
+/*** Validate input parameters */
+ /*** Border Mode */
+ if(! ((printJob.attr.printLayout == EPS_MLID_BORDERLESS ) ||
+ (printJob.attr.printLayout == EPS_MLID_BORDERS ) ||
+ (printJob.attr.printLayout == EPS_MLID_CDLABEL ) ||
+ (printJob.attr.printLayout == EPS_MLID_DIVIDE16 ) /*||
+ (printJob.attr.printLayout == EPS_MLID_CUSTOM ) */) ){
+ EPS_RETURN( EPS_ERR_INV_BORDER_MODE )
+ }
+ /*** Color Mode (APF Filter) */
+ if( !( (printJob.attr.colorMode == EPS_CM_COLOR ) ||
+ (printJob.attr.colorMode == EPS_CM_MONOCHROME ) ||
+ (printJob.attr.colorMode == EPS_CM_SEPIA ) ) ){
+ EPS_RETURN( EPS_ERR_INV_COLOR_MODE )
+ }
+
+ /*** APF Scene */
+ if( !( (printJob.attr.apfAutoCorrect == EPS_APF_ACT_NOTHING ) ||
+ (printJob.attr.apfAutoCorrect == EPS_APF_ACT_STANDARD ) ||
+ (printJob.attr.apfAutoCorrect == EPS_APF_ACT_PIM ) ||
+ (printJob.attr.apfAutoCorrect == EPS_APF_ACT_PORTRATE ) ||
+ (printJob.attr.apfAutoCorrect == EPS_APF_ACT_VIEW ) ||
+ (printJob.attr.apfAutoCorrect == EPS_APF_ACT_NIGHTVIEW) ) ){
+ EPS_RETURN( EPS_ERR_INV_APF_ACT );
+ }
+ /*** APF Sharpness */
+ if (! ((printJob.attr.sharpness >= -50 ) &&
+ (printJob.attr.sharpness <= 50 ) ) ){
+ EPS_RETURN( EPS_ERR_INV_APF_SHP );
+ }
+ /*** APF Redeye */
+ if( !( (printJob.attr.redeye == EPS_APF_RDE_NOTHING ) ||
+ (printJob.attr.redeye == EPS_APF_RDE_CORRECT ) ) ){
+ EPS_RETURN( EPS_ERR_INV_APF_RDE );
+ }
+#endif
+
+ printJob.bpp = 0;
+ printJob.attr.paletteSize = 0;
+ printJob.attr.paletteData = NULL;
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: AddCmdBuff() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBuff EPS_UINT8** IO: pointer to command buffer */
+/* pPos EPS_UINT8** IO: pointer to append position */
+/* bufSize EPS_UINT32* IO: pointer to size of command buffer(pBuff) */
+/* cmd EPS_UINT8* I : pointer to command */
+/* cmdSize EPS_UINT32 I : size of command(cmd) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Append command to buffer. If the buffer is short, expand it. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE AddCmdBuff(
+
+ EPS_UINT8 **pBuff,
+ EPS_UINT8 **pPos,
+ EPS_UINT32 *bufSize,
+ const EPS_UINT8 *cmd,
+ EPS_UINT32 cmdSize
+
+){
+ EPS_UINT32 cmdPosDist = (EPS_UINT32)(*pPos - *pBuff); /* command offset distance */
+
+ EPS_LOG_FUNCIN;
+
+ EPS_MEM_GROW(EPS_UINT8*, *pBuff, bufSize, cmdPosDist + cmdSize )
+
+ if(*pBuff != NULL){
+ *pPos = *pBuff + cmdPosDist;
+ memcpy(*pPos, cmd, cmdSize);
+ *pPos += cmdSize;
+ EPS_RETURN( EPS_ERR_NONE );
+ } else{
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SendStartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* bAddStartPage EPS_BOOL I: Append Start Page comannd */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* << Error >> */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send Start Job (&Page) commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE SendStartJob (
+
+ EPS_BOOL bAddStartPage
+
+){
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+EPS_UINT8* pCmdPos = NULL; /* Temporary buffer pointer */
+EPS_UINT32 retBufSize = 0; /* Size of buffer written */
+
+ EPS_LOG_FUNCIN;
+
+ pCmdPos = sendDataBuf;
+
+/*======================================================================================*/
+/*** Initialize Printer and Set Printer in ESC/PR mode */
+/*======================================================================================*/
+#define SendStartJob_ADDCMD_LEN(CMD, EXPLEN) { \
+ retStatus = AddCmdBuff(&sendDataBuf, &pCmdPos, &sendDataBufSize, CMD, sizeof(CMD)+EXPLEN); \
+ if(EPS_ERR_NONE != retStatus){ \
+ goto SendStartJob_END; \
+ } \
+ }
+#define SendStartJob_ADDCMD(CMD) SendStartJob_ADDCMD_LEN(CMD, 0)
+
+ /*** Exit Packet Mode */
+ SendStartJob_ADDCMD(ExitPacketMode)
+
+ /*** Initialize Printer */
+ SendStartJob_ADDCMD(InitPrinter)
+
+ /*** Enter Remote Mode */
+ SendStartJob_ADDCMD(EnterRemoteMode)
+
+ /*** Remote Command - TI */
+ if(epsCmnFnc.getLocalTime){
+ SendStartJob_ADDCMD(RemoteTI)
+ MakeRemoteTICmd(pCmdPos - sizeof(RemoteTI));
+ }
+
+ /*** Remote Command - JS */
+ SendStartJob_ADDCMD(RemoteJS)
+
+ /*** Remote Command - JH */
+ SendStartJob_ADDCMD(RemoteJH)
+
+ /*** Remote Command - HD */
+ SendStartJob_ADDCMD(RemoteHD)
+ *(pCmdPos - sizeof(RemoteHD) + 6) = printJob.platform;
+
+ /*** Remote Command - PP */
+ SendStartJob_ADDCMD(RemotePP)
+ pCmdPos -= sizeof(RemotePP);
+
+ switch(printJob.attr.paperSource){
+ case EPS_MPID_REAR:
+ pCmdPos[5] = 0x01; pCmdPos[6] = 0x00;
+ break;
+ case EPS_MPID_FRONT1:
+ pCmdPos[5] = 0x01; pCmdPos[6] = 0x01;
+ break;
+ case EPS_MPID_FRONT2:
+ pCmdPos[5] = 0x01; pCmdPos[6] = 0x02;
+ break;
+ case EPS_MPID_CDTRAY:
+ pCmdPos[5] = 0x02; pCmdPos[6] = 0x01;
+ break;
+
+ case EPS_MPID_AUTO:
+ default:
+ if( EPS_CP_JPEG == printJob.attr.colorPlane &&
+ EPS_IS_CDDVD(printJob.attr.mediaTypeIdx) ){
+ /* Jpeg CD print need PP */
+ pCmdPos[5] = 0x02; pCmdPos[6] = 0x01;
+ } else{
+ EPS_DBGPRINT(("Paper Sourcr AutoSelect\n"));
+ pCmdPos[5] = 0x01; pCmdPos[6] = 0xFF; /* auto select */
+ }
+ break;
+ }
+
+ pCmdPos += sizeof(RemotePP);
+
+ /*** Remote Command - DP(duplex) */
+ if(EPS_DUPLEX_NONE != printJob.attr.duplex){
+ SendStartJob_ADDCMD(RemoteDP)
+ }
+
+ /*** Exit Remote Mode */
+ SendStartJob_ADDCMD(ExitRemoteMode)
+
+ /*** Enter ESC/P-R mode */
+ if( EPS_CP_JPEG != printJob.attr.colorPlane ){ /* RGB */
+ SendStartJob_ADDCMD(ESCPRMode)
+ } else{ /* JPEG */
+ SendStartJob_ADDCMD(ESCPRModeJpg)
+ }
+
+ /*** ESC/PR "Print Quality" Command (Internal called Page Attributes) */
+ SendStartJob_ADDCMD_LEN(PrintQualityCmd, printJob.attr.paletteSize)
+ MakeQualityCmd(pCmdPos - (sizeof(PrintQualityCmd) + printJob.attr.paletteSize) );
+
+ /*** ESC/PR "apf setting" Command */
+ if(EPS_CP_JPEG == printJob.attr.colorPlane){
+ SendStartJob_ADDCMD(APFSettingCmd)
+ MakeAPFCmd(pCmdPos-sizeof(APFSettingCmd));
+ }
+
+ /*** ESC/PR "Job" Command to Printer */
+ if( EPS_CP_JPEG != printJob.attr.colorPlane ){ /* RGB */
+ SendStartJob_ADDCMD(JobCmd)
+ MakeJobCmd(pCmdPos-sizeof(JobCmd));
+ } else{ /* JPEG */
+ SendStartJob_ADDCMD(JobCmdJpg)
+ MakeJobCmd(pCmdPos-sizeof(JobCmdJpg));
+ }
+
+ if(bAddStartPage){
+ SendStartJob_ADDCMD(StartPage)
+ }
+
+ retStatus = SendCommand(sendDataBuf, (EPS_UINT32)(pCmdPos - sendDataBuf), &retBufSize, TRUE);
+
+SendStartJob_END:
+ if(EPS_ERR_NONE == retStatus){
+ printJob.sendJS = TRUE;
+ }
+
+ /*** Return to Caller */
+ EPS_RETURN( retStatus );
+}
+
+
+/*======================================================================================*/
+/*** Set up Remote "TI" Command */
+/*======================================================================================*/
+static void MakeRemoteTICmd (
+
+ EPS_UINT8* pBuf
+
+){
+/*** Declare Variable Local to Routine */
+EPS_LOCAL_TIME locTime;
+EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
+
+ EPS_LOG_FUNCIN;
+
+ /* Get platform local time */
+ epsCmnFnc.getLocalTime(&locTime);
+
+ /*** Skip Header */
+ pBuf += REMOTE_HEADER_LENGTH;
+
+ /*** Set Attributes/Values */
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, locTime.year, array2);
+ memcpy(pBuf, array2, sizeof(array2));
+ pBuf += sizeof(array2);
+ *pBuf++ = locTime.mon;
+ *pBuf++ = locTime.day;
+ *pBuf++ = locTime.hour;
+ *pBuf++ = locTime.min;
+ *pBuf = locTime.sec;
+
+ EPS_RETURN_VOID;
+}
+
+
+/*======================================================================================*/
+/*** Set up ESC/PR "Print Quality" Command */
+/*======================================================================================*/
+static void MakeQualityCmd (
+
+ EPS_UINT8* pBuf
+
+){
+/*** Declare Variable Local to Routine */
+EPS_UINT8* pCmdPosTmp = NULL;
+EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
+EPS_UINT8 array4[4] = {0, 0, 0, 0}; /* Temporary Buffer for 4 byte Big Endian */
+
+ EPS_LOG_FUNCIN;
+
+ /*** Parameter Length */
+ if(printJob.attr.paletteSize > 0){
+ pCmdPosTmp = pBuf + ESCPR_CLASS_LENGTH;
+ memSetEndian(EPS_ENDIAN_LITTLE, EPS_4_BYTES,
+ ESCPR_PRINT_QUALITY_LENGTH + printJob.attr.paletteSize, array4);
+ memcpy(pCmdPosTmp, array4, sizeof(array4));
+ }
+
+ pBuf += ESCPR_HEADER_LENGTH;
+
+ /*** Set Attributes/Values */
+ *pBuf++ = (EPS_UINT8)printJob.attr.mediaTypeIdx;
+ switch( printJob.attr.printQuality ){
+ case EPS_MQID_DRAFT:
+ *pBuf++ = 0;
+ break;
+ case EPS_MQID_HIGH:
+ *pBuf++ = 2;
+ break;
+ case EPS_MQID_NORMAL:
+ default:
+ *pBuf++ = 1;
+ break;
+ }
+ *pBuf++ = printJob.attr.colorMode;
+ *pBuf++ = (EPS_UINT8)printJob.attr.brightness;
+ *pBuf++ = (EPS_UINT8)printJob.attr.contrast;
+ *pBuf++ = (EPS_UINT8)printJob.attr.saturation;
+ *pBuf++ = printJob.attr.colorPlane;
+
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, printJob.attr.paletteSize, array2);
+ memcpy(pBuf, array2, sizeof(array2));
+
+ if (printJob.attr.paletteSize > 0){
+ pBuf += sizeof(array2);
+ memcpy(pBuf, printJob.attr.paletteData, printJob.attr.paletteSize);
+ }
+
+ EPS_RETURN_VOID;
+}
+
+
+/*======================================================================================*/
+/*** Set up ESC/PR "APF setting" Command */
+/*======================================================================================*/
+static void MakeAPFCmd (
+
+ EPS_UINT8* pBuf
+
+){
+ EPS_LOG_FUNCIN;
+
+ /*** Skip Header */
+ pBuf += ESCPR_HEADER_LENGTH;
+
+ /*** Set Attributes/Values */
+ *pBuf++ = printJob.attr.colorMode;
+ *pBuf++ = printJob.attr.apfAutoCorrect;
+ *pBuf++ = printJob.attr.sharpness;
+ *pBuf++ = printJob.attr.redeye;
+
+ EPS_RETURN_VOID;
+}
+
+
+/*======================================================================================*/
+/*** Set up ESC/PR "Job" Command */
+/*======================================================================================*/
+static void MakeJobCmd (
+
+ EPS_UINT8* pBuf
+
+){
+/*** Declare Variable Local to Routine */
+EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
+EPS_UINT8 array4[4] = {0, 0, 0, 0}; /* Temporary Buffer for 4 byte Big Endian */
+
+ EPS_LOG_FUNCIN;
+
+ /*** Skip Header */
+ pBuf += ESCPR_HEADER_LENGTH;
+
+ if( EPS_CP_JPEG != printJob.attr.colorPlane ){ /* RGB */
+ /*EPS_DBGPRINT(("(%d, %d) / (%d, %d) / (%d, %d)\n",
+ printJob.paperWidth, printJob.paperHeight,
+ printJob.topMargin, printJob.leftMargin,
+ printJob.printableAreaWidth, printJob.printableAreaHeight))*/
+ /*** Set Attributes/Values */
+ memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, (EPS_UINT32)printJob.paperWidth, array4);
+ memcpy(pBuf, array4, sizeof(array4));
+ pBuf += sizeof(array4);
+ memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, (EPS_UINT32)printJob.paperHeight, array4);
+ memcpy(pBuf, array4, sizeof(array4));
+ pBuf += sizeof(array4);
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)printJob.topMargin, array2);
+ memcpy(pBuf, array2, sizeof(array2));
+ pBuf += sizeof(array2);
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)printJob.leftMargin, array2);
+ memcpy(pBuf, array2, sizeof(array2));
+ pBuf += sizeof(array2);
+ memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, printJob.printableAreaWidth, array4);
+ memcpy(pBuf, array4, sizeof(array4));
+ pBuf += sizeof(array4);
+ memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, printJob.printableAreaHeight, array4);
+ memcpy(pBuf, array4, sizeof(array4));
+ pBuf += sizeof(array4);
+ switch( printJob.attr.inputResolution ){
+ case EPS_IR_720X720:
+ *pBuf++ = 0x01;
+ break;
+ case EPS_IR_300X300:
+ *pBuf++ = 0x02;
+ break;
+ case EPS_IR_600X600:
+ *pBuf++ = 0x03;
+ break;
+ case EPS_IR_360X360:
+ default:
+ *pBuf++ = 0x00;
+ break;
+ }
+ *pBuf = printJob.attr.printDirection;
+
+ } else{ /* JPEG */
+ /*** Set Attributes/Values */
+ *pBuf++ = (EPS_UINT8)printJob.attr.mediaSizeIdx;
+ if( EPS_IS_CDDVD( printJob.attr.mediaTypeIdx ) ){
+ *pBuf++ = 0x0A;
+ } else{
+ switch( printJob.attr.printLayout ){
+ case EPS_MLID_BORDERLESS:
+ *pBuf++ = 0x01;
+ break;
+ case EPS_MLID_CDLABEL:
+ *pBuf++ = 0x0A;
+ break;
+ case EPS_MLID_DIVIDE16:
+ *pBuf++ = 0x90;
+ break;
+ default: /* FIXED, CUSTOM */
+ *pBuf++ = 0x00;
+ }
+ }
+ *pBuf++ = printJob.attr.cdDimIn;
+ *pBuf++ = printJob.attr.cdDimOut;
+ *pBuf = printJob.attr.printDirection;
+ }
+
+ EPS_RETURN_VOID;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SendEndJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* bAddEndPage EPS_BOOL I: Append End Page comannd */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* << Error >> */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send End Page commands. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE SendEndJob (
+
+ EPS_BOOL bAddEndPage
+
+){
+/*** Declare Variable Local to Routine */
+EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+EPS_UINT8* pCmdPos = NULL;
+EPS_UINT32 retBufSize; /* Size of buffer written */
+
+ EPS_LOG_FUNCIN
+
+ EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize,
+ (sizeof(EndPage)+ sizeof(EndJob) + sizeof(InitPrinter)
+ + sizeof(EnterRemoteMode) + sizeof(RemoteLD) + sizeof(RemoteJE)+ sizeof(ExitRemoteMode)))
+ if(NULL == sendDataBuf){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ pCmdPos = sendDataBuf;
+
+ if(bAddEndPage){
+ memcpy(pCmdPos, EndPage, sizeof(EndPage));
+ pCmdPos[10] = EPS_END_PAGE;
+ pCmdPos += sizeof(EndPage);
+ }
+
+ /*** End Job */
+ memcpy(pCmdPos, EndJob, sizeof(EndJob));
+ pCmdPos += sizeof(EndJob);
+
+ /*** Initialize */
+ memcpy(pCmdPos, InitPrinter, sizeof(InitPrinter));
+ pCmdPos += sizeof(InitPrinter);
+
+ memcpy(pCmdPos, EnterRemoteMode, sizeof(EnterRemoteMode));
+ pCmdPos += sizeof(EnterRemoteMode);
+
+ if(EPS_DUPLEX_NONE != printJob.attr.duplex){
+ memcpy(pCmdPos, RemoteLD, sizeof(RemoteLD));
+ pCmdPos += sizeof(RemoteLD);
+ }
+
+ /*** Remote Command - JE */
+ memcpy(pCmdPos, RemoteJE, sizeof(RemoteJE));
+ pCmdPos += sizeof(RemoteJE);
+
+ /*** Exit Remote Mode */
+ memcpy(pCmdPos, ExitRemoteMode, sizeof(ExitRemoteMode));
+ pCmdPos += sizeof(ExitRemoteMode);
+
+ retStatus = SendCommand(sendDataBuf, (EPS_UINT32)(pCmdPos - sendDataBuf), &retBufSize, TRUE);
+
+ if(EPS_JOB_CANCELED == retStatus){
+ retStatus = EPS_ERR_NONE;
+ }
+
+ /*printJob.sendJS = FALSE;*/
+
+ /*** Return to Caller */
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SendCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Buffer EPS_INT8* I: Print Data Buffer */
+/* BuffLen EPS_UINT32 I: Print Data Buffer Size */
+/* pSize EPS_UINT32 O: Actual Length Transferred */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Sent the data successfully */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Send print data to the active printer */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE SendCommand (
+
+ const EPS_UINT8* Buffer,
+ EPS_UINT32 BuffLen,
+ EPS_UINT32* pSize,
+ EPS_BOOL bSave
+
+){
+
+#ifdef EPS_FILTER
+ //long int i;
+ EPS_UINT32 i;
+ FILE* outfp = stdout;
+ for (i = 0; i < BuffLen; i++){
+ putc(*(Buffer + i), outfp);
+ }
+ *pSize = BuffLen;
+ return EPS_ERR_NONE;
+#endif
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE Ret = EPS_ERR_NONE;
+ EPS_INT32 retStatus;
+ EPS_UINT32 sendSize;
+ EPS_UINT32 sentSize;
+ EPS_INT32 nRetry = 0;
+ EPS_UINT32 tmStart, tmNow, tmSpan;
+ EPS_INT32 nDlySpan = 10; /* first 10 ms */
+ EPS_INT32 nDlyTotal = EPS_TIMEOUT_SEC; /* total 1000 ms */
+
+ EPS_LOG_FUNCIN;
+
+/*** Validate input parameters */
+ if ((Buffer == NULL) || (BuffLen == 0))
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+
+/*** Initialize Global/Local Variables */
+ retStatus = EPS_ERR_NONE;
+ sentSize = 0;
+ sendSize = BuffLen;
+ *pSize = 0;
+
+ tmStart = tmNow = tmSpan = 0;
+
+ if( FALSE == printJob.bComm){
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
+ }
+
+ if( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+/***------------------------------------------------------------------------------------*/
+/*** Bi-Directional Mode */
+/***------------------------------------------------------------------------------------*/
+ /*** If printer reset command was already sent, don't send command any more. */
+ /*** When paper jam error happened, don't send command any more. */
+ /*** "transmittable == FLSE" means "paper jam error happened". */
+ if( printJob.resetSent == EPS_RESET_SENT || TRUE == printJob.resetReq ){
+ EPS_RETURN( EPS_JOB_CANCELED );
+ } else if(FALSE == printJob.transmittable){
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
+ }
+
+ /*** Send command */
+ if(epsCmnFnc.getTime){
+ tmStart = epsCmnFnc.getTime();
+ tmNow = tmSpan = 0;
+ }
+
+ while(nDlyTotal > 0){
+ if(gStatusCount == EPS_ROOP_NUM){
+ gStatusCount = 0;
+ if ((Ret = MonitorStatus(NULL) ) != EPS_ERR_NONE){
+ EPS_DBGPRINT(("MonitorStatus=%d\n", Ret));
+
+ if(Ret == EPS_JOB_CANCELED){
+ EPS_RETURN( Ret );
+ } else if(Ret == EPS_ERR_COMM_ERROR){
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
+ } else {
+ /*anoter error*/
+ if ( EPS_PROTOCOL_USB & printJob.printer->protocol ){
+ break;
+ } else{
+ /* Net continue to buffer full. */
+ }
+ }
+ }
+ }
+ gStatusCount++;
+
+ Ret = jobFnc.WriteData(Buffer, sendSize, &sentSize);
+ *pSize += sentSize;
+#ifdef LCOMSW_CMDDMP
+ EPS_DF_WRITE(Buffer, sentSize)
+#endif
+
+ if (Ret != EPS_ERR_NONE){
+ if (Ret == EPS_JOB_CANCELED) {
+ /* UPnP Job turned idle */
+ printJob.resetReq = TRUE;
+ EPS_RETURN( Ret );
+ } else if (Ret != EPS_COM_TINEOUT){
+ EPS_DBGPRINT(("PRINT--> Print Failed [%d]\r\n",Ret));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ } else if(sendSize > sentSize){
+ Buffer += sentSize;
+ sendSize -= sentSize;
+ }
+ } else if (sendSize > sentSize){ /* CBT returned OK, but size is less */
+ Ret = EPS_COM_TINEOUT;
+ Buffer += sentSize;
+ sendSize -= sentSize;
+ } else {
+ sendSize -= sentSize;
+ break;
+ }
+
+ if( !(EPS_PROTOCOL_USB & printJob.printer->protocol)
+ || NULL == epsCmnFnc.getTime ){
+ /* The count is made an upper bound. */
+ if(nRetry++ > EPS_TIMEOUT_NUM){
+ break;
+ }
+ } else{
+ /* The elapsed time is made an upper bound. */
+ tmNow = epsCmnFnc.getTime();
+ tmSpan = (EPS_UINT32)(tmNow - tmStart);
+ if( tmSpan >= EPS_TIMEOUT_SEC ){
+ break;
+ }
+
+ /* Wait */
+ nDlyTotal -= nDlySpan;
+ if(nDlySpan < 200){
+ nDlySpan += nDlySpan/2;
+ if(nDlySpan > 200){
+ nDlySpan = 200; /* max 200ms */
+ }
+ }
+ serDelayThread(nDlySpan, &epsCmnFnc);
+ }
+ }
+
+ if(0 < sendSize){
+ if(TRUE == bSave){
+ /* save the leftovers */
+ /*EPS_DBGPRINT(("%d / Save %d byte\r\n", Ret, sendSize));*/
+ printJob.contData.sendDataSize = sendSize;
+ printJob.contData.sendData = Buffer;
+ }
+
+ Ret = MonitorStatus(NULL);
+ if (Ret == EPS_JOB_CANCELED) {
+ EPS_RETURN( Ret );
+ } else{
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
+ }
+ } else{
+ printJob.contData.sendDataSize = 0;
+ }
+
+ if(Ret != EPS_ERR_NONE){
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
+ }
+
+ } else{
+/***------------------------------------------------------------------------------------*/
+/*** Uni-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ retStatus = jobFnc.WriteData(Buffer, BuffLen, &sentSize);
+
+ if ((retStatus == 0) && (sendSize == sentSize)) {
+ *pSize = sentSize;
+ } else {
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: AdjustBasePoint() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A void N/A */
+/* */
+/* Return value: N/A */
+/* */
+/* Description: Change the base point setting and the printable area value for */
+/* the custum border mode. */
+/* */
+/*******************************************|********************************************/
+static void AdjustBasePoint (
+
+ void
+
+){
+ /* temporary variables for max PAW/PAL */
+ EPS_UINT32 maxPAWidthBorder;
+ EPS_UINT32 maxPAHeightBorder;
+ EPS_UINT32 RightMargin;
+ EPS_UINT32 BottomMargin;
+
+ EPS_LOG_FUNCIN;
+
+ printJob.offset_x = 0;
+ printJob.offset_y = 0;
+
+
+/*** Adjust the base point for custum border printing mode */
+/*** (In case that left margin = 42 and top margin = 42 are NOT inputed) */
+ if (printJob.borderlessMode == EPS_BORDER_CUSTOM) {
+ if ( (printJob.attr.leftMargin > printJob.border.left) ||
+ (printJob.attr.topMargin > printJob.border.top ) ) {
+
+ printJob.offset_x = (EPS_INT16)(printJob.attr.leftMargin - printJob.border.left);
+ printJob.offset_y = (EPS_INT16)(printJob.attr.topMargin - printJob.border.top);
+
+ RightMargin = printJob.paperWidth
+ - printJob.attr.leftMargin - printJob.printableAreaWidth;
+ BottomMargin = printJob.paperHeight
+ - printJob.attr.topMargin - printJob.printableAreaHeight;
+
+ printJob.printableAreaWidth = printJob.paperWidth
+ - printJob.border.left - RightMargin;
+ printJob.printableAreaHeight = printJob.paperHeight
+ - printJob.border.top - BottomMargin;
+
+ printJob.leftMargin = (EPS_INT16)(printJob.border.left);
+ printJob.topMargin = (EPS_INT16)(printJob.border.top);
+
+ /* max PAW/PAL */
+ maxPAHeightBorder = (EPS_UINT32)(printJob.paperHeight
+ - printJob.border.top - printJob.border.bottom);
+ maxPAWidthBorder = (EPS_UINT32)(printJob.paperWidth
+ - printJob.border.left - printJob.border.right);
+
+ if (printJob.printableAreaHeight > maxPAHeightBorder) {
+ printJob.printableAreaHeight = maxPAHeightBorder;
+ }
+
+ if (printJob.printableAreaWidth > maxPAWidthBorder) {
+ printJob.printableAreaWidth = maxPAWidthBorder;
+ }
+ }
+ }
+
+ EPS_RETURN_VOID;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: PrintLine() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* line EPS_IMAGE* I: Image Data Structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Filter Print Raster Data. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE PrintLine (
+
+ EPS_IMAGE* line
+
+){
+ EPS_RECT AdjBandRec; /* Rectangle after BasePointAdjustment */
+ EPS_BANDBMP InBmp; /* Input band data */
+ EPS_LOG_FUNCIN;
+ /* Initialize input image structure */
+ InBmp.bits = line->data;
+ InBmp.widthBytes = line->bytesPerLine;
+
+ /* change rectangle due to base point adjustment */
+ AdjBandRec.top = line->rect.top + printJob.offset_y;
+ AdjBandRec.left = line->rect.left + printJob.offset_x;
+ AdjBandRec.bottom = line->rect.bottom + printJob.offset_y;
+ AdjBandRec.right = line->rect.right + printJob.offset_x;
+
+ /* band is not visible */
+ if ((EPS_UINT32)AdjBandRec.bottom > printJob.printableAreaHeight){
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+ if ((EPS_UINT32)AdjBandRec.right > printJob.printableAreaWidth){
+ AdjBandRec.right = (EPS_INT32)printJob.printableAreaWidth;
+ }
+
+#ifdef GCOMSW_CMD_ESCPAGE
+ if(EPS_LANG_ESCPR == printJob.printer->language ){
+#endif
+ /*** ESC/P-R ***/
+ EPS_RETURN( SendLine(&InBmp, &AdjBandRec) );
+#ifdef GCOMSW_CMD_ESCPAGE
+ } else{
+ /*** ESC/Page ***/
+ EPS_RETURN( pageColorRow(&InBmp, &AdjBandRec) );
+ }
+#endif
+
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SendLine() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pInBmp const EPS_BANDBMP I: [RGB] Image Data */
+/* pBandRec EPS_RECT I: Band rectangle information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Sent the data successfully */
+/* EPS_JOB_CANCELED - Cancelled operation by user */
+/* (Do not return when Uni-Directional) */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Send a line data to printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE SendLine (
+
+ const EPS_BANDBMP* pInBmp,
+ EPS_RECT* pBandRec
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus; /* Return status of internal calls */
+ EPS_UINT32 retBufSize; /* Size of buffer written */
+ EPS_UINT32 cmdSize; /* All Size of Print Job Command */
+ EPS_UINT32 cpyCount; /* Counter for Set Command */
+ EPS_UINT16 compDataSize; /* Raster Data Size */
+ EPS_UINT16 linePixelSize; /* Raster Pixel Size */
+ EPS_UINT8 compFlag; /* Compression flg (1:done compression 0:undone compression) */
+ EPS_UINT32 paramSize; /* Parameter Length */
+ EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
+ EPS_UINT8 array4[4] = {0, 0, 0, 0}; /* Temporary Buffer for 4 byte Big Endian */
+ EPS_UINT8* compData; /* Compression Data Pointer */
+ EPS_UINT8* sdBuf; /* Send Data Buffer Pointer */
+ const EPS_UINT8* srcAddr;
+
+#if LCOMSW_PACKET_4KB
+ EPS_INT32 rest_size;
+ EPS_INT32 idx;
+#endif
+
+ EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ compFlag = EPS_RLE_COMPRESS_DONE;
+
+/*** Initialize global valiable */
+ memset(sendDataBuf, 0xFF, (EPS_UINT32)sendDataBufSize);
+ memset(tmpLineBuf, 0xFF, (EPS_UINT32)tmpLineBufSize );
+
+/*** Initialize valiable */
+ sdBuf = sendDataBuf;
+ compData = tmpLineBuf;
+
+
+/* EPS_DBGPRINT(("MakeOneRasterData: T,B,L,R [%d,%d,%d,%d]\r\n",
+ pBandRec->top, pBandRec->bottom, pBandRec->left, pBandRec->right));
+*/
+ if( (EPS_UINT32)(pBandRec->right - pBandRec->left) <= printJob.printableAreaWidth){
+ linePixelSize = (EPS_UINT16)(pBandRec->right - pBandRec->left);
+ } else{
+ linePixelSize = (EPS_UINT16) printJob.printableAreaWidth;
+ }
+
+#if ESCPR_DEBUG_IMAGE_LOG
+ EPS_DBGPRINT(("ESCPRCMD : ImageData\r\n")
+ EPS_DUMP(pInBmp->bits, (pBandRec->right - pBandRec->left) * 3)
+#endif
+
+ /*** Layout Filter */
+ if(EPS_MLID_CDLABEL == printJob.attr.printLayout){
+#ifdef GCOMSW_EL_CDLABEL
+ elCDClipping(pInBmp->bits, sdBuf, printJob.bpp, pBandRec);
+ srcAddr = sdBuf;
+#else
+ srcAddr = pInBmp->bits;
+#endif
+
+ } else{
+ srcAddr = pInBmp->bits;
+ }
+
+ /*** RunLength Encode */
+
+ compDataSize = RunLengthEncode(srcAddr,
+ compData,
+ linePixelSize,
+ printJob.bpp,
+ &compFlag);
+
+ //compFlag = EPS_RLE_COMPRESS_NOT_DONE;
+ if(compDataSize < 0){
+ //return compDataSize;
+ }
+
+ /* Set Parameter Length */
+ paramSize = (EPS_UINT32)(ESCPR_SEND_DATA_LENGTH + compDataSize);
+ cmdSize = ESCPR_HEADER_LENGTH + paramSize;
+
+/*** Set Parameter */
+ cpyCount = 0;
+
+ /* Header */
+ memcpy(sdBuf, SendDataCmd, sizeof(SendDataCmd));
+ cpyCount += sizeof(SendDataCmd);
+
+ /* Parameter Length */
+ memSetEndian(EPS_ENDIAN_LITTLE, EPS_4_BYTES, (EPS_UINT32)paramSize, array4);
+ memcpy(sdBuf + cpyCount, array4, sizeof(array4));
+ cpyCount += sizeof(array4);
+
+ /* Command Name */
+ memcpy(sdBuf + cpyCount, SendDataName, sizeof(SendDataName));
+ cpyCount += sizeof(SendDataName);
+
+ /* lXoffset */
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)pBandRec->left, array2);
+ memcpy((sdBuf + cpyCount), array2, sizeof(array2));
+ cpyCount += sizeof(array2);
+
+ /* lYoffset */
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)pBandRec->top, array2);
+ memcpy((sdBuf + cpyCount), array2, sizeof(array2));
+ cpyCount += sizeof(array2);
+
+ /* Compression Mode */
+ if(compFlag == EPS_RLE_COMPRESS_DONE){
+ *(sdBuf + cpyCount) = EPS_COMP_RLE;
+ } else{
+ *(sdBuf + cpyCount) = EPS_COMP_NON;
+ }
+ cpyCount += sizeof(EPS_UINT8);
+
+ /* Raster Data Size */
+ memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)compDataSize, array2);
+ memcpy((sdBuf + cpyCount), array2, sizeof(array2));
+ cpyCount += sizeof(array2);
+
+ /* RGB Raster Data */
+ memcpy((sdBuf + cpyCount), compData, compDataSize);
+ cpyCount += compDataSize;
+
+ if (cmdSize != cpyCount) {
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+
+ /* Send Print Quality Command to Printer */
+/*** -----------------------------------------------------*/
+#if LCOMSW_PACKET_4KB /* Set 1 packett size in 4096byte */
+/*** -----------------------------------------------------*/
+ if(cmdSize > ESCPR_PACKET_SIZE_4KB) {
+ /* Send 4090 bytes Data */
+ for(idx = 0; idx < (EPS_INT32)(cmdSize / ESCPR_PACKET_SIZE_4KB); idx++){
+
+#if ESCPR_DEBUG_IMAGE_LOG
+ EPS_DUMP(sdBuf, ESCPR_PACKET_SIZE_4KB)
+#endif /* ESCPR_DEBUG_IMAGE_LOG */
+
+ retBufSize = 0;
+
+ retStatus = SendCommand(sdBuf, ESCPR_PACKET_SIZE_4KB, &retBufSize, TRUE);
+ if (!((retStatus == EPS_ERR_NONE) && (ESCPR_PACKET_SIZE_4KB == retBufSize))) {
+ EPS_RETURN( retStatus );
+ }
+ sdBuf += ESCPR_PACKET_SIZE_4KB;
+ }
+
+ /* Send Rest Data */
+ rest_size = cmdSize - ((EPS_INT32)(cmdSize / ESCPR_PACKET_SIZE_4KB)) * ESCPR_PACKET_SIZE_4KB;
+ retBufSize = 0;
+
+ retStatus = SendCommand(sdBuf, rest_size, &retBufSize, TRUE);
+ if (!((retStatus == EPS_ERR_NONE) && (rest_size == retBufSize))) {
+ EPS_RETURN( retStatus );
+ }
+
+#if ESCPR_DEBUG_IMAGE_LOG
+ EPS_DUMP(sdBuf, rest_size)
+#endif /* ESCPR_DEBUG_IMAGE_LOG */
+
+ } else /* if(cmdSize <= ESCPR_PACKET_SIZE_4KB) */{
+
+#if ESCPR_DEBUG_IMAGE_LOG
+ EPS_DUMP(sdBuf, cmdSize)
+#endif /* ESCPR_DEBUG_IMAGE_LOG */
+
+ retBufSize = 0;
+
+ retStatus = SendCommand(sdBuf, cmdSize, &retBufSize, TRUE);
+ if (!((retStatus == EPS_ERR_NONE) && (cmdSize == retBufSize))) {
+ EPS_RETURN( retStatus );
+ }
+
+ }
+
+/*** -----------------------------------------------------*/
+#else /* LCOMSW_PACKET_4KB */
+/*** -----------------------------------------------------*/
+
+#if ESCPR_DEBUG_IMAGE_LOG
+ EPS_DUMP(sdBuf, cpyCount)
+#endif /* ESCPR_DEBUG_IMAGE_LOG */
+
+ retBufSize = 0;
+ retStatus = SendCommand(sdBuf, cmdSize, &retBufSize, TRUE);
+ if (!((retStatus == EPS_ERR_NONE) && (cmdSize == retBufSize))) {
+ EPS_RETURN( retStatus );
+ }
+
+/*** -----------------------------------------------------*/
+#endif /* LCOMSW_PACKET_4KB */
+/*** -----------------------------------------------------*/
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: RunLengthEncode() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pSrcAddr const EPS_UINT8* I: An address of original raster */
+/* pDstAddr EPS_UINT8* O: An address of compressed raster */
+/* pixel EPS_INT16 I: Original Raster Size */
+/* bpp EPS_UINT8 I: Bytes Per Pixel */
+/* pCompress EPS_UINT8* O: Compression Flag */
+/* */
+/* Return value: */
+/* Compressed Data Size (byte) */
+/* */
+/* Description: */
+/* Runlength Compression for RGB Data. */
+/* */
+/*******************************************|********************************************/
+static EPS_UINT16 RunLengthEncode (
+
+ const EPS_UINT8* pSrcAddr,
+ EPS_UINT8* pDstAddr,
+ EPS_UINT16 pixel,
+ EPS_UINT8 bpp,
+ EPS_UINT8* pCompress
+
+){
+ const EPS_UINT8* pSrcPos = pSrcAddr; /* pointer to srcBuffer */
+ EPS_UINT8* pDstPos = pDstAddr; /* pointer to destBuffer */
+ EPS_UINT16 srcCnt = 0; /* counter */
+ EPS_UINT16 repCnt = 0; /* replay conter */
+ EPS_UINT16 retCnt = 0; /* conpressed data size */
+ EPS_UINT32 copySize = 0;
+ EPS_UINT16 widthPixels = pixel * bpp;
+ EPS_BOOL bCompress = TRUE;
+
+ EPS_LOG_FUNCIN;
+int i_index = 0;
+ while (srcCnt < pixel) {
+ /* In case of replay data */
+ if ((srcCnt + 1 < pixel) && (!memcmp(pSrcPos, pSrcPos + bpp, bpp))) {
+ repCnt = 2;
+ while ((srcCnt + repCnt < pixel) &&
+ (repCnt < 0x81) &&
+ (!memcmp(pSrcPos + (repCnt - 1) * bpp, pSrcPos + repCnt * bpp, bpp)) ) {
+ repCnt++;
+ }
+
+ /* Renewal compressed data size counter */
+ retCnt += 1 + bpp;
+
+ /* If compressed data size is bigger than original data size, */
+ /* stop compression process. */
+ if( retCnt > widthPixels ){
+ bCompress = FALSE;
+ retCnt -= 1 + bpp; /* rewind counter */
+ break;
+ }
+
+ /* Set replay count and data */
+ /* Set data counter */
+ if(pDstPos == NULL || (pDstPos+1) == NULL || (pDstPos + bpp) == NULL || pSrcPos == NULL ||( pSrcPos + bpp * repCnt) == NULL){
+ return i_index * (-1);
+ }
+ *pDstPos++ = (EPS_UINT8)(0xFF - repCnt + 2 );
+
+ /* Set data */
+ memcpy(pDstPos, pSrcPos, bpp);
+
+ /* Renewal data size counter */
+ srcCnt += repCnt;
+ i_index += bpp * repCnt;
+
+ /* Renewal original data address */
+ if((pSrcPos + bpp * repCnt) == NULL){
+ return i_index * (-1);
+ }
+ pSrcPos += bpp * repCnt;
+
+ /* Renewal compressed data address */
+ pDstPos += bpp;
+
+
+ }
+
+ /* In case of non replay data */
+ else {
+ copySize = 0;
+ repCnt = 1;
+
+ /* compare next data with next and next data */
+ while ((srcCnt + repCnt + 1< pixel) &&
+ (repCnt < 0x80) &&
+ (memcmp(pSrcPos + repCnt * bpp, pSrcPos + (repCnt + 1) * bpp, bpp)) ){
+ repCnt++;
+ }
+
+ /* Renewal compressed data size counter */
+ retCnt += 1 + repCnt * bpp;
+
+ /* If compressed data size is bigger than original data size, */
+ /* stop compression process. */
+ if( retCnt > widthPixels ){
+ bCompress = FALSE;
+ retCnt -= 1 + repCnt * bpp; /* rewind counter */
+ break;
+ }
+
+ /* Set data counter */
+ if(pDstPos == NULL || (pDstPos +1) == NULL){
+ return i_index *(-1);
+ }
+ *pDstPos++ = (EPS_UINT8)(repCnt - 1);
+ /* Renewal data size counter */
+
+ /* Size of non replay data (byte) */
+ srcCnt += repCnt;
+ copySize = (EPS_UINT32)(repCnt * bpp);
+ if(pDstPos == NULL || (pDstPos +1) == NULL || (pDstPos + copySize) == NULL || (pSrcPos + copySize) == NULL || pSrcPos == NULL){
+ return i_index * (-1);
+ }
+
+ /* Set data */
+ memcpy(pDstPos, pSrcPos, copySize);
+
+ /* Renewal original data address */
+ pSrcPos += copySize;
+
+ /* Renewal compressed data address */
+ pDstPos += copySize;
+ i_index += copySize;
+ }
+ }
+
+ if(TRUE == bCompress){
+ *pCompress = EPS_RLE_COMPRESS_DONE;
+ } else{
+ retCnt = widthPixels;
+ memcpy(pDstAddr, pSrcAddr, widthPixels);
+ *pCompress = EPS_RLE_COMPRESS_NOT_DONE;
+ }
+
+ EPS_RETURN( retCnt );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CreateMediaInfo() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* innerPrinter EPS_PRINTER_INN* I: printer that it has original structure */
+/* pmString EPS_INT8* I: PM reply string */
+/* pmSize EPS_INT32 I: size of PM reply string */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Alloc memory failed */
+/* */
+/* Description: */
+/* Marge paper source to EPS_SUPPORTED_MEDIA. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE CreateMediaInfo(
+
+ EPS_PRINTER_INN* innerPrinter,
+ EPS_UINT8* pmString,
+ EPS_INT32 pmSize
+
+){
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE;
+ EPS_UINT8* cmdField; /* Pointer of pm command field */
+ EPS_INT32 pmIdx; /* pm string index */
+ EPS_UINT32 idx; /* Index */
+ EPS_INT32 sIdx = 0; /* Media size index */
+ EPS_INT32 tIdx = 0; /* Media type index */
+ EPS_INT32 num_mType = 0; /* Media type number */
+ EPS_INT32 num_mSize = 0; /* Media size number */
+ EPS_BOOL extPaper = FALSE; /* extend paper source is exist */
+
+ EPS_LOG_FUNCIN;
+
+ /*** Is this really "PM" data */
+ cmdField = (EPS_UINT8*)strstr((const char*)pmString,"PM");
+ if (cmdField == NULL ) {
+ EPS_DBGPRINT(("Get Model Info faild : ModelInfo = [%s]\r\n",pmString));
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+EPS_DUMP(pmString, 256);
+
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ if(innerPrinter->supportedMedia.numSizes != -1){
+ /*** "Filter" Raw "PM" data (Remake the correct pm stirng) */
+ retStatus = _SP_ChangeSpec_UpdatePMReply(innerPrinter, pmString, pmSize);
+ if (retStatus != EPS_ERR_NONE) {
+ EPS_RETURN( retStatus );
+ }
+ }
+#else
+/*** "Filter" Raw "PM" data (Remake the correct pm stirng) */
+ retStatus = _SP_ChangeSpec_UpdatePMReply(innerPrinter, pmString, pmSize);
+ if (retStatus != EPS_ERR_NONE) {
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* Invalid format */
+ }
+#endif
+
+/*** Create the structure of the support media */
+ innerPrinter->supportedMedia.resolution = EPS_IR_360X360; /* default support */
+
+ /*** Count "Paper Size" field & check format */
+ pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
+ while( pmIdx < EPS_PM_MAXSIZE ) {
+ switch(pmString[pmIdx]) {
+ case 'R':
+ if( 720 == ((pmString[pmIdx+1] << 8) + pmString[pmIdx+2]) ){
+ innerPrinter->supportedMedia.resolution |= EPS_IR_720X720;
+ } else if( 600 == ((pmString[pmIdx+1] << 8) + pmString[pmIdx+2]) ){
+ innerPrinter->supportedMedia.resolution |= EPS_IR_300X300 | EPS_IR_600X600;
+ } else if( 300 == ((pmString[pmIdx+1] << 8) + pmString[pmIdx+2]) ){
+ innerPrinter->supportedMedia.resolution |= EPS_IR_300X300;
+ }
+ pmIdx += 6;
+ break;
+
+ case 'M':
+ innerPrinter->supportedMedia.JpegSizeLimit =
+ (pmString[pmIdx+1] << 24) + (pmString[pmIdx+2] << 16) + (pmString[pmIdx+3] << 8) + pmString[pmIdx+4];
+ innerPrinter->JpgMax = innerPrinter->supportedMedia.JpegSizeLimit;
+ pmIdx += 6;
+ break;
+
+ case 'S':
+ /* move T field */
+ if(pmIdx < EPS_PM_MAXSIZE-2){
+ pmIdx += 2;
+ } else{
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+ num_mSize++;
+
+ for(; pmIdx < EPS_PM_MAXSIZE-4; pmIdx += 4) { /* 4 = T x x / */
+ if(pmString[pmIdx] == '/'){
+ pmIdx += 1;
+ break;
+ } else if(pmString[pmIdx] != 'T') {
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+ }
+ if(pmIdx >= EPS_PM_MAXSIZE-4){
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+ break;
+
+ default:
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+
+ /* If we run into an occurrence of carriage return followed by line feed,
+ * we have found the terminating characters of the string. */
+ if(pmString[pmIdx] == 0x0D && pmString[pmIdx+1] == 0x0A) {
+ break;
+ }
+ }
+ if(pmIdx >= EPS_PM_MAXSIZE){
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+
+ /* Allocate memory for the media size list. */
+ innerPrinter->supportedMedia.sizeList =
+ (EPS_MEDIA_SIZE*)EPS_ALLOC( sizeof(EPS_MEDIA_SIZE) * num_mSize );
+ if( innerPrinter->supportedMedia.sizeList == NULL ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+ memset(innerPrinter->supportedMedia.sizeList, 0, sizeof(EPS_MEDIA_SIZE) * num_mSize);
+ innerPrinter->supportedMedia.numSizes = num_mSize;
+
+ pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
+ for(sIdx = 0; sIdx < num_mSize; sIdx++) {
+ if(pmString[pmIdx] == 'M' || pmString[pmIdx] == 'R') {
+ pmIdx += 6;
+ sIdx--;
+ continue;
+ }
+
+ innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID = pmString[pmIdx+1];
+/* EPS_DBGPRINT(("Size=%d\r\n", pmString[pmIdx+1]));*/
+ pmIdx += 2;
+
+ /* For the given paper type, iterate through the paper type to get the number
+ * of media types contained in it */
+ num_mType = 0;
+ for(idx = pmIdx; idx < EPS_PM_MAXSIZE-4; idx += 4) {
+ if(pmString[idx] == '/'){
+ idx += 1;
+ break;
+ }
+ num_mType++;
+ }
+
+ /* Allocate memory for the media type array. */
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList =
+ (EPS_MEDIA_TYPE*)EPS_ALLOC( sizeof(EPS_MEDIA_TYPE) * num_mType );
+
+ if (innerPrinter->supportedMedia.sizeList[sIdx].typeList == NULL) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+
+ memset(innerPrinter->supportedMedia.sizeList[sIdx].typeList, 0, sizeof(EPS_MEDIA_TYPE) * num_mType);
+ innerPrinter->supportedMedia.sizeList[sIdx].numTypes = num_mType;
+
+ for(tIdx = 0; tIdx < num_mType; tIdx++) {
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].mediaTypeID = pmString[pmIdx+1];
+/* EPS_DBGPRINT(("\tType=%d (%02X)\r\n", pmString[pmIdx+1], pmString[pmIdx+2]));*/
+
+ /* Bitwise OR with 10000000 - Check for borderless */
+ if( pmString[pmIdx+2] & 0x80 ){
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].layout |= EPS_MLID_BORDERLESS;
+ }
+ /* Bitwise OR with 01000000 - Check for border "disable" mode */
+ if( !(pmString[pmIdx+2] & 0x40) ){
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].layout |= EPS_MLID_BORDERS;
+ }
+
+ /* set quality */
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].quality |= (pmString[pmIdx+2] & EPS_MQID_ALL);
+
+ /* set duplex */
+ if( pmString[pmIdx+2] & 0x10 &&
+ obsEnableDuplex(innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID) ){
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].duplex = EPS_DUPLEX_ENABLE;/*EPS_DUPLEX_SHORT*/;
+ } else{
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].duplex = EPS_DUPLEX_DISABLE;
+ }
+
+ /* Bitwise OR with 00001000 - Check for extend paper source */
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ if( pmString[pmIdx+2] & 0x08 ){
+ extPaper = TRUE;
+ } else {
+ /* DEFAULT. All printer support rear paper source */
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].paperSource = EPS_MPID_REAR;
+ }
+
+ /* param2 value check */
+ if( !(pmString[pmIdx+2] & (0x01 | 0x02 | 0x04)) ){
+ printf("\n\n!!!!!!!!! Quality is not described. !!!!!!!!!\n"
+ "SizeID=0x%02X / TypeID=0x%02X / param2=0x%02X\n",
+ innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID,
+ pmString[pmIdx+1], pmString[pmIdx+2]);
+ }
+ if( !(pmString[pmIdx+2] & 0x80) && (pmString[pmIdx+2] & 0x40) ){
+ printf("\n\n!!!!!!!!! Layout is not described. !!!!!!!!!\n"
+ "SizeID=0x%02X / TypeID=0x%02X / param2=0x%02X\n",
+ innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID,
+ pmString[pmIdx+1], pmString[pmIdx+2]);
+ }
+
+#else
+ if( pmString[pmIdx+2] & 0x08 ){
+ extPaper = TRUE;
+ }
+ /* DEFAULT. All printer support rear paper source */
+ innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].paperSource = EPS_MPID_REAR;
+#endif
+ pmIdx += 4; /* move next field */
+ }
+ pmIdx += 1; /* skip terminater */
+ }
+
+/*** Add extend infomation */
+ if( EPS_ERR_NONE == retStatus && TRUE == extPaper ){
+ retStatus = GetPaperSource(innerPrinter);
+ if( EPS_ERR_NONE != retStatus){
+ prtClearSupportedMedia(innerPrinter);
+ }
+ }
+
+ serAppendMedia(&innerPrinter->supportedMedia);
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: GetPaperSource() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* innerPrinter EPS_PRINTER_INN* I: printer that it has original structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* */
+/* Description: */
+/* Marge paper source to EPS_SUPPORTED_MEDIA. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE GetPaperSource(
+
+ EPS_PRINTER_INN* innerPrinter
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT8 pmString[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
+ EPS_INT32 pmSize = EPS_PM_MAXSIZE;
+ EPS_UINT32 pmIdx; /* pm string index */
+ EPS_INT32 sIdx = 0; /* Media size index */
+ EPS_INT32 tIdx = 0; /* Media type index */
+ EPS_MEDIA_SIZE *pMSize = NULL;
+
+ EPS_LOG_FUNCIN;
+
+ /* Clear the Printer Model Information (Media data or "PM" data) */
+ memset(pmString, 0, EPS_PM_MAXSIZE);
+
+/*** Get PM2 from Printer */
+ ret = prtGetPMString(innerPrinter, 2, pmString, &pmSize);
+ if(ret == EPS_ERR_PROTOCOL_NOT_SUPPORTED){
+ EPS_RETURN( EPS_ERR_NONE );
+ } else if(ret != EPS_ERR_NONE){
+ EPS_RETURN( ret );
+ }
+
+ /*** Is this really "PM" data */
+ if( strstr((const char*)pmString, "PM") == NULL ) {
+ EPS_DBGPRINT(("Get Model Info faild : ModelInfo = [%s]\r\n", pmString));
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+ /* Delete the command header of pm string */
+ pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
+
+/*** Check to make sure the PM reply has a valid beginning */
+ if(pmString[pmIdx] != 'S' && pmString[pmIdx+2] != 'T') {
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+/*** Create the structure of the support media */
+ /*** Count "Paper Size" field & check format */
+ for(; pmIdx < EPS_PM_MAXSIZE-7; ) { /* 7 = S x T x x // */
+ if(pmString[pmIdx] != 'S') {
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+
+ /* search size ID */
+ pmIdx++;
+ pMSize = NULL;
+ for(sIdx = 0; sIdx < innerPrinter->supportedMedia.numSizes; sIdx++){
+ if(pmString[pmIdx] == innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID){
+ pMSize = &innerPrinter->supportedMedia.sizeList[sIdx];
+/* EPS_DBGPRINT(("Size = %d\n", innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID))*/
+ break;
+ }
+ }
+
+ pmIdx++; /* move next field */
+
+ while( pmIdx < EPS_PM_MAXSIZE-4 ){ /* 4 = T x x / */
+ if(pmString[pmIdx] == 'T'){
+ if(NULL != pMSize){
+ /* search type ID */
+ pmIdx++;
+ for(tIdx = 0; tIdx < pMSize->numTypes; tIdx++){
+ if(pmString[pmIdx] == pMSize->typeList[tIdx].mediaTypeID){
+ pMSize->typeList[tIdx].paperSource = pmString[pmIdx+1];
+#if !_VALIDATE_SUPPORTED_MEDIA_DATA_
+ pMSize->typeList[tIdx].paperSource &= EPS_MPID_ALL_ESCPR;
+#endif
+ pmIdx += 3;
+ break;
+ }
+ }
+ if(tIdx >= pMSize->numTypes){
+ /* Skip unknown T */
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ printf("\n\n!!!!!!!!! pm2 contains TypeID(0x%02X) that doesn't exist in pm1. !!!!!!!!!\n", pmString[pmIdx]);
+#endif
+ pmIdx += 3;
+ }
+ } else{
+ /* Skip unknown S */
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ printf("\n\n!!!!!!!!! pm2 contains SizeID(0x%02X) that doesn't exist in pm1. !!!!!!!!!\n", pmString[pmIdx]);
+#endif
+ pmIdx += 4;
+ }
+ } else if(pmString[pmIdx] == '/') {
+ pmIdx++;
+ break;
+ } else{
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+ }
+ if(pmIdx >= EPS_PM_MAXSIZE-4){
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+
+ /* If we run into an occurrence of carriage return followed by line feed,
+ * we have found the terminating characters of the string. */
+ if(pmString[pmIdx] == 0x0D && pmString[pmIdx+1] == 0x0A) {
+ break;
+ }
+ }
+ if(pmIdx >= EPS_PM_MAXSIZE){
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: GetJpgMax() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* innerPrinter EPS_PRINTER_INN* IO: printer that it has original structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* */
+/* Description: */
+/* Marge paper source to EPS_SUPPORTED_MEDIA. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE GetJpgMax(
+
+ EPS_PRINTER_INN* printer
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT8 pmString[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
+ EPS_INT32 pmSize = EPS_PM_MAXSIZE;
+ EPS_UINT32 pmIdx; /* pm string index */
+
+ EPS_LOG_FUNCIN;
+
+ if( !EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){ /* Uni direction */
+ /* set unlimited(2GB) */
+ printer->JpgMax = EPS_JPEG_SIZE_UNLIMIT;
+ EPS_RETURN( EPS_ERR_NONE )
+ }
+
+ /* Clear the Printer Model Information (Media data or "PM" data) */
+ memset(pmString, 0, EPS_PM_MAXSIZE);
+
+/*** Get PM1 from Printer */
+ ret = prtGetPMString(printer, 1, pmString, &pmSize);
+ if(ret == EPS_ERR_PROTOCOL_NOT_SUPPORTED){
+ /* set unlimited(2GB) */
+ printer->JpgMax = EPS_JPEG_SIZE_UNLIMIT;
+ EPS_RETURN( EPS_ERR_NONE )
+ } else if(ret != EPS_ERR_NONE){
+ EPS_RETURN( ret );
+ }
+
+/*** "Filter" Raw "PM" data (Remake the correct pm stirng) */
+ ret = _SP_ChangeSpec_UpdatePMReply(printer, pmString, pmSize);
+ if (ret != EPS_ERR_NONE) {
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* Invalid format */
+ }
+
+ /*** Is this really "PM" data */
+ if( strstr((const char*)pmString, "PM") == NULL ) {
+ EPS_DBGPRINT(("Get Model Info faild : ModelInfo = [%s]\r\n", pmString));
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+ /* Delete the command header of pm string */
+ pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
+ while( pmIdx < EPS_PM_MAXSIZE ) {
+ switch(pmString[pmIdx]) {
+ case 'M':
+ printer->JpgMax =
+ (pmString[pmIdx+1] << 24) + (pmString[pmIdx+2] << 16) + (pmString[pmIdx+3] << 8) + pmString[pmIdx+4];
+
+ pmIdx += 6;
+ break;
+
+ case 'R':
+ pmIdx += 6;
+ break;
+
+ case 'S':
+ /* move T field */
+ if(pmIdx < EPS_PM_MAXSIZE-2){
+ pmIdx += 2;
+ } else{
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+ for(; pmIdx < EPS_PM_MAXSIZE-4; pmIdx += 4) { /* 4 = T x x / */
+ if(pmString[pmIdx] == '/'){
+ pmIdx += 1;
+ break;
+ } else if(pmString[pmIdx] != 'T') {
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+ }
+ if(pmIdx >= EPS_PM_MAXSIZE-4){
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+ break;
+
+ default:
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+
+ /* If we run into an occurrence of carriage return followed by line feed,
+ * we have found the terminating characters of the string. */
+ if(pmString[pmIdx] == 0x0D && pmString[pmIdx+1] == 0x0A) {
+ break;
+ }
+ }
+ if(pmIdx >= EPS_PM_MAXSIZE || 0 == printer->JpgMax){
+ EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: DuplSupportedMedia() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* innerPrinter EPS_PRINTER_INN* I: printer that it has original structure */
+/* pMedia EPS_SUPPORTED_MEDIA* O: pointer to a distination */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Alloc memory failed */
+/* */
+/* Description: */
+/* Duplicate EPS_SUPPORTED_MEDIA to user buffer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE DuplSupportedMedia(
+
+ EPS_PRINTER_INN* innerPrinter,
+ EPS_SUPPORTED_MEDIA* pMedia
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT32 idx;
+
+ EPS_LOG_FUNCIN;
+
+ ClearSupportedMedia();
+
+ g_supportedMedia.JpegSizeLimit = innerPrinter->supportedMedia.JpegSizeLimit;
+ g_supportedMedia.resolution = innerPrinter->supportedMedia.resolution;
+ g_supportedMedia.numSizes = innerPrinter->supportedMedia.numSizes;
+ g_supportedMedia.sizeList = (EPS_MEDIA_SIZE*)EPS_ALLOC( sizeof(EPS_MEDIA_SIZE) * innerPrinter->supportedMedia.numSizes );
+ if( g_supportedMedia.sizeList ){
+ for(idx = 0; idx < innerPrinter->supportedMedia.numSizes; idx++) {
+ g_supportedMedia.sizeList[idx].mediaSizeID = innerPrinter->supportedMedia.sizeList[idx].mediaSizeID;
+ g_supportedMedia.sizeList[idx].numTypes = innerPrinter->supportedMedia.sizeList[idx].numTypes;
+ g_supportedMedia.sizeList[idx].typeList =
+ (EPS_MEDIA_TYPE*)EPS_ALLOC( sizeof(EPS_MEDIA_TYPE) * innerPrinter->supportedMedia.sizeList[idx].numTypes );
+ if( g_supportedMedia.sizeList[idx].typeList ){
+ memcpy(g_supportedMedia.sizeList[idx].typeList,
+ innerPrinter->supportedMedia.sizeList[idx].typeList,
+ sizeof(EPS_MEDIA_TYPE) * innerPrinter->supportedMedia.sizeList[idx].numTypes);
+ } else{
+ ret = EPS_ERR_MEMORY_ALLOCATION;
+ break;
+ }
+ }
+ } else{
+ ret = EPS_ERR_MEMORY_ALLOCATION;
+ }
+
+ if(EPS_ERR_NONE == ret){
+ /* Copy to out param */
+ pMedia->JpegSizeLimit = g_supportedMedia.JpegSizeLimit;
+ pMedia->resolution = g_supportedMedia.resolution;
+ pMedia->numSizes = g_supportedMedia.numSizes;
+ pMedia->sizeList = g_supportedMedia.sizeList;
+
+ } else{
+ /* If error occur, unwind. */
+ for(idx = 0; idx < g_supportedMedia.numSizes; idx++) {
+ EPS_SAFE_RELEASE(g_supportedMedia.sizeList[idx].typeList);
+ }
+ EPS_SAFE_RELEASE(g_supportedMedia.sizeList);
+ g_supportedMedia.numSizes = 0;
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: ClearSupportedMedia() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (none) */
+/* */
+/* Return value: */
+/* void */
+/* */
+/* Description: */
+/* Crean up inside list of supported media structure. */
+/* */
+/*******************************************|********************************************/
+void ClearSupportedMedia(
+
+ void
+
+){
+ EPS_INT32 idx;
+
+ EPS_LOG_FUNCIN;
+
+ /* Clear "supportedMedia" */
+ if( NULL != g_supportedMedia.sizeList){
+ for(idx = 0; idx < g_supportedMedia.numSizes; idx++) {
+ EPS_SAFE_RELEASE(g_supportedMedia.sizeList[idx].typeList);
+ }
+ EPS_SAFE_RELEASE(g_supportedMedia.sizeList);
+ g_supportedMedia.numSizes = 0;
+ }
+
+ EPS_RETURN_VOID;
+}
+
+/*_______________________________ epson-escpr-api.c ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-api.h b/lib/epson-escpr-api.h
new file mode 100644
index 0000000..2811577
--- /dev/null
+++ b/lib/epson-escpr-api.h
@@ -0,0 +1,114 @@
+/*_________________________________ epson-escpr-api.h _______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/PR Application Programming Interfaces */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPR_API_H__
+#define __EPSON_ESCPR_API_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*---------------------------------- Compile options --------------------------------*/
+/*******************************************|********************************************/
+/* GCOMSW_PRT_USE_USB Use USB printer. */
+/* GCOMSW_PRT_USE_LPR Use LPR printer. */
+/* GCOMSW_PRT_USE_RAW Use Raw printer. */
+
+/* GCOMSW_EL_CDLABEL Extend layout. Auto clipping at CD/DVD label print. (RGB only) */
+
+/* GCOMSW_DEBUG Enable Debug monde. */
+
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+#include "epson-escpr-def.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-media.h"
+
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+/*-------------------------------- Global Declarations ------------------------------*/
+/*******************************************|********************************************/
+
+/*---------------------------- API Function Declarations ----------------------------*/
+/*******************************************|********************************************/
+ /*** Printing API */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE epsInitDriver (EPS_INT32, const EPS_USB_FUNC*,
+ const EPS_NET_FUNC*, const EPS_CMN_FUNC* );
+extern EPS_ERR_CODE epsReleaseDriver (void );
+extern EPS_ERR_CODE epsSetPrinter (const EPS_PRINTER* );
+extern EPS_ERR_CODE epsStartJob (const EPS_JOB_ATTRIB* );
+extern EPS_ERR_CODE epsStartPage (const EPS_PAGE_ATTRIB* );
+extern EPS_ERR_CODE epsSendData (EPS_PRN_DATA* );
+extern EPS_ERR_CODE epsPrintBand (const EPS_UINT8*, EPS_UINT32, EPS_UINT32* );
+extern EPS_ERR_CODE epsEndPage (EPS_BOOL );
+extern EPS_ERR_CODE epsEndJob (void );
+extern EPS_ERR_CODE epsCancelJob (EPS_INT32 );
+extern EPS_ERR_CODE epsContinueJob (void );
+
+extern EPS_ERR_CODE epsSetAdditionalData (EPS_UINT32, const void* );
+extern EPS_ERR_CODE epsRemAdditionalData (EPS_UINT32 );
+
+ /*** Find Printer Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE epsFindPrinter (EPS_INT32, EPS_UINT32 );
+extern EPS_ERR_CODE epsProbePrinter (const EPS_PROBE* );
+extern EPS_ERR_CODE epsCancelFindPrinter (void );
+
+ /*** Get Status Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE epsGetStatus (EPS_STATUS* );
+extern EPS_ERR_CODE epsGetInkInfo (EPS_INK_INFO* );
+
+ /*** Get Supported Media Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE epsGetSupportedMedia (EPS_SUPPORTED_MEDIA* );
+
+ /*** Get Printable Area */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE epsGetPrintableArea (EPS_JOB_ATTRIB*, EPS_UINT32*, EPS_UINT32* );
+
+ /*** Maintenance Command function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE epsMakeMainteCmd (EPS_INT32, EPS_UINT8*, EPS_UINT32* );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPR_API_H__ */
+
+/*_________________________________ epson-escpr-api.h _______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-dbg.c b/lib/epson-escpr-dbg.c
new file mode 100644
index 0000000..683f0aa
--- /dev/null
+++ b/lib/epson-escpr-dbg.c
@@ -0,0 +1,461 @@
+/*________________________________ epson-escpr-dbg.c ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of copyrightable
+ * material and information now allowed by statutory or judicial law or hereinafter
+ * granted, including without limitation, material generated from the software
+ * programs which are displayed on the screen such as icons, screen display looks,
+ * etc.
+ */
+/****************************************************************************************/
+/* debug utility */
+/****************************************************************************************/
+
+#ifdef GCOMSW_DEBUG
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-def.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-dbg.h"
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_CMN_FUNC epsCmnFnc;
+
+
+/*-------------------------------- Local Definition ---------------------------------*/
+/*******************************************|********************************************/
+
+
+/*-------------------------------- Local Functions ----------------------------------*/
+/*******************************************|********************************************/
+
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+#ifdef WIN32
+#include <crtdbg.h>
+#endif
+
+#ifdef WINCE
+#include <windef.h>
+#include <winnt.h>
+#include <dbgapi.h>
+#endif
+
+static FILE *g_pLogFile = NULL;
+
+
+/* ------------------------------------------------------------------------------------ */
+/* Leak check */
+typedef struct _tagEPS_DBG_MEMINFO {
+ void *pAddress;
+ EPS_UINT32 size;
+ unsigned long nLine;
+ char szFile[64];
+}EPS_DBG_MEMINFO;
+
+#define EPS_DBG_MEMINFO_NUM (100)
+
+
+EPS_DBG_MEMINFO g_EpsDbgMemInfo[EPS_DBG_MEMINFO_NUM];
+EPS_UINT32 g_nCurSize = 0;
+EPS_UINT32 g_nPeakSize = 0;
+
+
+void dbgMemInit()
+{
+ memset( g_EpsDbgMemInfo, 0, sizeof(g_EpsDbgMemInfo) );
+ dbgMemResetPeak();
+}
+
+void dbgMemResetPeak()
+{
+ g_nPeakSize = g_nCurSize;
+}
+
+void dbgMemReportPeak()
+{
+#if defined(unix) || defined(__unix)
+ fprintf(stderr, "*** peak memory size = %d byte ***\n", g_nPeakSize);
+#elif defined(WIN32)
+ _RPT1(_CRT_WARN, "*** peak memory size = %d byte ***\n", g_nPeakSize);
+#elif defined(WINCE)
+ NKDbgPrintfW(L"*** peak memory size = %d ***\n", g_nPeakSize);
+#endif
+}
+
+EPS_UINT32 dbgMemGetPeak()
+{
+ return g_nPeakSize;
+}
+
+void dbgMemReportLeak()
+{
+ int i;
+ for(i = 0; i < EPS_DBG_MEMINFO_NUM; i++){
+ if( 0 != g_EpsDbgMemInfo[i].pAddress ){
+#if defined(unix) || defined(__unix)
+ fprintf(stderr, "!***** memory leak *****! %s (%ld) Size: %d / Addr: 0x%08X\n",
+ g_EpsDbgMemInfo[i].szFile, g_EpsDbgMemInfo[i].nLine, g_EpsDbgMemInfo[i].size, (EPS_UINT32)g_EpsDbgMemInfo[i].pAddress);
+#elif defined(WIN32)
+ _RPT4(_CRT_WARN, "!***** memory leak *****! %s (%d) Size: %d / Addr: 0x%08X\n",
+ g_EpsDbgMemInfo[i].szFile, g_EpsDbgMemInfo[i].nLine, g_EpsDbgMemInfo[i].size, g_EpsDbgMemInfo[i].pAddress);
+#elif defined(WINCE)
+ NKDbgPrintfW(L"!***** memory leak *****! %hs (%d) Addr: 0x%08X\n",
+ g_EpsDbgMemInfo[i].szFile, g_EpsDbgMemInfo[i].nLine, g_EpsDbgMemInfo[i].pAddress);
+#endif
+ }
+ }
+}
+
+
+void *dbgAlloc( EPS_INT8 *pszFile, EPS_INT32 nLine, EPS_UINT32 s )
+{
+ int i;
+ char *pFile;
+ void *p = epsCmnFnc.memAlloc(s);
+
+ if( NULL != p ){
+ for(i = 0; i < EPS_DBG_MEMINFO_NUM; i++){
+ if( NULL == g_EpsDbgMemInfo[i].pAddress ){
+ g_EpsDbgMemInfo[i].pAddress = p;
+ g_EpsDbgMemInfo[i].size = s;
+ g_EpsDbgMemInfo[i].nLine = nLine;
+#if defined(unix) || defined(__unix)
+ pFile = strrchr(pszFile, '/');
+ strcpy(g_EpsDbgMemInfo[i].szFile, (pFile?pFile:pszFile));
+#else
+ pFile = strrchr(pszFile, '\\');
+ strcpy(g_EpsDbgMemInfo[i].szFile, ++pFile);
+#endif
+ break;
+ }
+ }
+ if(i >= EPS_DBG_MEMINFO_NUM){
+#if defined(unix) || defined(__unix)
+ fprintf(stderr, "!!! WAN Debuginfo space not enough! \n");
+#elif defined(WIN32)
+ _RPT0(_CRT_WARN, "!!! WAN Debuginfo space not enough! \n");
+#elif defined(WINCE)
+ NKDbgPrintfW(L"!!! WAN Debuginfo space not enough! \n");
+#endif
+ }
+
+ g_nCurSize += s;
+
+ g_nPeakSize = ((g_nPeakSize > g_nCurSize)?g_nPeakSize:g_nCurSize);
+
+#if 0 /*defined(WIN32)*/
+ {
+ char* pSrc = strrchr(pszFile, '\\');
+ _RPT_BASE((_CRT_WARN, NULL, 0, NULL,
+ "ALC : %s(%d)\t+%5d -> %5d(%5d)\n", pSrc, nLine, s, g_nCurSize, g_nPeakSize));
+ }
+#endif
+
+ }
+
+ return p;
+}
+
+
+void dbgFree(void *p)
+{
+ int i;
+
+ if(NULL == p){
+ return;
+ }
+
+ for(i = 0; i < EPS_DBG_MEMINFO_NUM; i++){
+ if( p == g_EpsDbgMemInfo[i].pAddress ){
+ g_nCurSize -= g_EpsDbgMemInfo[i].size;
+ g_EpsDbgMemInfo[i].pAddress = NULL;
+
+#if 0/* defined(WIN32)*/
+ {
+ _RPT_BASE((_CRT_WARN, NULL, 0, NULL,
+ "FRR : %s(%d)\t-%5d -> %5d(%5d)\n",
+ g_EpsDbgMemInfo[i].szFile, g_EpsDbgMemInfo[i].nLine, g_EpsDbgMemInfo[i].size, g_nCurSize, g_nPeakSize));
+ }
+#endif
+
+ break;
+ }
+ }
+ if(i >= EPS_DBG_MEMINFO_NUM){
+#if defined(unix) || defined(__unix)
+ fprintf(stderr, "!!! WAN mem 0x%08X not found \n", (EPS_UINT32)p);
+#elif defined(WIN32)
+ _RPT1(_CRT_WARN, "!!! WAN mem 0x%08X not found \n", p);
+#elif defined(WINCE)
+ NKDbgPrintfW(L"!!! WAN mem 0x%08X not found \n", p);
+#endif
+ }
+
+ epsCmnFnc.memFree( p );
+}
+
+
+/* ------------------------------------------------------------------------------------ */
+/* Print */
+#define EPSN_MAX_MESSAGE (255)
+
+static EPS_INT8 g_DebugMsg[EPSN_MAX_MESSAGE+1];
+
+char *dbgPrintHlp(const char* frm, ...)
+{
+ int nLen = 0;
+ va_list ptr;
+
+ va_start(ptr, frm);
+#if defined(unix) || defined(__unix)
+ nLen = vsnprintf(g_DebugMsg, EPSN_MAX_MESSAGE, frm, ptr);
+#elif defined(WIN32) || defined(WINCE)
+ nLen = _vsnprintf(g_DebugMsg, EPSN_MAX_MESSAGE, frm, ptr);
+#endif
+ va_end(ptr);
+
+ if(nLen > 0 && nLen < EPSN_MAX_MESSAGE){
+ *(g_DebugMsg+nLen) = '\0';
+ } else{
+ *(g_DebugMsg+EPSN_MAX_MESSAGE) = '\0';
+ }
+ return g_DebugMsg;
+}
+
+
+void dbgPrint(EPS_INT8 *pszSrcFile, EPS_INT32 nSrcLine, EPS_INT8 *pMsg)
+{
+#if defined(unix) || defined(__unix)
+ char* pFile = strrchr(pszSrcFile, '/');
+ fprintf(stderr, "%s(%d): %s", (pFile?pFile:pszSrcFile), nSrcLine, pMsg);
+#elif defined(WIN32)
+ char* pFile = strrchr(pszSrcFile, '\\');
+ if(g_pLogFile){
+ fprintf(g_pLogFile, "%s(%d): %s", ++pFile, nSrcLine, pMsg);
+ } else{
+ _RPT3(_CRT_WARN, "%s(%d): %s", ++pFile, nSrcLine, pMsg);
+ }
+#elif defined(WINCE)
+ char* pFile = strrchr(pszSrcFile, '\\');
+ NKDbgPrintfW(L"%hs(%d): %hs", ++pFile, nSrcLine, pMsg);
+#endif
+}
+
+
+void dbgDumpStr(EPS_INT8 *pszSrcFile, EPS_INT32 nSrcLine, EPS_INT8 *p)
+{
+ unsigned long n = 0;
+ EPS_UINT32 pos = 0;
+ char c;
+ char *pFile;
+ EPS_UINT32 nLen = (EPS_UINT32)strlen(p);
+
+#if defined(unix) || defined(__unix)
+ pFile = strrchr(pszSrcFile, '/');
+ fprintf(stderr, "--- Dump String [%d] src: %s[%d] ---\n", nLen, (pFile?pFile:pszSrcFile), nSrcLine);
+#elif defined(WIN32)
+ pFile = strrchr(pszSrcFile, '\\');
+ _RPT3(_CRT_WARN, "--- Dump String [%d] src: %s[%d] ---\r\n", nLen, ++pFile, nSrcLine);
+#elif defined(WINCE)
+ pFile = strrchr(pszSrcFile, '\\');
+ NKDbgPrintfW(L"--- Dump String [%d] ---\n", nLen);
+#endif
+
+ for(n = 0; n < nLen; n += 255){
+ if(n+255 < nLen){
+ pos = 255;
+ } else{
+ pos = nLen - n;
+ }
+
+ c = *(p + n + pos);
+ *(p + n + pos) = '\0';
+#if defined(unix) || defined(__unix)
+ printf("%s\n", p+n);
+#elif defined(WIN32)
+ _RPT1(_CRT_WARN, "%s\n", p+n);
+#elif defined(WINCE)
+ NKDbgPrintfW(L"%hs\n", p+n);
+#endif
+ *(p + n + pos) = c;
+ }
+}
+
+
+void dbgDump(EPS_INT8 *pszSrcFile, EPS_INT32 nSrcLine, EPS_INT8 *p, EPS_UINT32 s)
+{
+#define EPSNET_DUMP_LINEBYTE (76)
+ int i;
+ EPS_UINT32 nCnt = 0;
+ char cBin[64];
+ char cChar[32];
+ char cLines[EPSNET_DUMP_LINEBYTE*4+1];
+ int nLine = 0;
+ char *pFile = NULL;
+
+#if defined(unix) || defined(__unix)
+ pFile = strrchr(pszSrcFile, '/');
+ fprintf(stderr, "--- Dump src: %s[%d] // data: 0x%08X [%dbyte] ---\n", (pFile?pFile:pszSrcFile), nSrcLine, (EPS_INT32)p, s);
+#elif defined(WIN32)
+ pFile = strrchr(pszSrcFile, '\\');
+ _RPT4(_CRT_WARN, "--- Dump src: %s[%d] // data: 0x%08X [%dbyte] ---\n", ++pFile, nSrcLine, p, s);
+#elif defined(WINCE)
+ pFile = strrchr(pszSrcFile, '\\');
+ NKDbgPrintfW(L"--- Dump src: %hs[%d] // data: 0x%08X [%dbyte] ---\n", ++pFile, nSrcLine, p, s);
+#endif
+
+ while( nCnt < s ){
+ for(i = 0; i < 16 && nCnt < s; i++, nCnt++){
+ sprintf(&cBin[i*3], "%02X ", (unsigned char)*(p + nCnt));
+ cChar[i] = ( 0x20 <= *(p + nCnt) && *(p + nCnt) <= 0x7e)?(*(p + nCnt)):'.';
+ }
+ cBin[i*3] = cChar[i] = '\0';
+
+ sprintf(cLines + (EPSNET_DUMP_LINEBYTE * nLine), "%08X %-48s %s\r\n", nCnt - i, cBin, cChar);
+ nLine++;
+
+ if(nLine >= 4){
+#if defined(unix) || defined(__unix)
+ fprintf(stderr, "%s", cLines);
+#elif defined(WIN32)
+ _RPT1(_CRT_WARN, "%s", cLines);
+#elif defined(WINCE)
+ NKDbgPrintfW(L"%hs", cLines);
+#endif
+ nLine = 0;
+ }
+ }
+
+ if(nLine > 0 && nLine < 4){
+#if defined(unix) || defined(__unix)
+ fprintf(stderr, "%s", cLines);
+#elif defined(WIN32)
+ _RPT1(_CRT_WARN, "%s", cLines);
+#elif defined(WINCE)
+ NKDbgPrintfW(L"%hs", cLines);
+#endif
+ }
+}
+
+
+/* ------------------------------------------------------------------------------------ */
+/* Runtime LOG */
+static long g_logModule = EPS_LOG_MODULE_NONE;
+static long g_logFuncLv = 0;
+/*static FILE *g_pLogFile = NULL;*/
+
+void dbgLogInit(const EPS_INT8 *pszFile, EPS_UINT32 nModule)
+{
+ if(pszFile){
+ if(g_pLogFile){
+ fclose(g_pLogFile);
+ }
+
+ g_pLogFile = fopen(pszFile, "w");
+ }
+
+ g_logModule = nModule;
+}
+
+void dbgLogTrem()
+{
+ if(g_pLogFile){
+ fclose(g_pLogFile);
+ g_pLogFile = NULL;
+ }
+
+ g_logModule = EPS_LOG_MODULE_NONE;
+}
+
+void dbgLogFunc(EPS_UINT32 nModule, EPS_INT8 *pszFunc, EPS_BOOL blnIn, EPS_INT32 nLine, EPS_ERR_CODE e, EPS_UINT32 tm)
+{
+ char szTag[256];
+#if defined(unix) || defined(__unix)
+ char *pFile;
+ pFile = strrchr(pszFunc, '/');
+ if(pFile)pszFunc = pFile;
+#endif
+
+#define EPS_DBGTAG_LEN 48
+
+ if(g_logModule & nModule){
+ memset(szTag, ' ', EPS_DBGTAG_LEN);
+ if(blnIn){
+ sprintf(szTag + g_logFuncLv*2, "+ %s", pszFunc);
+ szTag[strlen(szTag)] = ' ';
+ sprintf(szTag + EPS_DBGTAG_LEN, "L:%d\tTM:%d", nLine, tm);
+ g_logFuncLv++;
+ } else{
+ if(g_logFuncLv>0)g_logFuncLv--;
+ sprintf(szTag + g_logFuncLv*2, "- %s(%d)", pszFunc, e);
+ szTag[strlen(szTag)] = ' ';
+ sprintf(szTag + EPS_DBGTAG_LEN, " L:%d\tTM:%d", nLine, tm);
+ }
+
+ if(g_pLogFile){
+ fprintf(g_pLogFile, "%s\n", szTag);
+ } else{
+#if defined(unix) || defined(__unix)
+ fprintf(stderr, "%s\r\n", szTag);
+#elif defined(WIN32)
+ _RPT1(_CRT_WARN, "%s\n", szTag);
+#elif defined(WINCE)
+ NKDbgPrintfW(L"%s\n", szTag);
+#endif
+ }
+ }
+}
+
+
+
+/* ------------------------------------------------------------------------------------ */
+/* Dump to file */
+FILE *g_pDmpFile = NULL;
+FILE *dbgDumpFileOpen(EPS_INT8 *pszFile)
+{
+ FILE *hFile = fopen(pszFile, "wb");
+ return hFile;
+}
+
+
+void dbgDumpFileClose(FILE *hFile)
+{
+ if(hFile)fclose(hFile);
+}
+
+
+void dbgDumpFileWrite(FILE *hFile, const void *pData, size_t nSize)
+{
+ if(hFile)fwrite(pData, nSize, 1, hFile);
+}
+
+
+#endif /* GCOMSW_DEBUG */
+
+/*________________________________ epson-escpr-dbg.c _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-dbg.h b/lib/epson-escpr-dbg.h
new file mode 100644
index 0000000..1dfa8d8
--- /dev/null
+++ b/lib/epson-escpr-dbg.h
@@ -0,0 +1,183 @@
+/*_______________________________ epson-escpr-dbg.h ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+* Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+*
+* Copyright protection claimed includes all forms and matters of
+* copyrightable material and information now allowed by statutory or judicial
+* law or hereinafter granted, including without limitation, material generated
+* from the software programs which are displayed on the screen such as icons,
+* screen display looks, etc.
+*
+*/
+/*******************************************|********************************************/
+/* */
+/* Epson debuger Module Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef _EPSON_ESPCR_DBG_H_
+#define _EPSON_ESPCR_DBG_H_
+#ifdef __cplusplus
+extern "C" {
+#endif /* def __cplusplus */
+
+#ifdef GCOMSW_DEBUG
+
+/*------------------------------- Global Compiler Switch -------------------------------*/
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+#include "epson-escpr-pvt.h"
+
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+/*** memory */
+/*** -----------------------------------------------------------------------------------*/
+extern void dbgMemInit();
+extern void dbgMemResetPeak();
+extern void dbgMemReportPeak();
+extern EPS_UINT32 dbgMemGetPeak();
+extern void dbgMemReportLeak();
+extern void *dbgAlloc(EPS_INT8 *pszFile, EPS_INT32 nLine, EPS_UINT32 s);
+extern void dbgFree(void *p);
+
+#define EPS_MEM_INIT dbgMemInit();
+#define EPS_MEM_RESET_PEAK dbgMemResetPeak();
+#define EPS_MEM_REPORT_PEAK dbgMemReportPeak();
+#define EPS_MEM_GET_PEAK dbgMemGetPeak()
+#define EPS_MEM_REPORT_LEAK dbgMemReportLeak();
+#define EPS_ALLOC( s ) dbgAlloc( __FILE__, __LINE__, (EPS_UINT32)s )
+#define EPS_FREE( p ) dbgFree( (void*)p )
+
+
+/*** PRINT */
+/*** -----------------------------------------------------------------------------------*/
+extern char *dbgPrintHlp(const char* frm, ...);
+extern void dbgPrint(EPS_INT8 *pszSrcFile, EPS_INT32 nSrcLine, EPS_INT8 *pMsg);
+
+ #define EPS_DBGPRINT( f ) { \
+ char *pLine = dbgPrintHlp f; \
+ dbgPrint(__FILE__, __LINE__, pLine); \
+ }
+
+ /* Dump */
+extern void dbgDump(EPS_INT8 *pszFile, EPS_INT32 nLine, EPS_INT8* p, EPS_UINT32 s);
+ #define EPS_DUMP( p, s ) dbgDump(__FILE__, __LINE__, (EPS_INT8*)p, s);
+
+extern void dbgDumpStr(EPS_INT8 *pszSrcFile, EPS_INT32 nSrcLine, EPS_INT8 *p);
+ #define EPS_DUMP_STR( str ) dbgDumpStr(__FILE__, __LINE__, str);
+
+
+/*** Runtime LOG */
+/*** -----------------------------------------------------------------------------------*/
+extern void dbgLogInit(const EPS_INT8 *pszFile, EPS_UINT32 nModule);
+extern void dbgLogTrem();
+extern void dbgLogFunc(EPS_UINT32 nModule, EPS_INT8 *pszFunc, EPS_BOOL blnIn,
+ EPS_INT32 nLine, EPS_ERR_CODE e, EPS_UINT32 tm);
+
+ #define EPS_LOG_INITIALIZE(f, m) dbgLogInit(f, m);
+ #define EPS_LOG_TREMINATE dbgLogTrem();
+ #define EPS_LOG_MODULE_NONE (0x0000)
+ #define EPS_LOG_MODULE_API (0x0001)
+ #define EPS_LOG_MODULE_PRTCOL (0x0002)
+ #define EPS_LOG_MODULE_PAGE (0x0004)
+ #define EPS_LOG_MODULE_USB (0x0010)
+ #define EPS_LOG_MODULE_LPR (0x0020)
+ /*#define EPS_LOG_MODULE_UPNP (0x0040)*/
+ #define EPS_LOG_MODULE_RAW (0x0080)
+ #define EPS_LOG_MODULE_CBT (0x0100)
+ #define EPS_LOG_MODULE_SER (0x0200)
+
+
+#if defined(__func__) /* C99 */
+#define EPS_FUNCNAME __func__
+#elif defined(__FUNCTION__) /* Visual Studio */
+#define EPS_FUNCNAME __FUNCTION__
+#else
+#define EPS_FUNCNAME __FILE__
+#endif
+
+#if defined(EPS_FUNCNAME)
+#define EPS_LOG_FUNCIN_L(l) \
+ EPS_UINT32 prtm = 0; \
+ if(epsCmnFnc.getTime){ \
+ prtm = epsCmnFnc.getTime(); \
+ dbgLogFunc(EPS_LOG_MODULE, EPS_FUNCNAME, TRUE, l, 0, epsCmnFnc.getTime()); \
+ } else{ \
+ dbgLogFunc(EPS_LOG_MODULE, EPS_FUNCNAME, TRUE, l, 0, 0); \
+ }
+
+ #define EPS_LOG_FUNCOUT(l, e) \
+ if(epsCmnFnc.getTime){ \
+ dbgLogFunc(EPS_LOG_MODULE, EPS_FUNCNAME, FALSE, l, e, epsCmnFnc.getTime() - prtm); \
+ } else{ \
+ dbgLogFunc(EPS_LOG_MODULE, EPS_FUNCNAME, FALSE, l, e, 0); \
+ }
+ #define EPS_LOG_FUNCIN EPS_LOG_FUNCIN_L(__LINE__)
+ #define EPS_RETURN( e ) { \
+ EPS_INT32 res = e; \
+ EPS_LOG_FUNCOUT(__LINE__, res); \
+ return res; \
+ }
+
+ #define EPS_RETURN_VOID { \
+ EPS_LOG_FUNCOUT(__LINE__, 0); \
+ return; \
+ }
+
+#else
+ #define EPS_LOG_FUNCIN
+ #define EPS_LOG_FUNCOUT(e)
+ #define EPS_RETURN(e) return e;
+ #define EPS_RETURN_VOID return;
+#endif
+
+/*** Dump to file */
+/*** -----------------------------------------------------------------------------------*/
+extern FILE *dbgDumpFileOpen(EPS_INT8 *pszFile);
+extern void dbgDumpFileClose(FILE *hFile);
+extern void dbgDumpFileWrite(FILE *hFile, const void *pData, size_t nSize);
+
+ #define DECRALE_DMP_FILE extern FILE *g_pDmpFile;
+ #define EPS_DF_OPEN( fn ) \
+ { \
+ g_pDmpFile = dbgDumpFileOpen( fn ); \
+ }
+ #define EPS_DF_CLOSE \
+ { \
+ dbgDumpFileClose( g_pDmpFile ); \
+ g_pDmpFile = NULL; \
+ }
+ #define EPS_DF_WRITE( p, s ) \
+ if( g_pDmpFile ) \
+ { \
+ dbgDumpFileWrite(g_pDmpFile, p, s ); \
+ }
+
+#endif /* GCOMSW_DEBUG */
+
+
+#ifdef __cplusplus
+}
+#endif /* def __cplusplus */
+
+#endif /* def _EPSON_ESPCR_DBG_H_ */
+
+/*_______________________________ epson-escpr-dbg.h ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-def.h b/lib/epson-escpr-def.h
new file mode 100644
index 0000000..51a9800
--- /dev/null
+++ b/lib/epson-escpr-def.h
@@ -0,0 +1,630 @@
+/*________________________________ epson-escpr-def.h ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/PR External Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPR_DEF_2_H__
+#define __EPSON_ESCPR_DEF_2_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+ /*** Maximum Ink Cartridge Number */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_INK_NUM 20
+
+ /*** Buffer size for manufacter name and model name */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_NAME_BUFFSIZE 64
+#define EPS_PRNID_BUFFSIZE 128
+#define EPS_ADDR_BUFFSIZE 32
+
+ /*** Communication Mode */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_COMM_UNID 0x00000001 /* Uni-Directional Communication */
+#define EPS_COMM_BID 0x00000002 /* Bi-Directional Communication */
+
+ /*** print protocol */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PROTOCOL_INVALID 0x00000000 /* Invalid */
+#define EPS_PROTOCOL_USB 0x00000010 /* USB */
+/*#define EPS_PROTOCOL_UPNP 0x00000020 UPnP */
+#define EPS_PROTOCOL_LPR 0x00000040 /* LPR */
+#define EPS_PROTOCOL_RAW 0x00000080 /* RAW Port */
+#define EPS_PROTOCOL_NET (EPS_PROTOCOL_LPR | EPS_PROTOCOL_RAW) /* All Network */
+#define EPS_PROTOCOL_ALL (EPS_PROTOCOL_USB | EPS_PROTOCOL_NET) /* All */
+
+#define EPS_COMM_USB_UNID (EPS_COMM_UNID | EPS_PROTOCOL_USB ) /* USB Uni-Directional Communication */
+#define EPS_COMM_USB_BID (EPS_COMM_BID | EPS_PROTOCOL_USB ) /* USB Bi-Directional Communication */
+#define EPS_COMM_LPR_UNID (EPS_COMM_UNID | EPS_PROTOCOL_LPR ) /* LPR Uni-Directional Communication */
+#define EPS_COMM_LPR_BID (EPS_COMM_BID | EPS_PROTOCOL_LPR ) /* LPR Bi-Directional Communication */
+#define EPS_COMM_RAW_UNID (EPS_COMM_UNID | EPS_PROTOCOL_RAW ) /* RAW Uni-Directional Communication */
+#define EPS_COMM_RAW_BID (EPS_COMM_BID | EPS_PROTOCOL_RAW ) /* RAW Bi-Directional Communication */
+#define EPS_COMM_NET_UNID (EPS_COMM_UNID | EPS_PROTOCOL_NET ) /* Net Uni-Directional Communication */
+#define EPS_COMM_NET_BID (EPS_COMM_BID | EPS_PROTOCOL_NET ) /* Net Bi-Directional Communication */
+#define EPS_COMM_ALL_UNID (EPS_COMM_USB_UNID | EPS_COMM_NET_UNID) /* USB & Net Uni-Directional Communication */
+#define EPS_COMM_ALL_BID (EPS_COMM_USB_BID | EPS_COMM_NET_BID) /* USB & Net Bi-Directional Communication */
+
+ /*** sub protocol */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_SUBPROTOCOL_PCDEV 0x00001000 /* UPnP PC device */
+
+ /* mask */
+#define EPS_PRT_MASK_DIRECTION 0x0000000F
+#define EPS_PRT_MASK_PROTOCOL 0x00000FF0
+#define EPS_PRT_MASK_SUBPROTOCOL 0x0000F000
+
+#define EPS_PRT_DIRECTION(p) ( (p) & EPS_PRT_MASK_DIRECTION )
+#define EPS_PRT_PROTOCOL(p) ( (p) & EPS_PRT_MASK_PROTOCOL )
+#define EPS_PRT_SUBPROTOCOL(p) ( (p) & EPS_PRT_MASK_SUBPROTOCOL )
+#define EPS_PRT_PROTOCOL_EX(p) ( (p) & (EPS_PRT_MASK_PROTOCOL | EPS_PRT_MASK_SUBPROTOCOL) )
+#define EPS_IS_BI_PROTOCOL(p) ( ( (p) & EPS_COMM_BID) == EPS_COMM_BID )
+
+
+ /*** print language */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_LANG_UNKNOWN (0)
+#define EPS_LANG_ESCPR (1) /* ESC/P-R */
+#define EPS_LANG_ESCPAGE (2) /* ESC/Page(Mono) */
+#define EPS_LANG_ESCPAGE_COLOR (3) /* ESC/Page-Color */
+
+ /*** probe method */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PRB_BYID 1 /* probe by ID string */
+#define EPS_PRB_BYADDR 2 /* probe by IP Address */
+
+
+ /*** Supported functions */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_SPF_RGBPRINT 0x0001 /* bitmap print. */
+#define EPS_SPF_JPGPRINT 0x0002 /* jpeg print. */
+/*#define EPS_SPF_PAPERSOURCE 0x0004 Specify the Paper source. epsStatPage() */
+
+
+ /*** Print Page Attribute Values */
+ /*** -------------------------------------------------------------------------------*/
+ /*** Media Size */
+ /*** ---------------------------------------------------------------------------*/
+/*** See EPS_MSID_* in epson-escpr-media.h */
+
+ /*** Media Type */
+ /*** ---------------------------------------------------------------------------*/
+/*** See EPS_MTID_* in epson-escpr-media.h */
+
+ /*** Border Mode */
+ /*** ---------------------------------------------------------------------------*/
+/*** See EPS_MTID_* in epson-escpr-media.h */
+
+ /*** Print Quality */
+ /*** ---------------------------------------------------------------------------*/
+/*** See EPS_MTID_* in epson-escpr-media.h */
+
+ /*** Color Mode */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_CM_COLOR 0 /* Color */
+#define EPS_CM_MONOCHROME 1 /* Monochrome */
+#define EPS_CM_SEPIA 2 /* Sepia */
+
+
+ /*** In (input image) Resolution */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_IR_360X360 (1 << 0) /* 360 x 360 dpi */
+#define EPS_IR_720X720 (1 << 1) /* 720 x 720 dpi */
+#define EPS_IR_150X150 (1 << 2) /* 150 x 150 dpi */
+#define EPS_IR_300X300 (1 << 3) /* 300 x 300 dpi */
+#define EPS_IR_600X600 (1 << 4) /* 600 x 600 dpi */
+
+ /*** Print Direction */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_PD_BIDIREC 0 /* Bi-direction */
+#define EPS_PD_UNIDIREC 1 /* Uni-direction */
+
+ /*** Color Plane */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_CP_FULLCOLOR 0 /* Full Color */
+#define EPS_CP_256COLOR 1 /* 256 Color */
+#define EPS_CP_JPEG 2 /* Jpeg */
+#define EPS_CP_PRINTCMD 3 /* Print command */
+
+ /*** Command data type */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_MNT_UNKNOWN 0 /* invalid type */
+#define EPS_MNT_CUSTOM 1 /* Cusutom data */
+#define EPS_MNT_CLEANING 2 /* Cleaning command data */
+#define EPS_MNT_NOZZLE 3 /* NozzleCheck command data */
+
+ /*** Palette Size */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Palette Data */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Brightness (range: -50 <= brightness <= 50) */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Contrast (range: -50 <= contrast <= 50) */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Saturation (range: -50 <= saturation <= 50) */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Top Margin */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Left Margin */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Bottom Margin */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** Right Margin */
+ /*** ---------------------------------------------------------------------------*/
+/*** Specified in Developer code */
+
+ /*** CD/DVD Inside Dimameter */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_CDDIM_IN_MIN 18
+#define EPS_CDDIM_IN_MAX 46
+#define EPS_CDDIM_IN_DEF 43
+
+ /*** CD/DVD Outside Dimameter */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_CDDIM_OUT_MIN 114
+#define EPS_CDDIM_OUT_MAX 120
+#define EPS_CDDIM_OUT_DEF 116
+
+ /*** APF Automatic Correction */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_APF_ACT_NOTHING 0 /* Nothing */
+#define EPS_APF_ACT_STANDARD 1 /* Standard (use Exif) */
+#define EPS_APF_ACT_PIM 2 /* use PIM */
+#define EPS_APF_ACT_PORTRATE 3 /* Portrate */
+#define EPS_APF_ACT_VIEW 4 /* View */
+#define EPS_APF_ACT_NIGHTVIEW 5 /* Night View */
+
+ /*** APF Redeye */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_APF_RDE_NOTHING 0 /* Nothing */
+#define EPS_APF_RDE_CORRECT 1 /* MoreSoft */
+
+ /*** max Jpeg data size */
+ /*** ---------------------------------------------------------------------------*/
+#define EPS_JPEG_SIZE_MAX (1024*1024*3) /* 3MB */
+#define EPS_JPEG_PIXEL_MAX (9600)
+#define EPS_JPEG_CHUNK_SIZE_MAX (1024*64-1) /* 0xFFFF max short */
+#define EPS_JPEG_SIZE_UNLIMIT ~(1<<(sizeof(EPS_INT32)*8-1)) /* 2GB */
+
+
+ /*** Layout template value */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_POS_HLEFT (-1)
+#define EPS_POS_HRIGHT (-2)
+#define EPS_POS_HCENTER (-3)
+#define EPS_POS_VTOP (-1)
+#define EPS_POS_VBOTTOM (-2)
+#define EPS_POS_VMIDDLE (-3)
+
+
+ /*** duplex */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_DUPLEX_NONE (0)
+#define EPS_DUPLEX_LONG (1 << 0)
+#define EPS_DUPLEX_SHORT (1 << 1)
+
+
+ /*** feed direction */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_FEEDDIR_PORTRAIT (0)
+#define EPS_FEEDDIR_LANDSCAPE (1)
+
+
+ /*** Ink Color */
+ /*** -------------------------------------------------------------------------------*/
+enum EPS_COLOR {
+ EPS_COLOR_BLACK,
+ EPS_COLOR_CYAN,
+ EPS_COLOR_MAGENTA,
+ EPS_COLOR_YELLOW,
+ EPS_COLOR_LIGHTCYAN,
+ EPS_COLOR_LIGHTMAGENTA,
+ EPS_COLOR_LIGHTYELLOW,
+ EPS_COLOR_DARKYELLOW,
+ EPS_COLOR_LIGHTBLACK,
+ EPS_COLOR_RED,
+ EPS_COLOR_VIOLET,
+ EPS_COLOR_MATTEBLACK,
+ EPS_COLOR_LIGHTLIGHTBLACK,
+ EPS_COLOR_PHOTOBLACK,
+ EPS_COLOR_CLEAR,
+ EPS_COLOR_GRAY,
+ EPS_COLOR_UNKNOWN,
+
+ /* add ver5.0*/
+ EPS_COLOR_BLACK2,
+ EPS_COLOR_ORANGE,
+ EPS_COLOR_GREEN,
+ EPS_COLOR_WHITE,
+ EPS_COLOR_CLEAN
+};
+
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+ /*** Basic Rect Object */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_POS_ {
+ EPS_INT32 x;
+ EPS_INT32 y;
+} EPS_POS;
+
+ /*** Printer Infomation */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_PRINTER_ {
+ EPS_UINT32 supportFunc;
+ EPS_INT8 manufacturerName[EPS_NAME_BUFFSIZE];
+ EPS_INT8 modelName[EPS_NAME_BUFFSIZE];
+ EPS_INT8 friendlyName[EPS_NAME_BUFFSIZE];
+ EPS_INT8 location[EPS_ADDR_BUFFSIZE];
+ EPS_INT8 printerID[EPS_PRNID_BUFFSIZE];
+ /* ver 4.2 */
+ EPS_INT32 protocol; /* Communication protocol */
+ /* ver 5.0 */
+ EPS_UINT32 language; /* print language */
+ EPS_INT8 macAddress[EPS_ADDR_BUFFSIZE];
+} EPS_PRINTER;
+
+
+ /*** Job Attributes */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_JOB_ATTRIB_ {
+ EPS_UINT16 version; /* structure version */
+
+ /*** ------------------------------------------------------------------------------ */
+ /*** Source Image Attribute */
+ EPS_UINT8 colorPlane; /* Image color plane */
+ EPS_UINT16 paletteSize; /* Palette Size (if present) */
+ EPS_UINT8* paletteData; /* Palette Data (if present) */
+ EPS_UINT8 inputResolution; /* Input Image Resolution */
+
+ /*** ------------------------------------------------------------------------------ */
+ /*** Output Attribute */
+ EPS_INT32 mediaSizeIdx; /* Media Size Index (EPS_MSID_*) */
+ /* (see epson-escpr-media.h) */
+ EPS_INT32 mediaTypeIdx; /* Media Type Index (EPS_MTID_*) */
+ /* (see epson-escpr-media.h) */
+
+ EPS_UINT32 printLayout; /* Print Layout */
+ EPS_UINT32 printQuality; /* Print Quality */
+ EPS_UINT32 paperSource; /* Paper Source (Lv1 ext) */
+ EPS_UINT8 printDirection; /* Printing Direction */
+
+ EPS_UINT8 colorMode; /* Color Mode */
+ EPS_INT8 brightness; /* Print Brightness */
+ EPS_INT8 contrast; /* Print Contrast */
+ EPS_INT8 saturation; /* Print Saturation */
+ EPS_UINT8 apfAutoCorrect; /* APF Automatic (Jpeg only) */
+ EPS_INT8 sharpness; /* sharpness (Jpeg only) */
+ EPS_UINT8 redeye; /* redeye correct (Jpeg only) */
+
+ /*** Custom border ***/
+ EPS_INT16 topMargin; /* Desired Top print margin */
+ EPS_INT16 leftMargin; /* Desired Left print margin */
+ EPS_INT16 bottomMargin; /* Desired Bottom print margin */
+ EPS_INT16 rightMargin; /* Desired Right print margin */
+
+ /*** CD/DVD Label ***/
+ EPS_UINT8 cdDimIn; /* CD Diameter Inside */
+ EPS_UINT8 cdDimOut; /* CD Diameter Outside */
+
+ /* -------------------------------------------------------------------------------- */
+ /* Ver 2 */
+ EPS_INT32 cmdType; /* Print command type */
+
+ /* -------------------------------------------------------------------------------- */
+ /* Ver 3 */
+ EPS_INT32 duplex; /* Duplex print */
+ EPS_INT32 copies; /* copies count */
+ EPS_INT32 feedDirection; /* paper feed direction */
+} EPS_JOB_ATTRIB;
+
+#define EPS_JOB_ATTRIB_VER_1 1
+#define EPS_JOB_ATTRIB_VER_2 2
+#define EPS_JOB_ATTRIB_VER_3 3
+#define EPS_JOB_ATTRIB_VER_CUR EPS_JOB_ATTRIB_VER_3
+
+
+ /*** Page Attributes */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_PAGE_ATTRIB_ {
+ EPS_UINT16 version; /* structure version */
+} EPS_PAGE_ATTRIB;
+#define EPS_PAGE_ATTRIB_VERS_0 0
+#define EPS_PAGE_ATTRIB_VER_CUR EPS_PAGE_ATTRIB_VER_0
+
+
+ /*** Additional Data */
+ /*** -------------------------------------------------------------------------------*/
+#if 0 /* DEL */
+typedef struct _tagEPS_QRCODE_ {
+ EPS_UINT16 version; /* structure version */
+ EPS_INT8* source; /* source buffer */
+ EPS_UINT16 srcLength; /* source size */
+ EPS_INT32 xPos; /* Left position */
+ EPS_INT32 yPos; /* Top position */
+ EPS_UINT32 width; /* width */
+} EPS_QRCODE;
+#define EPS_QRCODE_VER_1 1
+#define EPS_QRCODE_VER_CUR EPS_QRCODE_VER_1
+
+#define EPS_ADDDATA_NONE 0x00
+#define EPS_ADDDATA_QRCODE 0x01
+#endif
+
+ /*** Print Data */
+ /*** -------------------------------------------------------------------------------*/
+typedef union _tagEPS_PRN_DATA_ {
+ EPS_UINT16 version; /* structure version */
+
+ struct {
+ EPS_UINT16 version;
+ const EPS_UINT8* data;
+ EPS_UINT32 heightPixels;
+ EPS_UINT32 widthPixels;
+ } band;
+
+ struct {
+ EPS_UINT16 version;
+ const EPS_UINT8* data;
+ EPS_UINT32 dataSize;
+ } chunk;
+} EPS_PRN_DATA;
+#define EPS_PRN_DATA_VER_1 1
+#define EPS_PRN_DATA_VER_CUR EPS_PRN_DATA_VER_1
+
+
+ /*** Printer Status */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_STATUS_ {
+ EPS_INT32 printerStatus;
+ EPS_INT32 errorCode;
+ EPS_BOOL jobContinue;
+} EPS_STATUS;
+
+ /*** Ink infomation */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_INK_INFO_ {
+ EPS_INT32 number;
+ EPS_INT32 colors[EPS_INK_NUM];
+ EPS_INT32 remaining[EPS_INK_NUM];
+} EPS_INK_INFO;
+
+ /*** Supported Media Information */
+ /*** -------------------------------------------------------------------------------*/
+ /* Media Type and Printing Modes */
+ /* (Container for media type information (nested inside EPS_MEDIA_SIZE) ) */
+typedef struct _tagEPS_MEDIA_TYPE_V1_ {
+ EPS_INT32 mediaTypeID;
+ EPS_UINT32 layout;
+ EPS_UINT32 quality;
+ EPS_UINT32 paperSource; /* Paper Source */
+}EPS_MEDIA_TYPE_V1;
+
+typedef struct _tagEPS_MEDIA_TYPE_V2_ {
+ EPS_INT32 mediaTypeID;
+ EPS_UINT32 layout;
+ EPS_UINT32 quality;
+ EPS_UINT32 paperSource; /* Paper Source */
+ EPS_UINT32 duplex; /* duplex print support */
+}EPS_MEDIA_TYPE_V2;
+#define EPS_MEDIA_TYPE EPS_MEDIA_TYPE_V2
+
+ /* Media Size */
+ /* (Container for media size information (nested inside EPS_CAPABILITIES) ) */
+typedef struct _tagEPS_MEDIA_SIZE_ {
+ EPS_INT32 mediaSizeID;
+ EPS_INT32 numTypes;
+ EPS_MEDIA_TYPE* typeList;
+}EPS_MEDIA_SIZE;
+
+ /* Supported Media */
+typedef struct _tagEPS_SUPPORTED_MEDIA_ {
+ EPS_INT32 JpegSizeLimit;
+ EPS_INT32 numSizes;
+ EPS_MEDIA_SIZE* sizeList;
+ EPS_UINT32 resolution; /* supported input resolution */
+}EPS_SUPPORTED_MEDIA;
+
+ /* USB device infomation */
+typedef struct _tagEPS_USB_DEVICE_ {
+ EPS_UINT32 vid; /* vender ID */
+ EPS_UINT32 pid; /* product ID */
+ EPS_UINT32 port; /* port number */
+}EPS_USB_DEVICE;
+
+
+ /*** Probe printer parameter */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct tagEPS_PROBE_ {
+ EPS_INT32 version; /* this version */
+ EPS_INT32 method;
+ EPS_UINT32 timeout;
+ union{
+ EPS_INT8 identify[EPS_PRNID_BUFFSIZE];
+ struct {
+ EPS_INT32 protocol;
+ EPS_INT8 address[EPS_ADDR_BUFFSIZE];
+ } addr;
+ } dsc;
+}EPS_PROBE;
+#define EPS_PROBE_VER_1 1
+#define EPS_PROBE_VER_CUR EPS_PROBE_VER_1
+
+ /* Local time */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_LOCAL_TIME_ {
+ EPS_UINT16 year;
+ EPS_UINT8 mon;
+ EPS_UINT8 day;
+ EPS_UINT8 hour;
+ EPS_UINT8 min;
+ EPS_UINT8 sec;
+}EPS_LOCAL_TIME;
+
+
+/*-------------------------- External Function Definitions --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Common Function Definitions */
+ /*** -------------------------------------------------------------------------------*/
+typedef EPS_INT32 (*EPS_FindCallback )(EPS_PRINTER );
+typedef EPS_INT32 (*EPS_StateCallback )(EPS_INT32, EPS_INT32 );
+typedef void* (*EPS_MemAlloc )(size_t );
+typedef void (*EPS_MemFree )(void* );
+ /* ESC/P-R Lib ignores sleep function return value, so any sleep function can be used. */
+typedef EPS_INT32 (*EPS_Sleep )(EPS_UINT32 );
+/*typedef void (*EPS_Sleep )(EPS_UINT32 );*/
+typedef EPS_UINT32 (*EPS_GetTime )(void );
+typedef EPS_UINT32 (*EPS_GetLocalTime )(EPS_LOCAL_TIME* );
+typedef EPS_INT32 (*EPS_LockSync )(void );
+typedef EPS_INT32 (*EPS_UnlockSync )(void );
+
+
+ /*** USB Function Definitions */
+ /*** -------------------------------------------------------------------------------*/
+typedef EPS_FILEDSC (*EPS_FindFirstPort )(EPS_USB_DEVICE* );
+typedef EPS_BOOL (*EPS_FindNextPort )(EPS_FILEDSC, EPS_USB_DEVICE* );
+typedef EPS_BOOL (*EPS_FindClose )(EPS_FILEDSC );
+typedef EPS_FILEDSC (*EPS_OpenPortal )(const EPS_USB_DEVICE* );
+typedef EPS_INT32 (*EPS_ClosePortal )(EPS_FILEDSC );
+typedef EPS_INT32 (*EPS_ReadPortal )(EPS_FILEDSC, EPS_UINT8*, EPS_INT32, EPS_INT32*);
+typedef EPS_INT32 (*EPS_WritePortal )(EPS_FILEDSC, const EPS_UINT8*, EPS_INT32, EPS_INT32*);
+typedef EPS_INT32 (*EPS_GetDeviceID )(EPS_FILEDSC, EPS_INT8* );
+
+
+ /*** Sockets Function Definitions */
+ /*** -------------------------------------------------------------------------------*/
+typedef EPS_SOCKET (*EPS_NetSocket )(EPS_INT32, EPS_INT32, EPS_INT32 );
+typedef EPS_INT32 (*EPS_NetClose )(EPS_SOCKET );
+typedef EPS_INT32 (*EPS_NetConnect )(EPS_SOCKET, const EPS_INT8*, EPS_UINT16);
+typedef EPS_INT32 (*EPS_NetShutdown )(EPS_SOCKET, EPS_INT32 );
+typedef EPS_INT32 (*EPS_NetBind )(EPS_SOCKET, EPS_UINT16, EPS_UINT16* );
+typedef EPS_INT32 (*EPS_NetListen )(EPS_SOCKET, EPS_INT32 );
+typedef EPS_INT32 (*EPS_NetAccept )(EPS_SOCKET, EPS_UINT32, EPS_SOCKET*,
+ EPS_INT8*, EPS_UINT16* );
+typedef EPS_INT32 (*EPS_NetSend )(EPS_SOCKET, const void*, EPS_INT32, EPS_UINT32);
+typedef EPS_INT32 (*EPS_NetSendTo )(EPS_SOCKET, const void*, EPS_INT32,
+ const EPS_INT8*, EPS_UINT16, EPS_UINT32 );
+typedef EPS_INT32 (*EPS_NetReceive )(EPS_SOCKET, void*, EPS_INT32, EPS_UINT32);
+typedef EPS_INT32 (*EPS_NetReceiveFrom )(EPS_SOCKET, void*, EPS_INT32,
+ EPS_INT8*, EPS_UINT16*, EPS_UINT32 );
+typedef EPS_INT32 (*EPS_NetGetSockName )(EPS_SOCKET, EPS_INT8*, EPS_UINT16* );
+typedef EPS_INT32 (*EPS_NetSetMulticastTTL )(EPS_SOCKET, EPS_INT32 );
+typedef EPS_INT32 (*EPS_NetSetBroadCast )(EPS_SOCKET );
+
+
+ /*** External Function Definitions */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_CMN_FUNC_ {
+ EPS_INT32 version; /* this version */
+ EPS_FindCallback findCallback; /* Find Notification Callback Function */
+ EPS_StateCallback stateCallback; /* unused */
+ EPS_MemAlloc memAlloc; /* Allocate Memory Function */
+ EPS_MemFree memFree; /* Free Memory Function */
+ EPS_Sleep sleep; /* Sleep Function */
+ EPS_GetTime getTime; /* GetTime Function */
+ EPS_GetLocalTime getLocalTime; /* Get Local Time Function */
+ EPS_LockSync lockSync; /* Thread lock Function */
+ EPS_UnlockSync unlockSync; /* Thread unlock Function */
+} EPS_CMN_FUNC;
+
+#define EPS_CMNFUNC_VER_1 1
+#define EPS_CMNFUNC_VER_CUR EPS_CMNFUNC_VER_1
+
+ /*** USB External Function Definitions */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_USB_FUNC_ {
+ EPS_INT32 version; /* this version */
+ EPS_OpenPortal openPortal; /* Open I/O Function */
+ EPS_ClosePortal closePortal; /* Close I/O Function */
+ EPS_ReadPortal readPortal; /* Read Data Function */
+ EPS_WritePortal writePortal; /* Write Data Function */
+ EPS_FindFirstPort findFirst; /* Find usb device start Function */
+ EPS_FindNextPort findNext; /* Find next usb device Function */
+ EPS_FindClose findClose; /* Find process end Function */
+} EPS_USB_FUNC;
+
+#define EPS_USBFUNC_VER_1 1
+#define EPS_USBFUNC_VER_CUR EPS_USBFUNC_VER_1
+
+ /*** NET External Function Definitions */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_NET_FUNC_ {
+ EPS_INT32 version; /* this version */
+ EPS_NetSocket socket; /* create socket Function */
+ EPS_NetClose close; /* close Function */
+ EPS_NetConnect connect; /* connect Function */
+ EPS_NetShutdown shutdown; /* shutdown Function */
+ EPS_NetBind bind; /* bind Function */
+ EPS_NetListen listen; /* listen Function */
+ EPS_NetAccept accept; /* accept Function */
+ EPS_NetSend send; /* send Function */
+ EPS_NetSendTo sendTo; /* sendto Function */
+ EPS_NetReceive receive; /* recv Function */
+ EPS_NetReceiveFrom receiveFrom; /* revcfrom Function */
+ EPS_NetGetSockName getsockname; /* getsockname Function */
+ EPS_NetSetMulticastTTL setMulticastTTL; /* Set Multicast TTL Function */
+ EPS_NetSetBroadCast setBroadcast; /* Set enable broadcast Function */
+} EPS_NET_FUNC;
+#define EPS_NETFUNC_VER_1 1
+#define EPS_NETFUNC_VER_CUR EPS_USBFUNC_VER_1
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPR_DEF_H__ */
+
+/*________________________________ epson-escpr-def.h ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-err.h b/lib/epson-escpr-err.h
new file mode 100644
index 0000000..f6e068c
--- /dev/null
+++ b/lib/epson-escpr-err.h
@@ -0,0 +1,333 @@
+/*________________________________ epson-escpr-err.h ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/PR Error Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPR_ERR_H__
+#define __EPSON_ESCPR_ERR_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+/*---------------------- Normal Return Value of ESC/P-R Lib API ----------------------*/
+/*******************************************|********************************************/
+#define EPS_JOB_CANCELED 40 /* Printing job is canceled by user */
+#define EPS_OUT_OF_BOUNDS 41 /* Print band is in out of printable area */
+#define EPS_FIND_CANCELED 42 /* Find printer is canceled by user */
+
+/*----------------------- Error Return Value of ESC/P-R Lib API ----------------------*/
+/*******************************************|********************************************/
+enum EPS_RUN_TIME_ERROR {
+ /*** No Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_NONE = 0, /* Routine / Action completed successfully */
+
+ /*** Global Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_OPR_FAIL = -1000, /* Generic / Internal Error */
+ EPS_ERR_MEMORY_ALLOCATION = -1001, /* Memory Allocation Error */
+ EPS_ERR_PRINTER_ERR_OCCUR = -1003, /* The error occurred by Printer */
+
+ EPS_ERR_PROTOCOL_NOT_SUPPORTED = -1010, /* Unsupported function Error (protocol) */
+ EPS_ERR_NEED_BIDIRECT = -1011, /* Need Bi-Directional Communication Mode */
+ EPS_ERR_INVALID_CALL = -1012, /* Invalid function call */
+ EPS_ERR_INVALID_VERSION = -1013, /* Invalid structure version */
+ EPS_ERR_INVALID_DATATYPE = -1014, /* Invalid data type */
+ EPS_ERR_LANGUAGE_NOT_SUPPORTED = -1015, /* Unsupported function Error (language) */
+
+ /*** Library Status Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_LIB_INTIALIZED = -1050, /* Lib already initialized */
+ EPS_ERR_LIB_NOT_INITIALIZED = -1051, /* Lib not initialized */
+ EPS_ERR_JOB_NOT_INITIALIZED = -1052, /* Start page before start job */
+ EPS_ERR_JOB_NOT_CLOSED = -1053, /* Started new job before closing open job */
+ EPS_ERR_PAGE_NOT_INITIALIZED = -1054, /* Close page before start page */
+ EPS_ERR_PAGE_NOT_CLOSED = -1055, /* Started new page before closing open page */
+
+ /*** I/O Errors */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_COMM_ERROR = -1100, /* Communication Error */
+ EPS_ERR_NOT_OPEN_IO = -1101, /* Could not open I/O port/channel */
+ EPS_ERR_NOT_CLOSE_IO = -1102, /* Could not close I/O port/channel */
+ EPS_ERR_2ND_OPEN_IO = -1103, /* Second Open I/O port */
+
+ /*** epsInitDriver() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_ARG_COMMMODE = -1200, /* Invalid argument "commMode" */
+ EPS_ERR_INV_FNCP_NULL = -1201, /* Invalid function pointer structure */
+ EPS_ERR_INV_FNCP_FINDCALLBACK = -1202, /* Invalid function pointer "findCallback" */
+ EPS_ERR_INV_FNCP_MEMALLOC = -1203, /* Invalid function pointer "memAlloc" */
+ EPS_ERR_INV_FNCP_MEMFREE = -1204, /* Invalid function pointer "memFree" */
+ EPS_ERR_INV_FNCP_SLEEP = -1205, /* Invalid function pointer "sleep" */
+ EPS_ERR_INV_FNCP_GETTIME = -1206, /* Invalid function pointer "getTime" and "lockSync" */
+
+ EPS_ERR_INV_FNCP_OPENPORTAL = -1211, /* Invalid function pointer "openPortal" */
+ EPS_ERR_INV_FNCP_CLOSEPORTAL = -1212, /* Invalid function pointer "closePortal" */
+ EPS_ERR_INV_FNCP_READPORTAL = -1213, /* Invalid function pointer "readPortal" */
+ EPS_ERR_INV_FNCP_WRITEPORTAL = -1214, /* Invalid function pointer "writePortal" */
+ EPS_ERR_INV_FNCP_FINDFIRST = -1215, /* Invalid function pointer "findFirst" */
+ EPS_ERR_INV_FNCP_FINDNEXT = -1216, /* Invalid function pointer "findNext" */
+ EPS_ERR_INV_FNCP_FINDCLOSE = -1217, /* Invalid function pointer "findClose" */
+
+ EPS_ERR_INV_FNCP_NETSOCKET = -1221, /* Invalid function pointer "socket" */
+ EPS_ERR_INV_FNCP_NETCLOSE = -1222, /* Invalid function pointer "close" */
+ EPS_ERR_INV_FNCP_NETCONNECT = -1223, /* Invalid function pointer "connect" */
+ EPS_ERR_INV_FNCP_NETSHUTDOWN = -1224, /* Invalid function pointer "shutdown" */
+ EPS_ERR_INV_FNCP_NETBIND = -1225, /* Invalid function pointer "bind" */
+ EPS_ERR_INV_FNCP_NETLISTEN = -1226, /* Invalid function pointer "listen" */
+ EPS_ERR_INV_FNCP_NETACCEPT = -1227, /* Invalid function pointer "accept" */
+ EPS_ERR_INV_FNCP_NETSEND = -1228, /* Invalid function pointer "send" */
+ EPS_ERR_INV_FNCP_NETSENDTO = -1229, /* Invalid function pointer "sendTo" */
+ EPS_ERR_INV_FNCP_NETRECEIVE = -1230, /* Invalid function pointer "receive" */
+ EPS_ERR_INV_FNCP_NETRECEIVEFROM = -1231, /* Invalid function pointer "receiveFrom" */
+ EPS_ERR_INV_FNCP_NETGETSOCKNAME = -1232, /* Invalid function pointer "getsockname" */
+ EPS_ERR_INV_FNCP_NETSETMULTITTL = -1233, /* Invalid function pointer "setMulticastMember" */
+ EPS_ERR_INV_FNCP_NETSETBROADCAST = -1234, /* Invalid function pointer "setBroadcast" */
+
+ /*** epsFindPrinter(), epsProbePrinter() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_PRINTER_NOT_FOUND = -1300, /* printer not found */
+ EPS_ERR_INV_ARG_PROBEINFO = -1301, /* Invalid argument probe infomation */
+ EPS_ERR_INV_ARG_UNK_METHOD = -1302, /* Invalid value "method" */
+ EPS_ERR_INV_ARG_PRINTER_ID = -1303, /* Invalid format "identify" */
+ EPS_ERR_INV_ARG_PRINTER_ADDR = -1304, /* Invalid format "address" */
+ EPS_ERR_FIND_NOT_STARTED = -1305, /* Cancel find before start find */
+ EPS_ERR_PRINTER_NOT_USEFUL = -1306, /* not useful printer found */
+
+ /*** epsSetPrinter() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_ARG_PRINTER = -1350, /* Invalid Argument "printer" */
+ EPS_ERR_PRINTER_NOT_SET = -1351, /* Target printer is not specified */
+ EPS_ERR_INV_PRINT_LANGUAGE = -1352, /* Invalid Argument "printer.language" */
+
+ /*** Page Attribution Error (epsStartJob(), epsGetPrintableArea()) */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_MEDIA_SIZE = -1400, /* Invalid Media Size */
+ EPS_ERR_INV_MEDIA_TYPE = -1401, /* Invalid Media Type */
+ EPS_ERR_INV_BORDER_MODE = -1402, /* Invalid Border Mode */
+ EPS_ERR_INV_PRINT_QUALITY = -1403, /* Invalid Print Quality */
+ EPS_ERR_INV_COLOR_MODE = -1404, /* Invalid Color Mode */
+ EPS_ERR_INV_INPUT_RESOLUTION = -1405, /* Invalid Input Resolution */
+ EPS_ERR_INV_PRINT_DIRECTION = -1406, /* Invalid Print Direction */
+ EPS_ERR_INV_COLOR_PLANE = -1407, /* Invalid Color Plane */
+ EPS_ERR_INV_PALETTE_SIZE = -1408, /* Invalid Palette Size */
+ EPS_ERR_INV_PALETTE_DATA = -1409, /* Invalid Palette Data */
+ EPS_ERR_INV_BRIGHTNESS = -1410, /* Invalid Brightness */
+ EPS_ERR_INV_CONTRAST = -1411, /* Invalid Contrast */
+ EPS_ERR_INV_SATURATION = -1412, /* Invalid Saturation */
+ /*EPS_ERR_INV_MEDIAOPTION = -1413, Invalid mediaOption */
+ EPS_ERR_INV_TOP_MARGIN = -1420, /* Invalid Top Magirn */
+ EPS_ERR_INV_LEFT_MARGIN = -1421, /* Invalid Left Margin */
+ EPS_ERR_INV_BOTTOM_MARGIN = -1422, /* Invalid Bottom Margin */
+ EPS_ERR_INV_RIGHT_MARGIN = -1423, /* Invalid Right Margin */
+ EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH = -1424, /* Invalid Margin Setting (Width) */
+ EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT = -1425, /* Invalid Margin Setting (Height) */
+ EPS_ERR_INV_PAPER_SOURCE = -1426, /* Invalid Paper source */
+ EPS_ERR_INV_DUPLEX = -1427, /* Invalid duplex */
+ EPS_ERR_INV_FEED_DIRECTION = -1428, /* Invalid feed direction */
+
+ /*EPS_ERR_INV_APF_FLT = -1430, Invalid APF Filter */
+ EPS_ERR_INV_APF_ACT = -1431, /* Invalid APF Auto Corretion */
+ EPS_ERR_INV_APF_SHP = -1432, /* Invalid APF Sharpness */
+ EPS_ERR_INV_APF_RDE = -1433, /* Invalid APF Redeye */
+ EPS_ERR_INV_CD_INDIM = -1434, /* Invalid CD Inside Diameter */
+ EPS_ERR_INV_CD_OUTDIM = -1435, /* Invalid CD Outside Diameter */
+ EPS_ERR_INV_CMDTYPE = -1436, /* Invalid Command Type */
+
+ EPS_ERR_INV_ARG_JOB_ATTRIB = -1450, /* Invalid argument "jobAttr" */
+ EPS_ERR_INV_ARG_PAGE_ATTRIB = -1451, /* Invalid argument "thisPage" */
+
+ /*** epsStartJob() / epsStartPage() Error */
+ /*** -------------------------------------------------------------------------------*/
+ /*EPS_ERR_CANNOT_PRINT = -1500,*//* Cannot start printing */
+
+ /*** epsPrintBand() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_ARG_DATA = -1600, /* Invalid argument "data" */
+ EPS_ERR_INV_ARG_WIDTH_PIXELS = -1601, /* Invalid argument "widthPixels" */
+ /* EPS_ERR_INV_ARG_BYTES_PER_LINE = -1602, Invalid argument "bytesPerLine" */
+ EPS_ERR_INV_ARG_HEIGHT_PIXELS = -1603, /* Invalid argument "heightPixels" */
+ EPS_ERR_INV_ARG_DATASIZE = -1610, /* Invalid argument "dataSize" */
+
+ /*** epsCancelJob() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_CAN_NOT_RESET = -1650, /* Failed to reset printer */
+
+ /*** epsGetStatus() / epsGetInkInfo() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_ARG_STATUS = -1700, /* Invalid argument "status" */
+ EPS_ERR_INV_ARG_INKINFO = -1710, /* Invalid argument "inkInfo" */
+
+ /*** epsGetSupportedMedia() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_ARG_SUPPORTED_MEDIA = -1750, /* Invalid Argument "supportedMedia" */
+
+ /*** epsGetPrintableArea() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_ARG_PRINTABLE_WIDTH = -1800, /* Invalid argument "printableWidth" */
+ EPS_ERR_INV_ARG_PRINTABLE_HEIGHT = -1801, /* Invalid argument "printableHeight" */
+
+ /*** epsSetAdditionalData() Error */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_ERR_INV_ARG_ADDDATA = -2001, /* Invalid argument "data" */
+ EPS_ERR_INV_ARG_QRSOURCE = -2002, /* Invalid argument "data.qrcode.source" */
+ EPS_ERR_INV_ARG_QRXPOS = -2003, /* Invalid argument "data.qrcode.xPos" */
+ EPS_ERR_INV_ARG_QRYPOS = -2004, /* Invalid argument "data.qrcode.yPos" */
+ EPS_ERR_QRSOURCE_TOO_LAGE = -2005 /* source is too lage to convert QR code */
+};
+
+
+/*--------------------------- Definition of Printer Status ---------------------------*/
+/*******************************************|********************************************/
+
+ /*** Printer Status */
+ /*** -------------------------------------------------------------------------------*/
+enum EPS_PRINTER_STATUS {
+ EPS_PRNST_IDLE = 0, /* Idle (Enable Start Job) */
+ EPS_PRNST_PRINTING , /* Printing */
+ /* EPS_PRNST_OFFLINE , Offline */
+ EPS_PRNST_BUSY , /* Busy (Disable Start Job) */
+ EPS_PRNST_CANCELLING , /* Cancellation processing */
+ EPS_PRNST_ERROR /* Printer has an error */
+};
+
+ /*** Printer Error */
+ /*** -------------------------------------------------------------------------------*/
+enum EPS_PRINTER_ERROR {
+ EPS_PRNERR_NOERROR = 0,
+ EPS_PRNERR_GENERAL ,
+ EPS_PRNERR_FATAL ,
+ EPS_PRNERR_INTERFACE ,
+ EPS_PRNERR_COVEROPEN ,
+/* EPS_PRNERR_LEVERPOSITION ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_PAPERJAM ,
+ EPS_PRNERR_INKOUT ,
+ EPS_PRNERR_PAPEROUT ,
+/* EPS_PRNERR_INITIALIZESETTING ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_UNKNOWN ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_PAPERCHANGE_UNCOMP ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_PAPERSIZE ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_RIBBONJAM ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_SIZE_TYPE_PATH ,
+/* EPS_PRNERR_PAPERTHICKLEVER ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_PAPERFEED ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_SIMMCOPY ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_SERVICEREQ , /* EPS_PRNERR_INKOVERFLOW1 */
+/* EPS_PRNERR_WAITTEAROFFRETURN ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_DOUBLEFEED ,
+/* EPS_PRNERR_HEADHOT ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_PAPERCUTMIS ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_HOLDLEVERRELEASE ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_NOT_CLEANING ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_PAPERCONFIG ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_PAPERSLANT ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_CLEANINGNUMOVER ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_INKCOVEROPEN ,
+/* EPS_PRNERR_LFP_INKCARTRIDGE ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_CUTTER ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_CUTTERJAM ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_INKCOLOR ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_CUTTERCOVEROPEN ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_LFP_INKLEVERRELEASE ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_LFP_NOMAINTENANCETANK1 ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_CARTRIDGECOMBINATION ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_LFP_COMMAND ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_LEARCOVEROPEN ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_MULTICENSORGAIN ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_NOT_AUTOADJUST ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_FAILCLEANING ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_NOTRAY ,
+ EPS_PRNERR_CARDLOADING ,
+ EPS_PRNERR_CARTRIDGEOVERFLOW ,
+/* EPS_PRNERR_LFP_NOMAINTENANCETANK2 ,*/ /* Not supported by 2006 Model */
+/* EPS_PRNERR_INKOVERFLOW2 ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_BATTERYVOLTAGE ,
+ EPS_PRNERR_BATTERYTEMPERATURE ,
+ EPS_PRNERR_BATTERYEMPTY ,
+ EPS_PRNERR_SHUTOFF ,
+ EPS_PRNERR_NOT_INITIALFILL ,
+ EPS_PRNERR_PRINTPACKEND ,
+/* EPS_PRNERR_ABNORMALHEAT ,*/ /* Not supported by 2006 Model */
+ EPS_PRNERR_SCANNEROPEN ,
+ EPS_PRNERR_CDRGUIDEOPEN ,
+
+ /* append for 2008 Model */
+ EPS_PRNERR_CDDVDCONFIG ,
+ EPS_PRNERR_CDREXIST_MAINTE ,
+
+ /* Status Error */
+ EPS_PRNERR_BUSY = 100,
+ EPS_PRNERR_FACTORY ,
+ /* Communication Error */
+ EPS_PRNERR_COMM ,
+ /* Ink Error */
+ EPS_PRNERR_CEMPTY ,
+ EPS_PRNERR_CFAIL ,
+ /* Printer Condition */
+ EPS_PRNERR_TRAYCLOSE ,
+ EPS_PRNERR_CDGUIDECLOSE , /* CDR guide close */
+/* EPS_PRNERR_OVERHEAT OVERHEAT is not an error */
+ EPS_PRNERR_JPG_LIMIT , /* Jpeg print data size limit */
+ EPS_PRNERR_DISABEL_CLEANING /* can not start Head Cleaning */
+
+};
+
+ /*** Ink Cartridge Error */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_INK_NOTPRESENT (-1)
+#define EPS_INK_FAIL (-2)
+#define EPS_INK_NOTAVAIL (-3)
+#define EPS_INK_NOREAD (-4)
+
+ /*** Notifification Reply Values */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_CONTINUE_POSSIBLE 1
+#define EPS_CONTINUE_NOT_POSSIBLE 0
+
+ /*** Notifification Reply Values */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_USER_CONTINUE -20
+#define EPS_USER_CANCEL -30
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPR_ERR_H__ */
+
+/*________________________________ epson-escpr-err.h ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-media.h b/lib/epson-escpr-media.h
new file mode 100644
index 0000000..25eb20e
--- /dev/null
+++ b/lib/epson-escpr-media.h
@@ -0,0 +1,480 @@
+/*_______________________________ epson-escpr-media.h _______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/PR Media Information */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPR_MEDIA_H__
+#define __EPSON_ESCPR_MEDIA_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------- Local Compiler Switch --------------------------------*/
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+
+/*------------- Definition of Media Size ID / Global Media Size Declarations --------*/
+/*******************************************|********************************************/
+ /*** Media Size ID */
+ /*** ---------------------------------------------------------------------------*/
+typedef enum _tagMEDIA_SIZE_ID_ {
+ /* Dec Hex [ mm ] */
+ EPS_MSID_A4 =0, /* 0 0x00 [210.000,297.000] */
+ EPS_MSID_LETTER , /* 1 0x01 [215.900,279.400] */
+ EPS_MSID_LEGAL , /* 2 0x02 [215.900,355.600] */
+ EPS_MSID_A5 , /* 3 0x03 [148.000,210.000] */
+ EPS_MSID_A6 , /* 4 0x04 [105.000,148.000] */
+ EPS_MSID_B5 , /* 5 0x05 [176.000,250.000] */
+ EPS_MSID_EXECUTIVE , /* 6 0x06 [184.150,266.700] */
+ EPS_MSID_HALFLETTER , /* 7 0x07 [127.000,215.900] */
+ EPS_MSID_PANORAMIC , /* 8 0x08 [210.000,594.000] */
+ EPS_MSID_TRIM_4X6 , /* 9 0x09 [113.600,164.400] */
+ EPS_MSID_4X6 , /* 10 0x0A [101.600,152.400] */
+ EPS_MSID_5X8 , /* 11 0x0B [127.000,203.200] */
+ EPS_MSID_8X10 , /* 12 0x0C [203.200,203.200] */
+ EPS_MSID_10X15 , /* 13 0x0D [254.000,381.000] */
+ EPS_MSID_200X300 , /* 14 0x0E [200.000,300.000] */
+ EPS_MSID_L , /* 15 0x0F [ 88.900,127.000] */
+ EPS_MSID_POSTCARD , /* 16 0x10 [100.000,148.000] */
+ EPS_MSID_DBLPOSTCARD , /* 17 0x11 [200.000,148.000] */
+ EPS_MSID_ENV_10_L , /* 18 0x12 [241.300,104.775] */
+ EPS_MSID_ENV_C6_L , /* 19 0x13 [162.000,114.000] */
+ EPS_MSID_ENV_DL_L , /* 20 0x14 [220.000,110.000] */
+ EPS_MSID_NEWEVN_L , /* 21 0x15 [220.000,132.000] */
+ EPS_MSID_CHOKEI_3 , /* 22 0x16 [120.000,235.000] */
+ EPS_MSID_CHOKEI_4 , /* 23 0x17 [ 90.000,205.000] */
+ EPS_MSID_YOKEI_1 , /* 24 0x18 [120.000,176.000] */
+ EPS_MSID_YOKEI_2 , /* 25 0x19 [114.000,162.000] */
+ EPS_MSID_YOKEI_3 , /* 26 0x1A [ 98.000,148.000] */
+ EPS_MSID_YOKEI_4 , /* 27 0x1B [105.000,235.000] */
+ EPS_MSID_2L , /* 28 0x1C [127.000,177.800] */
+ EPS_MSID_ENV_10_P , /* 29 0x1D [104.775,241.300] */
+ EPS_MSID_ENV_C6_P , /* 30 0x1E [114.000,162.000] */
+ EPS_MSID_ENV_DL_P , /* 31 0x1F [110.000,220.000] */
+ EPS_MSID_NEWENV_P , /* 32 0x20 [132.000,220.000] */
+ EPS_MSID_MEISHI , /* 33 0x21 [ 89.000, 55.000] */
+ EPS_MSID_BUZCARD_89X50 , /* 34 0x22 [ 89.000, 50.000] */
+ EPS_MSID_CARD_54X86 , /* 35 0x23 [ 54.000, 86.000] */
+ EPS_MSID_BUZCARD_55X91 , /* 36 0x24 [ 55.000, 91.000] */
+ EPS_MSID_ALBUM_L , /* 37 0x25 [127.000,198.000] */
+ EPS_MSID_ALBUM_A5 , /* 38 0x26 [210.000,321.000] */
+ EPS_MSID_PALBUM_L_L , /* 39 0x27 [127.000 89.000] */
+ EPS_MSID_PALBUM_2L , /* 40 0x28 [127.000,177.900] */
+ EPS_MSID_PALBUM_A5_L , /* 41 0x29 [210.000,148.300] */
+ EPS_MSID_PALBUM_A4 , /* 42 0x2A [210.000,296.300] */
+ EPS_MSID_HIVISION , /* 43 0x2B [101.600,180.600] */
+ EPS_MSID_A3NOBI =61, /* 61 0x3D [329.000,483.000] */
+ EPS_MSID_A3 , /* 62 0x3E [297.000,420.000] */
+ EPS_MSID_B4 , /* 63 0x3F [257.000,364.000] */
+ EPS_MSID_USB , /* 64 0x40 [279.400,431.800] */
+ EPS_MSID_11X14 , /* 65 0x41 [279.400,355.600] */
+ EPS_MSID_B3 , /* 66 0x42 [364.000,515.000] */
+ EPS_MSID_A2 , /* 67 0x43 [420.000,594.000] */
+ EPS_MSID_USC , /* 68 0x44 [431.800,558.800] */
+ EPS_MSID_10X12 , /* 69 0x45 [254.000,304.800] */
+ EPS_MSID_F4 ,
+ EPS_MSID_ENVY0 ,
+ EPS_MSID_ENVY6 ,
+ EPS_MSID_ENVK2 ,
+ EPS_MSID_4PC ,
+ EPS_MSID_CHOKEI_5 ,
+ EPS_MSID_CHOKEI_6 ,
+ EPS_MSID_YOUGATA_1 ,
+ EPS_MSID_YOUGATA_2 ,
+ EPS_MSID_KAKUGATA ,
+ //EPS_MSID_QPOSTCARD ,
+ EPS_MSID_LEB , /*Ledger(B)*/
+ EPS_MSID_GLG,
+ EPS_MSID_GLT , /*Government Letter */
+ EPS_MSID_HLT ,
+ EPS_MSID_12X12 , /* 70 0x46 [304.800,304.800] */
+ EPS_MSID_USER =99, /* 99 0x63 [ 0.000, 0.000] */
+ EPS_MSID_UNKNOWN =0xff/* unknown */
+} MEDIA_SIZE_ID;
+
+ /*** Media Data Struct */
+ /*** ---------------------------------------------------------------------------*/
+typedef struct _tagEPS_MEDIA_INFO_ {
+ EPS_INT32 id;
+ EPS_INT32 paper_x;
+ EPS_INT32 paper_y;
+ EPS_INT32 print_area_x_border;
+ EPS_INT32 print_area_y_border;
+ EPS_INT16 left_margin_borderless;
+ EPS_INT16 top_margin_borderless;
+ EPS_INT32 print_area_x_borderless;
+ EPS_INT32 print_area_y_borderless;
+} EPS_MEDIA_INFO;
+
+ /*** Media Size Information (360dpi) */
+ /*** ---------------------------------------------------------------------------*/
+static const EPS_MEDIA_INFO epsMediaSize[] = {
+/* ID PaperW/L 3mm W/L 0mm L/T 0mm W/L */
+{ EPS_MSID_A4, 2976, 4209, 2892, 4125, -36, -42, 3048, 4321 },
+{ EPS_MSID_LETTER, 3060, 3960, 2976, 3876, -36, -42, 3132, 4072 },
+{ EPS_MSID_LEGAL, 3060, 5040, 2976, 4956, -36, -42, 3132, 5152 },
+{ EPS_MSID_A5, 2098, 2976, 2014, 2892, -36, -42, 2170, 3088 },
+{ EPS_MSID_A6, 1488, 2098, 1404, 2014, -36, -42, 1560, 2210 },
+{ EPS_MSID_B5, 2580, 3643, 2495, 3558, -36, -42, 2652, 3755 },
+{ EPS_MSID_EXECUTIVE, 2610, 3780, 2526, 3696, -36, -42, 2682, 3892 },
+{ EPS_MSID_HALFLETTER, 1980, 3060, 1896, 2976, -36, -42, 2052, 3172 },
+{ EPS_MSID_PANORAMIC, 2976, 8419, 2892, 8335, -36, -42, 3048, 8531 },
+{ EPS_MSID_TRIM_4X6, 1610, 2330, 1526, 2246, -36, -42, 1682, 2442 },
+{ EPS_MSID_4X6, 1440, 2160, 1356, 2076, -36, -42, 1512, 2272 },
+{ EPS_MSID_5X8, 1800, 2880, 1716, 2796, -36, -42, 1872, 2992 },
+{ EPS_MSID_8X10, 2880, 3600, 2796, 3516, -36, -42, 2952, 3712 },
+{ EPS_MSID_F4, 2976, 4677, 2892, 4593, -36, -42, 3048, 4789 },
+{ EPS_MSID_ENVY0, 1701, 3331, 1617, 3247, -36, -42, 1773, 3443 },
+{ EPS_MSID_ENVY6, 1389, 2693, 1305, 2609, -36, -42, 1461, 2805 },
+{ EPS_MSID_ENVK2, 3402, 4706, 3318, 4622, -36, -42, 3474, 4818 },
+{ EPS_MSID_4PC, 2835, 4195, 2751, 4111, -36, -42, 2907, 4307 },
+{ EPS_MSID_10X15, 1417, 2125, 1333, 2041, -36, -42, 1489, 2237 },
+{ EPS_MSID_200X300, 3061, 4790, 2977, 4706, -36, -42, 3133, 4902 },
+{ EPS_MSID_L, 1260, 1800, 1176, 1716, -36, -42, 1332, 1912 },
+{ EPS_MSID_POSTCARD, 1417, 2098, 1333, 2013, -36, -42, 1489, 2210 },
+{ EPS_MSID_DBLPOSTCARD, 2835, 2098, 2751, 2014, -36, -42, 2907, 2210 },
+{ EPS_MSID_ENV_10_L, 3420, 1485, 3336, 1401, -36, -42, 3492, 1597 },
+{ EPS_MSID_ENV_C6_L, 2296, 1616, 2212, 1532, -36, -42, 2368, 1728 },
+{ EPS_MSID_ENV_DL_L, 3118, 1559, 3034, 1475, -36, -42, 3190, 1671 },
+{ EPS_MSID_NEWEVN_L, 3118, 1871, 3034, 1787, -36, -42, 3190, 1983 },
+{ EPS_MSID_CHOKEI_3, 1701, 3685, 1617, 3247, -36, -42, 1773, 3797 },
+{ EPS_MSID_CHOKEI_4, 1276, 3161, 1192, 2822, -36, -42, 1348, 3273 },
+{ EPS_MSID_YOKEI_1, 1701, 2494, 1617, 2410, -36, -42, 1773, 2606 },
+{ EPS_MSID_YOKEI_2, 1616, 2296, 1532, 2212, -36, -42, 1688, 2408 },
+{ EPS_MSID_YOKEI_3, 1389, 2098, 1305, 2014, -36, -42, 1461, 2210 },
+{ EPS_MSID_YOKEI_4, 1488, 3331, 1404, 3247, -36, -42, 1560, 3443 },
+{ EPS_MSID_2L, 1800, 2522, 1716, 2436, -36, -42, 1872, 2634 },
+{ EPS_MSID_ENV_10_P, 1485, 3420, 1401, 3336, -36, -42, 1557, 3532 },
+{ EPS_MSID_ENV_C6_P, 1616, 2296, 1532, 2212, -36, -42, 1688, 2408 },
+{ EPS_MSID_ENV_DL_P, 1559, 3118, 1475, 3034, -36, -42, 1631, 3230 },
+{ EPS_MSID_NEWENV_P, 1871, 3118, 1787, 3034, -36, -42, 1943, 3230 },
+{ EPS_MSID_MEISHI, 1261, 779, 1177, 695, -36, -42, 1333, 891 },
+{ EPS_MSID_BUZCARD_89X50, 1261, 709, 1177, 625, -36, -42, 1333, 821 },
+{ EPS_MSID_CARD_54X86, 765, 1219, 681, 1135, -36, -42, 837, 1331 },
+{ EPS_MSID_BUZCARD_55X91, 780, 1290, 696, 1206, -36, -42, 852, 1402 },
+{ EPS_MSID_ALBUM_L, 1800, 2607, 1716, 2523, -36, -42, 1872, 2719 },
+{ EPS_MSID_ALBUM_A5, 2976, 4294, 2892, 4210, -36, -42, 3048, 4406 },
+{ EPS_MSID_PALBUM_L_L, 1800, 1260, 1716, 1176, -36, -42, 1872, 1372 },
+{ EPS_MSID_PALBUM_2L, 1800, 2521, 1716, 2437, -36, -42, 1872, 2633 },
+{ EPS_MSID_PALBUM_A5_L, 2976, 2101, 2892, 2017, -36, -42, 3048, 2213 },
+{ EPS_MSID_PALBUM_A4, 2976, 4203, 2892, 4119, -36, -42, 3048, 4315 },
+{ EPS_MSID_HIVISION, 1440, 2560, 1356, 2476, -36, -42, 1512, 2672 },
+{ EPS_MSID_A3NOBI, 4663, 6846, 4578, 6761, -48, -42, 4759, 6958 },
+{ EPS_MSID_A3, 4209, 5953, 4125, 5868, -48, -42, 4305, 6065 },
+{ EPS_MSID_B4, 3643, 5159, 3559, 5075, -36, -42, 3715, 5271 },
+{ EPS_MSID_USB, 3960, 6120, 3876, 6036, -36, -42, 4032, 6232 },
+{ EPS_MSID_11X14, 3960, 5040, 3876, 4956, -36, -42, 4032, 5152 },
+{ EPS_MSID_B3, 5159, 7285, 5075, 7201, -48, -42, 5255, 7397 },
+{ EPS_MSID_A2, 5953, 8419, 5869, 8335, -48, -42, 6049, 8531 },
+{ EPS_MSID_USC, 6120, 7920, 6036, 7836, -48, -42, 6216, 8032 },
+{ EPS_MSID_10X12, 3600, 4320, 3516, 4236, -36, -42, 3672, 4432 },
+{ EPS_MSID_12X12, 4320, 4320, 4236, 4236, -36, -42, 4392, 4432 },
+{ EPS_MSID_GLT, 2880, 3780, 2796, 3696, -36, -42, 2952, 3892},
+{ EPS_MSID_GLG, 3060, 4680, 2976, 4596, -36, -42, 3132, 4792},
+{ EPS_MSID_USER, 0, 0, 0, 0, -36, -42, 0, 0 },
+{ -1, 0, 0, 0, 0, 0, 0, 0, 0 }
+};
+
+#define EPS_NUM_MEDIA_SIZES sizeof(epsMediaSize)/sizeof(EPS_MEDIA_INFO)
+
+
+ /*** Media Size Information (300dpi) */
+ /*** ---------------------------------------------------------------------------*/
+static const EPS_MEDIA_INFO epsMediaSize300[] = {
+/* ID PaperW/L 3mm W/L 0mm L/T 0mm W/L */
+{ EPS_MSID_A4, 2480, 3507, 2410, 3437, -30, -35, 2540, 3600 },
+{ EPS_MSID_LETTER, 2550, 3300, 2480, 3230, -30, -35, 2610, 3393 },
+{ EPS_MSID_LEGAL, 2550, 4200, 2480, 4130, -30, -35, 2610, 4293 },
+{ EPS_MSID_A5, 1748, 2480, 1678, 2410, -30, -35, 1808, 2573 },
+{ EPS_MSID_A6, 1240, 1748, 1170, 1678, -30, -35, 1300, 1841 },
+{ EPS_MSID_B5, 2149, 3035, 2079, 2965, -30, -35, 2209, 3128 },
+{ EPS_MSID_EXECUTIVE, 2175, 3150, 2105, 3080, -30, -35, 2235, 3243 },
+{ EPS_MSID_HALFLETTER, 1650, 2550, 1580, 2480, -30, -35, 1710, 2643 },
+{ EPS_MSID_PANORAMIC, 2480, 7016, 2410, 6946, -30, -35, 2540, 7109 },
+{ EPS_MSID_TRIM_4X6, 1342, 1942, 1272, 1872, -30, -35, 1402, 2035 },
+{ EPS_MSID_4X6, 1200, 1800, 1130, 1730, -30, -35, 1260, 1893 },
+{ EPS_MSID_5X8, 1500, 2400, 1430, 2330, -30, -35, 1560, 2493 },
+{ EPS_MSID_8X10, 2400, 3000, 2330, 2930, -30, -35, 2460, 3093 },
+{ EPS_MSID_10X15, 1181, 1771, 1111, 1701, -30, -35, 1241, 1864 },
+{ EPS_MSID_F4, 2480, 3898, 2410, 3828, -30, -35, 2540, 3991 },
+{ EPS_MSID_ENVY0, 1417, 2776, 1347, 2706, -36, -42, 1477, 2869 },
+{ EPS_MSID_ENVY6, 1157, 2244, 1087, 2174, -36, -42, 1217, 2337 },
+{ EPS_MSID_ENVK2, 2835, 3921, 2765, 3851, -36, -42, 2895, 4014 },
+{ EPS_MSID_4PC, 2362, 3496, 2292, 3426, -30, -35, 2422, 3589 },
+{ EPS_MSID_200X300, 2551, 3992, 2481, 3922, -30, -35, 2611, 4085 },
+{ EPS_MSID_L, 1050, 1500, 980, 1430, -30, -35, 1110, 1593 },
+{ EPS_MSID_POSTCARD, 1181, 1748, 1111, 1678, -30, -35, 1241, 1841 },
+{ EPS_MSID_DBLPOSTCARD, 2363, 1748, 2293, 1678, -30, -35, 2423, 1841 },
+{ EPS_MSID_ENV_10_L, 2850, 1238, 2780, 1168, -30, -35, 2910, 1331 },
+{ EPS_MSID_ENV_C6_L, 1913, 1347, 1843, 1277, -30, -35, 1973, 1440 },
+{ EPS_MSID_ENV_DL_L, 2598, 1299, 2528, 1229, -30, -35, 2658, 1392 },
+{ EPS_MSID_NEWEVN_L, 2598, 1559, 2528, 1489, -30, -35, 2658, 1652 },
+{ EPS_MSID_CHOKEI_3, 1418, 3071, 1348, 3001, -30, -35, 1478, 3164 },
+{ EPS_MSID_CHOKEI_4, 1063, 2634, 993, 2564, -30, -35, 1123, 2727 },
+{ EPS_MSID_YOKEI_1, 1418, 2078, 1348, 2008, -30, -35, 1478, 2171 },
+{ EPS_MSID_YOKEI_2, 1347, 1913, 1277, 1843, -30, -35, 1407, 2006 },
+{ EPS_MSID_YOKEI_3, 1158, 1748, 1088, 1678, -30, -35, 1218, 1841 },
+{ EPS_MSID_YOKEI_4, 1240, 2776, 1170, 2706, -30, -35, 1300, 2869 },
+{ EPS_MSID_2L, 1500, 2100, 1430, 2030, -30, -35, 1560, 2193 },
+{ EPS_MSID_ENV_10_P, 1238, 2850, 1168, 2780, -30, -35, 1298, 2943 },
+{ EPS_MSID_ENV_C6_P, 1347, 1913, 1277, 1843, -30, -35, 1407, 2006 },
+{ EPS_MSID_ENV_DL_P, 1299, 2598, 1229, 2528, -30, -35, 1359, 2691 },
+{ EPS_MSID_NEWENV_P, 1559, 2598, 1489, 2528, -30, -35, 1619, 2691 },
+{ EPS_MSID_MEISHI, 1051, 649, 981, 579, -30, -35, 1111, 742 },
+{ EPS_MSID_BUZCARD_89X50, 1051, 591, 981, 521, -30, -35, 1111, 684 },
+{ EPS_MSID_CARD_54X86, 638, 1016, 568, 946, -30, -35, 698, 1109 },
+{ EPS_MSID_BUZCARD_55X91, 650, 1075, 580, 1005, -30, -35, 710, 1168 },
+{ EPS_MSID_ALBUM_L, 1500, 2173, 1430, 2103, -30, -35, 1560, 2266 },
+{ EPS_MSID_ALBUM_A5, 2480, 3578, 2410, 3508, -30, -35, 2540, 3671 },
+{ EPS_MSID_PALBUM_L_L, 1500, 1050, 1430, 980, -30, -35, 1560, 1143 },
+{ EPS_MSID_PALBUM_2L, 1500, 2101, 1430, 2031, -30, -35, 1560, 2194 },
+{ EPS_MSID_PALBUM_A5_L, 2480, 1751, 2410, 1681, -30, -35, 2540, 1844 },
+{ EPS_MSID_PALBUM_A4, 2480, 3503, 2410, 3433, -30, -35, 2540, 3596 },
+{ EPS_MSID_HIVISION, 1200, 2133, 1130, 2063, -30, -35, 1260, 2226 },
+{ EPS_MSID_A3NOBI, 3886, 5705, 3816, 5635, -40, -35, 3946, 5798 },
+{ EPS_MSID_A3, 3507, 4960, 3437, 4890, -40, -35, 3567, 5053 },
+{ EPS_MSID_B4, 3036, 4299, 2966, 4229, -30, -35, 3096, 4392 },
+{ EPS_MSID_USB, 3300, 5100, 3230, 5030, -30, -35, 3360, 5193 },
+{ EPS_MSID_11X14, 3300, 4200, 3230, 4130, -30, -35, 3360, 4293 },
+{ EPS_MSID_B3, 4299, 6071, 4229, 6001, -40, -35, 4359, 6164 },
+{ EPS_MSID_A2, 4961, 7016, 4891, 6946, -40, -35, 5021, 7109 },
+{ EPS_MSID_USC, 5100, 6600, 5030, 6530, -40, -35, 5160, 6693 },
+{ EPS_MSID_10X12, 3000, 3600, 2930, 3530, -30, -35, 3060, 3693 },
+{ EPS_MSID_12X12, 3600, 3600, 3530, 3530, -30, -35, 3660, 3693 },
+{ EPS_MSID_GLT, 2400, 3150, 2330, 3080, -30, -35, 2460, 3243 },
+{ EPS_MSID_GLG, 2550, 3900, 2480, 3830, -30, -35, 2610, 3993 },
+{ EPS_MSID_USER, 0, 0, 0, 0, -30, -35, 0, 0 },
+{ -1, 0, 0, 0, 0, 0, 0, 0, 0 }
+};
+
+#define EPS_BORDERS_MARGIN_360 (42)
+/*#define EPS_BORDERS_MARGIN_720 (84)*/
+#define EPS_BORDERS_MARGIN_300 (35)
+/*#define EPS_BORDERS_MARGIN_600 (70)*/
+
+
+/*------------- Definition of Media Type ID / Global Media Type Declarations --------*/
+/*******************************************|********************************************/
+ /*** Media Type ID */
+ /*** ---------------------------------------------------------------------------*/
+typedef enum _tagMEDIA_TYPE_ID_ {
+ /* Dec Hex Text Name */
+ EPS_MTID_PLAIN =0, /* 0 0x00, "Plain Paper\0" */
+ EPS_MTID_360INKJET , /* 1 0x01, "360dpi Ink Jet Paper \0" */
+ EPS_MTID_IRON , /* 2 0x02, "Iron-On Cool Peel Transfer Paper\0" */
+ EPS_MTID_PHOTOINKJET , /* 3 0x03, "Photo Qaulity Ink Jet Paper #2\0" */
+ EPS_MTID_PHOTOADSHEET , /* 4 0x04, "Photo Qaulity Self Adhesive Sheets\0" */
+ EPS_MTID_MATTE , /* 5 0x05, "Mattee Paper-HeavyWeight\0" */
+ EPS_MTID_PHOTO , /* 6 0x06, "Photo Paper\0" */
+ EPS_MTID_PHOTOFILM , /* 7 0x07, "Photo Quality Glossy Flim\0" */
+ EPS_MTID_MINIPHOTO , /* 8 0x08, "Photo Stickers 4/6\0" */
+ EPS_MTID_OHP , /* 9 0x09, "Ink Jet Transparencies\0 */
+ EPS_MTID_BACKLIGHT , /* 10 0x0A, "Back Light Film\0" */
+ EPS_MTID_PGPHOTO , /* 11 0x0B, "Premium Glossy Photo Paper\0" */
+ EPS_MTID_PSPHOTO , /* 12 0x0C, "Premium Semigloss Photo Paper\0" */
+ EPS_MTID_PLPHOTO , /* 13 0x0D, "Premimum Luster Photo Paper\0" */
+ EPS_MTID_MCGLOSSY , /* 14 0x0E, "Glossy Paper - Photo Weight\0" */
+ EPS_MTID_ARCHMATTE , /* 15 0xOF, "Archival Matte Paper\0" */
+ EPS_MTID_WATERCOLOR , /* 16 0x10, "Water Paper-Radiant White\0" */
+ EPS_MTID_PROGLOSS , /* 17 0x11, "Professional Glossy Paper\0" */
+ EPS_MTID_MATTEBOARD , /* 18 0x12, "Matte Board Paper\0" */
+ EPS_MTID_PHOTOGLOSS , /* 19 0x13, "Photo Quality Glossy Paper\0" */
+ EPS_MTID_SEMIPROOF , /* 20 0x14, "Dupont/EPSON Semigloss Proofing Paper-A\0" */
+ EPS_MTID_SUPERFINE2 , /* 21 0x15, "Super Fine Paper -2\0" */
+ EPS_MTID_DSMATTE , /* 22 0x16, "Double Sided Matte Paper\0" */
+ EPS_MTID_CLPHOTO , /* 23 0x17, "ColorLife Photo Paper\0" */
+ EPS_MTID_ECOPHOTO , /* 24 0x18, "Economy Photo Paper\0" */
+ EPS_MTID_VELVETFINEART , /* 25 0x19, "Velvet Fine Art Paper\0" */
+ EPS_MTID_PROOFSEMI , /* 26 0x1A, "EPSON Proofing Paper Simimatte\0" */
+ EPS_MTID_HAGAKIRECL , /* 27 0x1B, "Post Card - Recycled Paper\0" */
+ EPS_MTID_HAGAKIINKJET , /* 28 0x1C, "Post Card - Ink Jet Paper\0" */
+ EPS_MTID_PHOTOINKJET2 , /* 29 0x1D, "Photo Quality Ink Jet Paper\0" */
+ EPS_MTID_DURABRITE , /* 30 0x1E, "DURABrite Ink Glossy Photo Paper\0" */
+ EPS_MTID_MATTEMEISHI , /* 31 0x1F, "Matte Meishi Card\0" */
+ EPS_MTID_HAGAKIATENA , /* 32 0x20, "Post Card - Address Side\0" */
+ EPS_MTID_PHOTOALBUM , /* 33 0x21, "Photo Album Kit\0" */
+ EPS_MTID_PHOTOSTAND , /* 34 0x22, "Photo Stand Kit\0" */
+ EPS_MTID_RCB , /* 35 0x23, "RC-B\0" */
+ EPS_MTID_PGPHOTOEG , /* 36 0x24, "Premimum Glossy Photo Paper - EG\0" */
+ EPS_MTID_ENVELOPE , /* 37 0x25, "Envelope\0" */
+ EPS_MTID_PLATINA , /* 38 0x26, "Ultra Glossy Photo Paper\0" */
+ EPS_MTID_ULTRASMOOTH , /* 39 0x27, "Ultra Smooth Fine Art Paper\0" */
+ EPS_MTID_SFHAGAKI , /* 40 0x28, "Super Fine Postcard\0" */
+ EPS_MTID_PHOTOSTD , /* 41 0x29, "Premium Glossy Photo Paper (Standard)\0" */
+ EPS_MTID_GLOSSYHAGAKI , /* 42 0x2A, "Glossy Postcard\0" */
+ EPS_MTID_GLOSSYPHOTO , /* 43 0x2B, "Glossy Photo Paper\0" */
+ EPS_MTID_GLOSSYCAST , /* 44 0x2C, "Epson Photo\0" */
+ EPS_MTID_LETTERHEAD , //lam dai hiep them
+ EPS_MTID_RECYCLED , //lam dai hiep them
+ EPS_MTID_COLORPAPER , //lam dai hiep them
+ EPS_MTID_LABEL , //lam dai hiep them
+ EPS_MTID_THICK , //lam dai hiep them
+ EPS_MTID_EXTHICK , //lam dai hiep them
+ EPS_MTID_COATED , //lam dai hiep them
+ EPS_MTID_SPECIAL , //lam dai hiep them
+ EPS_MTID_BUSINESSCOAT , /* 45 0x2D, "Business Ink Jet Coat Paper\0" */
+ EPS_MTID_CDDVD =91, /* 91 0x5B, "CD/DVD Label\0" */
+ EPS_MTID_CDDVDHIGH , /* 92 0x5C, "CD/DVD High Quality Label\0" */
+ EPS_MTID_CDDVDGLOSSY , /* 93 0x5D, "CD/DVD Glossy Surface\0" */
+ EPS_MTID_CLEANING =99, /* 99 0x63, "Cleaning Paper\0" */
+ EPS_MTID_UNKNOWN =0xff/* unknown */
+} MEDIA_TYPE_ID;
+
+
+ /*** Media Type Index */
+ /*** ---------------------------------------------------------------------------*/
+static const EPS_UINT32 epsMediaTypeIndex[] = {
+ /* Dec Hex Text Name */
+ EPS_MTID_PLAIN , /* 0 0x00, "Plain Paper\0" */
+ EPS_MTID_360INKJET , /* 1 0x01, "360dpi Ink Jet Paper \0" */
+ EPS_MTID_IRON , /* 2 0x02, "Iron-On Cool Peel Transfer Paper\0" */
+ EPS_MTID_PHOTOINKJET , /* 3 0x03, "Photo Qaulity Ink Jet Paper #2\0" */
+ EPS_MTID_PHOTOADSHEET , /* 4 0x04, "Photo Qaulity Self Adhesive Sheets\0" */
+ EPS_MTID_MATTE , /* 5 0x05, "Mattee Paper-HeavyWeight\0" */
+ EPS_MTID_PHOTO , /* 6 0x06, "Photo Paper\0" */
+ EPS_MTID_PHOTOFILM , /* 7 0x07, "Photo Quality Glossy Flim\0" */
+ EPS_MTID_MINIPHOTO , /* 8 0x08, "Photo Stickers 4/6\0" */
+ EPS_MTID_OHP , /* 9 0x09, "Ink Jet Transparencies\0 */
+ EPS_MTID_BACKLIGHT , /* 10 0x0A, "Back Light Film\0" */
+ EPS_MTID_PGPHOTO , /* 11 0x0B, "Premium Glossy Photo Paper\0" */
+ EPS_MTID_PSPHOTO , /* 12 0x0C, "Premium Semigloss Photo Paper\0" */
+ EPS_MTID_PLPHOTO , /* 13 0x0D, "Premimum Luster Photo Paper\0" */
+ EPS_MTID_MCGLOSSY , /* 14 0x0E, "Glossy Paper - Photo Weight\0" */
+ EPS_MTID_ARCHMATTE , /* 15 0xOF, "Archival Matte Paper\0" */
+ EPS_MTID_WATERCOLOR , /* 16 0x10, "Water Paper-Radiant White\0" */
+ EPS_MTID_PROGLOSS , /* 17 0x11, "Professional Glossy Paper\0" */
+ EPS_MTID_MATTEBOARD , /* 18 0x12, "Matte Board Paper\0" */
+ EPS_MTID_PHOTOGLOSS , /* 19 0x13, "Photo Quality Glossy Paper\0" */
+ EPS_MTID_SEMIPROOF , /* 20 0x14, "Dupont/EPSON Semigloss Proofing Paper-A\0" */
+ EPS_MTID_SUPERFINE2 , /* 21 0x15, "Super Fine Paper -2\0" */
+ EPS_MTID_DSMATTE , /* 22 0x16, "Double Sided Matte Paper\0" */
+ EPS_MTID_CLPHOTO , /* 23 0x17, "ColorLife Photo Paper\0" */
+ EPS_MTID_ECOPHOTO , /* 24 0x18, "Economy Photo Paper\0" */
+ EPS_MTID_VELVETFINEART , /* 25 0x19, "Velvet Fine Art Paper\0" */
+ EPS_MTID_PROOFSEMI , /* 26 0x1A, "EPSON Proofing Paper Simimatte\0" */
+ EPS_MTID_HAGAKIRECL , /* 27 0x1B, "Post Card - Recycled Paper\0" */
+ EPS_MTID_HAGAKIINKJET , /* 28 0x1C, "Post Card - Ink Jet Paper\0" */
+ EPS_MTID_PHOTOINKJET2 , /* 29 0x1D, "Photo Quality Ink Jet Paper\0" */
+ EPS_MTID_DURABRITE , /* 30 0x1E, "DURABrite Ink Glossy Photo Paper\0" */
+ EPS_MTID_MATTEMEISHI , /* 31 0x1F, "Matte Meishi Card\0" */
+ EPS_MTID_HAGAKIATENA , /* 32 0x20, "Post Card - Address Side\0" */
+ EPS_MTID_PHOTOALBUM , /* 33 0x21, "Photo Album Kit\0" */
+ EPS_MTID_PHOTOSTAND , /* 34 0x22, "Photo Stand Kit\0" */
+ EPS_MTID_RCB , /* 35 0x23, "RC-B\0" */
+ EPS_MTID_PGPHOTOEG , /* 36 0x24, "Premimum Glossy Photo Paper - EG\0" */
+ EPS_MTID_ENVELOPE , /* 37 0x25, "Envelope\0" */
+ EPS_MTID_PLATINA , /* 38 0x26, "Ultra Glossy Photo Paper\0" */
+ EPS_MTID_ULTRASMOOTH , /* 39 0x27, "Ultra Smooth Fine Art Paper\0" */
+ EPS_MTID_SFHAGAKI , /* 40 0x28, "Super Fine Postcard\0" */
+ EPS_MTID_PHOTOSTD , /* 41 0x29, "Premium Glossy Photo Paper (Standard)\0" */
+ EPS_MTID_GLOSSYHAGAKI , /* 42 0x2A, "Glossy Postcard\0" */
+ EPS_MTID_GLOSSYPHOTO , /* 43 0x2B, "Glossy Photo Paper\0" */
+ EPS_MTID_GLOSSYCAST , /* 44 0x2C, "Epson Photo\0" */
+ EPS_MTID_BUSINESSCOAT , /* 45 0x2D, "Business Ink Jet Coat Paper\0" */
+ EPS_MTID_CDDVD , /* 91 0x5B, "CD/DVD Label\0" */
+ EPS_MTID_CDDVDHIGH , /* 92 0x5C, "CD/DVD High Quality Label\0" */
+ EPS_MTID_CDDVDGLOSSY , /* 93 0x5D, "CD/DVD Glossy Surface\0" */
+ EPS_MTID_CLEANING , /* 99 0x63, "Cleaning Paper\0" */
+/* EPS_MTID_UNKNOWN not include this list */
+};
+
+#define EPS_NUM_MEDIA_TYPES sizeof(epsMediaTypeIndex)/sizeof(EPS_UINT32)
+
+
+ /*** LAYOUT */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_MLID_CUSTOM 0x00 /* User-defined margins */
+#define EPS_MLID_BORDERLESS 0x01 /* 0mm */
+#define EPS_MLID_BORDERS 0x02 /* 3mm */
+#define EPS_MLID_CDLABEL 0x04 /* CD/DVD Label */
+#define EPS_MLID_DIVIDE16 0x08 /* 16 Division (for mini phot sheel) */
+
+
+ /*** Print Quality */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_MQID_UNKNOWN 0x00 /* invalid type */
+#define EPS_MQID_DRAFT 0x01
+#define EPS_MQID_NORMAL 0x02
+#define EPS_MQID_HIGH 0x04
+#define EPS_MQID_ALL (EPS_MQID_DRAFT | EPS_MQID_NORMAL | EPS_MQID_HIGH)
+
+
+ /*** Paper Source */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_MPID_NOT_SPEC 0x00
+#define EPS_MPID_AUTO EPS_MPID_NOT_SPEC
+#define EPS_MPID_REAR 0x01
+#define EPS_MPID_FRONT1 0x02
+#define EPS_MPID_FRONT2 0x04
+#define EPS_MPID_CDTRAY 0x08
+//printer PAGE-S
+#define EPS_MPID_PAGE_S_MP_TRAY 0x00
+#define EPS_MPID_PAGE_S_CASSETTE1 0x01
+#define EPS_MPID_PAGE_S_CASSETTE2 0x02
+#define EPS_MPID_PAGE_S_CASSETTE3 0x03
+#define EPS_MPID_PAGE_S_CASSETTE4 0x04
+#define EPS_MPID_PAGE_S_PARAM_MANUALFEED 0x0A
+#define EPS_MPID_PAGE_S_AUTO_TRAY 0xFF
+
+
+/* append for page printer */
+#define EPS_MPID_MPTRAY 0x100
+#define EPS_MPID_FRONT3 0x200
+#define EPS_MPID_FRONT4 0x400
+#define EPS_MPID_ALL_ESCPR (EPS_MPID_REAR | EPS_MPID_FRONT1 | EPS_MPID_FRONT2 | EPS_MPID_CDTRAY)
+#define EPS_MPID_ALL_ESCPAGE (EPS_MPID_MPTRAY | EPS_MPID_FRONT1 | EPS_MPID_FRONT2 | EPS_MPID_FRONT3 | EPS_MPID_FRONT4)
+
+
+#define EPS_IS_CDDVD( t ) \
+ ( EPS_MTID_CDDVD == t \
+ || EPS_MTID_CDDVDHIGH == t \
+ || EPS_MTID_CDDVDGLOSSY == t )
+
+
+ /*** duplex */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_DUPLEX_DISABLE 0x00
+#define EPS_DUPLEX_ENABLE 0x01
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPR_MEDIA_H__ */
+
+/*_______________________________ epson-escpr-media.h _______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
diff --git a/lib/epson-escpr-mem.c b/lib/epson-escpr-mem.c
new file mode 100644
index 0000000..7205e52
--- /dev/null
+++ b/lib/epson-escpr-mem.c
@@ -0,0 +1,439 @@
+/*________________________________ epson-escpr-mem.c ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of copyrightable
+ * material and information now allowed by statutory or judicial law or hereinafter
+ * granted, including without limitation, material generated from the software
+ * programs which are displayed on the screen such as icons, screen display looks,
+ * etc.
+ */
+/*******************************************|********************************************/
+/* */
+/* memory Module */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* void* memRealloc (buffer, oldSizem, newSize ); */
+/* EPS_INT8* memStrStr (strSrc, strFind, gotoEnd ); */
+/* EPS_INT8* memStrStrWithLen (strSrc, nSrcLen, strFind ); */
+/* void memSetEndian (Endianess, byteSize, endTag, value, array); */
+/* void memInspectEndian ( ); */
+/* EPS_INT16 memHtoN16 (nSrc ); */
+/* EPS_INT32 memHtoN32 (nSrc ); */
+/* EPS_INT32 memGetBitCount (bitfield ); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-def.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-mem.h"
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_CMN_FUNC epsCmnFnc;
+
+EPS_INT16 cpuEndian; /* Endian-ness */
+
+
+/*-------------------------------- Local Definition ---------------------------------*/
+/*******************************************|********************************************/
+
+
+/*-------------------------------- Local Functions ----------------------------------*/
+/*******************************************|********************************************/
+
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: memRealloc() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* buffer void* I/O: pointer of buffer */
+/* oldSize EPS_UINT32 I: original buffer size */
+/* newSize EPS_UINT32 I: new buffer size */
+/* */
+/* Return value: */
+/* EPS_INT8* pointer to finded string */
+/* */
+/* Description: */
+/* Realocate buffer. */
+/* */
+/*******************************************|********************************************/
+void* memRealloc (
+
+ void* buffer,
+ EPS_UINT32 oldSize,
+ EPS_UINT32 newSize
+
+){
+ /* Create a temporary pointer to a new buffer of the desired size */
+ void* newBuffer = EPS_ALLOC(newSize);
+ if( NULL == newBuffer ){
+ EPS_SAFE_RELEASE( buffer );
+ return NULL;
+ }
+
+ memset(newBuffer, 0, newSize);
+
+ /* Copy the data from the old buffer to the new one */
+ if(oldSize < newSize)
+ {
+ memcpy(newBuffer, buffer, oldSize);
+ }
+ else
+ {
+ memcpy(newBuffer, buffer, newSize);
+ }
+ /* Free the original buffer */
+ EPS_SAFE_RELEASE( buffer );
+
+ /* Return a pointer to the new block of memory */
+ return newBuffer;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: memStrStr() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* strSrc EPS_INT8* I: Source string */
+/* strFind EPS_INT8* I: Find string. Size MUST be less than 64 byte. */
+/* gotoEnd EPS_BOOL I: If TRUE, the return value indicates */
+/* the end of found string. */
+/* */
+/* Return value: */
+/* EPS_INT8* pointer to finded string */
+/* */
+/* Description: */
+/* Finds the first occurrence of a substring within a string. */
+/* The comparison is NOT case sensitive. */
+/* */
+/*******************************************|********************************************/
+EPS_INT8* memStrStr (
+
+ EPS_INT8* strSrc,
+ const EPS_INT8* strFind,
+ EPS_BOOL gotoEnd
+
+){
+ EPS_INT8 strShadow[64];
+ EPS_INT32 nSrcPos = 0;
+ EPS_INT32 nFindPos = 0;
+ EPS_INT32 nFindedTop = -1;
+ EPS_UINT32 nFindStrLen = 0;
+
+ if(NULL == strSrc || 64 <= strlen(strFind)){
+ return NULL;
+ }
+
+ memset(strShadow, 0, sizeof(strShadow));
+
+ /* create shadow string */
+ do{
+ if( 0x41 <= strFind[nFindPos] && strFind[nFindPos] <= 0x5A){
+ strShadow[nFindPos] = (EPS_INT8)(strFind[nFindPos] + 0x20);
+ } else if( 0x61 <= strFind[nFindPos] && strFind[nFindPos] <= 0x7A){
+ strShadow[nFindPos] = (EPS_INT8)(strFind[nFindPos] - 0x20);
+ } else{
+ strShadow[nFindPos] = strFind[nFindPos];
+ }
+ }while('\0' != strFind[nFindPos++]);
+
+ /* search by strFind & strShadow */
+ nFindPos = 0;
+ while( '\0' != strSrc[nSrcPos] && '\0' != strFind[nFindPos]){
+ if( strSrc[nSrcPos] == strFind[nFindPos]
+ || strSrc[nSrcPos] == strShadow[nFindPos] ){
+ if(-1 == nFindedTop){
+ nFindedTop = nSrcPos;
+ }
+
+ nSrcPos++;
+ nFindPos++;
+
+ } else{
+ if(-1 == nFindedTop){
+ nSrcPos++;
+ nFindPos = 0;
+ } else{
+ nSrcPos = nFindedTop + 1;
+ }
+ nFindedTop = -1;
+ }
+ }
+
+ nFindStrLen = (EPS_UINT32)strlen(strFind);
+ if(0 <= nFindedTop && (EPS_INT32)strlen(strFind) == nFindPos){
+ if(!gotoEnd){
+ return &strSrc[nFindedTop];
+ } else{
+ return &strSrc[nFindedTop] + nFindStrLen;
+ }
+ } else{
+ return NULL;
+ }
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: memStrStrWithLen() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* strSrc EPS_INT8* I: Source string */
+/* nSrcLen EPS_UINT32 I: Source string length */
+/* strFind EPS_INT8* I: Find string. Size MUST be less than 64 byte. */
+/* */
+/* Return value: */
+/* EPS_INT8* pointer to finded string */
+/* */
+/* Description: */
+/* Finds the first occurrence of a substring within a string. */
+/* The comparison is NOT case sensitive. */
+/* Limit nSrcLen characters. */
+/* */
+/*******************************************|********************************************/
+EPS_INT8* memStrStrWithLen (
+
+ EPS_INT8* strSrc,
+ EPS_UINT32 nSrcLen,
+ const EPS_INT8* strFind
+
+){
+ EPS_INT8 strShadow[64];
+ EPS_INT32 nSrcPos = 0;
+ EPS_INT32 nFindPos = 0;
+ EPS_INT32 nFindedTop = -1;
+
+ if(NULL == strSrc || 64 <= strlen(strFind)){
+ return NULL;
+ }
+
+ memset(strShadow, 0, sizeof(strShadow));
+
+ /* create shadow string */
+ do{
+ if( 0x41 <= strFind[nFindPos] && strFind[nFindPos] <= 0x5A){
+ strShadow[nFindPos] = (EPS_INT8)(strFind[nFindPos] + 0x20);
+ } else if( 0x61 <= strFind[nFindPos] && strFind[nFindPos] <= 0x7A){
+ strShadow[nFindPos] = (EPS_INT8)(strFind[nFindPos] - 0x20);
+ } else{
+ strShadow[nFindPos] = strFind[nFindPos];
+ }
+ }while('\0' != strFind[nFindPos++]);
+
+ /* search by strFind & strShadow */
+ nFindPos = 0;
+ while( (EPS_INT32)nSrcLen > nSrcPos && '\0' != strFind[nFindPos]){
+ if( strSrc[nSrcPos] == strFind[nFindPos]
+ || strSrc[nSrcPos] == strShadow[nFindPos] ){
+ if(-1 == nFindedTop){
+ nFindedTop = nSrcPos;
+ }
+
+ nSrcPos++;
+ nFindPos++;
+ } else{
+ if(-1 == nFindedTop){
+ nSrcPos++;
+ } else{
+ nSrcPos = nFindedTop + 1;
+ }
+ nFindPos = 0;
+ nFindedTop = -1;
+ }
+ }
+
+ if(0 <= nFindedTop && (EPS_INT32)strlen(strFind) == nFindPos){
+ return &strSrc[nFindedTop];
+ } else{
+ return NULL;
+ }
+}
+
+
+/*******************************************|********************************************/
+/* Function name: memSetEndian() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Endianess EPS_ENDIAN I: Desired Endianess (Big/Little) */
+/* byteSize EPS_BYTE_SIZE I: 2-byte or 4 bytes to convert */
+/* value EPS_UINT32 I: 4 Bytes to be swapped if necesaray */
+/* array EPS_UINT8* O: Correct endian-ness bytes */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Swap data depending on endian-ness. */
+/* */
+/*******************************************|********************************************/
+void memSetEndian (
+
+ EPS_ENDIAN Endianess, /* Desired Endianess (Big/Little) */
+ EPS_BYTE_SIZE byteSize, /* 2-byte or 4 bytes to convert */
+ EPS_UINT32 value, /* 4 Bytes to be swapped if necesaray */
+ EPS_UINT8* array /* Correct endian-ness bytes */
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_UINT16 value2byte;
+ EPS_UINT32 value4byte;
+
+/*** Initialize Local Variables */
+
+/*** Based on desired Eniandess - Perform test and swap, if necessary */
+ switch (byteSize + Endianess) {
+ /*** Change 2 bytes value to the little endianness */
+ case (EPS_2_BYTES + EPS_ENDIAN_LITTLE):
+#if 0 /* Not Used */
+ value2byte = (EPS_UINT16)value;
+ array[0] = (EPS_UINT8)((value2byte ) & 0x00ff);
+ array[1] = (EPS_UINT8)((value2byte >> 8) & 0x00ff);
+#endif
+ break;
+ /*** Change 2 bytes value to the big endianness */
+ case (EPS_2_BYTES + EPS_ENDIAN_BIG):
+ value2byte = (EPS_UINT16)value;
+ array[0] = (EPS_UINT8)((value2byte >> 8) & 0x00ff);
+ array[1] = (EPS_UINT8)((value2byte ) & 0x00ff);
+ break;
+ /*** Change 4 bytes value to the little endianness */
+ case (EPS_4_BYTES + EPS_ENDIAN_LITTLE):
+ value4byte = (EPS_UINT32)value;
+ array[0] = (EPS_UINT8)((value4byte ) & 0x000000ff);
+ array[1] = (EPS_UINT8)((value4byte >> 8) & 0x000000ff);
+ array[2] = (EPS_UINT8)((value4byte >> 16) & 0x000000ff);
+ array[3] = (EPS_UINT8)((value4byte >> 24) & 0x000000ff);
+ break;
+ /*** Change 4 bytes value to the big endianness */
+ case (EPS_4_BYTES + EPS_ENDIAN_BIG):
+ value4byte = (EPS_UINT32)value;
+ array[0] = (EPS_UINT8)((value4byte >> 24) & 0x000000ff);
+ array[1] = (EPS_UINT8)((value4byte >> 16) & 0x000000ff);
+ array[2] = (EPS_UINT8)((value4byte >> 8) & 0x000000ff);
+ array[3] = (EPS_UINT8)((value4byte ) & 0x000000ff);
+ break;
+ default:
+ break;
+ }
+}
+
+
+/*******************************************|********************************************/
+/* Function name: memInspectEndian() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (None) */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Determine "Endian-ness" for the current cpu. */
+/* */
+/*******************************************|********************************************/
+void memInspectEndian (
+
+ void
+
+){
+ union {
+ EPS_INT8 array[2]; /* Endian-ness test array */
+ EPS_INT16 chars; /* Endian-ness test string */
+ } EndianTest;
+
+ EndianTest.array[0] = 'a';
+ EndianTest.array[1] = 'b';
+ if (EndianTest.chars == 0x6162) {
+ cpuEndian = EPS_ENDIAN_BIG;
+ } else{
+ cpuEndian = EPS_ENDIAN_LITTLE;
+ }
+}
+
+
+EPS_INT32 memGetBitCount(
+
+ EPS_INT32 bitfield
+
+){
+ EPS_INT32 i = 0;
+ EPS_INT32 cnt = 0;
+
+ for(i = 0; i < sizeof(bitfield)*8; i++){
+ if( (bitfield >> i) & 1 ){
+ cnt++;
+ }
+ }
+
+ return cnt;
+}
+
+
+EPS_UINT8 memSearchWhiteColorVal(
+
+ EPS_UINT8 colorPlane,
+ EPS_UINT8* paletteData,
+ EPS_UINT16 paletteSize
+
+){
+ EPS_UINT8 whiteColorValue = 255; /* Set default index for white to negative one */
+ EPS_UINT16 jdx; /* General indes/loop variable */
+ EPS_UINT8* bufPtr = NULL; /* Temporary buffer pointer */
+
+ if( colorPlane == EPS_CP_256COLOR ){
+ bufPtr = paletteData;
+ for ( jdx = 0; jdx < paletteSize/3; jdx++ ) {
+ if (*bufPtr == 255 && *(bufPtr+1) == 255 && *(bufPtr+2) == 255) {
+ whiteColorValue = (EPS_UINT8)jdx;
+ break;
+ }
+ bufPtr += 3;
+ }
+ } else /* if(EPS_CP_FULLCOLOR) */{
+ whiteColorValue = 0xFF;
+ }
+
+ return whiteColorValue;
+}
+
+/*________________________________ epson-escpr-mem.c _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-mem.h b/lib/epson-escpr-mem.h
new file mode 100644
index 0000000..70d4a50
--- /dev/null
+++ b/lib/epson-escpr-mem.h
@@ -0,0 +1,141 @@
+/*_______________________________ epson-escpr-mem.h ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+* Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+*
+* Copyright protection claimed includes all forms and matters of
+* copyrightable material and information now allowed by statutory or judicial
+* law or hereinafter granted, including without limitation, material generated
+* from the software programs which are displayed on the screen such as icons,
+* screen display looks, etc.
+*
+*/
+/*******************************************|********************************************/
+/* */
+/* Epson memory Module Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef _EPSON_ESPCR_MEM_H_
+#define _EPSON_ESPCR_MEM_H_
+#ifdef __cplusplus
+extern "C" {
+#endif /* def __cplusplus */
+
+
+/*------------------------------- Global Compiler Switch -------------------------------*/
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+#include "epson-escpr-pvt.h"
+
+
+/*------------------------------ Import Debug utility -------------------------------*/
+/*******************************************|********************************************/
+#ifdef GCOMSW_DEBUG
+#include "epson-escpr-dbg.h"
+#else
+/* Redefine Debug macros */
+#define EPS_ALLOC( s ) epsCmnFnc.memAlloc((EPS_UINT32)s)
+#define EPS_FREE( p ) epsCmnFnc.memFree( p )
+#define EPS_RETURN(e) return e;
+#define EPS_RETURN_VOID return;
+
+#define EPS_MEM_INIT
+#define EPS_MEM_RESET_PEAK
+#define EPS_MEM_REPORT_PEAK
+#define EPS_MEM_GET_PEAK (0)
+#define EPS_MEM_REPORT_LEAK
+
+#define EPS_DBGPRINT( f )
+#define EPS_DUMP( p, s )
+#define EPS_DUMP_STR( str )
+
+#define EPS_LOG_INITIALIZE(f, m)
+#define EPS_LOG_TREMINATE
+#define EPS_LOG_FUNCIN
+#define EPS_LOG_FUNCOUT(e)
+
+#define DECRALE_DMP_FILE
+#define EPS_DF_OPEN( fn )
+#define EPS_DF_CLOSE
+#define EPS_DF_WRITE( p, s )
+#endif
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+#define EPS_SAFE_RELEASE( p ) \
+ if( NULL != p ){ \
+ EPS_FREE( p ); \
+ p = NULL; \
+ }
+
+/*---------------------------------- CPU Endian-ness -----------------------------------*/
+/*******************************************|********************************************/
+typedef enum _EPS_ENDIAN {
+ EPS_ENDIAN_NOT_TESTED = 1000,
+ EPS_ENDIAN_BIG,
+ EPS_ENDIAN_LITTLE
+} EPS_ENDIAN;
+
+typedef enum _EPS_BYTE_SIZE {
+ EPS_2_BYTES = 2000,
+ EPS_4_BYTES = 4000
+} EPS_BYTE_SIZE;
+
+
+#define EPS_SWP_ORDER16(data) (EPS_INT16)((((data) >> 8) & 0x00FF )|(((data) << 8) & 0xFF00 ) )
+#define EPS_SWP_ORDER32(data) (EPS_INT32)((((data) >> 24) & 0x000000FF)|(((data) >> 8) & 0x0000FF00) | \
+ (((data) << 8) & 0x00FF0000)|(((data) << 24) & 0xFF000000) )
+
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+ /*** Max, Min */
+ /*** -------------------------------------------------------------------------------*/
+#define Max(a,b) ( ((a) > (b)) ? (a) : (b))
+#define Min(a,b) ( ((a) < (b)) ? (a) : (b))
+
+ /*** memcpy macro for readability */
+ /*** -------------------------------------------------------------------------------*/
+#define COPY_BYTES(des,src,size) memcpy(des,src,size); des+=size;
+
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern void* memRealloc (void*, EPS_UINT32, EPS_UINT32 );
+
+extern EPS_INT8* memStrStr (EPS_INT8*, const EPS_INT8*, EPS_BOOL );
+extern EPS_INT8* memStrStrWithLen (EPS_INT8*, EPS_UINT32, const EPS_INT8* );
+
+extern void memSetEndian (EPS_ENDIAN, EPS_BYTE_SIZE, EPS_UINT32, EPS_UINT8*);
+extern void memInspectEndian (void );
+extern EPS_INT32 memGetBitCount (EPS_INT32 );
+extern EPS_UINT8 memSearchWhiteColorVal(EPS_UINT8, EPS_UINT8*, EPS_UINT16 );
+
+#define EPS_MEM_GROW(t, p, pCurSize, nNewSize) \
+ /*EPS_DBGPRINT(("GROW %d->%d\n", *pCurSize, (nNewSize)))*/ \
+ if(*pCurSize < (nNewSize)){ \
+ p = (t)memRealloc(p, *pCurSize, (nNewSize)); \
+ *pCurSize = (nNewSize); \
+ }
+
+#ifdef __cplusplus
+}
+#endif /* def __cplusplus */
+
+#endif /* def _EPSON_ESPCR_MEM_H_ */
+
+/*_______________________________ epson-escpr-mem.h ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-pvt.h b/lib/epson-escpr-pvt.h
new file mode 100644
index 0000000..eb63fd2
--- /dev/null
+++ b/lib/epson-escpr-pvt.h
@@ -0,0 +1,400 @@
+/*_____________________________ epson-escpr-pvt.h __________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/PR Private Data Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPR_PVT_H__
+#define __EPSON_ESCPR_PVT_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------ Local Compiler Switch -------------------------------*/
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+#include "epson-escpr-def.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+typedef void* EPS_HANDLE; /* handle */
+
+/*-------------------------------------- Macros -------------------------------------*/
+/*******************************************|********************************************/
+
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+ /*** API Initialization States */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_STATUS_NOT_INITIALIZED 0
+#define EPS_STATUS_INITIALIZED 1
+#define EPS_STATUS_ESTABLISHED 2
+#define EPS_STATUS_PROCCESSING 3
+
+ /*** Definitions for pm string data */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PM_MAXSIZE 512
+#define EPS_PM_HEADER_LEN 9
+#define EPS_PM2_HEADER_LEN 10
+#define EPS_PM_TERMINATOR_LEN 2
+#define EPS_PM_DATA_LEN (EPS_PM_MAXSIZE - EPS_PM_HEADER_LEN)
+
+ /*** Definitions for device id string data */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_DI_MAXSIZE 512
+
+ /*** reset command states */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_RESET_NOT_SENT 0
+#define EPS_RESET_SENT 1
+
+ /*** I/O port states */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_IO_NOT_OPEN 0
+#define EPS_IO_OPEN 1
+
+ /*** pm Date States */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PM_STATE_NOT_FILTERED 0
+#define EPS_PM_STATE_FILTERED 1
+
+
+ /*** CBT Channel */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_CBTCHANNEL_CTRL 0x01 /* Control Channel */
+#define EPS_CBTCHANNEL_DATA 0x00 /* Data Channel */
+
+ /*** CBT Mechanical Commands */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_CBTCOM_CH 0
+#define EPS_CBTCOM_NC 1
+#define EPS_CBTCOM_EI 2
+#define EPS_CBTCOM_CSA 3
+#define EPS_CBTCOM_CSB 4
+#define EPS_CBTCOM_CX 5
+#define EPS_CBTCOM_XIA 6
+#define EPS_CBTCOM_XIB 7
+#define EPS_CBTCOM_PE 8
+#define EPS_CBTCOM_PJ 9
+#define EPS_CBTCOM_ST 10
+#define EPS_CBTCOM_XIA2 12
+#define EPS_CBTCOM_XIA3 13
+#define EPS_CBTCOM_PM 14
+#define EPS_CBTCOM_DI 15
+#define EPS_CBTCOM_PM2 16
+#define EPS_CBTCOM_RJ 17
+
+
+ /*** CBT Error Code */
+ /*** -------------------------------------------------------------------------------*/
+#define EPCBT_ERR_NONE 0 /* Normal End */
+
+#define EPSCBT_ERR_INITDENIED -1 /* Printer Result=0x01 */
+#define EPSCBT_ERR_VERSION -2 /* Printer Result=0x02 */
+#define EPSCBT_ERR_CLOSEDENIED -3 /* Printer Result=0x03 */
+#define EPSCBT_ERR_RESOURCE -4 /* Printer Result=0x04 */
+#define EPSCBT_ERR_OPENCHANNEL -5 /* Printer Result=0x05 */
+#define EPSCBT_ERR_CHOPENDED -6 /* Printer Result=0x06 */
+#define EPSCBT_ERR_CREDITOVF -7 /* Printer Result=0x07 */
+#define EPSCBT_ERR_CMDDENIED -8 /* Printer Result=0x08 */
+#define EPSCBT_ERR_CHNOTSUPPORT -9 /* Printer Result=0x09 */
+#define EPSCBT_ERR_NOSERVICE -10 /* Printer Result=0x0A */
+#define EPSCBT_ERR_INITFAILED -11 /* Printer Result=0x0B */
+#define EPSCBT_ERR_PACKETSIZE -12 /* Printer Result=0x0C */
+#define EPSCBT_ERR_NULLPACKETSZ -13 /* Printer Result=0x0D */
+
+#define EPSCBT_ERR_PARAM -20 /* parameter error */
+#define EPSCBT_ERR_NOTOPEN -22 /* Port Not open */
+#define EPSCBT_ERR_2NDOPEN -23 /* Port open second */
+#define EPSCBT_ERR_CHNOTOPEN -24 /* Channel not open or close */
+#define EPSCBT_ERR_CH2NDOPEN -25 /* Channel open second */
+#define EPSCBT_ERR_RPLYPSIZE -28 /* OpenChannel Paket Size Fail */
+#define EPSCBT_ERR_WRITEERROR -31 /* Write Error */
+#define EPSCBT_ERR_READERROR -32 /* Read Error */
+#define EPSCBT_ERR_FNCDISABLE -33 /* Not send or receive */
+
+#define EPSCBT_ERR_FATAL -50 /* FATAL Error */
+#define EPSCBT_ERR_CBTDISABLE -52 /* fail EpsonPackingCommand */
+#define EPSCBT_ERR_NOREPLY -55 /* no Reply */
+
+#define EPSCBT_ERR_MULFORMEDPACKET -80 /* packet data fail */
+#define EPSCBT_ERR_UEREPLY -82 /* miss match reply data */
+#define EPSCBT_ERR_UERESULT -85 /* Not Result value */
+
+ /*** Service Pack Error */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_ERR_SP_INVALID_POINTER -200
+#define EPS_ERR_SP_INVALID_HEADER -201
+#define EPS_ERR_SP_INVALID_TERMINATOR -202
+#define EPS_ERR_SP_NO_VALID_FIELD -203
+
+ /*** Misc */
+ /*** -------------------------------------------------------------------------------*/
+#define MERGED_FIELD 0xFF
+
+ /*** Save process for continue */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_SAVEP_NONE 0
+#define EPS_SAVEP_START_PAGE 1
+#define EPS_SAVEP_END_PAGE 2
+#define EPS_SAVEP_LEFTOVERS 3
+
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+ /*** Printer Status */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_STATUS_INFO_ {
+ EPS_INT32 nState;
+ EPS_INT32 nError;
+ EPS_INT32 nWarn;
+ EPS_INT32 nCancel;
+ EPS_INT32 nPrepare;
+ EPS_INT32 nInkNo;
+ EPS_INT32 nInkError;
+ EPS_INT32 nColor[EPS_INK_NUM];
+ EPS_INT32 nColorType[EPS_INK_NUM];
+} EPS_STATUS_INFO;
+
+ /*** Basic Rect Object */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_RECT_ {
+ EPS_INT32 top;
+ EPS_INT32 left;
+ EPS_INT32 bottom;
+ EPS_INT32 right;
+} EPS_RECT;
+
+typedef struct _tagEPS_LINE_SEGMENT_ {
+ EPS_INT32 start;
+ EPS_INT32 length;
+} EPS_LINE_SEGMENT;
+
+ /*** BMP Band Data */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_BANDBMP_ {
+ EPS_UINT32 widthBytes; /* number of bytes in each scan line */
+ const EPS_UINT8* bits; /* pointer to the the bit values for the bitmap */
+} EPS_BANDBMP;
+
+ /*** Base Point */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_BASEPOINT_ {
+ EPS_RECT border;
+ EPS_RECT borderless;
+ EPS_RECT pad;
+} EPS_BASEPT;
+
+ /*** "pm" Command Reply Data */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_PM_DATA_ {
+ EPS_INT32 state;
+ EPS_UINT8 pmString[EPS_PM_MAXSIZE];
+} EPS_PM_DATA;
+
+
+ /*** Printer Infomation */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_PRINTER_INN_ {
+ EPS_INT32 protocol; /* Communication protocol */
+ EPS_INT32 supportFunc;
+ EPS_INT8 manufacturerName[EPS_NAME_BUFFSIZE];
+ EPS_INT8 modelName[EPS_NAME_BUFFSIZE];
+ EPS_INT8 friendlyName[EPS_NAME_BUFFSIZE];
+ EPS_INT8 location[EPS_ADDR_BUFFSIZE];
+ /* unused EPS_INT8 serial[EPS_NAME_BUFFSIZE];*/
+ EPS_INT8 printerID[EPS_PRNID_BUFFSIZE];
+ /* unused EPS_BOOL needUpgrade; */
+ EPS_HANDLE protocolInfo;
+ EPS_UINT16 printPort;
+
+ EPS_UINT32 language; /* print language */
+ EPS_INT8 macAddress[EPS_ADDR_BUFFSIZE];
+
+ /*** Supported Media */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_SUPPORTED_MEDIA supportedMedia;
+ EPS_INT32 JpgMax;
+
+ /*** Original PM reply */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_PM_DATA pmData;
+
+ EPS_UINT8 feedDir;
+} EPS_PRINTER_INN;
+
+
+ /*** Printer List */
+ /*** -------------------------------------------------------------------------------*/
+typedef struct _tagEPS_PL_NODE_ {
+ EPS_PRINTER_INN* printer;
+ /* unused EPS_BOOL notified; */
+ struct _tagEPS_PL_NODE_* next;
+}EPS_PL_NODE;
+
+typedef struct _tagEPS_PRINTER_LIST_ {
+ EPS_INT32 num; /* printer count of espFindPrinter result */
+ EPS_PL_NODE* root; /* printer list of espFindPrinter result */
+}EPS_PRINTER_LIST;
+
+/*--------------------------- Internal Print Job Structure --------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagEPS_PRINT_JOB_ {
+
+ /*** Job / Page Status State */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_INT32 jobStatus; /* Job status */
+ EPS_INT32 pageStatus; /* Page status */
+ EPS_INT32 findStatus; /* Find status */
+
+ /*** Communication Mode */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_INT32 commMode; /* Computer byte storage order */
+
+ /*** Platform Specifics */
+ /*** -------------------------------------------------------------------------------*/
+#ifdef GCOMSW_EPSON_SLEEP
+ EPS_INT32 sleepSteps; /* Sleep loop value */
+#endif
+
+ /*** Page Attributes */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_JOB_ATTRIB attr;
+
+ /*** Run-Time Job Printing Parameters */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_INT32 verticalOffset;
+ EPS_UINT32 jpegSize;
+
+ /*** Borderless Printing Parameters */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_INT32 borderlessMode; /* Borderless mode selected */
+ /* unused EPS_INT32 topCnt; Counter - many top rasters saved */
+ /* unused EPS_INT32 botCnt; Counter - many bottom rasters saved */
+ /* unused EPS_BOOL topFlushed; Flag to determine if top to be flushed */
+ /* unused EPS_BASEPT basePt; */
+
+ EPS_RECT border; /* Border Base Point */
+ EPS_RECT borderless; /* Borderless Base Point */
+ EPS_RECT pad; /* Pad Base Point */
+
+ /*** Media */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_INT32 paperWidth; /* Width of Media */
+ EPS_INT32 paperHeight; /* Height of Media */
+
+ /*** Margins - based on Media and border Mode */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_INT32 topMargin; /* Media/Border-Mode Top Margin */
+ EPS_INT32 leftMargin; /* Media/Border-Mode Left Margin */
+ EPS_INT32 bottomMargin; /* Media/Border-Mode Bottom Margin */
+ EPS_INT32 rightMargin; /* Media/Border-Mode Right Margin */
+
+ /*** Printable */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_UINT32 printableAreaWidth; /* users setting */
+ EPS_UINT32 printableAreaHeight; /* users setting */
+ EPS_UINT8 bpp; /* 3 for RGB, 1 for 256 */
+ EPS_INT16 offset_x; /* offset to be used. calculated when */
+ EPS_INT16 offset_y; /* changing basepoint */
+
+ /*** Print Band Information */
+ /*** -------------------------------------------------------------------------------*/
+ /* unused const EPS_UINT8* printBandData; Print Band Data */
+ /* unused EPS_UINT32 printBandWidth; Print Band Width in Pixels */
+ EPS_UINT32 printBandHeight; /* Print Band Height in image lines */
+ /* unused EPS_UINT32 printBandBPL; Print Band Bytes Per Line */
+ /* unused EPS_RECT printBandRect; Rect for print band */
+
+ /*** Job Trarget Printer */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_PRINTER_INN* printer;
+
+ /*** Protocol depend info */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_HANDLE hProtInfo;
+
+ /*** Reset State Flag */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_INT32 resetSent; /* sent */
+ EPS_BOOL resetReq; /* reqest from printer */
+ EPS_BOOL sendJS;
+
+ /*** Communication */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_BOOL bComm;
+ EPS_BOOL transmittable; /* possible to transmit */
+ EPS_BOOL bJpgLimit;
+
+#if 0 /* DEL */
+ /*** Additional data */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_UINT32 additional;
+ struct { /* QR Code */
+ EPS_INT32 cellNum;
+ EPS_UINT8* bits;
+ EPS_INT32 dpc; /* Dots per Cell */
+ EPS_RECT rc;
+ } qrcode;
+#endif
+
+ /*** Misc */
+ /*** -------------------------------------------------------------------------------*/
+ EPS_UINT8 whiteColorValue; /* Define white value or index */
+ EPS_BOOL needBand;
+ EPS_UINT8 platform;
+ EPS_INT32 pageCount;
+
+ struct { /* Leftovers */
+ EPS_INT32 lastError;
+ EPS_INT32 savePoint;
+ EPS_INT32 saveStep;
+ const EPS_UINT8* sendData; /* buffer */
+ EPS_UINT32 sendDataSize; /* Data size */
+ EPS_UINT32 jpgSize; /* Jpeg Leftovers size */
+ EPS_BOOL nextPage;
+ EPS_INT32 epRetry;
+ EPS_BOOL skipLine;
+ } contData;
+
+}EPS_PRINT_JOB;
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+EPS_ERR_CODE SendCommand (const EPS_UINT8 *Buffer, EPS_UINT32, EPS_UINT32*, EPS_BOOL );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPR_PVT_H__ */
+
+/*________________________________ epson-escpr-pvt.h _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
diff --git a/lib/epson-escpr-services.c b/lib/epson-escpr-services.c
new file mode 100644
index 0000000..656fb12
--- /dev/null
+++ b/lib/epson-escpr-services.c
@@ -0,0 +1,2376 @@
+/*____________________________ epson-escpr-services.c ______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/P-R Lib Internal Service Routines */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE serAnalyzeStatus (Status, StatusInfo ); */
+/* void serDelayThread (Milliseconds ); */
+/* EPS_ERR_CODE serSleep (Milliseconds ); */
+/* EPS_INT32 serGetInkError (pStatInfo, pNotify ); */
+/* EPS_INT32 _SP_ChangeSpec_UpdatePMReply(printer, orgPmString ); */
+/* EPS_ERR_CODE _SP_ChangeSpec_DraftOnly(printer, jobAtter ); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-err.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpr-media.h"
+#include "epson-escpr-services.h"
+#ifdef GCOMSW_CMD_ESCPAGE_S
+#include "epson-escpage-s.h"
+#endif
+/*------------------------------------ Definition -----------------------------------*/
+/*******************************************|********************************************/
+ /*** Index of printing quality */
+ /*** -------------------------------------------------------------------------------*/
+#define Q_DRAFT 0
+#define Q_NORMAL 1
+#define Q_HIGH 2
+
+#ifdef EPS_LOG_MODULE_SER
+#define EPS_LOG_MODULE EPS_LOG_MODULE_SER
+extern EPS_CMN_FUNC epsCmnFnc;
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+/*------------------------------ Local Global Variables ------------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagSP_OBSERVER
+{
+ const EPS_PRINTER_INN *printer; /* current printer */
+ EPS_UINT8 colorPlane; /* Image color plane */
+}SP_OBSERVER;
+
+static SP_OBSERVER g_observer = {0};
+
+/*--------------------------- Special PM String table -------------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagSP_PM_STRINGS
+{
+ EPS_UINT32 id; /* ID */
+ const EPS_UINT8* res; /* PM String */
+ EPS_UINT32 len; /* length */
+}SP_PM_STRINGS;
+
+const EPS_UINT8 spm_E300[] = {0x40, 0x42, 0x44, 0x43, 0x20, 0x50, 0x4D, 0x0D, 0x0A, 0x53, 0x0F, 0x54, 0x26, 0x82, 0x2F, 0x54,
+ 0x0B, 0x82, 0x2F, 0x54, 0x2B, 0x82, 0x2F, 0x2F, 0x53, 0x0A, 0x54, 0x26, 0x82, 0x2F, 0x54, 0x0B,
+ 0x82, 0x2F, 0x54, 0x2B, 0x82, 0x2F, 0x2F, 0x53, 0x10, 0x54, 0x0B, 0x82, 0x2F, 0x54, 0x08, 0x02,
+ 0x2F, 0x2F, 0x53, 0x23, 0x54, 0x0B, 0x82, 0x2F, 0x2F, 0x0D, 0x0A};
+const EPS_UINT8 spm_E500[] = {0x40, 0x42, 0x44, 0x43, 0x20, 0x50, 0x4D, 0x0D, 0x0A, 0x53, 0x0F, 0x54, 0x26, 0x82, 0x2F, 0x54,
+ 0x0B, 0x82, 0x2F, 0x54, 0x2B, 0x82, 0x2F, 0x2F, 0x53, 0x0A, 0x54, 0x26, 0x82, 0x2F, 0x54, 0x0B,
+ 0x82, 0x2F, 0x54, 0x2B, 0x82, 0x2F, 0x2F, 0x53, 0x2B, 0x54, 0x0B, 0x82, 0x2F, 0x2F, 0x53, 0x10,
+ 0x54, 0x0B, 0x82, 0x2F, 0x54, 0x08, 0x02, 0x2F, 0x2F, 0x53, 0x23, 0x54, 0x0B, 0x82, 0x2F, 0x2F,
+ 0x0D, 0x0A};
+const EPS_UINT8 spm_PM200[] = {0x40, 0x42, 0x44, 0x43, 0x20, 0x50, 0x4D, 0x0D, 0x0A, 0x53, 0x0A, 0x54, 0x26, 0x82, 0x2F, 0x54,
+ 0x0B, 0x82, 0x2F, 0x54, 0x2B, 0x82, 0x2F, 0x2F, 0x53, 0x10, 0x54, 0x08, 0x02, 0x2F, 0x2F, 0x0D,
+ 0x0A};
+const EPS_UINT8 spm_PM240[] = {0x40, 0x42, 0x44, 0x43, 0x20, 0x50, 0x4D, 0x0D, 0x0A, 0x53, 0x0A, 0x54, 0x26, 0x82, 0x2F, 0x54,
+ 0x0B, 0x82, 0x2F, 0x54, 0x2B, 0x82, 0x2F, 0x2F, 0x53, 0x2B, 0x54, 0x0B, 0x82, 0x2F, 0x2F, 0x53,
+ 0x10, 0x54, 0x08, 0x42, 0x2F, 0x2F, 0x0D, 0x0A};
+
+const SP_PM_STRINGS spPMStrTbl[] =
+{
+ { EPS_PMS_E300, spm_E300, sizeof(spm_E300) },
+ { EPS_PMS_E500, spm_E500, sizeof(spm_E500) },
+ { EPS_PMS_PM200, spm_PM200, sizeof(spm_PM200) },
+ { EPS_PMS_PM240, spm_PM240, sizeof(spm_PM240) }
+};
+
+const EPS_UINT32 EPS_SPM_STRINGS = sizeof(spPMStrTbl) / sizeof(SP_PM_STRINGS);
+
+/*-------------------------------- Local Functions ----------------------------------*/
+/*******************************************|********************************************/
+static EPS_INT32 _SP_LoadPMString (EPS_UINT32, EPS_UINT8*, EPS_UINT32 );
+static EPS_INT32 _pmFindSfield (EPS_UINT8, EPS_UINT8*, EPS_UINT8**, EPS_UINT8**);
+static EPS_UINT8* _pmScanTfield (EPS_UINT8, EPS_UINT8* );
+static EPS_INT16 _pmAppendTfield (EPS_UINT8*, EPS_UINT8* );
+static void _pmValidateRemoveDelimiter (EPS_UINT8*, EPS_UINT8*, EPS_INT32 );
+static EPS_INT16 _pmValidateRemoveUnknownSfield (EPS_UINT8*, EPS_UINT8* );
+static void _pmCorrectUnknownTfield (EPS_UINT8*, EPS_UINT8* );
+static void _pmCorrectDupulicatedFields (EPS_UINT8*, EPS_UINT8* );
+static void _pmAdjustQuality (EPS_UINT8* );
+
+/*----------------------------------- Debug Dump -------------------------------------*/
+/*******************************************|********************************************/
+#define _DEBUG_BIN_STATUS_ 0 /* 0: OFF 1: ON */
+
+#if _DEBUG_BIN_STATUS_ || _VALIDATE_SUPPORTED_MEDIA_DATA_
+#define SerDebugPrintf(a) EPS_DBGPRINT( a )
+#else
+#define SerDebugPrintf(a)
+#endif
+
+/*------------------------------------ Debug Dump -----------------------------------*/
+/*******************************************|********************************************/
+ /*** ALL Debug Dump Switch for <epson-escpr-service.c> */
+ /*** -------------------------------------------------------------------------------*/
+#define _ESCPR_DEBUG_SP 0 /* 0: OFF 1: ON */
+#define _ESCPR_DEBUG_SP_VERBOSE 0 /* 0: OFF 1: ON */
+
+ /*** _ESCPR_DEBUG_SP --- Definition of << DUMP_PMREPLY() >> */
+ /*** -------------------------------------------------------------------------------*/
+#if _ESCPR_DEBUG_SP | _VALIDATE_SUPPORTED_MEDIA_DATA_
+
+typedef enum _DUMP_TYPE {
+ DUMP_HEX = 0,
+ DUMP_ASCII,
+ DUMP_S_TAG_ONLY,
+} DUMP_TYPE;
+
+char* str[] ={
+ "DUMP_HEX",
+ "DUMP_ASCII",
+ "DUMP_S_TAG_ONLY",
+ };
+
+static void print_PMREPLY(EPS_UINT8* pm, DUMP_TYPE type, EPS_INT8* msg)
+{
+ EPS_UINT8* p = pm;
+ EPS_INT16 col = 0;
+
+ if(*p != 'S') {
+ if(type != DUMP_HEX) {
+ return; /* do not anything */
+ }
+
+ /* Anyway if type is DUMP_HEX then dump it */
+ }
+
+ printf("%s\r\n", msg);
+ printf("PM REPLY DUMP [TYPE:%s]\r\n", str[type]);
+
+ if(type == DUMP_HEX) {
+ while(!((*p == 0x0D) && (*(p+1) == 0x0A))) {
+ printf("0x%02X ", *p++);
+
+ if((++col % 10) == 0) {
+ printf("\r\n");
+ }
+ }
+
+ } else {
+ while(*p == 'S') {
+ printf("%c ", *p++);
+ printf("%02d\r\n", *p++);
+ while(*p == 'T') {
+ printf(" %c", *p++);
+ printf(" %02d", *p++);
+ printf(" [0x%02X]", *p++);
+ printf(" %c\r\n", *p++);
+ }
+ printf("%c\r\n", *p++);
+
+ if(type == DUMP_S_TAG_ONLY) {
+ break;
+ }
+
+ if ((*p == 0x0D) && (*(p+1) == 0x0A)) {
+ break;
+ }
+ }
+
+ }
+
+ if(type != DUMP_S_TAG_ONLY) {
+ printf("0x%02X ", *p++);
+ printf("0x%02X ", *p);
+ }
+
+ printf("\r\nEND\r\n");
+
+}
+#endif
+
+#if _ESCPR_DEBUG_SP
+#define DUMP_PMREPLY(a) print_PMREPLY a
+#else
+#define DUMP_PMREPLY(a)
+#endif
+
+ /*** _ESCPR_DEBUG_SP_VERBOSE */
+ /*** --- Definition of << VERBOSE_DUMP_PMREPLY() >> and << verbose_dbprint() >> */
+ /*** -------------------------------------------------------------------------------*/
+#if _ESCPR_DEBUG_SP_VERBOSE
+#define VERBOSE_DUMP_PMREPLY(a) print_PMREPLY a
+#define verbose_dbprint(a) EPS_DBGPRINT(a)
+#else
+#define VERBOSE_DUMP_PMREPLY(a)
+#define verbose_dbprint(a)
+#endif
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: serParseDeviceID() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* deviceIDString EPS_INT8* I: DeviceID string */
+/* manufacturer EPS_INT8* I: Manufacturer Name */
+/* modelName EPS_INT8* I: Model Name */
+/* */
+/* Return value: */
+/* TRUE - Success */
+/* FALSE - Bad format or Not ESC/P-R device */
+/* */
+/* Description: */
+/* Get the manufacturer name and modelName from DeviceID string. */
+/* */
+/*******************************************|********************************************/
+EPS_BOOL serParseDeviceID (
+
+ EPS_INT8* deviceIDString,
+ EPS_INT8* manufacturer,
+ EPS_INT8* modelName,
+ EPS_INT32* cmdLevel,
+ EPS_UINT32* lang
+
+){
+ EPS_INT8* i;
+ EPS_INT8* j;
+ EPS_INT8* k;
+ EPS_INT8* p;
+ EPS_BOOL found = FALSE;
+
+ EPS_LOG_FUNCIN;
+
+/*** Delete the data of the device ID length from string */
+ if(strlen(deviceIDString) < 2){
+ EPS_RETURN( FALSE );
+ }
+ if(deviceIDString[0] == 0x00 || deviceIDString[1] == 0x00)
+ deviceIDString += 2;
+
+/*** ================================================================================== */
+/*** Step 1: Check for ESC/PR Support */
+/*** ================================================================================== */
+ if((i = strstr(deviceIDString, "CMD:")) == NULL) {
+ EPS_RETURN( FALSE );
+ }
+ i += 4;
+
+ if((j = strstr(i, ";")) == NULL) {
+ EPS_RETURN( FALSE );
+ }
+ *j = '\0';
+
+ while( NULL != i ){
+ if((k = strstr(i, ",")) != NULL) {
+ *k = '\0';
+ }
+
+ if((p = strstr(i, "ESCPR")) != NULL) {
+ found = TRUE;
+ if(NULL != lang){
+ *lang = EPS_LANG_ESCPR;
+ }
+ if(NULL != cmdLevel){
+ sscanf(p+5, "%d", cmdLevel);
+ }
+ break;
+
+#ifdef GCOMSW_CMD_ESCPAGE
+ } else if(strstr(i, "ESCPAGECOLOR") != NULL) {
+ found = TRUE;
+ if(NULL != lang){
+ *lang = EPS_LANG_ESCPAGE_COLOR;
+ }
+ if(NULL != cmdLevel){
+ *cmdLevel = 1;
+ }
+ break;
+
+ } else if(strstr(i, "ESCPAGE") != NULL) {
+ if(strstr(i, "ESCPAGES") == NULL) {
+ found = TRUE;
+ if(NULL != lang){
+ *lang = EPS_LANG_ESCPAGE;
+ }
+ if(NULL != cmdLevel){
+ *cmdLevel = 1;
+ }
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ } else{
+ found = pageS_ParseLang(i, cmdLevel, lang);
+#endif
+ }
+#endif
+ }
+
+ if(k){
+ *k = ',';
+ i = k+1;
+ if(i >= j){
+ break;
+ }
+ } else{
+ break;
+ }
+ }
+ if(k)*k = ',';
+
+ *j = ';';
+
+ if(FALSE == found){
+ EPS_RETURN( FALSE );
+ }
+
+
+/*** ================================================================================== */
+/*** Step 2: Get Manufacturer Name */
+/*** ================================================================================== */
+ if((i = strstr(deviceIDString, "MFG:")) == NULL) {
+ /* Invalid device ID. */
+ EPS_RETURN( FALSE );
+ }
+
+ i += 4;
+ j = i;
+
+ while(*j != ';')
+ {
+ j++;
+
+ /* Emergency exit condition to prevent an infinite loop scenario; if we hit a */
+ /* carriage return, we've run too far */
+ if(*j == 0x0D) {
+ EPS_RETURN( FALSE );
+ }
+ }
+ /* Null-terminate the MFG substring. */
+ *j = 0;
+
+ /* Make sure the manufacturer name is not longer than 64 bytes. */
+ if(strlen(i) < 64) {
+ strcpy(manufacturer, i); /* If the name is OK, copy the whole string as-is */
+ }
+ else {
+ memcpy(manufacturer, i, 63); /* If the name is longer than 64 bytes, only copy */
+ } /* 63 bytes and leave the 64th as null terminator */
+
+ /* Return the string to its original format. */
+ *j = ';';
+
+/*** ================================================================================== */
+/*** Step 3: Get Model Name */
+/*** ================================================================================== */
+ if((i = strstr(deviceIDString, "MDL:")) == NULL) {
+ /* Invalid device ID. */
+ EPS_RETURN( FALSE );
+ }
+
+ i += 4;
+ j = i;
+
+ while (*j != ';')
+ {
+ j++;
+
+ /* Emergency exit condition to prevent an infinite loop scenario; if we hit a */
+ /* carriage return, we've run too far */
+ if(*j == 0x0D){
+ /* Invalid device ID. */
+ EPS_RETURN( FALSE );
+ }
+ }
+
+ /* Null-terminate the MDL substring. */
+ *j = 0;
+
+ /* Make sure the model name is not longer than 64 bytes. */
+ if(strlen(i) < 64) {
+ strcpy(modelName, i); /* If the name is OK, copy the whole string as-is */
+ }
+ else {
+ memcpy(modelName, i, 63); /* If the name is longer than 64 bytes, only copy */
+ /* 63 bytes, leaving the 64th as null terminator */
+ }
+
+ EPS_RETURN( TRUE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: serAnalyzeStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Status EPS_INT8* I: Printer Status string */
+/* pstInfo EPS_STATUS_INFO* O: Printer Status information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get the printer status and analyze the status string. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE serAnalyzeStatus (
+
+ EPS_INT8* Status,
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_UINT8* Field;
+ EPS_UINT8* EndField;
+ EPS_INT32 i;
+ EPS_INT32 Min;
+
+ EPS_UINT8 Header;
+ EPS_UINT8 ParameterByte;
+ EPS_INT8* Ink;
+ EPS_INT8 Parameter[128];
+ EPS_UINT8 InkCartridgeType = 0;
+
+ EPS_LOG_FUNCIN;
+
+ if((Field = (EPS_UINT8*)strstr(Status,"ST2")) == NULL ){
+ SerDebugPrintf(("EPS SER: Get Stat -> ST not found [%s]\r\n",Status));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+
+ pstInfo->nState = EPS_ST_IDLE;
+ pstInfo->nError = EPS_PRNERR_NOERROR;
+ pstInfo->nWarn = EPS_PRNWARN_NONE;
+#if _DEBUG_BIN_STATUS_
+ EPS_DUMP(Status, 256);
+#endif
+ Field = Field + 5;
+ EndField = Field + (2+(*Field)+ ((*(Field+1))*256) );
+ Field = Field + 2;
+
+ while ( Field < EndField ) {
+
+ Header = (EPS_UINT8) Field[0];
+ ParameterByte = (EPS_UINT8) Field[1];
+ memcpy(Parameter, Field+2, (EPS_INT8)ParameterByte );
+
+ Field = Field + 2 + ParameterByte;
+
+ switch( Header ) {
+ case 0x01: /* ST */
+ switch( Parameter[0] ) {
+ case 0x00: pstInfo->nState = EPS_ST_ERROR; break;
+ case 0x01: pstInfo->nState = EPS_ST_SELF_PRINTING; break;
+ case 0x02: pstInfo->nState = EPS_ST_BUSY; break;
+ case 0x03: pstInfo->nState = EPS_ST_WAITING; break;
+ case 0x04: pstInfo->nState = EPS_ST_IDLE; break;
+ /* case 0x05: pstInfo->nState = EPS_ST_PAUSE; break;*/ /* Not supported by 2006 Model */
+ /* case 0x06: pstInfo->nState = EPS_ST_INKDRYING break;*/ /* Not supported by 2006 Model */
+ case 0x07: pstInfo->nState = EPS_ST_CLEANING; break;
+ case 0x08: pstInfo->nState = EPS_ST_FACTORY_SHIPMENT; break;
+ /* case 0x09: pstInfo->nState = EPS_ST_MOTOR_DRIVE_OFF; break;*/ /* Not supported by 2006 Model */
+ case 0x0A: pstInfo->nState = EPS_ST_SHUTDOWN; break;
+ /* case 0x0B: pstInfo->nState = EPS_ST_WAITPAPERINIT; break;*/ /* Not supported by 2006 Model */
+ /* case 0x0C: pstInfo->nState = EPS_ST_INIT_PAPER; break;*/ /* Not supported by 2006 Model */
+ default:
+ pstInfo->nState = EPS_ST_ERROR;
+ if(pstInfo->nError == EPS_PRNERR_NOERROR){
+ pstInfo->nError = EPS_PRNERR_GENERAL;
+ }
+ break;
+ }
+ break;
+ case 0x02: /* ER */
+ EPS_DBGPRINT(("* ERR 0x%02X *\n", Parameter[0]))
+ switch(Parameter[0]) {
+ case 0x00: pstInfo->nError = EPS_PRNERR_FATAL; break;
+ case 0x01: pstInfo->nError = EPS_PRNERR_INTERFACE; break;
+ case 0x02:
+ if ( obsIsA3Model(EPS_MDC_STATUS) == TRUE ) {
+ pstInfo->nError = EPS_PRNERR_CDRGUIDEOPEN;
+ } else{
+ pstInfo->nError = EPS_PRNERR_COVEROPEN;
+ }
+ break;
+ /* case 0x03: pstInfo->nError = EPS_PRNERR_LEVERPOSITION; break;*/ /* Not supported by 2006 Model */
+ case 0x04: pstInfo->nError = EPS_PRNERR_PAPERJAM; break;
+ case 0x05: pstInfo->nError = EPS_PRNERR_INKOUT; break;
+ case 0x06: pstInfo->nError = EPS_PRNERR_PAPEROUT; break;
+ /* case 0x07: pstInfo->nError = EPS_PRNERR_INITIALIZESETTING; break;*/ /* Not supported by 2006 Model */
+ /* case 0x08: pstInfo->nError = EPS_PRNERR_UNKNOWN; break;*/ /* Not supported by 2006 Model */
+ /* case 0x09: pstInfo->nError = EPS_PRNERR_PAPERCHANGE_UNCOMP; break;*/ /* Not supported by 2006 Model */
+ case 0x0A: pstInfo->nError = EPS_PRNERR_SIZE_TYPE_PATH/*EPS_PRNERR_PAPERSIZE*/;break;/* supported by 2008 Model */
+ /* case 0x0B: pstInfo->nError = EPS_PRNERR_RIBBONJAM; break;*/ /* Not supported by 2006 Model */
+ case 0x0C: pstInfo->nError = EPS_PRNERR_SIZE_TYPE_PATH; break;
+ /* case 0x0D: pstInfo->nError = EPS_PRNERR_PAPERTHICKLEVER; break;*/ /* Not supported by 2006 Model */
+ /* case 0x0E: pstInfo->nError = EPS_PRNERR_PAPERFEED; break;*/ /* Not supported by 2006 Model */
+ /* case 0x0F: pstInfo->nError = EPS_PRNERR_SIMMCOPY; break;*/ /* Not supported by 2006 Model */
+ case 0x10: pstInfo->nError = EPS_PRNERR_SERVICEREQ; break;
+ /* case 0x11: pstInfo->nError = EPS_PRNERR_WAITTEAROFFRETURN; break;*/ /* Not supported by 2006 Model */
+ case 0x12: pstInfo->nError = EPS_PRNERR_DOUBLEFEED; break;
+ /* case 0x13: pstInfo->nError = EPS_PRNERR_HEADHOT; break;*/ /* Not supported by 2006 Model */
+ /* case 0x14: pstInfo->nError = EPS_PRNERR_PAPERCUTMIS; break;*/ /* Not supported by 2006 Model */
+ /* case 0x15: pstInfo->nError = EPS_PRNERR_HOLDLEVERRELEASE; break;*/ /* Not supported by 2006 Model */
+ /* case 0x16: pstInfo->nError = EPS_PRNERR_NOT_CLEANING; break;*/ /* Not supported by 2006 Model */
+ /* case 0x17: pstInfo->nError = EPS_PRNERR_PAPERCONFIG; break;*/ /* Not supported by 2006 Model */
+ /* case 0x18: pstInfo->nError = EPS_PRNERR_PAPERSLANT; break;*/ /* Not supported by 2006 Model */
+ /* case 0x19: pstInfo->nError = EPS_PRNERR_CLEANINGNUMOVER; break;*/ /* Not supported by 2006 Model */
+ case 0x1A: pstInfo->nError = EPS_PRNERR_INKCOVEROPEN; break;
+ /* case 0x1B: pstInfo->nError = EPS_PRNERR_LFP_INKCARTRIDGE; break;*/ /* Not supported by 2006 Model */
+ /* case 0x1C: pstInfo->nError = EPS_PRNERR_CUTTER; break;*/ /* Not supported by 2006 Model */
+ /* case 0x1D: pstInfo->nError = EPS_PRNERR_CUTTERJAM; break;*/ /* Not supported by 2006 Model */
+ /* case 0x1E: pstInfo->nError = EPS_PRNERR_INKCOLOR; break;*/ /* Not supported by 2006 Model */
+ /* case 0x1F: pstInfo->nError = EPS_PRNERR_CUTTERCOVEROPEN; break;*/ /* Not supported by 2006 Model */
+ /* case 0x20: pstInfo->nError = EPS_PRNERR_LFP_INKLEVERRELEASE; break;*/ /* Not supported by 2006 Model */
+ /* case 0x22: pstInfo->nError = EPS_PRNERR_LFP_NOMAINTENANCETANK1; break;*/ /* Not supported by 2006 Model */
+ /* case 0x23: pstInfo->nError = EPS_PRNERR_CARTRIDGECOMBINATION; break;*/ /* Not supported by 2006 Model */
+ /* case 0x24: pstInfo->nError = EPS_PRNERR_LFP_COMMAND; break;*/ /* Not supported by 2006 Model */
+ /* case 0x25: pstInfo->nError = EPS_PRNERR_LEARCOVEROPEN; break;*/ /* Not supported by 2006 Model */
+ case 0x25: pstInfo->nError = EPS_PRNERR_COVEROPEN; break;
+ /* case 0x26: pstInfo->nError = EPS_PRNERR_MULTICENSORGAIN; break;*/ /* Not supported by 2006 Model */
+ /* case 0x27: pstInfo->nError = EPS_PRNERR_NOT_AUTOADJUST; break;*/ /* Not supported by 2006 Model */
+ /* case 0x28: pstInfo->nError = EPS_PRNERR_FAILCLEANING; break;*/ /* Not supported by 2006 Model */
+ case 0x29: pstInfo->nError = EPS_PRNERR_NOTRAY; break;
+ case 0x2A: pstInfo->nError = EPS_PRNERR_CARDLOADING; break;
+ case 0x2B:
+ if ( obsIsA3Model(EPS_MDC_STATUS) == TRUE ) {
+ pstInfo->nError = EPS_PRNERR_CDRGUIDEOPEN;
+ } else {
+ pstInfo->nError = EPS_PRNERR_CDDVDCONFIG; /* supported by 2008 Model */
+ }
+ break;
+ case 0x2C: pstInfo->nError = EPS_PRNERR_CARTRIDGEOVERFLOW; break;
+ /* case 0x2D: pstInfo->nError = EPS_PRNERR_LFP_NOMAINTENANCETANK2; break;*/ /* Not supported by 2006 Model */
+ /* case 0x2E: pstInfo->nError = EPS_PRNERR_INKOVERFLOW2; break;*/ /* Not supported by 2006 Model */
+ case 0x2F: pstInfo->nError = EPS_PRNERR_BATTERYVOLTAGE; break;
+ case 0x30: pstInfo->nError = EPS_PRNERR_BATTERYTEMPERATURE; break;
+ case 0x31: pstInfo->nError = EPS_PRNERR_BATTERYEMPTY; break;
+ case 0x32: pstInfo->nError = EPS_PRNERR_SHUTOFF; break; /* Not supported by 2006 Model */
+ case 0x33: pstInfo->nError = EPS_PRNERR_NOT_INITIALFILL; break; /* Not supported by 2006 Model */
+ case 0x34: pstInfo->nError = EPS_PRNERR_PRINTPACKEND; break; /* Not supported by 2006 Model */
+ /* case 0x35: pstInfo->nError = EPS_PRNERR_ABNORMALHEAT; break;*/ /* Not supported by 2006 Model */
+ case 0x37:
+ if ( obsIsA3Model(EPS_MDC_STATUS) == TRUE ) {
+ pstInfo->nError = EPS_PRNERR_COVEROPEN;
+ } else {
+ pstInfo->nError = EPS_PRNERR_SCANNEROPEN;
+ }
+ break;
+ case 0x38:
+ if ( obsIsA3Model(EPS_MDC_STATUS) == TRUE ) {
+ pstInfo->nError = EPS_PRNERR_CDDVDCONFIG;
+ } else {
+ pstInfo->nError = EPS_PRNERR_CDRGUIDEOPEN;
+ }
+ break;
+ case 0x44: pstInfo->nError = EPS_PRNERR_CDRGUIDEOPEN; break;
+ case 0x45: pstInfo->nError = EPS_PRNERR_CDREXIST_MAINTE; break;
+ case 0x46: pstInfo->nError = EPS_PRNERR_TRAYCLOSE; break;
+ case 0x47: pstInfo->nError = EPS_PRNERR_INKOUT; break; /* BlackPrint Error */
+
+ default:
+ pstInfo->nError = EPS_PRNERR_GENERAL;
+ break;
+ }
+ break;
+ case 0x04: /* WR */
+ /* ESC/P-R Lib does not notified the warning to application, */
+ /* so warning analysis dose not need to be done completely. */
+ pstInfo->nWarn = EPS_PRNWARN_NONE;
+ for(i = 0; i < ParameterByte; i++){
+ if( Parameter[i] >= 0x10 && Parameter[i] <= 0x1A ){
+ /* Ink Low Warning */
+ pstInfo->nWarn |= EPS_PRNWARN_INKLOW;
+ } else if( Parameter[i] >= 0x51 && Parameter[i] <= 0x5A ){
+ pstInfo->nWarn |= EPS_PRNWARN_DISABLE_CLEAN;
+ /*} else if( Parameter[i] == 0x44 ){ not use
+ pstInfo->nWarn |= EPS_PRNWARN_COLOR_INKOUT;*/
+ }
+ }
+ break;
+
+ case 0x0F: /* INK */
+ Ink = Parameter;
+
+ pstInfo->nInkError = EPS_INKERR_NONE;
+
+ if (Ink[1] >= 0x40) {
+ InkCartridgeType = MI_CARTRIDGE_ONE;
+ } else {
+ InkCartridgeType = MI_CARTRIDGE_INDEP;
+ }
+
+ for( pstInfo->nInkNo=0, i=0; i<EPS_INK_NUM; i++ ) {
+ pstInfo->nColorType[i] = EPS_COLOR_UNKNOWN;
+ pstInfo->nColor[i] = EPS_INK_NOTAVAIL;
+
+ if( Ink > Parameter+ParameterByte-Parameter[0] )
+ continue;
+
+ pstInfo->nInkNo++;
+
+ switch( Ink[2] ) {
+
+ case 0x00: pstInfo->nColorType[i] = EPS_COLOR_BLACK; break;
+ case 0x01: pstInfo->nColorType[i] = EPS_COLOR_CYAN; break;
+ case 0x02: pstInfo->nColorType[i] = EPS_COLOR_MAGENTA; break;
+ case 0x03: pstInfo->nColorType[i] = EPS_COLOR_YELLOW; break;
+ case 0x04: pstInfo->nColorType[i] = EPS_COLOR_LIGHTCYAN; break;
+ case 0x05: pstInfo->nColorType[i] = EPS_COLOR_LIGHTMAGENTA; break;
+ case 0x06: pstInfo->nColorType[i] = EPS_COLOR_LIGHTYELLOW; break;
+ case 0x07: pstInfo->nColorType[i] = EPS_COLOR_DARKYELLOW; break;
+ case 0x08: pstInfo->nColorType[i] = EPS_COLOR_LIGHTBLACK; break;
+ case 0x09: pstInfo->nColorType[i] = EPS_COLOR_RED; break;
+ case 0x0A: pstInfo->nColorType[i] = EPS_COLOR_VIOLET; break;
+ case 0x0B: pstInfo->nColorType[i] = EPS_COLOR_CLEAR; break;
+ case 0x0C: pstInfo->nColorType[i] = EPS_COLOR_LIGHTLIGHTBLACK; break;
+ case 0x0D: pstInfo->nColorType[i] = EPS_COLOR_ORANGE; break;
+ case 0x0E: pstInfo->nColorType[i] = EPS_COLOR_GREEN; break;
+ default:
+ pstInfo->nColorType[i] = EPS_COLOR_UNKNOWN;
+ break;
+ }
+
+ switch( Ink[3] ) {
+ case 'w' :
+ case 'r' :
+ pstInfo->nColor[i] = EPS_INK_FAIL;
+ ( pstInfo->nColorType[i]==EPS_COLOR_BLACK ) ?
+ (pstInfo->nInkError=EPS_INKERR_CFAILB) : (pstInfo->nInkError=EPS_INKERR_CFAILC);
+ break;
+ case 'n' :
+ pstInfo->nColor[i] = EPS_INK_NOTPRESENT;
+ ( pstInfo->nColorType[i]==EPS_COLOR_BLACK ) ?
+ (pstInfo->nInkError = EPS_INKERR_CEMPTYB) : (pstInfo->nInkError = EPS_INKERR_CEMPTYC);
+ break;
+ case 'i' :
+ pstInfo->nColor[i] = EPS_INK_NOREAD;
+ break;
+ default:
+ if((Ink[3] >= 0) && (Ink[3] <= 100)) {
+
+ pstInfo->nColor[i] = serInkLevelNromalize( Ink[3] );
+
+ if( pstInfo->nColor[i] == 0) {
+ if( pstInfo->nColorType[i]==EPS_COLOR_BLACK )
+ (pstInfo->nInkError = EPS_INKERR_INKENDB);
+ else
+ (pstInfo->nInkError = EPS_INKERR_INKENDC);
+ }
+ } else {
+ pstInfo->nColor[i] = EPS_INK_FAIL;
+ if( pstInfo->nColorType[i]==EPS_COLOR_BLACK )
+ (pstInfo->nInkError=EPS_INKERR_CFAILB);
+ else
+ (pstInfo->nInkError=EPS_INKERR_CFAILC);
+ }
+ break;
+ }
+
+ Ink = Ink + Parameter[0];
+ }
+
+ if((InkCartridgeType == MI_CARTRIDGE_ONE)){
+ switch(pstInfo->nInkError) {
+ case EPS_INKERR_INKENDB:
+ case EPS_INKERR_INKENDC:
+ pstInfo->nInkError = EPS_INKERR_INKENDALL;
+ break;
+ case EPS_INKERR_CFAILB:
+ case EPS_INKERR_CFAILC:
+ pstInfo->nInkError = EPS_INKERR_CFAILALL;
+ break;
+ case EPS_INKERR_CEMPTYB:
+ case EPS_INKERR_CEMPTYC:
+ pstInfo->nInkError = EPS_INKERR_CEMPTYALL;
+ break;
+ }
+ }
+ break;
+ case 0x13: /* CANCEL REQUEST by Printer cancel botton */
+ switch((EPS_UINT8)Parameter[0]) {
+ case 0x81:
+ pstInfo->nCancel = EPS_CAREQ_CANCEL;
+ break;
+ default:
+ pstInfo->nCancel = EPS_CAREQ_NOCANCEL;
+ break;
+ }
+ break;
+ case 0x18: /* Stacker(tray) open status */
+ switch((EPS_UINT8)Parameter[0]) {
+ case 0x02: /* Closed*/
+ pstInfo->nPrepare = EPS_PREPARE_TRAYCLOSED;
+ break;
+ case 0x03: /* Open*/
+ pstInfo->nPrepare = EPS_PREPARE_TRAYOPENED;
+ break;
+ }
+ break;
+ case 0x1C: /* Temperature information */
+ switch((EPS_UINT8)Parameter[0]) {
+ case 0x01: /* The printer temperature is higher than 40C*/
+ pstInfo->nPrepare = EPS_PREPARE_OVERHEAT;
+ break;
+ case 0x00: /* The printer temperature is lower than 40C*/
+ pstInfo->nPrepare = EPS_PREPARE_NORMALHEAT;
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if( EPS_CAREQ_CANCEL == pstInfo->nCancel ){
+ EPS_DBGPRINT(("*** Cancel Request (ignore error) ***\n"))
+ pstInfo->nState = EPS_ST_WAITING;
+ pstInfo->nError = EPS_PRNERR_NOERROR;
+ }
+
+#if _DEBUG_BIN_STATUS_
+ SerDebugPrintf(("***** ST = %d\r\n", pstInfo->nState));
+ SerDebugPrintf(("***** ER = %d\r\n", pstInfo->nError));
+ SerDebugPrintf(("***** WR = %d\r\n", pstInfo->nWarn));
+ SerDebugPrintf(("***** CA = %d\r\n", pstInfo->nCancel));
+ SerDebugPrintf(("***** INK NUM = %d\r\n", pstInfo->nInkNo));
+ for(i = 0; i < pstInfo->nInkNo; i++){
+ SerDebugPrintf(("***** INK = %d\t%d\r\n", pstInfo->nColorType[i], pstInfo->nColor[i]));
+ }
+#endif
+
+ if(InkCartridgeType == MI_CARTRIDGE_ONE) {
+ Min = pstInfo->nColor[0];
+ for(i = 1; i < pstInfo->nInkNo; i++){
+ Min = ( (Min <= pstInfo->nColor[i]) ? Min : pstInfo->nColor[i] );
+ }
+ for(i = 0; i < pstInfo->nInkNo; i++){
+ pstInfo->nColor[i] = Min;
+ }
+ }
+
+ EPS_RETURN( EPS_ERR_NONE );
+
+}
+
+EPS_INT32 serInkLevelNromalize (
+
+ EPS_INT32 level
+
+){
+ if ( (level >= 75) && (level <= 100)) {
+ return 100;
+ } else if ((level >= 50) && (level <= 74)) {
+ return 75;
+ } else if ((level >= 25) && (level <= 49)) {
+ return 50;
+ } else if ((level >= 4) && (level <= 24)) {
+ return 25;
+ } else if ((level >= 1) && (level <= 3)) {
+ return 1;
+ } else if ( level == 0) {
+ return 0;
+ }
+
+ return level;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: serDelayThread() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* milliseconds EPS_UINT32 I: Sleep Period in microseconds */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Wait <milliseconds>. */
+/* If OS sleep function is used, change the unit of sleep time from milliseconds */
+/* to microseconds. */
+/* */
+/*******************************************|********************************************/
+void serDelayThread (
+
+ EPS_UINT32 milliseconds,
+ EPS_CMN_FUNC* epsCmnFnc
+
+){
+
+#ifdef GCOMSW_EPSON_SLEEP
+ if (epsCmnFnc->sleep == serSleep) {
+ epsCmnFnc->sleep((EPS_UINT32)milliseconds); /* Ignore return value of sleep func */
+ } else{
+ epsCmnFnc->sleep(milliseconds * 1000); /* Ignore return value of sleep func */
+ }
+#else
+ epsCmnFnc->sleep(milliseconds * 1000); /* Ignore return value of sleep func */
+#endif /* GCOMSW_EPSON_SLEEP */
+
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: serSleep() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sleepPeriod EPS_UINT32 I: Sleep Period in milliseconds */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* */
+/* Description: */
+/* ESC/P-R Lib original sleep function. */
+/* This function is used when "epsCmnFnc.sleep = NULL". */
+/* */
+/*******************************************|********************************************/
+#ifdef GCOMSW_EPSON_SLEEP
+EPS_ERR_CODE serSleep (
+
+ EPS_UINT32 sleepPeriod /* Sleep Period in milliseconds */
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_INT32 idx; /* General loop/index varaible */
+ EPS_INT32 endx;
+ struct timeb sleepM;
+
+/*** Initialize Local Variables */
+ endx = sleepPeriod*printJob.sleepSteps;
+ if (printJob.sleepSteps <= 0) endx = sleepPeriod/(-printJob.sleepSteps);
+
+/*** Sleep for about the requested sleepPeriod */
+ for (idx = 1; idx < endx; idx++) {ftime(&sleepM); }
+
+/*** Return to Caller */
+ return((EPS_ERR_CODE)EPS_ERR_NONE);
+
+}
+#endif /* GCOMSW_EPSON_SLEEP */
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: serGetInkError() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pStatInfo EPS_STATUS_INFO* I: Printer Status Information */
+/* pNotify EPS_INT32* O: Notification Code */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Failed to operate */
+/* */
+/* Description: */
+/* Set notification code about ink error */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 serGetInkError (
+
+ EPS_STATUS_INFO* pStatInfo,
+ EPS_INT32* pNotify
+
+){
+ SerDebugPrintf(("EPS SER : In Get Ink Error\r\n"));
+
+ SerDebugPrintf(("EPS SER : In SP CTG %d,%d,%d,%d,%d,%d,%d,%d\r\n",
+ pStatInfo->nColor[0],
+ pStatInfo->nColor[1],
+ pStatInfo->nColor[2],
+ pStatInfo->nColor[3],
+ pStatInfo->nColor[4],
+ pStatInfo->nColor[5],
+ pStatInfo->nColor[6],
+ pStatInfo->nColor[7]));
+
+ switch(pStatInfo->nInkError){
+/*** Ink End */
+ case EPS_INKERR_INKENDALL:
+ case EPS_INKERR_INKENDB:
+ case EPS_INKERR_INKENDC:
+ *pNotify = EPS_PRNERR_INKOUT;
+ break;
+
+/*** Ink Fail */
+ case EPS_INKERR_CFAILALL:
+ case EPS_INKERR_CFAILB:
+ case EPS_INKERR_CFAILC:
+ *pNotify = EPS_PRNERR_CFAIL;
+ break;
+
+/*** Ink Empty */
+ case EPS_INKERR_CEMPTYALL:
+ case EPS_INKERR_CEMPTYB:
+ case EPS_INKERR_CEMPTYC:
+ *pNotify = EPS_PRNERR_CEMPTY;
+ break;
+
+ case EPS_INKERR_NONE:
+ break;
+
+ default:
+ return EPS_ERR_OPR_FAIL;
+ }
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _SP_ChangeSpec_UpdatePMReply() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I/O: Pointer to a printer infomation */
+/* orgPmString EPS_UINT8* I: String of the pm command reply */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_SP_INVALID_POINTER - Input pointer error */
+/* EPS_ERR_SP_INVALID_HEADER - pm string header error */
+/* EPS_ERR_SP_INVALID_TERMINATOR - pm string terminator error */
+/* EPS_ERR_SP_NO_VALID_FIELD - pm string field error */
+/* */
+/* Description: */
+/* - Invalid formats : Delete */
+/* - Unknown 'S' field : Delete */
+/* - Unknown 'T' field : Replace to PGPP-Premium Glossy Photo Paper(id:0x0b) */
+/* field If PGPP aleady exist its 'S' field then just */
+/* combine the mode property */
+/* - Duplicated 'S' fields : Merge together */
+/* - Duplicated 'T' fields : Merge together and combine each mode properties */
+/* - Only DRAFT mode exist : Add NORMAL mode to its print quality property */
+/* */
+/* NOTE: */
+/* Be sure that the pData is a pointers that a starting address of 512 bytes */
+/* buffer should be assigned or memory acces violation should be occured. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE _SP_ChangeSpec_UpdatePMReply (
+
+ EPS_PRINTER_INN* printer,
+ EPS_UINT8* orgPmString,
+ EPS_INT32 bufSize
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_UINT8* pBefore = NULL;
+ EPS_UINT8* pAfter = NULL;
+ EPS_UINT8* pSrc = NULL;
+ EPS_UINT8* pDes = NULL;
+ EPS_UINT8 tempPmString[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
+ EPS_UINT8 paperSize;
+ EPS_UINT8 paperType;
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ EPS_UINT8 PmStringForCompare[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
+#endif
+ static const EPS_UINT8 PM_REPLY_HEADER[EPS_PM_HEADER_LEN] = {
+ /* @ B D C <SP> P M <CR> <LF> */
+ 0x40, 0x42, 0x44, 0x43, 0x20, 0x50, 0x4D, 0x0D, 0x0A
+ };
+
+ EPS_INT16 idx;
+
+ EPS_LOG_FUNCIN;
+
+/*** Validate input parameters */
+ if(orgPmString == NULL) {
+ SerDebugPrintf(("_SP_ChangeSpec_UpdatePMReply > EPS_ERR_SP_INVALID_POINTER\r\n"));
+ EPS_RETURN( EPS_ERR_SP_INVALID_POINTER );
+ }
+
+ if(memcmp(orgPmString, PM_REPLY_HEADER, EPS_PM_HEADER_LEN) != 0) {
+ SerDebugPrintf(("_SP_ChangeSpec_UpdatePMReply > EPS_ERR_SP_INVALID_HEADER\r\n"));
+ EPS_RETURN( EPS_ERR_SP_INVALID_HEADER );
+ }
+
+ for(idx = EPS_PM_HEADER_LEN; idx <= (EPS_PM_MAXSIZE-EPS_PM_TERMINATOR_LEN); idx++) {
+ if(orgPmString[idx]== 0x0D && orgPmString[idx+1] == 0x0A) {
+ break;
+ }
+ }
+
+ if(idx > (EPS_PM_MAXSIZE-EPS_PM_TERMINATOR_LEN)) {
+ SerDebugPrintf(("_SP_ChangeSpec_UpdatePMReply > EPS_ERR_SP_INVALID_TERMINATOR\r\n"));
+ EPS_RETURN( EPS_ERR_SP_INVALID_TERMINATOR );
+ }
+
+/*** Initialize Local Variables */
+ memset(tempPmString, 0x00, EPS_PM_MAXSIZE);
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ memset(PmStringForCompare, 0x00, EPS_PM_MAXSIZE);
+#endif
+
+ /* Initialize pm data state */
+ memset(printer->pmData.pmString, 0x00, EPS_PM_MAXSIZE);
+ printer->pmData.state = EPS_PM_STATE_NOT_FILTERED;
+
+/*** Correct PM REPLY following 7 steps */
+/*** ---------------------------------------------------------------------------------- */
+/*** STEP 1 : Replace Built-in resource. Because PM REPLY of the following printers */
+/*** is insufficient, */
+/*** ---------------------------------------------------------------------------------- */
+ if( (strcmp(printer->modelName, "E-300" ) == 0) ){
+ bufSize = _SP_LoadPMString(EPS_PMS_E300, orgPmString, EPS_PM_MAXSIZE);
+
+ } else if( (strcmp(printer->modelName, "E-500" ) == 0) ||
+ (strcmp(printer->modelName, "E-700" ) == 0) ) {
+ bufSize = _SP_LoadPMString(EPS_PMS_E500, orgPmString, EPS_PM_MAXSIZE);
+
+ } else if( (strcmp(printer->modelName, "PictureMate PM 200" ) == 0) ||
+ (strcmp(printer->modelName, "PictureMate PM 210" ) == 0) ){
+ bufSize = _SP_LoadPMString(EPS_PMS_PM200, orgPmString, EPS_PM_MAXSIZE);
+
+ } else if( (strcmp(printer->modelName, "PictureMate PM 240" ) == 0) ||
+ (strcmp(printer->modelName, "PictureMate PM 250" ) == 0) ||
+ (strcmp(printer->modelName, "PictureMate PM 280" ) == 0) ){
+ bufSize = _SP_LoadPMString(EPS_PMS_PM240, orgPmString, EPS_PM_MAXSIZE);
+ }
+ if(bufSize <= 0){
+ return bufSize;
+ }
+
+
+ /* Use work pointers to call each filter functions */
+ pBefore = orgPmString + EPS_PM_HEADER_LEN; /* position of first tab 'S' */
+ pAfter = tempPmString;
+ bufSize -= EPS_PM_HEADER_LEN;
+
+/*** ---------------------------------------------------------------------------------- */
+/*** STEP 2 : Remove <CR><LF> on the way */
+/*** ---------------------------------------------------------------------------------- */
+ pSrc = pBefore;
+ pDes = pAfter;
+
+ DUMP_PMREPLY((pSrc, DUMP_HEX, "< ORIGINAL >"));
+
+ _pmValidateRemoveDelimiter(pDes, pSrc, bufSize);
+
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ if(memcmp(pBefore, pAfter, EPS_PM_DATA_LEN) != 0){
+ printf("!!!!!!!!! PM reply data modified on STEP 2. !!!!!!!!!\nRemove <CR><LF> on the way\n\n");
+ }
+#endif
+ /* Update orgPmString */
+ memcpy(pBefore, pAfter, EPS_PM_DATA_LEN);
+
+ VERBOSE_DUMP_PMREPLY((pDes, DUMP_ASCII, "< STEP 1 PASSED >"));
+
+/*** ---------------------------------------------------------------------------------- */
+/*** STEP 3 : Copy only valid fields to reply buffer and remove unknown 'S' from reply */
+/*** ---------------------------------------------------------------------------------- */
+ pSrc = pBefore;
+ pDes = pAfter;
+
+ DUMP_PMREPLY((pSrc, DUMP_HEX, "< ORIGINAL >"));
+
+ if(_pmValidateRemoveUnknownSfield(pDes, pSrc) == 0) {
+ SerDebugPrintf(("_SP_ChangeSpec_UpdatePMReply > EPS_ERR_SP_NO_VALID_FIELD\r\n"));
+ EPS_RETURN( EPS_ERR_SP_NO_VALID_FIELD );
+ }
+
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ if(memcmp(pBefore, pAfter, EPS_PM_DATA_LEN) != 0){
+ printf("!!!!!!!!! PM reply data modified on STEP 3. !!!!!!!!!\n\n\n");
+ print_PMREPLY(pAfter, DUMP_HEX, "< Filterd >");
+ }
+#endif
+ /* Update orgPmString */
+ memcpy(pBefore, pAfter, EPS_PM_DATA_LEN);
+
+ VERBOSE_DUMP_PMREPLY((pDes, DUMP_ASCII, "< STEP 1 PASSED >"));
+
+/*** ---------------------------------------------------------------------------------- */
+/*** STEP 4 : Correct unknown 'T' fields */
+/*** ---------------------------------------------------------------------------------- */
+ pSrc = pBefore;
+ pDes = pAfter;
+
+ _pmCorrectUnknownTfield(pDes, pSrc);
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ if(memcmp(pBefore, pAfter, EPS_PM_DATA_LEN) != 0){
+ printf("!!!!!!!!! PM reply data modified on STEP 4. !!!!!!!!!\n\n\n");
+ print_PMREPLY(pAfter, DUMP_HEX, "< Filterd >");
+ }
+#endif
+
+ /* Update orgPmString */
+ memcpy(pBefore, pAfter, EPS_PM_DATA_LEN);
+
+ VERBOSE_DUMP_PMREPLY((pDes, DUMP_ASCII, "< STEP 2 PASSED >"));
+
+/*** ---------------------------------------------------------------------------------- */
+/*** STEP 5 : Merge duplicated fields */
+/*** ---------------------------------------------------------------------------------- */
+ pSrc = pBefore;
+ pDes = pAfter;
+
+ _pmCorrectDupulicatedFields(pDes, pSrc);
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ if(memcmp(pBefore, pAfter, EPS_PM_DATA_LEN) != 0){
+ printf("!!!!!!!!! PM reply data modified on STEP 5. !!!!!!!!!\n\n\n");
+ print_PMREPLY(pAfter, DUMP_HEX, "< Filterd >");
+ }
+#endif
+
+ /* Update orgPmString */
+ memcpy(pBefore, pAfter, EPS_PM_DATA_LEN);
+
+ VERBOSE_DUMP_PMREPLY((pDes, DUMP_ASCII, "< STEP 3 PASSED >"));
+
+ /* Now, Service Pack retains filtered data its original quality properties */
+ /* within the inner buffer g_PMinfo.data */
+ /* This data would be referenced whenever it is required to compare its originality */
+ DUMP_PMREPLY((orgPmString, DUMP_ASCII, \
+ "< FILTERED (Retained within SP-same printer's caps) >"));
+
+
+/*** ---------------------------------------------------------------------------------- */
+/*** STEP 6 : Delete the paper type "CD/DVD label" from the pm string when "Stylus */
+/*** Photo R380" or "Stylus Photo RX580" is used. */
+/*** ---------------------------------------------------------------------------------- */
+ if ((strcmp(printer->modelName, "Stylus Photo R380" ) == 0) ||
+ (strcmp(printer->modelName, "Stylus Photo RX580") == 0) ) {
+
+ pSrc = pBefore;
+ pDes = pAfter;
+ paperSize = 0xFF;
+ paperType = 0xFF;
+
+ while (*pSrc == 'S') {
+ paperSize = *(pSrc + 1); /* Save the media size */
+
+ *pDes++ = *pSrc++; /* set 'S' */
+ *pDes++ = *pSrc++; /* set the meida size */
+
+ while (*pSrc == 'T') {
+ paperType = *(pSrc + 1); /* Save the media type */
+
+ if ((paperSize == EPS_MSID_LETTER) && (paperType == EPS_MTID_CDDVD)) {
+ pSrc += 4; /* Move to next 'T' */
+ } else{
+ *pDes++ = *pSrc++; /* set 'T' */
+ *pDes++ = *pSrc++; /* set the media type */
+ *pDes++ = *pSrc++; /* set the printing mode info */
+ *pDes++ = *pSrc++; /* set '/' */
+ }
+ }
+ if (*pSrc == '/') {
+ *pDes++ = *pSrc++; /* set '/' */
+ }
+
+ /* check for string termination */
+ if ((*pSrc == 0xD) && (*(pSrc+1) == 0xA)) {
+ *pDes++ = *pSrc++;
+ *pDes++ = *pSrc++;
+ break;
+ }
+ }
+
+ /* Update orgPmString */
+ memcpy(pBefore, pAfter, EPS_PM_DATA_LEN);
+ }
+
+/*** ---------------------------------------------------------------------------------- */
+/*** STEP 7 : Adjust quality properties to the formal in order to return to the driver. */
+/*** it dose not change the filtered data through previous steps retained */
+/*** within Service Pack. but just change the buffer asigned as parameter. */
+/*** (in this case orgPmString) */
+/*** after duplicating the filtered data to it. */
+/*** ---------------------------------------------------------------------------------- */
+ /* set filterd value "printer->pmData.pmString" */
+ memset(printer->pmData.pmString, 0x00, EPS_PM_MAXSIZE);
+ memcpy(printer->pmData.pmString, orgPmString, EPS_PM_MAXSIZE);
+
+ printer->pmData.state = EPS_PM_STATE_FILTERED;
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ memcpy(PmStringForCompare, orgPmString, EPS_PM_DATA_LEN);
+#endif
+
+ /* If Draft Quality is only supported, add Normal Quality */
+ _pmAdjustQuality(orgPmString);
+#if _VALIDATE_SUPPORTED_MEDIA_DATA_
+ if(memcmp(PmStringForCompare, orgPmString, EPS_PM_DATA_LEN) != 0){
+ printf("!!!!!!!!! PM reply data modified on STEP 7. !!!!!!!!!\n\n\n");
+ print_PMREPLY(PmStringForCompare + EPS_PM_HEADER_LEN, DUMP_HEX, "< Origin >");
+ print_PMREPLY(orgPmString + EPS_PM_HEADER_LEN, DUMP_HEX, "< Filterd >");
+ }
+#endif
+
+ DUMP_PMREPLY((orgPmString+EPS_PM_HEADER_LEN, DUMP_ASCII, \
+ "< FILTERED (Returned data to the driver-adjusted quality properties) >"));
+
+/*** Return to caller */
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _SP_ChangeSpec_DraftOnly() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I/O: Pointer to a printer infomation */
+/* jobAtter EPS_JOB_ATTRIB* I: Data structure containing page attribut settings */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* */
+/* Description: */
+/* If the quality mode which is not supported by printer is assigned, replace it */
+/* to printer's support mode. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE _SP_ChangeSpec_DraftOnly (
+
+ EPS_PRINTER_INN* printer,
+ EPS_JOB_ATTRIB* jobAtter /* Print Attributes for this Job */
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_UINT8 mediaSizeID;
+ EPS_UINT8 mediaTypeID;
+ EPS_UINT8* pPMinfo;
+ EPS_UINT8* pS_begin;
+ EPS_UINT8* pS_end;
+ EPS_UINT8* pTfield;
+ EPS_UINT8 quality[3]; /* Q_DRAFT / Q_NORMAL / Q_HIGH */
+
+ EPS_LOG_FUNCIN;
+
+/*** Validate input parameters */
+ if(printer->pmData.state != EPS_PM_STATE_FILTERED) {
+ SerDebugPrintf(("ChangeSpec_DraftOnly : PM info not initialized\r\n"));
+ /* it is not able to hadle this situation so do nothing */
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+/*** Initialize Global/Local Variables */
+ mediaSizeID = (EPS_UINT8)jobAtter->mediaSizeIdx;
+ mediaTypeID = (EPS_UINT8)jobAtter->mediaTypeIdx;
+ pPMinfo = NULL;
+ pS_begin = NULL;
+ pS_end = NULL;
+ pTfield = NULL;
+ memset(quality, 0, sizeof(quality));
+
+/*** Change quality */
+ /* Refer the data retained within Service Pack. */
+ /* "printer->pmData.pmString" has the header. */
+ pPMinfo = (EPS_UINT8*)(printer->pmData.pmString + EPS_PM_HEADER_LEN);
+
+ /* S field start postion */
+ if(_pmFindSfield(mediaSizeID, pPMinfo, &pS_begin, &pS_end) < 0) {
+ SerDebugPrintf(("ChangeSpec_DraftOnly : cannot find mediaSizeID(%d)\r\n", mediaSizeID));
+ /* it is not able to hadle this situation so do nothing */
+ EPS_RETURN( EPS_ERR_NONE );
+ };
+
+ VERBOSE_DUMP_PMREPLY((pS_begin, DUMP_S_TAG_ONLY,
+ "< ChangeSpec_DraftOnly : retained S field info >"));
+
+ /* Fetch the T field */
+ if((pTfield = _pmScanTfield(mediaTypeID, pS_begin)) == NULL) {
+ SerDebugPrintf(("ChangeSpec_DraftOnly : cannot find mediaTypeID(%d)\r\n", mediaTypeID));
+ /* it is not able to hadle this situation so do nothing */
+ EPS_RETURN( EPS_ERR_NONE );
+ }
+
+ /* Quality should be assigned to the only supported mode */
+ verbose_dbprint((" >> adjusted PrintQuality : %d -> ", jobAtter->printQuality));
+
+ if(!((*(pTfield+2) & 0x07) & /* Printer's support mode actually */
+ (jobAtter->printQuality))) { /* Upper layer(driver) assigned mode */
+
+ /* The quality mode which is not supported by printer is assigned */
+ /* Replace it to printer's support mode */
+ switch(*(pTfield+2) & 0x07) {
+ case 0x01: /* 0 0 1 : Draft only */
+ quality[Q_DRAFT] = EPS_MQID_DRAFT;
+ quality[Q_NORMAL] = EPS_MQID_DRAFT;
+ quality[Q_HIGH] = EPS_MQID_DRAFT;
+ break;
+ case 0x02: /* 0 1 0 : Normal only */
+ quality[Q_DRAFT] = EPS_MQID_NORMAL;
+ quality[Q_NORMAL] = EPS_MQID_NORMAL;
+ quality[Q_HIGH] = EPS_MQID_NORMAL;
+ break;
+ case 0x04: /* 1 0 0 : High only */
+ quality[Q_DRAFT] = EPS_MQID_HIGH;
+ quality[Q_NORMAL] = EPS_MQID_HIGH;
+ quality[Q_HIGH] = EPS_MQID_HIGH;
+ break;
+ case 0x03: /* 0 1 1 : Normal and Draft */
+ quality[Q_DRAFT] = EPS_MQID_DRAFT;
+ quality[Q_NORMAL] = EPS_MQID_NORMAL;
+ quality[Q_HIGH] = EPS_MQID_NORMAL;
+ break;
+ case 0x05: /* 1 0 1 : High and Draft */
+ quality[Q_DRAFT] = EPS_MQID_DRAFT;
+ quality[Q_NORMAL] = EPS_MQID_HIGH;
+ quality[Q_HIGH] = EPS_MQID_HIGH;
+ break;
+ case 0x06: /* 1 1 0 : High and Normal */
+ quality[Q_DRAFT] = EPS_MQID_NORMAL;
+ quality[Q_NORMAL] = EPS_MQID_NORMAL;
+ quality[Q_HIGH] = EPS_MQID_HIGH;
+ break;
+ case 0x07: /* 1 1 1 : Anything possible */
+ break;
+ default:
+ break;
+ }
+
+ /* Now, the value of quality array of index which is same as PrintQuality is valid */
+ switch(jobAtter->printQuality) {
+ case EPS_MQID_DRAFT:
+ jobAtter->printQuality= quality[Q_DRAFT];
+ break;
+ case EPS_MQID_NORMAL:
+ jobAtter->printQuality= quality[Q_NORMAL];
+ break;
+ case EPS_MQID_HIGH:
+ jobAtter->printQuality= quality[Q_HIGH];
+ break;
+ }
+ }
+
+ verbose_dbprint(("%d\r\n", jobAtter->printQuality));
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: serAppendMedia() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pMedia EPS_SUPPORTED_MEDIA* I/O: supported media structuer */
+/* */
+/* Return value: */
+/* none */
+/* */
+/* Description: */
+/* Append Media attribute from PM reply info. */
+/* */
+/*******************************************|********************************************/
+void serAppendMedia (
+
+ EPS_SUPPORTED_MEDIA* pMedia
+
+){
+ EPS_INT32 idxSize, idxType;
+ EPS_BOOL foundCD = FALSE;
+
+ EPS_LOG_FUNCIN;
+
+ for(idxSize = 0; idxSize < pMedia->numSizes; idxSize++){
+ /*** Append "CD/DVD Label" rayout to plain, CDDVD ***/
+ for(idxType = 0; idxType < pMedia->sizeList[idxSize].numTypes; idxType++){
+
+ if( EPS_IS_CDDVD( pMedia->sizeList[idxSize].typeList[idxType].mediaTypeID ) ){
+ /* Set "CD/DVD Label" rayout to CDDVD */
+ pMedia->sizeList[idxSize].typeList[idxType].layout = EPS_MLID_CDLABEL;
+
+ /* paperSource is only CD tray */
+ pMedia->sizeList[idxSize].typeList[idxType].paperSource = EPS_MPID_CDTRAY;
+
+ foundCD = TRUE;
+ } else if(EPS_MTID_MINIPHOTO == pMedia->sizeList[idxSize].typeList[idxType].mediaTypeID){
+ /* Append "16 Division" rayout to Photo Stickers */
+ pMedia->sizeList[idxSize].typeList[idxType].layout |= EPS_MLID_DIVIDE16;
+ }
+ }
+
+ if(foundCD){
+ for(idxType = 0; idxType < pMedia->sizeList[idxSize].numTypes; idxType++){
+ if(EPS_MTID_PLAIN == pMedia->sizeList[idxSize].typeList[idxType].mediaTypeID ){
+ /* Append "CD/DVD Label" rayout to plain */
+ pMedia->sizeList[idxSize].typeList[idxType].layout |= EPS_MLID_CDLABEL;
+ break;
+ }
+ }
+ foundCD = FALSE;
+ }
+ }
+
+ EPS_RETURN_VOID
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _SP_LoadPMString() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* resouceID EPS_UINT32 I: PM resouce ID */
+/* pString EPS_INT8* O: PM string */
+/* bufSize EPS_INT32 I: pString size */
+/* */
+/* Return value: */
+/* EPS_INT32 buffer size or error */
+/* */
+/* Description: */
+/* Load special PM string. Because a part of model is insufficient PM reply info. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 _SP_LoadPMString (
+
+ EPS_UINT32 resouceID,
+ EPS_UINT8* pString,
+ EPS_UINT32 bufSize
+
+){
+ EPS_UINT32 i = 0;
+
+ for (i = 0; i < EPS_SPM_STRINGS; i++){
+ if (spPMStrTbl[i].id == resouceID){
+ if(bufSize < spPMStrTbl[i].len){
+ return EPS_ERR_OPR_FAIL;
+ }
+ memcpy(pString, spPMStrTbl[i].res, spPMStrTbl[i].len);
+ return spPMStrTbl[i].len;
+ }
+ }
+
+ return EPS_ERR_OPR_FAIL;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmFindSfield() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* id EPS_UINT8 I: Media Size ID */
+/* pSrc EPS_UINT8* I: pm String */
+/* pStart EPS_UINT8** O: Start Pointer of 'S' fields */
+/* pEnd EPS_UINT8** O: End Pointer of 'S' fields */
+/* */
+/* Return value: */
+/* Length of founded 'S' fields - Success */
+/* -1 - There is NOT the Media Size ID in pm string */
+/* */
+/* Description: */
+/* Find a 'S' field that includes the <id> in <pSrc> and save its starting('S') */
+/* and ending pointer('/') to <pStart> and <pEnd>. */
+/* <pSrc> should be a complete PM REPLY format that start with 'S' and terminate */
+/* at "0x0D 0x0A". */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 _pmFindSfield (
+
+ EPS_UINT8 id,
+ EPS_UINT8* pSrc,
+ EPS_UINT8** pStart,
+ EPS_UINT8** pEnd
+
+){
+ EPS_LOG_FUNCIN;
+
+ while (*pSrc != 0xD || *(pSrc+1) != 0xA) {
+
+ *pStart = NULL;
+ *pEnd = NULL;
+
+ /* find 'S' */
+ while(*pSrc == 'S') {
+ if(id == *(pSrc+1)) {
+ *pStart = pSrc;
+ }
+
+ pSrc += 2;
+
+ while(*pSrc == 'T') {
+ pSrc += 4;
+ }
+
+ /* Found id */
+ if(*pStart != NULL) {
+ *pEnd = pSrc;
+ EPS_RETURN( (EPS_INT32)(*pEnd - *pStart)+1 );
+ }
+
+ /* next 'S' */
+ pSrc++;
+ }
+
+ if(*pSrc == 'M' || *pSrc == 'R'){
+ pSrc += 6;
+ }
+ }
+
+ EPS_RETURN( (-1) );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmScanTfield() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* id EPS_UINT8 Media Type ID */
+/* pSfield EPS_UINT8* Pointer to 'S' field */
+/* */
+/* Return value: */
+/* Pointer to 'T' on the pSfield - Success */
+/* NULL - There is NOT 'T' in the pSfield */
+/* */
+/* Description: */
+/* Find 'T' field that includs the <id>. */
+/* */
+/*******************************************|********************************************/
+static EPS_UINT8* _pmScanTfield (
+
+ EPS_UINT8 id,
+ EPS_UINT8* pSfield
+
+){
+ EPS_UINT8* pScan = pSfield;
+ EPS_UINT8* pT = NULL;
+
+ if(*pScan == 'S') {
+ pScan += 2;
+
+ while(*pScan == 'T') {
+ if(id == *(pScan+1)) {
+ pT = pScan;
+ break;
+ }
+
+ pScan += 4;
+ }
+ }
+
+ return pT;
+
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmAppendTfield() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pT EPS_UINT8* I: Pointer to 'T' field */
+/* pDes EPS_UINT8* O: Pointer to 'S' field */
+/* */
+/* Return value: */
+/* 4 - Success (Return increased bytes) */
+/* -1 - Failure */
+/* */
+/* Description: */
+/* Append 'T' field to <pDes> if same field dose not exsit, but same one aleady */
+/* exsits just combine mode properdy. */
+/* <pDes> should have a complete 'S' field consist of 'S' and '/' and pT should */
+/* have a 'T' field of 4 bytes starts with 'T'. */
+/* This function returns the increased bytes so that caller change the last */
+/* position or (-1) to indicate nothing changed. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 _pmAppendTfield (
+
+ EPS_UINT8* pT,
+ EPS_UINT8* pDes
+
+){
+ EPS_UINT8 t_id = *(pT+1);
+ EPS_INT16 t_exist = 0;
+
+ if(*pDes == 'S') {
+
+ pDes += 2; /* move to first 'T' */
+
+ while(*pDes == 'T') {
+
+ /* same id exist */
+ if(t_id == *(pDes+1)) {
+ /* Just combine mode property */
+ *(pDes+2) |= *(pT+2);
+
+ t_exist = 1;
+ break;
+ }
+
+ /* next 'T' */
+ pDes += 4;
+ }
+
+ /* samd id field dose not exist */
+ /* Append new 'T' fields */
+ if(t_exist == 0) {
+ memcpy(pDes, pT, 4);
+ pDes += 4;
+ *pDes = '/';
+
+ return 4; /* size of 'T' field */
+ }
+
+ /* type id aleady exist then do not anything */
+ }
+
+ return (-1);
+
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmValidateRemoveDelimiter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pDes EPS_UINT8* O: Pointer to validated pm string */
+/* pSrc EPS_UINT8* I: Pointer to original pm string */
+/* */
+/* Return value: */
+/* The number of valid fields */
+/* */
+/* Description: */
+/* Copy valid fields to reply buffer only. */
+/* Remove <CR><LF> on the way. */
+/* */
+/*******************************************|********************************************/
+static void _pmValidateRemoveDelimiter (
+
+ EPS_UINT8* pDes,
+ EPS_UINT8* pSrc,
+ EPS_INT32 bufSize
+
+){
+
+ EPS_UINT8* pEOF = pSrc + bufSize;
+
+ EPS_LOG_FUNCIN;
+
+ while (pSrc < pEOF) {
+
+ if(*pSrc == 'S') {
+ memcpy(pDes, pSrc, 2);
+ pSrc += 2;
+ pDes += 2;
+
+ while(*pSrc == 'T') {
+ memcpy(pDes, pSrc, 3);
+ pSrc += 3;
+ pDes += 3;
+
+ if(*pSrc == '/') {
+ *pDes++ = *pSrc++;
+ }
+ }
+
+ if(*pSrc == '/') {
+ *pDes++ = *pSrc++;
+ }
+
+ } else if(*pSrc == 'M' || *pSrc == 'R'){
+ /* Jpeg size limit */
+ if( *(pSrc + 5) == '/' ){
+ memcpy(pDes, pSrc, 6 );
+ pSrc += 6;
+ pDes += 6;
+ }
+ } else if(*pSrc == 0xD || *(pSrc+1) == 0xA){
+ /* Terminater skip */
+ pSrc += 2;
+ } else{
+ /* unknown field */
+ pSrc++;
+ }
+ }
+
+ /* set truth terminater */
+ *pDes++ = 0x0d; /* 0xD */
+ *pDes = 0x0a; /* 0xA */
+
+ EPS_RETURN_VOID;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmValidateRemoveUnknownSfield() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pDes EPS_UINT8* O: Pointer to validated pm string */
+/* pSrc EPS_UINT8* I: Pointer to original pm string */
+/* */
+/* Return value: */
+/* The number of valid fields */
+/* */
+/* Description: */
+/* Copy valid fields to reply buffer only. */
+/* Remove unknown 'S' field. */
+/* Minimum conditons for valid PM REPLY are */
+/* - it must have a complete 'S' field more than one ( 'S' ~ '/'). */
+/* - it must end with 0xD and 0xA. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 _pmValidateRemoveUnknownSfield (
+
+ EPS_UINT8* pDes,
+ EPS_UINT8* pSrc
+
+){
+
+ EPS_UINT8* pPrev = NULL; /* save previous pointer */
+ EPS_UINT8* pS = NULL; /* valid field's starting position */
+ EPS_UINT8* pE = NULL; /* valid field's ending postion */
+
+ EPS_INT16 valid = 0; /* flag for indicating 'S' field's validation */
+ EPS_INT16 t_cnt = 0; /* count valid 'T' fields */
+ EPS_UINT16 s_idx = 0; /* index of epsMediaSize */
+
+ EPS_INT16 num_valid_fields = 0; /* value for returning */
+
+ EPS_LOG_FUNCIN;
+
+#ifdef _TEST_PM_STEP_1 /* Change first 'S' field's id to unknown id such as 0xFF */
+ *(pSrc+1) = 0xFF;
+#endif
+
+ while (*pSrc != 0xD || *(pSrc+1) != 0xA) {
+ pPrev = pSrc;
+
+ pS = NULL;
+ pE = NULL;
+ valid = 0;
+ t_cnt = 0;
+ s_idx = 0;
+
+ if(*pSrc == 'S') {
+ pS = pSrc;
+ pSrc += 2;
+
+ while(*pSrc == 'T') {
+ pSrc += 3;
+
+ if(*pSrc == '/') {
+ pSrc++;
+ t_cnt++;
+ }
+ }
+
+ if(t_cnt && *pSrc == '/') {
+ pE = pSrc;
+ }
+
+ } else if(*pSrc == 'M' || *pSrc == 'R'){
+ /* Jpeg size limit */
+ if( *(pSrc + 5) == '/' ){
+ memcpy(pDes, pSrc, 6 );
+ pDes += 6;
+ pSrc += 6;
+ continue;
+ }
+ }
+
+ /* Copy valid and support 'S' fields only */
+ /* Valid means size id should be find in its table */
+ /* and 'T' field exist at least more than one */
+ /* Unknown 'S' field should be removed */
+ if(pS && pE) {
+ for(s_idx = 0; s_idx < EPS_NUM_MEDIA_SIZES; s_idx++) {
+ if(epsMediaSize[s_idx].id == *(pS+1)) {
+ memcpy(pDes, pS, (EPS_UINT32)((pE-pS)+1) );
+ pDes += (pE-pS)+1;
+ valid = 1;
+
+ /* now increase num of valid fields */
+ num_valid_fields++;
+
+ break;
+ }
+ }
+ }
+
+ /* Restore work buffer pos to the previous */
+ /* cause fail to get a valid fields */
+ if(valid == 0) {
+ pSrc = pPrev;
+ }
+
+ pSrc++;
+ }
+
+ *pDes++ = *pSrc++; /* 0xD */
+ *pDes++ = *pSrc; /* 0xA */
+
+ EPS_RETURN( num_valid_fields );
+
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmCorrectUnknownTfield() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pDes EPS_UINT8* O: Pointer to validated pm string */
+/* pSrc EPS_UINT8* I: Pointer to original pm string */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Change an unknown 'T' field to PGPP's in case that PGPP dose not exist in */
+/* 'S' field. If aleady PGPP exist delete it. */
+/* */
+/*******************************************|********************************************/
+static void _pmCorrectUnknownTfield (
+
+ EPS_UINT8* pDes,
+ EPS_UINT8* pSrc
+
+){
+
+ static const EPS_UINT8 PGPP_FIELD [ ] = { 0x54, 0x0B, 0x87, 0x2F };
+
+ EPS_INT16 PGPP = 0; /* Premium Glossy Photo Paper (type id : 0x0b) */
+ EPS_UINT16 t_idx = 0; /* Index of table defined Support 'T' id table */
+ EPS_UINT8 * pScan = NULL; /* word pointer for scanning id */
+
+ EPS_LOG_FUNCIN;
+
+#ifdef _TEST_PM_STEP_2 /* Change 'T' field's id to unknown id such as 0xFF */
+ *(pSrc+3) = 0xFF;
+#endif
+
+ while (*pSrc != 0xD || *(pSrc+1) != 0xA) {
+ /* reset PGPP flag each new 'S' field */
+ PGPP = 0;
+
+ if(*pSrc == 'S') {
+ /* Scan PGPP in current 'S' field */
+ pScan = pSrc;
+
+ if(_pmScanTfield(EPS_MTID_PGPHOTO, pScan) != NULL) {
+ PGPP = 1;
+ }
+
+ *pDes++ = *pSrc++;
+ *pDes++ = *pSrc++;
+
+ while(*pSrc == 'T') {
+ /* Copy support 'T' field */
+ for(t_idx = 0; t_idx < EPS_NUM_MEDIA_TYPES; t_idx++) {
+ if(epsMediaTypeIndex[t_idx] == *(pSrc+1)) {
+ memcpy(pDes, pSrc, 4);
+ pDes += 4;
+ break;
+ }
+ }
+
+ /* Unknown type id encountered */
+ /* if PGPP did not exist in 'S' field */
+ /* then append PGPP fields to pDes */
+ if(t_idx == EPS_NUM_MEDIA_TYPES && PGPP == 0) {
+ memcpy(pDes, PGPP_FIELD, 4);
+ pDes += 4;
+ PGPP = 1;
+ }
+
+ /* move to next 'T' */
+ pSrc += 4;
+ }
+
+ /* copy '/' and move next 'S' */
+ *pDes++ = *pSrc++;
+
+ }else if(*pSrc == 'M' || *pSrc == 'R') {
+ memcpy(pDes, pSrc, 6);
+ pDes += 6;
+ pSrc += 6;
+ }
+ }
+
+ *pDes++ = *pSrc++; /* 0xD */
+ *pDes = *pSrc; /* 0xA */
+
+ EPS_RETURN_VOID;
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmCorrectDupulicatedFields() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pDes EPS_UINT8* O: Pointer to validated pm string */
+/* pSrc EPS_UINT8* I: Pointer to original pm string */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Merge duplicated fields. */
+/* */
+/*******************************************|********************************************/
+static void _pmCorrectDupulicatedFields (
+
+ EPS_UINT8* pDes,
+ EPS_UINT8* pSrc
+
+){
+ EPS_UINT8 merged_buf[EPS_PM_MAXSIZE];
+
+ EPS_UINT8* pFieldS = NULL; /* current 'S' in merged buffer */
+ EPS_UINT8* pFieldT = NULL; /* work pontter to merge a 'T' */
+ EPS_UINT8* pS = NULL; /* duplicated field's starting position */
+ EPS_UINT8* pE = NULL; /* duplicated field's ending postion */
+ EPS_UINT8* pM = NULL; /* pos of merged buffer */
+ EPS_UINT8* pScan = NULL; /* work pointer to find a field */
+ EPS_UINT8 s_id = 0xFF; /* current 'S' id */
+ EPS_INT16 bytes;
+
+ EPS_LOG_FUNCIN;
+
+#ifdef _TEST_PM_STEP_3
+ *(pSrc+8) = 0x0F; /* make duplicate 'S' */
+#endif
+ memset(merged_buf, 0, EPS_PM_MAXSIZE);
+ pM = &merged_buf[0];
+
+ /* Aleady merged fields no need to copy again */
+ while (*pSrc != 0xD || *(pSrc+1) != 0xA) {
+ pFieldS = NULL;
+
+ if(*pSrc == 'S') {
+ VERBOSE_DUMP_PMREPLY((pSrc, DUMP_S_TAG_ONLY, "< STEP 3 : SOURCE 'S' ... >"));
+
+ /* save current 'S' id */
+ s_id = *(pSrc+1);
+
+ if(s_id != MERGED_FIELD) {
+ /* Current 'S' field's starting pos */
+ /* it is used to merge fields later */
+ pFieldS = pM;
+
+ COPY_BYTES(pM, pSrc, 2);
+ }
+
+ pSrc += 2; /* move to first 'T' */
+
+ /* Merge 'T' fields */
+ while(*pSrc == 'T') {
+
+ if(pFieldS && s_id != MERGED_FIELD) {
+ /* if 'T' aleady exist just combine its property by BIT OR operation */
+ if((pFieldT = _pmScanTfield(*(pSrc+1), pFieldS)) != NULL) {
+ *(pFieldT+2) |= *(pSrc+2);
+ }
+
+ /* Copy only new 'T' field */
+ if(pFieldT == NULL) {
+ COPY_BYTES(pM, pSrc, 4);
+ }
+ }
+
+ pSrc += 4; /* next 'T' */
+ }
+ }else if(*pSrc == 'M' || *pSrc == 'R') {
+ memcpy(pM, pSrc, 6);
+ pM += 6;
+ pSrc += 6;
+ continue;
+ }
+
+ if(s_id != MERGED_FIELD) {
+ COPY_BYTES(pM, pSrc, 1);
+ }
+ pSrc++;
+
+ /* aleady merged field just go on next */
+ if(s_id == MERGED_FIELD) {
+ continue;
+ }
+
+ /*----------------------------------------------------*/
+ /* Find dupulicated 'S' being followed and merge them */
+
+ pScan = pSrc; /* do not change pSrc in following loop */
+
+ while(_pmFindSfield(s_id, pScan, &pS, &pE) > 0) {
+
+ /* Change source's 'S' id to MERGED_FIELD */
+ *(pS+1) = MERGED_FIELD;
+ pS += 2;
+
+ /* merge dupulicated 'T' */
+ while(*pS == 'T') {
+
+ /* Append NEW 'T' field to the current 'S' field */
+ /* aleady same 'T' exist only its mode property will be combined */
+ /* after called function */
+ if(pFieldS) {
+ if((bytes = _pmAppendTfield(pS, pFieldS)) > 0) {
+
+ /* update merged_buf's the last pos that pM point it */
+ pM += bytes; /* MUST 4 BYTES(size of 'T' field) ! */
+ }
+ }
+
+ pS += 4; /* next 'T' */
+ }
+
+ /* find next 'S' */
+ pScan = (pE+1);
+
+ VERBOSE_DUMP_PMREPLY((pFieldS, DUMP_S_TAG_ONLY, "< STEP 3 : MERGE PROCESSING ... >"));
+ }
+ }
+
+ /* 0x0D & 0x0A */
+ COPY_BYTES(pM, pSrc, 2);
+
+ /*----------------------------------*/
+ /* Copy the merged PM REPLY to pDes */
+
+ pM = &merged_buf[0];
+
+ while (*pM != 0xD || *(pM+1) != 0xA) {
+ *pDes++ = *pM++;
+ }
+
+ *pDes++ = *pM++; /* 0xD */
+ *pDes = *pM; /* 0xA */
+
+ EPS_RETURN_VOID;
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: _pmAdjustQuality() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pData EPS_UINT8* I/O: Pointer to pm string */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* Adjust quality properties to the formal. */
+/* example : quality has only draft mode -> turn on normal mode. */
+/* */
+/*******************************************|********************************************/
+static void _pmAdjustQuality (
+
+ EPS_UINT8* pData
+
+){
+ EPS_UINT8* p = pData;
+
+ EPS_LOG_FUNCIN;
+
+ /* skip pm heder */
+ p += EPS_PM_HEADER_LEN;
+
+ verbose_dbprint(("< STEP 4 : Adjust quality >\r\n"));
+
+ /* adjuct each quality properties */
+ while(!(*p == 0x0D && *(p+1) == 0x0A)) {
+
+ while(*p == 'S') {
+
+ verbose_dbprint(("%c %02d\r\n", *p, *(p+1)));
+
+ p += 2; /* move to the first T field */
+
+ while(*p == 'T') {
+
+ verbose_dbprint(("\t%c %02d 0x%02x %c -> ", *p, *(p+1), *(p+2), *(p+3)));
+
+ p += 2; /* move to quality pos */
+
+ /* Quality property */
+ switch(*p & 0x07) {
+ /* Should be handled following case 1 bit of Draft turned on only */
+ case 0x01: /* 0 0 1 -> 0 1 1 */
+ *p |= (1<<1); /* turn normal on */
+ break;
+ default:
+ break;
+ }
+
+ verbose_dbprint(("%c %02d 0x%02x %c\r\n", *(p-2), *(p-1), *(p), *(p+1)));
+
+ p += 2; /* move to the next T field */
+ }
+
+ p += 1; /* move to the next S field */
+ }
+
+ if(*p == 'M' || *p == 'R') {
+ p += 6;
+ }
+ }
+
+ EPS_RETURN_VOID;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: obsSetPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN8* I: Pointer to printer info */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* set the observation target printer. */
+/* */
+/*******************************************|********************************************/
+void obsSetPrinter (
+
+ const EPS_PRINTER_INN* printer
+
+){
+ g_observer.printer = printer;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: obsSetColorPlane() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* colorPlane EPS_UINT8 I: color plane */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* set color plane of current job. */
+/* */
+/*******************************************|********************************************/
+void obsSetColorPlane (
+
+ EPS_UINT8 colorPlane
+
+){
+ g_observer.colorPlane = colorPlane;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: obsClear() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* clear all property. */
+/* */
+/*******************************************|********************************************/
+void obsClear (
+
+ void
+
+){
+ g_observer.printer = NULL;
+ g_observer.colorPlane = EPS_CP_FULLCOLOR;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: obsGetPageMode() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* Means to page process. */
+/* */
+/* Description: */
+/* The means to page process is decided. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 obsGetPageMode (
+
+ void
+
+){
+ const EPS_INT8 *modelName = NULL;
+
+ if( NULL == g_observer.printer ){
+ return EPS_PM_PAGE;
+ }
+
+ if(EPS_CP_JPEG == g_observer.colorPlane )
+ {
+ modelName = g_observer.printer->modelName;
+ if( (strcmp(modelName, "EP-801A" ) == 0) ||
+ (strcmp(modelName, "Artisan 700" ) == 0) ||
+ (strcmp(modelName, "Stylus Photo TX700W" ) == 0) ||
+ (strcmp(modelName, "Stylus Photo PX700W" ) == 0) ||
+ (strcmp(modelName, "EP-901F" ) == 0) ||
+ (strcmp(modelName, "EP-901A" ) == 0) ||
+ (strcmp(modelName, "Artisan 800" ) == 0) ||
+ (strcmp(modelName, "Stylus Photo PX800FW") == 0) ||
+ (strcmp(modelName, "Stylus Photo TX800FW") == 0) )
+ {
+ return EPS_PM_JOB;
+ }
+ }
+
+ return EPS_PM_PAGE;
+}
+
+
+EPS_BOOL obsIsA3Model (
+
+ EPS_INT32 ch
+
+){
+ const EPS_INT8 *modelName = NULL;
+
+ modelName = g_observer.printer->modelName;
+ if(EPS_MDC_STATUS == ch){ /* status code */
+ if( (strcmp(modelName, "PX-5V" ) == 0) ||
+ (strcmp(modelName, "Epson Stylus Photo R3000") == 0) ||
+ (strcmp(modelName, "PX-7V" ) == 0) ||
+ (strcmp(modelName, "Epson Stylus Photo R2000") == 0) ||
+ (strcmp(modelName, "EP-4004" ) == 0) ||
+ (strcmp(modelName, "Artisan 1430" ) == 0) ||
+ (strcmp(modelName, "Epson Stylus Photo 1430") == 0) ||
+ (strcmp(modelName, "Epson Stylus Photo 1500") == 0) )
+ {
+ return TRUE;
+ }
+ } else if(EPS_MDC_NOZZLE == ch){ /* nozzle patern */
+ if( (strcmp(modelName, "PX-5V" ) == 0) ||
+ (strcmp(modelName, "Epson Stylus Photo R3000") == 0) ||
+ (strcmp(modelName, "PX-7V" ) == 0) ||
+ (strcmp(modelName, "Epson Stylus Photo R2000") == 0) )
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+static EPS_INT8 modelFY11Bussiness[][16] = {
+ "PX-1600F", "WF-7510 Series", "WF-7511 Series", "WF-7515 Series",
+ "PX-1700F", "WF-7520 Series", "WF-7521 Series", "WF-7525 Series",
+ "PX-1200", "WF-7010 Series", "WF-7011 Series", "WF-7012 Series", "WF-7015 Series",
+ "PX-B750F", "WP-4511 Series", "WP-4515 Series", "WP-4521 Series", "WP-4525 Series",
+ "WP-4530 Series", "WP-4531 Series", "WP-4535 Series",
+ "WP-4540 Series", "WP-4545 Series",
+ "PX-B700", "WP-4015 Series", "WP-4011 Series", "WP-4020 Series", "WP-4025 Series"
+};
+
+EPS_BOOL obsEnableDuplex (
+
+ EPS_INT32 sizeID
+
+){
+ const EPS_INT8 *modelName = NULL;
+ EPS_INT32 i = 0;
+
+ if( !(sizeID == EPS_MSID_A4 ||
+ sizeID == EPS_MSID_LETTER ||
+ sizeID == EPS_MSID_B5 ))
+ {
+ modelName = g_observer.printer->modelName;
+ for(i = 0; i < 28; i++){
+ EPS_DBGPRINT(("%s\n", modelFY11Bussiness[i]));
+ if( strcmp(modelName, modelFY11Bussiness[i]) == 0){
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+}
+/*____________________________ epson-escpr-services.c ______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-escpr-services.h b/lib/epson-escpr-services.h
new file mode 100644
index 0000000..7ef27b6
--- /dev/null
+++ b/lib/epson-escpr-services.h
@@ -0,0 +1,204 @@
+/*_____________________________ epson-escpr-services.h ______________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson ESC/PR Sevice Functions */
+/* */
+/*******************************************|********************************************/
+#ifndef __EPSON_ESCPR_SERVICES_H__
+#define __EPSON_ESCPR_SERVICES_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+#include "epson-escpr-pvt.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+
+/*-------------------------------------- Macros -------------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+ /*** Ink Cartridge Type */
+ /*** -------------------------------------------------------------------------------*/
+#define MI_CARTRIDGE_INDEP 0x00 /* Independent Cartridge */
+#define MI_CARTRIDGE_ONE 0x01 /* One Cartridge */
+
+ /*** Device States */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_ST_ERROR 0x01
+#define EPS_ST_SELF_PRINTING 0x02
+#define EPS_ST_BUSY 0x04
+#define EPS_ST_WAITING 0x08
+#define EPS_ST_IDLE 0x10
+/*#define EPS_ST_PAUSE 0x20*/ /* Not supported by 2006 Model */
+/*#define EPS_ST_INKDRYING 0x40*/ /* Not supported by 2006 Model */
+#define EPS_ST_CLEANING 0x80
+#define EPS_ST_FACTORY_SHIPMENT 0x100
+/*#define EPS_ST_MOTOR_DRIVE_OFF 0x200*/ /* Not supported by 2006 Model */
+#define EPS_ST_SHUTDOWN 0x400
+/*#define EPS_ST_WAITPAPERINIT 0x800*/ /* Not supported by 2006 Model */
+/*#define EPS_ST_INIT_PAPER 0x1000*/ /* Not supported by 2006 Model */
+
+ /*** Device Warnings */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PRNWARN_NONE 0x00 /* No Warnings */
+#define EPS_PRNWARN_INKLOW (1 << 0) /* Ink Low */
+#define EPS_PRNWARN_DISABLE_CLEAN (1 << 1) /* disable cleaning */
+#define EPS_PRNWARN_COLOR_INKOUT (1 << 2) /* disable color print */
+
+
+ /*** Ink Error */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_INKERR_NONE 0
+
+#define EPS_INKERR_INKENDB -1
+#define EPS_INKERR_INKENDC -2
+#define EPS_INKERR_INKENDCY -3
+#define EPS_INKERR_INKENDMA -4
+#define EPS_INKERR_INKENDYL -5
+#define EPS_INKERR_INKENDLC -6
+#define EPS_INKERR_INKENDLM -7
+#define EPS_INKERR_INKENDLY -8
+#define EPS_INKERR_INKENDDY -9
+#define EPS_INKERR_INKENDB2 -10
+#define EPS_INKERR_INKENDRD -11
+#define EPS_INKERR_INKENDBL -12
+#define EPS_INKERR_INKENDMB -13
+#define EPS_INKERR_INKENDPB -14
+#define EPS_INKERR_INKENDGO -15
+#define EPS_INKERR_INKENDALL -16
+#define EPS_INKERR_INKENDBC -17
+
+#define EPS_INKERR_CEMPTYB -101
+#define EPS_INKERR_CEMPTYC -102
+#define EPS_INKERR_CEMPTYCY -103
+#define EPS_INKERR_CEMPTYMA -104
+#define EPS_INKERR_CEMPTYYL -105
+#define EPS_INKERR_CEMPTYLC -106
+#define EPS_INKERR_CEMPTYLM -107
+#define EPS_INKERR_CEMPTYLY -108
+#define EPS_INKERR_CEMPTYDY -109
+#define EPS_INKERR_CEMPTYB2 -110
+#define EPS_INKERR_CEMPTYRD -111
+#define EPS_INKERR_CEMPTYBL -112
+#define EPS_INKERR_CEMPTYMB -113
+#define EPS_INKERR_CEMPTYPB -114
+#define EPS_INKERR_CEMPTYGO -115
+#define EPS_INKERR_CEMPTYBC -116
+#define EPS_INKERR_CEMPTYALL -117
+
+#define EPS_INKERR_CFAILB -201
+#define EPS_INKERR_CFAILC -202
+#define EPS_INKERR_CFAILCY -203
+#define EPS_INKERR_CFAILMA -204
+#define EPS_INKERR_CFAILYL -205
+#define EPS_INKERR_CFAILLC -206
+#define EPS_INKERR_CFAILLM -207
+#define EPS_INKERR_CFAILLY -208
+#define EPS_INKERR_CFAILDY -209
+#define EPS_INKERR_CFAILB2 -210
+#define EPS_INKERR_CFAILRD -211
+#define EPS_INKERR_CFAILBL -212
+#define EPS_INKERR_CFAILMB -213
+#define EPS_INKERR_CFAILPB -214
+#define EPS_INKERR_CFAILGO -215
+#define EPS_INKERR_CFAILBC -216
+#define EPS_INKERR_CFAILALL -217
+
+ /*** Cancel request from printer */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_CAREQ_CANCEL -300
+#define EPS_CAREQ_NOCANCEL -301
+
+ /*** Other Printer Information */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PREPARE_OVERHEAT -400
+#define EPS_PREPARE_NORMALHEAT -401
+#define EPS_PREPARE_TRAYOPENED -402
+#define EPS_PREPARE_TRAYCLOSED -403
+
+ /*** reset mode */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PM_PAGE 1
+#define EPS_PM_JOB 2
+
+ /*** Misc */
+ /*** -------------------------------------------------------------------------------*/
+#define _SECOND_ 1000 /* Unit for changing milli second to second */
+#define _STATUS_REPLY_BUF 256 /* Printer status buffer size */
+
+
+ /*** PM string resource ID */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PMS_E300 (1)
+#define EPS_PMS_E500 (2)
+#define EPS_PMS_E700 EPS_PMS_E500
+#define EPS_PMS_PM200 (3)
+#define EPS_PMS_PM240 (4)
+
+ /*** Model depend */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_MDC_STATUS (1)
+#define EPS_MDC_NOZZLE (2)
+
+/*--------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern EPS_BOOL serParseDeviceID (EPS_INT8*, EPS_INT8*, EPS_INT8*, EPS_INT32*, EPS_UINT32*);
+extern EPS_ERR_CODE serAnalyzeStatus (EPS_INT8*, EPS_STATUS_INFO* );
+extern void serDelayThread (EPS_UINT32, EPS_CMN_FUNC* );
+extern EPS_INT32 serGetInkError (EPS_STATUS_INFO*, EPS_INT32* );
+extern EPS_INT32 serInkLevelNromalize (EPS_INT32 );
+
+#ifdef GCOMSW_EPSON_SLEEP
+extern EPS_ERR_CODE serSleep (EPS_UINT32 );
+#endif
+
+ /*** pm reply */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE _SP_ChangeSpec_UpdatePMReply(EPS_PRINTER_INN*, EPS_UINT8*, EPS_INT32);
+extern EPS_ERR_CODE _SP_ChangeSpec_DraftOnly (EPS_PRINTER_INN*, EPS_JOB_ATTRIB* );
+extern void serAppendMedia (EPS_SUPPORTED_MEDIA* );
+
+
+extern void obsSetPrinter (const EPS_PRINTER_INN* );
+extern void obsSetColorPlane (EPS_UINT8 );
+extern void obsClear (void );
+extern EPS_INT32 obsGetPageMode (void );
+extern EPS_BOOL obsIsA3Model (EPS_INT32 );
+extern EPS_BOOL obsEnableDuplex (EPS_INT32 );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* def __EPSON_ESCPR_SERVICES_H__ */
+
+
+/*_____________________________ epson-escpr-services.h _______________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-layout.c b/lib/epson-layout.c
new file mode 100644
index 0000000..d44e223
--- /dev/null
+++ b/lib/epson-layout.c
@@ -0,0 +1,223 @@
+/*_________________________________ epson-layout.c _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Extent Layout Module */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE elAppendQRCode (qrcode ); */
+/* EPS_ERR_CODE elComposeQrcode (pSrc, pDst, bpp, pRec ); */
+/* EPS_ERR_CODE elCDClipping (pSrc, pDst, bpp, pRec ); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-def.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-media.h"
+#include "epson-escpr-mem.h"
+#include "epson-layout.h"
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_ELT
+#define EPS_LOG_MODULE EPS_LOG_MODULE_ELT
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+extern EPS_CMN_FUNC epsCmnFnc;
+
+ /*** Print Job Structure */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_PRINT_JOB printJob;
+
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+
+/*-------------------------- Local Functions Declaration ----------------------------*/
+/*******************************************|********************************************/
+static EPS_UINT32 isqrt(EPS_UINT32 x);
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: elGetDots() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* resolution EPS_UINT8 I: resolution */
+/* length EPS_INT32 I: length */
+/* */
+/* Return value: */
+/* Dot num */
+/* */
+/* Description: */
+/* calc the number of the dots in the resolution. */
+/* */
+/*******************************************|********************************************/
+EPS_INT32 elGetDots (
+
+ EPS_UINT8 resolution,
+ EPS_FLOAT millimeter
+
+){
+ EPS_INT32 dots = 0;
+
+ if(resolution == EPS_IR_360X360){ /* EPS_IR_360X360 == 0 */
+ dots = (EPS_INT32)(millimeter * 14.1732); /* 0.03937 * 360 = 14.1732 */
+ } else if( resolution & EPS_IR_720X720 ){
+ dots = (EPS_INT32)(millimeter * 28.3464); /* 0.03937 * 720 = 28.3464 */
+ } else if( resolution & EPS_IR_300X300 ){
+ dots = (EPS_INT32)(millimeter * 11.811); /* 0.03937 * 300 = 11.811 */
+ } else if( resolution & EPS_IR_600X600 ){
+ dots = (EPS_INT32)(millimeter * 23.622); /* 0.03937 * 600 = 23.622 */
+ } else{
+ /* default 360dpi */
+ dots = (EPS_INT32)(millimeter * 14.1732); /* 0.03937 * 360 = 14.1732 */
+ }
+
+ return dots;
+}
+
+
+#ifdef GCOMSW_EL_CDLABEL
+/*******************************************|********************************************/
+/* */
+/* Function name: elCDClipping() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pSrc const EPS_UINT8* I: source buffer */
+/* pDst EPS_UINT8* O: destination buffer */
+/* bpp EPS_UINT8 I: byte per pixel */
+/* pRec EPS_RECT* I/O: byte per pixel */
+/* */
+/* Return value: */
+/* None */
+/* */
+/* Description: */
+/* clip band line to cd label */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE elCDClipping (
+
+ const EPS_UINT8* pSrc,
+ EPS_UINT8* pDst,
+ EPS_UINT8 bpp,
+ EPS_RECT* pRec
+
+){
+#define GET_RADIUS(mm) (EPS_INT32)(elGetDots(printJob.attr.inputResolution, mm)/2)
+#define X_OF_SECANT(r, y) ((EPS_INT32)isqrt((r-y) * (r+y)))
+
+ EPS_LINE_SEGMENT segOut, segIn;
+ EPS_INT32 rOut = GET_RADIUS(printJob.attr.cdDimOut);
+ EPS_INT32 rIn = GET_RADIUS(printJob.attr.cdDimIn);
+ EPS_INT32 y = 0;
+ EPS_UINT32 wOut = 0;
+ EPS_UINT32 wIn = 0;
+
+ EPS_LOG_FUNCIN;
+
+ /* calc clipping segment */
+ y = rOut - pRec->top;
+ if(y <= 0) {
+ y -= -1;
+ }
+
+ wOut = X_OF_SECANT(rOut, y);
+ segOut.start = rOut - wOut;
+ segOut.length = wOut * 2;
+
+ if(y <= rIn && y >= -rIn) {
+ wIn = X_OF_SECANT(rIn, y);
+ segIn.start = wOut - wIn;
+ segIn.length = wIn * 2;
+ } else{
+ segIn.start =
+ segIn.length = 0;
+ }
+
+/* EPS_DBGPRINT((" (%04d - %04d) (%04d - %04d)\n",
+ segOut.start, segOut.length,
+ segIn.start, segIn.length));
+*/
+ /* outside clip */
+ memcpy(pDst, pSrc + segOut.start * bpp, segOut.length * bpp);
+
+ /* inside mask */
+ if( 0 < segIn.start){
+ memset(pDst + segIn.start * bpp, 0xFF, segIn.length * bpp);
+ }
+
+ pRec->left = segOut.start;
+ pRec->right = segOut.start + segOut.length;
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+static EPS_UINT32 isqrt(EPS_UINT32 x)
+{
+ EPS_INT32 b = 15; /* this is the next bit we try */
+ EPS_UINT32 r = 0; /* r will contain the result */
+ EPS_UINT32 r2= 0; /* here we maintain r squared */
+
+ while(b>=0)
+ {
+ EPS_UINT32 sr2=r2;
+ EPS_UINT32 sr=r;
+ /* compute (r+(1<<b))**2, we have r**2 already. */
+ r2 += (EPS_UINT32)((r<<(1+b))+(1<<(b+b)));
+ r += (EPS_UINT32)(1<<b);
+ if (r2>x)
+ {
+ r=sr;
+ r2=sr2;
+ }
+ b--;
+ }
+ return r;
+}
+#endif /* GCOMSW_EL_CDLABEL */
+
+/*_________________________________ epson-layout.c _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
diff --git a/lib/epson-layout.h b/lib/epson-layout.h
new file mode 100644
index 0000000..2537ae7
--- /dev/null
+++ b/lib/epson-layout.h
@@ -0,0 +1,63 @@
+/*_________________________________ epson-layout.h _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+* Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+*
+* Copyright protection claimed includes all forms and matters of
+* copyrightable material and information now allowed by statutory or judicial
+* law or hereinafter granted, including without limitation, material generated
+* from the software programs which are displayed on the screen such as icons,
+* screen display looks, etc.
+*
+*/
+/*******************************************|********************************************/
+/* */
+/* Epson Extent Layout Definitions */
+/* */
+/*******************************************|********************************************/
+
+#ifndef __EPSON_LAYOUT_H__
+#define __EPSON_LAYOUT_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+ /*** CD/DVD Sizing Information */
+ /*** -------------------------------------------------------------------------------*/
+#define CDDVD_OFFSET_X(r, d) (EPS_INT32)(elGetDots(r, (EPS_FLOAT)(14.0 + (EPS_FLOAT)(EPS_CDDIM_OUT_DEF - d)/2)) + elGetDots(r, 3))
+#define CDDVD_OFFSET_Y(r, d) (EPS_INT32)(elGetDots(r, (EPS_FLOAT)( 6.5 + (EPS_FLOAT)(EPS_CDDIM_OUT_DEF - d)/2)) + elGetDots(r, 3))
+
+/*---------------------------- API Function Declarations ----------------------------*/
+/*******************************************|********************************************/
+extern EPS_INT32 elGetDots (EPS_UINT8 inputResolution, EPS_FLOAT length );
+
+#ifdef GCOMSW_EL_CDLABEL
+extern EPS_ERR_CODE elCDClipping (const EPS_UINT8*, EPS_UINT8*, EPS_UINT8, EPS_RECT* );
+#endif
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* def __EPSON_LAYOUT_H__ */
+
+/*_________________________________ epson-layout.h _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-net-lpr.c b/lib/epson-net-lpr.c
new file mode 100644
index 0000000..a184267
--- /dev/null
+++ b/lib/epson-net-lpr.c
@@ -0,0 +1,1091 @@
+/*________________________________ epson-net-lpr.c _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* LPR protocol Module */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE lprFindStart (sock, address, flg ); */
+/* EPS_ERR_CODE lprFind (sock, printer ); */
+/* EPS_ERR_CODE lprFindEnd (sock ); */
+/* EPS_ERR_CODE lprProbePrinterByID(printerUUID, timeout, printer ); */
+/* EPS_ERR_CODE lprStartJob (printr ); */
+/* EPS_ERR_CODE lprEndPage ( ); */
+/* EPS_ERR_CODE lprResetPrinter ( ); */
+/* EPS_ERR_CODE lprWritePrintData (buffer, bufferlen, sendlen ); */
+/* EPS_ERR_CODE lprGetStatus (printer, status, ioStatus ); */
+/* EPS_ERR_CODE lprGetJobStatus (pstInfo ); */
+/* EPS_ERR_CODE lprGetPMString (printer, pString, bufSize ); */
+/* EPS_ERR_CODE lprMechCommand (printer, Command ); */
+/* */
+/*******************************************|********************************************/
+
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-def.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpr-services.h"
+#include "epson-protocol.h"
+#include "epson-net-snmp.h"
+#include "epson-net-lpr.h"
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_LPR
+#define EPS_LOG_MODULE EPS_LOG_MODULE_LPR
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+#define LPR_PORT_NUM (515) /* Protocol port number */
+#define LPR_MAX_BUF (512) /* Communication buffer size */
+#define LPR_DUMMY_DATA_SIZE ("1073741824000") /* Enhanced LPR buffer size */
+#define LPR_HOST_NAME "escpr-lib" /* LPR print host name */
+
+#define IS_JOB_ACTIVE \
+ ( (NULL != printJob.printer) && (NULL != printJob.hProtInfo) \
+ && (EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol)) )
+
+#define IS_VALID_DATA_SESSION \
+ ( (NULL != printJob.printer) && (NULL != printJob.hProtInfo) \
+ && (EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol)) \
+ && (EPS_INVALID_SOCKET != ((EPS_PRINT_JOB_LPR*)printJob.hProtInfo)->socData) )
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+extern EPS_NET_FUNC epsNetFnc;
+extern EPS_CMN_FUNC epsCmnFnc;
+
+ /*** Print Job Structure */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_PRINT_JOB printJob;
+
+static EPS_SNMP_FUNCS snmp;
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagEPS_PRINT_JOB_LPR_ {
+ EPS_SOCKET socData; /* LPR socket for send data */
+ EPS_SOCKET socStat; /* SNMP socket for check status */
+ EPS_BOOL reseted; /* reseted */
+ EPS_BOOL pageend; /* page end - start */
+} EPS_PRINT_JOB_LPR;
+
+/*-------------------------------- LPR Local Variables -------------------------------*/
+/*******************************************|********************************************/
+
+/*-------------------------- Local Functions Declaration ----------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE StartDataSession (EPS_PRINT_JOB_LPR*, const EPS_PRINTER_INN* );
+static EPS_ERR_CODE EndDataSession (EPS_PRINT_JOB_LPR* );
+
+static EPS_INT16 GetJobId (void );
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+void lprSetupSTFunctions (
+
+ const EPS_PRINTER_INN* printer
+
+){
+ EPS_LOG_FUNCIN
+
+ snmpSetupSTFunctions(&snmp, printer);
+
+ EPS_RETURN_VOID
+}
+
+
+EPS_UINT16 lprGetDefautiPort (
+
+ void
+
+){
+ return LPR_PORT_NUM;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprFindStart() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET* O: send discovery message socket */
+/* address EPS_INT8* I: Destination address */
+/* multi EPS_BOOL I: If TRUE, send multicast */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Sends EPSNET_NUM_DISCOVERIES number of upnp discovery message to find */
+/* devices. Discovery message is sent more than once because udp is unreliable. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprFindStart(
+
+ EPS_SOCKET* sock,
+ const EPS_INT8* address,
+ EPS_BOOL multi
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpFindStart(sock, address, multi) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprFind() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: Discover Socket */
+/* printer EPS_PRINTER_INN** O: pointer for found printer structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - socket error */
+/* EPS_ERR_MEMORY_ALLOCATION */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
+/* */
+/* Description: */
+/* Receive discover messasge. Get printer name. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprFind (
+
+ EPS_SOCKET sock,
+ EPS_PRINTER_INN** printer
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpFind(sock, LPR_PORT_NUM, EPS_PROTOCOL_LPR, printer) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprFindEnd() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: Discover Socket */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Close socket failed */
+/* */
+/* Description: */
+/* close discover process. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprFindEnd (
+
+ EPS_SOCKET sock
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpFindEnd(sock) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprProbePrinterByID() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* defstr EPS_INT8* I: ID String of probe target */
+/* timeout EPS_UINT32 I: find timeout */
+/* printer EPS_PRINTER* O: Pointer for Alloc Printer infomation structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - socket failed */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* */
+/* Description: */
+/* Probe printer by ID String. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprProbePrinterByID (
+
+ EPS_INT8* printerUUID,
+ EPS_UINT32 timeout,
+ EPS_PRINTER_INN** printer
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpProbeByID(printerUUID, LPR_PORT_NUM, EPS_PROTOCOL_LPR, timeout, printer) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprStartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: pointer to printer Structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* Description: */
+/* Open socekt & Send start job messasge. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprStartJob(
+
+ void
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINT_JOB_LPR *lprPrintJob = NULL;
+
+ EPS_LOG_FUNCIN
+
+ /* Alloc LPR Job Data */
+ lprPrintJob = (EPS_PRINT_JOB_LPR*)EPS_ALLOC( sizeof(EPS_PRINT_JOB_LPR) );
+ if( NULL == lprPrintJob ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+ memset(lprPrintJob, 0, sizeof(EPS_PRINT_JOB_LPR));
+ lprPrintJob->socStat = lprPrintJob->socData = EPS_INVALID_SOCKET;
+ lprPrintJob->reseted = FALSE;
+ lprPrintJob->pageend = FALSE;
+
+ /* Establish Connection & send start job message */
+ ret = StartDataSession( lprPrintJob, printJob.printer );
+
+ if( EPS_ERR_NONE == ret
+ && EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ /* create check status */
+ ret = snmpOpenSocket( &(lprPrintJob->socStat) );
+ if( EPS_ERR_NONE != ret ){
+ goto lprStartJob_END;
+ }
+ }
+
+ printJob.hProtInfo = (EPS_HANDLE)lprPrintJob;
+
+lprStartJob_END:
+
+ if( EPS_ERR_NONE != ret ){
+ if( EPS_INVALID_SOCKET != lprPrintJob->socStat ){
+ snmpCloseSocket( &lprPrintJob->socStat );
+ }
+
+ if( EPS_INVALID_SOCKET != lprPrintJob->socData ){
+ epsNetFnc.close( lprPrintJob->socData );
+ lprPrintJob->socData = EPS_INVALID_SOCKET;
+ }
+ EPS_SAFE_RELEASE( lprPrintJob );
+
+ printJob.hProtInfo = NULL;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprRestartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Open socekt & Send start job messasge. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprRestartJob(
+
+ void
+
+){
+ EPS_PRINT_JOB_LPR *lprPrintJob = (EPS_PRINT_JOB_LPR*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == lprPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /* Establish Connection & send start job message */
+ EPS_RETURN( StartDataSession( lprPrintJob, printJob.printer ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprWritePrintData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* buffer EPS_UINT8* I: Print data */
+/* bufferlen EPS_INT32 I: Print data length */
+/* sendlen EPS_INT32* O: Sended length */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Called from SendCommand, Send print data. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprWritePrintData(
+
+ const EPS_UINT8* buffer,
+ EPS_UINT32 bufferlen,
+ EPS_UINT32* sendlen
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINT_JOB_LPR* lprPrintJob = (EPS_PRINT_JOB_LPR*)printJob.hProtInfo;
+ EPS_UINT32 timeout;
+ EPS_INT32 sentSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ if( !lprPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /* Send ESC/P-R data */
+ timeout = (EPS_UINT32)((EPS_IS_BI_PROTOCOL(printJob.printer->protocol))?EPSNET_BAND_SEND_TIMEOUT:EPSNET_BAND_SEND_TIMEOUTL);
+
+ sentSize = epsNetFnc.send(lprPrintJob->socData, (char*)buffer, (EPS_INT32)bufferlen, timeout);
+
+ if( EPS_SOCKET_ERROR == sentSize ){
+ *sendlen = 0;
+ ret = EPS_ERR_COMM_ERROR;
+ } else if( EPS_SOCKET_TIMEOUT == sentSize ){
+ *sendlen = 0;
+ ret = EPS_COM_TINEOUT;
+ } else{
+ *sendlen = (EPS_UINT32)sentSize;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprEndJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* */
+/* Description: */
+/* Send endjob messasge & Close connection. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprEndJob()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINT_JOB_LPR* lprPrintJob = (EPS_PRINT_JOB_LPR*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( !lprPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /* Close SendData Session */
+ EndDataSession(lprPrintJob);
+
+ if( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ snmpCloseSocket( &lprPrintJob->socStat );
+ }
+
+ EPS_SAFE_RELEASE( printJob.hProtInfo );
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprResetPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* */
+/* Description: */
+/* Send endjob messasge & Close connection. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprResetPrinter(
+
+ void
+
+){
+ EPS_PRINT_JOB_LPR* lprPrintJob = (EPS_PRINT_JOB_LPR*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == printJob.hProtInfo || NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+/*** If we already successfully called this function once for a given print job, */
+ if(printJob.resetSent != EPS_RESET_SENT
+ && FALSE != printJob.transmittable
+ && TRUE == printJob.sendJS ){
+ lprMechCommand(printJob.printer, EPS_CBTCOM_RJ);
+ }
+
+ lprPrintJob->reseted = TRUE;
+
+ /* Close SendData Session */
+ EPS_RETURN( EndDataSession(lprPrintJob) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprStartPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Open socekt & Send start job messasge. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprStartPage(
+
+ void
+
+){
+ EPS_PRINT_JOB_LPR *lprPrintJob = (EPS_PRINT_JOB_LPR*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == lprPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ ((EPS_PRINT_JOB_LPR*)printJob.hProtInfo)->pageend = FALSE;
+
+ /* Establish Connection & send start job message */
+ EPS_RETURN( StartDataSession( lprPrintJob, printJob.printer ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprEndPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* */
+/* Description: */
+/* Send endjob messasge & Close connection. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprEndPage(
+
+ void
+
+){
+ EPS_PRINT_JOB_LPR *lprPrintJob = (EPS_PRINT_JOB_LPR*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == printJob.hProtInfo ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ lprPrintJob->pageend = TRUE;
+
+ /* Close SendData Session */
+ EPS_RETURN( EndDataSession(lprPrintJob) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprGetStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Printer data structure */
+/* status EPS_STATUS_INFO* O: retrieve printer satus */
+/* ioStatus EPS_INT32* O: It is possible to communicate */
+/* canceling EPS_BOOL* O: Cancel processing */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get Printer status by SNMP. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprGetStatus(
+
+ EPS_STATUS_INFO* pstInfo,
+ EPS_BOOL* pIoStatus,
+ EPS_BOOL* pCancelling
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINTER_INN* printer = printJob.printer;
+ EPS_SOCKET sock = EPS_INVALID_SOCKET;
+
+ EPS_LOG_FUNCIN
+
+ if( !EPS_IS_BI_PROTOCOL(printer->protocol) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+ memset(pstInfo, -1, sizeof(EPS_STATUS_INFO));
+
+ /*** Get Printer status by SNMP */
+ ret = snmpOpenSocket( &sock );
+ if( EPS_ERR_NONE != ret ){
+ EPS_RETURN( ret )
+ }
+
+ ret = snmp.GetStatus(sock, printer->location, pstInfo );
+
+ if( !IS_VALID_DATA_SESSION ){
+ /* Another proceessing, or printing after endjob */
+ if( EPS_ST_WAITING == pstInfo->nState
+ && EPS_PRNERR_NOERROR == pstInfo->nError){
+ pstInfo->nState = EPS_ST_ERROR;
+ pstInfo->nError = EPS_PRNERR_BUSY;
+ }
+ }
+
+ if(NULL != pIoStatus && NULL != pCancelling){
+ if(EPS_ERR_NONE == ret){
+ if( IS_VALID_DATA_SESSION || pstInfo->nState == EPS_ST_IDLE ||
+ (IS_JOB_ACTIVE && ((EPS_PRINT_JOB_LPR*)printJob.hProtInfo)->pageend) ){
+ *pIoStatus = TRUE;
+ } else{
+ *pIoStatus = FALSE;
+ }
+
+ if( IS_JOB_ACTIVE ){
+ if( TRUE == ((EPS_PRINT_JOB_LPR*)printJob.hProtInfo)->reseted ){
+ if(EPS_ST_IDLE == pstInfo->nState){
+ /* cancel finished */
+ *pCancelling = FALSE;
+ ((EPS_PRINT_JOB_LPR*)printJob.hProtInfo)->reseted = FALSE;
+ } else{
+ /* cancelling */
+ *pCancelling = TRUE;
+ }
+ } else if( pstInfo->nCancel == EPS_CAREQ_CANCEL ){
+ /* cancel request from printer */
+ *pCancelling = TRUE;
+ } else{
+ *pCancelling = FALSE;
+ }
+ } else{
+ *pCancelling = FALSE;
+ }
+ } else{
+ *pIoStatus = FALSE;
+ *pCancelling = FALSE;
+ }
+ }
+
+ snmpCloseSocket( &sock );
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprGetJobStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pstInfo EPS_STATUS_INFO* O: retrieve printer satus */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get Printer status by SNMP. It is possible to use in Job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprGetJobStatus(
+
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_PRINT_JOB_LPR* lprPrintJob = (EPS_PRINT_JOB_LPR*)printJob.hProtInfo;
+ EPS_PRINTER_INN* printer = (EPS_PRINTER_INN*)printJob.printer;
+
+ EPS_LOG_FUNCIN
+
+ /* Initialize variables */
+ memset(pstInfo, 0, sizeof(EPS_STATUS_INFO));
+
+ if( !lprPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /*** Get Printer status by SNMP */
+ EPS_RETURN( snmp.GetStatus( lprPrintJob->socStat, printer->location, pstInfo ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprGetInkInfo() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* status EPS_STATUS_INFO* O: retrieve printer satus */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get Ink information. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprGetInkInfo(
+
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_PRINTER_INN* printer = printJob.printer;
+
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmp.GetInkInfo(printer->location, pstInfo ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprGetPMString() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
+/* pString EPS_UINT8* O: Pointer to PM String */
+/* bufSize EPS_INT32 I: pString buffer size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* */
+/* Description: */
+/* Sends request to printer for supported media. Parses response and stores */
+/* PM String : pString */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprGetPMString(
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 type,
+ EPS_UINT8* pString,
+ EPS_INT32* bufSize
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmp.GetPMString(printer, type, pString, bufSize) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: lprMechCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Command EPS_INT32 I: Command Code */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Mech command executed successfully */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Mech command execution error */
+/* */
+/* Description: */
+/* Sends mechanincal commands to the printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE lprMechCommand (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 Command
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmp.MechCommand(printer, Command) )
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: StartDataSession() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* lprPrintJob EPS_PRINT_JOB_LPR* O : LPR Job information */
+/* printer EPS_PRINTER_INN* I : target printer information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Starts a print job. Establish Connection, Send StartJob message. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE StartDataSession(
+
+ EPS_PRINT_JOB_LPR* lprPrintJob,
+ const EPS_PRINTER_INN* printer
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT16 nJobID = 0;
+ EPS_INT8 dname[EPS_NAME_BUFFSIZE+1];
+ EPS_INT8 cname[EPS_NAME_BUFFSIZE+1];
+ EPS_INT8 controlfile[256];
+
+ EPS_INT8* buffer = NULL;
+ const char pqueue[16] = "P1";
+
+ EPS_LOG_FUNCIN
+
+ if(EPS_INVALID_SOCKET != lprPrintJob->socData){
+ /* Already established */
+ EPS_RETURN( EPS_ERR_NONE )
+ }
+
+ /* Initialize variables */
+ buffer = (EPS_INT8*)EPS_ALLOC( LPR_MAX_BUF );
+ if( NULL == buffer ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ /* create socket */
+ lprPrintJob->socData = epsNetFnc.socket(EPS_PF_INET, EPS_SOCK_STREAM, EPS_PROTOCOL_TCP);
+ if( EPS_INVALID_SOCKET == lprPrintJob->socData ){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* connect to printer */
+ if(EPS_SOCKET_SUCCESS != epsNetFnc.connect(lprPrintJob->socData, printer->location, printer->printPort)){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* -------------------------------------------------------------------------------- */
+ /* COMMAND: PRINTJOB */
+ /* +----+-------+----+ */
+ /* | 02 | Queue | LF | */
+ /* +----+-------+----+ */
+ sprintf(buffer, "\x02%s\n", pqueue);
+
+ /* send command*/
+ if( epsNetFnc.send(lprPrintJob->socData, buffer, (EPS_INT32)strlen(buffer), EPSNET_SEND_TIMEOUT)
+ != (EPS_INT32)strlen(buffer)){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* receive response */
+ if( 0 >= epsNetFnc.receive(lprPrintJob->socData, buffer, LPR_MAX_BUF, EPSNET_RECV_TIMEOUT)
+ || buffer[0] != 0){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* -------------------------------------------------------------------------------- */
+ /* SUBCMD: CONTROL FILE */
+ /* +----+-------+----+------+----+ */
+ /* | 02 | Count | SP | Name | LF | */
+ /* +----+-------+----+------+----+ */
+ /* Command code - 2 */
+ /* Operand 1 - Number of bytes in control file */
+ /* Operand 2 - Name of control file */
+ nJobID = GetJobId();
+ sprintf(dname, "dfA%d%s", nJobID, LPR_HOST_NAME);
+ sprintf(cname, "cfA%d%s", nJobID, LPR_HOST_NAME);
+ sprintf(controlfile, "H%s\nP%s\nv%s\nU%s\nN%s\n",
+ LPR_HOST_NAME, "epson", dname, dname, "epson.prn");
+ sprintf(buffer, "\x02%d %s\n", (EPS_UINT32)strlen(controlfile), cname);
+
+ /* send command*/
+ if( epsNetFnc.send(lprPrintJob->socData, buffer, (EPS_INT32)strlen(buffer), EPSNET_SEND_TIMEOUT)
+ != (EPS_INT32)strlen(buffer)){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* receive response */
+ if( 0 >= epsNetFnc.receive(lprPrintJob->socData, buffer, LPR_MAX_BUF, EPSNET_RECV_TIMEOUT)
+ || buffer[0] != 0){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* -------------------------------------------------------------------------------- */
+ /* ADD CONTENT OF CONTROLFILE */
+ /* send command*/
+ if( epsNetFnc.send(lprPrintJob->socData, controlfile, (EPS_INT32)strlen(controlfile) + 1, EPSNET_SEND_TIMEOUT)
+ != (EPS_INT32)strlen(controlfile)+1){ /* Send '\0' */
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* receive response */
+ if( 0 >= epsNetFnc.receive(lprPrintJob->socData, buffer, LPR_MAX_BUF, EPSNET_RECV_TIMEOUT)
+ || buffer[0] != 0){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* -------------------------------------------------------------------------------- */
+ /* SUBCMD: DATA FILE */
+ /* +----+-------+----+------+----+ */
+ /* | 03 | Count | SP | Name | LF | */
+ /* +----+-------+----+------+----+ */
+ /* Command code - 3 */
+ /* Operand 1 - Number of bytes in data file */
+ /* Operand 2 - Name of data file */
+ sprintf(buffer, "\x03%s %s\n", LPR_DUMMY_DATA_SIZE, dname);
+
+ /* send command*/
+ if( epsNetFnc.send(lprPrintJob->socData, buffer, (EPS_INT32)strlen(buffer), EPSNET_SEND_TIMEOUT)
+ != (EPS_INT32)strlen(buffer)){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* receive response */
+ if( 0 >= epsNetFnc.receive(lprPrintJob->socData, buffer, LPR_MAX_BUF, EPSNET_RECV_TIMEOUT)
+ || buffer[0] != 0){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ lprPrintJob->reseted = FALSE;
+ lprPrintJob->pageend = FALSE;
+ /*printJob.hProtInfo = (EPS_HANDLE)lprPrintJob;*/
+
+StartDataSession_END:
+ if( EPS_ERR_NONE != ret ){
+ if( EPS_INVALID_SOCKET != lprPrintJob->socData ){
+ epsNetFnc.close( lprPrintJob->socData );
+ lprPrintJob->socData = EPS_INVALID_SOCKET;
+ }
+ }
+ EPS_SAFE_RELEASE( buffer );
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EndDataSession() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* lprPrintJob EPS_PRINT_JOB_LPR* IO : LPR Job information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Send EndJob line to printer, shutdown/close socket. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE EndDataSession(
+
+ EPS_PRINT_JOB_LPR* lprPrintJob
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Used for error handling */
+
+ EPS_LOG_FUNCIN
+
+ if( EPS_INVALID_SOCKET != lprPrintJob->socData){
+#if 0 /* This command is ineffectual. */
+ /* -------------------------------------------------------------------------------- */
+ /* COMMAND: End Job */
+ /* +----+ */
+ /* | 00 | */
+ /* +----+ */
+ EPS_INT8 buffer[LPR_MAX_BUF];
+ buffer[0] = 0x00;
+ if( epsNetFnc.send(lprPrintJob->socData, buffer, 1, EPSNET_SEND_TIMEOUT) >= 1){
+ epsNetFnc.receive(lprPrintJob->socData, buffer, LPR_MAX_BUF, EPSNET_RECV_TIMEOUT);
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ }
+#endif
+
+ /*** If we already successfully called this function once for a given print job, */
+ epsNetFnc.shutdown(lprPrintJob->socData, EPS_SHUTDOWN_SEND);
+ epsNetFnc.shutdown(lprPrintJob->socData, EPS_SHUTDOWN_RECV);
+ epsNetFnc.shutdown(lprPrintJob->socData, EPS_SHUTDOWN_BOTH);
+
+ ret = epsNetFnc.close(lprPrintJob->socData);
+ lprPrintJob->socData = EPS_INVALID_SOCKET;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: GetJobId() */
+/* */
+/* Arguments */
+/* --------- */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_INT16 : JobID */
+/* */
+/* Description: */
+/* Generate LPR job ID (value is between from 1 to 999). */
+/* */
+/*******************************************|********************************************/
+static EPS_INT16 GetJobId(
+
+ void
+
+){
+ static EPS_INT16 nJobId = 0;
+
+ nJobId++; /* next number but */
+ if(nJobId > 999){ /* keep cnt between 0 and 999 */
+ nJobId = 0;
+ }
+
+ return nJobId;
+}
+
+/*_______________________________ epson-net-lpr.c ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
diff --git a/lib/epson-net-lpr.h b/lib/epson-net-lpr.h
new file mode 100644
index 0000000..6c19c8d
--- /dev/null
+++ b/lib/epson-net-lpr.h
@@ -0,0 +1,75 @@
+/*_______________________________ epson-net-lpr.h ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+* Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+*
+* Copyright protection claimed includes all forms and matters of
+* copyrightable material and information now allowed by statutory or judicial
+* law or hereinafter granted, including without limitation, material generated
+* from the software programs which are displayed on the screen such as icons,
+* screen display looks, etc.
+*
+*/
+/*******************************************|********************************************/
+/* */
+/* Epson LPR Protocol Definitions */
+/* */
+/*******************************************|********************************************/
+
+#ifndef __EPSON_NET_LPR_H__
+#define __EPSON_NET_LPR_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+/* Initialize */
+extern void lprSetupSTFunctions (const EPS_PRINTER_INN* );
+extern EPS_UINT16 lprGetDefautiPort (void );
+
+/* Discovery message related Functions */
+extern EPS_ERR_CODE lprFindStart (EPS_SOCKET*, const EPS_INT8*, EPS_BOOL );
+extern EPS_ERR_CODE lprFind (EPS_SOCKET, EPS_PRINTER_INN** );
+extern EPS_ERR_CODE lprFindEnd (EPS_SOCKET );
+extern EPS_ERR_CODE lprProbePrinterByID (EPS_INT8*, EPS_UINT32, EPS_PRINTER_INN** );
+
+/* Job Functions */
+extern EPS_ERR_CODE lprStartJob (void );
+extern EPS_ERR_CODE lprEndJob (void );
+extern EPS_ERR_CODE lprRestartJob (void );
+extern EPS_ERR_CODE lprWritePrintData (const EPS_UINT8*, EPS_UINT32, EPS_UINT32* );
+extern EPS_ERR_CODE lprResetPrinter (void );
+extern EPS_ERR_CODE lprStartPage (void );
+extern EPS_ERR_CODE lprEndPage (void );
+extern EPS_ERR_CODE lprMechCommand (const EPS_PRINTER_INN*, EPS_INT32 );
+
+/* Printer status Functions */
+extern EPS_ERR_CODE lprGetStatus (EPS_STATUS_INFO*, EPS_BOOL*, EPS_BOOL* );
+extern EPS_ERR_CODE lprGetInkInfo (EPS_STATUS_INFO* );
+extern EPS_ERR_CODE lprGetJobStatus (EPS_STATUS_INFO* );
+extern EPS_ERR_CODE lprGetPMString (const EPS_PRINTER_INN*, EPS_INT32,
+ EPS_UINT8*, EPS_INT32* );
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* def __EPSON_NET_LPR_H__ */
+
+/*_______________________________ epson-net-lpr.h ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-net-raw.c b/lib/epson-net-raw.c
new file mode 100644
index 0000000..e22c8a0
--- /dev/null
+++ b/lib/epson-net-raw.c
@@ -0,0 +1,937 @@
+/*________________________________ epson-net-raw.c _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Raw Port protocol Module */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE rawFindStart (sock, address, flg ); */
+/* EPS_ERR_CODE rawFind (sock, printer ); */
+/* EPS_ERR_CODE rawFindEnd (sock ); */
+/* EPS_ERR_CODE rawProbePrinterByID(printerUUID, timeout, printer ); */
+/* EPS_ERR_CODE rawStartJob (printr ); */
+/* EPS_ERR_CODE rawEndPage ( ); */
+/* EPS_ERR_CODE rawResetPrinter ( ); */
+/* EPS_ERR_CODE rawWritePrintData (buffer, bufferlen, sendlen ); */
+/* EPS_ERR_CODE rawGetStatus (printer, status, ioStatus ); */
+/* EPS_ERR_CODE rawGetJobStatus (pstInfo ); */
+/* EPS_ERR_CODE rawGetPMString (printer, pString, bufSize ); */
+/* EPS_ERR_CODE rawMechCommand (printer, Command ); */
+/* */
+/*******************************************|********************************************/
+
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-def.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpr-services.h"
+#include "epson-protocol.h"
+#include "epson-net-snmp.h"
+#include "epson-net-raw.h"
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_RAW
+#define EPS_LOG_MODULE EPS_LOG_MODULE_RAW
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+#define RAW_PORT_NUM (9100) /* Protocol port number */
+
+#define IS_JOB_ACTIVE \
+ ( (NULL != printJob.printer) && (NULL != printJob.hProtInfo) \
+ && (EPS_PROTOCOL_RAW == EPS_PRT_PROTOCOL(printJob.printer->protocol)) )
+
+#define IS_VALID_DATA_SESSION \
+ ( (NULL != printJob.printer) && (NULL != printJob.hProtInfo) \
+ && (EPS_PROTOCOL_RAW == EPS_PRT_PROTOCOL(printJob.printer->protocol)) \
+ && (EPS_INVALID_SOCKET != ((EPS_PRINT_JOB_RAW*)printJob.hProtInfo)->socData) )
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+extern EPS_NET_FUNC epsNetFnc;
+extern EPS_CMN_FUNC epsCmnFnc;
+
+ /*** Print Job Structure */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_PRINT_JOB printJob;
+
+static EPS_SNMP_FUNCS snmp;
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagEPS_PRINT_JOB_RAW_ {
+ EPS_SOCKET socData; /* RAW socket for send data */
+ EPS_SOCKET socStat; /* SNMP socket for check status */
+ EPS_BOOL reseted; /* reseted */
+ EPS_BOOL pageend; /* page end - start */
+} EPS_PRINT_JOB_RAW;
+
+/*-------------------------------- RAW Local Variables -------------------------------*/
+/*******************************************|********************************************/
+
+/*-------------------------- Local Functions Declaration ----------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE StartDataSession (EPS_PRINT_JOB_RAW*, const EPS_PRINTER_INN* );
+static EPS_ERR_CODE EndDataSession (EPS_PRINT_JOB_RAW* );
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+void rawSetupSTFunctions (
+
+ const EPS_PRINTER_INN* printer
+
+){
+ EPS_LOG_FUNCIN
+
+ snmpSetupSTFunctions(&snmp, printer);
+
+ EPS_RETURN_VOID
+}
+
+
+EPS_UINT16 rawGetDefautiPort (
+
+ void
+
+){
+ return RAW_PORT_NUM;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawFindStart() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET* O: send discovery message socket */
+/* address EPS_INT8* I: Destination address */
+/* multi EPS_BOOL I: If TRUE, send multicast */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Sends EPSNET_NUM_DISCOVERIES number of upnp discovery message to find */
+/* devices. Discovery message is sent more than once because udp is unreliable. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawFindStart(
+
+ EPS_SOCKET* sock,
+ const EPS_INT8* address,
+ EPS_BOOL multi
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpFindStart(sock, address, multi) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawFind() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: Discover Socket */
+/* printer EPS_PRINTER_INN** O: pointer for found printer structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - socket error */
+/* EPS_ERR_MEMORY_ALLOCATION */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
+/* */
+/* Description: */
+/* Receive discover messasge. Get printer name. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawFind (
+
+ EPS_SOCKET sock,
+ EPS_PRINTER_INN** printer
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpFind(sock, RAW_PORT_NUM, EPS_PROTOCOL_RAW, printer) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawFindEnd() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: Discover Socket */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Close socket failed */
+/* */
+/* Description: */
+/* close discover process. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawFindEnd (
+
+ EPS_SOCKET sock
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpFindEnd(sock) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawProbePrinterByID() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* defstr EPS_INT8* I: ID String of probe target */
+/* timeout EPS_UINT32 I: find timeout */
+/* printer EPS_PRINTER* O: Pointer for Alloc Printer infomation structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - socket failed */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* */
+/* Description: */
+/* Probe printer by ID String. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawProbePrinterByID (
+
+ EPS_INT8* printerUUID,
+ EPS_UINT32 timeout,
+ EPS_PRINTER_INN** printer
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmpProbeByID(printerUUID, RAW_PORT_NUM, EPS_PROTOCOL_RAW, timeout, printer) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawStartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: pointer to printer Structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* Description: */
+/* Open socekt & Send start job messasge. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawStartJob(
+
+ void
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINT_JOB_RAW *rawPrintJob = NULL;
+
+ EPS_LOG_FUNCIN
+
+ /* Alloc RAW Job Data */
+ rawPrintJob = (EPS_PRINT_JOB_RAW*)EPS_ALLOC( sizeof(EPS_PRINT_JOB_RAW) );
+ if( NULL == rawPrintJob ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+ memset(rawPrintJob, 0, sizeof(EPS_PRINT_JOB_RAW));
+ rawPrintJob->socStat = rawPrintJob->socData = EPS_INVALID_SOCKET;
+ rawPrintJob->reseted = FALSE;
+ rawPrintJob->pageend = FALSE;
+
+ /* Establish Connection & send start job message */
+ ret = StartDataSession( rawPrintJob, printJob.printer );
+
+ if( EPS_ERR_NONE == ret
+ && EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ /* create check status */
+ ret = snmpOpenSocket( &(rawPrintJob->socStat) );
+ if( EPS_ERR_NONE != ret ){
+ goto rawStartJob_END;
+ }
+ }
+
+ printJob.hProtInfo = (EPS_HANDLE)rawPrintJob;
+
+rawStartJob_END:
+
+ if( EPS_ERR_NONE != ret ){
+ if( EPS_INVALID_SOCKET != rawPrintJob->socStat ){
+ snmpCloseSocket( &rawPrintJob->socStat );
+ }
+
+ if( EPS_INVALID_SOCKET != rawPrintJob->socData ){
+ epsNetFnc.close( rawPrintJob->socData );
+ rawPrintJob->socData = EPS_INVALID_SOCKET;
+ }
+ EPS_SAFE_RELEASE( rawPrintJob );
+
+ printJob.hProtInfo = NULL;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawRestartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Open socekt & Send start job messasge. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawRestartJob(
+
+ void
+
+){
+ EPS_PRINT_JOB_RAW *rawPrintJob = (EPS_PRINT_JOB_RAW*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == rawPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /* Establish Connection & send start job message */
+ EPS_RETURN( StartDataSession( rawPrintJob, printJob.printer ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawWritePrintData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* buffer EPS_UINT8* I: Print data */
+/* bufferlen EPS_INT32 I: Print data length */
+/* sendlen EPS_INT32* O: Sended length */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Called from epsPrintBand, Send ESC/P-R data. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawWritePrintData(
+
+ const EPS_UINT8* buffer,
+ EPS_UINT32 bufferlen,
+ EPS_UINT32* sendlen
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINT_JOB_RAW* rawPrintJob = (EPS_PRINT_JOB_RAW*)printJob.hProtInfo;
+ EPS_UINT32 timeout;
+ EPS_INT32 sentSize = 0;
+
+ EPS_LOG_FUNCIN
+
+ if( !rawPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /* Send ESC/P-R data */
+ timeout = (EPS_UINT32)((EPS_IS_BI_PROTOCOL(printJob.printer->protocol))?EPSNET_BAND_SEND_TIMEOUT:EPSNET_BAND_SEND_TIMEOUTL);
+
+ sentSize = epsNetFnc.send(rawPrintJob->socData, (char*)buffer, (EPS_INT32)bufferlen, timeout);
+
+ if( EPS_SOCKET_ERROR == sentSize ){
+ *sendlen = 0;
+ ret = EPS_ERR_COMM_ERROR;
+ } else if( EPS_SOCKET_TIMEOUT == sentSize ){
+ *sendlen = 0;
+ ret = EPS_COM_TINEOUT;
+ } else{
+ *sendlen = (EPS_UINT32)sentSize;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawEndJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* */
+/* Description: */
+/* Send endjob messasge & Close connection. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawEndJob()
+{
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINT_JOB_RAW* rawPrintJob = (EPS_PRINT_JOB_RAW*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( !rawPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /* Close SendData Session */
+ EndDataSession(rawPrintJob);
+
+ if( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ snmpCloseSocket( &rawPrintJob->socStat );
+ }
+
+ EPS_SAFE_RELEASE( printJob.hProtInfo );
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawResetPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* */
+/* Description: */
+/* Send endjob messasge & Close connection. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawResetPrinter(
+
+ void
+
+){
+ EPS_PRINT_JOB_RAW* rawPrintJob = (EPS_PRINT_JOB_RAW*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == printJob.hProtInfo || NULL == printJob.printer){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+/*** If we already successfully called this function once for a given print job, */
+ if(printJob.resetSent != EPS_RESET_SENT
+ && FALSE != printJob.transmittable
+ && TRUE == printJob.sendJS ){
+ rawMechCommand(printJob.printer, EPS_CBTCOM_RJ);
+ }
+
+ rawPrintJob->reseted = TRUE;
+
+ /* Close SendData Session */
+ EPS_RETURN( EndDataSession(rawPrintJob) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawStartPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Open socekt & Send start job messasge. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawStartPage(
+
+ void
+
+){
+ EPS_PRINT_JOB_RAW *rawPrintJob = (EPS_PRINT_JOB_RAW*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == rawPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ ((EPS_PRINT_JOB_RAW*)printJob.hProtInfo)->pageend = FALSE;
+
+ /* Establish Connection & send start job message */
+ EPS_RETURN( StartDataSession( rawPrintJob, printJob.printer ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawEndPage() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* */
+/* Description: */
+/* Send endjob messasge & Close connection. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawEndPage(
+
+ void
+
+){
+ EPS_PRINT_JOB_RAW *rawPrintJob = (EPS_PRINT_JOB_RAW*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN
+
+ if( NULL == printJob.hProtInfo ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ rawPrintJob->pageend = TRUE;
+
+ /* Close SendData Session */
+ EPS_RETURN( EndDataSession(rawPrintJob) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawGetStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Printer data structure */
+/* status EPS_STATUS_INFO* O: retrieve printer satus */
+/* ioStatus EPS_INT32* O: It is possible to communicate */
+/* canceling EPS_BOOL* O: Cancel processing */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get Printer status by SNMP. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawGetStatus(
+
+ EPS_STATUS_INFO* pstInfo,
+ EPS_BOOL* pIoStatus,
+ EPS_BOOL* pCancelling
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINTER_INN* printer = printJob.printer;
+ EPS_SOCKET sock = EPS_INVALID_SOCKET;
+
+ EPS_LOG_FUNCIN
+
+ if( !EPS_IS_BI_PROTOCOL(printer->protocol) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+ memset(pstInfo, -1, sizeof(EPS_STATUS_INFO));
+
+ /*** Get Printer status by SNMP */
+ ret = snmpOpenSocket( &sock );
+ if( EPS_ERR_NONE != ret ){
+ EPS_RETURN( ret )
+ }
+
+ ret = snmp.GetStatus(sock, printer->location, pstInfo );
+
+ if( !IS_VALID_DATA_SESSION ){
+ /* Another proceessing, or printing after endjob */
+ if( EPS_ST_WAITING == pstInfo->nState
+ && EPS_PRNERR_NOERROR == pstInfo->nError){
+ pstInfo->nState = EPS_ST_ERROR;
+ pstInfo->nError = EPS_PRNERR_BUSY;
+ }
+ }
+
+ if(NULL != pIoStatus && NULL != pCancelling){
+ if(EPS_ERR_NONE == ret){
+ if( IS_VALID_DATA_SESSION || pstInfo->nState == EPS_ST_IDLE ||
+ (IS_JOB_ACTIVE && ((EPS_PRINT_JOB_RAW*)printJob.hProtInfo)->pageend) ){
+ *pIoStatus = TRUE;
+ } else{
+ *pIoStatus = FALSE;
+ }
+
+ if( IS_JOB_ACTIVE ){
+ if( TRUE == ((EPS_PRINT_JOB_RAW*)printJob.hProtInfo)->reseted ){
+ if(EPS_ST_IDLE == pstInfo->nState){
+ /* cancel finished */
+ *pCancelling = FALSE;
+ ((EPS_PRINT_JOB_RAW*)printJob.hProtInfo)->reseted = FALSE;
+ } else{
+ /* cancelling */
+ *pCancelling = TRUE;
+ }
+ } else if( pstInfo->nCancel == EPS_CAREQ_CANCEL ){
+ /* cancel request from printer */
+ *pCancelling = TRUE;
+ } else{
+ *pCancelling = FALSE;
+ }
+ } else{
+ *pCancelling = FALSE;
+ }
+ } else{
+ *pIoStatus = FALSE;
+ *pCancelling = FALSE;
+ }
+ }
+
+ snmpCloseSocket( &sock );
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawGetJobStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pstInfo EPS_STATUS_INFO* O: retrieve printer satus */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get Printer status by SNMP. It is possible to use in Job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawGetJobStatus(
+
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_PRINT_JOB_RAW* rawPrintJob = (EPS_PRINT_JOB_RAW*)printJob.hProtInfo;
+ EPS_PRINTER_INN* printer = (EPS_PRINTER_INN*)printJob.printer;
+
+ EPS_LOG_FUNCIN
+
+ /* Initialize variables */
+ memset(pstInfo, 0, sizeof(EPS_STATUS_INFO));
+
+ if( !rawPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED )
+ }
+
+ /*** Get Printer status by SNMP */
+ EPS_RETURN( snmp.GetStatus( rawPrintJob->socStat, printer->location, pstInfo ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawGetInkInfo() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* status EPS_STATUS_INFO* O: retrieve printer satus */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get Ink information. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawGetInkInfo(
+
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_PRINTER_INN* printer = printJob.printer;
+
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmp.GetInkInfo(printer->location, pstInfo ) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawGetPMString() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
+/* pString EPS_UINT8* O: Pointer to PM String */
+/* bufSize EPS_INT32 I: pString buffer size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* */
+/* Description: */
+/* Sends request to printer for supported media. Parses response and stores */
+/* PM String : pString */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawGetPMString(
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 type,
+ EPS_UINT8* pString,
+ EPS_INT32* bufSize
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmp.GetPMString(printer, type, pString, bufSize) )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: rawMechCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Command EPS_INT32 I: Command Code */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Mech command executed successfully */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Mech command execution error */
+/* */
+/* Description: */
+/* Sends mechanincal commands to the printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE rawMechCommand (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 Command
+
+){
+ EPS_LOG_FUNCIN
+ EPS_RETURN( snmp.MechCommand(printer, Command) )
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: StartDataSession() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* rawPrintJob EPS_PRINT_JOB_RAW* O : RAW Job information */
+/* printer EPS_PRINTER_INN* I : target printer information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Starts a print job. Establish Connection, Send StartJob message. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE StartDataSession(
+
+ EPS_PRINT_JOB_RAW* rawPrintJob,
+ const EPS_PRINTER_INN* printer
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+
+ EPS_LOG_FUNCIN
+
+ if(EPS_INVALID_SOCKET != rawPrintJob->socData){
+ /* Already established */
+ EPS_RETURN( EPS_ERR_NONE )
+ }
+
+ /* Check status */
+ if( EPS_IS_BI_PROTOCOL(printer->protocol) ){
+ EPS_STATUS_INFO stInfo;
+ ret = rawGetStatus(&stInfo, NULL, NULL);
+ if(EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ } else if(stInfo.nState != EPS_ST_IDLE){
+ EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR )
+ }
+ }
+
+ /* create socket */
+ rawPrintJob->socData = epsNetFnc.socket(EPS_PF_INET, EPS_SOCK_STREAM, EPS_PROTOCOL_TCP);
+ if( EPS_INVALID_SOCKET == rawPrintJob->socData ){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ /* connect to printer */
+ if(EPS_SOCKET_SUCCESS != epsNetFnc.connect(rawPrintJob->socData, printer->location, printer->printPort)){
+ EPS_DBGPRINT(("StartDataSession ERR\n"));
+ ret = EPS_ERR_COMM_ERROR;
+ goto StartDataSession_END;
+ }
+
+ rawPrintJob->reseted = FALSE;
+ rawPrintJob->pageend = FALSE;
+ /*printJob.hProtInfo = (EPS_HANDLE)rawPrintJob;*/
+
+StartDataSession_END:
+ if( EPS_ERR_NONE != ret ){
+ if( EPS_INVALID_SOCKET != rawPrintJob->socData ){
+ epsNetFnc.close( rawPrintJob->socData );
+ rawPrintJob->socData = EPS_INVALID_SOCKET;
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: EndDataSession() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* rawPrintJob EPS_PRINT_JOB_RAW* IO : RAW Job information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Send EndJob line to printer, shutdown/close socket. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE EndDataSession(
+
+ EPS_PRINT_JOB_RAW* rawPrintJob
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Used for error handling */
+
+ EPS_LOG_FUNCIN
+
+ if( EPS_INVALID_SOCKET != rawPrintJob->socData){
+ /*** If we already successfully called this function once for a given print job, */
+ epsNetFnc.shutdown(rawPrintJob->socData, EPS_SHUTDOWN_SEND);
+ epsNetFnc.shutdown(rawPrintJob->socData, EPS_SHUTDOWN_RECV);
+ epsNetFnc.shutdown(rawPrintJob->socData, EPS_SHUTDOWN_BOTH);
+
+ ret = epsNetFnc.close(rawPrintJob->socData);
+ rawPrintJob->socData = EPS_INVALID_SOCKET;
+ }
+
+ EPS_RETURN( ret )
+}
+/*_______________________________ epson-net-raw.c ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
diff --git a/lib/epson-net-raw.h b/lib/epson-net-raw.h
new file mode 100644
index 0000000..5d58ec4
--- /dev/null
+++ b/lib/epson-net-raw.h
@@ -0,0 +1,74 @@
+/*_________________________________ epson-net-raw.h ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+* Copyright (c) 2010 Seiko Epson Corporation All rights reserved.
+*
+* Copyright protection claimed includes all forms and matters of
+* copyrightable material and information now allowed by statutory or judicial
+* law or hereinafter granted, including without limitation, material generated
+* from the software programs which are displayed on the screen such as icons,
+* screen display looks, etc.
+*
+*/
+/*******************************************|********************************************/
+/* */
+/* Epson Raw Port Protocol Definitions */
+/* */
+/*******************************************|********************************************/
+
+#ifndef __EPSON_NET_RAW_H__
+#define __EPSON_NET_RAW_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+/*---------------------------- API Function Declarations ----------------------------*/
+/*******************************************|********************************************/
+/* Initialize */
+extern void rawSetupSTFunctions (const EPS_PRINTER_INN* );
+extern EPS_UINT16 rawGetDefautiPort (void );
+
+/* Discovery message related Functions */
+extern EPS_ERR_CODE rawFindStart (EPS_SOCKET*, const EPS_INT8*, EPS_BOOL );
+extern EPS_ERR_CODE rawFind (EPS_SOCKET, EPS_PRINTER_INN** );
+extern EPS_ERR_CODE rawFindEnd (EPS_SOCKET );
+extern EPS_ERR_CODE rawProbePrinterByID (EPS_INT8*, EPS_UINT32, EPS_PRINTER_INN** );
+
+/* Job Functions */
+extern EPS_ERR_CODE rawStartJob (void );
+extern EPS_ERR_CODE rawEndJob (void );
+extern EPS_ERR_CODE rawRestartJob (void );
+extern EPS_ERR_CODE rawWritePrintData (const EPS_UINT8*, EPS_UINT32, EPS_UINT32* );
+extern EPS_ERR_CODE rawResetPrinter (void );
+extern EPS_ERR_CODE rawStartPage (void );
+extern EPS_ERR_CODE rawEndPage (void );
+extern EPS_ERR_CODE rawMechCommand (const EPS_PRINTER_INN*, EPS_INT32 );
+
+/* Printer status Functions */
+extern EPS_ERR_CODE rawGetStatus (EPS_STATUS_INFO*, EPS_BOOL*, EPS_BOOL* );
+extern EPS_ERR_CODE rawGetInkInfo (EPS_STATUS_INFO* );
+extern EPS_ERR_CODE rawGetJobStatus (EPS_STATUS_INFO* );
+extern EPS_ERR_CODE rawGetPMString (const EPS_PRINTER_INN*, EPS_INT32,
+ EPS_UINT8*, EPS_INT32* );
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* def __EPSON_NET_RAW_H__ */
+
+/*_________________________________ epson-net-raw.h ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-net-snmp.c b/lib/epson-net-snmp.c
new file mode 100644
index 0000000..ea10cf3
--- /dev/null
+++ b/lib/epson-net-snmp.c
@@ -0,0 +1,2776 @@
+/*________________________________ epson-net-snmp.c ________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* SNMP protocol Module */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE snmpFindStart (sock ); */
+/* EPS_ERR_CODE snmpFind (sock, printer ); */
+/* EPS_ERR_CODE snmpFindEnd (sock ); */
+/* EPS_ERR_CODE snmpProbeByID (printerUUID, timeout, printer ); */
+/* EPS_ERR_CODE snmpGetStatus (sock, address, pstInfo ); */
+/* EPS_ERR_CODE snmpGetPMString (printer, pString, bufSize ); */
+/* EPS_ERR_CODE snmpMechCommand (printer, Command ); */
+/* EPS_ERR_CODE snmpOpenSocket (sock ); */
+/* EPS_ERR_CODE snmpCloseSocket (sock ); */
+/* EPS_ERR_CODE mibGetPhysAddress (address, val, vallen ); */
+/* EPS_ERR_CODE mibConfirmPrintPort (address, printPort ); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-def.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-mem.h"
+#include "epson-escpr-services.h"
+#include "epson-protocol.h"
+#include "epson-net-snmp.h"
+#ifdef GCOMSW_CMD_ESCPAGE
+ #include "epson-escpr-media.h"
+
+ #ifdef GCOMSW_CMD_ESCPAGE_S
+ #include "epson-escpage-s.h"
+ #endif
+#endif
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_LPR
+#define EPS_LOG_MODULE EPS_LOG_MODULE_LPR
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+#define SNMP_PORT_NUM (161) /* Protocol port number */
+#define SNMP_MAX_BUF (512) /* Communication buffer size */
+#define SNMP_MAX_OID (128) /* max oid size */
+
+/* SNMP variables */
+#define ASN_VT_INTEGER (0x02) /* integer */
+#define ASN_VT_OCTET_STRING (0x04) /* octet stream */
+#define ASN_VT_NULL (0x05) /* null */
+#define ASN_VT_OBJECT_ID (0x06) /* OID */
+#define ASN_VT_SEQUENCE (0x30) /* sequence */
+
+/* SNMP message */
+#define ASN_PDU_GET (EPS_UINT8)(0xA0) /* GetRequest */
+#define ASN_PDU_GET_NEXT (EPS_UINT8)(0xA1) /* GetNextRequest */
+#define ASN_PDU_RESP (EPS_UINT8)(0xA2) /* Response */
+#define ASN_PDU_SET (EPS_UINT8)(0xA3) /* SetRequest */
+#define ASN_PDU_TRAP (EPS_UINT8)(0xA4) /* Trap */
+#define ASN_PDU_TRAP_RSP (EPS_UINT8)(0xC2) /* TrapResponse */
+
+
+#define SNMP_VERSION (0)
+#define SNMP_COMMUNITY_STR "public"
+/* Response corde */
+#define SNMP_ERR_NONE (0) /* noError(0) */
+#define SNMP_ERR_TOO_BIG (1) /* tooBig(1) */
+#define SNMP_ERR_SUCH_NAME (2) /* noSuchName(2) */
+#define SNMP_ERR_BAD_VALUE (3) /* badValue(3) */
+#define SNMP_ERR_READ_ONLY (4) /* readOnly(4) */
+#define SNMP_ERR_GENERAL (5) /* genErr(5) */
+
+#define SNMP_OBJID_LEN (129)
+
+/* MIB status */
+ /* hrDeviceStatus */
+#define MIB_DEVST_RUNNING (2)
+#define MIB_DEVST_WARNING (3)
+#define MIB_DEVST_DOWN (5)
+ /* hrPrinterStatus */
+#define MIB_PRNST_OTHER (1)
+#define MIB_PRNST_IDLE (3)
+#define MIB_PRNST_PRINTING (4)
+#define MIB_PRNST_WARMUP (5)
+ /* hrPrinterDetectedErrorState */
+#define MIB_PRERR_NOPAPER (1 << 6)
+#define MIB_PRERR_NOINK (1 << 4)
+#define MIB_PRERR_COVEROPEN (1 << 3)
+#define MIB_PRERR_PAPERJAM (1 << 2)
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+/* SNMP variant type */
+typedef struct tag_ASN_VARIANT {
+ EPS_INT8 type;
+ EPS_UINT32 length;
+ union{
+ EPS_INT32 v_long; /* Integer */
+ EPS_INT8* v_str; /* OCTET_STRING, ASN_VT_OBJECT_ID */
+ } val;
+}ASN_VARIANT;
+
+/* If type is OBJECT_ID, ParseField() alloc heap. */
+#define EPS_REREASE_VARIANT( v ) \
+ { \
+ if( ASN_VT_OBJECT_ID == (v).type ){ \
+ EPS_SAFE_RELEASE( (v).val.v_str ); \
+ } \
+ (v).type = ASN_VT_NULL; \
+ }
+
+
+/*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+extern EPS_NET_FUNC epsNetFnc;
+extern EPS_CMN_FUNC epsCmnFnc;
+
+ /*** Find */
+extern EPS_BOOL g_FindBreak; /* Find printer end flag */
+
+ /* CPU Endian-ness */
+extern EPS_INT16 cpuEndian;
+
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1)
+ interfaces(2) ifTable(2) ifEntry(1) 6 } */
+static EPS_INT8 s_oidPhysAddress[] = "1.3.6.1.2.1.2.2.1.6";
+
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1)
+ tcp(6) tcpConnTable(13) tcpConnEntry(1) 3 } */
+static EPS_INT8 s_oidTcpConnLocalPort[]= "1.3.6.1.2.1.6.13.1.3";
+
+
+#ifdef GCOMSW_CMD_ESCPAGE
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1)
+ host(25) hrDevice(3) hrDeviceTable(2) hrDeviceEntry(1) hrDeviceStatus(5) } */
+static EPS_INT8 s_oidDevStatus[] = "1.3.6.1.2.1.25.3.2.1.5";
+
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1)
+ host(25) hrDevice(3) hrPrinterTable(5) hrPrinterEntry(1) hrPrinterStatus(1) } */
+static EPS_INT8 s_oidPrinterStatus[]= "1.3.6.1.2.1.25.3.5.1.1";
+
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1)
+ host(25) hrDevice(3) hrPrinterTable(5) hrPrinterEntry(1) hrPrinterDetectedErrorState(2) } */
+static EPS_INT8 s_oidPrinterError[] = "1.3.6.1.2.1.25.3.5.1.2";
+
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) printmib(43) prtMarkerColorant(12)
+ prtMarkerColorantTable(1) prtMarkerColorantEntry(1) 4 } */
+static EPS_INT8 s_oidMarkerColorant[] = "1.3.6.1.2.1.43.12.1.1.4";
+
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1)
+ printmib(43) prtMarkerSupplies(11) prtMarkerSuppliesTable(1) prtMarkerSuppliesEntry(1)
+ prtMarkerSuppliesLevel(9) } */
+static EPS_INT8 s_oidMarkerLevel[] = "1.3.6.1.2.1.43.11.1.1.9";
+
+/* { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1)
+ printmib(43) prtInput(8) prtInputTable(2) prtInputEntry(1) prtInputName(13) } */
+static EPS_INT8 s_oidInputName[] = "1.3.6.1.2.1.43.8.2.1.13";
+#endif
+
+static EPS_INT8 s_oidPrvPrinter[] = "1.3.6.1.4.1.1248.1.2.2.1.1.1.1";
+static EPS_INT8 s_oidPrvBonjourName[] = "1.3.6.1.4.1.1248.1.1.3.1.14.4.1.2";
+static EPS_INT8 s_oidPrvStatus[] = "1.3.6.1.4.1.1248.1.2.2.1.1.1.4";
+static EPS_INT8 s_oidPrvCtrl[] = "1.3.6.1.4.1.1248.1.2.2.44.1.1.2";
+
+static EPS_INT8 g_TrnBuff[SNMP_MAX_BUF];
+
+
+/*-------------------------- Public Functions Declaration ---------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE snmpGetStatus (EPS_SOCKET, const EPS_INT8*, EPS_STATUS_INFO* );
+static EPS_ERR_CODE snmpGetInkInfo (const EPS_INT8*, EPS_STATUS_INFO* );
+static EPS_ERR_CODE snmpGetPMString (const EPS_PRINTER_INN*, EPS_INT32,
+ EPS_UINT8*, EPS_INT32* );
+static EPS_ERR_CODE snmpMechCommand (const EPS_PRINTER_INN*, EPS_INT32 );
+#ifdef GCOMSW_CMD_ESCPAGE
+static EPS_ERR_CODE snmpGetStatus_Page(EPS_SOCKET, const EPS_INT8*, EPS_STATUS_INFO* );
+static EPS_ERR_CODE snmpGetInkInfo_Page(const EPS_INT8*, EPS_STATUS_INFO* );
+static EPS_ERR_CODE snmpGetPMString_Page(const EPS_PRINTER_INN*, EPS_INT32,
+ EPS_UINT8*, EPS_INT32* );
+static EPS_ERR_CODE snmpMechCommand_Page(const EPS_PRINTER_INN*, EPS_INT32 );
+#endif
+
+/*-------------------------- Local Functions Declaration ----------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE SnmpTransact (const EPS_INT8*, EPS_INT32, const EPS_INT8*,
+ EPS_UINT8, ASN_VARIANT* pdu );
+static EPS_ERR_CODE SnmpTransactS (EPS_SOCKET, const EPS_INT8*, EPS_INT32,
+ const EPS_INT8*, EPS_UINT8, ASN_VARIANT* );
+
+static EPS_ERR_CODE SnmpFindRecv (EPS_SOCKET, EPS_UINT16, EPS_INT32,
+ const EPS_INT8*, const EPS_INT8*, EPS_PRINTER_INN**);
+
+static EPS_ERR_CODE mibGetPhysAddress(const EPS_INT8*, EPS_INT8*, EPS_UINT32 );
+static EPS_ERR_CODE mibConfirmPrintPort(const EPS_INT8*, EPS_UINT16 );
+#ifdef GCOMSW_CMD_ESCPAGE_S
+static EPS_ERR_CODE mibGetMaxMediaXFeedDir(const EPS_INT8* address, EPS_UINT32* val );
+#endif
+static EPS_ERR_CODE GetPDU (EPS_INT8*, EPS_INT32, EPS_UINT8, const EPS_INT8*,
+ ASN_VARIANT*, EPS_INT8*, EPS_INT32 );
+
+#ifdef GCOMSW_CMD_ESCPAGE
+static EPS_INT32 GetColorID (EPS_INT8* );
+#endif
+static EPS_ERR_CODE SnmpWalkMib (EPS_SOCKET, const EPS_INT8*, const EPS_INT8*, ASN_VARIANT*);
+static EPS_UINT8 GetRequestId (void );
+static EPS_ERR_CODE ParseLength (EPS_INT8**, EPS_INT32*, EPS_UINT32* );
+static EPS_ERR_CODE ParseField (EPS_INT8**, EPS_INT32*, ASN_VARIANT* );
+
+static EPS_ERR_CODE CreateCommand (EPS_INT8*, EPS_UINT8, EPS_UINT8, const EPS_INT8*, EPS_INT32*);
+static EPS_INT8* MakeLength (EPS_INT32, EPS_INT8* );
+static EPS_INT8* MakeIntField (EPS_INT32, EPS_INT8* );
+static EPS_INT8* MakeStrField (const EPS_INT8*, EPS_INT8* );
+static EPS_ERR_CODE MakeOidField (const EPS_INT8*, EPS_INT8** );
+static EPS_ERR_CODE MakeSequens (EPS_INT8*, EPS_UINT32*, EPS_BOOL );
+
+static EPS_UINT16 IntToBer (EPS_INT32, EPS_INT8* );
+static EPS_INT32 BerToInt (EPS_INT8*, EPS_INT32 );
+static EPS_ERR_CODE StrToOid (const EPS_INT8*, EPS_INT8*, EPS_UINT16* );
+static EPS_ERR_CODE OidToStr (EPS_INT8*, EPS_UINT32, EPS_INT8** );
+
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpSetupSTFunctions() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Opened Communication) */
+/* */
+/* Description: */
+/* Initialize protocol layer. */
+/* */
+/*******************************************|********************************************/
+void snmpSetupSTFunctions (
+
+ EPS_SNMP_FUNCS* fnc,
+ const EPS_PRINTER_INN* printer
+
+){
+ EPS_LOG_FUNCIN
+
+#ifdef GCOMSW_CMD_ESCPAGE
+ if( EPS_LANG_ESCPR != printer->language ){
+ fnc->GetStatus = snmpGetStatus_Page;
+ fnc->GetInkInfo = snmpGetInkInfo_Page;
+ fnc->GetPMString = snmpGetPMString_Page;
+ fnc->MechCommand = snmpMechCommand_Page;
+ }
+ else
+#endif
+ {
+ fnc->GetStatus = snmpGetStatus;
+ fnc->GetInkInfo = snmpGetInkInfo;
+ fnc->GetPMString = snmpGetPMString;
+ fnc->MechCommand = snmpMechCommand;
+ }
+
+ EPS_RETURN_VOID
+}
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpOpenSocket() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET* O: SNMP socket */
+/* */
+/* Return value: */
+/* EPS_ERR_CODE : result code */
+/* */
+/* Description: */
+/* Create SNMP socket for any command. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpOpenSocket(
+
+ EPS_SOCKET* sock
+
+){
+ *sock = epsNetFnc.socket( EPS_PF_INET, EPS_SOCK_DGRAM, EPS_PROTOCOL_UDP );
+ if( EPS_INVALID_SOCKET == *sock ){
+ return EPS_ERR_COMM_ERROR;
+ }
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpCloseSocket() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET* I/O: SNMP socket */
+/* */
+/* Return value: */
+/* (none) */
+/* */
+/* Description: */
+/* Destory SNMP socket. */
+/* */
+/*******************************************|********************************************/
+void snmpCloseSocket(
+
+ EPS_SOCKET* sock
+
+){
+ if(EPS_INVALID_SOCKET != *sock){
+ epsNetFnc.close( *sock );
+ *sock = EPS_INVALID_SOCKET;
+ }
+}
+
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpFindStart() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET O: Discover send/recv Socket */
+/* address EPS_INT8* I: Destination IP Address string (NULL terminate) */
+/* multi EPS_BOOL I: If TRUE, send multicast */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR */
+/* */
+/* Description: */
+/* Open socekt & Send discover messasge. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpFindStart (
+
+ EPS_SOCKET* sock,
+ const EPS_INT8* address,
+ EPS_BOOL multi
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT8 nRqID = 0;
+ EPS_INT32 nSize = 0;
+ ASN_VARIANT pdu;
+
+ EPS_INT32 i = 0; /* Temporary counter for number of discoveries */
+
+ EPS_LOG_FUNCIN
+
+ /* Create UDP broadcast socket */
+ if(EPS_INVALID_SOCKET == *sock){ /* First Time */
+ *sock = epsNetFnc.socket( EPS_PF_INET, EPS_SOCK_DGRAM, EPS_PROTOCOL_UDP );
+ if( EPS_INVALID_SOCKET == *sock ){
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+
+ if(multi){
+ if( EPS_SOCKET_SUCCESS != epsNetFnc.setBroadcast(*sock) ){
+ /* If error occurr, close socket */
+ epsNetFnc.close( *sock );
+ *sock = EPS_INVALID_SOCKET;
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+ }
+ }
+
+ /* Create command */
+ memset(&pdu, 0, sizeof(pdu));
+ nRqID = GetRequestId();
+ if( EPS_ERR_NONE != (ret = CreateCommand(g_TrnBuff, ASN_PDU_GET_NEXT, nRqID,
+ s_oidPrvPrinter, &nSize)) ){
+ EPS_RETURN( ret )
+ }
+
+ /* Send */
+ for (i = 0; i < EPSNET_NUM_DISCOVERIES; i++) {
+ if ( 0 >= epsNetFnc.sendTo(*sock, (char*)g_TrnBuff, nSize,
+ address, SNMP_PORT_NUM, 0)){
+ /* If error occurr, close socket */
+ epsNetFnc.close( *sock );
+ *sock = EPS_INVALID_SOCKET;
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpFind() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: Discover Socket */
+/* printer EPS_PRINTER_INN** O: pointer for found printer structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - socket error */
+/* EPS_ERR_MEMORY_ALLOCATION */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
+/* */
+/* Description: */
+/* Receive discover messasge. Get printer name. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpFind(
+
+ EPS_SOCKET sock,
+ EPS_UINT16 printPort,
+ EPS_INT32 printProtocol,
+ EPS_PRINTER_INN** printer
+
+){
+ EPS_LOG_FUNCIN
+
+ EPS_RETURN( SnmpFindRecv(sock, printPort, printProtocol, NULL, NULL, printer) )
+}
+
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpFindEnd() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: Discover Socket */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Close socket failed */
+/* */
+/* Description: */
+/* close discover process. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpFindEnd(
+
+ EPS_SOCKET sock
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 *pRecvBuf = NULL; /* Receive Buffer */
+
+EPS_LOG_FUNCIN
+ if(EPS_INVALID_SOCKET == sock){
+ EPS_RETURN( EPS_ERR_NONE )
+ }
+
+ pRecvBuf = (EPS_INT8*)EPS_ALLOC( SNMP_MAX_BUF );
+ if( NULL == pRecvBuf ){
+ ret = EPS_ERR_MEMORY_ALLOCATION;
+ goto snmpFindEnd_END;
+ }
+
+ /* Read All resopnse */
+ while(0 < epsNetFnc.receive(sock, pRecvBuf, SNMP_MAX_BUF, EPSNET_FIND_RECV_TIMEOUT) );
+
+snmpFindEnd_END:
+ EPS_SAFE_RELEASE( pRecvBuf );
+
+ epsNetFnc.shutdown(sock, EPS_SHUTDOWN_SEND);
+ epsNetFnc.shutdown(sock, EPS_SHUTDOWN_RECV);
+ epsNetFnc.shutdown(sock, EPS_SHUTDOWN_BOTH);
+
+ /* Close UDP socket */
+ if (EPS_SOCKET_SUCCESS != epsNetFnc.close(sock) ){
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpProbeByID() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printerUUID EPS_INT8* I: printr ID String */
+/* timeout EPS_UINT32 I: find timeout */
+/* printer EPS_PRINTER* O: Pointer for Alloc Printer infomation structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - socket failed */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* */
+/* Description: */
+/* Probe printer by ID String. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpProbeByID (
+
+ EPS_INT8* printerUUID,
+ EPS_UINT16 printPort,
+ EPS_INT32 printProtocol,
+ EPS_UINT32 timeout,
+ EPS_PRINTER_INN** printer
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_SOCKET sock = EPS_INVALID_SOCKET;
+ EPS_UINT32 tmStart, tmNow, tmSpan, tmReq;
+ EPS_INT8 compName[EPS_NAME_BUFFSIZE];
+ EPS_INT8 compSysName[EPS_NAME_BUFFSIZE];
+ EPS_INT8* pPos = NULL;
+ EPS_INT32 nSegCnt = 0;
+
+EPS_LOG_FUNCIN
+
+/*** Initialize Local & global Variables */
+ if(epsCmnFnc.getTime){
+ tmStart = tmReq = epsCmnFnc.getTime();
+ } else{
+ timeout = tmStart = tmNow = tmReq = 0;
+ }
+
+/*** Parse definition String */
+ pPos = strtok(printerUUID, EPS_NETID_SEP);
+ for(nSegCnt = 0; pPos != NULL && nSegCnt < EPS_NETID_SEGNUM; nSegCnt++){
+ switch(nSegCnt){
+ case 0: /* Get model name */
+ strcpy(compName, pPos);
+ break;
+ case 1: /* Get SysName */
+ strcpy(compSysName, pPos);
+ break;
+ }
+
+ pPos = strtok(NULL, EPS_NETID_SEP);
+ }
+ if(nSegCnt < EPS_NETID_SEGNUM){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
+ }
+
+/*** probe message broadcast */
+ ret = snmpFindStart( &sock, EPSNET_UDP_BROADCAST_ADDR, TRUE );
+ if(EPS_ERR_NONE != ret){
+ goto snmpProbeByID_END;
+ }
+
+/*** Check response */
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ while( EPS_ERR_PRINTER_NOT_FOUND == ret ||
+ EPS_ERR_PRINTER_NOT_USEFUL== ret )
+ {
+ ret = SnmpFindRecv(sock, printPort, printProtocol, compSysName, compName, printer);
+
+ /* epsCancelFindPriter() */
+ if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
+ if( 0 == epsCmnFnc.lockSync() ){
+ if( g_FindBreak ){
+ epsCmnFnc.unlockSync();
+ break;
+ }
+ epsCmnFnc.unlockSync();
+ }
+ }
+
+ /* Timeout */
+ if(timeout > 0){
+ tmNow = epsCmnFnc.getTime();
+ tmSpan = (EPS_UINT32)(tmNow - tmStart);
+ /*EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )*/
+ if( tmSpan >= timeout ){
+ break;
+ }
+ }
+
+ /*EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )*/
+ if( EPS_COM_NOT_RECEIVE == ret ){
+ /* beef up */
+ if( EPSNET_FIND_REREQUEST_TIME <= (EPS_UINT32)(tmNow - tmReq) ){
+ /*EPS_DBGPRINT( ("beef up\n") )*/
+ ret = snmpFindStart( &sock, EPSNET_UDP_BROADCAST_ADDR, TRUE );
+ if(EPS_ERR_NONE != ret){
+ goto snmpProbeByID_END;
+ }
+ }
+
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ } else{
+ tmReq = tmNow;
+ }
+ }
+
+ if( EPS_ERR_PRINTER_NOT_USEFUL == ret ||
+ EPS_COM_NOT_RECEIVE == ret ){
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+
+/*** Return to Caller */
+snmpProbeByID_END:
+ snmpFindEnd(sock);
+
+ if( EPS_ERR_NONE != ret ){
+ EPS_SAFE_RELEASE( *printer );
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpGetStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET* I: SNMP socket */
+/* address EPS_INT8* I: target printer IP Address */
+/* pstInfo EPS_STATUS_INFO* O: Printer Status information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get the printer status and analyze the status string. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpGetStatus(
+
+ EPS_SOCKET sock,
+ const EPS_INT8* address,
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+ EPS_INT32 retry = 0;
+
+EPS_LOG_FUNCIN
+
+ memset(&pdu, 0, sizeof(pdu));
+
+ for(retry = 0; retry < EPSNET_STAT_RETRY; retry++){
+ ret = SnmpTransactS(sock, address, EPSNET_STAT_RECV_TIMEOUT,
+ s_oidPrvStatus, ASN_PDU_GET_NEXT, &pdu);
+ if(EPS_ERR_NONE == ret ){
+ break;
+ }
+ EPS_REREASE_VARIANT( pdu );
+ EPS_DBGPRINT(("GetStatus retry %d\n", retry))
+ }
+
+ if( EPS_ERR_NONE == ret ){
+ if(ASN_VT_OCTET_STRING == pdu.type){
+ ret = serAnalyzeStatus(pdu.val.v_str, pstInfo);
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ }
+ }
+
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+
+#ifdef GCOMSW_CMD_ESCPAGE
+EPS_ERR_CODE snmpGetStatus_Page(
+
+ EPS_SOCKET sock,
+ const EPS_INT8* address,
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+ EPS_INT32 retry = 0;
+ EPS_INT32 devstat, prnstat;
+
+ EPS_LOG_FUNCIN
+
+ pstInfo->nState = EPS_ST_IDLE;
+ pstInfo->nError = EPS_PRNERR_NOERROR;
+ pstInfo->nWarn = EPS_PRNWARN_NONE;
+ pstInfo->nCancel= EPS_CAREQ_NOCANCEL;
+ pstInfo->nInkNo = 0;
+ memset(pstInfo->nColorType, 0, sizeof(pstInfo->nColorType) );
+ memset(pstInfo->nColor, 0, sizeof(pstInfo->nColor) );
+
+ memset(&pdu, 0, sizeof(pdu));
+
+ /* get Device Status */
+ for(retry = 0; retry < EPSNET_STAT_RETRY; retry++){
+ ret = SnmpTransactS(sock, address, EPSNET_STAT_RECV_TIMEOUT,
+ s_oidDevStatus, ASN_PDU_GET_NEXT, &pdu);
+ if(EPS_ERR_NONE == ret ){
+ break;
+ }
+ EPS_REREASE_VARIANT( pdu );
+ EPS_DBGPRINT(("GetStatus retry %d\n", retry))
+ }
+ if( EPS_ERR_NONE == ret && ASN_VT_INTEGER == pdu.type){
+ devstat = pdu.val.v_long;
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ goto snmpGetStatus_END;
+ }
+ EPS_REREASE_VARIANT( pdu );
+
+ /* get Printer Status */
+ for(retry = 0; retry < EPSNET_STAT_RETRY; retry++){
+ ret = SnmpTransactS(sock, address, EPSNET_STAT_RECV_TIMEOUT,
+ s_oidPrinterStatus, ASN_PDU_GET_NEXT, &pdu);
+ if(EPS_ERR_NONE == ret ){
+ break;
+ }
+ EPS_REREASE_VARIANT( pdu );
+ EPS_DBGPRINT(("GetStatus retry %d\n", retry))
+ }
+ if( EPS_ERR_NONE == ret && ASN_VT_INTEGER == pdu.type){
+ prnstat = pdu.val.v_long;
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ goto snmpGetStatus_END;
+ }
+ EPS_REREASE_VARIANT( pdu );
+
+ /*EPS_DBGPRINT(("%d / %d\n", devstat, prnstat))*/
+ switch(devstat){
+ case MIB_DEVST_RUNNING:
+ case MIB_DEVST_WARNING:
+ switch(prnstat){
+ case MIB_PRNST_IDLE:
+ case MIB_PRNST_OTHER: /* Standby */
+ pstInfo->nState = EPS_ST_IDLE;
+ pstInfo->nError = EPS_PRNERR_NOERROR;
+ break;
+ case MIB_PRNST_PRINTING:
+ pstInfo->nState = EPS_ST_WAITING;
+ pstInfo->nError = EPS_PRNERR_NOERROR;
+ break;
+ default:
+ /*case MIB_PRNST_WARMUP:*/
+ pstInfo->nState = EPS_ST_BUSY;
+ pstInfo->nError = EPS_PRNERR_BUSY;
+ break;
+ }
+ break;
+
+ case MIB_DEVST_DOWN:
+ switch(prnstat){
+ case MIB_PRNST_WARMUP:
+ pstInfo->nState = EPS_ST_BUSY;
+ pstInfo->nError = EPS_PRNERR_BUSY;
+ break;
+ default:
+ /*case MIB_PRNST_OTHER:*/
+ pstInfo->nState = EPS_ST_ERROR;
+ pstInfo->nError = EPS_PRNERR_GENERAL;
+ break;
+ }
+ break;
+
+ default:
+ pstInfo->nState = EPS_ST_ERROR;
+ pstInfo->nError = EPS_PRNERR_GENERAL;
+ break;
+ }
+
+ if( EPS_ST_ERROR == pstInfo->nState ){
+ /* get error reason */
+ for(retry = 0; retry < EPSNET_STAT_RETRY; retry++){
+ ret = SnmpTransactS(sock, address, EPSNET_STAT_RECV_TIMEOUT,
+ s_oidPrinterError, ASN_PDU_GET_NEXT, &pdu);
+ if(EPS_ERR_NONE == ret ){
+ break;
+ }
+ EPS_REREASE_VARIANT( pdu );
+ EPS_DBGPRINT(("GetStatus retry %d\n", retry))
+ }
+
+ if( EPS_ERR_NONE == ret && ASN_VT_OCTET_STRING == pdu.type){
+ EPS_DBGPRINT(("0x%02X\n", pdu.val.v_str[0]))
+ if( pdu.val.v_str[0] & MIB_PRERR_NOPAPER ){
+ pstInfo->nError = EPS_PRNERR_PAPEROUT;
+ } else if( pdu.val.v_str[0] & MIB_PRERR_NOINK ){
+ pstInfo->nError = EPS_PRNERR_INKOUT;
+ } else if( pdu.val.v_str[0] & MIB_PRERR_COVEROPEN ){
+ pstInfo->nError = EPS_PRNERR_COVEROPEN;
+ } else if( pdu.val.v_str[0] & MIB_PRERR_PAPERJAM ){
+ pstInfo->nError = EPS_PRNERR_PAPERJAM;
+ } else{
+ pstInfo->nError = EPS_PRNERR_GENERAL;
+ }
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ goto snmpGetStatus_END;
+ }
+ }
+
+snmpGetStatus_END:
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+#endif /* GCOMSW_CMD_ESCPAGE */
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpGetInkInfo() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* address EPS_INT8* I: target printer IP Address */
+/* pstInfo EPS_STATUS_INFO* O: Printer Status information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get the marker info. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpGetInkInfo(
+
+ const EPS_INT8* address,
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+
+ EPS_LOG_FUNCIN
+
+ memset(&pdu, 0, sizeof(pdu));
+
+ ret = SnmpTransact(address, EPSNET_RECV_TIMEOUT, s_oidPrvStatus, ASN_PDU_GET_NEXT, &pdu);
+
+ if( EPS_ERR_NONE == ret ){
+ if(ASN_VT_OCTET_STRING == pdu.type){
+ ret = serAnalyzeStatus(pdu.val.v_str, pstInfo);
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ }
+ }
+
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+
+#ifdef GCOMSW_CMD_ESCPAGE
+EPS_ERR_CODE snmpGetInkInfo_Page(
+
+ const EPS_INT8* address,
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_SOCKET soc;
+ ASN_VARIANT pdu;
+ EPS_INT32 i;
+
+ EPS_LOG_FUNCIN
+
+ pstInfo->nInkNo = 0;
+ memset(&pdu, 0, sizeof(pdu));
+
+ ret = snmpOpenSocket(&soc);
+ if( EPS_ERR_NONE != ret ){
+ ret = EPS_ERR_COMM_ERROR;
+ goto snmpGetInkInfo_END;
+ }
+
+ /* walk MarkerName record */
+ i = 0;
+ ret = SnmpWalkMib(soc, address, s_oidMarkerColorant, &pdu);
+ while(EPS_ERR_NONE == ret){
+ if(ASN_VT_OCTET_STRING == pdu.type){
+ pdu.val.v_str[pdu.length] = '\0';
+ pstInfo->nColorType[i++] = GetColorID(pdu.val.v_str);
+ }
+
+ /* next */
+ EPS_REREASE_VARIANT( pdu );
+ ret = SnmpWalkMib(soc, address, NULL, &pdu);
+ }
+ if(EPS_COM_NEXT_RECORD == ret){
+ ret = EPS_ERR_NONE;
+ } else if( EPS_ERR_NONE != ret ){
+ ret = EPS_ERR_COMM_ERROR;
+ goto snmpGetInkInfo_END;
+ }
+
+ pstInfo->nInkNo = i;
+
+ /* walk MarkerLevel record */
+ i = 0;
+ EPS_REREASE_VARIANT( pdu );
+ ret = SnmpWalkMib(soc, address, s_oidMarkerLevel, &pdu);
+ while(EPS_ERR_NONE == ret){
+ if(ASN_VT_INTEGER == pdu.type){
+ pstInfo->nColor[i++] = serInkLevelNromalize(pdu.val.v_long);
+ }
+
+ /* next */
+ EPS_REREASE_VARIANT( pdu );
+ ret = SnmpWalkMib(soc, address, NULL, &pdu);
+ }
+ if(EPS_COM_NEXT_RECORD == ret){
+ ret = EPS_ERR_NONE;
+ } else if( EPS_ERR_NONE != ret ){
+ ret = EPS_ERR_COMM_ERROR;
+ goto snmpGetInkInfo_END;
+ }
+
+snmpGetInkInfo_END:
+ snmpCloseSocket(&soc);
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+#endif /* GCOMSW_CMD_ESCPAGE */
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpGetPMString() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
+/* pString EPS_UINT8* O: Pointer to PM String */
+/* bufSize EPS_INT32 I: pString buffer size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Sends request to printer for supported media. Parses response and stores */
+/* PM String : pString */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpGetPMString(
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 type,
+ EPS_UINT8* pString,
+ EPS_INT32* bufSize
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+ EPS_INT8 cOid[SNMP_MAX_OID];
+
+ EPS_LOG_FUNCIN
+
+ memset(&pdu, 0, sizeof(pdu));
+
+ /* Create GetPM command */
+ if(1 == type){
+ sprintf(cOid, "%s.1.%d.%d.%d.%d.%d", s_oidPrvCtrl, 'p', 'm', 0x01, 0x00, 0x01);
+ } else if(2 == type){
+ sprintf(cOid, "%s.1.%d.%d.%d.%d.%d", s_oidPrvCtrl, 'p', 'm', 0x01, 0x00, 0x02);
+ } else{
+ EPS_RETURN( EPS_ERR_OPR_FAIL )
+ }
+
+ ret = SnmpTransact(printer->location, EPSNET_RECV_TIMEOUT, cOid, ASN_PDU_GET, &pdu);
+
+ if( EPS_ERR_NONE == ret ){
+ if(ASN_VT_OCTET_STRING == pdu.type){
+ *bufSize = Min((EPS_UINT32)*bufSize, pdu.length-1);
+ memcpy(pString, pdu.val.v_str+1, *bufSize);
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ }
+ }
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+
+#ifdef GCOMSW_CMD_ESCPAGE
+EPS_ERR_CODE snmpGetPMString_Page(
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 type,
+ EPS_UINT8* pString,
+ EPS_INT32* bufSize
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+ EPS_SOCKET soc;
+ EPS_UINT32 paperSource = EPS_MPID_AUTO;
+
+ EPS_LOG_FUNCIN
+
+ /* walk MarkerLevel record for enum paper tray */
+ *bufSize = 0;
+ ret = snmpOpenSocket(&soc);
+ if( EPS_ERR_NONE != ret ){
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+
+ ret = SnmpWalkMib(soc, printer->location, s_oidInputName, &pdu);
+ while(EPS_ERR_NONE == ret){
+ if(ASN_VT_OCTET_STRING == pdu.type){
+ if( strncmp(pdu.val.v_str, "MP Tray", pdu.length) == 0 ){
+ paperSource |= EPS_MPID_MPTRAY;
+ } else if( strncmp(pdu.val.v_str, "LC1", pdu.length) == 0 ){
+ paperSource |= EPS_MPID_FRONT1;
+ } else if( strncmp(pdu.val.v_str, "LC2", pdu.length) == 0 ){
+ paperSource |= EPS_MPID_FRONT2;
+ } else if( strncmp(pdu.val.v_str, "LC3", pdu.length) == 0 ){
+ paperSource |= EPS_MPID_FRONT3;
+ } else if( strncmp(pdu.val.v_str, "LC4", pdu.length) == 0 ){
+ paperSource |= EPS_MPID_FRONT4;
+ }
+ }
+
+ /* next */
+ EPS_REREASE_VARIANT( pdu );
+ ret = SnmpWalkMib(soc, printer->location, NULL, &pdu);
+ }
+
+ if(EPS_COM_NEXT_RECORD == ret){
+ ret = EPS_ERR_NONE;
+ } else if( EPS_ERR_NONE != ret ){
+ ret = EPS_ERR_COMM_ERROR;
+ *bufSize = 0;
+ }
+ snmpCloseSocket(&soc);
+
+ if(EPS_ERR_NONE == ret){
+ *bufSize = sizeof(EPS_UINT32);
+ memcpy(pString, &paperSource, sizeof(EPS_UINT32));
+ }
+
+ EPS_RETURN( ret )
+}
+#endif /*GCOMSW_CMD_ESCPAGE*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: snmpMechCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Command EPS_INT32 I: Command Code */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Mech command executed successfully */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Mech command execution error */
+/* */
+/* Description: */
+/* Sends mechanincal commands to the printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE snmpMechCommand (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 Command
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+ EPS_INT8 cOid[SNMP_MAX_OID];
+
+EPS_LOG_FUNCIN
+ memset(&pdu, 0, sizeof(pdu));
+
+ /* Create control command */
+ switch( Command ){
+ case EPS_CBTCOM_PE:
+ sprintf(cOid, "%s.1.%d.%d.%d.%d.%d", s_oidPrvCtrl, 'p', 'e', 0x01, 0x00, 0x01);
+ break;
+ case EPS_CBTCOM_RJ:
+ sprintf(cOid, "%s.1.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d",
+ s_oidPrvCtrl, 'r', 'j', 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* E , S , C , P , R , L , i , b */
+ 0x45, 0x53, 0x43, 0x50, 0x52, 0x4c, 0x69, 0x62);
+ break;
+ default:
+ EPS_RETURN( EPS_ERR_OPR_FAIL )
+ }
+
+ ret = SnmpTransact(printer->location, EPSNET_RECV_TIMEOUT, cOid, ASN_PDU_GET, &pdu);
+
+ if( EPS_ERR_NONE == ret ){
+ EPS_DBGPRINT(("%s\n", pdu.val.v_str+1))
+ if( (ASN_VT_OCTET_STRING == pdu.type) &&
+ (strstr(pdu.val.v_str+1,"OK") != NULL) ){
+ ret = EPS_ERR_NONE;
+ } else{
+ ret = EPS_ERR_COMM_ERROR;
+ }
+ }
+
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+
+#ifdef GCOMSW_CMD_ESCPAGE
+EPS_ERR_CODE snmpMechCommand_Page (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 Command
+
+){
+ EPS_LOG_FUNCIN
+ (void)printer;
+ (void)Command;
+ EPS_RETURN( EPS_ERR_PROTOCOL_NOT_SUPPORTED )
+}
+#endif /*GCOMSW_CMD_ESCPAGE*/
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SnmpTransact() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* address EPS_INT8* I: Destination IP Address string (NULL terminate) */
+/* recvtimeout EPS_UINT32 I: receive response timeout */
+/* oid EPS_INT8* I: Object ID */
+/* request EPS_INT8** I: Request type */
+/* pdu ASN_VARIANT* O: recieved value */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_COM_TINEOUT - Receive timeout */
+/* */
+/* Description: */
+/* SNMP send request and receive responce transaction. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE SnmpTransact(
+
+ const EPS_INT8* address,
+ EPS_INT32 recvtimeout,
+ const EPS_INT8* oid,
+ EPS_UINT8 request,
+ ASN_VARIANT* pdu
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_SOCKET soc;
+
+EPS_LOG_FUNCIN
+
+ ret = snmpOpenSocket(&soc);
+ if( EPS_ERR_NONE != ret ){
+ EPS_RETURN( ret )
+ }
+
+ ret = SnmpTransactS(soc, address, recvtimeout, oid, request, pdu);
+
+ snmpCloseSocket(&soc);
+
+ EPS_RETURN( ret )
+}
+
+
+static EPS_ERR_CODE SnmpTransactS(
+
+ EPS_SOCKET sock,
+ const EPS_INT8* address,
+ EPS_INT32 recvtimeout,
+ const EPS_INT8* oid,
+ EPS_UINT8 request,
+ ASN_VARIANT* pdu
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT8 nRqID = 0;
+ EPS_INT32 nSize = 0;
+ EPS_INT32 nRecvSize = 0;
+
+EPS_LOG_FUNCIN
+
+ memset(pdu, 0, sizeof(ASN_VARIANT));
+
+ /* Create GetStatus command */
+ nRqID = GetRequestId();
+ if( EPS_ERR_NONE != (ret = CreateCommand(g_TrnBuff, request, nRqID,
+ oid, &nSize)) ){
+ EPS_RETURN( ret )
+ }
+
+ /* Send */
+ if( epsNetFnc.sendTo(sock, (char*)g_TrnBuff, nSize,
+ address, SNMP_PORT_NUM, EPSNET_SEND_TIMEOUT) <= 0 ){
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+
+ ret = EPS_COM_READ_MORE;
+ while(ret == EPS_COM_READ_MORE){
+ /* Wireless network always send pair message and receive.
+ This behave make probrem that receive befor message. If it occur, try receive once.*/
+ nRecvSize = epsNetFnc.receive( sock, g_TrnBuff, SNMP_MAX_BUF, recvtimeout );
+ if( 0 >= nRecvSize ){ /* Error Occur or Not Recieve */
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+ ret = GetPDU(g_TrnBuff, nRecvSize, nRqID, oid, pdu, NULL, 0);
+ }
+
+ if( EPS_ERR_NONE != ret ){
+ EPS_REREASE_VARIANT( *pdu );
+ if(EPS_COM_NEXT_RECORD == ret){
+ ret = EPS_ERR_COMM_ERROR;
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SnmpWalkMib() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: Socket */
+/* address EPS_INT8* I: Destination IP Address string (NULL terminate) */
+/* oid EPS_INT8* I: Object ID. set first time only. */
+/* pdu ASN_VARIANT* O: recieved value */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_COM_TINEOUT - Receive timeout */
+/* */
+/* Description: */
+/* SNMP walk mib record transaction. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE SnmpWalkMib(
+
+ EPS_SOCKET sock,
+ const EPS_INT8* address,
+ const EPS_INT8* oid,
+ ASN_VARIANT* pdu
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT8 nRqID = 0;
+ EPS_INT32 nSize = 0;
+ EPS_INT32 nRecvSize = 0;
+ static EPS_INT8 orgObjID[SNMP_OBJID_LEN];
+ static EPS_INT8 nextObjID[SNMP_OBJID_LEN];
+
+EPS_LOG_FUNCIN
+
+ memset(pdu, 0, sizeof(ASN_VARIANT));
+
+ /* Create command */
+ nRqID = GetRequestId();
+ if( oid ){
+ strcpy(orgObjID, oid);
+ strcpy(nextObjID, oid);
+ }
+ ret = CreateCommand(g_TrnBuff, ASN_PDU_GET_NEXT, nRqID, nextObjID, &nSize);
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ /* Send */
+ if( epsNetFnc.sendTo(sock, (char*)g_TrnBuff, nSize,
+ address, SNMP_PORT_NUM, EPSNET_SEND_TIMEOUT) <= 0 ){
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+
+ ret = EPS_COM_READ_MORE;
+ while(ret == EPS_COM_READ_MORE){
+ /* Wireless network always send pair message and receive.
+ This behave make probrem that receive befor message. If it occur, try receive once.*/
+ nRecvSize = epsNetFnc.receive( sock, g_TrnBuff, SNMP_MAX_BUF, EPSNET_RECV_TIMEOUT );
+ if( 0 >= nRecvSize ){ /* Error Occur or Not Recieve */
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+ ret = GetPDU(g_TrnBuff, nRecvSize, nRqID, orgObjID, pdu, nextObjID, SNMP_OBJID_LEN);
+ }
+
+ if( EPS_ERR_NONE != ret ){
+ EPS_REREASE_VARIANT( *pdu );
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: mibGetPhysAddress() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* address EPS_INT8* I: Destination IP Address string (NULL terminate) */
+/* val EPS_INT8* O: pointer to return value */
+/* vallen EPS_UINT32 I: lenght of val buffer */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_COM_TINEOUT - Receive timeout */
+/* */
+/* Description: */
+/* Get MacAddress. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE mibGetPhysAddress(
+
+ const EPS_INT8* address,
+ EPS_INT8* val,
+ EPS_UINT32 vallen
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+ EPS_UINT8 *p;
+ EPS_UINT32 i;
+
+ EPS_LOG_FUNCIN
+
+ memset(&pdu, 0, sizeof(pdu));
+ ret = SnmpTransact(address, EPSNET_RECV_TIMEOUT, s_oidPhysAddress, ASN_PDU_GET_NEXT, &pdu);
+
+ if( EPS_ERR_NONE != ret ){
+ ret = EPS_ERR_COMM_ERROR;
+ goto mibGetPhysAddress_END;
+ }
+ if(ASN_VT_OCTET_STRING != pdu.type){
+ ret = EPS_ERR_COMM_ERROR;
+ goto mibGetPhysAddress_END;
+ }
+
+ /* convert to string */
+ p = (EPS_UINT8*)val;
+ vallen -= 2;
+ for(i = 0; i < pdu.length && i < vallen; i++ ){
+ *p = ((EPS_UINT8)pdu.val.v_str[i] >> 4);
+ if(*p < 10){
+ *p += 0x30;
+ } else{
+ *p += 0x37;
+ }
+ p++;
+
+ *p = ((EPS_UINT8)pdu.val.v_str[i] & 0x0F);
+ if(*p < 10){
+ *p += 0x30;
+ } else{
+ *p += 0x37;
+ }
+ p++;
+ }
+ *p = '\0';
+
+mibGetPhysAddress_END:
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: mibConfirmPrintPort() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printPort EPS_UINT16 I: print port */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_COM_TINEOUT - Receive timeout */
+/* EPS_COM_NEXT_RECORD - got next recode */
+/* */
+/* Description: */
+/* Confirm whether can use Print-port. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE mibConfirmPrintPort(
+
+ const EPS_INT8* address,
+ EPS_UINT16 printPort
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_SOCKET sckTmp;
+ ASN_VARIANT pdu;
+
+ EPS_LOG_FUNCIN
+
+ ret = snmpOpenSocket(&sckTmp);
+ if( EPS_ERR_NONE != ret ){
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+
+ /* walk Tcp port record */
+ ret = SnmpWalkMib(sckTmp, address, s_oidTcpConnLocalPort, &pdu);
+ while(EPS_ERR_NONE == ret){
+ if(ASN_VT_INTEGER == pdu.type){
+ EPS_DBGPRINT(("pdu.val.v_long = %d, %d\n", printPort, pdu.val.v_long));
+ if( printPort == pdu.val.v_long) {
+ break;
+ }
+ }
+ /* next */
+ EPS_REREASE_VARIANT( pdu );
+ ret = SnmpWalkMib(sckTmp, address, NULL, &pdu);
+ }
+
+ EPS_REREASE_VARIANT( pdu );
+ snmpCloseSocket(&sckTmp);
+
+ EPS_RETURN( ret )
+}
+
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+/*******************************************|********************************************/
+/* */
+/* Function name: mibGetMaxMediaXFeedDir() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* address EPS_INT8* I: Destination IP Address string (NULL terminate) */
+/* val EPS_INT8* O: pointer to return value */
+/* vallen EPS_UINT32 I: lenght of val buffer */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_COM_TINEOUT - Receive timeout */
+/* */
+/* Description: */
+/* Get MacAddress. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE mibGetMaxMediaXFeedDir(
+
+ const EPS_INT8* address,
+ EPS_UINT32* val
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ ASN_VARIANT pdu;
+ /* iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) printmib(43) prtMediaPath(13)
+ prtMediaPathTable(4) prtMediaPathEntry(1) prtMediaPathMaxMediaXFeedDir(6) */
+ const EPS_INT8 oidMaxMediaXFeedDir[] = "1.3.6.1.2.1.43.13.4.1.6";
+
+ EPS_LOG_FUNCIN
+
+ *val = 0;
+
+ memset(&pdu, 0, sizeof(pdu));
+ ret = SnmpTransact(address, EPSNET_RECV_TIMEOUT, oidMaxMediaXFeedDir, ASN_PDU_GET_NEXT, &pdu);
+
+ if( EPS_ERR_NONE != ret ){
+ ret = EPS_ERR_COMM_ERROR;
+ goto mibGetMaxMediaXFeedDir_END;
+ }
+ if(ASN_VT_INTEGER != pdu.type){
+ ret = EPS_ERR_COMM_ERROR;
+ goto mibGetMaxMediaXFeedDir_END;
+ }
+
+ *val = pdu.val.v_long;
+
+mibGetMaxMediaXFeedDir_END:
+ EPS_REREASE_VARIANT( pdu );
+
+ EPS_RETURN( ret )
+}
+#endif
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: SnmpFindRecv() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* sock EPS_SOCKET I: socket used in discovery phase */
+/* printPort EPS_UINT16 I: print data sending port */
+/* printProtocol EPS_INT32 I: print protocol */
+/* compSysName EPS_INT8* I: unique ID of target printer */
+/* compName EPS_INT8* I: model name of target printer */
+/* printer EPS_PRINTER_INN** O: pointer for found printer structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
+/* */
+/* Description: */
+/* Read discoverySocket and store information of valid devices that responded to */
+/* discovery message. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE SnmpFindRecv(
+
+ EPS_SOCKET sock,
+ EPS_UINT16 printPort,
+ EPS_INT32 printProtocol,
+ const EPS_INT8* compSysName,
+ const EPS_INT8* compName,
+ EPS_PRINTER_INN** printer
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 *pRecvBuf = NULL; /* Receive Buffer */
+ EPS_INT32 nRecvSize = 0; /* Received Length */
+ ASN_VARIANT pdu;
+ EPS_INT8 sFromAdder[EPS_ADDR_BUFFSIZE]; /* Remote Address */
+ EPS_UINT16 nFromPort = 0; /* Remote Port */
+ EPS_INT32 cmdLevel = 0;
+ EPS_INT8 idString[EPS_PRNID_BUFFSIZE];
+ EPS_INT8 devidString[SNMP_MAX_BUF];
+
+ EPS_LOG_FUNCIN
+
+ memset(&pdu, 0, sizeof(pdu));
+
+ pRecvBuf = (EPS_INT8*)EPS_ALLOC( SNMP_MAX_BUF );
+ if( NULL == pRecvBuf ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+ memset(sFromAdder, 0, sizeof(sFromAdder));
+
+ /* -------------------------------------------------------------------------------- */
+ /* Recieve discover response */
+ nRecvSize = epsNetFnc.receiveFrom( sock, pRecvBuf, SNMP_MAX_BUF,
+ sFromAdder, &nFromPort,
+ EPSNET_FIND_RECV_TIMEOUT);
+ if( 0 >= nRecvSize ){ /* Error Occur or No response*/
+ ret = EPS_COM_NOT_RECEIVE;
+ goto SnmpFindRecv_END;
+ }
+ /* Existing check */
+ EPS_DBGPRINT(("%s\n", sFromAdder))
+ if( prtIsRegistered(sFromAdder, NULL, printProtocol) ){
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ goto SnmpFindRecv_END;
+ }
+
+ /* parse value */
+ ret = GetPDU(pRecvBuf, nRecvSize, 0, s_oidPrvPrinter, &pdu, NULL, 0);
+ if( EPS_COM_ERR_REPLY == ret ||
+ EPS_COM_READ_MORE == ret ||
+ EPS_COM_NEXT_RECORD == ret ||
+ EPS_ERR_COMM_ERROR == ret ){
+ ret = EPS_ERR_PRINTER_NOT_USEFUL;
+ }
+ if( EPS_ERR_NONE != ret ){
+ goto SnmpFindRecv_END;
+ }
+ if (pdu.type != ASN_VT_OCTET_STRING) {
+ ret = EPS_ERR_PRINTER_NOT_USEFUL;
+ goto SnmpFindRecv_END;
+ }
+ memset(devidString, 0, sizeof(devidString));
+ strncpy(devidString, pdu.val.v_str, Min(pdu.length, SNMP_MAX_BUF-1));
+ devidString[Min(pdu.length, SNMP_MAX_BUF-1)] = 0;
+
+ /* Create printer data */
+ *printer = (EPS_PRINTER_INN*)EPS_ALLOC( sizeof(EPS_PRINTER_INN) );
+ if(NULL == *printer){
+ ret = EPS_ERR_MEMORY_ALLOCATION;
+ goto SnmpFindRecv_END;
+ }
+ memset( *printer, 0, sizeof(EPS_PRINTER_INN) );
+
+ if( !serParseDeviceID(devidString, (*printer)->manufacturerName, (*printer)->modelName,
+ &cmdLevel, &(*printer)->language) ){
+ ret = EPS_ERR_PRINTER_NOT_USEFUL; /* Not ESC/P-R,ESC/Page Printer */
+ goto SnmpFindRecv_END;
+ }
+ if( EPS_PROTOCOL_LPR != printProtocol ){
+ if( EPS_LANG_ESCPR != (*printer)->language ){
+ ret = EPS_ERR_PRINTER_NOT_USEFUL; /* Page Printer Not support via Raw */
+ goto SnmpFindRecv_END;
+ }
+ }
+
+ switch(cmdLevel){
+ case 0: /* Support all. For Uin communication */
+ case 2:
+ (*printer)->supportFunc |= EPS_SPF_JPGPRINT; /* Jpeg print */
+ case 1:
+ (*printer)->supportFunc |= EPS_SPF_RGBPRINT; /* RGB print */
+ }
+
+ (*printer)->protocol = printProtocol;
+ (*printer)->printPort = printPort;
+ strcpy( (*printer)->location, sFromAdder );
+
+ /* confirm whether can use Print-port */
+ if( 0 != printPort && EPS_LANG_ESCPR == (*printer)->language){
+ EPS_DBGPRINT(("mibConfirmPrintPort\n"))
+ ret = mibConfirmPrintPort(sFromAdder, printPort);
+ if( EPS_ERR_NONE != ret ){
+ ret = EPS_ERR_PRINTER_NOT_USEFUL;
+ goto SnmpFindRecv_END;
+ }
+ }
+
+ /* Get mac address */
+ ret = mibGetPhysAddress(sFromAdder, (*printer)->macAddress, sizeof((*printer)->macAddress));
+ if(EPS_ERR_NONE != ret){
+ ret = EPS_ERR_PRINTER_NOT_USEFUL;
+ goto SnmpFindRecv_END;
+ }
+
+ if( NULL != compSysName && NULL != compName){
+ /* compaire name */
+ if( strcmp(compSysName, (*printer)->macAddress) ||
+ strcmp(compName, (*printer)->modelName) ){
+
+ ret = EPS_ERR_PRINTER_NOT_USEFUL;
+ goto SnmpFindRecv_END;
+ }
+ }
+
+ /* Get friendly name */
+ EPS_REREASE_VARIANT( pdu );
+ ret = SnmpTransact(sFromAdder, EPSNET_RECV_TIMEOUT, s_oidPrvBonjourName, ASN_PDU_GET_NEXT, &pdu);
+ if( EPS_ERR_NONE == ret && ASN_VT_OCTET_STRING == pdu.type){
+ if(pdu.length < EPS_NAME_BUFFSIZE-1){
+ strncpy( (*printer)->friendlyName, pdu.val.v_str, pdu.length);
+ } else{
+ strncpy( (*printer)->friendlyName, pdu.val.v_str, EPS_NAME_BUFFSIZE-2);
+ }
+ } else{
+ ret = EPS_ERR_NONE; /* ignoure */
+ }
+
+ sprintf(idString, EPS_NET_IDPRM_STR, (*printer)->modelName, (*printer)->macAddress);
+ prtSetIdStr(*printer, idString);
+
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ if(EPS_LANG_ESCPAGE_S == (*printer)->language){
+ EPS_UINT32 feed = 0;
+ if( EPS_ERR_NONE == mibGetMaxMediaXFeedDir(sFromAdder, &feed) ){
+ (*printer)->feedDir = pageS_ParseFeedDir(feed);
+ }
+ }
+#endif
+
+/*** Return to Caller */
+SnmpFindRecv_END:
+ EPS_REREASE_VARIANT( pdu );
+ EPS_SAFE_RELEASE( pRecvBuf );
+ if(EPS_ERR_NONE != ret){
+ EPS_SAFE_RELEASE( *printer );
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CreateCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBuf EPS_INT8* O: SNMP request buffer */
+/* nPDUType EPS_UINT8 I: PDU type */
+/* nRqID EPS_UINT8 I: SNMP request ID */
+/* psIdentifire EPS_INT8* I: MIB number string */
+/* pDataSize EPS_INT32* O: SNMP request buffer size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Create SNMP request command. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE CreateCommand(
+
+ EPS_INT8* pBuff,
+ EPS_UINT8 nPDUType,
+ EPS_UINT8 nRqID,
+ const EPS_INT8* psIdentifire,
+ EPS_INT32* pDataSize
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8* pPos = pBuff;
+ EPS_INT8* pPDUTop = NULL;
+ EPS_INT8* pObjTop = NULL;
+ EPS_UINT32 nLen = 0;
+
+ /* version */
+ pPos = MakeIntField(SNMP_VERSION, pPos);
+ /* Community */
+ pPos = MakeStrField(SNMP_COMMUNITY_STR, pPos);
+ /* PDU Type */
+ *(pPos++) = nPDUType;
+ pPDUTop = pPos;
+
+ /* Request ID */
+ pPos = MakeIntField(nRqID, pPos);
+ /* Error Index */
+ pPos = MakeIntField(0, pPos);
+ /* Error Status */
+ pPos = MakeIntField(0, pPos);
+ pObjTop = pPos;
+
+ /* OID */
+ ret = MakeOidField(psIdentifire, &pPos);
+ /* Value(NULL) */
+ *(pPos++) = ASN_VT_NULL;
+ *(pPos++) = (EPS_INT8)(0);
+
+ /* Set Object Seupence */
+ nLen = (EPS_UINT32)(pPos - pObjTop);
+ ret = MakeSequens(pObjTop, &nLen, TRUE);
+ ret = MakeSequens(pObjTop, &nLen, TRUE);
+
+ /* Set Object Seupence */
+ nLen = (EPS_UINT32)(pObjTop - pPDUTop) + nLen;
+ ret = MakeSequens(pPDUTop, &nLen, FALSE);
+
+ /* Set All Seupence */
+ nLen = (EPS_UINT32)(pPDUTop - pBuff) + nLen;
+ ret = MakeSequens(pBuff, &nLen, TRUE);
+
+ *pDataSize = nLen;
+
+ return ret;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: GetPDU() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pBuf EPS_INT8* I: SNMP reply buffer */
+/* nBufSize EPS_INT32 I: SNMP reply buffer size */
+/* nRqID EPS_UINT8 I: SNMP request ID */
+/* pObjID EPS_INT8* I: requested OID */
+/* pPDU ASN_VARIANT* O: PDU field structure */
+/* pResObjID EPS_INT8* O: response OID */
+/* nResObjIDSize EPS_INT8* I: size of pResObjID buffer */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get PDU from SNMP reply. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE GetPDU(
+
+ EPS_INT8* pBuf,
+ EPS_INT32 nBufSize,
+ EPS_UINT8 nRqID,
+ const EPS_INT8* pObjID,
+ ASN_VARIANT *pPDU,
+ EPS_INT8* pResObjID,
+ EPS_INT32 nResObjIDSize
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 nAllSize = 0;
+ EPS_UINT32 nSeqSize = 0;
+ ASN_VARIANT vField;
+ EPS_INT32 nDataSize = nBufSize;
+ const EPS_INT8 *pOrg, *pRes;
+
+#define SNMP_CHECK_INTVALUE( r, v, n ) \
+ if(EPS_ERR_NONE != r ){ \
+ EPS_RETURN( r ) \
+ } else if( ASN_VT_INTEGER != v.type || n != v.val.v_long ){ \
+ EPS_DBGPRINT(("type=%d / value=%d\n", v.type, v.val.v_long)) \
+ EPS_REREASE_VARIANT( v ); \
+ EPS_RETURN( EPS_ERR_COMM_ERROR ) \
+ }
+
+EPS_LOG_FUNCIN
+
+ vField.length = 0;
+ vField.type = ASN_VT_NULL;
+ vField.val.v_str = NULL;
+
+ /* skip top tag */
+ pBuf++;
+ nDataSize--;
+ if( EPS_ERR_NONE != (ret = ParseLength( &pBuf, &nDataSize, &nAllSize ) ) ){
+ EPS_RETURN( ret )
+ }
+
+ /* check version */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ SNMP_CHECK_INTVALUE( ret, vField, SNMP_VERSION );
+
+ /* check community */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ if( ASN_VT_OCTET_STRING != vField.type
+ || NULL == memStrStrWithLen(vField.val.v_str, vField.length, SNMP_COMMUNITY_STR) ){
+ EPS_REREASE_VARIANT( vField );
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+ EPS_REREASE_VARIANT( vField );
+
+ /* check PDU Type */
+ if( (EPS_UINT8)(*pBuf) != ASN_PDU_RESP ){
+ EPS_RETURN( EPS_ERR_COMM_ERROR )
+ }
+ pBuf += 1;
+ nDataSize--;
+ /* skip sequence size */
+ if( EPS_ERR_NONE != (ret = ParseLength( &pBuf, &nDataSize, &nSeqSize ) ) ){
+ EPS_RETURN( ret )
+ }
+
+ /* check Request ID */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ if(nRqID != vField.val.v_long)
+ {
+ if(EPS_ERR_NONE != ret )
+ {
+ EPS_RETURN( ret )
+ }
+ else if( ASN_VT_INTEGER != vField.type ||
+ (nRqID != 0 && nRqID > vField.val.v_long ) )
+ {
+ /* The data in front of one was received.->retry */
+ EPS_REREASE_VARIANT( vField );
+ EPS_RETURN( EPS_COM_READ_MORE )
+ }
+ }
+
+ /* check Error */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ SNMP_CHECK_INTVALUE( ret, vField, SNMP_ERR_NONE );
+
+ /* skip Error Index */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ if(EPS_ERR_NONE != ret ){
+ EPS_RETURN( ret )
+ }
+ /* skip Sequence Head */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ if(EPS_ERR_NONE != ret ){
+ EPS_RETURN( ret )
+ }
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ if(EPS_ERR_NONE != ret ){
+ EPS_RETURN( ret )
+ }
+
+ /* Get MIB ID */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+ /*EPS_DBGPRINT(("\nORG : %s\nRES : %s\n", pObjID, vField.val.v_str))*/
+
+ /* Check response MIB ID */
+ pOrg = pObjID;
+ pRes = vField.val.v_str;
+ while(*pOrg != '\0' && *pRes != '\0'){
+ if( *pOrg++ < *pRes++ ){
+ /*if( strchr(pOrg, '.') != NULL){*/
+ ret = EPS_COM_NEXT_RECORD;
+ /*} else{ next item } */
+ break;
+ }
+ }
+ if( pResObjID ){
+ memset(pResObjID, 0, nResObjIDSize);
+ memcpy(pResObjID, vField.val.v_str, Min(nResObjIDSize-1, (EPS_INT32)strlen(vField.val.v_str)));
+ }
+
+ EPS_REREASE_VARIANT( vField );
+ if( EPS_ERR_NONE != ret){
+ EPS_RETURN( ret )
+ }
+
+ /* get valiable */
+ ret = ParseField( &pBuf, &nDataSize, &vField );
+
+ *pPDU = vField;
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: ParseField() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nSrc EPS_INT8** I/O: PDU buffer */
+/* pDataSize EPS_INT32* I/O: PDU buffer size */
+/* pVal ASN_VARIANT* O: PDU field structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Parse PDU field. And move next area. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE ParseField(
+
+ EPS_INT8** pSrc,
+ EPS_INT32* pDataSize,
+ ASN_VARIANT* pVal
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_UINT32 nInt = 0;
+
+ /* Field type */
+ pVal->type = *((*pSrc)++);
+ (*pDataSize)--;
+ if(*pDataSize <= 0){ /* data size not enough */
+ return EPS_ERR_COMM_ERROR;
+ }
+
+ /* Field length */
+ if( EPS_ERR_NONE != (ret = ParseLength( pSrc, pDataSize, &nInt ) ) ){
+ pVal->length = 0;
+ return ret;
+ }
+ pVal->length = nInt;
+ if((EPS_UINT32)*pDataSize < pVal->length){ /* data size not enough */
+ return EPS_ERR_COMM_ERROR;
+ }
+
+ /* Field value */
+ switch( pVal->type ){
+ case ASN_VT_INTEGER:
+ pVal->val.v_long = BerToInt(*pSrc, pVal->length);
+ break;
+
+ case ASN_VT_NULL:
+ pVal->val.v_long = 0;
+ break;
+
+ case ASN_VT_OCTET_STRING:
+ pVal->val.v_str = *pSrc;
+ break;
+
+ case ASN_VT_OBJECT_ID:
+ {
+ EPS_INT8* p = NULL;
+ ret = OidToStr( *pSrc, pVal->length, &p);
+ if( EPS_ERR_NONE != ret ){
+ return ret;
+ }
+ pVal->val.v_str = p;
+ }
+ break;
+
+ case ASN_VT_SEQUENCE:
+ pVal->val.v_str = *pSrc;
+ return ret; /* Not move next */
+ break;
+
+ }
+
+ *pSrc += pVal->length; /* Move next field */
+ *pDataSize -= pVal->length;
+
+ return ret;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: MakeIntField() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nSrc EPS_INT32 I: int value */
+/* pDst EPS_INT8* I: PDU buffer */
+/* */
+/* Return value: */
+/* EPS_INT8* : pointer for next area */
+/* */
+/* Description: */
+/* Make BER integer field. And move next area. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT8* MakeIntField(
+
+ EPS_INT32 nSrc,
+ EPS_INT8* pDst
+
+){
+ EPS_INT16 nLen = 0;
+
+ /* Field type */
+ *(pDst++) = ASN_VT_INTEGER;
+
+ /* Field value */
+ nLen = IntToBer(nSrc, pDst);
+ memmove(pDst+nLen, pDst , nLen);
+
+ /* Field length */
+ pDst = MakeLength( nLen, pDst );
+ pDst += nLen;
+
+ return pDst;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: MakeStrField() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pSrc EPS_INT8* I: string */
+/* pDst EPS_INT8* I: PDU buffer */
+/* */
+/* Return value: */
+/* EPS_INT8* : pointer for next area */
+/* */
+/* Description: */
+/* Make BER string field. And move next area. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT8* MakeStrField(
+
+ const EPS_INT8* pSrc,
+ EPS_INT8* pDst
+
+){
+ EPS_UINT32 nLen = (EPS_UINT32)strlen(pSrc);
+
+ /* Field type */
+ *(pDst++) = ASN_VT_OCTET_STRING;
+
+ /* Field length */
+ pDst = MakeLength( nLen, pDst );
+
+ /* Field value */
+ memcpy(pDst, pSrc, nLen);
+
+ pDst += nLen;
+
+ return pDst;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: MakeOidField() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pSrc EPS_INT8* I: ObjectID string */
+/* pDst EPS_INT8** I/O: PDU buffer(point to length field) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Make BER ObjectID field. And move next area. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE MakeOidField(
+
+ const EPS_INT8* pSrc,
+ EPS_INT8** pDst
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 cOid[SNMP_MAX_OID];
+ EPS_UINT16 nLen = 0;
+
+ /* Field type */
+ *(*pDst)++ = ASN_VT_OBJECT_ID;
+
+ /* Create OID */
+ nLen = sizeof(cOid);
+ if( EPS_ERR_NONE != (ret = StrToOid(pSrc, cOid, &nLen)) ){
+ return ret;
+ }
+
+ /* Field length */
+ *pDst = MakeLength( nLen, *pDst );
+
+ /* Field value */
+ memcpy(*pDst, cOid, nLen);
+
+ *pDst += nLen;
+
+ return ret;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: MakeSequens() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pSrc EPS_INT8* I: PDU buffer(point to length field) */
+/* pSize EPS_UINT32* O: pointer for length */
+/* bNeedType EPS_BOOL I: pointer for length */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Make BER Sequens. And move next area. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE MakeSequens(
+
+ EPS_INT8* pSrc,
+ EPS_UINT32* pSize,
+ EPS_BOOL bNeedType
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT8 nLengthLen = 0;
+
+ /* Length field length calculation */
+ if(*pSize <= 0x7F){
+ nLengthLen = 1;
+ } else{
+ if( EPS_ENDIAN_LITTLE == cpuEndian ){
+ nLengthLen = (sizeof(EPS_INT32) / sizeof(EPS_INT8)) - 1;
+ for(; nLengthLen > -1 && 0x00 == *((EPS_UINT8*)pSize + nLengthLen); nLengthLen--);
+ } else{
+ EPS_INT8 nLim = sizeof(EPS_INT32) / sizeof(EPS_INT8);
+ for(; nLengthLen < nLim && 0x00 == *((EPS_INT8*)pSize + nLengthLen); nLengthLen++);
+ }
+ }
+
+ if( bNeedType ){
+ memmove(pSrc + nLengthLen + 1, pSrc, *pSize); /* 1 = Field type */
+
+ /* Field type */
+ *(pSrc++) = ASN_VT_SEQUENCE;
+
+ /* Field length */
+ pSrc = MakeLength( *pSize, pSrc );
+
+ *pSize += nLengthLen + 1;
+ } else{
+ memmove(pSrc + nLengthLen, pSrc, *pSize);
+
+ /* Field length */
+ pSrc = MakeLength( *pSize, pSrc );
+
+ *pSize += nLengthLen;
+ }
+
+ return ret;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: ParseLength() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pSrc EPS_INT8** I/O: PDU buffer(point to length field) */
+/* pLength EPS_UINT32* O: pointer for length */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Parse Length field. And move next area. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE ParseLength(
+
+ EPS_INT8** pSrc,
+ EPS_INT32* pDataSize,
+ EPS_UINT32* pLength
+
+){
+ *pLength = 0;
+
+ if( (**pSrc) & 0x80 ){
+ EPS_INT8 n = 0;
+ EPS_INT8 nLenLength = (**pSrc) ^ 0x80;
+ if(sizeof(EPS_UINT32) < (EPS_UINT8)nLenLength){
+ /* Over flow */
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+
+ (*pSrc)++; (*pDataSize)--;
+
+ if( EPS_ENDIAN_LITTLE == cpuEndian ){
+ for(n = nLenLength-1; n >= 0; n--){
+ *((EPS_INT8*)&(*pLength) + n) = *(*pSrc)++;
+ (*pDataSize)--;
+ }
+ } else{
+ for(n = sizeof(EPS_UINT32) - nLenLength; (EPS_UINT8)n < sizeof(EPS_UINT32); n++){
+ *((EPS_INT8*)&(*pLength) + n) = *(*pSrc)++;
+ (*pDataSize)--;
+ if(*pDataSize <= 0){ /* data size not enough */
+ return EPS_ERR_COMM_ERROR;
+ }
+ }
+ }
+ } else{
+ *pLength = *(*pSrc)++;
+ (*pDataSize)--;
+ }
+
+ if((EPS_UINT32)*pDataSize < *pLength){ /* data size not enough */
+ return EPS_ERR_COMM_ERROR;
+ }
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: MakeLength() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nLength EPS_INT32 I: length value */
+/* pDst EPS_INT8* O: length field */
+/* */
+/* Return value: */
+/* EPS_INT8* : pointer for next area */
+/* */
+/* Description: */
+/* Make BER length field. And move next area. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT8* MakeLength(
+
+ EPS_INT32 nLength,
+ EPS_INT8* pDst
+
+){
+ if(nLength <= 0x7F){
+ *(pDst++) = (EPS_INT8)nLength;
+ } else{
+
+ if( EPS_ENDIAN_LITTLE == cpuEndian ){
+ EPS_INT8 n = (sizeof(EPS_INT32) / sizeof(EPS_INT8)) - 1;
+
+ /* set length */
+ for(; n > -1 && 0x00 == *((EPS_INT8*)&nLength + n); n--);
+ *(pDst++) = (EPS_INT8)(0x80 & (n+1));
+
+ for(; n > -1; n--){
+ *(pDst++) = *((EPS_INT8*)&nLength + n);
+ }
+ } else{
+ EPS_INT8 nLim = sizeof(EPS_INT32) / sizeof(EPS_INT8);
+ EPS_INT8 n = 0;
+
+ /* set length */
+ for(; n < nLim && 0x00 == *((EPS_INT8*)&nLength + n); n++);
+ *(pDst++) = (EPS_INT8)(0x80 & (nLim-n));
+
+ for(; n < nLim; n++){
+ *(pDst++) = *((EPS_INT8*)&nLength + n);
+ }
+ }
+ }
+
+ return pDst;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: OidToStr() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nSrc EPS_INT8* I: ObjectID binary */
+/* nSrcLen EPS_UINT16 O: ObjectID binary length */
+/* pDst EPS_INT8** O: ObjectID string */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Convert binary MIB ObjectID to string. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE OidToStr(
+
+ EPS_INT8* pSrc,
+ EPS_UINT32 nSrcLen,
+ EPS_INT8** pDst
+){
+
+#define SNMP_OID_SIZE_INI (32)
+#define SNMP_OID_SIZE_GRW (16) /* 32bit max = 4294967295 is 10 character */
+ EPS_UINT16 nCnt = 0;
+ EPS_UINT16 nDstSize = 0;
+ EPS_UINT16 nDstLen = 0;
+ EPS_INT8* pTmp = NULL;
+ EPS_UINT32 nElm = 0;
+ EPS_INT8* pEnd = pSrc + nSrcLen;
+
+ nDstSize = SNMP_OID_SIZE_INI;
+ *pDst = (EPS_INT8*)EPS_ALLOC( nDstSize );
+
+ sprintf(*pDst, "%d.%d.", *pSrc / 40, *pSrc % 40);
+ pSrc++;
+
+ while( pSrc < pEnd ){
+ nDstLen = (EPS_UINT16)strlen(*pDst);
+ if( nDstSize - nDstLen < SNMP_OID_SIZE_GRW ){
+ nDstSize += SNMP_OID_SIZE_GRW;
+ pTmp = (EPS_INT8*)EPS_ALLOC( nDstSize );
+ if(pTmp){
+ memcpy(pTmp, *pDst, nDstLen+1);
+ EPS_SAFE_RELEASE( *pDst );
+ *pDst = pTmp;
+ } else{
+ EPS_SAFE_RELEASE( *pDst );
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+ }
+
+ if( 0x80 & *pSrc ){
+ nElm = 0;
+ while( 0x80 & pSrc[nCnt] ){
+ nElm += (EPS_INT8)( *(pSrc++) ^ 0x80 );
+ nElm <<= 7;
+ }
+ nElm += (EPS_INT8)(*(pSrc++));
+
+ sprintf(&(*pDst)[nDstLen], "%d.", nElm);
+ } else{
+ sprintf(&(*pDst)[nDstLen], "%d.", *(pSrc++));
+ }
+ }
+
+ nDstLen = (EPS_UINT16)strlen(*pDst) - 1;
+ (*pDst)[nDstLen] = '\0';
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: StrToOid() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nSrc EPS_INT8* I: ObjectID string */
+/* pDst EPS_INT8* O: ObjectID binary */
+/* pDstLen EPS_INT16* I/O: ObjectID binary length */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Convert string to MIB ObjectID binary. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE StrToOid(
+
+ const EPS_INT8* pSrc,
+ EPS_INT8* pDst,
+ EPS_UINT16* pDstLen
+
+){
+ EPS_UINT16 nCnt = 0;
+ EPS_INT8* pTmp = NULL;
+ EPS_INT8* p = NULL;
+ EPS_UINT32 nElm = 0;
+ EPS_UINT8 nBinNum = 0;
+ EPS_UINT8 n = 0;
+
+ pTmp = (EPS_INT8*)EPS_ALLOC( strlen(pSrc)+1 );
+ if(!pTmp){
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+ strcpy(pTmp, pSrc);
+
+ p = strtok(pTmp, ".");
+ if( NULL != p ){
+ pDst[nCnt] = (EPS_INT8)(atoi(p) * 40);
+ } else{
+ EPS_FREE(pTmp);
+ return EPS_ERR_NONE;
+ }
+ p = strtok(NULL, ".");
+ if( NULL != p ){
+ pDst[nCnt] += (EPS_INT8)(atoi(p));
+ nCnt++;
+ } else{
+ EPS_FREE(pTmp);
+ return EPS_ERR_NONE;
+ }
+
+ p = strtok(NULL, ".");
+ while( NULL != p){
+ if(*pDstLen-1 < nCnt){
+ return EPS_ERR_MEMORY_ALLOCATION;
+ }
+
+ nElm = atoi(p);
+ if(0x7f >= nElm){
+ pDst[nCnt] = (EPS_INT8)nElm;
+ } else{
+ /* Necessary byte number calculation */
+ for(nBinNum = 0; !((nElm << nBinNum) & 0x80000000); nBinNum++);
+
+ nBinNum = sizeof(EPS_UINT32)*8 - nBinNum;
+ nBinNum = nBinNum / 7 + ((nBinNum%7)?1:0);
+ nCnt += nBinNum-1;
+
+ /* It stores it by dividing 7 bits. */
+ pDst[nCnt] = (EPS_INT8)(nElm & 0x7F);
+ for(n = 1; n < nBinNum; n++){
+ pDst[nCnt-n] = (EPS_INT8)(((nElm >> 7*n) & 0x7F) + 0x80);
+ }
+ }
+
+ nCnt++;
+ p = strtok(NULL, ".");
+ }
+
+ EPS_SAFE_RELEASE(pTmp);
+ *pDstLen = nCnt;
+
+ return EPS_ERR_NONE;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: IntToBer() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nSrc EPS_INT32 I: int value */
+/* pDst EPS_INT32 O: pointer for BER Integer */
+/* */
+/* Return value: */
+/* EPS_INT16 : BER Integer length */
+/* */
+/* Description: */
+/* Convert integer to BER integer. */
+/* */
+/*******************************************|********************************************/
+static EPS_UINT16 IntToBer(
+
+ EPS_INT32 nSrc,
+ EPS_INT8* pDst
+
+){
+ EPS_UINT16 nCnt = 0;
+
+ if( EPS_ENDIAN_LITTLE == cpuEndian ){
+ EPS_INT8 n = (sizeof(EPS_INT32) / sizeof(EPS_INT8)) - 1;
+
+ for(; n > -1; n--){
+ if( 0 == nCnt){
+ /* An unnecessary bit is thrown away. */
+ if( 0xff == (EPS_INT32)*((EPS_UINT8*)&nSrc + n) ){
+ if( n > 0 &&
+ *((EPS_UINT8*)&nSrc + n-1) & 0x80 ){
+ continue;
+ }
+ } else if( 0x00 == *((EPS_UINT8*)&nSrc + n) ){
+ if( n > 0 &&
+ !(*((EPS_UINT8*)&nSrc + n-1) & 0x80) ){
+ continue;
+ }
+ }
+ }
+
+ *(pDst++) = *((EPS_UINT8*)&nSrc + n);
+ nCnt++;
+ }
+ } else{
+ EPS_INT8 nMax = (sizeof(EPS_INT32) / sizeof(EPS_INT8));
+ EPS_INT8 n = 0;
+
+ for(; n < nMax; n++){
+ if( 0 == nCnt){
+ /* An unnecessary bit is thrown away. */
+ if( 0xff == *((EPS_UINT8*)&nSrc + n) ){
+ if( n < nMax-1 &&
+ *((EPS_UINT8*)&nSrc + n+1) & 0x80 ){
+ continue;
+ }
+ } else if( 0x00 == *((EPS_UINT8*)&nSrc + n) ){
+ if( n < nMax-1 &&
+ !(*((EPS_UINT8*)&nSrc + n+1) & 0x80) ){
+ continue;
+ }
+ }
+ }
+
+ *(pDst++) = *((EPS_UINT8*)&nSrc + n);
+ nCnt++;
+ }
+ }
+
+ return nCnt;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: BerToInt() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* nSrc EPS_INT32 I: pointer for BER Integer */
+/* pDst EPS_INT32 I: BER Integer length */
+/* */
+/* Return value: */
+/* EPS_INT32 : int value */
+/* */
+/* Description: */
+/* Convert BER integer to integer. */
+/* */
+/*******************************************|********************************************/
+static EPS_INT32 BerToInt(
+
+ EPS_INT8* pSrc,
+ EPS_INT32 nLen
+
+){
+ EPS_INT32 nDst = 0;
+
+ if( EPS_ENDIAN_LITTLE == cpuEndian ){
+ EPS_INT8 nMax = (sizeof(EPS_INT32) / sizeof(EPS_INT8)) - 1;
+ EPS_INT32 n = 0;
+ EPS_INT32 m = nLen - 1;
+
+ for(; n < nMax && m > -1; n++, m--){
+ *((EPS_INT8*)&nDst + n) = *(pSrc+m);
+ }
+
+ if( n < nMax ){
+ if( *(pSrc) & 0x80 ){
+ memset(((EPS_INT8*)&nDst + n), 0xff, nMax-(n-1));
+ } else{
+ memset(((EPS_INT8*)&nDst + n), 0x00, nMax-(n-1));
+ }
+ }
+ } else{
+ EPS_INT8 nDstSize = (sizeof(EPS_INT32) / sizeof(EPS_INT8));
+ EPS_INT32 n = nDstSize-nLen;
+ EPS_INT32 m = 0;
+
+ if( *(pSrc) & 0x80 ){
+ memset(&nDst, 0xff, nDstSize-nLen);
+ } else{
+ memset(&nDst, 0x00, nDstSize-nLen);
+ }
+
+ for(; n < nDstSize && m < nLen; n++, m++){
+ *((EPS_INT8*)&nDst + n) = *(pSrc+m);
+ }
+ }
+
+ return nDst;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: GetRequestId() */
+/* */
+/* Arguments */
+/* --------- */
+/* (none) */
+/* */
+/* Return value: */
+/* EPS_INT16 : RequestID */
+/* */
+/* Description: */
+/* Generate SNMP request ID (value is between from 1 to 127). */
+/* */
+/*******************************************|********************************************/
+static EPS_UINT8 GetRequestId(void)
+{
+ static EPS_UINT8 nId = 1;
+
+ nId++;
+ if( (char)0x7f < nId ){
+ nId = 1;
+ }
+
+ return nId;
+}
+
+#ifdef GCOMSW_CMD_ESCPAGE
+static EPS_INT32 GetColorID(EPS_INT8* name)
+{
+ EPS_INT32 id = EPS_COLOR_UNKNOWN;
+ EPS_INT8* p;
+
+ if( memStrStr(name, "Black", FALSE) ){
+ id = EPS_COLOR_BLACK;
+ } else if( memStrStr(name, "Cyan", FALSE) ){
+ id = EPS_COLOR_CYAN;
+ } else if( memStrStr(name, "Magenta", FALSE) ){
+ id = EPS_COLOR_MAGENTA;
+ } else if( memStrStr(name, "Yellow", FALSE) ){
+ id = EPS_COLOR_YELLOW;
+ } else if( memStrStr(name, "Red", FALSE) ){
+ id = EPS_COLOR_RED;
+ } else if( memStrStr(name, "Violet", FALSE) ){
+ id = EPS_COLOR_VIOLET;
+ } else if( memStrStr(name, "Clear", FALSE) ){
+ id = EPS_COLOR_CLEAR;
+ } else if( memStrStr(name, "Gray", FALSE) ){
+ id = EPS_COLOR_GRAY;
+ } else if( memStrStr(name, "Orange", FALSE) ){
+ id = EPS_COLOR_ORANGE;
+ } else if( memStrStr(name, "Green", FALSE) ){
+ id = EPS_COLOR_GREEN;
+ }
+
+ if( (p = memStrStr(name, "Light", TRUE)) != NULL ){
+ if(EPS_COLOR_CYAN == id){
+ id = EPS_COLOR_LIGHTCYAN;
+ } else if(EPS_COLOR_MAGENTA == id){
+ id = EPS_COLOR_LIGHTMAGENTA;
+ } else if(EPS_COLOR_YELLOW == id){
+ id = EPS_COLOR_LIGHTYELLOW;
+ } else if(EPS_COLOR_BLACK == id){
+ if( memStrStr(p, "Light", FALSE) ){
+ id = EPS_COLOR_LIGHTLIGHTBLACK;
+ } else{
+ id = EPS_COLOR_LIGHTBLACK;
+ }
+ }
+
+ } else if( memStrStr(name, "Matte", FALSE) ){
+ if(EPS_COLOR_BLACK == id){
+ id = EPS_COLOR_MATTEBLACK;
+ }
+ } else if( memStrStr(name, "Dark", FALSE) ){
+ if(EPS_COLOR_YELLOW == id){
+ id = EPS_COLOR_DARKYELLOW;
+ }
+ } else if( memStrStr(name, "Photo", FALSE) ){
+ if(EPS_COLOR_BLACK == id){
+ id = EPS_COLOR_PHOTOBLACK;
+ }
+ }
+
+ return id;
+}
+#endif /* GCOMSW_CMD_ESCPAGE */
+
+/*________________________________ epson-net-snmp.c ________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-net-snmp.h b/lib/epson-net-snmp.h
new file mode 100644
index 0000000..35b7f78
--- /dev/null
+++ b/lib/epson-net-snmp.h
@@ -0,0 +1,77 @@
+/*_______________________________ epson-net-snmp.h _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+* Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+*
+* Copyright protection claimed includes all forms and matters of
+* copyrightable material and information now allowed by statutory or judicial
+* law or hereinafter granted, including without limitation, material generated
+* from the software programs which are displayed on the screen such as icons,
+* screen display looks, etc.
+*
+*/
+/*******************************************|********************************************/
+/* */
+/* Epson SNMP Protocol Definitions */
+/* */
+/*******************************************|********************************************/
+
+#ifndef __EPSON_NET_SNMP_H__
+#define __EPSON_NET_SNMP_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+/****************************************************************************************/
+/* public SNMP functions */
+typedef EPS_ERR_CODE (*SNMP_GetStatus )(EPS_SOCKET, const EPS_INT8*, EPS_STATUS_INFO*);
+typedef EPS_ERR_CODE (*SNMP_GetInkInfo )(const EPS_INT8*, EPS_STATUS_INFO* );
+typedef EPS_ERR_CODE (*SNMP_GetPMString )(const EPS_PRINTER_INN*, EPS_INT32,
+ EPS_UINT8*, EPS_INT32* );
+typedef EPS_ERR_CODE (*SNMP_MechCommand )(const EPS_PRINTER_INN*, EPS_INT32 );
+
+typedef struct tagEPS_SNMP_FUNCS {
+ SNMP_GetStatus GetStatus;
+ SNMP_GetInkInfo GetInkInfo;
+ SNMP_GetPMString GetPMString;
+ SNMP_MechCommand MechCommand;
+}EPS_SNMP_FUNCS;
+
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern void snmpSetupSTFunctions(EPS_SNMP_FUNCS*, const EPS_PRINTER_INN* );
+
+extern EPS_ERR_CODE snmpOpenSocket (EPS_SOCKET* );
+extern void snmpCloseSocket (EPS_SOCKET* );
+
+extern EPS_ERR_CODE snmpFindStart (EPS_SOCKET*, const EPS_INT8*, EPS_BOOL );
+extern EPS_ERR_CODE snmpFind (EPS_SOCKET, EPS_UINT16, EPS_INT32, EPS_PRINTER_INN**);
+extern EPS_ERR_CODE snmpFindEnd (EPS_SOCKET );
+extern EPS_ERR_CODE snmpProbeByID (EPS_INT8*, EPS_UINT16, EPS_INT32, EPS_UINT32, EPS_PRINTER_INN**);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* def __EPSON_NET_SNMP_H__ */
+
+/*_______________________________ epson-net-snmp.h _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-protocol.c b/lib/epson-protocol.c
new file mode 100644
index 0000000..8a69047
--- /dev/null
+++ b/lib/epson-protocol.c
@@ -0,0 +1,1766 @@
+/*________________________________ epson-protocol.c _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of copyrightable
+ * material and information now allowed by statutory or judicial law or hereinafter
+ * granted, including without limitation, material generated from the software
+ * programs which are displayed on the screen such as icons, screen display looks,
+ * etc.
+ */
+/*******************************************|********************************************/
+/* */
+/* Protocol Depend functions */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE prtFunctionCheck (commMode, usbFuncPtrs, netFuncPtrs, */
+/* cmnFuncPtrs ); */
+/* EPS_ERR_CODE prtFindPrinter (timeout ); */
+/* void prtCancelFindPrinter ( ); */
+/* EPS_ERR_CODE prtProbePrinterByID (probeParam ); */
+/* EPS_ERR_CODE prtProbePrinterByAddr (probeParam ); */
+/* EPS_ERR_CODE prtRecoverPE ( ); */
+/* EPS_ERR_CODE prtGetPMString (printer, pString, bufSize ); */
+/* EPS_ERR_CODE prtRegPrinter (printer, bNotify ); */
+/* EPS_ERR_CODE prtIsRegistered (Address, Protocol ); */
+/* EPS_ERR_CODE prtClearPrinterList (printer ); */
+/* EPS_ERR_CODE prtClearSupportedMedia (printer ); */
+/* EPS_ERR_CODE prtSetIdStr (printer, idString ); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-services.h"
+#include "epson-escpr-mem.h"
+#ifdef GCOMSW_CMD_ESCPAGE
+#include "epson-escpage.h"
+#endif
+#ifdef GCOMSW_CMD_ESCPAGE_S
+#include "epson-escpage-s.h"
+#endif
+
+#include "epson-protocol.h"
+
+#ifdef GCOMSW_PRT_USE_USB
+#include "epson-usb.h"
+#endif
+
+#ifdef GCOMSW_PRT_USE_LPR
+#include "epson-net-lpr.h"
+#endif
+
+#ifdef GCOMSW_PRT_USE_RAW
+#include "epson-net-raw.h"
+#endif
+
+/*----------------------------- Local Macro Definitions -------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_PRTCOL
+#define EPS_LOG_MODULE EPS_LOG_MODULE_PRTCOL
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+/*------------------------------------ Definition -----------------------------------*/
+/*******************************************|********************************************/
+/* Find Printer functions */
+typedef EPS_ERR_CODE (*NET_FindStart )(EPS_SOCKET*, const EPS_INT8*, EPS_BOOL );
+typedef EPS_ERR_CODE (*NET_FindCheck )(EPS_SOCKET, EPS_PRINTER_INN** );
+typedef EPS_ERR_CODE (*NET_FindEnd )(EPS_SOCKET );
+
+typedef struct tagEPS_FIND_FUNCS {
+ NET_FindStart fncStart; /* Start function */
+ NET_FindCheck fncCheck; /* Check function */
+ NET_FindEnd fncEnd; /* End function */
+ EPS_SOCKET sock; /* socekt */
+ EPS_INT8 address[EPS_ADDR_BUFFSIZE];
+}EPS_FIND_FUNCS;
+
+
+#define EPS_FINDNOTIFY_DELAY_COUNT (10)
+
+/*-------------------------- ESC/P-R Net Lib Global Variables ------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_NET_FUNC epsNetFnc;
+extern EPS_CMN_FUNC epsCmnFnc;
+
+ /*** Print Job Structure */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_PRINT_JOB printJob;
+
+ /*** Find */
+ /*** -------------------------------------------------------------------------------*/
+EPS_BOOL g_FindBreak; /* Find printer end flag */
+EPS_INT32 g_FindProtocol;
+
+/*------------------------- Module "Local Global" Variables --------------------------*/
+/*******************************************|********************************************/
+
+ /*** internal stock */
+ /*** -------------------------------------------------------------------------------*/
+static EPS_PRINTER_LIST epsPrinterList; /* Printer List */
+
+
+
+/*-------------------------------- Local Functions ----------------------------------*/
+/*******************************************|********************************************/
+#ifdef GCOMSW_PRT_USE_NETWORK
+static EPS_ERR_CODE FindNetPrinter (EPS_INT32, EPS_UINT32, EPS_BOOL, const EPS_INT8* );
+#endif
+static void MakePrinterStructure (EPS_PRINTER* dst, EPS_PRINTER_INN* src );
+static EPS_BOOL IsValidAddress (const EPS_INT8* );
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtFunctionCheck() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* commMode EPS_INT8 I: Communication Mode */
+/* (Bi-Directional or Uni-Directional) */
+/* usbFuncPtrs EPS_USB_FUNC* I: Data structure containing function pointers to */
+/* USB I/O functions. */
+/* netFuncPtrs EPS_NET_FUNC* I: Data structure containing function pointers to */
+/* Socket I/O functions. */
+/* cmnFuncPtrs EPS_CMN_FUNC* I: Data structure containing function pointers to */
+/* external memory management functions. */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "commMode" */
+/* EPS_ERR_INV_FNCP_NULL - Invalid function pointer structure */
+/* EPS_ERR_INV_FNCP_FINDCALLBACK - Invalid function pointer "findCallback" */
+/* EPS_ERR_INV_FNCP_MEMALLOC - Invalid function pointer "memAlloc" */
+/* EPS_ERR_INV_FNCP_MEMFREE - Invalid function pointer "memFree" */
+/* EPS_ERR_INV_FNCP_SLEEP - Invalid function pointer "sleep" */
+/* EPS_ERR_INV_FNCP_GETTIME - Invalid function pointer "GetTime" */
+/* EPS_ERR_INV_FNCP_OPENPORTAL - Invalid function pointer "openPortal" */
+/* EPS_ERR_INV_FNCP_CLOSEPORTAL - Invalid function pointer "closePortal" */
+/* EPS_ERR_INV_FNCP_READPORTAL - Invalid function pointer "readPortal" */
+/* EPS_ERR_INV_FNCP_WRITEPORTAL - Invalid function pointer "writePortal" */
+/* EPS_ERR_INV_FNCP_FINDFIRST - Invalid function pointer "findFirst" */
+/* EPS_ERR_INV_FNCP_FINDNEXT - Invalid function pointer "findNext" */
+/* EPS_ERR_INV_FNCP_FINDCLOSE - Invalid function pointer "findClose" */
+/* EPS_ERR_INV_FNCP_NETSOCKET - Invalid function pointer "socket" */
+/* EPS_ERR_INV_FNCP_NETCLOSE - Invalid function pointer "close" */
+/* EPS_ERR_INV_FNCP_NETCONNECT - Invalid function pointer "connect" */
+/* EPS_ERR_INV_FNCP_NETSHUTDOWN - Invalid function pointer "shutdown" */
+/* EPS_ERR_INV_FNCP_NETBIND - Invalid function pointer "bind" */
+/* EPS_ERR_INV_FNCP_NETLISTEN - Invalid function pointer "listen" */
+/* EPS_ERR_INV_FNCP_NETACCEPT - Invalid function pointer "accept" */
+/* EPS_ERR_INV_FNCP_NETSEND - Invalid function pointer "send" */
+/* EPS_ERR_INV_FNCP_NETSENDTO - Invalid function pointer "sendTo" */
+/* EPS_ERR_INV_FNCP_NETRECEIVE - Invalid function pointer "receive" */
+/* EPS_ERR_INV_FNCP_NETRECEIVEFROM - Invalid function pointer "receiveFrom" */
+/* EPS_ERR_INV_FNCP_NETGETSOCKNAME - Invalid function pointer "getsockname" */
+/* EPS_ERR_INV_FNCP_NETSETBROADCAST - Invalid function pointer "setBroadcast" */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Validate external functions. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtFunctionCheck (
+
+ EPS_INT32 commMode,
+ const EPS_USB_FUNC* usbFuncPtrs,
+ const EPS_NET_FUNC* netFuncPtrs,
+ const EPS_CMN_FUNC* cmnFuncPtrs
+
+){
+ EPS_UINT8* testptr; /* Test pointer to do memory test */
+ EPS_UINT32 validProtocol;
+
+ EPS_LOG_FUNCIN
+
+/*** Validate communication mode */
+ if( (commMode & EPS_COMM_UNID) && (commMode & EPS_COMM_BID) ){
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+ if( !(commMode & EPS_PROTOCOL_ALL) ){
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+
+ validProtocol = EPS_PROTOCOL_INVALID;
+#ifdef GCOMSW_PRT_USE_USB
+ validProtocol |= EPS_PROTOCOL_USB;
+#endif
+#ifdef GCOMSW_PRT_USE_LPR
+ validProtocol |= EPS_PROTOCOL_LPR;
+#endif
+#ifdef GCOMSW_PRT_USE_RAW
+ validProtocol |= EPS_PROTOCOL_RAW;
+#endif
+ if( EPS_PRT_PROTOCOL(commMode) & ~validProtocol ){
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+
+/*** Validate External Functions */
+ if(cmnFuncPtrs == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NULL )
+ }
+
+ if (cmnFuncPtrs->memAlloc == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_MEMALLOC )
+ }
+
+ if (cmnFuncPtrs->memFree == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_MEMFREE )
+ }
+#ifdef GCOMSW_EPSON_SLEEP
+ if (cmnFuncPtrs->sleep != NULL){
+#else
+ if (cmnFuncPtrs->sleep == NULL){
+#endif
+ EPS_RETURN( EPS_ERR_INV_FNCP_SLEEP )
+ }
+
+ if (cmnFuncPtrs->findCallback == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_FINDCALLBACK )
+ }
+
+ if (cmnFuncPtrs->getTime == NULL
+ && ((cmnFuncPtrs->lockSync == NULL) || (cmnFuncPtrs->unlockSync == NULL)) ){
+ EPS_RETURN( EPS_ERR_INV_FNCP_GETTIME )
+ }
+
+ /*** Check Memory Functions */
+ testptr = NULL;
+ testptr = (EPS_UINT8 *)cmnFuncPtrs->memAlloc(10);
+ if (testptr == NULL) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+ cmnFuncPtrs->memFree(testptr);
+
+
+/*** Validate USB Functions */
+#ifdef GCOMSW_PRT_USE_USB
+ if (commMode & EPS_PROTOCOL_USB) {
+ if (usbFuncPtrs == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NULL )
+ }
+
+ if (usbFuncPtrs->openPortal == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_OPENPORTAL )
+ }
+ if (usbFuncPtrs->closePortal == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_CLOSEPORTAL )
+ }
+ if (usbFuncPtrs->writePortal == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_WRITEPORTAL )
+ }
+
+ if ( commMode & EPS_COMM_BID ) {
+ if (usbFuncPtrs->readPortal == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_READPORTAL )
+ }
+ if (usbFuncPtrs->findFirst == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_FINDFIRST )
+ }
+ if (usbFuncPtrs->findNext == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_FINDNEXT )
+ }
+ if (usbFuncPtrs->findClose == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_FINDCLOSE )
+ }
+#if 0 /* not necessary */
+ if (cmnFuncPtrs->stateCallback == NULL)
+ return (EPS_ERR_CODE)EPS_ERR_INV_FNCP_NOTIFYCALLBACK;
+#endif
+ }
+ }
+#else
+ (void)usbFuncPtrs;
+#endif
+
+
+/*** Validate Net Functions */
+#ifdef GCOMSW_PRT_USE_NETWORK
+ if( (commMode & EPS_PROTOCOL_NET) ){
+ if (netFuncPtrs == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NULL )
+ }
+
+ if (netFuncPtrs->socket == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETSOCKET )
+ }
+ if (netFuncPtrs->close == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETCLOSE )
+ }
+ if (netFuncPtrs->connect == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETCONNECT )
+ }
+ if (netFuncPtrs->shutdown == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETSHUTDOWN )
+ }
+ if (netFuncPtrs->send == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETSEND )
+ }
+ if (netFuncPtrs->sendTo == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETSENDTO )
+ }
+ if (netFuncPtrs->receive == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETRECEIVE )
+ }
+ if (netFuncPtrs->receiveFrom == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETRECEIVEFROM )
+ }
+
+#ifdef GCOMSW_PRT_USE_LPR
+ if(commMode & EPS_PROTOCOL_LPR){
+ if (netFuncPtrs->setBroadcast == NULL){
+ EPS_RETURN( EPS_ERR_INV_FNCP_NETSETBROADCAST )
+ }
+ }
+#endif
+
+ }
+#else
+ (void)netFuncPtrs;
+#endif /* GCOMSW_PRT_USE_NETWORK */
+
+#ifdef GCOMSW_EPSON_SLEEP
+/*** Initial parameters for internal (simple) timing routine */
+/*** Used when system sleep routines are not available */
+ if (epsCmnFnc.sleep == serSleep) {
+ tdx = sleepTime = 0;
+ ftime(&sleepS);
+ while (!sleepTime) {
+ ftime(&sleepE);
+ sleepTime = 1000*(sleepE.time - sleepS.time) +
+ (sleepE.millitm - sleepS.millitm);
+ tdx++;
+ }
+ tdx *= 50;
+ for (idx = 1; idx < tdx; idx++) {ftime(&sleepE); }
+ sleepTime = 1000*(sleepE.time - sleepS.time) +
+ (sleepE.millitm - sleepS.millitm);
+ printJob.sleepSteps = tdx/sleepTime; /* Num steps for one msec */
+ if (!printJob.sleepSteps)
+ printJob.sleepSteps = -sleepTime/tdx; /* Num msec for each step */
+ }
+#endif /* GCOMSW_EPSON_SLEEP */
+
+ EPS_RETURN( EPS_ERR_NONE )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtFindPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* protocol EPS_INT32 I: traget protocol */
+/* timeout EPS_UINT32 I: find timeout */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Opened Communication) */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_PRINTER_NOT_FOUND - Printer not found (or error occur) */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* EPS_FIND_CANCELED - user discontinued it */
+/* */
+/* Description: */
+/* Find USB and network printers. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtFindPrinter (
+
+ EPS_INT32 protocol,
+ EPS_UINT32 timeout
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_PRINTER_NOT_FOUND; /* Return status of internal calls */
+ EPS_INT32 initProtocol = EPS_PRT_PROTOCOL(printJob.commMode);
+ EPS_INT32 tgtProtocol = EPS_PRT_PROTOCOL(protocol);
+
+ EPS_LOG_FUNCIN
+
+ if( (tgtProtocol | initProtocol) != initProtocol){
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+ g_FindProtocol = tgtProtocol;
+
+ /* Reset break flag */
+ if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
+ epsCmnFnc.lockSync();
+ g_FindBreak = FALSE;
+ epsCmnFnc.unlockSync();
+ }
+
+/***------------------------------------------------------------------------------------*/
+/*** USB find */
+/***------------------------------------------------------------------------------------*/
+#ifdef GCOMSW_PRT_USE_USB
+ if( protocol & EPS_PROTOCOL_USB ){
+
+ ret = usbFind( &timeout, printJob.commMode );
+
+ if( !(EPS_ERR_NONE == ret || EPS_ERR_PRINTER_NOT_FOUND == ret
+ || EPS_ERR_NOT_OPEN_IO == ret) ){
+ EPS_RETURN( ret )
+ }
+ }
+#endif
+
+/***------------------------------------------------------------------------------------*/
+/*** Net find */
+/***------------------------------------------------------------------------------------*/
+#ifdef GCOMSW_PRT_USE_NETWORK
+ if( protocol & EPS_PROTOCOL_NET ){
+
+ ret = FindNetPrinter( protocol, timeout, TRUE, NULL );
+
+ }
+#endif /* GCOMSW_PRT_USE_NETWORK */
+
+ if( epsPrinterList.num <= 0 ){
+ if(EPS_ERR_NONE == ret ||
+ EPS_ERR_PRINTER_NOT_USEFUL== ret ){
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+ } else{
+ if(EPS_ERR_PRINTER_NOT_FOUND == ret ||
+ EPS_ERR_PRINTER_NOT_USEFUL== ret ){
+ ret = EPS_ERR_NONE;
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtCancelFindPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* - void - */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_INVALID_CALL - invalid called */
+/* */
+/* Description: */
+/* Cancel epsFindPrinter(), epsProbePrinter(). */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtCancelFindPrinter(
+
+ void
+
+){
+ EPS_LOG_FUNCIN
+
+ if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
+ if( 0 == epsCmnFnc.lockSync() ){
+ g_FindBreak = TRUE;
+ epsCmnFnc.unlockSync();
+ }
+ EPS_RETURN( EPS_ERR_NONE )
+ } else{
+ EPS_RETURN( EPS_ERR_INVALID_CALL )
+ }
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtProbePrinterByID() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* probeParam EPS_PROBE* Pointer to a Prober parameter structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Opened Communication) */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* */
+/* Description: */
+/* Probe printer by ID string. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtProbePrinterByID (
+
+ const EPS_PROBE* probeParam
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_PRINTER_INN* innerPrinter = NULL;
+ EPS_UINT16 protocol = EPS_PROTOCOL_INVALID;
+ EPS_INT8 sParse[EPS_PRNID_BUFFSIZE];
+ EPS_INT8* pPos = NULL;
+ EPS_INT32 nSegCnt = 0;
+ EPS_UINT32 nTmp = 0;
+ EPS_INT8 defStr[EPS_PRNID_BUFFSIZE];
+
+ EPS_LOG_FUNCIN
+
+/*** Initialize Local Variables */
+ ret = EPS_ERR_NONE;
+
+/*** Parse ID String */
+ strcpy(sParse, probeParam->dsc.identify);
+
+ pPos = strtok(sParse, EPS_PID_SEP);
+ for(nSegCnt = 0; pPos != NULL && nSegCnt < EPS_PID_SEGNUM; nSegCnt++){
+ switch(nSegCnt){
+ case 0: /* P */
+ if( 0 != strcmp(pPos, EPS_PID_PRT) ){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
+ }
+ break;
+
+ case 1: /* Get protocol number */
+ sscanf(pPos, "%x", &nTmp);
+ if(nTmp == 0){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
+ }
+ protocol = (EPS_UINT16)nTmp;
+ break;
+
+ case 2: /* D */
+ if( 0 != strcmp(pPos, EPS_PID_DEF) ){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
+ }
+ break;
+
+ case 3: /* Get description string */
+ strcpy(defStr, pPos);
+ break;
+ }
+
+ pPos = strtok(NULL, EPS_PID_SEP);
+ }
+ if(nSegCnt < EPS_PID_SEGNUM){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
+ }
+
+ /* Reset break flag */
+ if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
+ epsCmnFnc.lockSync();
+ g_FindBreak = FALSE;
+ epsCmnFnc.unlockSync();
+ }
+
+/*** protocol depend probe */
+ switch( EPS_PRT_PROTOCOL( protocol ) ){
+#ifdef GCOMSW_PRT_USE_USB
+ case EPS_PROTOCOL_USB:
+ if( printJob.commMode & EPS_PROTOCOL_USB ){
+ ret = usbProbePrinterByID(defStr, probeParam->timeout, &innerPrinter);
+ } else{
+ ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
+ }
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_LPR
+ case EPS_PROTOCOL_LPR:
+ if( printJob.commMode & EPS_PROTOCOL_LPR ){
+ ret = lprProbePrinterByID(defStr, probeParam->timeout, &innerPrinter);
+ } else{
+ ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
+ }
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_RAW
+ case EPS_PROTOCOL_RAW:
+ if( printJob.commMode & EPS_PROTOCOL_RAW ){
+ ret = rawProbePrinterByID(defStr, probeParam->timeout, &innerPrinter);
+ } else{
+ ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
+ }
+ break;
+#endif
+
+ default:
+ ret = EPS_ERR_INV_ARG_PRINTER_ID;
+ }
+
+ if(EPS_ERR_NONE == ret){
+ innerPrinter->protocol = protocol | EPS_PRT_DIRECTION(printJob.commMode);
+ ret = prtRegPrinter( innerPrinter, TRUE );
+ if(EPS_FIND_CANCELED == ret){
+ ret = EPS_ERR_NONE;
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtProbePrinterByAddr() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* probeParam EPS_PROBE* Pointer to a Prober parameter structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Opened Communication) */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
+/* */
+/* Description: */
+/* Probe network printer by IP Address. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtProbePrinterByAddr (
+
+ const EPS_PROBE* probeParam
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_PRINTER_NOT_FOUND; /* Return status of internal calls */
+ EPS_INT32 initProtocol = EPS_PRT_PROTOCOL(printJob.commMode);
+ EPS_INT32 tgtProtocol = EPS_PROTOCOL_INVALID;
+
+ EPS_LOG_FUNCIN
+
+/*** Validate input parameters */
+ if (NULL == probeParam) {
+ EPS_RETURN( EPS_ERR_INV_ARG_PROBEINFO )
+ }
+ tgtProtocol = EPS_PRT_PROTOCOL(probeParam->dsc.addr.protocol);
+ if( (tgtProtocol | initProtocol) != initProtocol){
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+ g_FindProtocol = tgtProtocol;
+
+ /* Reset break flag */
+ if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
+ epsCmnFnc.lockSync();
+ g_FindBreak = FALSE;
+ epsCmnFnc.unlockSync();
+ }
+
+ if( IsValidAddress(probeParam->dsc.addr.address) ){
+#if defined(GCOMSW_PRT_USE_NETWORK)
+ /***--------------------------------------------------------------------------------*/
+ /*** If IPAddress, Probe network printer */
+ /***--------------------------------------------------------------------------------*/
+ if( tgtProtocol & EPS_PROTOCOL_NET ){
+ ret = FindNetPrinter(tgtProtocol, probeParam->timeout, FALSE, probeParam->dsc.addr.address);
+ if(EPS_FIND_CANCELED == ret){
+ ret = EPS_ERR_NONE;
+ }
+ } else{
+ ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
+ }
+#else
+ ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
+#endif /* GCOMSW_PRT_USE_NETWORK */
+ } else{
+ ret = EPS_ERR_INV_ARG_PRINTER_ADDR;
+ }
+
+ if( epsPrinterList.num <= 0 ){
+ if(EPS_ERR_NONE == ret){
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+ } else{
+ if(EPS_ERR_PRINTER_NOT_FOUND == ret ||
+ EPS_ERR_PRINTER_NOT_USEFUL== ret ){
+ ret = EPS_ERR_NONE;
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtSetupJobFunctions() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer const EPS_PRINTER* I: Pointer to a target printer info. */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* */
+/* Description: */
+/* construct job function table. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtSetupJobFunctions (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_JOB_FUNCS* pFuncs
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+
+ EPS_LOG_FUNCIN
+
+ switch( EPS_PRT_PROTOCOL( printer->protocol ) ){
+#ifdef GCOMSW_PRT_USE_USB
+ case EPS_PROTOCOL_USB:
+ pFuncs->StartJob = &usbStartJob;
+ pFuncs->EndJob = &usbEndJob;
+ pFuncs->RestartJob = &usbRestartJob;
+ pFuncs->WriteData = &usbWritePrintData;
+ pFuncs->ResetPrinter = &usbResetPrinter;
+ pFuncs->MonitorStatus = &usbGetJobStatus;
+ pFuncs->GetStatus = &usbGetStatus;
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_LPR
+ case EPS_PROTOCOL_LPR:
+ pFuncs->StartJob = &lprStartJob;
+ pFuncs->EndJob = &lprEndJob;
+ pFuncs->RestartJob = &lprRestartJob;
+ pFuncs->WriteData = &lprWritePrintData;
+ pFuncs->ResetPrinter = &lprResetPrinter;
+ pFuncs->StartPage = &lprStartPage;
+ pFuncs->EndPage = &lprEndPage;
+ pFuncs->MonitorStatus = &lprGetJobStatus;
+ pFuncs->GetStatus = &lprGetStatus;
+ lprSetupSTFunctions(printer);
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_RAW
+ case EPS_PROTOCOL_RAW:
+ pFuncs->StartJob = &rawStartJob;
+ pFuncs->EndJob = &rawEndJob;
+ pFuncs->RestartJob = &rawRestartJob;
+ pFuncs->WriteData = &rawWritePrintData;
+ pFuncs->ResetPrinter = &rawResetPrinter;
+ pFuncs->StartPage = &rawStartPage;
+ pFuncs->EndPage = &rawEndPage;
+ pFuncs->MonitorStatus = &rawGetJobStatus;
+ pFuncs->GetStatus = &rawGetStatus;
+ rawSetupSTFunctions(printer);
+ break;
+#endif
+
+ default:
+ ret = EPS_ERR_OPR_FAIL;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtGetInkStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* status EPS_STATUS* Pointer to the printer status. */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
+/* EPS_ERR_COMM_ERROR - Failed to send command */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPS_ERR_NOT_CLOSE_IO - Cannot Close I/O Portal */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* */
+/* Description: */
+/* Gets the Ink Infomation. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtGetInkInfo (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INK_INFO* info
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_STATUS_INFO lclStatus;
+ EPS_INT32 idx;
+
+ EPS_LOG_FUNCIN
+
+/*** Validate communication mode */
+ if ( !EPS_IS_BI_PROTOCOL(printer->protocol) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT )
+ }
+
+ memset(&lclStatus, 0, sizeof(lclStatus));
+/*** protocol GetStatus */
+ switch( EPS_PRT_PROTOCOL( printer->protocol ) ){
+#ifdef GCOMSW_PRT_USE_USB
+ case EPS_PROTOCOL_USB:
+ ret = usbGetStatus(&lclStatus, NULL, NULL);
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_LPR
+ case EPS_PROTOCOL_LPR:
+ ret = lprGetInkInfo(&lclStatus);
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_RAW
+ case EPS_PROTOCOL_RAW:
+ ret = rawGetInkInfo(&lclStatus);
+ break;
+#endif
+
+ default:
+ ret = EPS_ERR_OPR_FAIL;
+ }
+
+ if(EPS_ERR_NONE == ret
+ && EPS_SUBPROTOCOL_PCDEV != EPS_PRT_SUBPROTOCOL(printer->protocol) ){
+ info->number = lclStatus.nInkNo;
+ for(idx=0; idx < EPS_INK_NUM; idx++) {
+ info->colors[idx] = lclStatus.nColorType[idx];
+ info->remaining[idx] = lclStatus.nColor[idx];
+ }
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtGetPMString() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
+/* type EPS_INT32 I: PM kind 1 or 2 */
+/* pString EPS_UINT8* O: Pointer to PM String */
+/* bufSize EPS_INT32 I: pString buffer size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
+/* */
+/* Description: */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtGetPMString (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 type,
+ EPS_UINT8* pString,
+ EPS_INT32* bufSize
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+
+ EPS_LOG_FUNCIN
+
+ switch( EPS_PRT_PROTOCOL( printer->protocol ) ){
+#ifdef GCOMSW_PRT_USE_USB
+ case EPS_PROTOCOL_USB:
+ ret = usbGetPMString(printer, type, pString, bufSize);
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_LPR
+ case EPS_PROTOCOL_LPR:
+ ret = lprGetPMString(printer, type, pString, bufSize);
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_RAW
+ case EPS_PROTOCOL_RAW:
+ ret = rawGetPMString(printer, type, pString, bufSize);
+ break;
+#endif
+
+ default:
+ ret = EPS_ERR_OPR_FAIL;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtRegPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER* I:Data structure containing printer information. */
+/* bNotify EPS_BOOL I:This item need notify. */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Printer settled into one of the requested state(s)*/
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_FIND_CANCELED - cancel find by user */
+/* */
+/* Description: */
+/* Registers a new printer with the global linked list managed by this module. */
+/* And Notify to user. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtRegPrinter(
+
+ EPS_PRINTER_INN* printer,
+ EPS_BOOL bNotify
+
+){
+/*** Declare Variables Local to Routine */
+ EPS_PRINTER usrPrinter; /* for user notify */
+ EPS_PL_NODE* current = NULL;
+ EPS_BOOL registered = FALSE;
+
+ EPS_LOG_FUNCIN
+
+ EPS_DBGPRINT( ("%X / %s\n", printer->protocol, printer->location) )
+
+ if (printer->protocol == EPS_PROTOCOL_INVALID){
+ EPS_RETURN( EPS_ERR_OPR_FAIL )
+ }
+
+ if( NULL == epsPrinterList.root){
+ /*** This is the first printer in the list. */
+ epsPrinterList.root = (EPS_PL_NODE*)EPS_ALLOC(sizeof(EPS_PL_NODE));
+ if(epsPrinterList.root == NULL) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+ epsPrinterList.num = 1;
+
+ current = epsPrinterList.root;
+ current->printer = printer;
+ current->next = NULL;
+
+ } else {
+
+ current = epsPrinterList.root;
+ while( current ){
+ /* If we've found a printer in the list that matches the module's printer, */
+ if( 0 == strcmp(printer->location, current->printer->location)){
+ if(0 == strcmp(printer->modelName, current->printer->modelName)){
+ registered = TRUE;
+ }
+ }
+
+ if (registered ){
+
+ /* And the new protocol has priority over the old one... */
+ if (EPS_PRT_PROTOCOL(current->printer->protocol) > EPS_PRT_PROTOCOL(printer->protocol) ) {
+ /* Prioritize the protocols. The lower-numbered protocol always */
+ /* has precendence over the higher-numbered one (1 outranks 3). */
+ current->printer->protocol = printer->protocol;
+
+ /* Replase protocol */
+ EPS_DBGPRINT( ("Discover %d %s %s (Upgrade)\n", printer->protocol, printer->modelName, printer->printerID) )
+ EPS_SAFE_RELEASE( current->printer->protocolInfo );
+ EPS_SAFE_RELEASE( current->printer );
+ current->printer = printer;
+ break;
+ } else{
+ /* In this case, the current protocol already has priority. Simply return. */
+ EPS_SAFE_RELEASE( printer->protocolInfo );
+ EPS_SAFE_RELEASE( printer );
+ EPS_RETURN( EPS_ERR_NONE )
+ }
+ }
+
+ if( NULL == current->next){
+ break;
+ }
+ current = current->next;
+ }
+
+ /* If we've reached this part of the code, it means we haven't found the printer. */
+ /* Time to add a new node to the list. */
+ /* The variable "current" is right now pointing to the last member of the list. */
+ if( !registered ){
+ /* Allocate a new printer on the end of the linked list. */
+ current->next = (EPS_PL_NODE*)EPS_ALLOC(sizeof(EPS_PL_NODE));
+ if(current->next == NULL) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ /* Fill in the list node. */
+ current->next->printer = printer;
+ current->next->next = NULL;
+ epsPrinterList.num++;
+
+ current = current->next;
+ }
+ }
+
+ EPS_DBGPRINT( ("Discover x%X (x%X) %s %s\n", printer->protocol, printer->supportFunc, printer->modelName, printer->printerID) )
+
+ if( TRUE == bNotify ){
+ MakePrinterStructure(&usrPrinter, printer);
+
+ if( EPS_USER_CANCEL == epsCmnFnc.findCallback(usrPrinter) ){
+ EPS_RETURN( EPS_FIND_CANCELED )
+ }
+ }
+
+ EPS_RETURN( EPS_ERR_NONE )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtIsRegistered() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Address EPS_INT8* IP Address. */
+/* modelName EPS_INT8* Printer model name. */
+/* Protocol EPS_INT32 Protocol ID. */
+/* */
+/* Return value: */
+/* TRUE (registered), FALSE(not registered). */
+/* */
+/* Description: */
+/* Whether the printer has registered is confirmed. */
+/* */
+/*******************************************|********************************************/
+EPS_BOOL prtIsRegistered(
+
+ const EPS_INT8 *Address,
+ const EPS_INT8 *modelName,
+ EPS_INT32 Protocol
+
+){
+ EPS_PL_NODE* current = epsPrinterList.root;
+ EPS_BOOL bMatch = FALSE;
+
+ EPS_LOG_FUNCIN
+
+ while(NULL != current) {
+ /* If we've found a printer in the list that matches the module's printer, */
+ bMatch = FALSE;
+ if( 0 == strcmp(current->printer->location, Address) ){
+ if(NULL != modelName){
+ if( 0 == strcmp(current->printer->modelName, modelName) ){
+ bMatch = TRUE;
+ }
+ } else{
+ bMatch = TRUE;
+ }
+ }
+
+ if(TRUE == bMatch){
+ /* And the new protocol has priority over the old one... */
+ if (EPS_PRT_PROTOCOL(current->printer->protocol) <= EPS_PRT_PROTOCOL(Protocol)) {
+ EPS_RETURN( TRUE )
+ } else{
+ /* already registered However it's low level protocol */
+ EPS_RETURN( FALSE )
+ }
+ }
+
+ current = current->next;
+ }
+
+ EPS_RETURN( FALSE )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtAddUsrPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* usrPrinter EPS_PRINTER* I: User specified printer. */
+/* printer EPS_PRINTER* O: Internal printer information. */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "usrPrinter.protocol" */
+/* EPS_ERR_INV_ARG_PRINTER_ADDR - Invalid format " printer.location" */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_INV_PRINT_LANGUAGE - Invalid argument "usrPrinter.language" */
+/* */
+/* Description: */
+/* Register a user specified printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtAddUsrPrinter(
+
+ const EPS_PRINTER* usrPrinter,
+ EPS_PRINTER_INN** printer
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_INT32 initProtocol = EPS_PRT_PROTOCOL(printJob.commMode);
+ EPS_INT32 tgtProtocol = EPS_PRT_PROTOCOL(usrPrinter->protocol);
+ EPS_INT8 address[EPS_ADDR_BUFFSIZE];
+ EPS_INT8* p = NULL;
+ EPS_INT32 nPort = 0;
+ EPS_PRINTER_INN* innerPrinter = NULL;
+
+ EPS_LOG_FUNCIN
+
+ *printer = NULL;
+
+ /*** Validate input parameters */
+ if( (tgtProtocol | initProtocol) != initProtocol){ /* Not Init protocol */
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+ if( tgtProtocol & EPS_PROTOCOL_USB ){ /* USB */
+
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+ if( memGetBitCount(tgtProtocol) > 1 ){ /* Multi protocol */
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+ if( '\0' == usrPrinter->location[0] ){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ADDR )
+ }
+ if( EPS_ADDR_BUFFSIZE < strlen(usrPrinter->location) ){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ADDR )
+ }
+
+ if( !(EPS_LANG_ESCPR == usrPrinter->language ||
+#ifdef GCOMSW_CMD_ESCPAGE_S
+ EPS_LANG_ESCPAGE_S == usrPrinter->language ||
+#endif
+ EPS_LANG_ESCPAGE == usrPrinter->language ||
+ EPS_LANG_ESCPAGE_COLOR == usrPrinter->language ) ){
+ EPS_RETURN( EPS_ERR_INV_PRINT_LANGUAGE );
+ }
+
+ /*** pase location */
+ strcpy(address, usrPrinter->location);
+ p = strchr(address, ':');
+ if( NULL != p ){
+ *p = '\0';
+ p++; /* 1 = ':' */
+ sscanf(p, "%d", &nPort);
+ } else{
+ /* Default Port */
+ if( tgtProtocol & EPS_PROTOCOL_LPR ){
+#ifdef GCOMSW_PRT_USE_LPR
+ nPort = lprGetDefautiPort();
+#else
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+#endif
+ } else if( tgtProtocol & EPS_PROTOCOL_RAW ){
+#ifdef GCOMSW_PRT_USE_RAW
+ nPort = rawGetDefautiPort();
+#else
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+#endif
+ } else{
+ EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
+ }
+ }
+ if( FALSE == IsValidAddress( address ) ){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ADDR )
+ }
+
+ /*** Create new printer */
+ innerPrinter = (EPS_PRINTER_INN*)EPS_ALLOC(sizeof(EPS_PRINTER_INN));
+ if( NULL == innerPrinter ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ memset(innerPrinter, 0x00, sizeof(EPS_PRINTER_INN));
+
+ strcpy(innerPrinter->location, address);
+ innerPrinter->printPort = (EPS_UINT16)nPort;
+ innerPrinter->protocol = usrPrinter->protocol;
+ innerPrinter->supportFunc = EPS_SPF_RGBPRINT | EPS_SPF_JPGPRINT;
+ innerPrinter->JpgMax = EPS_JPEG_SIZE_UNLIMIT;
+ innerPrinter->language = usrPrinter->language;
+ strcpy(innerPrinter->modelName, usrPrinter->modelName);
+ /* innerPrinter->manufacturerName */
+ /* innerPrinter->friendlyName */
+ /* innerPrinter->printerID; */
+ /* innerPrinter->protocolInfo; */
+
+ /*** Append to printer lsit */
+ ret = prtRegPrinter(innerPrinter, FALSE);
+ if( EPS_ERR_NONE == ret ){
+ *printer = innerPrinter;
+ }
+
+ EPS_RETURN( ret )
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtGetInnerPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER Pointer to public infomation structure */
+/* */
+/* Return value: */
+/* EPS_PRINTER_INN Pointer to private infomation structure */
+/* */
+/* Description: */
+/* Get private infomation of printer. */
+/* */
+/*******************************************|********************************************/
+EPS_PRINTER_INN* prtGetInnerPrinter(
+
+ const EPS_PRINTER* printer
+
+){
+ EPS_PL_NODE* pCur = epsPrinterList.root;
+ EPS_PRINTER_INN* innerPrinter = NULL;
+
+ /* collates it with found printer */
+ while(NULL != pCur){
+ if(0 == strcmp(printer->modelName, pCur->printer->modelName)
+ && 0 == strcmp(printer->location, pCur->printer->location) ){
+ innerPrinter = pCur->printer;
+ break;
+ }
+ pCur = pCur->next;
+ }
+
+ return innerPrinter;
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtClearPrinterList() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* void */
+/* */
+/* Return value: */
+/* void */
+/* */
+/* Description: */
+/* Crean up inside list of printer structure . */
+/* */
+/*******************************************|********************************************/
+void prtClearPrinterList(
+
+ void
+
+){
+ EPS_PL_NODE* pCur = epsPrinterList.root;
+ EPS_PL_NODE* pNext = NULL;
+
+ EPS_LOG_FUNCIN
+
+ /* Clear stock printer list */
+ while(NULL != pCur){
+ pNext = pCur->next;
+
+ prtClearSupportedMedia(pCur->printer);
+
+ EPS_SAFE_RELEASE( pCur->printer->protocolInfo );
+ EPS_SAFE_RELEASE( pCur->printer );
+ EPS_SAFE_RELEASE( pCur );
+
+ pCur = pNext;
+ }
+
+ epsPrinterList.num = 0;
+ epsPrinterList.root = NULL;
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtClearSupportedMedia() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a printer info structure */
+/* */
+/* Return value: */
+/* void */
+/* */
+/* Description: */
+/* Crean up inside list of supported media structure. */
+/* */
+/*******************************************|********************************************/
+void prtClearSupportedMedia(
+
+ EPS_PRINTER_INN* printer
+
+){
+ EPS_INT32 idx;
+
+ EPS_LOG_FUNCIN
+
+ /* Clear "supportedMedia" */
+ if( NULL == printer ){
+ return;
+ }
+
+#ifdef GCOMSW_CMD_ESCPAGE
+ if(EPS_LANG_ESCPR == printer->language ){
+#endif
+ /*** ESC/P-R ***/
+ if( NULL != printer->supportedMedia.sizeList ){
+ for(idx = 0; idx < printer->supportedMedia.numSizes; idx++) {
+ EPS_SAFE_RELEASE(printer->supportedMedia.sizeList[idx].typeList);
+ }
+ EPS_SAFE_RELEASE(printer->supportedMedia.sizeList);
+ }
+#ifdef GCOMSW_CMD_ESCPAGE
+ } else{
+ /*** ESC/Page ***/
+ pageClearSupportedMedia(printer);
+ }
+#endif
+
+ printer->supportedMedia.numSizes = 0;
+ printer->supportedMedia.JpegSizeLimit = EPS_JPEG_SIZE_MAX; /* lowest guarantee */
+ printer->supportedMedia.resolution = EPS_IR_360X360;
+
+ EPS_RETURN_VOID
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtSetIdStr() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I/O: Pointer to a printer info structure */
+/* idString EPS_INT8* I: protocol depended unique string */
+/* */
+/* Return value: */
+/* void */
+/* */
+/* Description: */
+/* Set the Printer ID. */
+/* */
+/*******************************************|********************************************/
+void prtSetIdStr(
+
+ EPS_PRINTER_INN* printer,
+ const EPS_INT8* idString
+
+){
+ sprintf(printer->printerID, EPS_PRINTER_ID_STR,
+ EPS_PRT_PROTOCOL_EX(printer->protocol), idString);
+
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: prtRecoverPE() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* void - - */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Recovered successfully */
+/* EPS_ERR_COMM_ERROR - Recovery failed */
+/* */
+/* Description: */
+/* Tries to recover from the paper end error */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE prtRecoverPE (
+
+ void
+
+){
+ EPS_ERR_CODE ret;
+
+ EPS_LOG_FUNCIN
+
+ switch( EPS_PRT_PROTOCOL( printJob.printer->protocol ) ){
+#ifdef GCOMSW_PRT_USE_USB
+ case EPS_PROTOCOL_USB:
+ ret = usbMechCommand(EPS_CBTCOM_PE);
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_LPR
+ case EPS_PROTOCOL_LPR:
+ ret = lprMechCommand(printJob.printer, EPS_CBTCOM_PE);
+ break;
+#endif
+
+#ifdef GCOMSW_PRT_USE_RAW
+ case EPS_PROTOCOL_RAW:
+ ret = rawMechCommand(printJob.printer, EPS_CBTCOM_PE);
+ break;
+#endif
+ default:
+ EPS_RETURN( EPS_ERR_NONE ) /* Other protocol Not Support recover command */
+ }
+
+ EPS_RETURN( ret )
+}
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#ifdef GCOMSW_PRT_USE_NETWORK
+/*******************************************|********************************************/
+/* */
+/* Function name: FindNetPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* protocol EPS_INT32 I: traget protocol */
+/* timeout EPS_UINT32 I: find timeout */
+/* plural EPS_BOOL I: TRUE= find plural printer / FALSE= one printer */
+/* address EPS_INT8* I: send discover message address. */
+/* (If plural=TRUE, this is NULL) */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (Opened Communication) */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_PRINTER_NOT_FOUND - Printer not found (or error occur) */
+/* EPS_ERR_COMM_ERROR - socket error */
+/* */
+/* EPS_FIND_CANCELED - user discontinued it */
+/* */
+/* Description: */
+/* Find network printers. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE FindNetPrinter (
+
+ EPS_INT32 protocol,
+ EPS_UINT32 timeout,
+ EPS_BOOL plural,
+ const EPS_INT8* address
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_PRINTER_NOT_FOUND; /* Return status of internal calls */
+ EPS_PRINTER_INN* innerPrinter = NULL;
+
+ EPS_FIND_FUNCS* pProtocolFncs = NULL;
+ EPS_FIND_FUNCS* pFncs = NULL;
+ EPS_UINT32 tmStart, tmNow, tmSpan, tmReq;
+ EPS_INT32 nProtocolCnt = 0;
+ EPS_INT32 nCnt = 0;
+ EPS_BOOL bBreak = FALSE;
+
+ EPS_LOG_FUNCIN
+
+ if(epsCmnFnc.getTime){
+ tmStart = epsCmnFnc.getTime();
+ tmNow = tmSpan = tmReq = 0;
+ } else{
+ timeout = tmStart = tmNow = tmSpan = tmReq = 0;
+ }
+
+#ifdef GCOMSW_PRT_USE_LPR
+ if(protocol & EPS_PROTOCOL_LPR) nProtocolCnt++;
+#endif
+#ifdef GCOMSW_PRT_USE_RAW
+ if( (protocol & EPS_PROTOCOL_RAW) && !(protocol & EPS_PROTOCOL_LPR) ) nProtocolCnt++;
+#endif
+ if(0 == nProtocolCnt){
+ EPS_RETURN( EPS_ERR_PRINTER_NOT_FOUND )
+ }
+
+ /* Setup net Find functions */
+ pProtocolFncs = (EPS_FIND_FUNCS*)EPS_ALLOC(sizeof(EPS_FIND_FUNCS)*nProtocolCnt);
+ if(NULL == pProtocolFncs){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
+ }
+
+ pFncs = pProtocolFncs;
+
+#ifdef GCOMSW_PRT_USE_LPR
+ if(protocol & EPS_PROTOCOL_LPR){
+ pFncs->fncStart = &lprFindStart;
+ pFncs->fncCheck = &lprFind;
+ pFncs->fncEnd = &lprFindEnd;
+ pFncs->sock = EPS_INVALID_SOCKET;
+ if(plural){
+ strcpy(pFncs->address, EPSNET_UDP_BROADCAST_ADDR);
+ } else{
+ strcpy(pFncs->address, address);
+ }
+ pFncs++;
+ }
+#endif
+#ifdef GCOMSW_PRT_USE_RAW
+ if( (protocol & EPS_PROTOCOL_RAW) && !(protocol & EPS_PROTOCOL_LPR) ){
+ pFncs->fncStart = &rawFindStart;
+ pFncs->fncCheck = &rawFind;
+ pFncs->fncEnd = &rawFindEnd;
+ pFncs->sock = EPS_INVALID_SOCKET;
+ if(plural){
+ strcpy(pFncs->address, EPSNET_UDP_BROADCAST_ADDR);
+ } else{
+ strcpy(pFncs->address, address);
+ }
+ }
+#endif
+
+ /* Start (send discover message) */
+ pFncs = pProtocolFncs;
+ ret = EPS_ERR_NONE;
+ for(nCnt = 0; (nCnt < nProtocolCnt) && (ret == EPS_ERR_NONE); nCnt++, pFncs++){
+ ret = pFncs->fncStart( &(pFncs->sock), pFncs->address, plural );
+ }
+
+ /* Check response */
+ if( EPS_ERR_NONE == ret){
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+ while( (EPS_ERR_PRINTER_NOT_FOUND == ret || EPS_ERR_PRINTER_NOT_USEFUL == ret) && !bBreak ){
+ pFncs = pProtocolFncs;
+ for(nCnt = 0; nCnt < nProtocolCnt; ){
+ innerPrinter = NULL;
+ ret = pFncs->fncCheck(pFncs->sock, &innerPrinter);
+
+ if( EPS_COM_NOT_RECEIVE == ret ){
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ } else{
+ tmReq = 0;
+ }
+
+ if( EPS_ERR_NONE == ret ){
+ innerPrinter->protocol |= EPS_PRT_DIRECTION(printJob.commMode);
+
+ ret = prtRegPrinter( innerPrinter, TRUE );
+
+ if(EPS_FIND_CANCELED == ret){
+ break;
+ } else if(FALSE == plural){
+ /* find one printer */
+ bBreak = TRUE;
+ break;
+ }
+
+ } else if(EPS_ERR_PRINTER_NOT_FOUND == ret ){
+ /* next protocol */
+ nCnt++;
+ pFncs++;
+ } else if(EPS_ERR_PRINTER_NOT_USEFUL == ret ){
+ if(FALSE == plural){
+ /* find one printer */
+ bBreak = TRUE;
+ break;
+ }
+ /* next protocol */
+ nCnt++;
+ pFncs++;
+ } else{
+ bBreak = TRUE;
+ break;
+ }
+ }
+ if(bBreak)break;
+
+ /* epsCancelFindPriter() */
+ if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
+ if( 0 == epsCmnFnc.lockSync() ){
+ if( g_FindBreak ){
+ epsCmnFnc.unlockSync();
+ bBreak = TRUE;
+ break;
+ }
+ epsCmnFnc.unlockSync();
+ }
+ }
+
+ /* Timeout */
+ if(timeout > 0){
+ tmNow = epsCmnFnc.getTime();
+ tmSpan = (EPS_UINT32)(tmNow - tmStart);
+ /*EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )*/
+ if( tmSpan >= timeout ){
+ bBreak = TRUE;
+ break;
+ }
+ }
+
+ /* re isuue request */
+ /*EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )*/
+ if( (EPS_ERR_PRINTER_NOT_FOUND == ret ||
+ EPS_ERR_PRINTER_NOT_USEFUL == ret) && epsCmnFnc.getTime )
+ {
+ tmNow = epsCmnFnc.getTime();
+ if( 0 == tmReq ){
+ tmReq = tmNow;
+ } else{
+ /* beef up */
+ if( EPSNET_FIND_REREQUEST_TIME <= (EPS_UINT32)(tmNow - tmReq) ){
+ EPS_DBGPRINT( ("beef up TM %u - %u <> %u\n", tmNow, tmReq, (EPS_UINT32)(tmNow - tmReq)) )
+ pFncs = pProtocolFncs;
+ ret = EPS_ERR_NONE;
+ for(nCnt = 0; (nCnt < nProtocolCnt) && (ret == EPS_ERR_NONE); nCnt++, pFncs++){
+ ret = pFncs->fncStart( &(pFncs->sock), pFncs->address, plural );
+ }
+ tmReq = 0;
+ if( EPS_ERR_NONE == ret){
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+ }
+
+ }
+ }
+ }
+
+ /* End */
+ pFncs = pProtocolFncs;
+ for(nCnt = 0; (nCnt < nProtocolCnt); nCnt++, pFncs++){
+ pFncs->fncEnd( pFncs->sock );
+ }
+
+ EPS_SAFE_RELEASE(pProtocolFncs);
+
+ EPS_RETURN( ret )
+}
+
+#endif /* GCOMSW_PRT_USE_NETWORK */
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: MakePrinterStructure() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* dst EPS_PRINTER* O: Printer information */
+/* src EPS_PRINTER_INN* I: Printer information internal */
+/* */
+/* Return value: */
+/* void */
+/* */
+/* Description: */
+/* Copy printer information. */
+/* */
+/*******************************************|********************************************/
+static void MakePrinterStructure(
+
+ EPS_PRINTER* dst,
+ EPS_PRINTER_INN* src
+
+){
+ EPS_DBGPRINT(("%s : %d\n", src->modelName, src->protocol))
+ dst->protocol = EPS_PRT_PROTOCOL(src->protocol);
+ dst->supportFunc = src->supportFunc;
+ dst->language = src->language;
+ strcpy(dst->location, src->location);
+ strcpy(dst->macAddress, src->macAddress);
+ strcpy(dst->manufacturerName, src->manufacturerName);
+ strcpy(dst->modelName, src->modelName);
+ strcpy(dst->friendlyName, src->friendlyName);
+ strcpy(dst->printerID, src->printerID);
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: IsValidAddress() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* addr EPS_INT8* I: IP Address */
+/* */
+/* Return value: */
+/* TRUE - valid */
+/* FALSE - invalid */
+/* */
+/* Description: */
+/* Validation of IP(v4) Address. */
+/* */
+/*******************************************|********************************************/
+static EPS_BOOL IsValidAddress(
+
+ const EPS_INT8* addr
+
+){
+#define EPS_IPSEGNUM (4)
+
+ EPS_UINT32 nSeg[EPS_IPSEGNUM];
+ EPS_INT16 nCnt;
+
+ memset(nSeg, 0xFF, sizeof(EPS_UINT32)*EPS_IPSEGNUM);
+
+ sscanf(addr, "%d.%d.%d.%d", &nSeg[0], &nSeg[1], &nSeg[2], &nSeg[3]);
+
+ for(nCnt = 0; nCnt < EPS_IPSEGNUM; nCnt++){
+ if(nSeg[nCnt] > 255){
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/*________________________________ epson-protocol.c _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
diff --git a/lib/epson-protocol.h b/lib/epson-protocol.h
new file mode 100644
index 0000000..765ed0b
--- /dev/null
+++ b/lib/epson-protocol.h
@@ -0,0 +1,171 @@
+/*________________________________ epson-protocol.h _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson Protocol layer Module Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef _EPSON_PROROCOL_H_
+#define _EPSON_PROROCOL_H_
+#ifdef __cplusplus
+extern "C" {
+#endif /* def __cplusplus */
+
+/*------------------------------- Local Compiler Switch --------------------------------*/
+/*******************************************|********************************************/
+/* #define GCOMSW_PRT_USE_USB 1*/ /* Use USB Communication */
+/* #define GCOMSW_PRT_USE_LPR 1*/ /* Use LPR Communication */
+/* #define GCOMSW_PRT_USE_RAW 1*/ /* Use RawPort Communication */
+
+#if defined(GCOMSW_PRT_USE_LPR) || defined(GCOMSW_PRT_USE_RAW)
+#define GCOMSW_PRT_USE_NETWORK
+#endif
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+#include "epson-escpr-pvt.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+#define EPS_USB_NAME "USB"
+
+#define EPSNET_UDP_BROADCAST_ADDR "255.255.255.255"
+#define EPSNET_UPNP_MULTICAST_ADDR "239.255.255.250"
+#define EPSNET_NUM_DISCOVERIES (3) /* times to send discovery msg */
+#define EPSNET_RECV_TIMEOUT (5000) /* default receive tiomeout */
+#define EPSNET_FIND_RECV_TIMEOUT (100) /* discover receive tiomeout */
+#define EPSNET_STAT_RECV_TIMEOUT (1000) /* status receive tiomeout */
+#define EPSNET_SEND_TIMEOUT (500) /* default send tiomeout */
+#define EPSNET_BAND_SEND_TIMEOUT (100) /* band data send tiomeout */
+#define EPSNET_BAND_SEND_TIMEOUTL (3*60*1000) /* band data send tiomeout */
+#define EPSNET_FIND_REREQUEST_TIME (500) /* request re issue */
+#define EPSNET_MAX_PATH (255) /* path buffer length */
+#define EPSNET_STAT_RETRY (5) /* getstatus retry count */
+
+
+ /*** PrinterID string format */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_PID_PRT "P"
+#define EPS_PID_DEF "D"
+#define EPS_PID_SEP "#"
+#define EPS_PID_SEGNUM (4)
+#define EPS_PRINTER_ID_STR EPS_PID_PRT EPS_PID_SEP "%04X" EPS_PID_SEP EPS_PID_DEF EPS_PID_SEP "%s"
+ /* P#xx#D#sssssssss */
+
+ /* USB ID String 'D' parameter */
+#define EPS_USBID_SEP "."
+#define EPS_USBID_SEGNUM (3)
+#define EPS_USB_IDPRM_STR "%04X" EPS_USBID_SEP "%04X" EPS_USBID_SEP "%s"
+ /* [VID].[PID].[ModelName] */
+
+ /* Net ID String 'D' parameter */
+#define EPS_NETID_SEP "?"
+#define EPS_NETID_SEGNUM (2)
+#define EPS_NET_IDPRM_STR "%s" EPS_NETID_SEP "%s"
+ /* [ModelName]?[uuid] */
+
+/*----------------------------------- Error Code -------------------------------------*/
+/*******************************************|********************************************/
+#define EPS_COM_TINEOUT (-2) /* recv time out */
+#define EPS_COM_READ_MORE (-3) /* need more receive */
+#define EPS_COM_ERR_REPLY (-4) /* error reply */
+#define EPS_COM_NEXT_RECORD (-5) /* mib next record received */
+#define EPS_COM_NOT_RECEIVE (-6) /* not recieve */
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+
+/* Print Job functions */
+typedef EPS_ERR_CODE (*PRT_StartJob )(void );
+typedef EPS_ERR_CODE (*PRT_EndJob )(void );
+typedef EPS_ERR_CODE (*PRT_RestartJob )(void );
+typedef EPS_ERR_CODE (*PRT_WritePrintData)(const EPS_UINT8*, EPS_UINT32, EPS_UINT32* );
+typedef EPS_ERR_CODE (*PRT_ResetPrinter )(void );
+typedef EPS_ERR_CODE (*PRT_StartPage )(void );
+typedef EPS_ERR_CODE (*PRT_EndPage )(void );
+typedef EPS_ERR_CODE (*PRT_MonitorStatus )(EPS_STATUS_INFO* );
+typedef EPS_ERR_CODE (*PRT_GetStatus )(EPS_STATUS_INFO*, EPS_BOOL*, EPS_BOOL* );
+
+typedef struct tagEPS_JOB_FUNCS {
+ PRT_StartJob StartJob;
+ PRT_EndJob EndJob;
+ PRT_RestartJob RestartJob;
+ PRT_WritePrintData WriteData;
+ PRT_ResetPrinter ResetPrinter;
+ PRT_StartPage StartPage;
+ PRT_EndPage EndPage;
+ PRT_MonitorStatus MonitorStatus;
+ PRT_GetStatus GetStatus;
+}EPS_JOB_FUNCS;
+
+#define PRT_INVOKE_JOBFNC( f, prm ) ((NULL != f)?f prm:EPS_ERR_NONE)
+
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+ /*** Initialize */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE prtFunctionCheck (EPS_INT32, const EPS_USB_FUNC*,
+ const EPS_NET_FUNC*, const EPS_CMN_FUNC* );
+
+ /*** Find */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE prtFindPrinter (EPS_INT32, EPS_UINT32 );
+extern EPS_ERR_CODE prtCancelFindPrinter (void );
+extern EPS_ERR_CODE prtProbePrinterByID (const EPS_PROBE* );
+extern EPS_ERR_CODE prtProbePrinterByAddr (const EPS_PROBE* );
+
+ /*** Job */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE prtSetupJobFunctions (const EPS_PRINTER_INN*, EPS_JOB_FUNCS* );
+extern EPS_ERR_CODE prtRecoverPE (void );
+
+ /*** Information */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE prtGetPMString (const EPS_PRINTER_INN*, EPS_INT32,
+ EPS_UINT8*, EPS_INT32* );
+extern EPS_ERR_CODE prtGetInkInfo (const EPS_PRINTER_INN*, EPS_INK_INFO* );
+
+ /*** Printer list */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_ERR_CODE prtRegPrinter (EPS_PRINTER_INN*, EPS_BOOL );
+extern EPS_BOOL prtIsRegistered (const EPS_INT8*, const EPS_INT8*, EPS_INT32);
+extern void prtClearPrinterList (void );
+extern EPS_ERR_CODE prtDuplPrinterList (void );
+extern EPS_ERR_CODE prtAddUsrPrinter (const EPS_PRINTER*, EPS_PRINTER_INN** );
+extern EPS_PRINTER_INN* prtGetInnerPrinter (const EPS_PRINTER* );
+extern void prtClearSupportedMedia (EPS_PRINTER_INN* );
+
+extern void prtSetIdStr (EPS_PRINTER_INN*, const EPS_INT8* );
+
+#ifdef __cplusplus
+}
+#endif /* def __cplusplus */
+
+#endif /* def _EPSON_PROROCOL_H_ */
+
+/*________________________________ epson-protocol.h _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-typedefs.h b/lib/epson-typedefs.h
new file mode 100644
index 0000000..7f3681a
--- /dev/null
+++ b/lib/epson-typedefs.h
@@ -0,0 +1,121 @@
+/*________________________________ epson-typedefs.h _________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson Common Type Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef EPSON_TYPEDEFS_H_
+#define EPSON_TYPEDEFS_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*--------------------------------- System Includes ---------------------------------*/
+/*******************************************|********************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <stdarg.h>
+
+#ifdef GCOMSW_EPSON_SLEEP
+#include <sys/timeb.h>
+#endif
+
+/*------------------------------- Define Basic Data Types ------------------------------*/
+/*******************************************|********************************************/
+typedef unsigned char EPS_UINT8; /* unsigned 8-bit Min: 0 Max: 255 */
+typedef unsigned short EPS_UINT16; /* unsigned 16-bit Min: 0 Max: 65535 */
+typedef unsigned int EPS_UINT32; /* unsigned 32-bit Min: 0 Max: 4294967295 */
+typedef char EPS_INT8; /* signed 8-bit Min: -128 Max: 127 */
+typedef short EPS_INT16; /* signed 16-bit Min: -32768 Max: 32767 */
+typedef int EPS_INT32; /* signed 32-bit Min:-2147483648 Max: 2147483647 */
+typedef float EPS_FLOAT; /* float 32-bit Min:3.4E-38 Max: 3.4E+38 */
+typedef EPS_INT32 EPS_BOOL; /* Boolean type */
+typedef EPS_INT32 EPS_ERR_CODE; /* Error code for API's and routines */
+typedef int EPS_SOCKET; /* socket discripter */
+
+#if defined(unix)||defined(__unix)
+typedef int EPS_FILEDSC; /* file discripter */
+#else
+typedef void* EPS_FILEDSC; /* file discripter */
+#endif
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Data Structure -----------------------------------*/
+/*******************************************|********************************************/
+
+/*--------------------------------- Basic State Types ----------------------------------*/
+/*******************************************|********************************************/
+#ifndef NULL
+#define NULL 0 /* Value of null */
+#endif
+
+#ifndef TRUE
+#define TRUE 1 /* Value of "true" */
+#endif
+
+#ifndef FALSE
+#define FALSE 0 /* Value of "false" */
+#endif
+
+ /*** USB */
+ /*** -------------------------------------------------------------------------------*/
+ /* sign of invalid file discripter */
+#define EPS_INVALID_FILEDSC (EPS_FILEDSC)(-1)
+
+
+ /*** Socket */
+ /*** -------------------------------------------------------------------------------*/
+ /* sign of invalid socket */
+#define EPS_INVALID_SOCKET (EPS_SOCKET)(-1)
+
+ /*** Socket function retrieve value */
+ /*** -------------------------------------------------------------------------------*/
+#define EPS_SOCKET_SUCCESS (0)
+#define EPS_SOCKET_ERROR (-1)
+#define EPS_SOCKET_TIMEOUT (-2)
+
+ /* protocol family */
+#define EPS_PF_INET 1 /* Internetwork protocol family */
+ /* semantics */
+#define EPS_SOCK_STREAM 1 /* Stream socket */
+#define EPS_SOCK_DGRAM 2 /* Datagram socket */
+ /* protocol */
+#define EPS_PROTOCOL_TCP 1 /* TCP protocol */
+#define EPS_PROTOCOL_UDP 2 /* UDP protocol */
+ /* shutdown method */
+#define EPS_SHUTDOWN_SEND 1 /* Shutdown dir: send */
+#define EPS_SHUTDOWN_RECV 2 /* Shutdown dir: receive */
+#define EPS_SHUTDOWN_BOTH 3 /* Shutdown dir: both */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* for EPSON_TYPEDEFS_H_ */
+
+/*________________________________ epson-typedefs.h _________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-usb.c b/lib/epson-usb.c
new file mode 100644
index 0000000..9b4af81
--- /dev/null
+++ b/lib/epson-usb.c
@@ -0,0 +1,1732 @@
+/*___________________________________ epson-usb.c ___________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of copyrightable
+ * material and information now allowed by statutory or judicial law or hereinafter
+ * granted, including without limitation, material generated from the software
+ * programs which are displayed on the screen such as icons, screen display looks,
+ * etc.
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson USB Module */
+/* */
+/* Public Function Calls */
+/* -------------------------- */
+/* EPS_ERR_CODE usbFind (protocol ); */
+/* EPS_ERR_CODE usbProbePrinterByID(modelNameTgt, protocol, printer ); */
+/* EPS_ERR_CODE usbStartJob (printer ); */
+/* EPS_ERR_CODE usbStartPage ( ); */
+/* EPS_ERR_CODE usbEndJob (printer ); */
+/* EPS_ERR_CODE usbGetPMString (printer, pString, bufSize ); */
+/* EPS_ERR_CODE usbGetStatus (printer, status, ioStatus ); */
+/* EPS_ERR_CODE usbGetJobStatus (pstInfo ); */
+/* EPS_ERR_CODE usbWritePrintData (Buffer, BuffLen, sentSize ); */
+/* EPS_ERR_CODE usbResetPrinter (void ); */
+/* EPS_ERR_CODE usbMechCommand (Command ); */
+/* */
+/*******************************************|********************************************/
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-escpr-pvt.h"
+#include "epson-escpr-err.h"
+#include "epson-escpr-services.h"
+#include "epson-escpr-mem.h"
+#include "epson-protocol.h"
+#include "epson-cbt.h"
+#include "epson-usb.h"
+
+/*-------------------------------- Local Definition ---------------------------------*/
+/*******************************************|********************************************/
+#ifdef EPS_LOG_MODULE_USB
+#define EPS_LOG_MODULE EPS_LOG_MODULE_USB
+#else
+#define EPS_LOG_MODULE 0
+#endif
+
+/*--------------------------- Data Structure Declarations ---------------------------*/
+/*******************************************|********************************************/
+typedef struct _tagEPS_USB_PRINTER_INFO_ {
+ EPS_USB_DEVICE dev;
+ EPS_BOOL bCheckDataChannel;
+}EPS_USB_PRINTER_INFO;
+
+typedef struct _tagEPS_PRINT_JOB_USB_ {
+ EPS_FILEDSC fd; /* usb file descriptor */
+ EPS_BOOL resetRequest; /* recv reset request & yet not reset */
+} EPS_PRINT_JOB_USB;
+
+
+/*-------------------------- ESC/P-R USB Lib Global Variables ------------------------*/
+/*******************************************|********************************************/
+
+ /*** Extern Function */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_USB_FUNC epsUsbFnc;
+extern EPS_CMN_FUNC epsCmnFnc;
+
+ /*** Print Job Structure */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_PRINT_JOB printJob;
+
+ /*** Find */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_BOOL g_FindBreak; /* Find printer end flag */
+
+ /*** I/O Channel */
+ /*** -------------------------------------------------------------------------------*/
+extern EPS_BOOL ioOpenState; /* Open state of I/O port (Bi-Directional) */
+extern EPS_BOOL ioDataChState; /* Open state of Data Channel */
+extern EPS_BOOL ioControlChState; /* Open state of Control Channel */
+extern EPS_BOOL ioOpenUniDirect; /* Open state of I/O port (Uni-Directional) */
+
+/*-------------------------------- Local Functions ----------------------------------*/
+/*******************************************|********************************************/
+static EPS_ERR_CODE ProbePrinterByName (const EPS_INT8*, EPS_BOOL, EPS_UINT32,
+ EPS_USB_DEVICE*, EPS_INT8*, EPS_INT8*, EPS_INT32*);
+static EPS_ERR_CODE ProbeESCPR (const EPS_USB_DEVICE*, EPS_INT8*, EPS_INT8*,
+ EPS_INT32* );
+static EPS_ERR_CODE CreatePrinterInfo (const EPS_USB_DEVICE*, const EPS_INT8*,
+ const EPS_INT8*, EPS_INT32, EPS_PRINTER_INN** );
+static EPS_ERR_CODE PortResolution (const EPS_PRINTER_INN*, EPS_FILEDSC* );
+static EPS_ERR_CODE GetBinaryStatus (EPS_FILEDSC, EPS_STATUS_INFO* );
+static EPS_ERR_CODE InfoCommand (EPS_FILEDSC, EPS_INT32, EPS_UINT8*, EPS_INT32* );
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Public Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbFind() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* timeout EPS_UINT32 I: find timeout */
+/* protocol EPS_INT32 I: communication mode */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success Printer found */
+/* EPS_ERR_PRINTER_NOT_FOUND - Printer not found (or error occur) */
+/* EPS_ERR_MEMORY_ALLOCATION - memory allocation failed */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* */
+/* Description: */
+/* find all USB printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbFind (
+
+ EPS_UINT32* timeout,
+ EPS_INT32 protocol
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_FILEDSC fd = EPS_INVALID_FILEDSC;
+ EPS_PRINTER_INN* printer = NULL;
+ EPS_USB_DEVICE dev;
+ EPS_INT8 manufacturer[EPS_NAME_BUFFSIZE]; /* Manufacturer name */
+ EPS_INT8 modelName[EPS_NAME_BUFFSIZE]; /* Printer model name */
+ EPS_UINT32 tmStart, tmNow, tmSpan;
+ EPS_INT32 cmdLevel = 0;
+
+ EPS_LOG_FUNCIN;
+
+ memset(&dev, 0, sizeof(dev));
+ memset(manufacturer, 0, EPS_NAME_BUFFSIZE);
+ memset(modelName, 0, EPS_NAME_BUFFSIZE);
+
+/***------------------------------------------------------------------------------------*/
+/*** Bi-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ if ( EPS_IS_BI_PROTOCOL(protocol) ) {
+ fd = epsUsbFnc.findFirst( &dev );
+ if(EPS_INVALID_FILEDSC != fd){
+ if(epsCmnFnc.getTime){
+ tmStart = epsCmnFnc.getTime();
+ } else{
+ *timeout = tmStart = tmNow = tmSpan = 0;
+ }
+
+ do{
+ /*** Validate this is an Epson ESC/PR Printer */
+ ret = ProbeESCPR(&dev, manufacturer, modelName, &cmdLevel);
+
+ if(EPS_ERR_NONE == ret){
+ ret = CreatePrinterInfo(&dev, manufacturer, modelName, cmdLevel, &printer);
+ if( EPS_ERR_NONE == ret ){
+ ret = prtRegPrinter( printer, TRUE );
+ }
+
+ if( EPS_ERR_NONE != ret ){
+ break;
+ }
+
+ if(*timeout > 0){
+ tmNow = epsCmnFnc.getTime();
+ tmSpan = (EPS_UINT32)(tmNow - tmStart);
+ EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )
+ if( tmSpan >= *timeout ){
+ break;
+ }
+ }
+ if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
+ if( 0 == epsCmnFnc.lockSync() ){
+ if( g_FindBreak ){
+ epsCmnFnc.unlockSync();
+ break;
+ }
+ epsCmnFnc.unlockSync();
+ }
+ }
+ }
+ }while( epsUsbFnc.findNext( fd, &dev ) );
+
+ epsUsbFnc.findClose(fd);
+
+ if(*timeout > 0){
+ /* calculate elapsed time */
+ tmNow = epsCmnFnc.getTime();
+ tmSpan = (EPS_UINT32)(tmNow - tmStart);
+ if(tmSpan < *timeout){
+ *timeout -= tmSpan;
+ } else{
+ *timeout = 1;
+ }
+ }
+
+ } else{
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+
+/***------------------------------------------------------------------------------------*/
+/*** Uni-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ } else{
+ /*** Open Portal check */
+ fd = epsUsbFnc.openPortal(NULL);
+ if(EPS_INVALID_FILEDSC != fd){
+ epsUsbFnc.closePortal(fd);
+
+ /*** Create printer info structure */
+ ret = CreatePrinterInfo(&dev, "", "", 0, &printer);
+ if( EPS_ERR_NONE == ret ){
+ ret = prtRegPrinter( printer, TRUE );
+ }
+ } else{
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbProbePrinterByID() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printerUUID EPS_INT8* I: ID String of probe target */
+/* timeout EPS_UINT32 I: find timeout */
+/* printer EPS_PRINTER_INN** O: pointer for found printer structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (printer found) */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* */
+/* Description: */
+/* looks for specified printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbProbePrinterByID (
+
+ EPS_INT8* printerUUID,
+ EPS_UINT32 timeout,
+ EPS_PRINTER_INN** printer
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_FILEDSC fd = EPS_INVALID_FILEDSC;
+ EPS_USB_DEVICE dev;
+ EPS_INT8 manufacturer[EPS_NAME_BUFFSIZE]; /* Manufacturer name */
+ EPS_INT8 modelName[EPS_NAME_BUFFSIZE]; /* Printer model name */
+ EPS_INT8* pPos = NULL;
+ EPS_INT32 nSegCnt = 0;
+ EPS_UINT32 nTmp = 0;
+ EPS_INT8 modelNameTgt[EPS_NAME_BUFFSIZE]; /* target printer model name */
+ EPS_BOOL enableBreak = FALSE;
+ EPS_INT32 cmdLevel = 0;
+
+ EPS_LOG_FUNCIN;
+
+/*** Parse definition String */
+ pPos = strtok(printerUUID, EPS_USBID_SEP);
+ for(nSegCnt = 0; pPos != NULL && nSegCnt < EPS_USBID_SEGNUM; nSegCnt++){
+ switch(nSegCnt){
+ case 0: /* Get VID */
+ case 1: /* Get PID */
+ sscanf(pPos, "%x", &nTmp);
+ if(nTmp == 0){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID );
+ }
+ /* lib do not use VID, PID */
+ break;
+
+ case 2: /* Get model name */
+ strcpy(modelNameTgt, pPos);
+ break;
+ }
+
+ pPos = strtok(NULL, EPS_USBID_SEP);
+ }
+ if(nSegCnt < EPS_USBID_SEGNUM){
+ EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID );
+ }
+
+ memset(&dev, 0, sizeof(dev));
+
+/***------------------------------------------------------------------------------------*/
+/*** Bi-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ if ( EPS_IS_BI_PROTOCOL(printJob.commMode) ) {
+ enableBreak = (epsCmnFnc.lockSync && epsCmnFnc.unlockSync );
+ memset(manufacturer, 0, sizeof(manufacturer));
+ memset(modelName, 0, sizeof(modelName));
+ ret = ProbePrinterByName(modelNameTgt, enableBreak, timeout,
+ &dev, manufacturer, modelName, &cmdLevel);
+ if(EPS_ERR_NONE == ret){
+ /*** Create printer info structure */
+ ret = CreatePrinterInfo(&dev, manufacturer, modelName, cmdLevel, printer);
+ }
+/***------------------------------------------------------------------------------------*/
+/*** Uni-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ } else{
+ /*** Open Portal check */
+ fd = epsUsbFnc.openPortal(NULL);
+ if(EPS_INVALID_FILEDSC != fd){
+ epsUsbFnc.closePortal(fd);
+
+ /*** Create printer info structure */
+ ret = CreatePrinterInfo(&dev, "", "", 0, printer);
+
+ } else{
+ ret = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbStartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* (Uni/Bi-Directional) */
+/* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
+/* EPS_ERR_NOT_OPEN_IO - Failed to open I/O */
+/* (Bi-Directional Only) */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* Creates a new print job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbStartJob (
+
+ void
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+ const EPS_PRINTER_INN* printer = printJob.printer;
+ EPS_PRINT_JOB_USB *usbPrintJob = NULL;
+
+ EPS_LOG_FUNCIN;
+
+/*** Create USB Job data */
+ usbPrintJob = (EPS_PRINT_JOB_USB*)EPS_ALLOC( sizeof(EPS_PRINT_JOB_USB) );
+ if( NULL == usbPrintJob ){
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+ memset(usbPrintJob, 0, sizeof(EPS_PRINT_JOB_USB));
+ usbPrintJob->fd = EPS_INVALID_FILEDSC;
+ usbPrintJob->resetRequest = FALSE;
+
+/***------------------------------------------------------------------------------------*/
+/*** Bi-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ if( EPS_IS_BI_PROTOCOL(printer->protocol) ){
+ /*** Resolve present port number. And Open the I/O Port for communication */
+ retStatus = PortResolution(printer, &usbPrintJob->fd);
+ if (retStatus != EPS_ERR_NONE) {
+ cbtCommClose(usbPrintJob->fd);
+ retStatus = (EPS_ERR_CODE)EPS_ERR_NOT_OPEN_IO;
+ goto epsStartJob_END;
+ }
+
+ /*** Open the command channel */
+ retStatus = cbtCommChannelOpen(usbPrintJob->fd, EPS_CBTCHANNEL_CTRL, TRUE);
+ if (retStatus != EPS_ERR_NONE) {
+ retStatus = cbtCommClose(usbPrintJob->fd);
+ retStatus = (EPS_ERR_CODE)EPS_ERR_NOT_OPEN_IO;
+ goto epsStartJob_END;
+ }
+
+ /*** Open Data Channel */
+ retStatus = cbtCommChannelOpen(usbPrintJob->fd, EPS_CBTCHANNEL_DATA, TRUE);
+ if (retStatus != EPS_ERR_NONE) {
+ retStatus = cbtCommChannelClose(usbPrintJob->fd, EPS_CBTCHANNEL_CTRL);
+ retStatus = cbtCommClose(usbPrintJob->fd);
+ retStatus = (EPS_ERR_CODE)EPS_ERR_PRINTER_ERR_OCCUR/*EPS_ERR_CANNOT_PRINT*/;
+ goto epsStartJob_END;
+ }
+ ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel = FALSE;
+
+/***------------------------------------------------------------------------------------*/
+/*** Uni-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ } else{
+ /*** Open Portal */
+ if (ioOpenUniDirect == EPS_IO_OPEN) {
+ retStatus = EPS_ERR_2ND_OPEN_IO;
+ goto epsStartJob_END;
+ } else {
+ usbPrintJob->fd = epsUsbFnc.openPortal( NULL );
+ if (EPS_INVALID_FILEDSC == usbPrintJob->fd) {
+ retStatus = EPS_ERR_NOT_OPEN_IO;
+ goto epsStartJob_END;
+ }
+ ioOpenUniDirect = EPS_IO_OPEN;
+ }
+ }
+
+ printJob.hProtInfo = (EPS_HANDLE)usbPrintJob;
+
+epsStartJob_END:
+ if(EPS_ERR_NONE != retStatus){
+ EPS_SAFE_RELEASE(usbPrintJob);
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbRestartJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* (Uni/Bi-Directional) */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_NOT_OPEN_IO - Failed to open I/O */
+/* (Bi-Directional Only) */
+/* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
+/* */
+/* Description: */
+/* The port shut by usbResetPrinter() is opened again. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbRestartJob (
+
+ void
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+ const EPS_PRINTER_INN* printer = printJob.printer;
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+ EPS_LOG_FUNCIN;
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+/***------------------------------------------------------------------------------------*/
+/*** Bi-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ if( EPS_IS_BI_PROTOCOL(printer->protocol) ){
+ if(EPS_IO_NOT_OPEN == ioDataChState){
+ /*if( EPS_RESET_SENT == printJob.resetSent ){*/
+ /* If pre page canceled, Re open data channel */
+ retStatus = cbtCommChannelOpen(usbPrintJob->fd, EPS_CBTCHANNEL_DATA, TRUE);
+ if (retStatus == EPS_ERR_NONE) {
+ ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel = FALSE;
+ } else{
+ retStatus = (EPS_ERR_CODE)EPS_ERR_PRINTER_ERR_OCCUR/*EPS_ERR_CANNOT_PRINT*/;
+ }
+ }
+/***------------------------------------------------------------------------------------*/
+/*** Uni-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+/* } else{
+ no operation*/
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbEndJob() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* N/A */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_NOT_CLOSE_IO - Cannot close I/O portal */
+/* */
+/* Description: */
+/* Ends the current print job. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbEndJob (
+
+ void
+
+){
+ EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+EPS_LOG_FUNCIN;
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+ switch(printJob.printer->protocol){
+ case EPS_COMM_USB_BID:
+/***------------------------------------------------------------------------------------*/
+/*** Bi-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ /*** Close communication */
+ retStatus = cbtCommChannelClose(usbPrintJob->fd, EPS_CBTCHANNEL_DATA);
+ retStatus = cbtCommChannelClose(usbPrintJob->fd, EPS_CBTCHANNEL_CTRL);
+ retStatus = cbtCommClose(usbPrintJob->fd);
+ if (retStatus != EPS_ERR_NONE) {
+ retStatus = EPS_ERR_NOT_CLOSE_IO;
+ }
+ break;
+
+ case EPS_COMM_USB_UNID:
+/***------------------------------------------------------------------------------------*/
+/*** Uni-Directional Communication Mode */
+/***------------------------------------------------------------------------------------*/
+ /*** Close Portal */
+ if (ioOpenUniDirect == EPS_IO_OPEN) {
+ retStatus = epsUsbFnc.closePortal(usbPrintJob->fd);
+ if (retStatus != 0) {
+ EPS_RETURN( EPS_ERR_NOT_CLOSE_IO );
+ }
+ ioOpenUniDirect = EPS_IO_NOT_OPEN;
+ }
+ break;
+
+ default:
+ retStatus = EPS_ERR_OPR_FAIL;
+ }
+
+ EPS_SAFE_RELEASE( printJob.hProtInfo );
+
+ EPS_RETURN( retStatus );
+}
+
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbWritePrintData() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Buffer const EPS_UINT8* I: Buffer Pointer for Write Data */
+/* BuffLen EPS_UINT32 I: Write Data Buffer Length (bytes) */
+/* sentSize EPS_UINT32* O: Actuall Write Size */
+/* */
+/* Return value: */
+/* EPCBT_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Write the data to printer Data Channel. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbWritePrintData (
+
+ const EPS_UINT8* Buffer,
+ EPS_UINT32 BuffLen,
+ EPS_UINT32* sentSize
+
+){
+ EPS_INT32 retCom;
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+EPS_LOG_FUNCIN;
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+ if( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
+ retCom = cbtCommWriteData(usbPrintJob->fd, EPS_CBTCHANNEL_DATA, Buffer, (EPS_INT32)BuffLen, (EPS_INT32*)sentSize);
+ if(EPCBT_ERR_NONE == retCom){
+ EPS_RETURN( EPS_ERR_NONE );
+ } else if(EPSCBT_ERR_FNCDISABLE == retCom){
+ EPS_RETURN( EPS_COM_TINEOUT );
+ }else{
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ } else{
+ retCom = epsUsbFnc.writePortal(usbPrintJob->fd, Buffer, (EPS_INT32)BuffLen, (EPS_INT32*)sentSize);
+ if(0 == retCom){
+ EPS_RETURN( EPS_ERR_NONE );
+ } else{
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ }
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbResetPrinter() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* void - - */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Failed to send command */
+/* EPS_ERR_CAN_NOT_RESET - Failed to reset printer */
+/* EPS_ERR_NOT_CLOSE_IO - Cannot Close I/O Portal */
+/* */
+/* Description: */
+/* Send "rj" command and reset printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbResetPrinter (
+
+ void
+
+){
+/*** Declare Variable Local to Routine */
+#define EPS_RSREPLY_SIZE (32)
+ EPS_ERR_CODE Ret;
+ EPS_INT32 ComSize = 0;
+ EPS_INT32 retBufSize; /* Size of buffer written */
+ EPS_INT32 retryComm;
+ EPS_INT32 retryReset;
+ EPS_INT32 Size = EPS_RSREPLY_SIZE;
+ EPS_INT32 lSize;
+ EPS_UINT8 pResult[EPS_RSREPLY_SIZE];
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+ EPS_UINT8 CBTcmd_rj[] = { 'r', 'j', 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* E , S , C , P , R , L , i , b */
+ 0x45, 0x53, 0x43, 0x50, 0x52, 0x4c, 0x69, 0x62 };
+#if 0 /* Not use "rs" command */
+ EPS_UINT8 CBTcmd_rs[] = {'r', 's', 0x01, 0x00, 0x01};
+#endif
+
+
+EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ retBufSize = 0;
+ memset(pResult, 0, 32);
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+/*** If we already successfully called this function once for a given print job, */
+ if( printJob.resetSent == EPS_RESET_SENT
+ || FALSE == printJob.transmittable
+ || FALSE == printJob.sendJS ){
+ EPS_RETURN( EPS_ERR_NONE );/* no need to send an "rj" command again. Therefore, */
+ /* return EPS_ERR_NONE and exit gracefully. */
+ }
+
+ EPS_DBGPRINT((">>>> Send Printer Reset Command.\r\n"));
+ serDelayThread(500, &epsCmnFnc); /* wait printer 500ms */
+
+ retryReset = 5; /* 5 times time out */
+ do{
+/*** Send "rj" command */
+ retryComm = 5;
+ do{
+ Ret = cbtCommWriteData(usbPrintJob->fd, EPS_CBTCHANNEL_CTRL, (const EPS_UINT8*)CBTcmd_rj, sizeof(CBTcmd_rj), &ComSize);
+
+ if ( Ret != EPCBT_ERR_NONE){
+ if (Ret != EPSCBT_ERR_FNCDISABLE){
+ EPS_DBGPRINT(("CBT Command Write Failed [%d]\r\n",Ret));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ retryComm--;
+ if (!retryComm) {
+ EPS_DBGPRINT(("CBT Command Write Retry Failed \r\n"));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ serDelayThread(1*_SECOND_, &epsCmnFnc); /* retry command after 1 seconds*/
+ }
+ }while (Ret == EPSCBT_ERR_FNCDISABLE);
+
+/*** Read "rj" Reply */
+ retryComm = 5;
+ lSize = Size-1;
+ do{
+ if ((Ret = cbtCommReadData(usbPrintJob->fd, EPS_CBTCHANNEL_CTRL, pResult, lSize, &Size)) != EPCBT_ERR_NONE){
+ if (Ret != EPSCBT_ERR_FNCDISABLE){
+ EPS_DBGPRINT(("CBT Command Write Reply Failed [%d]\r\n",Ret));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ }else if (Size != 0){
+ break;
+ }
+
+ retryComm--;
+ if (!retryComm){
+ EPS_DBGPRINT(("CBT Command Write Reply Retry Failed \r\n"));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ serDelayThread(1*_SECOND_, &epsCmnFnc); /* retry command after 1 seconds*/
+ }while(retryComm > 0);
+
+/*** Make sure we received a correct reply in response to the reset command we sent. */
+ pResult[EPS_RSREPLY_SIZE-1] = '\0';
+ EPS_DUMP(pResult, Size);
+ if (strstr((EPS_INT8*)pResult, "rj:OK;") == NULL) {
+ retryReset--;
+ if (!retryReset) {
+ EPS_DBGPRINT(("Failed to <rj> reset \r\n"));
+ EPS_RETURN( EPS_ERR_CAN_NOT_RESET );
+ }
+ serDelayThread(500, &epsCmnFnc); /* retry command after 500m seconds*/
+ } else{
+ break;
+ }
+
+ }while(retryReset > 0);
+
+ /*** Close Data Channel after sent "rj" command */
+ Ret = cbtCommChannelClose(usbPrintJob->fd, EPS_CBTCHANNEL_DATA);
+ if (Ret != EPS_ERR_NONE) {
+ EPS_RETURN( EPS_ERR_NOT_CLOSE_IO );
+ }
+ if(printJob.printer && printJob.printer->protocolInfo){
+ ((EPS_USB_PRINTER_INFO*)printJob.printer->protocolInfo)->bCheckDataChannel = TRUE;
+ }
+
+ usbPrintJob->resetRequest = FALSE;
+
+/*** Return to Caller */
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbGetPMString() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
+/* type EPS_INT32 I: PM kind 1 or 2 */
+/* pString EPS_UINT8* O: Pointer to PM String */
+/* bufSize EPS_INT32 I: pString buffer size */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPS_ERR_COMM_ERROR - Info command execution error */
+/* */
+/* Description: */
+/* Get PM string from usb printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbGetPMString (
+
+ const EPS_PRINTER_INN* printer,
+ EPS_INT32 type,
+ EPS_UINT8* pString,
+ EPS_INT32* bufSize
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_FILEDSC fd = EPS_INVALID_FILEDSC;
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+EPS_LOG_FUNCIN;
+
+ if (ioOpenState == EPS_IO_NOT_OPEN) {
+ /*** Resolve present port number. And Open the I/O Port for communication */
+ ret = PortResolution(printer, &fd);
+ if (ret != EPS_ERR_NONE) {
+ cbtCommClose(fd);
+ EPS_RETURN( EPS_ERR_NOT_OPEN_IO );
+ }
+
+ /*** Open the control channel */
+ ret = cbtCommChannelOpen(fd, EPS_CBTCHANNEL_CTRL, TRUE);
+ if (ret != EPS_ERR_NONE) {
+ cbtCommChannelClose(fd, EPS_CBTCHANNEL_CTRL);
+ cbtCommClose(fd);
+ EPS_RETURN( EPS_ERR_NOT_OPEN_IO );
+ }
+
+/*** Get PM from Printer */
+ if(1 == type){
+ ret = InfoCommand(fd, EPS_CBTCOM_PM, pString, bufSize);
+ } else if(2 == type){
+ ret = InfoCommand(fd, EPS_CBTCOM_PM2, pString, bufSize);
+ } else{
+ ret = EPS_ERR_OPR_FAIL;
+ }
+
+ /* Close Port */
+ cbtCommChannelClose(fd, EPS_CBTCHANNEL_CTRL);
+ cbtCommClose(fd);
+ } else{
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+/*** Get PM from Printer */
+ if(1 == type){
+ ret = InfoCommand(usbPrintJob->fd, EPS_CBTCOM_PM, pString, bufSize);
+ } else if(2 == type){
+ ret = InfoCommand(usbPrintJob->fd, EPS_CBTCOM_PM2, pString, bufSize);
+ } else{
+ ret = EPS_ERR_OPR_FAIL;
+ }
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbGetStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
+/* status EPS_STATUS_INFO* O: Pointer to the printer status. */
+/* ioStatus EPS_INT32* O: It is possible to communicate */
+/* canceling EPS_BOOL* O: Cancel processing */
+/* */
+/* Return value: */
+/* << Normal >> */
+/* EPS_ERR_NONE - Success */
+/* << Error >> */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_COMM_ERROR - Info command execution error */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPS_ERR_NOT_CLOSE_IO - Cannot Close I/O Portal */
+/* */
+/* Description: */
+/* Gets the printer status. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbGetStatus (
+
+ EPS_STATUS_INFO* pstInfo,
+ EPS_BOOL* pIoStatus,
+ EPS_BOOL* pCancelling
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret; /* Return status of internal calls */
+ EPS_FILEDSC fd = EPS_INVALID_FILEDSC;
+ EPS_PRINTER_INN* printer = printJob.printer;
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ ret = EPS_ERR_NONE;
+ memset(pstInfo, -1, sizeof(EPS_STATUS_INFO));
+
+/*** Get Status Data */
+ if (ioOpenState == EPS_IO_NOT_OPEN) {
+ /*** Resolve present port number. And Open the I/O Port for communication */
+ ret = PortResolution(printer, &fd);
+ if (ret != EPS_ERR_NONE) {
+ cbtCommClose(fd);
+ EPS_RETURN( EPS_ERR_NOT_OPEN_IO );
+ }
+
+ /*** Open the control channel */
+ ret = cbtCommChannelOpen(fd, EPS_CBTCHANNEL_CTRL, TRUE);
+ if (ret != EPS_ERR_NONE) {
+ cbtCommChannelClose(fd, EPS_CBTCHANNEL_CTRL);
+ cbtCommClose(fd);
+ EPS_RETURN( EPS_ERR_NOT_OPEN_IO );
+ }
+
+ /*** Get Printer Status */
+ ret = GetBinaryStatus(fd, pstInfo);
+ if (ret != EPS_ERR_NONE) {
+ cbtCommChannelClose(fd, EPS_CBTCHANNEL_CTRL);
+ cbtCommClose(fd);
+ EPS_RETURN( ret );
+ }
+
+ if(NULL != pIoStatus && NULL != pCancelling){
+ /*** Check I/O status */
+ *pCancelling = FALSE;
+ if(EPS_CAREQ_CANCEL == pstInfo->nCancel
+ || (usbPrintJob && TRUE == usbPrintJob->resetRequest)){
+ *pIoStatus = FALSE;
+ *pCancelling = TRUE;
+ if(usbPrintJob){
+ /* Because EPS_CAREQ_CANCEL can be acquired only once, it memorizes. */
+ usbPrintJob->resetRequest = TRUE;
+ }
+ } else if(EPS_ST_IDLE == pstInfo->nState){
+ if( ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel ){
+ /*** Open Data Channel */
+ if (cbtCommChannelOpen(fd, EPS_CBTCHANNEL_DATA, FALSE) == EPS_ERR_NONE) {
+ ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel = FALSE;
+ *pIoStatus = TRUE;
+ } else{
+ *pIoStatus = FALSE;
+ *pCancelling = TRUE;
+ }
+ cbtCommChannelClose(fd, EPS_CBTCHANNEL_DATA);
+ } else{
+ *pIoStatus = TRUE;
+ }
+ } else{
+ *pIoStatus = FALSE;
+ if( ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel ){
+ *pCancelling = TRUE;
+ }
+ }
+ }
+
+ /* Close Port */
+ ret = cbtCommChannelClose(fd, EPS_CBTCHANNEL_CTRL);
+ ret = cbtCommClose(fd);
+ if (ret != EPS_ERR_NONE) {
+ EPS_RETURN( EPS_ERR_NOT_CLOSE_IO );
+ }
+
+ } else{ /* Job running now */
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_OPR_FAIL );
+ }
+
+ /*** Get Printer Status */
+ ret = GetBinaryStatus(usbPrintJob->fd, pstInfo);
+ if (ret != EPS_ERR_NONE) {
+ EPS_RETURN( ret );
+ }
+
+ if(NULL != pIoStatus && NULL != pCancelling){
+ /*** Check I/O status */
+ *pCancelling = FALSE;
+ if(EPS_CAREQ_CANCEL == pstInfo->nCancel
+ || (usbPrintJob && TRUE == usbPrintJob->resetRequest)){
+ *pIoStatus = FALSE;
+ *pCancelling = TRUE;
+ if(usbPrintJob){
+ /* Because EPS_CAREQ_CANCEL can be acquired only once, it memorizes. */
+ usbPrintJob->resetRequest = TRUE;
+ }
+ } else if(EPS_IO_OPEN == ioDataChState){
+ *pIoStatus = TRUE; /* Evidence */
+ } else if(EPS_ST_IDLE == pstInfo->nState){
+ if( ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel ){
+ /*** Open Data Channel */
+ if (cbtCommChannelOpen(usbPrintJob->fd, EPS_CBTCHANNEL_DATA, FALSE) == EPS_ERR_NONE) {
+ ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel = FALSE;
+ *pIoStatus = TRUE;
+ } else{
+ *pIoStatus = FALSE;
+ *pCancelling = TRUE;
+ }
+ cbtCommChannelClose(usbPrintJob->fd, EPS_CBTCHANNEL_DATA);
+ } else{
+ *pIoStatus = TRUE;
+ }
+ } else{
+ *pIoStatus = FALSE;
+ if( ((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->bCheckDataChannel ){
+ *pCancelling = TRUE;
+ }
+ }
+ }
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbGetJobStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* pstInfo EPS_STATUS_INFO* O: Printer Status information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get the printer status and analyze the status string. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbGetJobStatus (
+
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_ERR_CODE ret = EPS_ERR_NONE;
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+EPS_LOG_FUNCIN;
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+ ret = GetBinaryStatus(usbPrintJob->fd, pstInfo);
+ if(EPS_ERR_NONE == ret
+ && EPS_CAREQ_CANCEL == pstInfo->nCancel){
+ usbPrintJob->resetRequest = TRUE;
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: usbMechCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Command EPS_INT32 I: Command Code */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Mech command executed successfully */
+/* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
+/* EPS_ERR_COMM_ERROR - Mech command execution error */
+/* */
+/* Description: */
+/* Sends mechanincal commands to the printer. */
+/* */
+/*******************************************|********************************************/
+EPS_ERR_CODE usbMechCommand (
+
+ EPS_INT32 Command
+
+){
+/*** Declare Variable Local to Routine */
+ static EPS_UINT8 stCom[] = {'x', 'x', 0x01, 0x00, 0x01};
+ EPS_INT8 Reply[32];
+ EPS_INT32 Size = 32;
+ EPS_INT32 Retry;
+ EPS_INT32 ComSize = 0;
+ EPS_INT32 Ret;
+ EPS_UINT8* Com;
+ EPS_INT32 cSize;
+ EPS_PRINT_JOB_USB* usbPrintJob = (EPS_PRINT_JOB_USB*)printJob.hProtInfo;
+
+EPS_LOG_FUNCIN;
+
+ if( !usbPrintJob ){
+ EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
+ }
+
+/*** Initialize Local Variables */
+ memset(Reply, 0, 32);
+
+/*** Select Command */
+ switch(Command){
+ case EPS_CBTCOM_XIA:
+ stCom[0] = 'x'; stCom[1] = 'i';
+ break;
+ case EPS_CBTCOM_XIA2:
+ stCom[0] = 'x'; stCom[1] = 'i'; stCom[4] = 0x03;
+ break;
+ case EPS_CBTCOM_XIA3:
+ stCom[0] = 'x'; stCom[1] = 'i'; stCom[4] = 0x04;
+ break;
+ case EPS_CBTCOM_XIB:
+ stCom[0] = 'x'; stCom[1] = 'i';stCom[4] = 0x80;
+ break;
+ case EPS_CBTCOM_CH:
+ stCom[0] = 'c'; stCom[1] = 'h';
+ break;
+ case EPS_CBTCOM_NC:
+ stCom[0] = 'n'; stCom[1] = 'c'; stCom[4] = 0x00;
+ break;
+ case EPS_CBTCOM_EI:
+ stCom[0] = 'e'; stCom[1] = 'i'; stCom[4] = 0x00;
+ break;
+ case EPS_CBTCOM_PE:
+ stCom[0] = 'p'; stCom[1] = 'e';
+ break;
+ case EPS_CBTCOM_PJ:
+ stCom[0] = 'p'; stCom[1] = 'j';
+ break;
+ }
+
+/*** Send Command */
+ Retry = 5;
+ do{
+ Com = stCom;
+ cSize = 5;
+
+ EPS_DBGPRINT(("EPS SER : Sending CHANNEL_COMMAND %c%c\r\n", Com[0], Com[1]));
+ if ((Ret = cbtCommWriteData(usbPrintJob->fd, EPS_CBTCHANNEL_CTRL, Com, cSize, &ComSize)) != EPCBT_ERR_NONE){
+ if (Ret != EPSCBT_ERR_FNCDISABLE){
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ Retry--;
+ if (!Retry) {
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ serDelayThread(2*_SECOND_, &epsCmnFnc); /* retry command after 2 seconds */
+ }
+ }while (Ret == EPSCBT_ERR_FNCDISABLE);
+
+/*** Read Reply */
+ Retry = 5;
+ do{
+ if ((Ret = cbtCommReadData(usbPrintJob->fd, EPS_CBTCHANNEL_CTRL, (EPS_UINT8 *)Reply, 32, &Size)) != EPCBT_ERR_NONE){
+ if (Ret != EPSCBT_ERR_FNCDISABLE){
+ EPS_DBGPRINT(("EPS SER : CBT Command Write Reply Failed [%d]\r\n",Ret));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ }else if (Size != 0){
+ break;
+ }
+
+ Retry--;
+ if (!Retry){
+ EPS_DBGPRINT(("EPS SER : CBT Command Write Reply Retry Failed \r\n"));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ serDelayThread(2*_SECOND_, &epsCmnFnc); /* retry command after 2 seconds*/
+ }while(Retry > 0);
+
+/*** Check Reply */
+ EPS_DBGPRINT(("EPS SER : Mech Command reply -> %s\r\n", Reply));
+ if (strstr(Reply,"OK") == NULL){
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+
+/*** Return to Caller */
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*-------------------- Local Functions ---------------------*/
+/*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*******************************************|********************************************/
+/* */
+/* Function name: GetBinaryStatus() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* fd EPS_FILEDSC I: file discripter */
+/* pstInfo EPS_STATUS_INFO* O: Printer Status information */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* */
+/* Description: */
+/* Get the printer status and analyze the status string. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE GetBinaryStatus (
+
+ EPS_FILEDSC fd,
+ EPS_STATUS_INFO* pstInfo
+
+){
+ EPS_INT8 Status[_STATUS_REPLY_BUF];
+ EPS_INT32 Size = _STATUS_REPLY_BUF;
+
+EPS_LOG_FUNCIN;
+
+ memset(Status, 0x00, _STATUS_REPLY_BUF);
+
+ if (InfoCommand(fd, EPS_CBTCOM_ST, (EPS_UINT8*)Status, &Size) != EPS_ERR_NONE){
+ EPS_DBGPRINT(("EPS SER: Get Stat -> CBT Com Failed\r\n"));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+
+ EPS_RETURN( serAnalyzeStatus(Status, pstInfo) );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: ProbeESCPR() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* dev EPS_USB_DEVICE* I: Pointer to a usb device infomatio */
+/* manufacturer EPS_INT8* O: Pointer to a 64-byte buffer for the manufacturer */
+/* name. */
+/* modelName EPS_INT8* O: Pointer to a 64-byte buffer for the printer */
+/* model name. */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPS_ERR_COMM_ERROR - Communication Error */
+/* EPS_ERR_PRINTER_NOT_FOUND - Connected printer is not supported */
+/* */
+/* Description: */
+/* Opens the portal, gets the printer's PM reply, parses it, and stores the data */
+/* in the capabilities structure. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE ProbeESCPR (
+
+ const EPS_USB_DEVICE* dev,
+ EPS_INT8* manufacturer,
+ EPS_INT8* modelName,
+ EPS_INT32* cmdLevel
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus;
+ EPS_FILEDSC fd;
+ EPS_INT8* tmpDeviceIdBuf;
+ EPS_INT32 bufSize;
+ EPS_BOOL found_dev;
+
+EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ retStatus = EPS_ERR_NONE;
+ found_dev = FALSE;
+
+ EPS_DBGPRINT(("PROT=%d / PID=%04X / VID=%04X\n", dev->port, dev->pid, dev->vid))
+
+ /* Allocate temp buffer */
+ tmpDeviceIdBuf = (EPS_INT8*)EPS_ALLOC(EPS_DI_MAXSIZE);
+ if (tmpDeviceIdBuf == NULL) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+ memset(tmpDeviceIdBuf, 0, EPS_DI_MAXSIZE);
+ bufSize = EPS_DI_MAXSIZE;
+
+ /*** Get device ID */
+ retStatus = cbtCommOpen( dev, &fd );
+ if(EPS_ERR_NONE == retStatus ){
+ retStatus = cbtCommChannelOpen(fd, EPS_CBTCHANNEL_CTRL, TRUE);
+ if (retStatus == EPS_ERR_NONE) {
+ retStatus = InfoCommand(fd, EPS_CBTCOM_DI, (EPS_UINT8*)tmpDeviceIdBuf, &bufSize);
+ } else{
+ retStatus = (EPS_ERR_CODE)EPS_ERR_NOT_OPEN_IO;
+ }
+ cbtCommChannelClose(fd, EPS_CBTCHANNEL_CTRL);
+ } else{
+ retStatus = (EPS_ERR_CODE)EPS_ERR_NOT_OPEN_IO;
+ }
+ cbtCommClose(fd);
+
+ if (EPS_ERR_NONE == retStatus ) {
+ found_dev = serParseDeviceID(tmpDeviceIdBuf, manufacturer, modelName, cmdLevel, NULL);
+ if(found_dev == FALSE) {
+ retStatus = EPS_ERR_PRINTER_NOT_FOUND;
+ }
+ }
+
+ EPS_SAFE_RELEASE(tmpDeviceIdBuf);
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: CreatePrinterInfo() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* dev EPS_USB_DEVICE* I: Pointer to a usb device infomatio */
+/* manufacturer EPS_INT8* I: Pointer to a 64-byte buffer for the manufacturer */
+/* name. */
+/* modelName EPS_INT8* I: Pointer to a 64-byte buffer for the printer */
+/* model name. */
+/* printer EPS_PRINTER_INN** O: pointer for found printer structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_OPR_FAIL - Internal Error */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* */
+/* Description: */
+/* Create Printer info structure and setup data. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE CreatePrinterInfo (
+
+ const EPS_USB_DEVICE* dev,
+ const EPS_INT8* manufacturer,
+ const EPS_INT8* modelName,
+ EPS_INT32 cmdLevel,
+ EPS_PRINTER_INN** printer
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE retStatus;
+ EPS_INT8 usbIDString[EPS_NAME_BUFFSIZE];
+ EPS_USB_PRINTER_INFO* pUsbPrinter = NULL;
+
+EPS_LOG_FUNCIN;
+
+/*** Initialize Local Variables */
+ retStatus = EPS_ERR_NONE;
+
+/*** Create printer info structure */
+ *printer = (EPS_PRINTER_INN*)EPS_ALLOC( sizeof(EPS_PRINTER_INN) );
+ if(NULL == *printer){
+ retStatus = EPS_ERR_MEMORY_ALLOCATION;
+ goto CreatePrinterInfo_ERROR;
+ }
+ memset( *printer, 0, sizeof(EPS_PRINTER_INN) );
+
+ pUsbPrinter = (EPS_USB_PRINTER_INFO*)EPS_ALLOC( sizeof(EPS_USB_PRINTER_INFO) );
+ if(NULL == pUsbPrinter){
+ retStatus = EPS_ERR_MEMORY_ALLOCATION;
+ goto CreatePrinterInfo_ERROR;
+ }
+ memcpy(&pUsbPrinter->dev, dev, sizeof(pUsbPrinter->dev));
+ pUsbPrinter->bCheckDataChannel = FALSE;
+ (*printer)->protocolInfo = pUsbPrinter;
+
+ strcpy( (*printer)->location, EPS_USB_NAME );
+ strcpy( (*printer)->manufacturerName, manufacturer );
+ strcpy( (*printer)->modelName, modelName );
+ (*printer)->protocol = EPS_PROTOCOL_USB;
+ (*printer)->protocol |= EPS_PRT_DIRECTION(printJob.commMode);
+ (*printer)->language = EPS_LANG_ESCPR; /* ESC/P-R only via USB */
+ switch(cmdLevel){
+ case 0: /* Support all. For Uin communication */
+ case 2:
+ (*printer)->supportFunc |= EPS_SPF_JPGPRINT; /* Jpeg print */
+ case 1:
+ (*printer)->supportFunc |= EPS_SPF_RGBPRINT; /* RGB print */
+ }
+
+ sprintf(usbIDString, EPS_USB_IDPRM_STR, dev->vid, dev->pid, modelName);
+ prtSetIdStr(*printer, usbIDString);
+
+CreatePrinterInfo_ERROR:
+ if(EPS_ERR_NONE != retStatus){
+ EPS_SAFE_RELEASE( pUsbPrinter );
+ EPS_SAFE_RELEASE( *printer );
+ }
+
+ EPS_RETURN( retStatus );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: PortResolution() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* printer EPS_PRINTER_INN* I: pointer for found printer structure */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success */
+/* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* EPS_ERR_PRINTER_NOT_FOUND - Printer not found (or error occur) */
+/* */
+/* Description: */
+/* Resolve present port number. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE PortResolution(
+
+ const EPS_PRINTER_INN* printer,
+ EPS_FILEDSC* pFd
+
+){
+
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_BOOL bNeedResolve = TRUE;
+ EPS_USB_DEVICE dev;
+ EPS_FILEDSC fdInt = EPS_INVALID_FILEDSC;
+ EPS_INT8* tmpDeviceIdBuf;
+ EPS_INT32 bufSize;
+ EPS_INT8 modelName[EPS_NAME_BUFFSIZE]; /* Printer model name */
+ EPS_INT8 manufacturer[EPS_NAME_BUFFSIZE]; /* Manufacturer name */
+
+EPS_LOG_FUNCIN;
+
+ *pFd = EPS_INVALID_FILEDSC;
+
+ if( !EPS_IS_BI_PROTOCOL(printer->protocol) ){
+ EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
+ }
+
+ /* Allocate temp buffer */
+ tmpDeviceIdBuf = (EPS_INT8*)EPS_ALLOC(EPS_DI_MAXSIZE);
+ if (tmpDeviceIdBuf == NULL) {
+ EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
+ }
+ memset(tmpDeviceIdBuf, 0, EPS_DI_MAXSIZE);
+ bufSize = EPS_DI_MAXSIZE;
+
+ memset(&dev, 0, sizeof(dev));
+
+ /*** Get device ID */
+ ret = cbtCommOpen( (EPS_USB_DEVICE*)printer->protocolInfo, &fdInt );
+ if( EPS_ERR_NONE == ret ){
+ ret = cbtCommChannelOpen(fdInt, EPS_CBTCHANNEL_CTRL, TRUE);
+ if( EPS_ERR_NONE == ret ){
+ ret = InfoCommand(fdInt, EPS_CBTCOM_DI, (EPS_UINT8*)tmpDeviceIdBuf, &bufSize);
+ cbtCommChannelClose(fdInt, EPS_CBTCHANNEL_CTRL);
+ if( EPS_ERR_NONE == ret ){
+ /*** Get Printer name */
+ memset(manufacturer, 0, sizeof(manufacturer));
+ memset(modelName, 0, sizeof(modelName));
+ if( serParseDeviceID(tmpDeviceIdBuf, manufacturer, modelName, NULL, NULL) ){
+ /*** Printer names compare. */
+ if( 0 == strcmp(modelName, printer->modelName) ){
+ bNeedResolve = FALSE;
+ }
+ }
+ }
+ }
+ }
+
+ if(bNeedResolve){
+ if(EPS_INVALID_FILEDSC != fdInt){
+ cbtCommClose(fdInt);
+ fdInt = EPS_INVALID_FILEDSC;
+ }
+
+ /* Probe other port */
+ ret = ProbePrinterByName(printer->modelName, FALSE, 0, &dev, manufacturer, modelName, NULL);
+ if(EPS_ERR_NONE == ret){
+ /* Reset printer port */
+ memcpy(&((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->dev, &dev,
+ sizeof(((EPS_USB_PRINTER_INFO*)printer->protocolInfo)->dev));
+
+ ret = cbtCommOpen( (EPS_USB_DEVICE*)printer->protocolInfo, &fdInt );
+ }
+ }
+
+ EPS_SAFE_RELEASE(tmpDeviceIdBuf);
+
+ if( EPS_ERR_NONE == ret ){
+ *pFd = fdInt;
+ } else{
+ if(EPS_INVALID_FILEDSC != fdInt){
+ cbtCommClose(fdInt);
+ }
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: ProbePrinterByName() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* modelNameTgt EPS_INT8* I: target printer modelname */
+/* enableBreak EPS_BOOL I: enable break */
+/* timeout EPS_UINT32 I: find timeout */
+/* dev EPS_USB_DEVICE* O: Pointer to a usb device infomatio */
+/* manufacturer EPS_INT8* O: Pointer to a 64-byte buffer for the manufacturer */
+/* name. */
+/* modelName EPS_INT8* O: Pointer to a 64-byte buffer for the printer */
+/* model name. */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Success (printer found) */
+/* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
+/* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
+/* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
+/* */
+/* Description: */
+/* looks for specified printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE ProbePrinterByName (
+
+ const EPS_INT8* modelNameTgt,
+ EPS_BOOL enableBreak,
+ EPS_UINT32 timeout,
+ EPS_USB_DEVICE* dev,
+ EPS_INT8* manufacturer,
+ EPS_INT8* modelName,
+ EPS_INT32* cmdLevel
+
+){
+/*** Declare Variable Local to Routine */
+ EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
+ EPS_BOOL found = FALSE;
+ EPS_FILEDSC fd = EPS_INVALID_FILEDSC;
+ EPS_UINT32 tmStart, tmNow, tmSpan;
+
+EPS_LOG_FUNCIN;
+
+ *modelName = '\0';
+ *manufacturer = '\0';
+
+ fd = epsUsbFnc.findFirst( dev );
+ if(EPS_INVALID_FILEDSC != fd){
+ if(epsCmnFnc.getTime){
+ tmStart = epsCmnFnc.getTime();
+ } else{
+ timeout = tmStart = tmNow = tmSpan = 0;
+ }
+
+ do{
+ /*** Validate this is an Epson ESC/PR Printer */
+ ret = ProbeESCPR(dev, manufacturer, modelName, cmdLevel);
+
+ if(EPS_ERR_NONE == ret){
+ if( 0 == strcmp(modelNameTgt, modelName) ){
+ /* Found target printer */
+ found = TRUE;
+ break;
+ }
+ } else if(EPS_ERR_PRINTER_NOT_FOUND != ret){
+ break;
+ }
+
+ if(timeout > 0){
+ tmNow = epsCmnFnc.getTime();
+ tmSpan = (EPS_UINT32)(tmNow - tmStart);
+ EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )
+ if( tmSpan >= timeout ){
+ break;
+ }
+ }
+ if( enableBreak ){
+ if( 0 == epsCmnFnc.lockSync() ){
+ if( g_FindBreak ){
+ epsCmnFnc.unlockSync();
+ break;
+ }
+ epsCmnFnc.unlockSync();
+ }
+ }
+ }while( epsUsbFnc.findNext( fd, dev ) );
+
+ epsUsbFnc.findClose(fd);
+ }
+
+ if(EPS_ERR_NONE == ret){
+ ret = (found?EPS_ERR_NONE:EPS_ERR_PRINTER_NOT_FOUND);
+ }
+
+ EPS_RETURN( ret );
+}
+
+
+/*******************************************|********************************************/
+/* */
+/* Function name: InfoCommand() */
+/* */
+/* Arguments */
+/* --------- */
+/* Name: Type: Description: */
+/* Command EPS_INT32 I: Command Code */
+/* pResult EPS_UINT8* O: Result of Info command */
+/* Size EPS_INT32* I/O: size of buffer */
+/* */
+/* Return value: */
+/* EPS_ERR_NONE - Info command executed successfully */
+/* EPS_ERR_COMM_ERROR - Info command execution error */
+/* */
+/* Description: */
+/* Sends Information commands to the printer. */
+/* */
+/*******************************************|********************************************/
+static EPS_ERR_CODE InfoCommand (
+
+ EPS_FILEDSC fd,
+ EPS_INT32 Command,
+ EPS_UINT8* pResult,
+ EPS_INT32* Size
+
+){
+ static EPS_UINT8 stCom[5] = {'x', 'x', 0x01,0x00,0x01};
+ EPS_INT32 ComSize = 0;
+ EPS_INT32 Retry;
+ EPS_INT32 Ret;
+ EPS_INT32 lSize;
+
+ EPS_LOG_FUNCIN;
+
+ switch(Command){
+ case EPS_CBTCOM_DI:
+ stCom[0] = 'd'; stCom[1] = 'i'; stCom[4] = 0x01;
+ break;
+ case EPS_CBTCOM_ST:
+ stCom[0] = 's'; stCom[1] = 't'; stCom[4] = 0x01;
+ break;
+ case EPS_CBTCOM_CX:
+ stCom[0] = 'c'; stCom[1] = 'x'; stCom[4] = 0x01;
+ break;
+ case EPS_CBTCOM_CSA:
+ stCom[0] = 'c'; stCom[1] = 's'; stCom[4] = 0x00;
+ break;
+ case EPS_CBTCOM_CSB:
+ stCom[0] = 'c'; stCom[1] = 's'; stCom[4] = 0x01;
+ break;
+ case EPS_CBTCOM_PM:
+ stCom[0] = 'p'; stCom[1] = 'm'; stCom[4] = 0x01;
+ break;
+ case EPS_CBTCOM_PM2:
+ stCom[0] = 'p'; stCom[1] = 'm'; stCom[4] = 0x02;
+ break;
+ }
+
+ Retry = 5;
+ do{
+ if ((Ret = cbtCommWriteData(fd, EPS_CBTCHANNEL_CTRL, stCom, 5, &ComSize)) != EPCBT_ERR_NONE){
+ EPS_DBGPRINT(("EPS SER : CBT Command Write Failed [%d]\r\n",Ret));
+ if (Ret != EPSCBT_ERR_FNCDISABLE && Ret != EPSCBT_ERR_WRITEERROR){
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+
+ Retry--;
+ if (!Retry) {
+ EPS_DBGPRINT(("EPS SER : CBT Command Write Retry Failed \r\n"));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ serDelayThread(2*_SECOND_, &epsCmnFnc); /* retry command after 2 seconds*/
+ }
+ }while (Ret == EPSCBT_ERR_FNCDISABLE);
+
+ Retry = 5;
+ lSize = *Size;
+ do{
+ if ((Ret = cbtCommReadData(fd, EPS_CBTCHANNEL_CTRL, (EPS_UINT8 *)pResult, lSize, Size)) != EPCBT_ERR_NONE){
+ EPS_DBGPRINT(("EPS SER : CBT Command Read Reply Failed [%d]\r\n",Ret));
+ if (Ret != EPSCBT_ERR_FNCDISABLE && Ret != EPSCBT_ERR_READERROR){
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ }else if (*Size != 0){
+ break;
+ }
+
+ Retry--;
+ if (!Retry){
+ EPS_DBGPRINT(("EPS SER : CBT Command Read Reply Retry Failed \r\n"));
+ EPS_RETURN( EPS_ERR_COMM_ERROR );
+ }
+ serDelayThread(2*_SECOND_, &epsCmnFnc); /* retry command after 2 seconds*/
+ }while(Retry > 0);
+
+ pResult[*Size] = '\0';
+
+ EPS_RETURN( EPS_ERR_NONE );
+}
+
+
+
+/*___________________________________ epson-usb.c ____________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/epson-usb.h b/lib/epson-usb.h
new file mode 100644
index 0000000..823677d
--- /dev/null
+++ b/lib/epson-usb.h
@@ -0,0 +1,71 @@
+/*___________________________________ epson-usb.h ___________________________________*/
+
+/* 1 2 3 4 5 6 7 8 */
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/*******************************************|********************************************/
+/*
+ * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
+ *
+ * Copyright protection claimed includes all forms and matters of
+ * copyrightable material and information now allowed by statutory or judicial
+ * law or hereinafter granted, including without limitation, material generated
+ * from the software programs which are displayed on the screen such as icons,
+ * screen display looks, etc.
+ *
+ */
+/*******************************************|********************************************/
+/* */
+/* Epson USB I/F Definitions */
+/* */
+/*******************************************|********************************************/
+#ifndef _EPSON_USB_H_
+#define _EPSON_USB_H_
+#ifdef __cplusplus
+extern "C" {
+#endif /* def __cplusplus */
+
+/*------------------------------------ Includes -------------------------------------*/
+/*******************************************|********************************************/
+#include "epson-typedefs.h"
+
+/*------------------------------------- Data Types -------------------------------------*/
+/*******************************************|********************************************/
+
+/*---------------------------------- Generic Macros ---------------------------------*/
+/*******************************************|********************************************/
+
+/*----------------------------------- Definitions ------------------------------------*/
+/*******************************************|********************************************/
+
+/*-------------------------- Public Function Declarations ---------------------------*/
+/*******************************************|********************************************/
+extern EPS_ERR_CODE usbFind (EPS_UINT32*, EPS_INT32 );
+extern EPS_ERR_CODE usbProbePrinterByID (EPS_INT8*, EPS_UINT32, EPS_PRINTER_INN** );
+
+extern EPS_ERR_CODE usbStartJob (void );
+extern EPS_ERR_CODE usbRestartJob (void );
+extern EPS_ERR_CODE usbEndJob (void );
+extern EPS_ERR_CODE usbWritePrintData (const EPS_UINT8*, EPS_UINT32, EPS_UINT32* );
+extern EPS_ERR_CODE usbResetPrinter (void );
+
+extern EPS_ERR_CODE usbGetStatus (EPS_STATUS_INFO*, EPS_BOOL*, EPS_BOOL* );
+extern EPS_ERR_CODE usbGetJobStatus (EPS_STATUS_INFO* );
+extern EPS_ERR_CODE usbGetPMString (const EPS_PRINTER_INN*, EPS_INT32,
+ EPS_UINT8*, EPS_INT32* );
+
+extern EPS_ERR_CODE usbMechCommand (EPS_INT32 );
+
+#ifdef __cplusplus
+}
+#endif /* def __cplusplus */
+
+#endif /* def _EPSON_USB_H_ */
+
+/*___________________________________ epson-usb.h ____________________________________*/
+
+/*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
+/* 1 2 3 4 5 6 7 8 */
+/*******************************************|********************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/***** End of File *** End of File *** End of File *** End of File *** End of File ******/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
diff --git a/lib/escpr_def.h b/lib/escpr_def.h
new file mode 100644
index 0000000..780ea3f
--- /dev/null
+++ b/lib/escpr_def.h
@@ -0,0 +1,218 @@
+/***********************************************************************
+ *
+ * Copyright (c) 2005 Seiko Epson Corporation.
+ *
+ * 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
+ *
+ * File Name: escpr_def.h
+ *
+ ***********************************************************************/
+
+#ifndef __EPSON_ESCPR_DEF_H__
+#define __EPSON_ESCPR_DEF_H__
+
+#include "escpr_osdep.h"
+
+/*=======================================================================================*/
+/* typedef */
+/*=======================================================================================*/
+
+typedef ESCPR_BYTE4 (* ESCPR_FPSPOOLFUNC)(void* hParam,
+ const ESCPR_UBYTE1* pBuf, ESCPR_UBYTE4 cbBuf);
+
+typedef ESCPR_BYTE4 ESCPR_ERR_CODE;
+
+typedef enum _ESCPR_ENDIAN {
+ ESCPR_ENDIAN_NOT_TESTED = 0,
+ ESCPR_ENDIAN_BIG,
+ ESCPR_ENDIAN_LITTLE
+} ESCPR_ENDIAN;
+
+/*=======================================================================================*/
+/* struct */
+/*=======================================================================================*/
+
+typedef struct tagESCPR_RECT{
+ ESCPR_BYTE4 left;
+ ESCPR_BYTE4 top;
+ ESCPR_BYTE4 right;
+ ESCPR_BYTE4 bottom;
+}ESCPR_RECT;
+
+typedef struct tagESCPR_BANDBMP{
+ ESCPR_UBYTE4 WidthBytes; /* number of bytes in each scan line */
+ ESCPR_UBYTE1* Bits; /* pointer to the the bit values for the bitmap */
+}ESCPR_BANDBMP;
+
+typedef struct tagESCPR_OPT{
+ ESCPR_BYTE4 nPrnID; /* Printer ID */
+ ESCPR_FPSPOOLFUNC fpspoolfunc; /* pointer to spool function */
+}ESCPR_OPT;
+
+
+/*----- Set Print Quality -----*/
+typedef struct tagESCPR_PRINT_QUALITY{
+ ESCPR_UBYTE1 MediaTypeID;
+ ESCPR_UBYTE1 PrintQuality;
+ ESCPR_UBYTE1 ColorMono;
+ ESCPR_BYTE1 Brightness;
+ ESCPR_BYTE1 Contrast;
+ ESCPR_BYTE1 Saturation;
+ ESCPR_UBYTE1 ColorPlane;
+ ESCPR_UBYTE2 PaletteSize;
+ ESCPR_UBYTE1* PaletteData;
+}ESCPR_PRINT_QUALITY;
+
+/*----- Set Print Job -----*/
+typedef struct tagESCPR_PRINT_JOB{
+ ESCPR_UBYTE4 PaperWidth;
+ ESCPR_UBYTE4 PaperLength;
+ ESCPR_BYTE2 TopMargin;
+ ESCPR_BYTE2 LeftMargin;
+ ESCPR_UBYTE4 PrintableAreaWidth;
+ ESCPR_UBYTE4 PrintableAreaLength;
+ ESCPR_UBYTE1 InResolution;
+ ESCPR_UBYTE1 PrintDirection;
+}ESCPR_PRINT_JOB;
+
+typedef enum tagESCPR_STATUS{
+ ESCPR_STATUS_NOT_INITIALIZED,
+ ESCPR_STATUS_INITIALIZED
+}ESCPR_STATUS;
+
+typedef struct {
+ ESCPR_FPSPOOLFUNC gfpSendData; /* A function pointer for send data function */
+} ESCPR_GLOBALFUNC;
+
+
+/*=======================================================================================*/
+/* define */
+/*=======================================================================================*/
+
+/*=======================================================================================*/
+/* Media Information of Control Command "MI" */
+/*=======================================================================================*/
+/* Media Types */
+#define ESCPR_MTID_PLAIN 0
+#define ESCPR_MTID_360INKJET 1
+#define ESCPR_MTID_IRON 2
+#define ESCPR_MTID_PHOTOINKJET 3
+#define ESCPR_MTID_PHOTOADSHEET 4
+#define ESCPR_MTID_MATTE 5
+#define ESCPR_MTID_PHOTO 6
+#define ESCPR_MTID_PHOTOFILM 7
+#define ESCPR_MTID_MINIPHOTO 8
+#define ESCPR_MTID_OHP 9
+#define ESCPR_MTID_BACKLIGHT 10
+#define ESCPR_MTID_PGPHOTO 11
+#define ESCPR_MTID_PSPHOTO 12
+#define ESCPR_MTID_PLPHOTO 13
+#define ESCPR_MTID_MCGLOSSY 14
+#define ESCPR_MTID_ARCHMATTE 15
+#define ESCPR_MTID_WATERCOLOR 16
+#define ESCPR_MTID_PROGLOSS 17
+#define ESCPR_MTID_MATTEBOARD 18
+#define ESCPR_MTID_PHOTOGLOSS 19
+#define ESCPR_MTID_SEMIPROOF 20
+#define ESCPR_MTID_SUPERFINE2 21
+#define ESCPR_MTID_DSMATTE 22
+#define ESCPR_MTID_CLPHOTO 23
+#define ESCPR_MTID_ECOPHOTO 24
+#define ESCPR_MTID_VELVETFINEART 25
+#define ESCPR_MTID_PROOFSEMI 26
+#define ESCPR_MTID_HAGAKIRECL 27
+#define ESCPR_MTID_HAGAKIINKJET 28
+#define ESCPR_MTID_PHOTOINKJET2 29
+#define ESCPR_MTID_DURABRITE 30
+#define ESCPR_MTID_MATTEMEISHI 31
+#define ESCPR_MTID_HAGAKIATENA 32
+#define ESCPR_MTID_PHOTOALBUM 33
+#define ESCPR_MTID_PHOTOSTAND 34
+#define ESCPR_MTID_RCB 35
+#define ESCPR_MTID_PGPHOTOEG 36
+#define ESCPR_MTID_ENVELOPE 37
+#define ESCPR_MTID_PLATINA 38
+#define ESCPR_MTID_ULTRASMOOTH 39
+#define ESCPR_MTID_CDDVD 91
+#define ESCPR_MTID_CDDVDHIGH 92
+#define ESCPR_MTID_CLEANING 99
+
+/*=======================================================================================*/
+/* Definition of Parameter for Print Quality */
+/*=======================================================================================*/
+/* PrintQuality */
+#define ESCPR_PQ_DRAFT 0 /* Draft */
+#define ESCPR_PQ_NORMAL 1 /* Normal */
+#define ESCPR_PQ_HIGH 2 /* High */
+
+/* ColorMono */
+#define ESCPR_CM_COLOR 0 /* Color */
+#define ESCPR_CM_MONOCHROME 1 /* Monochrome */
+
+/* Brightness */
+#define ESCPR_BRIGHT_DEF 0 /* Default */
+
+/* Contrast */
+#define ESCPR_CONT_DEF 0 /* Default */
+
+/* Saturation */
+#define ESCPR_SATU_DEF 0 /* Default */
+
+/* ColorPlane */
+#define ESCPR_CP_FULLCOLOR 0 /* Full Color */
+#define ESCPR_CP_256COLOR 1 /* 256 Color */
+
+/*=======================================================================================*/
+/* Definition of Parameter for Print Job */
+/*=======================================================================================*/
+/* InResolution */
+#define ESCPR_IR_3636 0 /* 360 x 360 dpi */
+#define ESCPR_IR_7272 1 /* 720 x 720 dpi */
+#define ESCPR_IR_3030 2 /* 300 x 300 dpi */
+#define ESCPR_IR_6060 3 /* 600 x 600 dpi */
+
+/* PrintDirection */
+#define ESCPR_PD_BIDIREC 0 /* Bi-direction */
+#define ESCPR_PD_UNIDIREC 1 /* Uni-direction */
+
+/*=======================================================================================*/
+/* Definition of Send Data */
+/*=======================================================================================*/
+/* CompMode */
+#define ESCPR_COMP_NO 0 /* Non compression */
+#define ESCPR_COMP_DONE 1 /* Runlength compression */
+
+/*=======================================================================================*/
+/* Definition of End Page */
+/*=======================================================================================*/
+#define ESCPR_END_PAGE 0 /* There is no next page */
+#define ESCPR_NEXT_PAGE 1 /* There is a next page */
+
+/*=======================================================================================*/
+/* Definition of Error Code */
+/*=======================================================================================*/
+#define ESCPR_ERR_NOERROR 0 /* terminated normally */
+#define ESCPR_ERR_NOT_SUPPORT -1 /* parameter aren't be supported. */
+#define ESCPR_ERR_DON_T_PROCESS -2 /* on don't process this situation. */
+#define ESCPR_ERR_CAN_T_FREE_HANDLE -3 /* can't free handle. */
+#define ESCPR_ERR_CAN_T_ALLOC_MEMORY -4 /* can't allocate needed memory. */
+#define ESCPR_ERR_HAPPEN_PROBLEM -10 /* happened any error. */
+#define ESCPR_ERR_NOINBMP -20 /* doesn't get an input bitmap. */
+#define ESCPR_ERR_NOATBMP -21 /* doesn't get an attribute bitmap. */
+#define ESCPR_ERR_CAN_T_LOAD_DLL -30 /* can't load DLL */
+#define ESCPR_ERR_SPOOL_IO -40 /* error with spooling i/o function */
+
+#endif
+
diff --git a/lib/escpr_osdep.h b/lib/escpr_osdep.h
new file mode 100644
index 0000000..100dcdd
--- /dev/null
+++ b/lib/escpr_osdep.h
@@ -0,0 +1,74 @@
+/***********************************************************************
+ *
+ * Copyright (c) 2005-2008 Seiko Epson Corporation.
+ *
+ * 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
+ *
+ * File Name: escpr_osdep.h
+ *
+ ***********************************************************************/
+
+#ifndef __EPSON_ESCPR_OSDEP_H__
+#define __EPSON_ESCPR_OSDEP_H__
+
+#include <stddef.h>
+
+/*=======================================================================================*/
+/* typedef Area */
+/*=======================================================================================*/
+typedef unsigned char ESCPR_UBYTE1;
+typedef unsigned short ESCPR_UBYTE2;
+typedef unsigned int ESCPR_UBYTE4;
+
+typedef char ESCPR_BYTE1;
+typedef short ESCPR_BYTE2;
+typedef int ESCPR_BYTE4;
+
+/* Local time */
+typedef struct _tagESCPR_LOCAL_TIME_ {
+ ESCPR_UBYTE2 year;
+ ESCPR_UBYTE1 mon;
+ ESCPR_UBYTE1 day;
+ ESCPR_UBYTE1 hour;
+ ESCPR_UBYTE1 min;
+ ESCPR_UBYTE1 sec;
+}ESCPR_LOCAL_TIME;
+
+/*=======================================================================================*/
+/* Define Area */
+/*=======================================================================================*/
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef BOOL
+#define BOOL int
+#endif
+
+/*=======================================================================================*/
+/* Global Functions */
+/*=======================================================================================*/
+void ESCPR_Mem_Set(void* Dest, ESCPR_BYTE4 c, size_t Size);
+void ESCPR_Mem_Copy(void* Dest, const void* Src, size_t Size);
+void* ESCPR_Mem_Alloc(size_t MemSize);
+void ESCPR_Mem_Free(void* MemPtr);
+BOOL ESCPR_Mem_Compare(const void *s1, const void *s2, size_t n);
+void ESCPR_GetLocalTime(ESCPR_LOCAL_TIME *epsTime);
+
+#endif