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

SPI Programming Examples
SPI Programming Manual427506-006
E-52
Example E-11: A Simple SPI Server in TAL
INT PROC validate^tokens;
BEGIN
STRUCT .l^ssid (zspi^ddl^ssid^def);
! set default token values
! IF any of these have to appear for a command set them to
! null values here & check them in the command^ code
! reset token counts
context^count := 0;
tkn^count := 1;
! get the header tokens- validate that they were retrieved ok
IF err := ssgettkn (req^buffer, zspi^tkn^ssid, l^ssid) THEN
CALL display^spi^error (err, zspi^val^ssgettkn,
zspi^tkn^ssid, true);
! check if the SSID matches mine, but don’t check the version.
IF l^ssid <> my^ssid FOR 5 WORDS THEN
BEGIN
tkn^code := zspi^tkn^ssid;
RETURN (zcom^err^tkn^val^inv);
END;
IF err := ssgettkn (req^buffer, zspi^tkn^maxresp, max^resp) THEN
CALL display^spi^error (err, zspi^val^ssgettkn,
zspi^tkn^maxresp, true);
IF max^resp < -1 THEN
BEGIN
tkn^code := zspi^tkn^maxresp;
RETURN (zcom^err^tkn^val^inv);
END;
! reposition to head of SPI buffer
tkn^value := 0;
IF err := ssputtkn (req^buffer, zspi^tkn^initial^position,
tkn^value) THEN
CALL display^spi^error (err, zspi^val^ssputtkn,
zspi^tkn^initial^position, true);
! walk through the buffer pulling out tokens
WHILE (err := ssgettkn (req^buffer, zspi^tkn^nextcode, tkn^code,,
tkn^count)) = zspi^err^ok
DO
BEGIN
CASE $INT (tkn^code) OF
BEGIN
zspi^tnm^comment ->
! Check the entire token code, just to be sure.
IF tkn^code <> zspi^tkn^comment THEN
RETURN (zcom^err^tkn^code^inv);
IF err := ssgettkn (req^buffer, zspi^tkn^comment, in^string) THEN
CALL display^spi^error (err, zspi^val^ssgettkn,
zspi^tkn^comment, true);
zspi^tnm^context ->
! Check the entire token code, just to be sure.
IF tkn^code <> zspi^tkn^context THEN
RETURN (zcom^err^tkn^code^inv);
Example E-11. TAL File: A Simple SPI Server (page 8 of 10)