xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | |
| 2 | |
| 3 | |
| 4 | /*============================================================================= |
| 5 | ** FileName: dhcp_test.cpp |
| 6 | ** Desc: about function test |
| 7 | ** Author: grays |
| 8 | ** Version: V1.0 |
| 9 | ** LastChange: 2021-08-18 |
| 10 | ** History: |
| 11 | =============================================================================*/ |
| 12 | |
| 13 | |
| 14 | #include "function_common.h" |
| 15 | #include <log/log.h> |
| 16 | #include <unistd.h> |
| 17 | #include <stdio.h> |
| 18 | #include <string.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <pthread.h> |
| 22 | #include "liblog/liblog.h" |
| 23 | #include "liblog/lynq_deflog.h" |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | #include "include/lynq-system-own.h" |
| 29 | #ifdef __cplusplus |
| 30 | } |
| 31 | #endif |
| 32 | |
| 33 | void* thread(void* arg) |
| 34 | { |
| 35 | #if 1 |
| 36 | pthread_detach(pthread_self()); |
| 37 | int edge=0; |
| 38 | while(LYNQ_Lpm_Handler){ |
| 39 | lynq_lpm_handler(edge);//gpio电平变化则上报 |
| 40 | } |
| 41 | #endif |
| 42 | pthread_exit(0); |
| 43 | } |
| 44 | |
| 45 | int system_test(char *api,char *string) { |
| 46 | char *argv[100] = {0}; |
| 47 | pthread_t id; |
| 48 | int ret; |
| 49 | parseParameters(string,argv); |
| 50 | int Flag=0; |
| 51 | if(!strcmp(api, "init")){ |
| 52 | LYNQ_Lpm_Init(lynq_lpm_handler);//初始化lpm,监听gpio电平上报事件 |
| 53 | ret = pthread_create(&id,NULL,thread,NULL); //创建线程来监听gpio电平变化 |
| 54 | if(ret != 0) |
| 55 | { |
| 56 | printf("Create pthread error!\n"); |
| 57 | exit(1); |
| 58 | } |
| 59 | sleep(2); |
| 60 | }else if(!strcmp(api, "deinit")){ |
| 61 | LYNQ_Lpm_Deinit();//注销lpm。 |
| 62 | }else if(!strcmp(api,"adc")){ |
| 63 | int adc_n = atoi(argv[0]); |
| 64 | printf("api = %s adc=%d\n", api,LYNQ_Adc_Show(adc_n));//当前电源电压 |
| 65 | }else if(!strcmp(api, "suspend")){ |
| 66 | Flag = atoi(argv[0]); |
| 67 | LYNQ_Autosleep_Enable(Flag);//使能系统睡眠 |
| 68 | }else if(!strcmp(api, "Lock")){ |
| 69 | LYNQ_SLP_WakeLock_Lock(argv[0]);//创建wakelock锁,此时系统无法进入睡眠 |
| 70 | }else if(!strcmp(api, "Unlock")){ |
| 71 | LYNQ_SLP_WakeLock_Unlock(argv[0]);//解锁wakelock,此时系统可进入睡眠 |
| 72 | }else if(!strcmp(api, "powerdown")){ |
| 73 | Flag = atoi(argv[0]); |
| 74 | LYNQ_Power_Down(Flag);//开关机接口,用于选择关机或重启 |
| 75 | }else if(!strcmp(api, "changemod")){ |
| 76 | LYNQ_Power_Mode(argv[0]);//开关机接口,用于选择关机或重启 |
| 77 | }else { |
| 78 | printf("invalid api \n" ); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |