diff options
Diffstat (limited to 'attic/servers/gpib_server_lin/src')
-rwxr-xr-x | attic/servers/gpib_server_lin/src/Makefile.am | 11 | ||||
-rw-r--r-- | attic/servers/gpib_server_lin/src/Makefile.in | 531 | ||||
-rw-r--r-- | attic/servers/gpib_server_lin/src/commanalyzer_functions.c | 962 | ||||
-rw-r--r-- | attic/servers/gpib_server_lin/src/commanalyzer_functions.h | 56 | ||||
-rwxr-xr-x | attic/servers/gpib_server_lin/src/gpib_functions.c | 40 | ||||
-rwxr-xr-x | attic/servers/gpib_server_lin/src/gpib_functions.h | 23 | ||||
-rw-r--r-- | attic/servers/gpib_server_lin/src/main_server_lin.c | 1340 | ||||
-rwxr-xr-x | attic/servers/gpib_server_lin/src/parameters.h | 28 | ||||
-rwxr-xr-x | attic/servers/gpib_server_lin/src/scope_functions.c | 516 | ||||
-rwxr-xr-x | attic/servers/gpib_server_lin/src/scope_functions.h | 37 | ||||
-rwxr-xr-x | attic/servers/gpib_server_lin/src/signal_functions.c | 284 | ||||
-rwxr-xr-x | attic/servers/gpib_server_lin/src/signal_functions.h | 28 |
12 files changed, 3856 insertions, 0 deletions
diff --git a/attic/servers/gpib_server_lin/src/Makefile.am b/attic/servers/gpib_server_lin/src/Makefile.am new file mode 100755 index 0000000..05d3a8e --- /dev/null +++ b/attic/servers/gpib_server_lin/src/Makefile.am @@ -0,0 +1,11 @@ +bin_PROGRAMS = gpib_server_lin +gpib_server_lin_SOURCES = gpib_functions.c main_server_lin.c scope_functions.c \ + signal_functions.c commanalyzer_functions.c + +# set the include path found by configure +INCLUDES= $(all_includes) $(GTK_CFLAGS) $(allegro_CFLAGS) + +# the library search path. +gpib_server_lin_LDFLAGS = $(all_libraries) $(GTK_LIBS) $(allegro_LIBS) -lgpib +noinst_HEADERS = gpib_functions.h parameters.h scope_functions.h \ + signal_functions.h commanalyzer_functions.h diff --git a/attic/servers/gpib_server_lin/src/Makefile.in b/attic/servers/gpib_server_lin/src/Makefile.in new file mode 100644 index 0000000..1b9e1d9 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/Makefile.in @@ -0,0 +1,531 @@ +# 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@ +bin_PROGRAMS = gpib_server_lin$(EXEEXT) +subdir = src +DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_gpib_server_lin_OBJECTS = gpib_functions.$(OBJEXT) \ + main_server_lin.$(OBJEXT) scope_functions.$(OBJEXT) \ + signal_functions.$(OBJEXT) commanalyzer_functions.$(OBJEXT) +gpib_server_lin_OBJECTS = $(am_gpib_server_lin_OBJECTS) +gpib_server_lin_LDADD = $(LDADD) +gpib_server_lin_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(gpib_server_lin_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 = $(gpib_server_lin_SOURCES) +DIST_SOURCES = $(gpib_server_lin_SOURCES) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALLEGRO_CONFIG = @ALLEGRO_CONFIG@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +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@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +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@ +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_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +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@ +allegro_CFLAGS = @allegro_CFLAGS@ +allegro_LIBS = @allegro_LIBS@ +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@ +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@ +gpib_server_lin_SOURCES = gpib_functions.c main_server_lin.c scope_functions.c \ + signal_functions.c commanalyzer_functions.c + + +# set the include path found by configure +INCLUDES = $(all_includes) $(GTK_CFLAGS) $(allegro_CFLAGS) + +# the library search path. +gpib_server_lin_LDFLAGS = $(all_libraries) $(GTK_LIBS) $(allegro_LIBS) -lgpib +noinst_HEADERS = gpib_functions.h parameters.h scope_functions.h \ + signal_functions.h commanalyzer_functions.h + +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) --foreign src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/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-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +gpib_server_lin$(EXEEXT): $(gpib_server_lin_OBJECTS) $(gpib_server_lin_DEPENDENCIES) + @rm -f gpib_server_lin$(EXEEXT) + $(gpib_server_lin_LINK) $(gpib_server_lin_OBJECTS) $(gpib_server_lin_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/commanalyzer_functions.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gpib_functions.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main_server_lin.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scope_functions.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal_functions.Po@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 $@ $< + +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 $(PROGRAMS) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; 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: + +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-binPROGRAMS clean-generic 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-binPROGRAMS + +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-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic 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-binPROGRAMS 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-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-binPROGRAMS + + +# 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/attic/servers/gpib_server_lin/src/commanalyzer_functions.c b/attic/servers/gpib_server_lin/src/commanalyzer_functions.c new file mode 100644 index 0000000..207a4d5 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/commanalyzer_functions.c @@ -0,0 +1,962 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <getopt.h> +#include <allegro.h> +#include "parameters.h" +#include "gpib_functions.h" +#include "gpib/ib.h" + +char falpha[1024]; +double commanalyzer_raw_trace_data[1024]; + +unsigned long commanalyzerTraceLength (char * commanalyzerType) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + return 417; + } + else { + return 1; + } +} + +int commanalyzer_set_date(struct tm * datetime, char * commanalyzerType, int gpibDevice) { + char datebuffer [80]; + strftime(datebuffer,80,"CONF:DATE %m%d%y",datetime); + + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting date on communications analyzer\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", datebuffer); + #endif + if (gpib_write(gpibDevice, datebuffer) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_time(struct tm * datetime, char * commanalyzerType, int gpibDevice) { + char timebuffer [80]; + strftime(timebuffer,80,"CONF:TIME +%H.%M",datetime); // FIXME wrong format + + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting time on communications analyzer\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", timebuffer); + #endif + if (gpib_write(gpibDevice, timebuffer) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_switch_to_spectrum_analyzer_mode(char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting communications analyzer to spectrum anayzer mode\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"DISP SAN"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_lock_screen (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Locking communications analyzer screen\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SPEC:DISP 'LOCKED'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_generator_mode_tracking (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer generator to tracking mode\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:RFG 'TRACK'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_generator_mode_fixed (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer generator to fixed mode\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:RFG 'FIXED'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_rf_input_dedicated (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer RF input to dedicated connector\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:INP 'ANT'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_rf_input_muxed (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer RF input to multiplexed connector\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:INP 'RF IN'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_generator_output_dedicated (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer generator output to dedicated connector\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:TGEN:DEST 'DUPL'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_generator_output_muxed (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer generator output to multiplexed connector\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:TGEN:DEST 'RF OUT'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_get_spectrum_analyzer_trace(char * commanalyzerType, int gpibDevice) { + int max_num_bytes = 0; + + unsigned char segarray[4194304]; + unsigned char floatstring[1024]; + long array_pointer; + long ai; + long left_char; + long right_char; + + int x; + int y; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + // Send request + printf("[INFO] Getting spectrum analyzer trace [Stage 1]\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"MEAS:SAN:TRACE?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + max_num_bytes = (commanalyzerTraceLength(commanalyzerType)*24); // Request more bytes than are possible to ensure no bytes are left behind + } + else { + return 2; + } + } + + // Read response + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ibtmo(gpibDevice, T30s); + ibeos(gpibDevice, 0x0); + + ai = gpib_read_array(gpibDevice, max_num_bytes, segarray); + if (ai == -1) { + return 1; + } + else { + if (strcmp("HP8924C", commanalyzerType) == 0) { + left_char = 0; + right_char = 0; + array_pointer = 0; + while (left_char < ai) { + for (right_char=left_char;right_char<ai;right_char++) { + if (segarray[right_char] == ',') { + break; + } + } + strncpy(floatstring, segarray+left_char, right_char-left_char); + floatstring[right_char-left_char] = 0; + commanalyzer_raw_trace_data[array_pointer] = atof(floatstring); + array_pointer++; + left_char = right_char+1; + } + } + else { + return 2; + } + } + + ibtmo(gpibDevice, T10s); + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", array_pointer); + #endif + + return 0; + } +} + +int commanalyzer_set_spectrum_analyzer_center_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + printf("[INFO] Setting spectrum analyzer center frequency to %f\n\r", desired_frequency); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:CFR %E", desired_frequency); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_frequency_span(float desired_frequency, char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + printf("[INFO] Setting spectrum analyzer span frequency to %f\n\r", desired_frequency); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:SPAN %E", desired_frequency); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuation, char * commanalyzerType, int gpibDevice) { + int instrument_att; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + // Only three attenuation values are valid + if (desired_attenuation < 10) { + instrument_att = 0; + } + else if (desired_attenuation < 30) { + instrument_att = 20; + } + else { + instrument_att = 40; + } + } + printf("[INFO] Setting spectrum analyzer attenuation to %d dB\n\r", instrument_att); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:ATT '%d DB'", instrument_att); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, char * commanalyzerType, int gpibDevice) { + int instrument_scale; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + // Only three scale values are valid + if (desired_scale < 1.5) { + instrument_scale = 1; + } + else if (desired_scale < 6) { + instrument_scale = 2; + } + else { + instrument_scale = 10; + } + } + printf("[INFO] Setting spectrum analyzer scale to %d dB/div\n\r", instrument_scale); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:DISP:SCAL '%d DB/DIV'", instrument_scale); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto( char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + printf("[INFO] Setting spectrum analyzer attenuation mode to automatic\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:ATT:MODE 'AUTO'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed( char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + printf("[INFO] Setting spectrum analyzer attenuation mode to fixed\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:ATT:MODE 'HOLD'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_generator_power(float desired_power, char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + printf("[INFO] Setting spectrum analyzer generator power to %f\n\r", desired_power); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:TGEN:AMPL %E", desired_power); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_generator_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + printf("[INFO] Setting spectrum analyzer generator frequency to %f\n\r", desired_frequency); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:TGEN:OFR %E", desired_frequency); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer generator output sweep to ascending\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:TGEN:SWE 'NORM'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_spectrum_analyzer_set_generator_sweep_descending (char * commanalyzerType, int gpibDevice) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + printf("[INFO] Setting spectrum analyzer generator output sweep to descending\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:TGEN:SWE 'INVERT'"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples, char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + int instrument_samples; + if (strcmp("HP8924C", commanalyzerType) == 0) { + // Only certain values are valid, and I am interpreting 0 as no pk/avg and -1 as peak hold + instrument_samples = desired_avg_samples; + if (desired_avg_samples > 5) { + if (desired_avg_samples < 5) { + instrument_samples = desired_avg_samples; + } + else if (desired_avg_samples < 7) { + instrument_samples = 5; + } + else if (desired_avg_samples < 15) { + instrument_samples = 10; + } + else if (desired_avg_samples < 35) { + instrument_samples = 20; + } + else if (desired_avg_samples < 75) { + instrument_samples = 50; + } + else { + instrument_samples = 100; + } + } + } + printf("[INFO] Setting spectrum analyzer generator trace averaging to %d\n\r", instrument_samples); + if (strcmp("HP8924C", commanalyzerType) == 0) { + if (instrument_samples > 0) { + sprintf(falpha,"SAN:TRAC:MHOL 'AVG %d'", instrument_samples); + } + else if (instrument_samples == -1) { + sprintf(falpha,"SAN:TRAC:MHOL 'PK HOLD'"); + } + else { + sprintf(falpha,"SAN:TRAC:MHOL 'NO PK/AVG'"); + } + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_set_spectrum_analyzer_reference_power_level(float desired_reflevel, char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + printf("[INFO] Setting spectrum analyzer generator reference level to %f dBm\n\r", desired_reflevel); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:RLEV %E", desired_reflevel); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + return 8; + } + else { + return -1; + } +} + +int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * commanalyzerType, int gpibDevice) { + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + return 10; + } + else { + return -1; + } +} + +double commanalyzer_get_spectrum_analyzer_reference_power_level(double * retval, char * commanalyzerType, int gpibDevice) { + unsigned char segarray[4194304]; + unsigned char floatstring[1024]; + long array_pointer; + long ai; + long left_char; + long right_char; + + int max_num_bytes = 0; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + // Send request + printf("[INFO] Getting spectrum analyzer reference power level\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:RLEV?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind + } + else { + return 2; + } + } + + // Read response + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ibtmo(gpibDevice, T10s); + ibeos(gpibDevice, 0x0); + + ai = gpib_read_array(gpibDevice, max_num_bytes, segarray); + if (ai == -1) { + return 1; + } + else { + if (strcmp("HP8924C", commanalyzerType) == 0) { + segarray[ai] = 0; + *retval = atof(segarray); + } + else { + return 2; + } + } + + ibtmo(gpibDevice, T10s); + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + +double commanalyzer_get_spectrum_analyzer_scale(double * retval, char * commanalyzerType, int gpibDevice) { + unsigned char segarray[4194304]; + unsigned char floatstring[1024]; + long array_pointer; + long ai; + long left_char; + long right_char; + + int max_num_bytes = 0; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + // Send request + printf("[INFO] Getting spectrum analyzer scale\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:DISP:SCAL?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind + } + else { + return 2; + } + } + + // Read response + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ibtmo(gpibDevice, T10s); + ibeos(gpibDevice, 0x0); + + ai = gpib_read_array(gpibDevice, max_num_bytes, segarray); + if (ai == -1) { + return 1; + } + else { + if (strcmp("HP8924C", commanalyzerType) == 0) { + left_char = 1; + right_char = 0; + array_pointer = 0; + for (right_char=left_char;right_char<ai;right_char++) { + if (segarray[right_char] == ' ') { + break; + } + } + strncpy(floatstring, segarray+left_char, right_char-left_char); + floatstring[right_char-left_char] = 0; + *retval = atof(floatstring); + } + else { + return 2; + } + } + + ibtmo(gpibDevice, T10s); + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + +int commanalyzer_set_display_brightness(float percent, char * commanalyzerType, int gpibDevice) { + int instrument_scale; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + instrument_scale = ((percent/100.0)*7.0)+1; + } + printf("[INFO] Setting display brightness to %d\n\r", instrument_scale); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"CONF:INT %d", instrument_scale); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +double commanalyzer_get_spectrum_analyzer_center_frequency(double * retval, char * commanalyzerType, int gpibDevice) { + unsigned char segarray[4194304]; + unsigned char floatstring[1024]; + long array_pointer; + long ai; + long left_char; + long right_char; + + int max_num_bytes = 0; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + // Send request + printf("[INFO] Getting spectrum analyzer center frequency\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:CFR?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind + } + else { + return 2; + } + } + + // Read response + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ibtmo(gpibDevice, T10s); + ibeos(gpibDevice, 0x0); + + ai = gpib_read_array(gpibDevice, max_num_bytes, segarray); + if (ai == -1) { + return 1; + } + else { + if (strcmp("HP8924C", commanalyzerType) == 0) { + left_char = 1; + right_char = 0; + array_pointer = 0; + for (right_char=left_char;right_char<ai;right_char++) { + if (segarray[right_char] == ' ') { + break; + } + } + strncpy(floatstring, segarray+left_char, right_char-left_char); + floatstring[right_char-left_char] = 0; + *retval = atof(floatstring); + } + else { + return 2; + } + } + + ibtmo(gpibDevice, T10s); + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + +double commanalyzer_get_spectrum_analyzer_span(double * retval, char * commanalyzerType, int gpibDevice) { + unsigned char segarray[4194304]; + unsigned char floatstring[1024]; + long array_pointer; + long ai; + long left_char; + long right_char; + + int max_num_bytes = 0; + + if ((strcmp("HP8924C", commanalyzerType) == 0)) { + // Send request + printf("[INFO] Getting spectrum analyzer frequency span\n\r"); + if (strcmp("HP8924C", commanalyzerType) == 0) { + sprintf(falpha,"SAN:SPAN?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind + } + else { + return 2; + } + } + + // Read response + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ibtmo(gpibDevice, T10s); + ibeos(gpibDevice, 0x0); + + ai = gpib_read_array(gpibDevice, max_num_bytes, segarray); + if (ai == -1) { + return 1; + } + else { + if (strcmp("HP8924C", commanalyzerType) == 0) { + left_char = 1; + right_char = 0; + array_pointer = 0; + for (right_char=left_char;right_char<ai;right_char++) { + if (segarray[right_char] == ' ') { + break; + } + } + strncpy(floatstring, segarray+left_char, right_char-left_char); + floatstring[right_char-left_char] = 0; + *retval = atof(floatstring); + } + else { + return 2; + } + } + + ibtmo(gpibDevice, T10s); + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +}
\ No newline at end of file diff --git a/attic/servers/gpib_server_lin/src/commanalyzer_functions.h b/attic/servers/gpib_server_lin/src/commanalyzer_functions.h new file mode 100644 index 0000000..50f1474 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/commanalyzer_functions.h @@ -0,0 +1,56 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +extern double commanalyzer_raw_trace_data[1024]; + +unsigned long commanalyzerTraceLength (char * commanalyzerType); +int commanalyzer_set_date(struct tm * datetime, char * commanalyzerType, int gpibDevice); +int commanalyzer_set_time(struct tm * datetime, char * commanalyzerType, int gpibDevice); +int commanalyzer_switch_to_spectrum_analyzer_mode (char * commanalyzerType, int gpibDevice); +int commanalyzer_lock_screen (char * commanalyzerType, int gpibDevice); + +int commanalyzer_get_spectrum_analyzer_trace (char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_center_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_frequency_span(float desired_frequency, char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_generator_mode_tracking (char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_generator_mode_fixed (char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_rf_input_dedicated (char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_rf_input_muxed (char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_generator_output_dedicated (char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_generator_output_muxed (char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuation, char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto( char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed( char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_generator_power(float desired_power, char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_generator_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (char * commanalyzerType, int gpibDevice); +int commanalyzer_spectrum_analyzer_set_generator_sweep_descending (char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples, char * commanalyzerType, int gpibDevice); +int commanalyzer_set_spectrum_analyzer_reference_power_level(float desired_reflevel, char * commanalyzerType, int gpibDevice); +int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * commanalyzerType, int gpibDevice); +int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * commanalyzerType, int gpibDevice); + +double commanalyzer_get_spectrum_analyzer_reference_power_level (double * retval, char * commanalyzerType, int gpibDevice); +double commanalyzer_get_spectrum_analyzer_scale (double * retval, char * commanalyzerType, int gpibDevice); +double commanalyzer_get_spectrum_analyzer_center_frequency (double * retval, char * commanalyzerType, int gpibDevice); +double commanalyzer_get_spectrum_analyzer_span (double * retval, char * commanalyzerType, int gpibDevice);
\ No newline at end of file diff --git a/attic/servers/gpib_server_lin/src/gpib_functions.c b/attic/servers/gpib_server_lin/src/gpib_functions.c new file mode 100755 index 0000000..57b20f0 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/gpib_functions.c @@ -0,0 +1,40 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <getopt.h> +#include <allegro.h> +#include "gpib/ib.h" + +int gpib_write(int ud, char * buffer){ + if( ibwrt(ud, buffer, strlen(buffer)) & ERR ) + { + return -1; + } + return 0; +}
\ No newline at end of file diff --git a/attic/servers/gpib_server_lin/src/gpib_functions.h b/attic/servers/gpib_server_lin/src/gpib_functions.h new file mode 100755 index 0000000..d2d6dc6 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/gpib_functions.h @@ -0,0 +1,23 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +int gpib_write(int ud, char * buffer); diff --git a/attic/servers/gpib_server_lin/src/main_server_lin.c b/attic/servers/gpib_server_lin/src/main_server_lin.c new file mode 100644 index 0000000..9788566 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/main_server_lin.c @@ -0,0 +1,1340 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <stdio.h> /* perror() */ +#include <stdlib.h> /* atoi() */ +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <unistd.h> /* read() */ +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <fcntl.h> +#include <glib.h> +#include <gtk/gtk.h> +#include <termios.h> +#include <unistd.h> +#include <sys/signal.h> +#include <sys/types.h> +#include <gpib/ib.h> +#include <time.h> +#include "parameters.h" +#include "scope_functions.h" +#include "signal_functions.h" +#include "commanalyzer_functions.h" + +// Server variables +char *serverAddress; +unsigned short serverPort = 4000; +char *serialportDescription; +char *gpibServerString; + +// Scope parameters +char *scopeBoard; +char *scopeDevice; +char *scopeType; +char scopeFound = 0; +int scope_board_device; + +// Function generator parameters +char *funcgenBoard; +char *funcgenDevice; +char *funcgenType; +char funcgenFound = 0; +int funcgen_board_device; + +// Communications analyzer parameters +char *commanalyzerBoard; +char *commanalyzerDevice; +char *commanalyzerType; +char commanalyzerFound = 0; +int commanalyzer_board_device; + +// Serial port parameters +char *serialDevice; +long serialBaud = 0; + +// Serial stuff +int tty; +struct termios oldtio, newtio; //place for old and new port settings for serial port +struct termios oldkey, newkey; //place tor old and new port settings for keyboard teletype +struct sigaction saio; //definition of signal action +char buf[256]; //buffer for where data is put +int fd_tty; +int wait_flag=TRUE; //TRUE while no signal received +int server_fd_with_serial = -1; + +// Network variables +int clientSocket; +int status = 0; +int last_command_acked = 0; +struct hostent *hostPtr = NULL; +struct sockaddr_in serverName = { 0 }; +int authentication_timer_check(void); +long optval; +int return_status; + +// Timing variables +unsigned int authentication_timer; +unsigned char enable_authentication_timer; + +unsigned char buffer[100000]; + +// Generic server stuff +#define QLEN 100000 +u_short portbase = 0; +struct timeval server_multiplexer; + +// Query server stuff +char *queryservice_port = "4003"; +struct sockaddr_in fsin_query; +int msock_query; +fd_set rfds_query; +fd_set afds_query; +int alen_query; +int fd_query; +int nfds_query; + +// Main server stuff +char *mainservice_port = "4002"; +struct sockaddr_in fsin_mainserver; +int msock_mainserver; +fd_set rfds_mainserver; +fd_set afds_mainserver; +int alen_mainserver; +int fd_mainserver; +int nfds_mainserver; +int ssock_mainserver; +//char main_server_in_use; +//char main_server_fd; +char main_server_state[65535]; +char auth_char_pos; +char auth_string[40]; +int k; +int m; + +// Configuration stuff +static const char filename[] = "remotefpga_gpib.conf"; +char linedata [256]; + +// Shut up GCC +void quiet_write(int fd, const void *buf, size_t count) { + int retcode = write(fd, buf, count); + if (retcode < 0) { + printf("[WARN] Network error\n\r"); + } +} + +void getMyIP (void) +{ + char Buf [256]; + struct hostent* Host; + gethostname (Buf, 256); + Host=(struct hostent *) gethostbyname (Buf); + serverAddress=strdup(inet_ntoa(*((struct in_addr *)Host->h_addr))); + //serverAddress=strdup(Buf); +} + +int msleep(unsigned long milisec) { + struct timespec req={0}; + time_t sec=(int)(milisec/1000); + milisec=milisec-(sec*1000); + req.tv_sec=sec; + req.tv_nsec=milisec*1000000L; + while(nanosleep(&req,&req)==-1) + continue; + return 1; +} + +int musleep(unsigned long milisec) { + struct timespec req={0}; + time_t sec=(int)(milisec/1000); + milisec=milisec-(sec*1000); + req.tv_sec=sec; + req.tv_nsec=milisec*1000L; + while(nanosleep(&req,&req)==-1) + continue; + return 1; +} + +void signal_handler_IO (int status) { + wait_flag = FALSE; +} + +int setupSerial(void) { + struct termios oldtio,newtio; + + fd_tty = open(serialDevice, O_RDWR | O_NOCTTY | O_NONBLOCK | O_APPEND); + if (fd_tty < 0) { + printf("[FAIL] Unable to open serial device %s\n\r", serialDevice); + return 1; + } + + tcgetattr(fd_tty,&oldtio); // Save current port settings + + bzero(&newtio, sizeof(newtio)); + newtio.c_cflag = serialBaud | CS8 | CLOCAL | CREAD; + newtio.c_iflag = IGNPAR; + newtio.c_oflag = 0; + + // Set input mode (non-canonical, no echo,...) + newtio.c_lflag = 0; + + newtio.c_cc[VTIME] = 0; // Inter-character timer unused + newtio.c_cc[VMIN] = 0; // Blocking read unused + + tcflush(fd_tty, TCIFLUSH); + tcsetattr(fd_tty,TCSANOW,&newtio); + + return 0; +} + +int getConfig(char *parameter, char *line) { + int i; + + if (strstr(line, parameter) != NULL) { + for (i=0; i<(strlen(line)-strlen(parameter));i++) { + linedata[i] = line[i+strlen(parameter)]; + } + linedata[i-1]=0; + + return 0; + } + else { + return 1; + } +} + +void concatenateStrings(char * str1, char * str2) { + char *str3; + + str3 = (char *)calloc(strlen(str1) + strlen(str2) + 1, sizeof(char)); + strcpy(str3, str1); + strcat(str3, str2); + + str1 = (char *)calloc(strlen(str3) + 1, sizeof(char)); + + strcpy(str1, str3); + + free(str1); + free(str3); +} + +/* returns a device descriptor after prompting user for primary address */ +int open_gpib_device(int minor, int pad) +{ + int ud; + const int sad = 0; + const int send_eoi = 1; + const int eos_mode = 0; + const int timeout = T1s; + + printf("[INFO] Trying to open GPIB device %i on board /dev/gpib%i...\n\r", pad, minor); + ud = ibdev(minor, pad, sad, timeout, send_eoi, eos_mode); + if(ud < 0) + { + printf("[WARN] GPIB interface error\n\r"); + return -1; + } + + return ud; +} + +char * scopeLongDescription (char * scopeType) { + if (strcmp("HP54600OS", scopeType) == 0) { + return "Hewlett Packard 54600 series"; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + return "Tektronix 744A series"; + } + else { + return "UNKNOWN"; + } +} + +char * commanalyzerLongDescription (char * scopeType) { + if (strcmp("HP8924C", commanalyzerType) == 0) { + return "Hewlett Packard 8924 series"; + } + else { + return "UNKNOWN"; + } +} + +char * funcgenLongDescription (char * funcgenType) { + if (strcmp("AG33250A", funcgenType) == 0) { + return "Agilent AG33250A"; + } + else { + return "UNKNOWN"; + } +} + +int readConfig(void) { + int i; + + FILE *file = fopen ( filename, "r" ); + if ( file != NULL ) { + char line [256]; // or other suitable maximum line size + // read a line + while ( fgets ( line, sizeof line, file ) != NULL ) { + // Parse the line and update global variables (current line in variable "line") + if (getConfig("SERVER_DESCRIPTION:", line) == 0) { + gpibServerString = strdup(linedata); + printf("[INFO] Server Description: %s\n\r", gpibServerString); + } + if (getConfig("SERIAL_PORT:", line) == 0) { + serialDevice = strdup(linedata); + printf("[INFO] Serial Port: %s\n\r", serialDevice); + } + if (getConfig("BAUD_RATE:", line) == 0) { + if (strcmp(linedata, "9600") == 0) serialBaud = B9600; + if (strcmp(linedata, "115200") == 0) serialBaud = B115200; + //serialBaud = B9600; + printf("[INFO] Baud Rate: %s [%ld]\n\r", linedata, serialBaud); + serialportDescription = strdup(linedata); + } + if (getConfig("SCOPE_BOARD:", line) == 0) { + scopeBoard = strdup(linedata); + scopeFound++; + } + if (getConfig("SCOPE_DEVICE:", line) == 0) { + scopeDevice = strdup(linedata); + scopeFound++; + } + if (getConfig("SCOPE_TYPE:", line) == 0) { + scopeType = strdup(linedata); + scopeFound++; + } + if (getConfig("FUNCTION_GENERATOR_BOARD:", line) == 0) { + funcgenBoard = strdup(linedata); + funcgenFound++; + } + if (getConfig("FUNCTION_GENERATOR_DEVICE:", line) == 0) { + funcgenDevice = strdup(linedata); + funcgenFound++; + } + if (getConfig("FUNCTION_GENERATOR_TYPE:", line) == 0) { + funcgenType = strdup(linedata); + funcgenFound++; + } + if (getConfig("COMMANALYZER_BOARD:", line) == 0) { + commanalyzerBoard = strdup(linedata); + commanalyzerFound++; + } + if (getConfig("COMMANALYZER_DEVICE:", line) == 0) { + commanalyzerDevice = strdup(linedata); + commanalyzerFound++; + } + if (getConfig("COMMANALYZER_TYPE:", line) == 0) { + commanalyzerType = strdup(linedata); + commanalyzerFound++; + } + } + fclose ( file ); + if (scopeFound == 3) { + printf("[INFO] Oscilloscope conjectured to be on GPIB address %s:%s\n\r", scopeBoard, scopeDevice); + scope_board_device = open_gpib_device(atoi(scopeBoard), atoi(scopeDevice)); + if (scope_board_device < 0) { + //return 1; + } + else { + time_t rawtime; + struct tm * timeinfo; + char datebuffer [80]; + char timebuffer [80]; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + strftime(timebuffer,80,"TIME \"%H:%M:%S\"",timeinfo); + strftime(datebuffer,80,"DATE \"%Y-%m-%d\"",timeinfo); + printf("[INFO] Configuring %s oscilloscope\n\r", scopeLongDescription(scopeType)); + printf("[INFO] %s\n\r", datebuffer); + printf("[INFO] %s\n\r", timebuffer); + if (gpib_write(scope_board_device, timebuffer) == 0) { + gpib_write(scope_board_device, datebuffer); + printf("[INFO] Communication verified\n\r"); + } + else { + printf("[WARN] Communication failed!\n\r"); + } + } + } + if (funcgenFound == 3) { + printf("[INFO] Function generator conjectured to be on GPIB address %s:%s\n\r", funcgenBoard, funcgenDevice); + funcgen_board_device = open_gpib_device(atoi(funcgenBoard), atoi(funcgenDevice)); + if (funcgen_board_device < 0) { + //return 1; + } + else { + printf("[INFO] Configuring %s function generator\n\r", funcgenLongDescription(funcgenType)); + if (gpib_write(funcgen_board_device, "RESET") == 0) { + printf("[INFO] Communication verified\n\r"); + } + else { + printf("[WARN] Communication failed!\n\r"); + } + } + } + if (commanalyzerFound == 3) { + printf("[INFO] Communications analyzer conjectured to be on GPIB address %s:%s\n\r", commanalyzerBoard, commanalyzerDevice); + commanalyzer_board_device = open_gpib_device(atoi(commanalyzerBoard), atoi(commanalyzerDevice)); + if (commanalyzer_board_device < 0) { + //return 1; + } + else { + time_t rawtime; + struct tm * timeinfo; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + printf("[INFO] Configuring %s communications analyzer\n\r", commanalyzerLongDescription(commanalyzerType)); + if (commanalyzer_set_time(timeinfo, commanalyzerType, commanalyzer_board_device) == 0) { + commanalyzer_set_date(timeinfo, commanalyzerType, commanalyzer_board_device); + printf("[INFO] Communication verified\n\r"); + } + else { + printf("[WARN] Communication failed!\n\r"); + } + } + } + } + else + { + printf("[WARN] Unable to open configuration file %s\n\r", filename); + return 1; + } + + return 0; +} + +int authentication_timer_check(void) { + authentication_timer++; + + return enable_authentication_timer; +} + +int passivesock(const char *service, const char *transport, int qlen) { + struct servent *pse; + struct protoent *ppe; + struct sockaddr_in sin; + int s; + int type; + + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + + // Map service name to port number + if(pse = getservbyname(service, transport)) { + sin.sin_port = htons(ntohs((u_short)pse->s_port) + portbase); + } + else if((sin.sin_port = htons((u_short)atoi(service))) == 0) { + printf("[FAIL] Query Server Service Entry %s\n\r", service); + return -1; + } + + // Map protocol name to protocol number + if((ppe = getprotobyname(transport)) == 0) { + printf("[FAIL] Query Server Protocol Entry %s\n\r", transport); + return -1; + } + + // Use protocol to choose a socket type + if(strcmp(transport, "udp") == 0) { + type = SOCK_DGRAM; + } + else { + type = SOCK_STREAM; + } + + // Allocate a socket + s = socket(PF_INET, type, ppe->p_proto); + + if(s < 0) { + printf("[FAIL] Socket Error\n\r"); + return -1; + } + + // Bind the socket + if(bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + printf("[FAIL] Cannot bind to port %s\n\r", service); + return -1; + } + + if(type == SOCK_STREAM && listen(s, qlen) < 0) { + printf("[FAIL] Cannot bind to port %s\n\r", service); + return -1; + } + return s; +} + +int passiveTCP(const char *service, int qlen) { + return passivesock(service, "tcp", qlen); +} + +int queryserver(int fd) { + return 0; +} + +void buffer_lookfor_two_termdegree (unsigned char * array, unsigned char * array2, int termination_count) { + int i; + int k; + char degree_found; + + degree_found = 0; + k=0; + for (i=0;i<termination_count;i++) { + if (array[i+1] == 176) { + if (degree_found == 0) { + degree_found = 1; + } + else { + degree_found = 3; + } + } + if (degree_found == 2) { + array2[k] = array[i+1]; + k++; + } + if (degree_found == 1) { + array[i] = 0; + degree_found = 2; + k=0; + } + else { + array[i] = array[i+1]; + } + } + array[i] = 0; + array2[k] = 0; +} + +void buffer_lookfor_termdegree (unsigned char * array, int termination_count) { + int i; + char degree_found; + + degree_found = 0; + for (i=0;i<termination_count;i++) { + if (array[i+1] == 176) { + degree_found = 1; + } + if (degree_found == 1) { + array[i] = 0; + } + else { + array[i] = array[i+1]; + } + } + array[i] = 0; +} + +int mainserver(int fd) { + char readbuf[100000]; + char readbuf2[100000]; + char writebuf[100000]; + int cc; + int z; + long bytestosend; + char errorbuf[1000]; + + cc = 1; + switch (main_server_state[fd]) { + case 1: // Check the command code + cc = read(fd, readbuf, 1); + if (cc > 0) { + // Got one! + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Got command %d on server fd %d\n\r", readbuf[0], fd); + #endif + + // What is it? + if (readbuf[0] == 31) { + // Serial channel open request + // Open the serial port + printf("[INFO] Opening serial port for fd %d...\n\r", fd); + if (serialBaud != 0) { + if (setupSerial() != 0) { + printf("[FAIL] Cannot open serial port\n\r"); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + else { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + main_server_state[fd] = 4; + server_fd_with_serial = fd; + printf("[INFO] Entering state 4 on server fd %d\n\r", fd); + } + } + else { + printf("[FAIL] Serial port not set up!\n\r"); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 21) { + // Scope request + if (scope_board_device < 0) { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + else { + if (strcmp("HP54600OS", scopeType) == 0) { + quiet_write(fd, "546\r", strlen("546\r")); + main_server_state[fd] = 5; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + quiet_write(fd, "744\r", strlen("744\r")); + main_server_state[fd] = 5; + } + else { + // Scope not recognized, apparently + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + printf("[INFO] Entering state %d on server fd %d\n\r", main_server_state[fd], fd); + } + } + else if (readbuf[0] == 40) { + // Function generator request + if (funcgen_board_device < 0) { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + else { + if (strcmp("AG33250A", funcgenType) == 0) { + //if (signal_reset(funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + main_server_state[fd] = 6; + //} + // Function generator seems to have failed + //write(fd, "NCK\r", strlen("NCK\r")); + } + else { + // Function generator not recognized, apparently + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + printf("[INFO] Entering state %d on server fd %d\n\r", main_server_state[fd], fd); + } + } + else if (readbuf[0] == 41) { + // Communications analyzer request + if (commanalyzer_board_device < 0) { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + else { + if (strcmp("HP8924C", commanalyzerType) == 0) { + quiet_write(fd, "892\r", strlen("892\r")); + main_server_state[fd] = 7; + } + else { + // Communications analyzer not recognized, apparently + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + printf("[INFO] Entering state %d on server fd %d\n\r", main_server_state[fd], fd); + } + } + } + break; + + case 4: // Process serial port transfers + cc = read(fd_tty, readbuf, 100000); + if (cc > 0) { + quiet_write(fd, readbuf, cc); + fsync(fd_tty); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Got %d bytes from the serial port\n\r", cc); + #endif + } + cc = read(fd, writebuf, 100000); + if (cc > 0) { + quiet_write(fd_tty, writebuf, cc); + fsync(fd); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Got %d bytes from the network interface\n\r", cc); + #endif + } + break; + + case 5: // Process scope interface commands + cc = read(fd, readbuf, 25); + if (cc > 0) { + // Got one! + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Got command %d on server fd %d\n\r", readbuf[0], fd); + #endif + if ((readbuf[0] == 20) || (readbuf[0] == 29)) { // Want scope screenshot! + quiet_write(fd, "ACK", strlen("ACK")); + fsync(fd); + if (scope_get_screenshot(scopeType, scope_board_device) == 0) { + sleep (5); + scope_board_device = open_gpib_device(atoi(scopeBoard), atoi(scopeDevice)); + if (scope_get_screenshot_stage2(scopeType, scope_board_device) == 0) { + // Send the data, all of it! + quiet_write(fd, "ACK", strlen("ACK")); + + bytestosend = scopeScreenSize(scopeType); + k=0; + while (bytestosend > 0) { + return_status = write(fd, scope_raw_screenshot_data+k, 1); + if (return_status > 0) { + bytestosend = bytestosend - return_status; + k++; + } + else { + bytestosend = 0; + } + } + } + else { + quiet_write(fd, "NCK", strlen("NCK")); + } + } + else { + quiet_write(fd, "NCK", strlen("NCK")); + } + } + else if (readbuf[0] == 22) { // Want to change horizontal timebase + buffer_lookfor_termdegree(readbuf, 25); + if (scope_set_timebase(atof(readbuf), scopeType, scope_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 23) { // Want to change volts per division + buffer_lookfor_two_termdegree(readbuf, readbuf2, 25); + if (scope_set_volts_div(atoi(readbuf), atof(readbuf2), scopeType, scope_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 24) { // Want to change run status + buffer_lookfor_termdegree(readbuf, 25); + if (scope_set_acquisition(atoi(readbuf), scopeType, scope_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 25) { // Want to change channel enable + buffer_lookfor_two_termdegree(readbuf, readbuf2, 25); + if (scope_set_channel_state(atoi(readbuf), atoi(readbuf2), scopeType, scope_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 26) { // Want to change trigger channel + buffer_lookfor_termdegree(readbuf, 25); + if (scope_set_trigger_channel(atoi(readbuf), scopeType, scope_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 27) { // Want to change trigger level + buffer_lookfor_termdegree(readbuf, 25); + if (scope_set_trigger_level(atof(readbuf), scopeType, scope_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 28) { // Want to change channel vertical position + buffer_lookfor_two_termdegree(readbuf, readbuf2, 25); + if (scope_set_channel_position(atoi(readbuf), atof(readbuf2), scopeType, scope_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + } + break; + case 6: // Process function generator interface commands + cc = read(fd, readbuf, 25); + if (cc > 0) { + // Got one! + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Got command %d on server fd %d\n\r", readbuf[0], fd); + #endif + if (readbuf[0] == 40) { // Want to reset function generator + if (signal_reset(funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 41) { // Is function generator configured? + // If I'm in state 6 it had *better* be available!!! + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else if (readbuf[0] == 42) { // Want to change frequency + buffer_lookfor_termdegree(readbuf, 25); + if (signal_set_frequency(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 43) { // Want to change duty cycle + buffer_lookfor_termdegree(readbuf, 25); + if (signal_set_duty_cycle(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 44) { // Want to set square wave + if (signal_set_waveform("SQUARE", funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 45) { // Want to set sine wave + if (signal_set_waveform("SINUSOID", funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 46) { // Want to set triangle wave + if (signal_set_waveform("RAMP", funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 47) { // Want to set noise wave + if (signal_set_waveform("NOISE", funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 48) { // Want to change P-P voltage + buffer_lookfor_termdegree(readbuf, 25); + if (signal_set_peak_peak_voltage(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + else if (readbuf[0] == 49) { // Want to change offset voltage + buffer_lookfor_termdegree(readbuf, 25); + if (signal_set_offset_voltage(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, errorbuf, strlen(errorbuf)); + } + } + } + break; + case 7: // Process communications analyzer interface commands + cc = read(fd, readbuf, 25); + if (cc > 0) { + // Got one! + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Got command %d on server fd %d\n\r", readbuf[0], fd); + #endif + if (readbuf[0] == 40) { // Want to set SA mode + if (commanalyzer_switch_to_spectrum_analyzer_mode(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 41) { // Is communications analyzer configured? + // If I'm in state 7 it had *better* be available!!! + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else if ((readbuf[0] == 42)) { // Want SA trace + quiet_write(fd, "ACK\r", strlen("ACK\r")); + fsync(fd); + if (commanalyzer_get_spectrum_analyzer_trace(commanalyzerType, commanalyzer_board_device) == 0) { + bytestosend = commanalyzerTraceLength(commanalyzerType)*sizeof(double); + int16_t numbytes = bytestosend; + quiet_write(fd, &numbytes, 2); + quiet_write(fd, "\r", 1); + fsync(fd); + k=0; + while (bytestosend > 0) { + return_status = write(fd, ((uint8_t*)commanalyzer_raw_trace_data)+k, 1); + if (return_status > 0) { + bytestosend = bytestosend - return_status; + k++; + } + else { + bytestosend = 0; + } + } + fsync(fd); + } + else { + quiet_write(fd, "NCK", strlen("NCK")); + } + } + else if (readbuf[0] == 43) { // Want to lock screen + if (commanalyzer_lock_screen(commanalyzerType, commanalyzer_board_device) == 0) { + commanalyzer_set_display_brightness(0, commanalyzerType, commanalyzer_board_device); // Don't burn in the screen + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 44) { // Want to set generator to tracking mode + if (commanalyzer_spectrum_analyzer_set_generator_mode_tracking(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 45) { // Want to set generator to fixed mode + if (commanalyzer_spectrum_analyzer_set_generator_mode_fixed(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 46) { // Want to change center frequency + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_center_frequency(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 47) { // Want to change frequency span + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_frequency_span(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 48) { // Want to set RF input to dedicated connector + if (commanalyzer_spectrum_analyzer_set_rf_input_dedicated(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 49) { // Want to set RF input to multiplexed connector + if (commanalyzer_spectrum_analyzer_set_rf_input_muxed(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 50) { // Want to set generator output to dedicated connector + if (commanalyzer_spectrum_analyzer_set_generator_output_dedicated(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 51) { // Want to set generator output to multiplexed connector + if (commanalyzer_spectrum_analyzer_set_generator_output_muxed(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 52) { // Want to change input attenuation + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_input_attenuation(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 53) { // Want to change scale + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_scale(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 54) { // Want to set RF input attenuator mode to automatic + if (commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 55) { // Want to set RF input attenuator mode to fixed + if (commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 56) { // Want to change generator output power + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_generator_power(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 57) { // Want to change generator output frequency + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_generator_frequency(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 58) { // Want to set generator sweep to ascending + if (commanalyzer_spectrum_analyzer_set_generator_sweep_ascending(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 59) { // Want to set generator sweep to descending + if (commanalyzer_spectrum_analyzer_set_generator_sweep_descending(commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 60) { // Want to set trace averaging + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_trace_averaging(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 61) { // Want to set reference power level + buffer_lookfor_termdegree(readbuf, 25); + if (commanalyzer_set_spectrum_analyzer_reference_power_level(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 62) { // Want the number of vertical divisions available + int16_t divisions = commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions(commanalyzerType, commanalyzer_board_device); + if (divisions >= 0) { + quiet_write(fd, &divisions, 2); + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 63) { // Want the number of samples in a trace + int16_t divisions = commanalyzerTraceLength(commanalyzerType); + if (divisions >= 0) { + quiet_write(fd, &divisions, 2); + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, &divisions, 2); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 64) { // Want the number of horizontal divisions available + int16_t divisions = commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions(commanalyzerType, commanalyzer_board_device); + if (divisions >= 0) { + quiet_write(fd, &divisions, 2); + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, &divisions, 2); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 65) { // Want the reference power level + double rpower; + if (commanalyzer_get_spectrum_analyzer_reference_power_level(&rpower, commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, &rpower, sizeof(double)); + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, &rpower, sizeof(double)); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 66) { // Want the vertical division scale + double scale; + if (commanalyzer_get_spectrum_analyzer_scale(&scale, commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, &scale, sizeof(double)); + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, &scale, sizeof(double)); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 67) { // Want to get the center frequency + double freq; + if (commanalyzer_get_spectrum_analyzer_center_frequency(&freq, commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, &freq, sizeof(double)); + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, &freq, sizeof(double)); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + else if (readbuf[0] == 68) { // Want to get the frequency span + double freq; + if (commanalyzer_get_spectrum_analyzer_span(&freq, commanalyzerType, commanalyzer_board_device) == 0) { + quiet_write(fd, &freq, sizeof(double)); + quiet_write(fd, "ACK\r", strlen("ACK\r")); + } + else { + quiet_write(fd, &freq, sizeof(double)); + quiet_write(fd, "NCK\r", strlen("NCK\r")); + } + } + } + break; + case 2: // Open the serial port + printf("[INFO] Opening serial port...\n\r"); + if (setupSerial() != 0) { + printf("[FAIL] Cannot open serial port\n\r"); + cc = 0; + } + main_server_state[fd] = 1; + break; + case 127: sleep(1); + cc = 0; + break; + } + + return cc; +} + +int RunQueryServer() { + msock_query = passiveTCP(queryservice_port, QLEN); + if (msock_query == -1) { + return -1; + } + nfds_query = getdtablesize(); + FD_ZERO(&afds_query); + FD_SET(msock_query, &afds_query); +} + +int RunMainServer() { + //main_server_in_use = 0; + //main_server_fd = -1; + msock_mainserver = passiveTCP(mainservice_port, QLEN); + if (msock_mainserver == -1) { + return -1; + } + nfds_mainserver = getdtablesize();; + FD_ZERO(&afds_mainserver); + FD_SET(msock_mainserver, &afds_mainserver); +} + +int main(int argc, char *argv[]) +{ + char successful = 1; + + server_multiplexer.tv_sec = 0; + server_multiplexer.tv_usec = 10; + + // Register signal handler + signal(SIGPIPE, signal_handler_IO); + + printf("RemoteFPGA GPIB Server v%s.%s%s\n\r", SERVER_MAJOR, SERVER_MINOR, SERVER_REVISION); + printf("(c) %s Timothy Pearson\n\r", COPYRIGHT_DATE); + printf("(c) %s Remote Laboratory FOSS Contributors\n\r", FOSS_COPYRIGHT_DATE); + + getMyIP(); + + printf("[INFO] Reading configuration from %s...\n\r", filename); + readConfig(); + + if (serialBaud != 0) { + printf("[INFO] Opening serial port...\n\r"); + if (setupSerial() != 0) { + successful = 0; + } + printf("[INFO] Closing serial port...\n\r"); + close(fd_tty); + } + + if (successful == 1) { + // Open query port 4001 + if (RunQueryServer() == -1) { + successful = 0; + } + else { + printf("[INFO] Query process started on %s:%s\n\r", serverAddress, queryservice_port); + } + } + + if (successful == 1) { + // Open main port 4000 + if (RunMainServer() == -1) { + successful = 0; + } + else { + printf("[INFO] Main port opened on %s:%s\n\r", serverAddress, mainservice_port); + } + } + + if (successful == 1) { + while (1) { + //musleep(1); + musleep(10); + //musleep(50); + //musleep(100); + //musleep(250); + //musleep(1000); + + // Execute Query Server + memcpy(&rfds_query, &afds_query, sizeof(rfds_query)); + if (select(nfds_query, &rfds_query, (fd_set *)0, (fd_set *)0, &server_multiplexer) < 0) { + //errexit("select: %s\n\r", strerror(errno)); + } + if (FD_ISSET(msock_query, &rfds_query)) { + int ssock_query; + alen_query = sizeof(fsin_query); + ssock_query = accept(msock_query, (struct sockaddr *)&fsin_query, &alen_query); + if (ssock_query >= 0) { + printf("[INFO] Query received from %s\n\r", inet_ntoa(fsin_query.sin_addr)); + + FD_SET(ssock_query, &afds_query); + if (strlen(gpibServerString) > 0) { + quiet_write(ssock_query, gpibServerString, strlen(gpibServerString)); + quiet_write(ssock_query, "\r", strlen("\r")); + } + if (serialBaud != 0) { + quiet_write(ssock_query, "Auxiliary serial port: ", strlen("Auxiliary serial port: ")); + quiet_write(ssock_query, serialportDescription, strlen(serialportDescription)); + quiet_write(ssock_query, " baud\r", strlen(" baud\r")); + } + if (scopeFound == 3) { + quiet_write(ssock_query, scopeLongDescription(scopeType), strlen(scopeLongDescription(scopeType))); + quiet_write(ssock_query, " oscilloscope\r", strlen(" oscilloscope\r")); + } + if (funcgenFound == 3) { + quiet_write(ssock_query, funcgenLongDescription(funcgenType), strlen(funcgenLongDescription(funcgenType))); + quiet_write(ssock_query, " signal generator\r", strlen(" signal generator\r")); + } + if (commanalyzerFound == 3) { + quiet_write(ssock_query, commanalyzerLongDescription(commanalyzerType), strlen(commanalyzerLongDescription(commanalyzerType))); + quiet_write(ssock_query, " communications analyzer\r", strlen(" communications analyzer\r")); + } + } + else { + printf("[WARN] Unable to accept query connection\n\r"); + } + } + for (fd_query=0; fd_query < nfds_query; fd_query++) { + if(fd_query != msock_query && FD_ISSET(fd_query, &rfds_query)) { + if(queryserver(fd_query) == 0) { + (void) close(fd_query); + FD_CLR(fd_query, &afds_query); + } + } + } + + // Execute Main Server + memcpy(&rfds_mainserver, &afds_mainserver, sizeof(rfds_mainserver)); + if (select(nfds_mainserver, &rfds_mainserver, (fd_set *)0, (fd_set *)0, &server_multiplexer) < 0) { + //errexit("select: %s\n\r", strerror(errno)); + } + if (FD_ISSET(msock_mainserver, &rfds_mainserver)) { + int ssock_mainserver; + alen_mainserver = sizeof(fsin_mainserver); + ssock_mainserver = accept(msock_mainserver, (struct sockaddr *)&fsin_mainserver, &alen_mainserver); + + optval = 4194304; + status = setsockopt(ssock_mainserver, SOL_SOCKET, SO_SNDBUF, &optval, sizeof(optval)); + printf("[INFO] Socket send buffer size set to %ld bytes\n", optval, status); + + if (ssock_mainserver >= 0) { + //printf("[INFO] Connection established with %s\n\r", &fsin_mainserver.sin_addr); + } + FD_SET(ssock_mainserver, &afds_mainserver); + + fcntl(ssock_mainserver, F_SETFL, (fcntl(ssock_mainserver, F_GETFL) | O_NONBLOCK)); + //int sockbufsize = 0; + //int size = sizeof(int); + //getsockopt(ssock_mainserver, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &size); + //printf("[DEBG] SO_RCVBUF: %d\n\r", sockbufsize); + main_server_state[ssock_mainserver] = 1; + //write(ssock_mainserver, "OPENA", strlen("OPENA")); + + printf("[INFO] Connection established with client %s\n\r", inet_ntoa(fsin_mainserver.sin_addr)); + } + for (fd_mainserver=0; fd_mainserver < nfds_mainserver; ++fd_mainserver) { + if (fd_mainserver != msock_mainserver && FD_ISSET(fd_mainserver, &rfds_mainserver)) { + if (mainserver(fd_mainserver) == 0) { + (void) close(fd_mainserver); + FD_CLR(fd_mainserver, &afds_mainserver); + if (server_fd_with_serial != -1) { + printf("[INFO] Closing serial port...\n\r"); + close(fd_tty); + } + printf("[INFO] Connection with client terminated\n\r"); + } + } + } + if (server_fd_with_serial != -1) { + mainserver(server_fd_with_serial); + } + } + } + + return EXIT_SUCCESS; +}
\ No newline at end of file diff --git a/attic/servers/gpib_server_lin/src/parameters.h b/attic/servers/gpib_server_lin/src/parameters.h new file mode 100755 index 0000000..0c1776d --- /dev/null +++ b/attic/servers/gpib_server_lin/src/parameters.h @@ -0,0 +1,28 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#define SERVER_MAJOR "1" +#define SERVER_MINOR "01" +#define SERVER_REVISION "a" +#define COPYRIGHT_DATE "2009-2012" +#define FOSS_COPYRIGHT_DATE "2009-2012" +#define ENABLE_EXTRA_DEBUGGING
\ No newline at end of file diff --git a/attic/servers/gpib_server_lin/src/scope_functions.c b/attic/servers/gpib_server_lin/src/scope_functions.c new file mode 100755 index 0000000..8d35552 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/scope_functions.c @@ -0,0 +1,516 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <getopt.h> +#include <allegro.h> +#include "parameters.h" +#include "gpib_functions.h" +#include "gpib/ib.h" + +char falpha[1024]; +unsigned char scope_raw_screenshot_data[4194304]; + +unsigned long scopeScreenWidth (char * scopeType) { + if (strcmp("HP54600OS", scopeType) == 0) { + return 512; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + return 640; + } + else { + return 1; + } +} + +unsigned long scopeScreenHeight (char * scopeType) { + if (strcmp("HP54600OS", scopeType) == 0) { + return 280; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + return 480; + } + else { + return 1; + } +} + +unsigned long scopeScreenSize (char * scopeType) { + if (strcmp("HP54600OS", scopeType) == 0) { + return scopeScreenWidth(scopeType)*scopeScreenHeight(scopeType)*3; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + return scopeScreenWidth(scopeType)*scopeScreenHeight(scopeType)*3; + } + else { + return 1; + } +} + +int gpib_read_binblock(int ud, int max_num_bytes, char * scopeType) +{ + unsigned char segarray[4194304]; + long array_pointer; + long ai; + + int x; + int y; + + array_pointer = 0; + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ibtmo(ud, T30s); + ibeos(ud, 0x0); + + ai = gpib_read_array(ud, max_num_bytes, segarray); + if (ai == -1) { + return 1; + } + else { + if (strcmp("HP54600OS", scopeType) == 0) { + ai = 0; + for (x=0;x<scopeScreenWidth(scopeType);x++) { + for (y=0;y<scopeScreenHeight(scopeType);y++) { + if ((x & 0x7) == 0) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x80) << 0; + if ((x & 0x7) == 1) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x40) << 1; + if ((x & 0x7) == 2) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x20) << 2; + if ((x & 0x7) == 3) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x10) << 3; + if ((x & 0x7) == 4) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x08) << 4; + if ((x & 0x7) == 5) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x04) << 5; + if ((x & 0x7) == 6) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x02) << 6; + if ((x & 0x7) == 7) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x01) << 7; + if (scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] == 0x0) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = 255; + if (scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] == 0x80) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = 0; + } + } + } + else { + return 2; + } + } + + ibtmo(ud, T10s); + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", array_pointer); + #endif + + return 0; +} + +int gpib_read_array(int ud, int max_num_bytes, unsigned char * segarray) +{ + int br; + + ibrd(ud, segarray, max_num_bytes-1); + br = ThreadIbcntl(); + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Number of bytes read from GPIB device: %li\n", br); + #endif + if ((ThreadIbsta() & ERR) && (br == 0)) { + return -1; + } + return br; +} + +int gpib_read_binary(int ud, int max_num_bytes) +{ + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + //ibrd(ud, scope_raw_screenshot_data, max_num_bytes-1); + system("rm -f /tmp/current_scope_screenshot.bmp"); + ibrdf(ud, "/tmp/current_scope_screenshot.bmp"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Number of bytes read from GPIB device: %li\n", ThreadIbcntl()); + #endif + if (ThreadIbsta() & ERR) { + return -1; + } + return 0; +} + +int scope_get_screenshot_stage2(char * scopeType, int gpibDevice) { + long bytestosend; + int k; + int m; + + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Getting scope screenshot [Stage 2]\n\r"); + if (strcmp("HP54600OS", scopeType) == 0) { + if (gpib_read_binblock(gpibDevice, 19768, scopeType) == 0) { + return 0; + } + else { + return 1; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + gpib_read_binary(gpibDevice, scopeScreenSize(scopeType)); + + BITMAP *bmp; + PALETTE palette; + int bpp; + install_allegro(SYSTEM_AUTODETECT, &errno, atexit); + bmp = load_bmp("/tmp/current_scope_screenshot.bmp", palette); + if (!bmp) { + printf("[WARN] Unable to load screenshot bitmap\n\r"); + return 1; + } + set_palette(palette); + bpp = bitmap_color_depth(bmp); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Found BPP of %d\n\r", bpp); + #endif + bytestosend = 0; + for (m=0;m<scopeScreenWidth(scopeType);m++) { + for (k=0;k<scopeScreenHeight(scopeType);k++) { + scope_raw_screenshot_data[bytestosend] = getr_depth(bpp, getpixel(bmp, m, k)); + bytestosend = bytestosend + 1; + scope_raw_screenshot_data[bytestosend] = getg_depth(bpp, getpixel(bmp, m, k)); + bytestosend = bytestosend + 1; + scope_raw_screenshot_data[bytestosend] = getb_depth(bpp, getpixel(bmp, m, k)); + bytestosend = bytestosend + 1; + } + } + destroy_bitmap(bmp); + return 0; + } + } + return 1; +} + + +int scope_get_screenshot(char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Getting scope screenshot [Stage 1]\n\r"); + if (strcmp("HP54600OS", scopeType) == 0) { + sprintf(falpha,"PRINT?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"HARDCOPY:FORMAT BMPCOLOR"); + if (gpib_write(gpibDevice, falpha) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Wrote: %s\n\r", falpha); + #endif + sprintf(falpha,"HARDCOPY:LAYOUT PORTRAIT"); + if (gpib_write(gpibDevice, falpha) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Wrote: %s\n\r", falpha); + #endif + sprintf(falpha,"HARDCOPY:PALETTE HARDCOPY"); + if (gpib_write(gpibDevice, falpha) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Wrote: %s\n\r", falpha); + #endif + sprintf(falpha,"HARDCOPY:PORT GPIB"); + if (gpib_write(gpibDevice, falpha) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Wrote: %s\n\r", falpha); + #endif + sprintf(falpha,"HARDCOPY START"); + if (gpib_write(gpibDevice, falpha) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Wrote: %s\n\r", falpha); + #endif + return 0; + } + } + } + } + } + } + } + return 1; +} + +int scope_set_timebase(float desired_timebase, char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Setting scope timebase to %E\n\r", desired_timebase); + if (strcmp("HP54600OS", scopeType) == 0) { + sprintf(falpha,"TIM:RANG %E", desired_timebase); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"HORIZONTAL:MAIN:SCALE %E", desired_timebase/10); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int scope_set_volts_div(int desired_channel, float desired_volts, char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Setting scope volts/div on channel %d to %f\n\r", desired_channel, desired_volts/8); + if (strcmp("HP54600OS", scopeType) == 0) { + sprintf(falpha,"CHAN%d:RANG %E", desired_channel, desired_volts); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"CH%d:SCALE %f", desired_channel, desired_volts/8); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int scope_set_acquisition(int status, char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Setting scope run status to %d\n\r", status); + if (strcmp("HP54600OS", scopeType) == 0) { + if (status == 0) { + sprintf(falpha,"STOP"); + } + else { + sprintf(falpha,"RUN"); + } + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"ACQUIRE:STATE %d", status); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int scope_set_channel_state(int desired_channel, int status, char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Setting channel %d state to %i\n\r", desired_channel, status); + if (strcmp("HP54600OS", scopeType) == 0) { + if (status == 0) { + sprintf(falpha,"BLAN CHAN%d", desired_channel); + } + else if (status == 1) { + sprintf(falpha,"VIEW CHAN%d", desired_channel); + } + else { + return 2; + } + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + if (status == 0) { + sprintf(falpha,"SELECT:CH%d OFF", desired_channel); + } + else if (status == 1) { + sprintf(falpha,"SELECT:CH%d ON", desired_channel); + } + else { + return 2; + } + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int scope_set_trigger_channel(int desired_channel, char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Setting scope trigger channel to %d\n\r", desired_channel); + if (strcmp("HP54600OS", scopeType) == 0) { + sprintf(falpha,"TRIG:SOUR CHAN%d", desired_channel); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"TRIGGER:MAIN:EDGE:SOURCE CH%d", desired_channel); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int scope_set_trigger_level(float desired_level, char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Setting scope trigger level to %f\n\r", desired_level); + if (strcmp("HP54600OS", scopeType) == 0) { + sprintf(falpha,"TRIG:LEV %E", desired_level); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"TRIGGER:MAIN:LEVEL %f", desired_level); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} + +int scope_set_channel_position(int desired_channel, float desired_level, char * scopeType, int gpibDevice) { + if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { + printf("[INFO] Setting scope channel %d level to %f\n\r", desired_channel, desired_level); + if (strcmp("HP54600OS", scopeType) == 0) { + sprintf(falpha,"CHAN%d:OFFS %E", desired_channel, desired_level); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"CH%d:POSITION %f", desired_channel, desired_level); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + return 2; + } + } + } + else { + return 1; + } +} diff --git a/attic/servers/gpib_server_lin/src/scope_functions.h b/attic/servers/gpib_server_lin/src/scope_functions.h new file mode 100755 index 0000000..2e7eaa3 --- /dev/null +++ b/attic/servers/gpib_server_lin/src/scope_functions.h @@ -0,0 +1,37 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +extern unsigned char scope_raw_screenshot_data[4194304]; + +unsigned long scopeScreenSize (char * scopeType); +unsigned long scopeScreenWidth (char * scopeType); +unsigned long scopeScreenHeight (char * scopeType); +int gpib_read_binary(int ud, int max_num_bytes); +int scope_get_screenshot(char * scopeType, int gpibDevice); +int scope_get_screenshot_stage2(char * scopeType, int gpibDevice); +int scope_set_timebase(float desired_timebase, char * scopeType, int gpibDevice); +int scope_set_volts_div(int desired_channel, float desired_volts, char * scopeType, int gpibDevice); +int scope_set_acquisition(int status, char * scopeType, int gpibDevice); +int scope_set_channel_state(int desired_channel, int status, char * scopeType, int gpibDevice); +int scope_set_trigger_channel(int desired_channel, char * scopeType, int gpibDevice); +int scope_set_trigger_level(float desired_level, char * scopeType, int gpibDevice); +int scope_set_channel_position(int desired_channel, float desired_level, char * scopeType, int gpibDevice);
\ No newline at end of file diff --git a/attic/servers/gpib_server_lin/src/signal_functions.c b/attic/servers/gpib_server_lin/src/signal_functions.c new file mode 100755 index 0000000..63562cb --- /dev/null +++ b/attic/servers/gpib_server_lin/src/signal_functions.c @@ -0,0 +1,284 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <getopt.h> +#include "gpib_functions.h" +#include "parameters.h" +#include "gpib/ib.h" + +char falpha[1024]; + +int signal_get_last_error(char * funcgenType, int gpibDevice, char * extendedError) { + char error_array[1024]; + int ei; + char * ep; + + // Zero the error array + for (ei=0;ei<1024;ei++) { + error_array[ei] = 0; + } + + if ((strcmp("AG33250A", funcgenType) == 0)) { + if (strcmp("AG33250A", funcgenType) == 0) { + sleep (1); + sprintf(falpha,"SYSTEM:ERROR?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + ibrd(gpibDevice, error_array, 1024-1); + ep = strstr(error_array, "+0,"); + if (ep != 0) { + return 0; + } + else { + sprintf(extendedError, "EXT%s%c\n\r", error_array, 176); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Extended error: %s\n\r", extendedError); + #endif + return 3; + } + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!%c\n\r", 176); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Extended error: %s\n\r", extendedError); + #endif + return 2; + } + } + } + sprintf(extendedError, "EXTAn invalid device was selected!%c\n\r", 176); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Extended error: %s\n\r", extendedError); + #endif + return 1; +} + +int signal_reset(char * funcgenType, int gpibDevice, char * extendedError) +{ + if ((strcmp("AG33250A", funcgenType) == 0)) { + printf("[INFO] Resetting function generator\n\r"); + if (strcmp("AG33250A", funcgenType) == 0) { + sprintf(falpha,"*RST"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"*CLS"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"DISP:TEXT 'Remote Control System v%s.%s%s'", SERVER_MAJOR, SERVER_MINOR, SERVER_REVISION); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"FUNCTION SQUARE"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"OUTPUT:LOAD INFINITY"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"VOLTAGE 3.3"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"FUNCTION SQUARE"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"FUNCTION:SQUARE:DCYCLE 50"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"SYSTEM:BEEPER:STATE ON"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"OUTPUT ON"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"SYSTEM:BEEPER"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return signal_get_last_error(funcgenType, gpibDevice, extendedError); + } + } + } + } + } + } + } + } + } + } + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!�"); + return 2; + } + } + } + sprintf(extendedError, "EXTAn invalid device was selected!�"); + return 1; +} + +int signal_set_frequency(float desired_frequency, char * funcgenType, int gpibDevice, char * extendedError) { + if ((strcmp("AG33250A", funcgenType) == 0)) { + printf("[INFO] Setting function generator frequency to %f\n\r", desired_frequency); + if (strcmp("AG33250A", funcgenType) == 0) { + // FIXME + sprintf(falpha,"FREQUENCY %E", desired_frequency); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return signal_get_last_error(funcgenType, gpibDevice, extendedError); + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!�"); + return 2; + } + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!�"); + return 1; + } +} + +int signal_set_duty_cycle(float desired_dcycle, char * funcgenType, int gpibDevice, char * extendedError) { + if ((strcmp("AG33250A", funcgenType) == 0)) { + printf("[INFO] Setting function generator period to %f\n\r", desired_dcycle); + if (strcmp("AG33250A", funcgenType) == 0) { + // FIXME + sprintf(falpha,"FUNCTION:SQUARE:DCYCLE %E", desired_dcycle); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return signal_get_last_error(funcgenType, gpibDevice, extendedError); + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!�"); + return 2; + } + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!�"); + return 1; + } +} + +int signal_set_waveform(char * waveform, char * funcgenType, int gpibDevice, char * extendedError) { + if ((strcmp("AG33250A", funcgenType) == 0)) { + printf("[INFO] Setting function generator waveform to %s\n\r", waveform); + if (strcmp("AG33250A", funcgenType) == 0) { + // FIXME + sprintf(falpha,"FUNCTION %s", waveform); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return signal_get_last_error(funcgenType, gpibDevice, extendedError); + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!�"); + return 2; + } + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!�"); + return 1; + } +} + +int signal_set_peak_peak_voltage(float desired_voltage, char * funcgenType, int gpibDevice, char * extendedError) { + if ((strcmp("AG33250A", funcgenType) == 0)) { + printf("[INFO] Setting function generator peak-peak voltage to %f\n\r", desired_voltage); + if (strcmp("AG33250A", funcgenType) == 0) { + // FIXME + sprintf(falpha,"VOLTAGE %E", desired_voltage); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return signal_get_last_error(funcgenType, gpibDevice, extendedError); + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!�"); + return 2; + } + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!�"); + return 1; + } +} + +int signal_set_offset_voltage(float desired_voltage, char * funcgenType, int gpibDevice, char * extendedError) { + if ((strcmp("AG33250A", funcgenType) == 0)) { + printf("[INFO] Setting function generator peak-peak voltage to %f\n\r", desired_voltage); + if (strcmp("AG33250A", funcgenType) == 0) { + // FIXME + sprintf(falpha,"VOLTAGE:OFFSET %E", desired_voltage); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return signal_get_last_error(funcgenType, gpibDevice, extendedError); + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!�"); + return 2; + } + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!�"); + return 1; + } +}
\ No newline at end of file diff --git a/attic/servers/gpib_server_lin/src/signal_functions.h b/attic/servers/gpib_server_lin/src/signal_functions.h new file mode 100755 index 0000000..e1e05bd --- /dev/null +++ b/attic/servers/gpib_server_lin/src/signal_functions.h @@ -0,0 +1,28 @@ +/* + * Remote Laboratory Instrumentation Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +int signal_reset(char * funcgenType, int gpibDevice, char * extendedError); +int signal_set_frequency(float desired_frequency, char * funcgenType, int gpibDevice, char * extendedError); +int signal_set_duty_cycle(float desired_dcycle, char * funcgenType, int gpibDevice, char * extendedError); +int signal_set_waveform(char * waveform, char * funcgenType, int gpibDevice, char * extendedError); +int signal_set_peak_peak_voltage(float desired_voltage, char * funcgenType, int gpibDevice, char * extendedError); +int signal_set_offset_voltage(float desired_voltage, char * funcgenType, int gpibDevice, char * extendedError); |