Hello Rodrigo & OpenOCD comrades! Le jeudi 07 juillet 2011 à 14:55 -0700, Rodrigo Rosa a écrit :
> the c part of your code was very useful. i'm was the telnet port, and > ignoring the output i did not care about. > now with the gdb port i get: > - "0" for success > - "1" for fail > - a message "invalid command name ...." if the cmd name is invalid > - whatever the command would normally output to the telnet console > if i run "capture command_name \x1a" or "capture {command_name > command_arguments} \x1a". Nice to know this bit of code was useful to you! > regarding the tcl part: i don't know much about tcl, and i couldn't > get answers from you tcl script. > examples: > > mdh 0x0 > Sending "mdh 0x0" ... OK. > > asdsf > Sending "asdsf" ... OK. > > sdfsdf > Sending "sdfsdf" ... OK. > > sdfsd > Sending "sdfsd" ... OK. > > flash > Sending "flash" ... OK. > > capture flash > Sending "capture flash" ... OK. > > capture flash > Sending "capture flash" ... OK. > > capture asdfs > Sending "capture asdfs" ... OK. > > the debug console show the output from openocd (warnings, errors, etc) > but nothing on the tcl script. Fetching properly the server's response wasn't too much the focus of my original script, and so it did it badly :D. But with some fresh ideas from folks on the #tcl freenode channel, I came up with the following script, which seems to work very well! Non-blocking read & fileevent based, this is supposedly the optimal solution (and a bit overkill in this simple scenario). Give it a try, and feel free to report any problems. #!/usr/bin/tclsh8.5 # Simple tcl client to test OpenOCD tcl_server # # Original script idea by Charles Hardin # <http://lists.berlios.de/pipermail/openocd-development/2008-July/002368.html> # # Author: Maxim Cournoyer, 2011 # OpenOCD server settings set server localhost set port 6666 set EOC \x1a #--------------------------------------------------------------- proc get_reply { channelId EOC } { set LAST_CHAR "" set reply "" # Loop until we receive $EOC char while { [string compare $LAST_CHAR $EOC] } { if { [eof $channelId] || [catch {append line [read $channelId]}] } { close $channelId puts "\nConnection or server error." exit 1 } set LAST_CHAR [string index $line end] } # Server returns empty string (only EOC received) if OK. Longer output is # returned in case of wrong command name or if the user specified the command name # with the capture parameter, e.g.: capture { halt } if { [string equal $line $EOC] } { puts "OK." } else { set line "[string range $line 0 end-1]" puts "$line" } global done_flag set done_flag 1 } #--------------------------------------------------------------- puts "Use empty line to exit." # Open TCP socket set fo [socket $server $port] # Configure the channel in non-blocking mode fconfigure $fo -blocking 0 # Configure event driven read command fileevent $fo readable {get_reply $fo $EOC} puts -nonewline stdout "> " flush stdout while { [gets stdin line] > 0 } { puts -nonewline stdout "Sending \"$line\" ... " puts -nonewline $fo "$line$EOC" flush $fo # Event driven get_reply routine is being ran. vwait done_flag puts -nonewline stdout "> " flush stdout } close $fo exit 0
<<attachment: face-smile-big.png>>
_______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development