From 884a288cc0f15f5ab9ea36077b08ff002ff7eac2 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周二, 27 11月 2012 23:34:38 +0800 Subject: [PATCH] Include cleanup, better error handling --- netbeans/tests/test_scpi_utils.c | 1 scpi/scpi_ieee488.h | 29 test-parser.c | 16 scpi/scpi_parser.h | 68 +++ scpi/scpi_error.h | 8 scpi/scpi_types.h | 172 +++++++ netbeans/nbproject/Makefile-Debug.mk | 88 +++ scpi/scpi_parser.c | 37 - netbeans/tests/test_fifo.c | 109 ++++ scpi/scpi_units.h | 52 -- scpi/scpi.h | 92 --- netbeans/nbproject/configurations.xml | 32 + scpi/scpi_utils.c | 4 netbeans/nbproject/Makefile-Release.mk | 88 +++ scpi/scpi_minimal.h | 21 scpi/scpi_error.c | 160 +++++- scpi/scpi_debug.c | 52 ++ scpi/scpi_fifo.c | 46 ++ scpi/scpi_utils.h | 2 scpi/scpi_minimal.c | 53 +- scpi/scpi_debug.h | 59 ++ scpi/scpi_units.c | 2 scpi/scpi_fifo.h | 67 +++ scpi/scpi_ieee488.c | 56 +- 24 files changed, 979 insertions(+), 335 deletions(-) diff --git a/netbeans/nbproject/Makefile-Debug.mk b/netbeans/nbproject/Makefile-Debug.mk index c3a9616..edc5a57 100644 --- a/netbeans/nbproject/Makefile-Debug.mk +++ b/netbeans/nbproject/Makefile-Debug.mk @@ -34,10 +34,12 @@ # Object Files OBJECTFILES= \ + ${OBJECTDIR}/_ext/760632520/scpi_debug.o \ ${OBJECTDIR}/_ext/760632520/scpi_utils.o \ + ${OBJECTDIR}/_ext/760632520/scpi_fifo.o \ ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o \ - ${OBJECTDIR}/_ext/760632520/scpi.o \ ${OBJECTDIR}/_ext/760632520/scpi_minimal.o \ + ${OBJECTDIR}/_ext/760632520/scpi_parser.o \ ${OBJECTDIR}/_ext/1472/test-parser.o \ ${OBJECTDIR}/_ext/760632520/scpi_units.o \ ${OBJECTDIR}/_ext/760632520/scpi_error.o @@ -47,6 +49,7 @@ # Test Files TESTFILES= \ + ${TESTDIR}/TestFiles/f2 \ ${TESTDIR}/TestFiles/f3 # C Compiler Flags @@ -73,25 +76,35 @@ ${MKDIR} -p ${TESTDIR}/TestFiles ${LINK.c} -g3 -o ${TESTDIR}/TestFiles/f1 ${OBJECTFILES} ${LDLIBSOPTIONS} +${OBJECTDIR}/_ext/760632520/scpi_debug.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_debug.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + ${RM} $@.d + $(COMPILE.c) -Wall -I. -I. -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_debug.o ../scpi/scpi_debug.c + ${OBJECTDIR}/_ext/760632520/scpi_utils.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_utils.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 ${RM} $@.d $(COMPILE.c) -Wall -I. -I. -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_utils.o ../scpi/scpi_utils.c + +${OBJECTDIR}/_ext/760632520/scpi_fifo.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_fifo.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + ${RM} $@.d + $(COMPILE.c) -Wall -I. -I. -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_fifo.o ../scpi/scpi_fifo.c ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_ieee488.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 ${RM} $@.d $(COMPILE.c) -Wall -I. -I. -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o ../scpi/scpi_ieee488.c -${OBJECTDIR}/_ext/760632520/scpi.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi.c - ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 - ${RM} $@.d - $(COMPILE.c) -Wall -I. -I. -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi.o ../scpi/scpi.c - ${OBJECTDIR}/_ext/760632520/scpi_minimal.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_minimal.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 ${RM} $@.d $(COMPILE.c) -Wall -I. -I. -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_minimal.o ../scpi/scpi_minimal.c + +${OBJECTDIR}/_ext/760632520/scpi_parser.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_parser.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + ${RM} $@.d + $(COMPILE.c) -Wall -I. -I. -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_parser.o ../scpi/scpi_parser.c ${OBJECTDIR}/_ext/1472/test-parser.o: nbproject/Makefile-${CND_CONF}.mk ../test-parser.c ${MKDIR} -p ${OBJECTDIR}/_ext/1472 @@ -113,9 +126,19 @@ # Build Test Targets .build-tests-conf: .build-conf ${TESTFILES} +${TESTDIR}/TestFiles/f2: ${TESTDIR}/tests/test_fifo.o ${OBJECTFILES:%.o=%_nomain.o} + ${MKDIR} -p ${TESTDIR}/TestFiles + ${LINK.c} -o ${TESTDIR}/TestFiles/f2 $^ ${LDLIBSOPTIONS} -lcunit + ${TESTDIR}/TestFiles/f3: ${TESTDIR}/tests/test_scpi_utils.o ${OBJECTFILES:%.o=%_nomain.o} ${MKDIR} -p ${TESTDIR}/TestFiles ${LINK.c} -o ${TESTDIR}/TestFiles/f3 $^ ${LDLIBSOPTIONS} + + +${TESTDIR}/tests/test_fifo.o: tests/test_fifo.c + ${MKDIR} -p ${TESTDIR}/tests + ${RM} $@.d + $(COMPILE.c) -Wall -I. -I. -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/test_fifo.o tests/test_fifo.c ${TESTDIR}/tests/test_scpi_utils.o: tests/test_scpi_utils.c @@ -123,6 +146,19 @@ ${RM} $@.d $(COMPILE.c) -Wall -I. -I. -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/test_scpi_utils.o tests/test_scpi_utils.c + +${OBJECTDIR}/_ext/760632520/scpi_debug_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_debug.o ../scpi/scpi_debug.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_debug.o`; \ + if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ + then \ + ${RM} $@.d;\ + $(COMPILE.c) -Wall -I. -I. -I. -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_debug_nomain.o ../scpi/scpi_debug.c;\ + else \ + ${CP} ${OBJECTDIR}/_ext/760632520/scpi_debug.o ${OBJECTDIR}/_ext/760632520/scpi_debug_nomain.o;\ + fi ${OBJECTDIR}/_ext/760632520/scpi_utils_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_utils.o ../scpi/scpi_utils.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 @@ -135,6 +171,19 @@ $(COMPILE.c) -Wall -I. -I. -I. -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_utils_nomain.o ../scpi/scpi_utils.c;\ else \ ${CP} ${OBJECTDIR}/_ext/760632520/scpi_utils.o ${OBJECTDIR}/_ext/760632520/scpi_utils_nomain.o;\ + fi + +${OBJECTDIR}/_ext/760632520/scpi_fifo_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_fifo.o ../scpi/scpi_fifo.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_fifo.o`; \ + if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ + then \ + ${RM} $@.d;\ + $(COMPILE.c) -Wall -I. -I. -I. -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_fifo_nomain.o ../scpi/scpi_fifo.c;\ + else \ + ${CP} ${OBJECTDIR}/_ext/760632520/scpi_fifo.o ${OBJECTDIR}/_ext/760632520/scpi_fifo_nomain.o;\ fi ${OBJECTDIR}/_ext/760632520/scpi_ieee488_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o ../scpi/scpi_ieee488.c @@ -150,19 +199,6 @@ ${CP} ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o ${OBJECTDIR}/_ext/760632520/scpi_ieee488_nomain.o;\ fi -${OBJECTDIR}/_ext/760632520/scpi_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi.o ../scpi/scpi.c - ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 - @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi.o`; \ - if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ - (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ - (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ - then \ - ${RM} $@.d;\ - $(COMPILE.c) -Wall -I. -I. -I. -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_nomain.o ../scpi/scpi.c;\ - else \ - ${CP} ${OBJECTDIR}/_ext/760632520/scpi.o ${OBJECTDIR}/_ext/760632520/scpi_nomain.o;\ - fi - ${OBJECTDIR}/_ext/760632520/scpi_minimal_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_minimal.o ../scpi/scpi_minimal.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_minimal.o`; \ @@ -174,6 +210,19 @@ $(COMPILE.c) -Wall -I. -I. -I. -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_minimal_nomain.o ../scpi/scpi_minimal.c;\ else \ ${CP} ${OBJECTDIR}/_ext/760632520/scpi_minimal.o ${OBJECTDIR}/_ext/760632520/scpi_minimal_nomain.o;\ + fi + +${OBJECTDIR}/_ext/760632520/scpi_parser_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_parser.o ../scpi/scpi_parser.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_parser.o`; \ + if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ + then \ + ${RM} $@.d;\ + $(COMPILE.c) -Wall -I. -I. -I. -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_parser_nomain.o ../scpi/scpi_parser.c;\ + else \ + ${CP} ${OBJECTDIR}/_ext/760632520/scpi_parser.o ${OBJECTDIR}/_ext/760632520/scpi_parser_nomain.o;\ fi ${OBJECTDIR}/_ext/1472/test-parser_nomain.o: ${OBJECTDIR}/_ext/1472/test-parser.o ../test-parser.c @@ -219,6 +268,7 @@ .test-conf: @if [ "${TEST}" = "" ]; \ then \ + ${TESTDIR}/TestFiles/f2 || true; \ ${TESTDIR}/TestFiles/f3 || true; \ else \ ./${TEST} || true; \ diff --git a/netbeans/nbproject/Makefile-Release.mk b/netbeans/nbproject/Makefile-Release.mk index 107285b..9b93efd 100644 --- a/netbeans/nbproject/Makefile-Release.mk +++ b/netbeans/nbproject/Makefile-Release.mk @@ -34,10 +34,12 @@ # Object Files OBJECTFILES= \ + ${OBJECTDIR}/_ext/760632520/scpi_debug.o \ ${OBJECTDIR}/_ext/760632520/scpi_utils.o \ + ${OBJECTDIR}/_ext/760632520/scpi_fifo.o \ ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o \ - ${OBJECTDIR}/_ext/760632520/scpi.o \ ${OBJECTDIR}/_ext/760632520/scpi_minimal.o \ + ${OBJECTDIR}/_ext/760632520/scpi_parser.o \ ${OBJECTDIR}/_ext/1472/test-parser.o \ ${OBJECTDIR}/_ext/760632520/scpi_units.o \ ${OBJECTDIR}/_ext/760632520/scpi_error.o @@ -47,6 +49,7 @@ # Test Files TESTFILES= \ + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans # C Compiler Flags @@ -73,25 +76,35 @@ ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/scpi_parser ${OBJECTFILES} ${LDLIBSOPTIONS} +${OBJECTDIR}/_ext/760632520/scpi_debug.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_debug.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + ${RM} $@.d + $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_debug.o ../scpi/scpi_debug.c + ${OBJECTDIR}/_ext/760632520/scpi_utils.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_utils.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 ${RM} $@.d $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_utils.o ../scpi/scpi_utils.c + +${OBJECTDIR}/_ext/760632520/scpi_fifo.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_fifo.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + ${RM} $@.d + $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_fifo.o ../scpi/scpi_fifo.c ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_ieee488.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 ${RM} $@.d $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o ../scpi/scpi_ieee488.c -${OBJECTDIR}/_ext/760632520/scpi.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi.c - ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 - ${RM} $@.d - $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi.o ../scpi/scpi.c - ${OBJECTDIR}/_ext/760632520/scpi_minimal.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_minimal.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 ${RM} $@.d $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_minimal.o ../scpi/scpi_minimal.c + +${OBJECTDIR}/_ext/760632520/scpi_parser.o: nbproject/Makefile-${CND_CONF}.mk ../scpi/scpi_parser.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + ${RM} $@.d + $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_parser.o ../scpi/scpi_parser.c ${OBJECTDIR}/_ext/1472/test-parser.o: nbproject/Makefile-${CND_CONF}.mk ../test-parser.c ${MKDIR} -p ${OBJECTDIR}/_ext/1472 @@ -113,9 +126,19 @@ # Build Test Targets .build-tests-conf: .build-conf ${TESTFILES} +${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans: ${TESTDIR}/tests/test_fifo.o ${OBJECTFILES:%.o=%_nomain.o} + ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} + ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans $^ ${LDLIBSOPTIONS} + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans: ${TESTDIR}/tests/test_scpi_utils.o ${OBJECTFILES:%.o=%_nomain.o} ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans $^ ${LDLIBSOPTIONS} + + +${TESTDIR}/tests/test_fifo.o: tests/test_fifo.c + ${MKDIR} -p ${TESTDIR}/tests + ${RM} $@.d + $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${TESTDIR}/tests/test_fifo.o tests/test_fifo.c ${TESTDIR}/tests/test_scpi_utils.o: tests/test_scpi_utils.c @@ -123,6 +146,19 @@ ${RM} $@.d $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${TESTDIR}/tests/test_scpi_utils.o tests/test_scpi_utils.c + +${OBJECTDIR}/_ext/760632520/scpi_debug_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_debug.o ../scpi/scpi_debug.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_debug.o`; \ + if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ + then \ + ${RM} $@.d;\ + $(COMPILE.c) -O2 -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_debug_nomain.o ../scpi/scpi_debug.c;\ + else \ + ${CP} ${OBJECTDIR}/_ext/760632520/scpi_debug.o ${OBJECTDIR}/_ext/760632520/scpi_debug_nomain.o;\ + fi ${OBJECTDIR}/_ext/760632520/scpi_utils_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_utils.o ../scpi/scpi_utils.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 @@ -135,6 +171,19 @@ $(COMPILE.c) -O2 -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_utils_nomain.o ../scpi/scpi_utils.c;\ else \ ${CP} ${OBJECTDIR}/_ext/760632520/scpi_utils.o ${OBJECTDIR}/_ext/760632520/scpi_utils_nomain.o;\ + fi + +${OBJECTDIR}/_ext/760632520/scpi_fifo_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_fifo.o ../scpi/scpi_fifo.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_fifo.o`; \ + if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ + then \ + ${RM} $@.d;\ + $(COMPILE.c) -O2 -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_fifo_nomain.o ../scpi/scpi_fifo.c;\ + else \ + ${CP} ${OBJECTDIR}/_ext/760632520/scpi_fifo.o ${OBJECTDIR}/_ext/760632520/scpi_fifo_nomain.o;\ fi ${OBJECTDIR}/_ext/760632520/scpi_ieee488_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o ../scpi/scpi_ieee488.c @@ -150,19 +199,6 @@ ${CP} ${OBJECTDIR}/_ext/760632520/scpi_ieee488.o ${OBJECTDIR}/_ext/760632520/scpi_ieee488_nomain.o;\ fi -${OBJECTDIR}/_ext/760632520/scpi_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi.o ../scpi/scpi.c - ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 - @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi.o`; \ - if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ - (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ - (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ - then \ - ${RM} $@.d;\ - $(COMPILE.c) -O2 -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_nomain.o ../scpi/scpi.c;\ - else \ - ${CP} ${OBJECTDIR}/_ext/760632520/scpi.o ${OBJECTDIR}/_ext/760632520/scpi_nomain.o;\ - fi - ${OBJECTDIR}/_ext/760632520/scpi_minimal_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_minimal.o ../scpi/scpi_minimal.c ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_minimal.o`; \ @@ -174,6 +210,19 @@ $(COMPILE.c) -O2 -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_minimal_nomain.o ../scpi/scpi_minimal.c;\ else \ ${CP} ${OBJECTDIR}/_ext/760632520/scpi_minimal.o ${OBJECTDIR}/_ext/760632520/scpi_minimal_nomain.o;\ + fi + +${OBJECTDIR}/_ext/760632520/scpi_parser_nomain.o: ${OBJECTDIR}/_ext/760632520/scpi_parser.o ../scpi/scpi_parser.c + ${MKDIR} -p ${OBJECTDIR}/_ext/760632520 + @NMOUTPUT=`${NM} ${OBJECTDIR}/_ext/760632520/scpi_parser.o`; \ + if (echo "$$NMOUTPUT" | ${GREP} '|main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T main$$') || \ + (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ + then \ + ${RM} $@.d;\ + $(COMPILE.c) -O2 -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/_ext/760632520/scpi_parser_nomain.o ../scpi/scpi_parser.c;\ + else \ + ${CP} ${OBJECTDIR}/_ext/760632520/scpi_parser.o ${OBJECTDIR}/_ext/760632520/scpi_parser_nomain.o;\ fi ${OBJECTDIR}/_ext/1472/test-parser_nomain.o: ${OBJECTDIR}/_ext/1472/test-parser.o ../test-parser.c @@ -220,6 +269,7 @@ @if [ "${TEST}" = "" ]; \ then \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans || true; \ + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans || true; \ else \ ./${TEST} || true; \ fi diff --git a/netbeans/nbproject/configurations.xml b/netbeans/nbproject/configurations.xml index 229ffad..43b7cc0 100644 --- a/netbeans/nbproject/configurations.xml +++ b/netbeans/nbproject/configurations.xml @@ -7,9 +7,13 @@ <logicalFolder name="f1" displayName="scpi" projectFiles="true"> <itemPath>../scpi/scpi.h</itemPath> <itemPath>../scpi/scpi_constants.h</itemPath> + <itemPath>../scpi/scpi_debug.h</itemPath> <itemPath>../scpi/scpi_error.h</itemPath> + <itemPath>../scpi/scpi_fifo.h</itemPath> <itemPath>../scpi/scpi_ieee488.h</itemPath> <itemPath>../scpi/scpi_minimal.h</itemPath> + <itemPath>../scpi/scpi_parser.h</itemPath> + <itemPath>../scpi/scpi_types.h</itemPath> <itemPath>../scpi/scpi_units.h</itemPath> <itemPath>../scpi/scpi_utils.h</itemPath> </logicalFolder> @@ -22,10 +26,12 @@ displayName="Source Files" projectFiles="true"> <logicalFolder name="f1" displayName="scpi" projectFiles="true"> - <itemPath>../scpi/scpi.c</itemPath> + <itemPath>../scpi/scpi_debug.c</itemPath> <itemPath>../scpi/scpi_error.c</itemPath> + <itemPath>../scpi/scpi_fifo.c</itemPath> <itemPath>../scpi/scpi_ieee488.c</itemPath> <itemPath>../scpi/scpi_minimal.c</itemPath> + <itemPath>../scpi/scpi_parser.c</itemPath> <itemPath>../scpi/scpi_units.c</itemPath> <itemPath>../scpi/scpi_utils.c</itemPath> </logicalFolder> @@ -35,6 +41,12 @@ displayName="Test Files" projectFiles="false" kind="TEST_LOGICAL_FOLDER"> + <logicalFolder name="f1" + displayName="FIFO test" + projectFiles="true" + kind="TEST"> + <itemPath>tests/test_fifo.c</itemPath> + </logicalFolder> <logicalFolder name="f3" displayName="Test SCPI utils" projectFiles="true" @@ -97,6 +109,24 @@ group="bin"/> </packFileList> </packaging> + <folder path="TestFiles/f1"> + <cTool> + <incDir> + <pElem>.</pElem> + </incDir> + </cTool> + <ccTool> + <incDir> + <pElem>.</pElem> + </incDir> + </ccTool> + <linkerTool> + <output>${TESTDIR}/TestFiles/f2</output> + <linkerLibItems> + <linkerLibStdlibItem>CUnit</linkerLibStdlibItem> + </linkerLibItems> + </linkerTool> + </folder> <folder path="TestFiles/f3"> <cTool> <incDir> diff --git a/netbeans/tests/test_fifo.c b/netbeans/tests/test_fifo.c new file mode 100644 index 0000000..6be41e7 --- /dev/null +++ b/netbeans/tests/test_fifo.c @@ -0,0 +1,109 @@ +/* + * File: test_fifo.c + * Author: jaybee + * + * Created on 27.11.2012, 16:01:38 + */ + +#include <stdio.h> +#include <stdlib.h> +#include "CUnit/Basic.h" + +#include "../scpi/scpi_fifo.h" + +/* + * CUnit Test Suite + */ + +int init_suite(void) { + return 0; +} + +int clean_suite(void) { + return 0; +} + +void testFifo() { + fifo_t fifo; + fifo_init(&fifo); + int16_t value; + + fifo.size = 4; + +#define TEST_FIFO_COUNT(n) \ + do { \ + fifo_count(&fifo, &value); \ + CU_ASSERT_EQUAL(value, n); \ + } while(0) \ + + + TEST_FIFO_COUNT(0); + CU_ASSERT_TRUE(fifo_push(&fifo, 1)); + TEST_FIFO_COUNT(1); + CU_ASSERT_TRUE(fifo_push(&fifo, 2)); + TEST_FIFO_COUNT(2); + CU_ASSERT_TRUE(fifo_push(&fifo, 3)); + TEST_FIFO_COUNT(3); + CU_ASSERT_TRUE(fifo_push(&fifo, 4)); + TEST_FIFO_COUNT(4); + CU_ASSERT_FALSE(fifo_push(&fifo, 1)); + TEST_FIFO_COUNT(4); + + CU_ASSERT_EQUAL(fifo.data[0], 1); + CU_ASSERT_EQUAL(fifo.data[1], 2); + CU_ASSERT_EQUAL(fifo.data[2], 3); + CU_ASSERT_EQUAL(fifo.data[3], 4); + + CU_ASSERT_TRUE(fifo_pop(&fifo, &value)); + CU_ASSERT_EQUAL(value, 1); + TEST_FIFO_COUNT(3); + + CU_ASSERT_TRUE(fifo_push(&fifo, 5)); + TEST_FIFO_COUNT(4); + + CU_ASSERT_TRUE(fifo_pop(&fifo, &value)); + CU_ASSERT_EQUAL(value, 2); + TEST_FIFO_COUNT(3); + + CU_ASSERT_TRUE(fifo_pop(&fifo, &value)); + CU_ASSERT_EQUAL(value, 3); + TEST_FIFO_COUNT(2); + + CU_ASSERT_TRUE(fifo_pop(&fifo, &value)); + CU_ASSERT_EQUAL(value, 4); + TEST_FIFO_COUNT(1); + + CU_ASSERT_TRUE(fifo_pop(&fifo, &value)); + CU_ASSERT_EQUAL(value, 5); + TEST_FIFO_COUNT(0); + + CU_ASSERT_FALSE(fifo_pop(&fifo, &value)); + TEST_FIFO_COUNT(0); +} + +int main() { + CU_pSuite pSuite = NULL; + + /* Initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* Add a suite to the registry */ + pSuite = CU_add_suite("FIFO", init_suite, clean_suite); + if (NULL == pSuite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + /* Add the tests to the suite */ + if ((NULL == CU_add_test(pSuite, "test fifo", testFifo))) { + CU_cleanup_registry(); + return CU_get_error(); + } + + /* Run all tests using the CUnit Basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + return CU_get_error(); +} diff --git a/netbeans/tests/test_scpi_utils.c b/netbeans/tests/test_scpi_utils.c index 63b9eaa..44686ce 100644 --- a/netbeans/tests/test_scpi_utils.c +++ b/netbeans/tests/test_scpi_utils.c @@ -10,7 +10,6 @@ #include "CUnit/Basic.h" #include "../scpi/scpi.h" -#include "../scpi/scpi_utils.h" /* * CUnit Test Suite diff --git a/scpi/scpi.h b/scpi/scpi.h index 8181502..cc9bd79 100644 --- a/scpi/scpi.h +++ b/scpi/scpi.h @@ -29,7 +29,7 @@ * @file scpi.h * @date Thu Nov 15 10:58:45 UTC 2012 * - * @brief SCPI parser implementation + * @brief SCPI library include file * * */ @@ -37,91 +37,15 @@ #ifndef SCPI_H #define SCPI_H -#include <stddef.h> -#include <stdint.h> -#include <stdbool.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define FALSE false -#define TRUE true - typedef bool bool_t; - //typedef enum { FALSE = 0, TRUE } bool_t; - - typedef struct _scpi_t scpi_t; - typedef struct _scpi_param_list_t scpi_param_list_t; - typedef struct _scpi_command_t scpi_command_t; - typedef struct _scpi_buffer_t scpi_buffer_t; - typedef struct _scpi_interface_t scpi_interface_t; - typedef int (*scpi_command_callback_t)(scpi_t *); - typedef size_t(*scpi_write_t)(scpi_t * context, const char * data, size_t len); - typedef int (*scpi_error_callback_t)(scpi_t * context, int_fast16_t error); - - struct _scpi_param_list_t { - const scpi_command_t * cmd; - const char * parameters; - size_t length; - }; - - struct _scpi_command_t { - const char * pattern; - scpi_command_callback_t callback; - }; - - struct _scpi_buffer_t { - size_t length; - size_t position; - char * data; - }; - - struct _scpi_interface_t { - scpi_error_callback_t error; - scpi_write_t write; - scpi_command_callback_t reset; - scpi_command_callback_t test; - }; - - struct _scpi_t { - const scpi_command_t * cmdlist; - scpi_buffer_t buffer; - scpi_param_list_t paramlist; - scpi_interface_t * interface; - int_fast16_t output_count; - int_fast16_t input_count; - bool_t error; - }; +#include "scpi_parser.h" +#include "scpi_ieee488.h" +#include "scpi_error.h" +#include "scpi_constants.h" +#include "scpi_minimal.h" +#include "scpi_utils.h" +#include "scpi_units.h" - -#define SCPI_CMD_LIST_END {.pattern = NULL, .callback = NULL, } - - - void SCPI_Init(scpi_t * context, scpi_command_t * command_list, scpi_buffer_t * buffer, scpi_interface_t * interface); - - int SCPI_Input(scpi_t * context, const char * data, size_t len); - int SCPI_Parse(scpi_t * context, const char * data, size_t len); - - - size_t SCPI_ResultString(scpi_t * context, const char * data); - size_t SCPI_ResultInt(scpi_t * context, int32_t val); - size_t SCPI_ResultDouble(scpi_t * context, double val); - size_t SCPI_ResultText(scpi_t * context, const char * data); - - bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory); - bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory); - bool_t SCPI_ParamString(scpi_t * context, char ** value, size_t * len, bool_t mandatory); - - bool_t SCPI_DebugCommand(scpi_t * context); - - //#define SCPI_DEBUG_COMMAND(a) scpi_debug_command(a) -#define SCPI_DEBUG_COMMAND(a) - - -#ifdef __cplusplus -} -#endif #endif /* SCPI_H */ diff --git a/scpi/scpi_debug.c b/scpi/scpi_debug.c new file mode 100644 index 0000000..bf8baf5 --- /dev/null +++ b/scpi/scpi_debug.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2012-2013 Jan Breuer, + * + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file scpi_debug.c + * @date Thu Nov 15 10:58:45 UTC 2012 + * + * @brief Debugging SCPI + * + * + */ + +#include <stdio.h> +#include "scpi_debug.h" + +/** + * Debug function: show current command and its parameters + * @param context + * @return + */ +bool_t SCPI_DebugCommand(scpi_t * context) { + (void) context; + printf("**DEBUG: %s (\"", context->paramlist.cmd->pattern); + fwrite(context->paramlist.parameters, 1, context->paramlist.length, stdout); + printf("\" - %ld)\r\n", context->paramlist.length); + + return TRUE; +} \ No newline at end of file diff --git a/scpi/scpi_debug.h b/scpi/scpi_debug.h new file mode 100644 index 0000000..f202f2a --- /dev/null +++ b/scpi/scpi_debug.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2012-2013 Jan Breuer, + * + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file scpi_debug.h + * @date Thu Nov 15 10:58:45 UTC 2012 + * + * @brief SCPI debug function + * + * + */ + +#ifndef SCPI_DEBUG_H +#define SCPI_DEBUG_H + +#include "scpi_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + //#define SCPI_DEBUG_COMMAND(a) scpi_debug_command(a) +#define SCPI_DEBUG_COMMAND(a) + + + bool_t SCPI_DebugCommand(scpi_t * context); + + +#ifdef __cplusplus +} +#endif + +#endif /* SCPI_DEBUG_H */ + diff --git a/scpi/scpi_error.c b/scpi/scpi_error.c index 8b2aa9e..2cc1620 100644 --- a/scpi/scpi_error.c +++ b/scpi/scpi_error.c @@ -34,52 +34,37 @@ * */ -#include "scpi.h" -#include "scpi_ieee488.h" -#include "scpi_error.h" #include <stdint.h> -static int16_t scpi_err = 0; +#include "scpi_parser.h" +#include "scpi_ieee488.h" +#include "scpi_error.h" +#include "scpi_fifo.h" + +// basic FIFO +static fifo_t local_error_queue; + + + +void SCPI_ErrorInit(scpi_t * context) { + //// FreeRTOS + // context->error_queue = (scpi_error_queue_t)xQueueCreate(100, sizeof(int16_t)); + + // basic FIFO + context->error_queue = (scpi_error_queue_t)&local_error_queue; + fifo_init((fifo_t *)context->error_queue); +} /** * Clear error queue * @param context - scpi context */ void SCPI_ErrorClear(scpi_t * context) { - (void) context; - scpi_err = 0; -} - -/** - * Push error to queue - * @param context - scpi context - * @param err - error number - */ -void SCPI_ErrorPush(scpi_t * context, int16_t err) { - scpi_err = err; - - // Command error (e.g. syntax error) - if ((err < -101) && (err > -158)) { - SCPI_RegSetBits(SCPI_REG_ESR, ESR_CER); - } - - // Execution Error (e.g. range error) - if ((err < -211) && (err > -230)) { - SCPI_RegSetBits(SCPI_REG_ESR, ESR_EER); - } - - // Device Dependent Error - if ((err < -501) && (err > -748)) { - SCPI_RegSetBits(SCPI_REG_ESR, ESR_DER); - } - - if (context) { - if (context->interface && context->interface->error) { - context->interface->error(context, err); - } - - context->error = TRUE; - } + //// FreeRTOS + //xQueueReset((xQueueHandle)context->error_queue); + + // basic FIFO + fifo_clear((fifo_t *)context->error_queue); } /** @@ -88,10 +73,99 @@ * @return error number */ int16_t SCPI_ErrorPop(scpi_t * context) { - (void) context; - int16_t result = scpi_err; - scpi_err = 0; + int16_t result = 0; + + //// FreeRTOS + //if (pdFALSE == xQueueReceive((xQueueHandle)context->error_queue, &result, 0)) { + // result = 0; + //} + + // basic FIFO + fifo_pop((fifo_t *)context->error_queue, &result); + return result; +} + +/** + * Return number of errors/events in the queue + * @param context + * @return + */ +int32_t SCPI_ErrorCount(scpi_t * context) { + int16_t result = 0; + + //// FreeRTOS + //result = uxQueueMessagesWaiting((xQueueHandle)context->error_queue); + + //basic FIFO + fifo_count((fifo_t *)context->error_queue, &result); + + + return result; +} + +static void SCPI_ErrorPushInternal(scpi_t * context, int16_t err) { + //// FreeRTOS + //xQueueSend((xQueueHandle)context->error_queue, &err, 0); + + // basic FIFO + fifo_push((fifo_t *)context->error_queue, err); +} +/** + * Push error to queue + * @param context - scpi context + * @param err - error number + */ +void SCPI_ErrorPush(scpi_t * context, int16_t err) { + SCPI_ErrorPushInternal(context, err); + + // Command error (e.g. syntax error) ch 21.8.9 + if ((err < -100) && (err > -199)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_CER); + } + + // Execution Error (e.g. range error) ch 21.8.10 + if ((err < -200) && (err > -299)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_EER); + } + + // Device specific error -300, -399 ch 21.8.11 + if ((err < -300) && (err > -399)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_DER); + } + + // Query error -400, -499 ch 21.8.12 + if ((err < -400) && (err > -499)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_QER); + } + + // Power on event -500, -599 ch 21.8.13 + if ((err < -500) && (err > -599)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_PON); + } + + // User Request Event -600, -699 ch 21.8.14 + if ((err < -600) && (err > -699)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_URQ); + } + + // Request Control Event -700, -799 ch 21.8.15 + if ((err < -700) && (err > -799)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_REQ); + } + + // Operation Complete Event -800, -899 ch 21.8.16 + if ((err < -800) && (err > -899)) { + SCPI_RegSetBits(SCPI_REG_ESR, ESR_OPC); + } + + if (context) { + if (context->interface && context->interface->error) { + context->interface->error(context, err); + } + + context->cmd_error = TRUE; + } } /** @@ -111,4 +185,6 @@ case SCPI_ERROR_SUFFIX_NOT_ALLOWED: return "Suffix not allowed"; default: return "Unknown error"; } -} \ No newline at end of file +} + + diff --git a/scpi/scpi_error.h b/scpi/scpi_error.h index 9643054..5d8315e 100644 --- a/scpi/scpi_error.h +++ b/scpi/scpi_error.h @@ -37,13 +37,17 @@ #ifndef SCPI_ERROR_H #define SCPI_ERROR_H +#include "scpi_types.h" + #ifdef __cplusplus extern "C" { #endif - + + void SCPI_ErrorInit(scpi_t * context); void SCPI_ErrorClear(scpi_t * context); int16_t SCPI_ErrorPop(scpi_t * context); void SCPI_ErrorPush(scpi_t * context, int16_t err); + int32_t SCPI_ErrorCount(scpi_t * context); const char * SCPI_ErrorTranslate(int16_t err); #define SCPI_ERROR_SYNTAX -102 @@ -54,6 +58,8 @@ #define SCPI_ERROR_INVALID_SUFFIX -131 #define SCPI_ERROR_SUFFIX_NOT_ALLOWED -138 +#define SCPI_ERROR_EXECUTION_ERROR -200 + #ifdef __cplusplus } #endif diff --git a/scpi/scpi_fifo.c b/scpi/scpi_fifo.c new file mode 100644 index 0000000..8ad432b --- /dev/null +++ b/scpi/scpi_fifo.c @@ -0,0 +1,46 @@ + +#include "scpi_fifo.h" + +void fifo_init(fifo_t * fifo) { + fifo->wr = 0; + fifo->rd = 0; + fifo->size = FIFO_SIZE; +} + +void fifo_clear(fifo_t * fifo) { + fifo->wr = 0; + fifo->rd = 0; +} + +bool_t fifo_push(fifo_t * fifo, int16_t value) { + /* FIFO full? */ + if (fifo->wr == ((fifo->rd + fifo->size) % (fifo->size + 1))) { + return FALSE; + } + + fifo->data[fifo->wr] = value; + fifo->wr = (fifo->wr + 1) % (fifo->size + 1); + + return TRUE; +} + +bool_t fifo_pop(fifo_t * fifo, int16_t * value) { + /* FIFO empty? */ + if (fifo->wr == fifo->rd) { + return FALSE; + } + + *value = fifo->data[fifo->rd]; + + fifo->rd = (fifo->rd + 1) % (fifo->size + 1); + + return TRUE; +} + +bool_t fifo_count(fifo_t * fifo, int16_t * value) { + *value = fifo->wr - fifo->rd; + if (*value < 0) { + *value += (fifo->size + 1); + } + return TRUE; +} \ No newline at end of file diff --git a/scpi/scpi_fifo.h b/scpi/scpi_fifo.h new file mode 100644 index 0000000..a798641 --- /dev/null +++ b/scpi/scpi_fifo.h @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2012-2013 Jan Breuer, + * + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file scpi_fifo.h + * @date Thu Nov 15 10:58:45 UTC 2012 + * + * @brief basic FIFO implementation + * + * + */ + +#ifndef SCPI_FIFO_H +#define SCPI_FIFO_H + +#include "scpi_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#define FIFO_SIZE 100 + + struct _fifo_t { + int16_t wr; + int16_t rd; + int16_t size; + int16_t data[FIFO_SIZE]; + }; + typedef struct _fifo_t fifo_t; + + void fifo_init(fifo_t * fifo); + void fifo_clear(fifo_t * fifo); + bool_t fifo_push(fifo_t * fifo, int16_t value); + bool_t fifo_pop(fifo_t * fifo, int16_t * value); + bool_t fifo_count(fifo_t * fifo, int16_t * value); + +#ifdef __cplusplus +} +#endif + +#endif /* SCPI_FIFO_H */ \ No newline at end of file diff --git a/scpi/scpi_ieee488.c b/scpi/scpi_ieee488.c index 809ae33..a0983e3 100644 --- a/scpi/scpi_ieee488.c +++ b/scpi/scpi_ieee488.c @@ -34,12 +34,10 @@ * */ -#include "scpi.h" +#include "scpi_parser.h" #include "scpi_ieee488.h" #include "scpi_error.h" #include "scpi_constants.h" -#include <string.h> -#include <stdint.h> /* register array */ static scpi_reg_val_t regs[SCPI_REG_COUNT]; @@ -162,13 +160,13 @@ * @param context * @return */ -int SCPI_CoreCls(scpi_t * context) { +scpi_result_t SCPI_CoreCls(scpi_t * context) { (void) context; SCPI_EventClear(); SCPI_ErrorClear(context); SCPI_RegSet(SCPI_REG_OPER, 0); SCPI_RegSet(SCPI_REG_QUES, 0); - return 0; + return SCPI_RES_OK; } /** @@ -176,12 +174,12 @@ * @param context * @return */ -int SCPI_CoreEse(scpi_t * context) { +scpi_result_t SCPI_CoreEse(scpi_t * context) { int32_t new_ESE; if (SCPI_ParamInt(context, &new_ESE, TRUE)) { SCPI_RegSet(SCPI_REG_ESE, new_ESE); } - return 0; + return SCPI_RES_OK; } /** @@ -189,10 +187,10 @@ * @param context * @return */ -int SCPI_CoreEseQ(scpi_t * context) { +scpi_result_t SCPI_CoreEseQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_ESE)); - return 0; + return SCPI_RES_OK; } /** @@ -200,11 +198,11 @@ * @param context * @return */ -int SCPI_CoreEsrQ(scpi_t * context) { +scpi_result_t SCPI_CoreEsrQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_ESR)); SCPI_RegSet(SCPI_REG_ESR, 0); - return 0; + return SCPI_RES_OK; } /** @@ -212,12 +210,12 @@ * @param context * @return */ -int SCPI_CoreIdnQ(scpi_t * context) { +scpi_result_t SCPI_CoreIdnQ(scpi_t * context) { (void) context; SCPI_ResultString(context, SCPI_MANUFACTURE); SCPI_ResultString(context, SCPI_DEV_NAME); SCPI_ResultString(context, SCPI_DEV_VERSION); - return 0; + return SCPI_RES_OK; } /** @@ -225,10 +223,10 @@ * @param context * @return */ -int SCPI_CoreOpc(scpi_t * context) { +scpi_result_t SCPI_CoreOpc(scpi_t * context) { (void) context; SCPI_RegSetBits(SCPI_REG_ESR, ESR_OPC); - return 0; + return SCPI_RES_OK; } /** @@ -236,11 +234,11 @@ * @param context * @return */ -int SCPI_CoreOpcQ(scpi_t * context) { +scpi_result_t SCPI_CoreOpcQ(scpi_t * context) { (void) context; // Operation is always completed SCPI_ResultInt(context, 1); - return 0; + return SCPI_RES_OK; } /** @@ -248,11 +246,11 @@ * @param context * @return */ -int SCPI_CoreRst(scpi_t * context) { +scpi_result_t SCPI_CoreRst(scpi_t * context) { if (context && context->interface && context->interface->reset) { return context->interface->reset(context); } - return 0; + return SCPI_RES_OK; } /** @@ -260,12 +258,12 @@ * @param context * @return */ -int SCPI_CoreSre(scpi_t * context) { +scpi_result_t SCPI_CoreSre(scpi_t * context) { int32_t new_SRE; if (SCPI_ParamInt(context, &new_SRE, TRUE)) { SCPI_RegSet(SCPI_REG_SRE, new_SRE); } - return 0; + return SCPI_RES_OK; } /** @@ -273,10 +271,10 @@ * @param context * @return */ -int SCPI_CoreSreQ(scpi_t * context) { +scpi_result_t SCPI_CoreSreQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_SRE)); - return 0; + return SCPI_RES_OK; } /** @@ -284,10 +282,10 @@ * @param context * @return */ -int SCPI_CoreStbQ(scpi_t * context) { +scpi_result_t SCPI_CoreStbQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_STB)); - return 0; + return SCPI_RES_OK; } /** @@ -295,14 +293,14 @@ * @param context * @return */ -int SCPI_CoreTstQ(scpi_t * context) { +scpi_result_t SCPI_CoreTstQ(scpi_t * context) { (void) context; int result = 0; if (context && context->interface && context->interface->test) { result = context->interface->test(context); } SCPI_ResultInt(context, result); - return 0; + return SCPI_RES_OK; } /** @@ -310,9 +308,9 @@ * @param context * @return */ -int SCPI_CoreWai(scpi_t * context) { +scpi_result_t SCPI_CoreWai(scpi_t * context) { (void) context; // NOP - return 0; + return SCPI_RES_OK; } diff --git a/scpi/scpi_ieee488.h b/scpi/scpi_ieee488.h index 845d88e..c161e4b 100644 --- a/scpi/scpi_ieee488.h +++ b/scpi/scpi_ieee488.h @@ -37,8 +37,7 @@ #ifndef SCPI_IEEE488_H #define SCPI_IEEE488_H -#include "scpi.h" -#include <stdint.h> +#include "scpi_types.h" typedef uint16_t scpi_reg_val_t; @@ -56,19 +55,19 @@ SCPI_REG_COUNT, } scpi_reg_name_t; -int SCPI_CoreCls(scpi_t * context); -int SCPI_CoreEse(scpi_t * context); -int SCPI_CoreEseQ(scpi_t * context); -int SCPI_CoreEsrQ(scpi_t * context); -int SCPI_CoreIdnQ(scpi_t * context); -int SCPI_CoreOpc(scpi_t * context); -int SCPI_CoreOpcQ(scpi_t * context); -int SCPI_CoreRst(scpi_t * context); -int SCPI_CoreSre(scpi_t * context); -int SCPI_CoreSreQ(scpi_t * context); -int SCPI_CoreStbQ(scpi_t * context); -int SCPI_CoreTstQ(scpi_t * context); -int SCPI_CoreWai(scpi_t * context); +scpi_result_t SCPI_CoreCls(scpi_t * context); +scpi_result_t SCPI_CoreEse(scpi_t * context); +scpi_result_t SCPI_CoreEseQ(scpi_t * context); +scpi_result_t SCPI_CoreEsrQ(scpi_t * context); +scpi_result_t SCPI_CoreIdnQ(scpi_t * context); +scpi_result_t SCPI_CoreOpc(scpi_t * context); +scpi_result_t SCPI_CoreOpcQ(scpi_t * context); +scpi_result_t SCPI_CoreRst(scpi_t * context); +scpi_result_t SCPI_CoreSre(scpi_t * context); +scpi_result_t SCPI_CoreSreQ(scpi_t * context); +scpi_result_t SCPI_CoreStbQ(scpi_t * context); +scpi_result_t SCPI_CoreTstQ(scpi_t * context); +scpi_result_t SCPI_CoreWai(scpi_t * context); #define STB_R01 0x01 // Not used diff --git a/scpi/scpi_minimal.c b/scpi/scpi_minimal.c index 79f6bec..3ee8d80 100644 --- a/scpi/scpi_minimal.c +++ b/scpi/scpi_minimal.c @@ -35,7 +35,7 @@ */ -#include "scpi.h" +#include "scpi_parser.h" #include "scpi_minimal.h" #include "scpi_constants.h" #include "scpi_error.h" @@ -46,9 +46,9 @@ * @param context * @return */ -int SCPI_Stub(scpi_t * context) { +scpi_result_t SCPI_Stub(scpi_t * context) { (void) context; - return 0; + return SCPI_RES_OK; } /** @@ -56,10 +56,9 @@ * @param context * @return */ -int SCPI_StubQ(scpi_t * context) { - (void) context; +scpi_result_t SCPI_StubQ(scpi_t * context) { SCPI_ResultString(context, ""); - return 0; + return SCPI_RES_OK; } /** @@ -67,10 +66,9 @@ * @param context * @return */ -int SCPI_SystemVersionQ(scpi_t * context) { - (void) context; +scpi_result_t SCPI_SystemVersionQ(scpi_t * context) { SCPI_ResultString(context, SCPI_DEV_VERSION); - return 0; + return SCPI_RES_OK; } /** @@ -78,15 +76,24 @@ * @param context * @return */ -int SCPI_SystemErrorNextQ(scpi_t * context) { - (void) context; - +scpi_result_t SCPI_SystemErrorNextQ(scpi_t * context) { int16_t err = SCPI_ErrorPop(context); SCPI_ResultInt(context, err); SCPI_ResultText(context, SCPI_ErrorTranslate(err)); - return 0; + return SCPI_RES_OK; +} + +/** + * SYSTem:ERRor:COUNt? + * @param context + * @return + */ +scpi_result_t SCPI_SystemErrorCountQ(scpi_t * context) { + SCPI_ResultInt(context, SCPI_ErrorCount(context)); + + return SCPI_RES_OK; } /** @@ -94,16 +101,14 @@ * @param context * @return */ -int SCPI_StatusQuestionableEventQ(scpi_t * context) { - (void) context; - +scpi_result_t SCPI_StatusQuestionableEventQ(scpi_t * context) { // return value SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_QUES)); // clear register SCPI_RegSet(SCPI_REG_QUES, 0); - return 0; + return SCPI_RES_OK; } /** @@ -111,13 +116,11 @@ * @param context * @return */ -int SCPI_StatusQuestionableEnableQ(scpi_t * context) { - (void) context; - +scpi_result_t SCPI_StatusQuestionableEnableQ(scpi_t * context) { // return value SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_QUESE)); - return 0; + return SCPI_RES_OK; } /** @@ -125,12 +128,12 @@ * @param context * @return */ -int SCPI_StatusQuestionableEnable(scpi_t * context) { +scpi_result_t SCPI_StatusQuestionableEnable(scpi_t * context) { int32_t new_QUESE; if (SCPI_ParamInt(context, &new_QUESE, TRUE)) { SCPI_RegSet(SCPI_REG_QUESE, new_QUESE); } - return 0; + return SCPI_RES_OK; } /** @@ -138,9 +141,9 @@ * @param context * @return */ -int SCPI_StatusPreset(scpi_t * context) { +scpi_result_t SCPI_StatusPreset(scpi_t * context) { (void) context; // clear STATUS:... SCPI_RegSet(SCPI_REG_QUES, 0); - return 0; + return SCPI_RES_OK; } diff --git a/scpi/scpi_minimal.h b/scpi/scpi_minimal.h index f993bbb..ce3f4ee 100644 --- a/scpi/scpi_minimal.h +++ b/scpi/scpi_minimal.h @@ -37,19 +37,22 @@ #ifndef SCPI_MINIMAL_H #define SCPI_MINIMAL_H +#include "scpi_types.h" + #ifdef __cplusplus extern "C" { #endif - int SCPI_Stub(scpi_t * context); - int SCPI_StubQ(scpi_t * context); - - int SCPI_SystemVersionQ(scpi_t * context); - int SCPI_SystemErrorNextQ(scpi_t * context); - int SCPI_StatusQuestionableEventQ(scpi_t * context); - int SCPI_StatusQuestionableEnableQ(scpi_t * context); - int SCPI_StatusQuestionableEnable(scpi_t * context); - int SCPI_StatusPreset(scpi_t * context); + scpi_result_t SCPI_Stub(scpi_t * context); + scpi_result_t SCPI_StubQ(scpi_t * context); + + scpi_result_t SCPI_SystemVersionQ(scpi_t * context); + scpi_result_t SCPI_SystemErrorNextQ(scpi_t * context); + scpi_result_t SCPI_SystemErrorCountQ(scpi_t * context); + scpi_result_t SCPI_StatusQuestionableEventQ(scpi_t * context); + scpi_result_t SCPI_StatusQuestionableEnableQ(scpi_t * context); + scpi_result_t SCPI_StatusQuestionableEnable(scpi_t * context); + scpi_result_t SCPI_StatusPreset(scpi_t * context); #ifdef __cplusplus diff --git a/scpi/scpi.c b/scpi/scpi_parser.c similarity index 95% rename from scpi/scpi.c rename to scpi/scpi_parser.c index ad45d8c..09ebe7b 100644 --- a/scpi/scpi.c +++ b/scpi/scpi_parser.c @@ -26,7 +26,7 @@ */ /** - * @file scpi.c + * @file scpi_parser.c * @date Thu Nov 15 10:58:45 UTC 2012 * * @brief SCPI parser implementation @@ -34,13 +34,13 @@ * */ -#include "scpi.h" -#include "scpi_utils.h" -#include "scpi_error.h" #include <ctype.h> #include <string.h> -#include <stdio.h> -#include <stdint.h> + +#include "scpi_parser.h" +#include "scpi_utils.h" +#include "scpi_error.h" + static size_t patternSeparatorPos(const char * pattern, size_t len); static size_t cmdSeparatorPos(const char * cmd, size_t len); @@ -295,7 +295,7 @@ for (i = 0; context->cmdlist[i].pattern != NULL; i++) { if (cmdMatch(context->cmdlist[i].pattern, cmdline_ptr, cmd_len)) { if (context->cmdlist[i].callback != NULL) { - context->error = FALSE; + context->cmd_error = FALSE; context->paramlist.cmd = &context->cmdlist[i]; context->paramlist.parameters = cmdline_ptr + cmd_len; context->paramlist.length = cmdlineSeparatorPos(context->paramlist.parameters, cmdline_end - context->paramlist.parameters); @@ -303,12 +303,14 @@ context->input_count = 0; SCPI_DEBUG_COMMAND(context); - context->cmdlist[i].callback(context); + if ((context->cmdlist[i].callback(context) != SCPI_RES_OK) && !context->cmd_error) { + SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); + } writeNewLine(context); // conditionaly write new line paramSkipWhitespace(context); - if (context->paramlist.length != 0 && !context->error) { + if (context->paramlist.length != 0 && !context->cmd_error) { SCPI_ErrorPush(context, SCPI_ERROR_PARAMETER_NOT_ALLOWED); } @@ -340,6 +342,7 @@ context->buffer.length = buffer->length; context->buffer.position = 0; context->interface = interface; + SCPI_ErrorInit(context); } /** @@ -382,21 +385,6 @@ return result; } - -/** - * Debug function: show current command and its parameters - * @param context - * @return - */ -bool_t SCPI_DebugCommand(scpi_t * context) { - (void) context; - printf("**DEBUG: %s (\"", context->paramlist.cmd->pattern); - fwrite(context->paramlist.parameters, 1, context->paramlist.length, stdout); - printf("\" - %ld)\r\n", context->paramlist.length); - - return TRUE; -} - /* writing results */ @@ -507,7 +495,6 @@ paramSkipBytes(context, 1); paramSkipWhitespace(context); } else { - printf("******** :%c:\r\n", context->paramlist.parameters[0]); SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SEPARATOR); return FALSE; } diff --git a/scpi/scpi_parser.h b/scpi/scpi_parser.h new file mode 100644 index 0000000..b18240c --- /dev/null +++ b/scpi/scpi_parser.h @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 2012-2013 Jan Breuer, + * + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file scpi_parser.h + * @date Thu Nov 15 10:58:45 UTC 2012 + * + * @brief SCPI parser implementation + * + * + */ + +#ifndef SCPI_PARSER_H +#define SCPI_PARSER_H + +#include "scpi_types.h" +#include "scpi_debug.h" + +#ifdef __cplusplus +extern "C" { +#endif + + void SCPI_Init(scpi_t * context, scpi_command_t * command_list, scpi_buffer_t * buffer, scpi_interface_t * interface); + + int SCPI_Input(scpi_t * context, const char * data, size_t len); + int SCPI_Parse(scpi_t * context, const char * data, size_t len); + + + size_t SCPI_ResultString(scpi_t * context, const char * data); + size_t SCPI_ResultInt(scpi_t * context, int32_t val); + size_t SCPI_ResultDouble(scpi_t * context, double val); + size_t SCPI_ResultText(scpi_t * context, const char * data); + + bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory); + bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory); + bool_t SCPI_ParamString(scpi_t * context, char ** value, size_t * len, bool_t mandatory); + + +#ifdef __cplusplus +} +#endif + +#endif /* SCPI_PARSER_H */ + diff --git a/scpi/scpi_types.h b/scpi/scpi_types.h new file mode 100644 index 0000000..fb880e2 --- /dev/null +++ b/scpi/scpi_types.h @@ -0,0 +1,172 @@ +/*- + * Copyright (c) 2012-2013 Jan Breuer, + * + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file scpi_types.h + * @date Thu Nov 15 10:58:45 UTC 2012 + * + * @brief SCPI data types + * + * + */ + +#ifndef SCPI_TYPES_H +#define SCPI_TYPES_H + +#include <stddef.h> +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define FALSE false +#define TRUE true + + /* basic data types */ + typedef bool bool_t; + //typedef enum { FALSE = 0, TRUE } bool_t; + + /* scpi interface */ + typedef struct _scpi_t scpi_t; + typedef struct _scpi_interface_t scpi_interface_t; + typedef struct _scpi_buffer_t scpi_buffer_t; + typedef size_t(*scpi_write_t)(scpi_t * context, const char * data, size_t len); + typedef int (*scpi_error_callback_t)(scpi_t * context, int_fast16_t error); + + /* scpi commands */ + typedef enum _scpi_result_t scpi_result_t; + typedef struct _scpi_param_list_t scpi_param_list_t; + typedef struct _scpi_command_t scpi_command_t; + typedef scpi_result_t (*scpi_command_callback_t)(scpi_t *); + + /* scpi error queue */ + typedef void * scpi_error_queue_t; + + /* scpi units */ + typedef enum _scpi_unit_t scpi_unit_t; + typedef struct _scpi_unit_def_t scpi_unit_def_t; + typedef enum _scpi_special_number_t scpi_special_number_t; + typedef struct _scpi_special_number_def_t scpi_special_number_def_t; + typedef struct _scpi_number_t scpi_number_t; + + + struct _scpi_param_list_t { + const scpi_command_t * cmd; + const char * parameters; + size_t length; + }; + + +#define SCPI_CMD_LIST_END {.pattern = NULL, .callback = NULL, } + + struct _scpi_command_t { + const char * pattern; + scpi_command_callback_t callback; + }; + + struct _scpi_buffer_t { + size_t length; + size_t position; + char * data; + }; + + struct _scpi_interface_t { + scpi_error_callback_t error; + scpi_write_t write; + scpi_command_callback_t reset; + scpi_command_callback_t test; + }; + + struct _scpi_t { + const scpi_command_t * cmdlist; + scpi_buffer_t buffer; + scpi_param_list_t paramlist; + scpi_interface_t * interface; + int_fast16_t output_count; + int_fast16_t input_count; + bool_t cmd_error; + scpi_error_queue_t error_queue; + }; + + enum _scpi_unit_t { + SCPI_UNIT_NONE, + SCPI_UNIT_VOLT, + SCPI_UNIT_AMPER, + SCPI_UNIT_OHM, + SCPI_UNIT_HERTZ, + SCPI_UNIT_CELSIUS, + SCPI_UNIT_SECONDS, + }; + + +#define SCPI_UNITS_LIST_END {.name = NULL, .unit = SCPI_UNIT_NONE, .mult = 0} + + struct _scpi_unit_def_t { + const char * name; + scpi_unit_t unit; + double mult; + }; + + enum _scpi_special_number_t { + SCPI_NUM_NUMBER, + SCPI_NUM_MIN, + SCPI_NUM_MAX, + SCPI_NUM_DEF, + SCPI_NUM_UP, + SCPI_NUM_DOWN, + SCPI_NUM_NAN, + SCPI_NUM_INF, + SCPI_NUM_NINF, + }; + +#define SCPI_SPECIAL_NUMBERS_LIST_END {.name = NULL, .type = SCPI_NUM_NUMBER} + + struct _scpi_special_number_def_t { + const char * name; + scpi_special_number_t type; + }; + + struct _scpi_number_t { + double value; + scpi_unit_t unit; + scpi_special_number_t type; + }; + + enum _scpi_result_t { + SCPI_RES_OK = 1, + SCPI_RES_ERR = -1, + }; + + +#ifdef __cplusplus +} +#endif + +#endif /* SCPI_TYPES_H */ + diff --git a/scpi/scpi_units.c b/scpi/scpi_units.c index 591d6e3..dc058fe 100644 --- a/scpi/scpi_units.c +++ b/scpi/scpi_units.c @@ -35,7 +35,7 @@ */ #include <string.h> -#include "scpi.h" +#include "scpi_parser.h" #include "scpi_units.h" #include "scpi_utils.h" #include "scpi_error.h" diff --git a/scpi/scpi_units.h b/scpi/scpi_units.h index d50fdcc..9521ff0 100644 --- a/scpi/scpi_units.h +++ b/scpi/scpi_units.h @@ -37,61 +37,11 @@ #ifndef SCPI_UNITS_H #define SCPI_UNITS_H -#include "scpi.h" +#include "scpi_types.h" #ifdef __cplusplus extern "C" { #endif - - enum _scpi_unit_t { - SCPI_UNIT_NONE, - SCPI_UNIT_VOLT, - SCPI_UNIT_AMPER, - SCPI_UNIT_OHM, - SCPI_UNIT_HERTZ, - SCPI_UNIT_CELSIUS, - SCPI_UNIT_SECONDS, - }; - typedef enum _scpi_unit_t scpi_unit_t; - - struct _scpi_unit_def_t { - const char * name; - scpi_unit_t unit; - double mult; - }; - typedef struct _scpi_unit_def_t scpi_unit_def_t; - -#define SCPI_UNITS_LIST_END {.name = NULL, .unit = SCPI_UNIT_NONE, .mult = 0} - - enum _scpi_special_number_t { - SCPI_NUM_NUMBER, - SCPI_NUM_MIN, - SCPI_NUM_MAX, - SCPI_NUM_DEF, - SCPI_NUM_UP, - SCPI_NUM_DOWN, - SCPI_NUM_NAN, - SCPI_NUM_INF, - SCPI_NUM_NINF, - }; - typedef enum _scpi_special_number_t scpi_special_number_t; - - struct _scpi_special_number_def_t { - const char * name; - scpi_special_number_t type; - }; - typedef struct _scpi_special_number_def_t scpi_special_number_def_t; - - struct _scpi_number_t { - double value; - scpi_unit_t unit; - scpi_special_number_t type; - }; - typedef struct _scpi_number_t scpi_number_t; - - -#define SCPI_SPECIAL_NUMBERS_LIST_END {.name = NULL, .type = SCPI_NUM_NUMBER} - bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory); size_t SCPI_NumberToStr(scpi_t * context, scpi_number_t * value, char * str, size_t len); diff --git a/scpi/scpi_utils.c b/scpi/scpi_utils.c index 94aaf8f..4546b35 100644 --- a/scpi/scpi_utils.c +++ b/scpi/scpi_utils.c @@ -34,13 +34,13 @@ * */ -#include "scpi.h" -#include "scpi_utils.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> +#include "scpi_utils.h" + static size_t patternSeparatorShortPos(const char * pattern, size_t len); /** diff --git a/scpi/scpi_utils.h b/scpi/scpi_utils.h index 521fe87..7da171a 100644 --- a/scpi/scpi_utils.h +++ b/scpi/scpi_utils.h @@ -37,8 +37,8 @@ #ifndef SCPI_UTILS_H #define SCPI_UTILS_H -#include "scpi.h" #include <stdint.h> +#include "scpi_types.h" #ifdef __cplusplus extern "C" { diff --git a/test-parser.c b/test-parser.c index 685fc65..66ca530 100644 --- a/test-parser.c +++ b/test-parser.c @@ -38,14 +38,8 @@ #include <stdlib.h> #include <string.h> #include "scpi/scpi.h" -#include "scpi/scpi_ieee488.h" -#include "scpi/scpi_error.h" -#include "scpi/scpi_constants.h" -#include "scpi/scpi_minimal.h" -#include "scpi/scpi_utils.h" -#include "scpi/scpi_units.h" -int DMM_MeasureVoltageDcQ(scpi_t * context) { +scpi_result_t DMM_MeasureVoltageDcQ(scpi_t * context) { scpi_number_t param1, param2; char bf[15]; fprintf(stderr, "meas:volt:dc\r\n"); // debug command name @@ -63,7 +57,8 @@ } SCPI_ResultDouble(context, 0); - return 0; + + return SCPI_RES_OK; } scpi_command_t scpi_commands[] = { @@ -85,6 +80,7 @@ /* Required SCPI commands (SCPI std V1999.0 4.2.1) */ {.pattern = "SYSTem:ERRor?", .callback = SCPI_SystemErrorNextQ,}, {.pattern = "SYSTem:ERRor:NEXT?", .callback = SCPI_SystemErrorNextQ,}, + {.pattern = "SYSTem:ERRor:COUNt?", .callback = SCPI_SystemErrorCountQ,}, {.pattern = "SYSTem:VERSion?", .callback = SCPI_SystemVersionQ,}, //{.pattern = "STATus:OPERation?", .callback = scpi_stub_callback,}, @@ -187,8 +183,8 @@ // interactive demo //char smbuffer[10]; //while (1) { - // fgets(smbuffer, 10, stdin); - // SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); + // fgets(smbuffer, 10, stdin); + // SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); //} -- Gitblit v1.9.1