/
core.tcl
55 lines (49 loc) · 1.48 KB
/
core.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace eval expectnmcu::core {
}
# Establish a serial connection to the device via socat
proc ::expectnmcu::core::connect { dev baud } {
spawn "socat" "STDIO" "${dev},b${baud},rawer,crnl"
close -onexec 1 -i ${spawn_id}
return ${spawn_id}
}
# Use DTR/RTS signaling to reboot the device
## I'm not sure why we have to keep resetting the mode, but so it goes.
proc ::expectnmcu::core::reboot { dev baud } {
set victimfd [open "${dev}"]
fconfigure ${victimfd} -mode ${baud},n,8,1 -ttycontrol {DTR 0 RTS 1}
sleep 0.1
fconfigure ${victimfd} -mode ${baud},n,8,1 -ttycontrol {DTR 0 RTS 0}
close ${victimfd}
}
proc ::expectnmcu::core::waitboot { victim } {
expect {
-i ${victim} "Formatting file system" {
set timeout 60
exp_continue
}
-i ${victim} "powered by Lua" { }
timeout { return -code error "Timeout" }
}
# Catch nwf's system bootup, in case we're testing an existing system,
# rather than a blank firmware.
expect {
-i ${victim} "Reset delay!" { send "got:stop()\n" ; expect "> " }
-i ${victim} "> " { }
timeout { return -code error "Timeout" }
}
}
proc ::expectnmcu::core::send_exp_prompt { sid cmd } {
send -i ${sid} -- "${cmd}\n"
expect {
-i ${sid} -ex "\n> " { }
timeout { return -code error "Timeout" }
}
}
proc ::expectnmcu::core::send_exp_prompt_c { sid cmd } {
send -i ${sid} -- "${cmd}\n"
expect {
-i ${sid} -ex "\n>> " { }
timeout { return -code error "Timeout" }
}
}
package provide expectnmcu::core 1.0