From bc7cbe98dbc90a4fdcaf48c9adab2b0213aaac4f Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 19 Feb 2024 18:56:44 +0800 Subject: incar demo: test files help test whether hardwares work Change-Id: I17912e3c29a5100bdf988ff825e876915512e91d Signed-off-by: Yan --- test/Makefile | 16 ++++++++++++++++ test/README.md | 9 +++++++++ test/test_gprs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ test/test_zigbee.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 test/Makefile create mode 100644 test/README.md create mode 100644 test/test_gprs.c create mode 100644 test/test_zigbee.c (limited to 'test') 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 +#include +#include + +#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 +#include +#include + +#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; +} -- cgit 1.2.3-korg