Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4515 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69928 invoked by uid 1010); 17 Sep 2003 19:11:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 69904 invoked from network); 17 Sep 2003 19:11:20 -0000 Received: from unknown (HELO tomts8-srv.bellnexxia.net) (209.226.175.52) by pb1.pair.com with SMTP; 17 Sep 2003 19:11:20 -0000 Received: from gregmaclellan.com ([67.69.108.23]) by tomts8-srv.bellnexxia.net (InterMail vM.5.01.06.04 201-253-122-130-104-20030726) with ESMTP id <20030917191119.TPTS719.tomts8-srv.bellnexxia.net@gregmaclellan.com> for ; Wed, 17 Sep 2003 15:11:19 -0400 Message-ID: <3F68B1D7.2090008@gregmaclellan.com> Date: Wed, 17 Sep 2003 15:11:19 -0400 Reply-To: greg@gregmaclellan.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------060307010201090401000805" Subject: PATCH: get modem status (direct io) From: greg@gregmaclellan.com (Greg MacLellan) --------------060307010201090401000805 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Quick patch to add a function dio_modemget() to the DirectIO extension. Does an ioctl(TIOCMGET) to get the status of the modem control lines. array dio_modemget(fd descriptor) Returns an array with elements "dsr", "cts", etc equal to 1 or 0. Example output: array(6) { ["dsr"]=> int(0) ["cts"]=> int(0) ["dcd"]=> int(0) ["ri"]=> int(0) ["rts"]=> int(1) ["dtr"]=> int(1) } I wrote this for a script that checks the status of a UPS (which is provided on the serial control lines). A test script is also attached. Btw, this is my first attempt at both working on PHP itself, and submitting a patch. If anything here is wrong, let me know! :p ttyl, greg -- Greg MacLellan --------------060307010201090401000805 Content-Type: text/plain; name="dio_modemget.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="dio_modemget.patch.txt" ? autom4te-2.53.cache ? dio_modemget.patch ? dio_modemget.patch.2 Index: ext/dio/dio.c =================================================================== RCS file: /repository/php-src/ext/dio/dio.c,v retrieving revision 1.21.2.3 diff -u -r1.21.2.3 dio.c --- ext/dio/dio.c 7 Mar 2003 13:42:11 -0000 1.21.2.3 +++ ext/dio/dio.c 15 Sep 2003 22:56:07 -0000 @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,7 @@ PHP_FE(dio_write, NULL) PHP_FE(dio_close, NULL) PHP_FE(dio_tcsetattr, NULL) + PHP_FE(dio_modemget, NULL) {NULL, NULL, NULL} }; @@ -54,7 +56,7 @@ dio_functions, PHP_MINIT(dio), NULL, - NULL, + NULL, NULL, PHP_MINFO(dio), "0.1", @@ -592,6 +594,37 @@ zend_list_delete(Z_LVAL_P(r_fd)); } /* }}} */ + + +/* {{{ proto array dio_modemget(resource fd) + Get modem bit status for the file descriptor fd */ +PHP_FUNCTION(dio_modemget) +{ + zval *r_fd; + php_fd_t *f; + int status; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &r_fd) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd); + + if (ioctl(f->fd, TIOCMGET, &status) == -1) { + php_error(E_WARNING, "%s(): cannot ioctl(TIOCMGET) %d: %s", + get_active_function_name(TSRMLS_C), f->fd, strerror(errno)); + RETURN_FALSE; + } + + array_init(return_value); + ADD_FIELD("dsr", (TIOCM_DSR & status) == TIOCM_DSR); + ADD_FIELD("cts", (TIOCM_CTS & status) == TIOCM_CTS); + ADD_FIELD("dcd", (TIOCM_CAR & status) == TIOCM_CAR); + ADD_FIELD("ri", (TIOCM_RNG & status) == TIOCM_RNG); + ADD_FIELD("rts", (TIOCM_RTS & status) == TIOCM_RTS); + ADD_FIELD("dtr", (TIOCM_DTR & status) == TIOCM_DTR); +} +/* }}} */ + /* * Local variables: Index: ext/dio/php_dio.h =================================================================== RCS file: /repository/php-src/ext/dio/php_dio.h,v retrieving revision 1.4.4.1 diff -u -r1.4.4.1 php_dio.h --- ext/dio/php_dio.h 31 Dec 2002 16:34:25 -0000 1.4.4.1 +++ ext/dio/php_dio.h 15 Sep 2003 22:56:07 -0000 @@ -45,6 +45,7 @@ PHP_FUNCTION(dio_fcntl); PHP_FUNCTION(dio_close); PHP_FUNCTION(dio_tcsetattr); +PHP_FUNCTION(dio_modemget); typedef struct { int fd; --------------060307010201090401000805 Content-Type: text/plain; name="upscheck" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="upscheck" #!/usr/bin/php --------------060307010201090401000805--