[Feature][ZXW-116] add AT-common code
Only Configure:No
Affected branch:master
Affected module:AT
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: Yes
Change-Id: If1959f30300651421feab53af8820d05967056c8
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-at-common/liblynq-at-common.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-at-common/liblynq-at-common.cpp
new file mode 100755
index 0000000..cacdf2d
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-at-common/liblynq-at-common.cpp
@@ -0,0 +1,105 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <error.h>
+#include <string.h>
+#include <errno.h>
+#include <liblog/lynq_deflog.h>
+#include "include/liblynq-at-common.h"
+
+DEFINE_LYNQ_LIB_LOG(LYNQ_AT_COMMON)
+
+lynq_atsvc_outcb handle_output;
+typedef struct
+{
+ char *cmd;
+ void (*func)(char *input);
+}Command;
+
+enum
+{
+ Response = 0,
+ Urc
+};
+
+void lynq_response_ok()
+{
+ char *str = "OK\n";
+ handle_output(str, strlen(str), Response);
+}
+
+void lynq_response_error(int error_code)
+{
+ char str[32] = {0};
+ sprintf(str, "+CME ERROR: %d\n", error_code);
+ handle_output(str, strlen(str), Response);
+}
+
+void lynq_handle_version()
+{
+ char buf[64] = {0};
+ sprintf(buf,"%s\n",LYNQ_SW_INSIDE_VERSION);
+ handle_output(buf, strlen(buf), Response);
+ lynq_response_ok();
+ return;
+}
+
+static Command commands[] =
+{
+ {"CGIR",lynq_handle_version},
+ {NULL, NULL}
+};
+
+Command* find_command(char *input)
+{
+ ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
+ int i;
+ int ret = -1;
+ for (i = 0; commands[i].cmd; i++)
+ {
+ ret = strncmp(input, commands[i].cmd, strlen(commands[i].cmd));
+ if(ret == 0)
+ {
+ 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);
+ return (&commands[i]);
+ }
+ }
+ ALOGD("function %s line %d not find ret %d \n", __FUNCTION__, __LINE__, ret);
+ return ((Command *)NULL);
+}
+
+void lynq_at_common_cb(char *input, int input_max_size)
+{
+ if(handle_output != NULL)
+ {
+ ALOGD("function %s line %d input %s\n", __FUNCTION__, __LINE__, input);
+ if(input != NULL)
+ {
+ char *handle_string = input + strlen("AT+");
+ ALOGE("HJAHS:%s\n",handle_string);
+ if(!strlen(handle_string))
+ {
+ ALOGE("function %s line %d strlen %d\n", __FUNCTION__, __LINE__, strlen(handle_string));
+ return;
+ }
+ ALOGD("function %s line %d handle_string %s\n", __FUNCTION__, __LINE__, handle_string);
+ Command *cmd = find_command(handle_string);
+ if(cmd != NULL)
+ {
+ ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
+ (*(cmd->func))(handle_string);
+ return;
+ }
+ }
+ }
+}
+
+lynq_atsvc_incb lynq_register_at_common(lynq_atsvc_outcb out_cb)
+{
+ if(out_cb != NULL)
+ {
+ handle_output = out_cb;
+ ALOGD("function %s line %d\n", __FUNCTION__, __LINE__);
+ return lynq_at_common_cb;
+ }
+}
\ No newline at end of file