OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [lib/] [kermit.exp] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 92, 93, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-dejagnu@prep.ai.mit.edu
19
 
20
#
21
# Connect to DEST using kermit. Note that we're just using kermit as a
22
# simple serial or network connect program; we don't actually use Kermit
23
# protocol to do downloads.
24
#     returns -1 if it failed, otherwise it returns
25
#         the spawn_id.
26
#
27
proc kermit_open { dest args } {
28
    global spawn_id
29
    global board_info
30
 
31
    if [board_info $dest exists name] {
32
        set dest [board_info $dest name];
33
    }
34
    if [board_info ${dest} exists serial] {
35
        set port [board_info ${dest} serial];
36
        set device "-l [board_info ${dest} serial]"
37
        if [board_info ${dest} exists baud] {
38
            append device " -b [board_info ${dest} baud]"
39
        }
40
    } else {
41
        set port [board_info ${dest} netport];
42
        set device "-j [board_info ${dest} netport]";
43
    }
44
 
45
    set tries 0
46
    set result -1
47
    verbose "kermit $device"
48
    eval spawn kermit $device
49
    if { $spawn_id < 0 } {
50
        perror "invalid spawn id from kermit"
51
        return -1
52
    }
53
 
54
    expect {
55
        -re ".*ermit.*>.*$" {
56
            send "c\n"
57
            expect {
58
                -re "Connecting to.*$port.*Type the escape character followed by C to.*options.*\[\r\n\]$" {
59
                    verbose "Got prompt\n"
60
                    set result 0
61
                    incr tries
62
                }
63
                timeout {
64
                    warning "Never got prompt from Kermit."
65
                    set result -1
66
                    incr tries
67
                    if { $tries <= 2 } {
68
                        exp_continue
69
                    }
70
                }
71
            }
72
        }
73
        -re "Connection Closed.*$" {
74
            perror "Never connected."
75
            set result -1
76
            incr tries
77
            if { $tries <= 2 } {
78
                exp_continue
79
            }
80
        }
81
        timeout                 {
82
            warning "Timed out trying to connect."
83
            set result -1
84
            incr tries
85
            if { $tries<=2 } {
86
                exp_continue
87
            }
88
        }
89
    }
90
 
91
    if { $result < 0 } {
92
        perror "Couldn't connect after $tries tries."
93
        if [info exists board_info($dest,fileid)] {
94
            unset board_info($dest,fileid);
95
        }
96
        return -1
97
    } else {
98
        verbose "Kermit connection established with spawn_id $spawn_id."
99
        set board_info($dest,fileid) $spawn_id
100
        kermit_command $dest "set file type binary" "set transfer display none"
101
        if [board_info $dest exists transmit_pause] {
102
            kermit_command $dest "set transmit pause [board_info $dest transmit_pause]"
103
        }
104
        return $spawn_id
105
    }
106
}
107
 
108
#
109
# Send a list of commands to the Kermit session connected to DEST.
110
#
111
proc kermit_command { dest args } {
112
    if [board_info $dest exists name] {
113
        set dest [board_info $dest name];
114
    }
115
    set shell_id [board_info $dest fileid];
116
    # Sometimes we have to send multiple ^\c sequences. Don't know
117
    # why.
118
    set timeout 2;
119
    for { set i 1; } {$i<=5} {incr i} {
120
        send -i $shell_id "c";
121
        expect {
122
            -i $shell_id -re ".*Back at.*ermit.*>.*$" { set i 10;}
123
            -i $shell_id timeout {
124
                if { $i > 2 } {
125
                    warning "Unable to get prompt from kermit.";
126
                }
127
            }
128
        }
129
    }
130
    foreach command $args {
131
        set timeout 120
132
        send -i $shell_id "${command}\r";
133
        expect {
134
            -i $shell_id -re ".*ermit.*>.*$" { }
135
            -i $shell_id timeout {
136
                perror "Response failed from kermit.";
137
                return -1;
138
            }
139
        }
140
    }
141
    send -i $shell_id "c\r";
142
    expect {
143
        -i $shell_id -re ".*other options.\[\r\n\]+" { }
144
        -i $shell_id timeout {
145
            perror "Unable to resume kermit connection.";
146
            return -1;
147
        }
148
    }
149
    return 0;
150
}
151
 
152
 
153
#
154
# Send STRING to DEST.
155
#
156
proc kermit_send { dest string args } {
157
    if [board_info $dest exists transmit_pause] {
158
        set f [open "/tmp/fff" "w"];
159
        puts -nonewline $f "$string";
160
        close $f;
161
        set result [remote_transmit $dest /tmp/fff];
162
        remote_file build delete "/tmp/fff";
163
        return "$result";
164
    } else {
165
        return [standard_send $dest $string];
166
    }
167
}
168
 
169
#
170
# Transmit FILE directly to DEST as raw data. No translation is
171
# performed.
172
#
173
proc kermit_transmit { dest file args } {
174
    if [board_info $dest exists transmit_pause] {
175
        kermit_command $dest "transmit $file";
176
        return "";
177
    } else {
178
        return [standard_transmit $dest $file];
179
    }
180
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.