lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 1 | #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.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 9 | #include <include/lynq-qser-autosuspend.h> |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 10 | |
| 11 | DEFINE_LYNQ_LIB_LOG(LYNQ_AT_COMMON) |
| 12 | |
| 13 | lynq_atsvc_outcb handle_output; |
| 14 | typedef struct |
| 15 | { |
| 16 | char *cmd; |
| 17 | void (*func)(char *input); |
| 18 | }Command; |
| 19 | |
| 20 | enum |
| 21 | { |
| 22 | Response = 0, |
| 23 | Urc |
| 24 | }; |
| 25 | |
| 26 | void lynq_response_ok() |
| 27 | { |
lichengzhang | a252bb8 | 2023-10-14 00:22:02 -0700 | [diff] [blame] | 28 | char *str = "OK\r\n"; |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 29 | handle_output(str, strlen(str), Response); |
| 30 | } |
| 31 | |
| 32 | void lynq_response_error(int error_code) |
| 33 | { |
| 34 | char str[32] = {0}; |
lichengzhang | a252bb8 | 2023-10-14 00:22:02 -0700 | [diff] [blame] | 35 | sprintf(str, "+CME ERROR: %d\r\n", error_code); |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 36 | handle_output(str, strlen(str), Response); |
| 37 | } |
| 38 | |
| 39 | void lynq_handle_version() |
| 40 | { |
| 41 | char buf[64] = {0}; |
lichengzhang | a252bb8 | 2023-10-14 00:22:02 -0700 | [diff] [blame] | 42 | sprintf(buf,"+CGIR:%s\r\n",LYNQ_SW_INSIDE_VERSION); |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 43 | handle_output(buf, strlen(buf), Response); |
| 44 | lynq_response_ok(); |
| 45 | return; |
| 46 | } |
| 47 | |
jb.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 48 | void 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 | |
| 69 | static Command commands[] = |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 70 | { |
| 71 | {"CGIR",lynq_handle_version}, |
jb.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 72 | {"LEELSP",lynq_handle_autosuspend}, |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 73 | {NULL, NULL} |
| 74 | }; |
| 75 | |
| 76 | Command* 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 | |
| 94 | void 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 | |
| 120 | lynq_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.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 128 | } |