blob: ca00017c1c6cc7b6b1adb04e4e64a0253a489229 [file] [log] [blame]
xjde81d1d2021-11-25 15:01:52 +08001/*=============================================================================
2** FileName: gpio_test.cpp
3** Desc: about function test
4** Author: zhou
5** Version: V1.0
6** LastChange: 2021-03-04
7** History:
8=============================================================================*/
9#include "function_common.h"
10#include <log/log.h>
11#include "gpio_test.h"
12#include <stdio.h>
13#include <string.h>
14#include <stdlib.h>
15#ifdef __cplusplus
16extern "C" {
17#endif
18#include "liblynq-driver/libdriver.h"
19#ifdef __cplusplus
20}
21#endif
22int check_mode(const char *mode)
23{
24if(!strcmp(mode, GPIO_DIR))
25{
26 return 1;
27}
28if(!strcmp(mode, GPIO_OUT))
29{
30 return 1;
31}
32if(!strcmp(mode, GPIO_MODE))
33{
34 return 1;
35}
36 return -1;
37}
38int check_status(int statu)
39{
40 if (statu == 0)
41 return 1;
42 if (statu ==1)
43 return 1;
44 return -1;
45}
46int gpio_test(char *api,char *string) {
47 char *argv[100] = {0};
48 parseParameters(string,argv);
49 if(!strcmp(api, "get")){
50 char output1[1024] = {0};
51 int value = atoi(argv[0]);
52 lynq_get_gpio (value,output1);
53 // printf("Factory_result get %d gpio:%s \n",value,output1)
54 LYVERBLOG("+[gpio][get]: data = %s\n",output1);
55
56 }
57 else if(!strcmp(api, "set")){
58 int gpio_numb = atoi(argv[1]);
59 int gpio_statu = atoi(argv[2]);
60 int check_prame;
61 check_prame = check_mode(argv[0]);
62 if(check_prame == -1)
63 {
64 LYVERBLOG("+[gpio][set]: error num = %d \n",GPIO_PRAME_ERROR);
65 return 0;
66 }
67 check_prame = check_status(gpio_statu);
68 if(check_prame == -1)
69 {
70 LYVERBLOG("+[gpio][set]: error num = %d \n",GPIO_PRAME_ERROR);
71 return 0;
72 }
73 int result = lynq_set_gpio(argv[0], gpio_numb,gpio_statu);
74 if(result == -1)
75 {
76 LYVERBLOG("+[gpio][set]: error num = %d \n",GPIO_SET_ERROR);
77 return 0;
78 }
79 else
80 {
81 LYVERBLOG("+[gpio][set]: ok!!\n",result);
82 return 1;
83 }
84 // printf("Factory_result gpio %d set state :%d\n",gpio_numb,result);
85 }
86 else {
87 LYVERBLOG("+[gpio][lynq_set_gpio]: error num =%d\n",GPIO_PRAME_ERROR);
88 }
89
90 return 0;
91}