blob: ea38faf2ac27833fa85dca31a05496f13ebbe7ea [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>
lichengzhang45091302023-10-08 02:10:34 -070010
11DEFINE_LYNQ_LIB_LOG(LYNQ_AT_COMMON)
12
13lynq_atsvc_outcb handle_output;
14typedef struct
15{
16 char *cmd;
17 void (*func)(char *input);
18}Command;
19
20enum
21{
22 Response = 0,
23 Urc
24};
25
26void lynq_response_ok()
27{
lichengzhanga252bb82023-10-14 00:22:02 -070028 char *str = "OK\r\n";
lichengzhang45091302023-10-08 02:10:34 -070029 handle_output(str, strlen(str), Response);
30}
31
32void lynq_response_error(int error_code)
33{
34 char str[32] = {0};
lichengzhanga252bb82023-10-14 00:22:02 -070035 sprintf(str, "+CME ERROR: %d\r\n", error_code);
lichengzhang45091302023-10-08 02:10:34 -070036 handle_output(str, strlen(str), Response);
37}
38
39void lynq_handle_version()
40{
41 char buf[64] = {0};
lichengzhanga252bb82023-10-14 00:22:02 -070042 sprintf(buf,"+CGIR:%s\r\n",LYNQ_SW_INSIDE_VERSION);
lichengzhang45091302023-10-08 02:10:34 -070043 handle_output(buf, strlen(buf), Response);
44 lynq_response_ok();
45 return;
46}
47
jb.qi539afe42023-11-23 01:52:18 -080048void lynq_handle_autosuspend(char* input)
49{
50 int len;
51 int ret;
52 char buf[64] = {0};
53 ALOGE("lynq_handle_autosuspend start\n");
54 len = strlen(input);
jb.qi3763a822023-12-21 02:05:12 -080055 system("echo 0 >/sys/devices/platform/soc/1307000.gmac/gmac_power");
jb.qi539afe42023-11-23 01:52:18 -080056 ret = qser_autosuspend_enable(input[len-1]);
57 if(ret != 0)
58 {
59 sprintf(buf,"+CME ERROR: 100\r\n");
60 handle_output(buf, strlen(buf), Response);
61 }
62 else
63 {
64 lynq_response_ok();
65 }
66
67 return;
68}
69
70static Command commands[] =
lichengzhang45091302023-10-08 02:10:34 -070071{
72 {"CGIR",lynq_handle_version},
jb.qi539afe42023-11-23 01:52:18 -080073 {"LEELSP",lynq_handle_autosuspend},
lichengzhang45091302023-10-08 02:10:34 -070074 {NULL, NULL}
75};
76
77Command* find_command(char *input)
78{
79 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
80 int i;
81 int ret = -1;
82 for (i = 0; commands[i].cmd; i++)
83 {
84 ret = strncmp(input, commands[i].cmd, strlen(commands[i].cmd));
85 if(ret == 0)
86 {
87 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);
88 return (&commands[i]);
89 }
90 }
91 ALOGD("function %s line %d not find ret %d \n", __FUNCTION__, __LINE__, ret);
92 return ((Command *)NULL);
93}
94
95void lynq_at_common_cb(char *input, int input_max_size)
96{
97 if(handle_output != NULL)
98 {
99 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
100 if(input != NULL)
101 {
102 char *handle_string = input + strlen("AT+");
103 ALOGE("HJAHS:%s\n",handle_string);
104 if(!strlen(handle_string))
105 {
106 ALOGE("function %s line %d strlen %d\n", __FUNCTION__, __LINE__, strlen(handle_string));
107 return;
108 }
109 ALOGD("function %s line %d handle_string %s\n", __FUNCTION__, __LINE__, handle_string);
110 Command *cmd = find_command(handle_string);
111 if(cmd != NULL)
112 {
113 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
114 (*(cmd->func))(handle_string);
115 return;
116 }
117 }
118 }
119}
120
121lynq_atsvc_incb lynq_register_at_common(lynq_atsvc_outcb out_cb)
122{
123 if(out_cb != NULL)
124 {
125 handle_output = out_cb;
126 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
127 return lynq_at_common_cb;
128 }
jb.qi539afe42023-11-23 01:52:18 -0800129}