Fix gnss 8122 and IPC socket.
Change-Id: Id413efb4dd8df3e5a52333cc0c1400db7f84ad9f
diff --git a/mbtk/test/others/mbtk_gnss_cli.c b/mbtk/test/others/mbtk_gnss_cli.c
new file mode 100755
index 0000000..d830e0c
--- /dev/null
+++ b/mbtk/test/others/mbtk_gnss_cli.c
@@ -0,0 +1,140 @@
+/*
+* gnss_ipc.c
+*
+* MBTK GNSS IPC service source.
+*
+*/
+/******************************************************************************
+
+ EDIT HISTORY FOR FILE
+
+ WHEN WHO WHAT,WHERE,WHY
+-------- -------- -------------------------------------------------------
+2024/6/15 LiuBin Initial version
+
+******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <sys/epoll.h>
+
+#include "mbtk_log.h"
+#include "mbtk_type.h"
+
+#define GNSS_SOCK_PATH "/tmp/mbtk_gnss_sock"
+
+static int sock_listen_fd = -1;
+
+typedef enum {
+ GNSS_CMD_INIT = 0,
+ GNSS_CMD_DEINIT
+} gnss_cmd_enum;
+
+static void help()
+{
+ printf("gnss_cli gnss_init xxx\n");
+ printf("gnss_cli gnss_deinit\n");
+}
+
+static int cmd_process(gnss_cmd_enum cmd, void *arg)
+{
+ if(sock_listen_fd < 0) {
+ sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+ if(sock_listen_fd < 0)
+ {
+ printf("socket() fail[%d].\n", errno);
+ return -1;
+ }
+
+ struct sockaddr_un cli_addr;
+ memset(&cli_addr, 0, sizeof(cli_addr));
+ cli_addr.sun_family = AF_LOCAL;
+ strcpy(cli_addr.sun_path, GNSS_SOCK_PATH);
+ if(connect(sock_listen_fd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)))
+ {
+ printf("connect() fail[%d].\n", errno);
+ close(sock_listen_fd);
+ sock_listen_fd = -1;
+ return -1;
+ }
+ }
+
+ char buff[100] = {0};
+ if(cmd == GNSS_CMD_INIT) {
+ if(arg) {
+ int type = atoi((char*)arg);
+ sprintf(buff, "gnss_init:%d", type);
+ } else {
+ return -1;
+ }
+ } else if(cmd == GNSS_CMD_DEINIT) {
+ sprintf(buff, "gnss_deinit");
+ } else {
+ printf("Unknown cmd.\n");
+ return -1;
+ }
+
+ write(sock_listen_fd, buff, strlen(buff));
+
+ int len = 0;
+ while(1) {
+ memset(buff, 0, sizeof(buff));
+ len = read(sock_listen_fd, buff, sizeof(buff));
+ if(len > 0) {
+ printf("RSP : %s\n", buff);
+ if(cmd == GNSS_CMD_INIT) {
+ if(memcmp(buff, "gnss_init", 9) == 0) {
+ return atoi(buff + 10);
+ } else {
+ printf("gnss_init response error.\n");
+ return -1;
+ }
+ } else if(cmd == GNSS_CMD_DEINIT) {
+ if(memcmp(buff, "gnss_deinit", 11) == 0) {
+ return atoi(buff + 12);
+ } else {
+ printf("gnss_deinit response error.\n");
+ return -1;
+ }
+ } else {
+ printf("Unknown response.\n");
+ return -1;
+ }
+ } else {
+ printf("read = %d:errno = %d\n", len, errno);
+ }
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+ if(argc == 2) {
+ if(strcmp(argv[1], "gnss_deinit")) {
+ help();
+ return -1;
+ }
+
+ ret = cmd_process(GNSS_CMD_DEINIT, NULL);
+ } else if(argc == 3) {
+ if(strcmp(argv[1], "gnss_init")) {
+ help();
+ return -1;
+ }
+
+ ret = cmd_process(GNSS_CMD_INIT, argv[2]);
+ } else {
+ help();
+ return -1;
+ }
+
+ printf("Result : %d\n", ret);
+ return 0;
+}
+