author: bocianu bocianu@gmail.com
This library provides an easy interface to estabilish TCP connection, and transfer data both directions.
It allows you to use SIO interrupts, to read data from SIO only on device request.
It uses 256 bytes circular buffer located in your MadPascal DATA block.
https://fujinet.online/
This library is a part of 'blibs' - set of custom Mad-Pascal libraries.
https://gitlab.com/bocianu/blibs
name: | type: | description: |
---|---|---|
TCP_status | FN_StatusStruct | Status operation result data. Structure defined in fn_sio module. |
TCP_bytesWaiting | word | Number of bytes waiting in network device |
TCP_bufferLength | word | Number of bytes in receive buffer |
TCP_dataFlag | byte | This byte is updated by SIO interrupt. 1 is set here if there is incoming data. |
name: | description: |
---|---|
TCP_AttachIRQ | procedure TCP_AttachIRQ;Attaches interrupt handler, to update TCP_dataFlag byte on incoming data connection. This interrupt sets 1 into TCP_dataFlag variable. If you want to be informed on next packet, you need to reset it to zero manualy (probably after data fetch). |
TCP_DetachIRQ | procedure TCP_DetachIRQ;Removes custom SIO interrupt handler. Do not call this procedure without TCP_AttachIRQ before. |
TCP_Connect | function TCP_Connect(var tcp_uri:PChar):byte;overload;Opens #FujiNet connection to remote host, at selected port using declared protocol.
parameters: |
TCP_Connect | function TCP_Connect(var tcp_uri: PChar; aux1,aux2: byte):byte;overload;Opens #FujiNet connection to remote host, at selected port using declared protocol.
parameters: |
TCP_GetStatus | function TCP_GetStatus:byte;Reads network device status and stores information in TCP_status variable. |
TCP_SIORead | function TCP_SIORead:word;Performs data fetch from SIO device (N:) to free space in local TCP buffer. If amount of SIO data is bigger than available space in buffer, only part of the data is received. To fetch rest of it you need to release some buffer space, by calling TCP_ReadByte or TCP_ReadBuffer procedure. And then call TCP_SIORead again... and again... |
TCP_ReadByte | function TCP_ReadByte: byte;Reads one byte from TCP receive buffer (if available). It also frees one byte in buffer for future SIOReads. Always check if there is at least one byte available in buffer (TCP_bufferLength > 0). If you will call this function on empty buffer, returned value is unpredictable.
returns: |
TCP_ReadBuffer | function TCP_ReadBuffer(buf: pointer; len: word): word;Reads block of bytes from TCP receive buffer. It also frees space in buffer for future SIOReads. If amount of data available in buffer is smaller then desired (len), only available part is received. Function will return exact number of received/freed bytes.
parameters:returns: |
TCP_CheckAndPoll | function TCP_CheckAndPoll:word;This function performs check if there is any incoming data available. If there is and we have free space in receive buffer, it reads biggest possible chunk of data from SIO to our TCP buffer. After operation it returns amount of data added to buffer, and updates value of TCP_bufferLength. Also TCP_dataFlag is set to 0 after every succesful poll. This function should be called periodicaly to retrieve incoming data, and process it when it shows up in buffer.
returns: |
TCP_SendString | procedure TCP_SendString(var s:string);Sends string using existing connection.
parameters: |
TCP_SendBuffer | procedure TCP_SendBuffer(buf: pointer;len: word);Sends data buffer using already opened connection.
parameters: |
TCP_Close | procedure TCP_Close;Closes #FujiNet network connection. |
TCP_WaitForData | function TCP_WaitForData(timeout:word):byte;Waits for declared time (in frames) for incoming data.
returns: |
TCP_ClearBuffer | procedure TCP_ClearBuffer;Clears TCP data buffer. |