aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan <yanxk.fnst@fujitsu.com>2024-02-19 18:56:44 +0800
committerYan <yanxk.fnst@fujitsu.com>2024-02-19 18:56:44 +0800
commitbc7cbe98dbc90a4fdcaf48c9adab2b0213aaac4f (patch)
tree9c26f54e595103405a2e693bcb772f374ee825b3
parent9de8a16162dcae3da11700df3e9ef18571c08969 (diff)
incar demo: test files
help test whether hardwares work Change-Id: I17912e3c29a5100bdf988ff825e876915512e91d Signed-off-by: Yan <yanxk.fnst@fujitsu.com>
-rw-r--r--test/Makefile16
-rw-r--r--test/README.md9
-rw-r--r--test/test_gprs.c47
-rw-r--r--test/test_zigbee.c56
4 files changed, 128 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..0b04442
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,16 @@
+CFLAGS = -Wall -I../include/ -g
+
+LDFLAGS = -lcomfig -L../lib/
+
+.PHONY: all clean
+
+all: test_gprs test_zigbee
+
+test_gprs: test_gprs.c
+ $(CC) $(CFLAGS) test_gprs.c -o $@ $(LDFLAGS)
+
+test_zigbee: test_zigbee.c
+ $(CC) $(CFLAGS) test_zigbee.c -o $@ $(LDFLAGS)
+
+clean:
+ rm test_zigbee test_gprs
diff --git a/test/README.md b/test/README.md
new file mode 100644
index 0000000..771cdcd
--- /dev/null
+++ b/test/README.md
@@ -0,0 +1,9 @@
+Tips:
+
+This is the basic test of demo.
+
+Bugs:
+
+1, File describer can be got only for once.
+
+2, Zigbee TH not responding.
diff --git a/test/test_gprs.c b/test/test_gprs.c
new file mode 100644
index 0000000..fa0bf3b
--- /dev/null
+++ b/test/test_gprs.c
@@ -0,0 +1,47 @@
+/*
+ * File Name: test_gprs.c
+ * Workflow: init serial port, write to GPRS module
+ * Return Value: 0 always
+ */
+
+/* Header files */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "uart_api.h"
+
+int main() {
+
+ int gprs_fd;
+
+ gprs_fd = open_port("/dev/ttyUSB0");
+
+ set_comfig(gprs_fd, 9600);
+
+ char temp[32] = {0};
+
+ memset(temp, '\0', 32);
+ strcpy(temp, "AT\n");
+ write(gprs_fd, temp, strlen(temp));
+ read(gprs_fd, temp, 32);
+
+ if (strncmp(temp, "OK", 2)) {
+ printf("[SUCCESS]Connection fine!\n");
+ } else {
+ printf("[ERROR]Connection invalid!\n");
+ }
+
+ sleep(1);
+
+ printf("Testing module function......\n");
+ memset(temp, '\0', 32);
+
+ sprintf(temp, "ATD%s;", "YOUR PHONE NUMBER");
+
+ strcat(temp, "\n");
+
+ write(gprs_fd, temp, strlen(temp));
+
+ return 0;
+} \ No newline at end of file
diff --git a/test/test_zigbee.c b/test/test_zigbee.c
new file mode 100644
index 0000000..57b6b90
--- /dev/null
+++ b/test/test_zigbee.c
@@ -0,0 +1,56 @@
+/*
+ * File Name: test_zigbee.c
+ * Workflow: init serial port, write/read from coordinator
+ * Return Value: 0 always
+ */
+
+/* Header files */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "uart_api.h"
+
+int main() {
+
+ int coordinator_fd;
+ int retVal;
+
+ coordinator_fd = open_port("/dev/ttyUSB0");
+ printf("Open port get file describer: %d\n", coordinator_fd);
+
+ set_comfig(coordinator_fd, 115200);
+ printf("Set serial com config 115200\n");
+
+ char temp[8] = {0};
+
+ memset(temp, '\0', 8);
+ strcpy(temp, "ON");
+
+ retVal = write(coordinator_fd, temp, strlen(temp));
+ printf("[Manual] You have 5 seconds to check fan status, should be ON...\n");
+
+ sleep(5);
+
+ memset(temp, '\0', 8);
+ strcpy(temp, "OFF");
+ retVal = write(coordinator_fd, temp, strlen(temp));
+ printf("[Manual] You have 5 seconds to check fan status, should be OFF...\n");
+
+ memset(temp, '\0', 8);
+ strcpy(temp, "TH");
+ retVal = write(coordinator_fd, temp, strlen(temp));
+
+ sleep(1);
+ memset(temp, '\0', 8);
+ retVal = read(coordinator_fd, temp, 8);
+
+ if (retVal >= 6) {
+ printf("[SUCCESS] DHT11 response detected.\n");
+ } else {
+ printf("[ERROR] Invalid respone format.\n");
+ }
+
+ close(coordinator_fd);
+ return 0;
+}