1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
}
|