| |
| |
| |
| /*============================================================================= |
| ** FileName: dhcp_test.cpp |
| ** Desc: about function test |
| ** Author: grays |
| ** Version: V1.0 |
| ** LastChange: 2021-08-18 |
| ** History: |
| =============================================================================*/ |
| |
| |
| #include "function_common.h" |
| #include <log/log.h> |
| #include <unistd.h> |
| #include <stdio.h> |
| #include <string.h> |
| #include <stdlib.h> |
| #include <fcntl.h> |
| #include <pthread.h> |
| #include "liblog/liblog.h" |
| #include "liblog/lynq_deflog.h" |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| #include "include/lynq-system-own.h" |
| #ifdef __cplusplus |
| } |
| #endif |
| |
| void* thread(void* arg) |
| { |
| #if 1 |
| pthread_detach(pthread_self()); |
| int edge=0; |
| while(LYNQ_Lpm_Handler){ |
| lynq_lpm_handler(edge);//gpio电平变化则上报 |
| } |
| #endif |
| pthread_exit(0); |
| } |
| |
| int system_test(char *api,char *string) { |
| char *argv[100] = {0}; |
| pthread_t id; |
| int ret; |
| parseParameters(string,argv); |
| int Flag=0; |
| if(!strcmp(api, "init")){ |
| LYNQ_Lpm_Init(lynq_lpm_handler);//初始化lpm,监听gpio电平上报事件 |
| ret = pthread_create(&id,NULL,thread,NULL); //创建线程来监听gpio电平变化 |
| if(ret != 0) |
| { |
| printf("Create pthread error!\n"); |
| exit(1); |
| } |
| sleep(2); |
| }else if(!strcmp(api, "deinit")){ |
| LYNQ_Lpm_Deinit();//注销lpm。 |
| }else if(!strcmp(api,"adc")){ |
| int adc_n = atoi(argv[0]); |
| printf("api = %s adc=%d\n", api,LYNQ_Adc_Show(adc_n));//当前电源电压 |
| }else if(!strcmp(api, "suspend")){ |
| Flag = atoi(argv[0]); |
| LYNQ_Autosleep_Enable(Flag);//使能系统睡眠 |
| }else if(!strcmp(api, "Lock")){ |
| LYNQ_SLP_WakeLock_Lock(argv[0]);//创建wakelock锁,此时系统无法进入睡眠 |
| }else if(!strcmp(api, "Unlock")){ |
| LYNQ_SLP_WakeLock_Unlock(argv[0]);//解锁wakelock,此时系统可进入睡眠 |
| }else if(!strcmp(api, "powerdown")){ |
| Flag = atoi(argv[0]); |
| LYNQ_Power_Down(Flag);//开关机接口,用于选择关机或重启 |
| }else if(!strcmp(api, "changemod")){ |
| LYNQ_Power_Mode(argv[0]);//开关机接口,用于选择关机或重启 |
| }else { |
| printf("invalid api \n" ); |
| } |
| |
| return 0; |
| } |