blob: cacdf2d5abfd9a83874b68ce1ab594bae527a590 [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"
9
10DEFINE_LYNQ_LIB_LOG(LYNQ_AT_COMMON)
11
12lynq_atsvc_outcb handle_output;
13typedef struct
14{
15 char *cmd;
16 void (*func)(char *input);
17}Command;
18
19enum
20{
21 Response = 0,
22 Urc
23};
24
25void lynq_response_ok()
26{
27 char *str = "OK\n";
28 handle_output(str, strlen(str), Response);
29}
30
31void lynq_response_error(int error_code)
32{
33 char str[32] = {0};
34 sprintf(str, "+CME ERROR: %d\n", error_code);
35 handle_output(str, strlen(str), Response);
36}
37
38void lynq_handle_version()
39{
40 char buf[64] = {0};
41 sprintf(buf,"%s\n",LYNQ_SW_INSIDE_VERSION);
42 handle_output(buf, strlen(buf), Response);
43 lynq_response_ok();
44 return;
45}
46
47static Command commands[] =
48{
49 {"CGIR",lynq_handle_version},
50 {NULL, NULL}
51};
52
53Command* find_command(char *input)
54{
55 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
56 int i;
57 int ret = -1;
58 for (i = 0; commands[i].cmd; i++)
59 {
60 ret = strncmp(input, commands[i].cmd, strlen(commands[i].cmd));
61 if(ret == 0)
62 {
63 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);
64 return (&commands[i]);
65 }
66 }
67 ALOGD("function %s line %d not find ret %d \n", __FUNCTION__, __LINE__, ret);
68 return ((Command *)NULL);
69}
70
71void lynq_at_common_cb(char *input, int input_max_size)
72{
73 if(handle_output != NULL)
74 {
75 ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
76 if(input != NULL)
77 {
78 char *handle_string = input + strlen("AT+");
79 ALOGE("HJAHS:%s\n",handle_string);
80 if(!strlen(handle_string))
81 {
82 ALOGE("function %s line %d strlen %d\n", __FUNCTION__, __LINE__, strlen(handle_string));
83 return;
84 }
85 ALOGD("function %s line %d handle_string %s\n", __FUNCTION__, __LINE__, handle_string);
86 Command *cmd = find_command(handle_string);
87 if(cmd != NULL)
88 {
89 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
90 (*(cmd->func))(handle_string);
91 return;
92 }
93 }
94 }
95}
96
97lynq_atsvc_incb lynq_register_at_common(lynq_atsvc_outcb out_cb)
98{
99 if(out_cb != NULL)
100 {
101 handle_output = out_cb;
102 ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
103 return lynq_at_common_cb;
104 }
105}