blob: c8accebf7dfe72da18fc22d10690fa3f9b544077 [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);
55 ret = qser_autosuspend_enable(input[len-1]);
56 if(ret != 0)
57 {
58 sprintf(buf,"+CME ERROR: 100\r\n");
59 handle_output(buf, strlen(buf), Response);
60 }
61 else
62 {
63 lynq_response_ok();
64 }
65
66 return;
67}
68
69static Command commands[] =
lichengzhang45091302023-10-08 02:10:34 -070070{
71 {"CGIR",lynq_handle_version},
jb.qi539afe42023-11-23 01:52:18 -080072 {"LEELSP",lynq_handle_autosuspend},
lichengzhang45091302023-10-08 02:10:34 -070073 {NULL, NULL}
74};
75
76Command* find_command(char *input)
77{
78 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
79 int i;
80 int ret = -1;
81 for (i = 0; commands[i].cmd; i++)
82 {
83 ret = strncmp(input, commands[i].cmd, strlen(commands[i].cmd));
84 if(ret == 0)
85 {
86 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);
87 return (&commands[i]);
88 }
89 }
90 ALOGD("function %s line %d not find ret %d \n", __FUNCTION__, __LINE__, ret);
91 return ((Command *)NULL);
92}
93
94void lynq_at_common_cb(char *input, int input_max_size)
95{
96 if(handle_output != NULL)
97 {
98 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
99 if(input != NULL)
100 {
101 char *handle_string = input + strlen("AT+");
102 ALOGE("HJAHS:%s\n",handle_string);
103 if(!strlen(handle_string))
104 {
105 ALOGE("function %s line %d strlen %d\n", __FUNCTION__, __LINE__, strlen(handle_string));
106 return;
107 }
108 ALOGD("function %s line %d handle_string %s\n", __FUNCTION__, __LINE__, handle_string);
109 Command *cmd = find_command(handle_string);
110 if(cmd != NULL)
111 {
112 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
113 (*(cmd->func))(handle_string);
114 return;
115 }
116 }
117 }
118}
119
120lynq_atsvc_incb lynq_register_at_common(lynq_atsvc_outcb out_cb)
121{
122 if(out_cb != NULL)
123 {
124 handle_output = out_cb;
125 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
126 return lynq_at_common_cb;
127 }
jb.qi539afe42023-11-23 01:52:18 -0800128}