|
|
|
@ -23,9 +23,14 @@ |
|
|
|
|
(fn escape-readably [s] |
|
|
|
|
(s:gsub "%c" (fn [x] (string.format "\\u{%.3x}" (string.byte x))))) |
|
|
|
|
|
|
|
|
|
(fn log-xfer [direction message] |
|
|
|
|
(when _G.modem-spew |
|
|
|
|
(_G.modem-spew:write direction " " (escape-readably message) "\n")) |
|
|
|
|
message) |
|
|
|
|
|
|
|
|
|
(fn tx [fd s] |
|
|
|
|
(write fd s) |
|
|
|
|
(print (.. ">>> " (escape-readably s))) |
|
|
|
|
(log-xfer :>>> s) |
|
|
|
|
(nanosleep {:tv_sec 0 :tv_nsec (* 10 1000 1000)})) |
|
|
|
|
|
|
|
|
|
(fn chars [i] |
|
|
|
@ -47,15 +52,15 @@ |
|
|
|
|
(fn expect [fd pattern fail-pattern] |
|
|
|
|
(let [b (read fd 1024)] |
|
|
|
|
(if (> (# b) 0) |
|
|
|
|
(do |
|
|
|
|
(print (.. "<<< " (escape-readably b))) |
|
|
|
|
(if (string.find b pattern) |
|
|
|
|
(do (print "found" pattern) true) |
|
|
|
|
(and fail-pattern (string.find b fail-pattern)) |
|
|
|
|
(error (.. "Expected " pattern ", got " (escape-readably b))) |
|
|
|
|
(expect fd pattern))) |
|
|
|
|
(if (string.find (log-xfer :<<< b) pattern) |
|
|
|
|
(log-xfer :!!! pattern) |
|
|
|
|
(and fail-pattern (string.find b fail-pattern)) |
|
|
|
|
(error (.. "Expected " pattern ", got " (escape-readably b))) |
|
|
|
|
(expect fd pattern fail-pattern)) |
|
|
|
|
nil))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(fn even? [x] |
|
|
|
|
(= (% x 2) 0)) |
|
|
|
|
|
|
|
|
|