Include cleanup, better error handling
16个文件已修改
7个文件已添加
1 文件已重命名
| | |
| | | |
| | | # 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 |
| | |
| | | |
| | | # Test Files |
| | | TESTFILES= \ |
| | | ${TESTDIR}/TestFiles/f2 \ |
| | | ${TESTDIR}/TestFiles/f3 |
| | | |
| | | # C Compiler Flags |
| | |
| | | ${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 |
| | |
| | | |
| | | # 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 |
| | |
| | | ${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 |
| | |
| | | $(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 |
| | |
| | | ${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`; \ |
| | |
| | | $(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 |
| | |
| | | .test-conf: |
| | | @if [ "${TEST}" = "" ]; \ |
| | | then \ |
| | | ${TESTDIR}/TestFiles/f2 || true; \ |
| | | ${TESTDIR}/TestFiles/f3 || true; \ |
| | | else \ |
| | | ./${TEST} || true; \ |
| | |
| | | |
| | | # 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 |
| | |
| | | |
| | | # Test Files |
| | | TESTFILES= \ |
| | | ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans \ |
| | | ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans |
| | | |
| | | # C Compiler Flags |
| | |
| | | ${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 |
| | |
| | | |
| | | # 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 |
| | |
| | | ${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 |
| | |
| | | $(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 |
| | |
| | | ${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`; \ |
| | |
| | | $(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 |
| | |
| | | @if [ "${TEST}" = "" ]; \ |
| | | then \ |
| | | ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans || true; \ |
| | | ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/netbeans || true; \ |
| | | else \ |
| | | ./${TEST} || true; \ |
| | | fi |
| | |
| | | <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> |
| | |
| | | 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> |
| | |
| | | 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" |
| | |
| | | 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> |
New file |
| | |
| | | /* |
| | | * 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(); |
| | | } |
| | |
| | | #include "CUnit/Basic.h" |
| | | |
| | | #include "../scpi/scpi.h" |
| | | #include "../scpi/scpi_utils.h" |
| | | |
| | | /* |
| | | * CUnit Test Suite |
| | |
| | | * @file scpi.h |
| | | * @date Thu Nov 15 10:58:45 UTC 2012 |
| | | * |
| | | * @brief SCPI parser implementation |
| | | * @brief SCPI library include file |
| | | * |
| | | * |
| | | */ |
| | |
| | | #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 */ |
| | | |
New file |
| | |
| | | /*- |
| | | * 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; |
| | | } |
New file |
| | |
| | | /*- |
| | | * 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 */ |
| | | |
| | |
| | | * |
| | | */ |
| | | |
| | | #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); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | case SCPI_ERROR_SUFFIX_NOT_ALLOWED: return "Suffix not allowed"; |
| | | default: return "Unknown error"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | #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 |
| | |
| | | #define SCPI_ERROR_INVALID_SUFFIX -131 |
| | | #define SCPI_ERROR_SUFFIX_NOT_ALLOWED -138 |
| | | |
| | | #define SCPI_ERROR_EXECUTION_ERROR -200 |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
New file |
| | |
| | | |
| | | #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; |
| | | } |
New file |
| | |
| | | /*- |
| | | * 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 */ |
| | |
| | | * |
| | | */ |
| | | |
| | | #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]; |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | |
| | | #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; |
| | | |
| | |
| | | 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 |
| | |
| | | */ |
| | | |
| | | |
| | | #include "scpi.h" |
| | | #include "scpi_parser.h" |
| | | #include "scpi_minimal.h" |
| | | #include "scpi_constants.h" |
| | | #include "scpi_error.h" |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | |
| | | #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 |
File was renamed from scpi/scpi.c |
| | |
| | | */ |
| | | |
| | | /** |
| | | * @file scpi.c |
| | | * @file scpi_parser.c |
| | | * @date Thu Nov 15 10:58:45 UTC 2012 |
| | | * |
| | | * @brief SCPI parser implementation |
| | |
| | | * |
| | | */ |
| | | |
| | | #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); |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | context->buffer.length = buffer->length; |
| | | context->buffer.position = 0; |
| | | context->interface = interface; |
| | | SCPI_ErrorInit(context); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | 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 */ |
| | | |
| | |
| | | paramSkipBytes(context, 1); |
| | | paramSkipWhitespace(context); |
| | | } else { |
| | | printf("******** :%c:\r\n", context->paramlist.parameters[0]); |
| | | SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SEPARATOR); |
| | | return FALSE; |
| | | } |
New file |
| | |
| | | /*- |
| | | * 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 */ |
| | | |
New file |
| | |
| | | /*- |
| | | * 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 */ |
| | | |
| | |
| | | */ |
| | | |
| | | #include <string.h> |
| | | #include "scpi.h" |
| | | #include "scpi_parser.h" |
| | | #include "scpi_units.h" |
| | | #include "scpi_utils.h" |
| | | #include "scpi_error.h" |
| | |
| | | #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); |
| | |
| | | * |
| | | */ |
| | | |
| | | #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); |
| | | |
| | | /** |
| | |
| | | #ifndef SCPI_UTILS_H |
| | | #define SCPI_UTILS_H |
| | | |
| | | #include "scpi.h" |
| | | #include <stdint.h> |
| | | #include "scpi_types.h" |
| | | |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | |
| | | #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 |
| | |
| | | } |
| | | |
| | | SCPI_ResultDouble(context, 0); |
| | | return 0; |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | scpi_command_t scpi_commands[] = { |
| | |
| | | /* 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,}, |
| | |
| | | // 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)); |
| | | //} |
| | | |
| | | |