blob: 7a8fc43a3023f21ec9a793500d067e2647fce951 [file] [log] [blame]
b.liu9bcf4932024-02-06 17:17:43 +08001#include <stdio.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <signal.h>
5#include <fcntl.h>
b.liu9e8584b2024-11-06 19:21:28 +08006#include <string.h>
b.liu9bcf4932024-02-06 17:17:43 +08007
8#include "mbtk_utils.h"
9
10static int running = 0;
11
12static void sig_handler(int sig)
13{
14 printf("Signal : %d\n", sig);
15 running = 0;
16}
17
18
19int main(int argc, char *argv[])
20{
b.liub3b923a2024-06-06 15:15:49 +080021 int fd = open("/tmp/usb.info", O_CREAT | O_WRONLY, 0666);
b.liu9bcf4932024-02-06 17:17:43 +080022 signal(SIGINT, sig_handler);
23 signal(SIGTERM, sig_handler);
24 if(fd > 0) {
25 char buff[1024];
26 running = 1;
27 while(running){
28 memset(buff, 0, 1024);
29 if(mbtk_cmd_line("cat /sys/class/android_usb/android0/state", buff, 1024)) {
b.liu9e8584b2024-11-06 19:21:28 +080030 mbtk_write(fd, buff, strlen(buff));
31 mbtk_write(fd, "\n", 1);
b.liu9bcf4932024-02-06 17:17:43 +080032 }
33 sleep(1);
34 }
35 close(fd);
36 }
37 return 0;
38}
39