Send commitlog mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r4135 - in developers/sean_chiang: . gsm-pm
      ([EMAIL PROTECTED])
   2. Re:r4135 - in developers/sean_chiang: . gsm-pm
      (Werner Almesberger)
   3. r4136 - developers/sean_chiang/gsm-pm
      ([EMAIL PROTECTED])
   4. r4137 - developers/sean_chiang/gsm-pm
      ([EMAIL PROTECTED])
--- Begin Message ---
Author: sean_chiang
Date: 2008-02-29 05:12:52 +0100 (Fri, 29 Feb 2008)
New Revision: 4135

Added:
   developers/sean_chiang/gsm-pm/
   developers/sean_chiang/gsm-pm/Makefile
   developers/sean_chiang/gsm-pm/gsm-pm.c
Log:
A wrapper for power control of GSM modem

Added: developers/sean_chiang/gsm-pm/Makefile
===================================================================
--- developers/sean_chiang/gsm-pm/Makefile      2008-02-29 03:14:45 UTC (rev 
4134)
+++ developers/sean_chiang/gsm-pm/Makefile      2008-02-29 04:12:52 UTC (rev 
4135)
@@ -0,0 +1,5 @@
+CC=arm-angstrom-linux-gnueabi-gcc
+all: 
+       $(CC) -o gsm-pm gsm-pm.c
+clean:
+       rm gsm-pm

