blob: 391d43c905ba03855013b33fe44c9f92cbbbd081 [file] [log] [blame]
lichengzhang45091302023-10-08 02:10:34 -07001#include <string.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <error.h>
5#include <string.h>
6#include <errno.h>
7#include <liblog/lynq_deflog.h>
8#include "include/liblynq-at-common.h"
jb.qi539afe42023-11-23 01:52:18 -08009#include <include/lynq-qser-autosuspend.h>
rita6966c302024-01-09 10:50:18 +080010#include <libled/lynq_led.h>
lichengzhang45091302023-10-08 02:10:34 -070011
12DEFINE_LYNQ_LIB_LOG(LYNQ_AT_COMMON)
13
14lynq_atsvc_outcb handle_output;
15typedef struct
16{
17 char *cmd;
18 void (*func)(char *input);
19}Command;
20
21enum
22{
23 Response = 0,
24 Urc
25};
26
27void lynq_response_ok()
28{
lichengzhanga252bb82023-10-14 00:22:02 -070029 char *str = "OK\r\n";
lichengzhang45091302023-10-08 02:10:34 -070030 handle_output(str, strlen(str), Response);
31}
32
33void lynq_response_error(int error_code)
34{
35 char str[32] = {0};
lichengzhanga252bb82023-10-14 00:22:02 -070036 sprintf(str, "+CME ERROR: %d\r\n", error_code);
lichengzhang45091302023-10-08 02:10:34 -070037 handle_output(str, strlen(str), Response);
38}
39
40void lynq_handle_version()
41{
42 char buf[64] = {0};
lichengzhanga252bb82023-10-14 00:22:02 -070043 sprintf(buf,"+CGIR:%s\r\n",LYNQ_SW_INSIDE_VERSION);
lichengzhang45091302023-10-08 02:10:34 -070044 handle_output(buf, strlen(buf), Response);
45 lynq_response_ok();
46 return;
47}
48
jb.qi539afe42023-11-23 01:52:18 -080049void lynq_handle_autosuspend(char* input)
50{
51 int len;
52 int ret;
53 char buf[64] = {0};
54 ALOGE("lynq_handle_autosuspend start\n");
55 len = strlen(input);
jb.qi3763a822023-12-21 02:05:12 -080056 system("echo 0 >/sys/devices/platform/soc/1307000.gmac/gmac_power");
jb.qi539afe42023-11-23 01:52:18 -080057 ret = qser_autosuspend_enable(input[len-1]);
58 if(ret != 0)
59 {
60 sprintf(buf,"+CME ERROR: 100\r\n");
61 handle_output(buf, strlen(buf), Response);
62 }
63 else
64 {
65 lynq_response_ok();
66 }
67
68 return;
69}
70
rita6966c302024-01-09 10:50:18 +080071void lynq_handle_netled(char* input)
72{
73 int ret;
74 char buf[64] = {0};
75 int mode = input[strlen(input)-1]-'0';
76 ALOGE("lynq_handle_netled start\n");
77
78 ret = lynq_set_netled_on(mode);
79 if(ret != 0)
80 {
81 sprintf(buf,"+CME ERROR: 100\r\n");
82 handle_output(buf, strlen(buf), Response);
83 }
84 else
85 {
86 lynq_response_ok();
87 }
88
89 return;
90}
91
92void lynq_handle_statusled(char* input)
93{
94 int ret;
95 char buf[64] = {0};
96 int mode = input[strlen(input)-1]-'0';
97
98 ALOGE("lynq_handle_statusled start\n");
99 ret = lynq_set_statusled_on(mode);
100
101 if(ret != 0)
102 {
103 sprintf(buf,"+CME ERROR: 100\r\n");
104 handle_output(buf, strlen(buf), Response);
105 }
106 else
107 {
108 lynq_response_ok();
109 }
110
111 return;
112}
jb.qi539afe42023-11-23 01:52:18 -0800113static Command commands[] =
lichengzhang45091302023-10-08 02:10:34 -0700114{
115 {"CGIR",lynq_handle_version},
jb.qi539afe42023-11-23 01:52:18 -0800116 {"LEELSP",lynq_handle_autosuspend},
rita6966c302024-01-09 10:50:18 +0800117 {"NETLED",lynq_handle_netled},
118 {"STATUSLED",lynq_handle_statusled},
lichengzhang45091302023-10-08 02:10:34 -0700119 {NULL, NULL}
120};
121
122Command* find_command(char *input)
123{
124 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
125 int i;
126 int ret = -1;
127 for (i = 0; commands[i].cmd; i++)
128 {
129 ret = strncmp(input, commands[i].cmd, strlen(commands[i].cmd));
130 if(ret == 0)
131 {
132 ALOGD("function %s line %d find input %s commands[i].cmd %s strlen %d ret %d\n", __FUNCTION__, __LINE__, input, commands[i].cmd, strlen(commands[i].cmd), ret);
133 return (&commands[i]);
134 }
135 }
136 ALOGD("function %s line %d not find ret %d \n", __FUNCTION__, __LINE__, ret);
137 return ((Command *)NULL);
138}
139
140void lynq_at_common_cb(char *input, int input_max_size)
141{
142 if(handle_output != NULL)
143 {
144 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
145 if(input != NULL)
146 {
147 char *handle_string = input + strlen("AT+");
148 ALOGE("HJAHS:%s\n",handle_string);
149 if(!strlen(handle_string))
150 {
151 ALOGE("function %s line %d strlen %d\n", __FUNCTION__, __LINE__, strlen(handle_string));
152 return;
153 }
154 ALOGD("function %s line %d handle_string %s\n", __FUNCTION__, __LINE__, handle_string);
155 Command *cmd = find_command(handle_string);
156 if(cmd != NULL)
157 {
158 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
159 (*(cmd->func))(handle_string);
160 return;
161 }
162 }
163 }
164}
165
166lynq_atsvc_incb lynq_register_at_common(lynq_atsvc_outcb out_cb)
167{
168 if(out_cb != NULL)
169 {
170 handle_output = out_cb;
171 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
172 return lynq_at_common_cb;
173 }
jb.qi539afe42023-11-23 01:52:18 -0800174}