| #include <stdio.h> |
| #include <string.h> |
| #include <strings.h> |
| #include <stdlib.h> |
| #include <errno.h> |
| #include <fcntl.h> |
| #include <signal.h> |
| #include <sys/types.h> |
| #include <unistd.h> |
| #include <pthread.h> |
| #include <termios.h> |
| #include <time.h> |
| #include <sys/ioctl.h> |
| #include <dlfcn.h> |
| #include <stdint.h> |
| #include <stdbool.h> |
| |
| #include "gsw_usb.h" |
| |
| int32_t (*gsw_usb_permanent_switch_demo)(EN_GSW_USB_SWITCH_TYPE type); |
| int32_t (*gsw_usb_tempporary_switch_demo)(EN_GSW_USB_SWITCH_TYPE type); |
| void *dlHandle; |
| char *lynqLib = "/lib/libgsw_lib.so"; |
| |
| int main(int argc, char *argv[]) |
| { |
| int ret; |
| EN_GSW_USB_SWITCH_TYPE type; |
| bool usb_change = false; |
| if(argc != 2) |
| { |
| printf("parameter error,please input open or close\n"); |
| return -1; |
| } |
| |
| if(strcmp(argv[0],"gsw_usb_test") == 0) |
| usb_change = true; |
| else |
| usb_change = false; |
| printf("usb is %s\n",argv[1]); |
| if(strcmp(argv[1],"open") == 0) |
| type = EN_GSW_USB_SWITCH_OPEN; |
| else if(strcmp(argv[1],"close") == 0) |
| type = EN_GSW_USB_SWITCH_CLOSE; |
| else |
| { |
| printf("parameter error,please input open or close\n"); |
| return -1; |
| } |
| dlHandle = dlopen(lynqLib, RTLD_NOW); |
| if(dlHandle == NULL) |
| { |
| printf("dlopen libgsw_lib fail\n"); |
| return -1; |
| } |
| if(usb_change) |
| { |
| gsw_usb_permanent_switch_demo=(int32_t(*)(EN_GSW_USB_SWITCH_TYPE type))dlsym(dlHandle, "gsw_usb_permanent_switch"); |
| if(gsw_usb_permanent_switch_demo == NULL) |
| { |
| printf("dlsym gsw_usb_permanent_switch_demo fail\n"); |
| return -1; |
| } |
| ret = gsw_usb_permanent_switch_demo(type); |
| if(ret) |
| { |
| printf("gsw_usb_permanent_switch_demo fail\n"); |
| } |
| else |
| { |
| printf("gsw_usb_permanent_switch_demo successful\n"); |
| } |
| } |
| else |
| { |
| gsw_usb_tempporary_switch_demo=(int32_t(*)(EN_GSW_USB_SWITCH_TYPE type))dlsym(dlHandle, "gsw_usb_tempporary_switch"); |
| if(gsw_usb_tempporary_switch_demo == NULL) |
| { |
| printf("dlsym gsw_usb_tempporary_switch_demo fail\n"); |
| return -1; |
| } |
| ret = gsw_usb_tempporary_switch_demo(type); |
| if(ret) |
| { |
| printf("gsw_usb_tempporary_switch_demo fail\n"); |
| } |
| else |
| { |
| printf("gsw_usb_tempporary_switch_demo successful\n"); |
| } |
| } |
| |
| |
| return 0; |
| } |