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> |
rita | 6966c30 | 2024-01-09 10:50:18 +0800 | [diff] [blame] | 10 | #include <libled/lynq_led.h> |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 11 | |
| 12 | DEFINE_LYNQ_LIB_LOG(LYNQ_AT_COMMON) |
| 13 | |
| 14 | lynq_atsvc_outcb handle_output; |
| 15 | typedef struct |
| 16 | { |
| 17 | char *cmd; |
| 18 | void (*func)(char *input); |
| 19 | }Command; |
| 20 | |
| 21 | enum |
| 22 | { |
| 23 | Response = 0, |
| 24 | Urc |
| 25 | }; |
| 26 | |
| 27 | void lynq_response_ok() |
| 28 | { |
lichengzhang | a252bb8 | 2023-10-14 00:22:02 -0700 | [diff] [blame] | 29 | char *str = "OK\r\n"; |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 30 | handle_output(str, strlen(str), Response); |
| 31 | } |
| 32 | |
| 33 | void lynq_response_error(int error_code) |
| 34 | { |
| 35 | char str[32] = {0}; |
lichengzhang | a252bb8 | 2023-10-14 00:22:02 -0700 | [diff] [blame] | 36 | sprintf(str, "+CME ERROR: %d\r\n", error_code); |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 37 | handle_output(str, strlen(str), Response); |
| 38 | } |
| 39 | |
| 40 | void lynq_handle_version() |
| 41 | { |
| 42 | char buf[64] = {0}; |
lichengzhang | a252bb8 | 2023-10-14 00:22:02 -0700 | [diff] [blame] | 43 | sprintf(buf,"+CGIR:%s\r\n",LYNQ_SW_INSIDE_VERSION); |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 44 | handle_output(buf, strlen(buf), Response); |
| 45 | lynq_response_ok(); |
| 46 | return; |
| 47 | } |
| 48 | |
jb.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 49 | void 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.qi | 3763a82 | 2023-12-21 02:05:12 -0800 | [diff] [blame] | 56 | system("echo 0 >/sys/devices/platform/soc/1307000.gmac/gmac_power"); |
jb.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 57 | 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 | |
rita | 6966c30 | 2024-01-09 10:50:18 +0800 | [diff] [blame] | 71 | void 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 | |
| 92 | void 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.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 113 | static Command commands[] = |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 114 | { |
| 115 | {"CGIR",lynq_handle_version}, |
jb.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 116 | {"LEELSP",lynq_handle_autosuspend}, |
rita | 6966c30 | 2024-01-09 10:50:18 +0800 | [diff] [blame] | 117 | {"NETLED",lynq_handle_netled}, |
| 118 | {"STATUSLED",lynq_handle_statusled}, |
lichengzhang | 4509130 | 2023-10-08 02:10:34 -0700 | [diff] [blame] | 119 | {NULL, NULL} |
| 120 | }; |
| 121 | |
| 122 | Command* 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 | |
| 140 | void 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 | |
| 166 | lynq_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.qi | 539afe4 | 2023-11-23 01:52:18 -0800 | [diff] [blame] | 174 | } |