# HG changeset patch # User Daniele Nicolodi # Date 1434890673 -7200 # Node ID da38cbbc7ec8ba6ef234716d9896e75ff6d2c2cd # Parent a40c8af8b0288147885e138ce2e878b29c0d7b24 Add DDS clients test code To verify the portabiolity of the clients code and to make testing easier the test code is independent of the CVI environment and runtime. diff -r a40c8af8b028 -r da38cbbc7ec8 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Sun Jun 21 14:44:33 2015 +0200 @@ -0,0 +1,13 @@ +# makefile to compile test programs independently of LabWindowCVI + +TESTS = test-ad9912 test-ad9956 +CFLAGS = -Wall -Wextra -Werror + +all: $(TESTS) + +test-ad9912: xsocket.o ad9912.o + +test-ad9956: xsocket.o ad9956.o + +clean: + rm -f *.o $(TESTS) diff -r a40c8af8b028 -r da38cbbc7ec8 test-ad9912.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-ad9912.c Sun Jun 21 14:44:33 2015 +0200 @@ -0,0 +1,43 @@ +#include +#include +#include +#include "ad9912.h" + +#define die() do { printf("ERROR: %s\n", strerror(-r)); exit(EXIT_FAILURE); } while (0) +#define error() do { printf("ERROR: %s\n", strerror(-r)); } while (0) + +int main(int argc, char **argv) +{ + int r; + double f; + struct ad9912 dds; + + if (argc < 2) + exit(EXIT_FAILURE); + + r = ad9912_init(&dds, argv[1], 1e9); + if (r < 0) + error(); + + for (int i = 0; i < 4; i++) { + r = ad9912_get_frequency(&dds, i, &f); + if (r < 0) + die(); + printf("DDS%d f=%f Hz\n", i, f); + } + + for (int i = 0; i < 4; i++) { + r = ad9912_set_frequency(&dds, i, i * 10e6); + if (r < 0) + error(); + } + + for (int i = 0; i < 4; i++) { + r = ad9912_get_frequency(&dds, i, &f); + if (r < 0) + error(); + printf("DDS%d f=%f Hz\n", i, f); + } + + return 0; +} diff -r a40c8af8b028 -r da38cbbc7ec8 test-ad9956.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-ad9956.c Sun Jun 21 14:44:33 2015 +0200 @@ -0,0 +1,29 @@ +#include +#include +#include "ad9956.h" + +#define error() do { printf("ERROR: %s\n", strerror(-r)); exit(EXIT_FAILURE); } while (0) + +int main(int argc, char **argv) +{ + int r; + double f; + struct ad9956 dds; + + if (argc < 2) + return 1; + + r = ad9956_init(&dds, argv[1], 1e9); + if (r < 0) + error(); + + r = ad9956_get_frequency(&dds, &f); + if (r < 0) + error(); + + r = ad9956_set_frequency(&dds, 10e6); + if (r < 0) + error(); + + return 0; +}