From 8a8c2607b875122d18b778a323ff0e446e6c8b5a Mon Sep 17 00:00:00 2001 From: Joerg Deckert Date: Mon, 16 Dec 2013 22:34:11 +0100 Subject: [PATCH] working handle index --- lib/reg-ios.spin | 86 ++++++++--------- system/administra/admnet/admnet.spin | 139 ++++++++++++++++----------- system/regnatix/ftp.spin | 18 ++-- 3 files changed, 133 insertions(+), 110 deletions(-) diff --git a/lib/reg-ios.spin b/lib/reg-ios.spin index 0259100..9d72a7f 100644 --- a/lib/reg-ios.spin +++ b/lib/reg-ios.spin @@ -1046,7 +1046,7 @@ PUB lanstop 'LAN beenden bus_putchar1(gc#a_lanStop) -PUB lan_connect(ipaddr, remoteport): handle +PUB lan_connect(ipaddr, remoteport): handleidx ''funktionsgruppe : lan ''funktion : ausgehende TCP-Verbindung öffnen (mit Server verbinden) '' : Da hier feste Puffer (bufrxconn,buftxconn) verwendet werden, @@ -1054,102 +1054,102 @@ PUB lan_connect(ipaddr, remoteport): handle '' : (driver_socket.spin handelt per default bis 4 Sockets) ''eingabe : - ''ausgabe : - -''busprotokoll : [073][sub_putlong.ipaddr][sub_putword.remoteport][sub_getlong.handle] +''busprotokoll : [073][sub_putlong.ipaddr][sub_putword.remoteport][get.handleidx] '' : ipaddr - ipv4 address packed into a long (ie: 1.2.3.4 => $01_02_03_04) '' : remoteport - port number to connect to -'' : handle - lfd. Nr. der Verbindung +'' : handleidx - lfd. Nr. der Verbindung bus_putchar1(gc#a_lanConnect) bus_putlong1(ipaddr) bus_putword1(remoteport) - handle := bus_getlong1 + handleidx := bus_getchar1 PUB lan_listen PUB lan_relisten -PUB lan_isconnected(handle): connected +PUB lan_isconnected(handleidx): connected ''funktionsgruppe : lan ''funktion : Abfrage, ob Socket verbunden ''eingabe : - ''ausgabe : - ''busprotokoll : [076][sub_putlong.handle][get.connected] -'' : handle - lfd. Nr. der zu testenden Verbindung +'' : handleidx - lfd. Nr. der zu testenden Verbindung '' : connected - True, if connected bus_putchar1(gc#a_lanIsConnected) - bus_putlong1(handle) + bus_putchar1(handleidx) connected := bus_getchar1 PUB lan_rxcount -PUB lan_resetbuffers(handle) +PUB lan_resetbuffers(handleidx) ''funktionsgruppe : lan ''funktion : Sende- und Empfangspuffer zurücksetzen ''eingabe : - ''ausgabe : - -''busprotokoll : [078][sub_putlong.handle] -'' : handle - lfd. Nr. der Verbindung +''busprotokoll : [078][put.handleidx] +'' : handleidx - lfd. Nr. der Verbindung bus_putchar1(gc#a_lanResetBuffers) - bus_putlong1(handle) + bus_putchar1(handleidx) -PUB lan_waitconntimeout(handle, timeout): connected +PUB lan_waitconntimeout(handleidx, timeout): connected ''funktionsgruppe : lan ''funktion : bestimmte Zeit auf Verbindung warten ''eingabe : - ''ausgabe : - -''busprotokoll : [079][sub_putlong.handle][sub_putword.timeout][get.connected] -'' : handle - lfd. Nr. der zu testenden Verbindung +''busprotokoll : [079][put.handleidx][sub_putword.timeout][get.connected] +'' : handleidx - lfd. Nr. der zu testenden Verbindung '' : timeout - Timeout in Millisekunden '' : connected - True, if connected bus_putchar1(gc#a_lanWaitConnTimeout) - bus_putlong1(handle) + bus_putchar1(handleidx) bus_putword1(timeout) connected := bus_getchar1 -PUB lan_close(handle) +PUB lan_close(handleidx) ''funktionsgruppe : lan ''funktion : TCP-Verbindung (ein- oder ausgehend) schließen ''eingabe : - ''ausgabe : - -''busprotokoll : [080][sub_putlong.handle] -'' : handle - lfd. Nr. der zu schließenden Verbindung +''busprotokoll : [080][put.handleidx] +'' : handleidx - lfd. Nr. der zu schließenden Verbindung bus_putchar1(gc#a_lanClose) - bus_putlong1(handle) + bus_putchar1(handleidx) PUB lan_rxflush -PUB lan_rxcheck(handle): rxbyte +PUB lan_rxcheck(handleidx): 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][sub_putlong.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 +''busprotokoll : [082][put.handleidx][get.rxbyte] +'' : handleidx - 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_putlong1(handle) + bus_putchar1(handleidx) rxbyte := bus_getchar1 rxbyte := ~rxbyte -PUB lan_rxtime(handle, timeout): rxbyte +PUB lan_rxtime(handleidx, 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][sub_putlong.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 +''busprotokoll : [083][sub_putlong.handleidx][sub_putword.timeout][get.rxbyte] +'' : handleidx - 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_putlong1(handle) + bus_putchar1(handleidx) bus_putword1(timeout) rxbyte := bus_getchar1 rxbyte := ~rxbyte @@ -1158,37 +1158,37 @@ PUB lan_rxbyte PUB lan_rxdatatime PUB lan_rxdata PUB lan_txflush -PUB lan_txcheck(handle, txbyte): error +PUB lan_txcheck(handleidx, 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][sub_putlong.handle][put.tybyte][get.error] -'' : handle - lfd. Nr. der Verbindung -'' : txbyte - zu sendendes Zeichen -'' : error - ungleich Null bei Fehler +''busprotokoll : [088][put.handleidx][put.tybyte][get.error] +'' : handleidx - lfd. Nr. der Verbindung +'' : txbyte - zu sendendes Zeichen +'' : error - ungleich Null bei Fehler bus_putchar1(gc#a_lanTXCheck) - bus_putlong1(handle) + bus_putchar1(handleidx) bus_putchar1(txbyte) error := bus_getchar1 PUB lan_tx -PUB lan_txdata(handle, ptr, len): error +PUB lan_txdata(handleidx, ptr, len): error ''funktionsgruppe : lan ''funktion : bei bestehender Verbindung die angegebene Datenmenge senden ''eingabe : - ''ausgabe : - -''busprotokoll : [090][sub_putlong.handle][sub_putlong.len][put.byte1][put.byte][get.error] -'' : handle - lfd. Nr. der Verbindung +''busprotokoll : [090][put.handleidx][sub_putlong.len][put.byte1][put.byte][get.error] +'' : handleidx - lfd. Nr. der Verbindung '' : byte1 ... byte - zu sendende Bytes '' : len - Anzahl zu sendender Bytes '' : error - ungleich Null bei Fehler bus_putchar1(gc#a_lanTXData) - bus_putlong1(handle) + bus_putchar1(handleidx) bus_putlong1(len) repeat len diff --git a/system/administra/admnet/admnet.spin b/system/administra/admnet/admnet.spin index 1c0b707..0de6840 100644 --- a/system/administra/admnet/admnet.spin +++ b/system/administra/admnet/admnet.spin @@ -209,10 +209,10 @@ VAR long com_baud byte lan_started 'LAN gestartet? long sockhandle[sock#sNumSockets] 'Handle für mit sock.connect/sock.listen erstellten Socket - byte bufrxconn[rxlen] 'LAN Empfangspuffer ausgehende Verbindung - byte buftxconn[txlen] 'LAN Sendepuffer ausgehende Verbindung - byte bufrxlist[rxlen] 'LAN Empfangspuffer eingehende Verbindung - byte buftxlist[txlen] 'LAN Sendepuffer eingehende Verbindung + byte bufidx[sock#sNumSockets] 'zum Handle-Index gehörender Puffer-abschnitt + '(zum Socket mit dem Handle 2 gehört der Pufferabschnitt aus bufidx[2]) + byte bufrx[rxlen*sock#sNumSockets] 'LAN Empfangspuffer + byte buftx[txlen*sock#sNumSockets] 'LAN Sendepuffer CON ''------------------------------------------------- ADMINISTRA @@ -1117,7 +1117,7 @@ PRI rtc_pauseForMilliseconds 'rtc: Pauses execution f CON ''------------------------------------------------- LAN-FUNKTIONEN -PRI lan_start | hiveid, hivestr, strpos, macpos +PRI lan_start | hiveid, hivestr, strpos, macpos, i ''funktionsgruppe : lan ''funktion : Netzwerk starten ''eingabe : - @@ -1125,6 +1125,13 @@ PRI lan_start | hiveid, hivestr, strpos, macpos ''busprotokoll : [071] if (not lan_started) + + 'Pufferindex zurücksetzen + i := 0 + repeat sock#sNumSockets + bufidx[i++] := $FF '0xFF: nicht zugewiesen + + 'IP-Parameter setzen ip_addr := rtc.getNVSRAM(NVRAM_IPADDR) ip_addr[1] := rtc.getNVSRAM(NVRAM_IPADDR+1) ip_addr[2] := rtc.getNVSRAM(NVRAM_IPADDR+2) @@ -1175,7 +1182,7 @@ PRI lan_stop sock.stop lan_started := false -PRI lan_connect | ipaddr, remoteport, handle, handleidx +PRI lan_connect | ipaddr, remoteport, handle, handleidx, i ''funktionsgruppe : lan ''funktion : ausgehende TCP-Verbindung öffnen (mit Server verbinden) ''eingabe : - @@ -1188,12 +1195,20 @@ PRI lan_connect | ipaddr, remoteport, handle, handleidx ipaddr := sub_getlong remoteport := sub_getword - handle := sock.connect(ipaddr, remoteport, @bufrxconn, rxlen, @buftxconn, txlen) - handleidx := handle.byte[0] 'extract the handle index from the lower 8 bits - sockhandle[handleidx] := handle 'komplettes handle zu handle index speichern - - bus_putchar(handleidx) 'handle senden + 'freien Pufferabschnitt suchen + i := 0 + repeat sock#sNumSockets + if bufidx[i] == $FF '0xFF: nicht zugewiesen + quit + i++ + ifnot (handle := sock.connect(ipaddr, remoteport, @bufrx[i*sock#sNumSockets], rxlen, @buftx[i*sock#sNumSockets], txlen)) ==-102 + handleidx := handle.byte[0] 'extract the handle index from the lower 8 bits + sockhandle[handleidx] := handle 'komplettes handle zu handle index speichern + bufidx[i] :=handleidx + bus_putchar(handleidx) 'handleidx senden + else + bus_putchar($FF) PRI lan_listen PRI lan_relisten @@ -1211,87 +1226,95 @@ PRI lan_isconnected | handleidx bus_putchar(sock.isConnected(sockhandle[handleidx])) PRI lan_rxcount -PRI lan_resetbuffers | handle +PRI lan_resetbuffers | handleidx ''funktionsgruppe : lan ''funktion : Sende- und Empfangspuffer zurücksetzen ''eingabe : - ''ausgabe : - ''busprotokoll : [078][sub_getlong.handle] -'' : handle - lfd. Nr. der Verbindung +'' : handleidx - lfd. Nr. der Verbindung - handle := sub_getlong + handleidx := bus_getchar - sock.resetBuffers(handle) + sock.resetBuffers(sockhandle[handleidx]) -PRI lan_waitconntimeout | handle, timeout, t, connected +PRI lan_waitconntimeout | handleidx, timeout, t, connected ''funktionsgruppe : lan ''funktion : bestimmte Zeit auf Verbindung warten ''eingabe : - ''ausgabe : - -''busprotokoll : [079][sub_getlong.handle][sub_getword.timeout][put.connected] -'' : handle - lfd. Nr. der zu testenden Verbindung +''busprotokoll : [079][get.handleidx][sub_getword.timeout][put.connected] +'' : handleidx - lfd. Nr. der zu testenden Verbindung '' : timeout - Timeout in Millisekunden '' : connected - True, if connected - handle := sub_getlong + handleidx := bus_getchar timeout := sub_getword t := cnt - repeat until (connected := sock.isConnected(handle)) or (((cnt - t) / (clkfreq / 1000)) > timeout) + repeat until (connected := sock.isConnected(sockhandle[handleidx])) or (((cnt - t) / (clkfreq / 1000)) > timeout) bus_putchar(connected) -PRI lan_close | handle +PRI lan_close | handleidx, i ''funktionsgruppe : lan ''funktion : TCP-Verbindung (ein- oder ausgehend) schließen ''eingabe : - ''ausgabe : - -''busprotokoll : [080][sub_getlong.handle] -'' : handle - lfd. Nr. der zu schließenden Verbindung +''busprotokoll : [080][get.handleidx] +'' : handleidx - lfd. Nr. der zu schließenden Verbindung - handle := sub_getlong + handleidx := bus_getchar + + sock.close(sockhandle[handleidx]) + + 'reservierten Pufferabschnitt freigeben + i := 0 + repeat sock#sNumSockets + if bufidx[i++] == handleidx '0xFF: nicht zugewiesen + bufidx[i++] := $FF + quit - sock.close(handle) PRI lan_rxflush -PRI lan_rxcheck | handle, rxbyte +PRI lan_rxcheck | handleidx, 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][sub_getlong.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 +''busprotokoll : [082][get.handleidx][put.rxbyte] +'' : handleidx - lfd. Nr. der Verbindung +'' : rxbyte - empfangenes Zeichen (0 - 127) oder +'' : sock#RETBUFFEREMPTY (-1) wenn Puffer leer +'' : sock#ERRSOCKETCLOSED (-3) wenn keine Verbindung mehr - handle := sub_getlong + handleidx := bus_getchar - rxbyte := sock.readByteNonBlocking(handle) - if (not sock.isConnected(handle)) and (rxbyte == -1) + rxbyte := sock.readByteNonBlocking(sockhandle[handleidx]) + if (not sock.isConnected(sockhandle[handleidx])) and (rxbyte == -1) rxbyte := sock#ERRSOCKETCLOSED bus_putchar(rxbyte) -PRI lan_rxtime | handle, timeout, t, rxbyte +PRI lan_rxtime | handleidx, 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][sub_getlong.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 +''busprotokoll : [083][get.handleidx][sub_getword.timeout][put.rxbyte] +'' : handleidx - lfd. Nr. der Verbindung +'' : timeout - Timeout in Millisekunden +'' : rxbyte - empfangenes Zeichen (0 - 127) oder +'' : sock#RETBUFFEREMPTY (-1) wenn Timeout oder keine Verbindung mehr - handle := sub_getlong + handleidx := 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 + repeat until (rxbyte := sock.readByteNonBlocking(sockhandle[handleidx])) => 0 or (not sock.isConnected(sockhandle[handleidx])) or (cnt - t) / (clkfreq / 1000) > timeout bus_putchar(rxbyte) @@ -1299,50 +1322,50 @@ PRI lan_rxbyte PRI lan_rxdatatime PRI lan_rxdata PRI lan_txflush -PRI lan_txcheck | handle, txbyte +PRI lan_txcheck | handleidx, 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][sub_getlong.handle][get.tybyte][put.error] -'' : handle - lfd. Nr. der Verbindung -'' : txbyte - zu sendendes Zeichen -'' : error - ungleich Null bei Fehler +''busprotokoll : [088][get.handleidx][get.tybyte][put.error] +'' : handleidx - lfd. Nr. der Verbindung +'' : txbyte - zu sendendes Zeichen +'' : error - ungleich Null bei Fehler - handle := sub_getlong + handleidx := bus_getchar txbyte := bus_getchar - ifnot sock.isConnected(handle) + ifnot sock.isConnected(sockhandle[handleidx]) bus_putchar(sock#ERRSOCKETCLOSED) - if (sock.writeByteNonBlocking(handle, txbyte) == txbyte) + if (sock.writeByteNonBlocking(sockhandle[handleidx], txbyte) == txbyte) bus_putchar(0) else bus_putchar(sock#RETBUFFERFULL) PRI lan_tx -PRI lan_txdata | handle, len, txbyte, error +PRI lan_txdata | handleidx, len, txbyte, error ''funktionsgruppe : lan ''funktion : bei bestehender Verbindung die angegebene Datenmenge senden ''eingabe : - ''ausgabe : - -''busprotokoll : [090][sub_getlong.handle][sub_getlong.len][get.byte1][get.byte][put.error] -'' : handle - lfd. Nr. der Verbindung -'' : len - Anzahl zu sendender Bytes -'' : error - ungleich Null bei Fehler +''busprotokoll : [090][get.handleidx][sub_getlong.len][get.byte1][get.byte][put.error] +'' : handleidx - lfd. Nr. der Verbindung +'' : len - Anzahl zu sendender Bytes +'' : error - ungleich Null bei Fehler error := FALSE - handle := sub_getlong + handleidx := bus_getchar len := sub_getlong repeat len txbyte := bus_getchar ifnot error - repeat while sock.writeByteNonBlocking(handle, txbyte) < 0 - ifnot sock.isConnected(handle) + repeat while sock.writeByteNonBlocking(sockhandle[handleidx], txbyte) < 0 + ifnot sock.isConnected(sockhandle[handleidx]) error := sock#ERRSOCKETCLOSED quit diff --git a/system/regnatix/ftp.spin b/system/regnatix/ftp.spin index 3244791..764526a 100644 --- a/system/regnatix/ftp.spin +++ b/system/regnatix/ftp.spin @@ -14,7 +14,7 @@ Chip : Regnatix Typ : Programm Version : Subversion : -Funktion : IP-Konfiguration in NVRAM ablegen +Funktion : FTP-Client Komponenten : - COG's : - Logbuch : @@ -46,8 +46,8 @@ VAR byte parastr[64] byte strTemp[128] byte addrset - long handle_control 'Handle FTP Control Verbindung - long handle_data 'Handle FTP Data Verbindung + byte handleidx_control 'Handle FTP Control Verbindung + byte handleidx_data 'Handle FTP Data Verbindung PUB main | pasvport @@ -84,12 +84,12 @@ PRI ftpconnect delay_ms(1000) 'nach ios.lanstart dauert es, bis der Stack funktioniert ios.print(string("Verbinde mit FTP-Server...")) ios.printnl - if (handle_control := ios.lan_connect(ip_addr, 21)) == -102 + if (handleidx_control := ios.lan_connect(ip_addr, 21)) == $FF ios.print(string("Kein Socket frei...")) ios.printnl return(-1) -'' ios.lan_resetbuffers(handle_control) - ifnot (ios.lan_waitconntimeout(handle_control, 2000)) +'' ios.lan_resetbuffers(handleidx_control) + ifnot (ios.lan_waitconntimeout(handleidx_control, 2000)) ios.print(string("Verbindung mit FTP-Server konnte nicht aufgebaut werden.")) ios.printnl return(-1) @@ -192,9 +192,9 @@ PRI getResponse (strOk) : respOk | len PRI readLine | i, ch repeat i from 0 to 126 - ch := ios.lan_rxtime(handle_control, 500) + ch := ios.lan_rxtime(handleidx_control, 500) if ch == 13 - ch := ios.lan_rxtime(handle_control, 500) + ch := ios.lan_rxtime(handleidx_control, 500) if ch == -1 or ch == 10 quit strTemp[i] := ch @@ -208,7 +208,7 @@ PRI sendStr (strSend) : error ios.print(string(" > ")) ios.print(strSend) ios.printnl - error := ios.lan_txdata(handle_control, strSend, strsize(strSend)) + error := ios.lan_txdata(handleidx_control, strSend, strsize(strSend)) PRI delay_ms(Duration) waitcnt(((clkfreq / 1_000 * Duration - 3932)) + cnt)