diff --git a/ueforth/Makefile b/ueforth/Makefile index c33dd22..1f5c25b 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -141,7 +141,7 @@ ARDUINO_BOOT = common/boot.fs common/vocabulary.fs \ arduino/bindings.fs common/highlevel.fs \ common/filetools.fs common/utils.fs common/locals.fs \ common/tasks.fs common/streams.fs arduino/arduino_server.fs \ - arduino/arduino_bterm.fs \ + arduino/arduino_bterm.fs arduino/telnetd.fs \ arduino/esp_camera.fs common/blocks.fs \ arduino/autoboot.fs \ common/fini.fs diff --git a/ueforth/arduino/arduino_server.fs b/ueforth/arduino/arduino_server.fs index f37de8e..70ba354 100644 --- a/ueforth/arduino/arduino_server.fs +++ b/ueforth/arduino/arduino_server.fs @@ -143,13 +143,12 @@ create out-string out-size 1+ allot align webserver-task start-task ; +also forth definitions + : login ( z z -- ) WIFI_MODE_STA Wifi.mode WiFi.begin begin WiFi.localIP 0= while 100 ms repeat WiFi.localIP ip. cr z" forth" MDNS.begin if ." MDNS started" else ." MDNS failed" then cr ; - -also forth definitions - : webui ( z z -- ) login serve ; only forth definitions diff --git a/ueforth/arduino/telnetd.fs b/ueforth/arduino/telnetd.fs new file mode 100644 index 0000000..4bd750e --- /dev/null +++ b/ueforth/arduino/telnetd.fs @@ -0,0 +1,40 @@ +( Telnet ) +vocabulary telnetd telnetd definitions also sockets also internals + +8080 constant port +-1 value sockfd -1 value clientfd +: bs, ( n -- ) dup 256 / c, c, ; +: s, ( n -- ) dup c, 256 / c, ; +: l, ( n -- ) dup s, 65536 / s, ; +create telnet-port 16 c, AF_INET c, port bs, 0 l, 0 l, 0 l, +create client sizeof(sockaddr_in) allot variable client-len + +defer broker + +: telnet-type ( a n -- ) clientfd write-file if broker then ; +: telnet-key ( -- n ) 0 >r rp@ 1 clientfd read-file if drop rdrop broker else drop then r> ; + +: connection ( n -- ) + dup 0< if drop exit then to clientfd + 0 echo ! + ['] telnet-key is key + ['] telnet-type is type quit ; + +: broker-connection + rp0 rp! sp0 sp! + begin + ['] arduino-key is key + ['] arduino-type is type + -1 echo ! + ." Listening on port " port . cr + sockfd client client-len accept + ." Connected: " dup . cr connection + again ; +' broker-connection is broker + +: server + AF_INET SOCK_STREAM 0 socket to sockfd + sockfd telnet-port sizeof(sockaddr_in) bind throw + sockfd 10 listen throw broker ; + +only forth definitions diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index d110f66..f797d07 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -194,12 +194,12 @@ variable hld ( Input ) : raw.s depth 0 max for aft sp@ r@ cells - @ . then next ; -variable echo -1 echo ! +variable echo -1 echo ! variable arrow -1 arrow ! : ?echo ( n -- ) echo @ if emit else drop then ; -: ?echo-prompt echo @ if >r >r raw.s r> r> ." --> " then ; -: accept ( a n -- n ) ?echo-prompt 0 swap begin 2dup < while +: ?arrow. arrow @ if >r >r raw.s r> r> ." --> " then ; +: accept ( a n -- n ) ?arrow. 0 swap begin 2dup < while key - dup nl = if ?echo drop nip exit then + dup nl = if 13 emit ?echo drop nip exit then dup 8 = over 127 = or if drop over if rot 1- rot 1- rot 8 ?echo bl ?echo 8 ?echo then else diff --git a/ueforth/common/vocabulary.fs b/ueforth/common/vocabulary.fs index 25aeb1d..f382106 100644 --- a/ueforth/common/vocabulary.fs +++ b/ueforth/common/vocabulary.fs @@ -33,7 +33,7 @@ transfer{ last-vocabulary branch 0branch donext dolit 'context 'notfound notfound - immediate? input-buffer ?echo ?echo-prompt + immediate? input-buffer ?echo ?arrow. arrow evaluate1 evaluate-buffer 'sys 'heap aliteral leaving( )leaving leaving leaving, diff --git a/ueforth/posix/telnetd.fs b/ueforth/posix/telnetd.fs index 2cdbe39..cda00a9 100644 --- a/ueforth/posix/telnetd.fs +++ b/ueforth/posix/telnetd.fs @@ -1,4 +1,4 @@ -( WebServer ) +( Telnet ) include posix/sockets.fs vocabulary telnetd telnetd definitions also posix