proceeding implementing ftp

This commit is contained in:
Jörg Deckert 2013-12-12 16:47:00 +01:00
parent 07bbde82c6
commit 213f20ee7a
4 changed files with 283 additions and 56 deletions

View File

@ -172,7 +172,7 @@ A_AYS = %00000000_00000000_00000010_00000000
a_lanIsConnected 'Prüfen, ob verbunden
a_lanRXCount 'Anzahl Zeichen im Empfangspuffer
a_lanResetBuffers 'Puffer zurücksetzen
a_lanWaitConnectTimeout 'bestimmte Zeit auf Verbindung warten
a_lanWaitConnTimeout 'bestimmte Zeit auf Verbindung warten
a_lanClose 'TCP-Verbindung schließen
a_lanRXFlush 'Empfangspuffer leeren
a_lanRXCheck 'warten auf Byte aus Empfangspuffer

View File

@ -1066,10 +1066,36 @@ PUB lan_connect(ipaddr, remoteport): handle
PUB lan_listen
PUB lan_relisten
PUB lan_isconnected
PUB lan_isconnected(handle): connected
''funktionsgruppe : lan
''funktion : Abfrage, ob Socket verbunden
''eingabe : -
''ausgabe : -
''busprotokoll : [076][put.handle][get.connected]
'' : handle - lfd. Nr. der zu testenden Verbindung
'' : connected - True, if connected
bus_putchar1(gc#a_lanIsConnected)
bus_putchar1(handle)
connected := bus_getchar1
PUB lan_rxcount
PUB lan_resetbuffers
PUB lan_waitconntimeout
PUB lan_waitconntimeout(handle, timeout): connected
''funktionsgruppe : lan
''funktion : bestimmte Zeit auf Verbindung warten
''eingabe : -
''ausgabe : -
''busprotokoll : [079][put.handle][sub_putword.timeout][get.connected]
'' : handle - lfd. Nr. der zu testenden Verbindung
'' : timeout - Timeout in Millisekunden
'' : connected - True, if connected
bus_putchar1(gc#a_lanWaitConnTimeout)
bus_putchar1(handle)
bus_putword1(timeout)
connected := bus_getchar1
PUB lan_close(handle)
''funktionsgruppe : lan
''funktion : TCP-Verbindung (ein- oder ausgehend) schließen
@ -1082,13 +1108,61 @@ PUB lan_close(handle)
bus_putchar1(handle)
PUB lan_rxflush
PUB lan_rxcheck
PUB lan_rxtime
PUB lan_rxcheck(handle): rxbyte
''funktionsgruppe : lan
''funktion : ASCII-Zeichen lesen, wenn vorhanden
'' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird
'' : (vor allem nicht, wenn -1 und -3 enthalten sein können)
''eingabe : -
''ausgabe : -
''busprotokoll : [082][put.handle][get.rxbyte]
'' : handle - lfd. Nr. der Verbindung
'' : rxbyte - empfangenes Zeichen (0 - 127) oder
'' : sock#RETBUFFEREMPTY (-1) wenn Puffer leer
'' : sock#ERRSOCKETCLOSED (-3) wenn keine Verbindung mehr
bus_putchar1(gc#a_lanRXCheck)
bus_putchar1(handle)
rxbyte := bus_getchar1
PUB lan_rxtime(handle, timeout): rxbyte
''funktionsgruppe : lan
''funktion : angegebene Zeit auf ASCII-Zeichen warten
'' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird
''eingabe : -
''ausgabe : -
''busprotokoll : [083][put.handle][sub_putword.timeout][get.rxbyte]
'' : handle - lfd. Nr. der Verbindung
'' : timeout - Timeout in Millisekunden
'' : rxbyte - empfangenes Zeichen (0 - 127) oder
'' : sock#RETBUFFEREMPTY (-1) wenn Timeout oder keine Verbindung mehr
bus_putchar1(gc#a_lanRXTime)
bus_putchar1(handle)
bus_putword1(timeout)
rxbyte := bus_getchar1
PUB lan_rxbyte
PUB lan_rxdatatime
PUB lan_rxdata
PUB lan_txflush
PUB lan_txcheck
PUB lan_txcheck(handle, txbyte): error
''funktionsgruppe : lan
''funktion : bei bestehender Verbindung ein ASCII-Zeichen zu senden
'' : nicht verwenden, wenn anderes als ASCII (0 - 127) gesendet wird
'' : (vor allem nicht, wenn -1 enthalten sein kann)
''eingabe : -
''ausgabe : -
''busprotokoll : [088][put.handle][put.tybyte][get.error]
'' : handle - lfd. Nr. der Verbindung
'' : txbyte - zu sendendes Zeichen
'' : error - ungleich Null bei Fehler
bus_putchar1(gc#a_lanTXCheck)
bus_putchar1(handle)
bus_putchar1(txbyte)
error := bus_getchar1
PUB lan_tx
PUB lan_txdata

View File

@ -207,6 +207,7 @@ VAR
byte tbuf[20] 'stringpuffer
byte tbuf2[20]
long com_baud
byte lan_started 'LAN gestartet?
byte bufrxconn[rxlen] 'LAN Empfangspuffer ausgehende Verbindung
byte buftxconn[txlen] 'LAN Sendepuffer ausgehende Verbindung
byte bufrxlist[rxlen] 'LAN Empfangspuffer eingehende Verbindung
@ -293,7 +294,7 @@ PUB main | cmd,err 'chip: kommandointerpret
gc#a_lanIsConnected: lan_isconnected 'Prüfen, ob verbunden
gc#a_lanRXCount: lan_rxcount 'Anzahl Zeichen im Empfangspuffer
gc#a_lanResetBuffers: lan_resetbuffers 'Puffer zurücksetzen
gc#a_lanWaitConnectTimeout: lan_waitconntimeout 'bestimmte Zeit auf Verbindung warten
gc#a_lanWaitConnTimeout: lan_waitconntimeout 'bestimmte Zeit auf Verbindung warten
gc#a_lanClose: lan_close 'TCP-Verbindung schließen
gc#a_lanRXFlush: lan_rxflush 'Empfangspuffer leeren
gc#a_lanRXCheck: lan_rxcheck 'warten auf Byte aus Empfangspuffer
@ -345,11 +346,10 @@ PRI init_chip | err,i,j 'chip: initialisierung d
'serielle schnittstelle starten
com_baud := 115200
com.start(gc#SER_RX,gc#SER_TX,0,com_baud) ' start the default serial interface
com.start(gc#SER_RX,gc#SER_TX,0,com_baud) 'start the default serial interface
'' 'Netz starten
'' lan.start
'' lan.ftpBoot
'LAN
lan_started := false 'LAN noch nicht gestartet
PRI bus_putchar(zeichen) 'chip: ein byte über bus ausgeben
''funktionsgruppe : chip
@ -1123,6 +1123,7 @@ PRI lan_start | hiveid, hivestr, strpos, macpos
''ausgabe : -
''busprotokoll : [071]
if (not lan_started)
ip_addr := rtc.getNVSRAM(NVRAM_IPADDR)
ip_addr[1] := rtc.getNVSRAM(NVRAM_IPADDR+1)
ip_addr[2] := rtc.getNVSRAM(NVRAM_IPADDR+2)
@ -1159,6 +1160,7 @@ PRI lan_start | hiveid, hivestr, strpos, macpos
macpos--
sock.start(A_NETCS,A_NETSCK,A_NETSI,A_NETSO, -1, @mac_addr, @ip_addr)
lan_started := true
PRI lan_stop
@ -1168,7 +1170,9 @@ PRI lan_stop
''ausgabe : -
''busprotokoll : [072]
if lan_started
sock.stop
lan_started := false
PRI lan_connect | ipaddr, remoteport, handle
''funktionsgruppe : lan
@ -1183,9 +1187,6 @@ PRI lan_connect | ipaddr, remoteport, handle
'' : remoteport - port number to connect to
'' : handle - lfd. Nr. der Verbindung
{if sock.isValidHandle(handle)
close}
ipaddr := sub_getlong
remoteport := sub_getword
@ -1196,10 +1197,39 @@ PRI lan_connect | ipaddr, remoteport, handle
PRI lan_listen
PRI lan_relisten
PRI lan_isconnected
PRI lan_isconnected | handle
''funktionsgruppe : lan
''funktion : Abfrage, ob Socket verbunden
''eingabe : -
''ausgabe : -
''busprotokoll : [076][get.handle][put.connected]
'' : handle - lfd. Nr. der zu testenden Verbindung
'' : connected - True, if connected
handle := bus_getchar
bus_putchar(sock.isConnected(handle))
PRI lan_rxcount
PRI lan_resetbuffers
PRI lan_waitconntimeout
PRI lan_waitconntimeout | handle, timeout, t, connected
''funktionsgruppe : lan
''funktion : bestimmte Zeit auf Verbindung warten
''eingabe : -
''ausgabe : -
''busprotokoll : [079][get.handle][sub_getword.timeout][put.connected]
'' : handle - lfd. Nr. der zu testenden Verbindung
'' : timeout - Timeout in Millisekunden
'' : connected - True, if connected
handle := bus_getchar
timeout := sub_getword
t := cnt
repeat until (connected := sock.isConnected(handle)) or (((cnt - t) / (clkfreq / 1000)) > timeout)
bus_putchar(connected)
PRI lan_close | handle
''funktionsgruppe : lan
''funktion : TCP-Verbindung (ein- oder ausgehend) schließen
@ -1213,13 +1243,75 @@ PRI lan_close | handle
sock.close(handle)
PRI lan_rxflush
PRI lan_rxcheck
PRI lan_rxtime
PRI lan_rxcheck | handle, rxbyte
''funktionsgruppe : lan
''funktion : ASCII-Zeichen lesen, wenn vorhanden
'' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird
'' : (vor allem nicht, wenn -1 und -3 enthalten sein können)
''eingabe : -
''ausgabe : -
''busprotokoll : [082][get.handle][put.rxbyte]
'' : handle - lfd. Nr. der Verbindung
'' : rxbyte - empfangenes Zeichen (0 - 127) oder
'' : sock#RETBUFFEREMPTY (-1) wenn Puffer leer
'' : sock#ERRSOCKETCLOSED (-3) wenn keine Verbindung mehr
handle := bus_getchar
rxbyte := sock.readByteNonBlocking(handle)
if (not sock.isConnected(handle)) and (rxbyte == -1)
rxbyte := sock#ERRSOCKETCLOSED
bus_putchar(rxbyte)
PRI lan_rxtime | handle, timeout, t, rxbyte
''funktionsgruppe : lan
''funktion : angegebene Zeit auf ASCII-Zeichen warten
'' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird
''eingabe : -
''ausgabe : -
''busprotokoll : [083][get.handle][sub_getword.timeout][put.rxbyte]
'' : handle - lfd. Nr. der Verbindung
'' : timeout - Timeout in Millisekunden
'' : rxbyte - empfangenes Zeichen (0 - 127) oder
'' : sock#RETBUFFEREMPTY (-1) wenn Timeout oder keine Verbindung mehr
handle := bus_getchar
timeout := sub_getword
t := cnt
repeat until (rxbyte := sock.readByteNonBlocking(handle)) => 0 or (not sock.isConnected(handle)) or (cnt - t) / (clkfreq / 1000) > timeout
bus_putchar(rxbyte)
PRI lan_rxbyte
PRI lan_rxdatatime
PRI lan_rxdata
PRI lan_txflush
PRI lan_txcheck
PRI lan_txcheck | handle, txbyte
''funktionsgruppe : lan
''funktion : bei bestehender Verbindung ein ASCII-Zeichen zu senden
'' : nicht verwenden, wenn anderes als ASCII (0 - 127) gesendet wird
'' : (vor allem nicht, wenn -1 enthalten sein kann)
''eingabe : -
''ausgabe : -
''busprotokoll : [088][get.handle][get.tybyte][put.error]
'' : handle - lfd. Nr. der Verbindung
'' : txbyte - zu sendendes Zeichen
'' : error - ungleich Null bei Fehler
handle := bus_getchar
txbyte := bus_getchar
ifnot sock.isConnected(handle)
bus_putchar(sock#ERRSOCKETCLOSED)
if (sock.writeByteNonBlocking(handle, txbyte) == txbyte)
bus_putchar(0)
else
bus_putchar(sock#RETBUFFERFULL)
PRI lan_tx
PRI lan_txdata

View File

@ -42,11 +42,12 @@ _XINFREQ = 5_000_000
VAR
long ip_addr
byte parastr[64]
byte addrset
byte handle_control 'Handle FTP Control Verbindung
byte handle_data 'Handle FTP Data Verbindung
long ip_addr
byte parastr[64]
byte strTemp[128]
byte addrset
byte handle_control 'Handle FTP Control Verbindung
byte handle_data 'Handle FTP Data Verbindung
PUB main
@ -70,6 +71,24 @@ PUB main
ios.print(string("Handle Connect: "))
ios.print(num.ToStr(handle_control, num#DEC))
ios.printnl
if (ios.lan_waitconntimeout(handle_control, 1500))
ios.print(string("Verbindung mit FTP-Server hergestellt."))
ios.printnl
if getResponse(string("220 "))
if sendStr(handle_control, string("USER anonymous",13,10))
getResponse(string("230 "))
else
ios.print(string("Fehler beim Senden des Usernamens"))
ios.printnl
else
ios.print(string("Antwort falsch."))
ios.printnl
else
ios.print(string("Verbindung mit FTP-Server konnte nicht aufgebaut werden."))
ios.printnl
ios.lan_close(handle_control)
ios.stop
@ -86,6 +105,48 @@ PRI setaddr (ipaddr) | pos, count 'IP-Adresse in Variable
if(count == -1)
quit
PRI getResponse (strOk) : respOk | len
respOk := FALSE
repeat
readLine
if strsize(@strTemp) == 0
quit
ios.print(string("Antwort: "))
ios.print(strTemp)
ios.printnl
'byte[@strTemp+strsize(strOk)] := 0
strTemp[strsize(strOk)] := 0
if strcomp(@strTemp, strOk)
respOk := TRUE
ios.print(string("Antwort korrekt."))
ios.printnl
return respOk
PRI readLine | i, ch
repeat i from 0 to 126
ch := ios.lan_rxtime(handle_control, 500)
if ch == 13
ch := ios.lan_rxtime(handle_control, 500)
if ch == -1 or ch == 10
quit
strTemp[i] := ch
strTemp[i] := 0
return i
PRI sendStr (handle, strSend) | i, err
repeat i from 0 to strsize(strSend)
if (err := ios.lan_txcheck(handle, strSend[i]))
quit
return err
DAT 'sys: helptext