Adding telnetd for Arduino.
This commit is contained in:
@ -141,7 +141,7 @@ ARDUINO_BOOT = common/boot.fs common/vocabulary.fs \
|
|||||||
arduino/bindings.fs common/highlevel.fs \
|
arduino/bindings.fs common/highlevel.fs \
|
||||||
common/filetools.fs common/utils.fs common/locals.fs \
|
common/filetools.fs common/utils.fs common/locals.fs \
|
||||||
common/tasks.fs common/streams.fs arduino/arduino_server.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/esp_camera.fs common/blocks.fs \
|
||||||
arduino/autoboot.fs \
|
arduino/autoboot.fs \
|
||||||
common/fini.fs
|
common/fini.fs
|
||||||
|
|||||||
@ -143,13 +143,12 @@ create out-string out-size 1+ allot align
|
|||||||
webserver-task start-task
|
webserver-task start-task
|
||||||
;
|
;
|
||||||
|
|
||||||
|
also forth definitions
|
||||||
|
|
||||||
: login ( z z -- )
|
: login ( z z -- )
|
||||||
WIFI_MODE_STA Wifi.mode
|
WIFI_MODE_STA Wifi.mode
|
||||||
WiFi.begin begin WiFi.localIP 0= while 100 ms repeat WiFi.localIP ip. cr
|
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 ;
|
z" forth" MDNS.begin if ." MDNS started" else ." MDNS failed" then cr ;
|
||||||
|
|
||||||
also forth definitions
|
|
||||||
|
|
||||||
: webui ( z z -- ) login serve ;
|
: webui ( z z -- ) login serve ;
|
||||||
|
|
||||||
only forth definitions
|
only forth definitions
|
||||||
|
|||||||
40
ueforth/arduino/telnetd.fs
Normal file
40
ueforth/arduino/telnetd.fs
Normal file
@ -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
|
||||||
@ -194,12 +194,12 @@ variable hld
|
|||||||
|
|
||||||
( Input )
|
( Input )
|
||||||
: raw.s depth 0 max for aft sp@ r@ cells - @ . then next ;
|
: 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 ( n -- ) echo @ if emit else drop then ;
|
||||||
: ?echo-prompt echo @ if >r >r raw.s r> r> ." --> " then ;
|
: ?arrow. arrow @ if >r >r raw.s r> r> ." --> " then ;
|
||||||
: accept ( a n -- n ) ?echo-prompt 0 swap begin 2dup < while
|
: accept ( a n -- n ) ?arrow. 0 swap begin 2dup < while
|
||||||
key
|
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
|
dup 8 = over 127 = or if
|
||||||
drop over if rot 1- rot 1- rot 8 ?echo bl ?echo 8 ?echo then
|
drop over if rot 1- rot 1- rot 8 ?echo bl ?echo 8 ?echo then
|
||||||
else
|
else
|
||||||
|
|||||||
@ -33,7 +33,7 @@ transfer{
|
|||||||
last-vocabulary
|
last-vocabulary
|
||||||
branch 0branch donext dolit
|
branch 0branch donext dolit
|
||||||
'context 'notfound notfound
|
'context 'notfound notfound
|
||||||
immediate? input-buffer ?echo ?echo-prompt
|
immediate? input-buffer ?echo ?arrow. arrow
|
||||||
evaluate1 evaluate-buffer
|
evaluate1 evaluate-buffer
|
||||||
'sys 'heap aliteral
|
'sys 'heap aliteral
|
||||||
leaving( )leaving leaving leaving,
|
leaving( )leaving leaving leaving,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
( WebServer )
|
( Telnet )
|
||||||
include posix/sockets.fs
|
include posix/sockets.fs
|
||||||
|
|
||||||
vocabulary telnetd telnetd definitions also posix
|
vocabulary telnetd telnetd definitions also posix
|
||||||
|
|||||||
Reference in New Issue
Block a user