Added: developers/sean_chiang/gsm-pm/gsm-pm.c
===================================================================
--- developers/sean_chiang/gsm-pm/gsm-pm.c      2008-02-29 03:14:45 UTC (rev 
4134)
+++ developers/sean_chiang/gsm-pm/gsm-pm.c      2008-02-29 04:12:52 UTC (rev 
4135)
@@ -0,0 +1,169 @@
+/* gsm-pm                                                                      
                                                                       
+ *
+ * (C) 2006-2007 by OpenMoko, Inc.
+ * Written by Sean Chiang <[EMAIL PROTECTED]>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */ 
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <termios.h>
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x)  (sizeof(x) / sizeof((x)[0]))
+#endif
+
+struct bdrt { 
+       int bps;
+       u_int32_t b;
+};     
+
+static struct bdrt bdrts[] = {
+       { 0, B0 },
+       { 9600, B9600 },
+       { 19200, B19200 },
+       { 38400, B38400 },
+       { 57600, B57600 },
+       { 115200, B115200 },
+       { 230400, B230400 },
+       { 460800, B460800 },
+       { 921600, B921600 },
+};     
+
+static int set_baudrate(int fd, int baudrate, int hwflow) 
+{
+       int i;
+       u_int32_t bd = 0;
+       struct termios ti;
+
+       for (i = 0; i < ARRAY_SIZE(bdrts); i++) {
+               if (bdrts[i].bps == baudrate)
+                       bd = bdrts[i].b;
+       }
+       if (bd == 0) {
+               printf("can't set Baud rate\n");        
+               exit(1);
+       }       
+
+       i = tcgetattr(fd, &ti);
+       if (i < 0) {
+               printf("can't get attr\n");     
+               exit(1);
+       }
+
+       i = cfsetispeed(&ti, B0);
+       if (i < 0) {
+               printf("can't set input baud rate to B0\n");    
+               exit(1);
+       }
+
+       i = cfsetospeed(&ti, bd);
+       if (i < 0) {
+               printf("can't set output baud rate");   
+               exit(1);
+       }
+
+       if (hwflow)
+               ti.c_cflag |= CRTSCTS;
+       else
+               ti.c_cflag &= ~CRTSCTS;
+
+       return tcsetattr(fd, 0, &ti);
+}      
+
+int main(int argc, char **argv) {
+
+       char *p_DL, *p_POW, *p_RES, *p_OPTS, *p_DEV;
+       char buf[128];
+       pid_t child;
+       int fd;
+
+       p_DL = getenv("GSM_DL");
+       p_POW = getenv("GSM_POW");
+       p_RES = getenv("GSM_RES");
+       p_OPTS = getenv("GSMD_OPTS");
+       p_DEV = getenv("GSM_DEV");
+
+       if ( p_DL ) {
+               sprintf(buf, "echo \"1\" > %s", p_DL);
+               system(buf);
+               sleep(1);
+       }
+
+       if ( p_POW ) {
+               sprintf(buf, "echo \"0\" > %s", p_POW);
+               system(buf);
+               sleep(1);
+               sprintf(buf, "echo \"1\" > %s", p_POW);
+               system(buf);
+               sleep(1);
+       }
+
+       if ( p_RES ) {
+               sprintf(buf, "echo \"1\" > %s", p_RES);
+               system(buf);
+               sleep(1);
+               sprintf(buf, "echo \"0\" > %s", p_RES);
+               system(buf);
+               sleep(2);
+       }
+
+       printf("Starting GSM daemon: \n");
+       
+       if ( p_OPTS && p_DEV ) {
+               
+               sprintf(buf, "start-stop-daemon -S -x /usr/sbin/gsmd -- gsmd -p 
%s %s >/tmp/gsm.log 2>&1", p_DEV,p_OPTS);
+               system(buf);
+       }
+       
+       {
+               wait();
+               printf("gsmd is killed\n");
+
+               // Send [EMAIL PROTECTED]
+               fd = open(p_DEV, O_RDWR);
+               if (fd < 0) {
+                       printf("can't open device %s", p_DEV);
+                       exit(1);
+               }  
+
+               if (set_baudrate(fd, 115200, 1) < 0) { 
+                       printf("can't set baudrate\n");
+                       exit(1);
+               }
+               
+               write(fd, "AT", 2);     
+               write(fd, " \r", 2);    
+               write(fd,"[EMAIL PROTECTED]", 7);
+               close(fd);
+               
+               sleep(1);
+
+               if ( p_POW ) {
+                       sprintf(buf, "echo \"0\" > %s", p_POW);
+                       system(buf);
+               }
+       }
+
+       exit(0);
+}




--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
> A wrapper for power control of GSM modem

Ah, nice ! 

> +             write(fd,"[EMAIL PROTECTED]", 7);

No \r at the end ?

Cheers, Werner



--- End Message ---
--- Begin Message ---
Author: sean_chiang
Date: 2008-02-29 09:41:52 +0100 (Fri, 29 Feb 2008)
New Revision: 4136

Modified:
   developers/sean_chiang/gsm-pm/gsm-pm.c
Log:
drain the uart before we send [EMAIL PROTECTED]

Modified: developers/sean_chiang/gsm-pm/gsm-pm.c
===================================================================
--- developers/sean_chiang/gsm-pm/gsm-pm.c      2008-02-29 04:12:52 UTC (rev 
4135)
+++ developers/sean_chiang/gsm-pm/gsm-pm.c      2008-02-29 08:41:52 UTC (rev 
4136)
@@ -91,6 +91,19 @@
        return tcsetattr(fd, 0, &ti);
 }      
 
+static void drain(int fd)
+{
+       int rc;
+       struct termios t;
+       rc = tcflush(fd, TCIOFLUSH);   
+       rc = tcgetattr(fd, &t);
+       printf("c_iflag = 0x%08x, c_oflag = 0x%08x, c_cflag = 0x%08x, c_lflag = 
0x%08x\n",
+                       t.c_iflag, t.c_oflag, t.c_cflag, t.c_lflag);
+       t.c_iflag = t.c_oflag = 0;     
+       cfmakeraw(&t);
+       rc = tcsetattr(fd, TCSANOW, &t);
+}
+
 int main(int argc, char **argv) {
 
        char *p_DL, *p_POW, *p_RES, *p_OPTS, *p_DEV;
@@ -151,14 +164,25 @@
                        printf("can't set baudrate\n");
                        exit(1);
                }
