blob: 0161a3f386e07c7dae45ff090fdeb64f2d6e90ba [file] [log] [blame]
r.xiaoab6f4ec2024-12-19 03:42:17 -08001#if 1
2#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5#include <unistd.h>
6#include <errno.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10#include <sys/socket.h>
11#include <sys/un.h>
12#include <netinet/in.h>
13#include <sys/epoll.h>
14#include <time.h>
15#include <arpa/inet.h>
16
17#include "mbtk_log.h"
18#include "mbtk_utils.h"
19#include "mbtk_led_control.h"
20
21
22#define LED_SOCK_PATH "/tmp/mbtk_led_sock"
23
24static int led_cli_fd = -1;
25
26int mbtk_led_contril_init()
27{
28 if(led_cli_fd > 0) {
29 LOGW("led_contril client has inited.");
30 return 0;
31 }
32
33 led_cli_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
34 if(led_cli_fd < 0)
35 {
36 LOGE("socket() fail[%d].", errno);
37 goto error;
38 }
39
40 struct sockaddr_un cli_addr;
41 memset(&cli_addr, 0, sizeof(cli_addr));
42 cli_addr.sun_family = AF_LOCAL;
43 strcpy(cli_addr.sun_path, LED_SOCK_PATH);
44 if(connect(led_cli_fd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)))
45 {
46 LOGE("connect() fail[%d].", errno);
47 goto error;
48 }
49
50 return 0;
51error:
52 if(led_cli_fd > 0) {
53 close(led_cli_fd);
54 led_cli_fd = -1;
55 }
56
57 return -1;
58}
59
60int mbtk_led_send(char *data)
61{
62 int ret = mbtk_led_contril_init();
63 if (ret == -1)
64 {
65 LOGE("mbtk_led_contril_init error");
66 return -1;
67 }
68 //LOGI("data %s",data);
69 mbtk_write(led_cli_fd, data, strlen(data)+1);
70
71 return 0;
72}
73
74int mbtk_led_set(led_info_s led_info)
75{
76 char resp_buf[4];
77 int type,status,ret;
78
79 memset(resp_buf,0,4);
80 type = led_info.led_type;
81 status = led_info.status;
82 sprintf(resp_buf, "%d,%d",type,status);
83 ret = mbtk_led_send(resp_buf);
84 if (ret)
85 {
86 LOGE("[led]mbtk_led_set error");
87 }
88
89 return ret;
90}
91
92#endif
93
94