SPI Programming Manual (G06.24+, H06.03+, J06.03+)

SPI Programming Examples
SPI Programming Manual427506-006
E-50
Example E-11: A Simple SPI Server in TAL
IF out^string.len < in^string.len THEN
BEGIN
! update the context and add it to the returned buffer.
the^context.command := spi^command;
the^context.index := l^start^idx;
the^context.con^string.len := out^string.len;
the^context.con^string.data ':=' out^string.data FOR
out^string.len BYTES;
the^context.len := $offset (context^template.con^string) +
out^string.len + 2;
IF err := ssputtkn (res^buffer, zspi^tkn^context,
the^context) THEN
CALL display^spi^error (err, zspi^val^ssputtkn,
zspi^tkn^context, true);
END;
! Here I have the option to add the work that has been done to
! returned buffer. This depends on the function being performed.
! I will add it here just for illustration purposes.
!
IF err := ssputtkn (res^buffer, zspi^tkn^comment,
out^string) THEN
CALL display^spi^error (err, zspi^val^ssputtkn,
zspi^tkn^comment, true);
3 -> ! Shift string to lowercase
out^string.len := in^string.len;
out^string.data ':=' in^string.data FOR in^string.len BYTES;
CALL shiftstring (out^string.data,
out^string.len,
1 !downshift!); ! Change to lower-case
IF err := ssputtkn (res^buffer, zspi^tkn^comment,
out^string) THEN
CALL display^spi^error (err, zspi^val^ssputtkn,
zspi^tkn^comment, true);
OTHERWISE -> ! (invalid command)
tkn^retcode := zspi^err^notimp;
END; ! End of CASE (spi^command) !
!Put return code token in response buffer
IF err := ssputtkn (res^buffer, zspi^tkn^retcode, tkn^retcode) THEN
CALL display^spi^error (err, zspi^val^ssputtkn,
zspi^tkn^retcode, true);
! Put endlist token for end of response
IF max^resp AND (resp^type <> zspi^val^err^and^warn) THEN
IF err := ssputtkn (res^buffer, zspi^tkn^endlist) THEN
CALL display^spi^error (err, zspi^val^ssputtkn,
zspi^tkn^endlist, true);
END; ! End of process^spi^buffer procedure
?PAGE "PROC process^requests"
!======================================================================!
! Proc : process^requests !
! Function : This procedure will process the requests received !
! on $RECEIVE !
!======================================================================!
Example E-11. TAL File: A Simple SPI Server (page 6 of 10)