blob: 110ad99c8689d5228ec7f5723aaa8704f474ae1b [file] [log] [blame]
b.liu68a94c92025-05-24 12:53:41 +08001#include <stdio.h>
2#include <string.h>
3#include <strings.h>
4#include <stdlib.h>
5#include <errno.h>
6#include <fcntl.h>
7#include <signal.h>
8#include <sys/types.h>
9#include <unistd.h>
10#include <pthread.h>
11#include <termios.h>
12#include <time.h>
13#include <sys/ioctl.h>
14#include <dlfcn.h>
15#include <stdint.h>
16#include <stdbool.h>
17
hong.liufe423492025-05-28 20:40:40 -070018#include "gsw_usb_interface.h"
b.liu68a94c92025-05-24 12:53:41 +080019
20int32_t (*gsw_usb_permanent_switch_demo)(EN_GSW_USB_SWITCH_TYPE type);
21int32_t (*gsw_usb_tempporary_switch_demo)(EN_GSW_USB_SWITCH_TYPE type);
22void *dlHandle;
23char *lynqLib = "/lib/libgsw_lib.so";
24
25int main(int argc, char *argv[])
26{
27 int ret;
28 EN_GSW_USB_SWITCH_TYPE type;
29 bool usb_change = false;
30 if(argc != 2)
31 {
32 printf("parameter error,please input open or close\n");
33 return -1;
34 }
35
36 if(strcmp(argv[0],"gsw_usb_test") == 0)
37 usb_change = true;
38 else
39 usb_change = false;
40 printf("usb is %s\n",argv[1]);
41 if(strcmp(argv[1],"open") == 0)
42 type = EN_GSW_USB_SWITCH_OPEN;
43 else if(strcmp(argv[1],"close") == 0)
44 type = EN_GSW_USB_SWITCH_CLOSE;
45 else
46 {
47 printf("parameter error,please input open or close\n");
48 return -1;
49 }
50 dlHandle = dlopen(lynqLib, RTLD_NOW);
51 if(dlHandle == NULL)
52 {
53 printf("dlopen libgsw_lib fail\n");
54 return -1;
55 }
56 if(usb_change)
57 {
58 gsw_usb_permanent_switch_demo=(int32_t(*)(EN_GSW_USB_SWITCH_TYPE type))dlsym(dlHandle, "gsw_usb_permanent_switch");
59 if(gsw_usb_permanent_switch_demo == NULL)
60 {
61 printf("dlsym gsw_usb_permanent_switch_demo fail\n");
62 return -1;
63 }
64 ret = gsw_usb_permanent_switch_demo(type);
65 if(ret)
66 {
67 printf("gsw_usb_permanent_switch_demo fail\n");
68 }
69 else
70 {
71 printf("gsw_usb_permanent_switch_demo successful\n");
72 }
73 }
74 else
75 {
76 gsw_usb_tempporary_switch_demo=(int32_t(*)(EN_GSW_USB_SWITCH_TYPE type))dlsym(dlHandle, "gsw_usb_tempporary_switch");
77 if(gsw_usb_tempporary_switch_demo == NULL)
78 {
79 printf("dlsym gsw_usb_tempporary_switch_demo fail\n");
80 return -1;
81 }
82 ret = gsw_usb_tempporary_switch_demo(type);
83 if(ret)
84 {
85 printf("gsw_usb_tempporary_switch_demo fail\n");
86 }
87 else
88 {
89 printf("gsw_usb_tempporary_switch_demo successful\n");
90 }
91 }
92
93
94 return 0;
95}