diff test-ad9912.c @ 265:da38cbbc7ec8

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.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Sun, 21 Jun 2015 14:44:33 +0200
parents
children
line wrap: on
line diff
--- /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 <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#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;
+}