+
+               drain(fd);
                
-               write(fd, "AT", 2);     
-               write(fd, " \r", 2);    
-               write(fd,"[EMAIL PROTECTED]", 7);
+               if ( write(fd, "AT\r", 3) <= 0 ) {
+                       printf("1 error\n");
+                       exit(1);
+               }       
+               if ( write(fd, "AT\r", 3) <= 0 ) {
+                       printf("2 error\n");
+                       exit(1);
+               }       
+               if ( write(fd,"[EMAIL PROTECTED]", 8) <=0 ) {
+                       printf("3 error\n");
+                       exit(1);
+               }
                close(fd);
+
+               sleep(1);
                
-               sleep(1);
-
                if ( p_POW ) {
                        sprintf(buf, "echo \"0\" > %s", p_POW);
                        system(buf);




--- End Message ---
--- Begin Message ---
Author: sean_chiang
Date: 2008-02-29 10:14:50 +0100 (Fri, 29 Feb 2008)
New Revision: 4137

Modified:
   developers/sean_chiang/gsm-pm/gsm-pm.c
Log:
replace sprintf with snprintf

Modified: developers/sean_chiang/gsm-pm/gsm-pm.c
===================================================================
--- developers/sean_chiang/gsm-pm/gsm-pm.c      2008-02-29 08:41:52 UTC (rev 
4136)
+++ developers/sean_chiang/gsm-pm/gsm-pm.c      2008-02-29 09:14:50 UTC (rev 
4137)
@@ -118,25 +118,25 @@
        p_DEV = getenv("GSM_DEV");
 
        if ( p_DL ) {
-               sprintf(buf, "echo \"1\" > %s", p_DL);
+               snprintf(buf, sizeof(buf), "echo \"1\" > %s", p_DL);
                system(buf);
                sleep(1);
        }
 
        if ( p_POW ) {
-               sprintf(buf, "echo \"0\" > %s", p_POW);
+               snprintf(buf, sizeof(buf), "echo \"0\" > %s", p_POW);
                system(buf);
                sleep(1);
-               sprintf(buf, "echo \"1\" > %s", p_POW);
+               snprintf(buf, sizeof(buf), "echo \"1\" > %s", p_POW);
                system(buf);
                sleep(1);
        }
 
        if ( p_RES ) {
-               sprintf(buf, "echo \"1\" > %s", p_RES);
+               snprintf(buf, sizeof(buf), "echo \"1\" > %s", p_RES);
                system(buf);
                sleep(1);
-               sprintf(buf, "echo \"0\" > %s", p_RES);
+               snprintf(buf, sizeof(buf), "echo \"0\" > %s", p_RES);
                system(buf);
                sleep(2);
        }
@@ -145,7 +145,7 @@
        
        if ( p_OPTS && p_DEV ) {
                
-               sprintf(buf, "start-stop-daemon -S -x /usr/sbin/gsmd -- gsmd -p 
%s %s >/tmp/gsm.log 2>&1", p_DEV,p_OPTS);
+               snprintf(buf, sizeof(buf), "start-stop-daemon -S -x 
/usr/sbin/gsmd -- gsmd -p %s %s >/tmp/gsm.log 2>&1", p_DEV,p_OPTS);
                system(buf);
        }
        
@@ -166,6 +166,8 @@
                }
 
                drain(fd);
+
+               sleep(1);
                
                if ( write(fd, "AT\r", 3) <= 0 ) {
                        printf("1 error\n");
@@ -184,7 +186,7 @@
                sleep(1);
                
                if ( p_POW ) {
-                       sprintf(buf, "echo \"0\" > %s", p_POW);
+                       snprintf(buf, sizeof(buf), "echo \"0\" > %s", p_POW);
                        system(buf);
                }
        }




--- End Message ---
_______________________________________________
commitlog mailing list
[email protected]
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to