blob: 4806be3f7215f156e5e5cf0c3a91a4c5c254071a [file] [log] [blame]
b.liuc7ffd092024-01-03 15:23:07 +08001#include <unistd.h>
2
3#include <libubox/blobmsg_json.h>
4#include "libubus.h"
5#include "mbtk_audio.h"
6
7void receive_call_result_data(struct ubus_request *req, int type, struct blob_attr *msg)
8{
9 printf("receive_call_result_data()\n");
10 if (!msg)
11 return;
12
13 printf("len - %d,data - %s\n", msg->id_len, msg->data);
14}
15
16
17int main(int argc, char *argv[])
18{
19#if 1
20 if(argc != 3) {
21 printf("ubus_demo switch/mode 0/1/-2/2\n");
22 return -1;
23 }
24 char *type = NULL;
25 int value = atoi(argv[2]);
26 if(!strcmp(argv[1], "switch")) {
27 type = "switch_pcm";
28 if(value != 0 && value != 1) {
29 printf("ubus_demo switch/mode 0/1/-2/2\n");
30 return -1;
31 }
32 } else if(!strcmp(argv[1], "mode")) {
33 type = "audio_mode_set";
34 if(value != -2 && value != 2) {
35 printf("ubus_demo switch/mode 0/1/-2/2\n");
36 return -1;
37 }
38 } else {
39 printf("ubus_demo switch/mode 0/1/-2/2\n");
40 return -1;
41 }
42
43 static struct ubus_context *ctx;
44 ctx = ubus_connect(NULL);
45 if (!ctx) {
46 printf("Failed to connect to ubus\n");
47 return -1;
48 }
49
50 static struct blob_buf b;
51 uint32_t id;
52 int ret;
53 ret = ubus_lookup_id(ctx, "audio_if", &id);
54 if (ret) {
55 printf("ubus_lookup_id() fail.\n");
56 return ret;
57 }
58
59
60
61 blob_buf_init(&b, 0);
62 blobmsg_add_u32(&b, "param0", value);
63 if((ret = ubus_invoke(ctx, id, type, b.head, NULL/*receive_call_result_data*/, NULL, 0)) != UBUS_STATUS_OK) {
64 printf("ubus_invoke fail:%d.\n", ret);
65 } else {
66 printf("ubus_invoke success.\n");
67 }
68#else
69
70 int handler = 0;
71 mbtk_audio_ubus_client_init(&handler, NULL);
72
73 mbtk_audio_switch_pcm(1);
74 mbtk_audio_mode_set(2);
75
76#endif
77
78 return 0;
79}