blob: ca00017c1c6cc7b6b1adb04e4e64a0253a489229 [file] [log] [blame]
/*=============================================================================
** FileName: gpio_test.cpp
** Desc: about function test
** Author: zhou
** Version: V1.0
** LastChange: 2021-03-04
** History:
=============================================================================*/
#include "function_common.h"
#include <log/log.h>
#include "gpio_test.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "liblynq-driver/libdriver.h"
#ifdef __cplusplus
}
#endif
int check_mode(const char *mode)
{
if(!strcmp(mode, GPIO_DIR))
{
return 1;
}
if(!strcmp(mode, GPIO_OUT))
{
return 1;
}
if(!strcmp(mode, GPIO_MODE))
{
return 1;
}
return -1;
}
int check_status(int statu)
{
if (statu == 0)
return 1;
if (statu ==1)
return 1;
return -1;
}
int gpio_test(char *api,char *string) {
char *argv[100] = {0};
parseParameters(string,argv);
if(!strcmp(api, "get")){
char output1[1024] = {0};
int value = atoi(argv[0]);
lynq_get_gpio (value,output1);
// printf("Factory_result get %d gpio:%s \n",value,output1)
LYVERBLOG("+[gpio][get]: data = %s\n",output1);
}
else if(!strcmp(api, "set")){
int gpio_numb = atoi(argv[1]);
int gpio_statu = atoi(argv[2]);
int check_prame;
check_prame = check_mode(argv[0]);
if(check_prame == -1)
{
LYVERBLOG("+[gpio][set]: error num = %d \n",GPIO_PRAME_ERROR);
return 0;
}
check_prame = check_status(gpio_statu);
if(check_prame == -1)
{
LYVERBLOG("+[gpio][set]: error num = %d \n",GPIO_PRAME_ERROR);
return 0;
}
int result = lynq_set_gpio(argv[0], gpio_numb,gpio_statu);
if(result == -1)
{
LYVERBLOG("+[gpio][set]: error num = %d \n",GPIO_SET_ERROR);
return 0;
}
else
{
LYVERBLOG("+[gpio][set]: ok!!\n",result);
return 1;
}
// printf("Factory_result gpio %d set state :%d\n",gpio_numb,result);
}
else {
LYVERBLOG("+[gpio][lynq_set_gpio]: error num =%d\n",GPIO_PRAME_ERROR);
}
return 0;
}