Applied Andy Herkey's new modemtest.rb script to contrib/
[barry.git] / contrib / modemtest.rb
blobaaee1c4c4d77467afa3c0b7057e88db63cc6a166
1 #!/usr/bin/env ruby
3 #Change the $PPP variable to point to where pppob is installed.
4 $PPP="/usr/local/sbin/pppob -vP xxxxx -l /tmp/modemtest.log"
6 class IPmodem
8    def initialize
9       @connecting = true
10       @connectionHandle = IO.popen( $PPP,"w+" )
11       sleep 2
12       authAtempts = 0
13       timeout = 0
14    end
16    def write( data )
17       @connectionHandle.write( data ) 
18    end
20    def read()
21       timeout = 0
22       return nil if @connectionHandle.closed?
23          @ioBuffer = ""
24          while input = IO.select([@connectionHandle],nil,nil,1)
25             c = @connectionHandle.getc
26             @ioBuffer <<  c if c != nil
27             return if ! @connecting
28             if c == nil
29                timeout+=1
30                break if timeout >= 9000
31             else
32                timeout = 0
33             end
34          end
35       return @ioBuffer
36    end
37 end
39 commands = [
40         "+++AT",
41         "AT",
42         "AT&F",
43         "ATZ",
44         "ATS0=0",
45         "ATE0",
46         "ATE0V1",
47         "ATE0V1Q0X4",
48         "AT+CRC=1",
49         "AT+SPSERVICE",
50         "AT+SPSERVICE",
51         "AT$QCMIPP?",
52         "AT$QCMIPP=?",
53         "AT+CSQ",
54         "AT+CSQ?",
55         "AT+CSQ=?",
56         "AT+CSS",
57         "AT+CSS?",
58         "AT+CSS=?",
59         "ATI1",
60         "ATI2",
61         "ATI3",
62         "AT+CAD?",
63         "AT+CIMI",
64         "AT+CGMI",
65         "AT+CGMR",
66         "AT+CGDCONT?",
67         "AT+GMI",
68         "AT+GMM",
69         "AT+GMR",
70         "AT+GSN",
71         "AT+CBC",
72         "AT+CBIP",
73         "AT+CCED?",
74         "AT+ESR",
75         "AT+CIND=?",
76         "AT+FCLASS=?",
77         "AT+GCAP=?",
78         "AT$SPMDN?",
79         "AT$QCMIPGETP=1",
80         "AT&V",
81         "ATH"
84 modem = IPmodem.new
85 puts("Testing the Blackberry Modem by sending AT commands through pppob.") 
86 printf("Starting %s: %s",$PPP,modem.read())
87 puts("--------------------------------------------")
89 commands.each {|c|
90          modem.write(c+"\r")
91          printf("Command: %s \nResult: %s",c,modem.read())
92          puts("--------------------------------------------")
94          }