From cbffc8d64707828b045b679e8db0269ae362ffcf Mon Sep 17 00:00:00 2001 From: laforge Date: Mon, 23 Oct 2006 20:28:37 +0000 Subject: more gsmd/libgsm implementation git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@114 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/util/shell.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'src/util/shell.c') diff --git a/src/util/shell.c b/src/util/shell.c index 3b13bc9..77f0c57 100644 --- a/src/util/shell.c +++ b/src/util/shell.c @@ -1,30 +1,66 @@ #include #include +#include +#include #include #define STDIN_BUF_SIZE 1024 -int shell_main(struct lgsmd_handle *lgsmh) +/* this is the handler for receiving passthrough responses */ +static int pt_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) +{ + char *payload = (char *)gmh + sizeof(*gmh); + printf("RSTR=`%s'\n", payload); +} + +int shell_main(struct lgsm_handle *lgsmh) { int rc; char buf[STDIN_BUF_SIZE+1]; char rbuf[STDIN_BUF_SIZE+1]; int rlen = sizeof(rbuf); + fd_set readset; + + lgsm_register_handler(lgsmh, GSMD_MSG_PASSTHROUGH, &pt_msghandler); + + FD_ZERO(&readset); while (1) { - rc = fscanf(stdin, "%s", buf); - if (rc == EOF) { - printf("EOF\n"); - return -1; + fd_set readset; + int gsm_fd = lgsm_fd(lgsmh); + FD_SET(0, &readset); + FD_SET(gsm_fd, &readset); + + rc = select(gsm_fd+1, &readset, NULL, NULL, NULL); + if (rc <= 0) + break; + if (FD_ISSET(gsm_fd, &readset)) { + /* we've received something on the gsmd socket, pass it + * on to the library */ + rc = read(gsm_fd, buf, sizeof(buf)); + if (rc <= 0) { + printf("ERROR reding from gsm_fd\n"); + break; + } + rc = lgsm_handle_packet(lgsmh, buf, rc); } - if (rc <= 0) { - printf("NULL\n"); - continue; + if (FD_ISSET(0, &readset)) { + /* we've received something on stdin. send it as passthrough + * to gsmd */ + rc = fscanf(stdin, "%s", buf); + if (rc == EOF) { + printf("EOF\n"); + return -1; + } + if (rc <= 0) { + printf("NULL\n"); + continue; + } + printf("STR=`%s'\n", buf); } - printf("STR=`%s'\n", buf); + /* this is a synchronous call for a passthrough command */ lgsm_passthrough(lgsmh, buf, rbuf, &rlen); - printf("RSTR=`%s'\n", rbuf); } } -- cgit v1.2.3