hci_pd_accept info
This arranges to deliver the specified portions of the input as a message to the system, where info is a Tcl keylist with these keys:
- text is required, and is associated with a list of regions to extract from the input as the data portion of the message.
- end is required, and its value is the amount of input to extract. The end key value is a list of two numbers, with the first being the amount of input to extract.
- code is optional, and is the read completion code to pass to the system along with the data part of the message. 0 usually indicates a successful protocol-level read. If omitted, then the value defaults to 0.
Example
The input buffer contains:
*100*Me...*
-
*
are protocol control characters for this protocol. -
100
andMe...
are data fields matched with this phrase:define phrase record; "*"; field id_num = fixed-array(3,digit); "*"; field name = fixed-array(5,any); "*"; end phrase;
You can then specify this command to accept the input as a valid message and deliver it to the engine:
hci_pd_accept {{text {{1 3} {5 5}}} end 11}
Usually, it is unnecessary and undesirable to code the text regions directly.
If the results of the phrase-match are stored in the variable info
, then specify:
hci_pd_accept "{{text {{[keylget info id_num]}
{[keylget info name]}}}
{end [keylget info end]}}"
This shows the input buffer’s state after receiving two complete messages in the foo phrase form that is given above:
-->;001;Attack at Dawn\r-->;002;Retreat\r
|||||||||||||||||||||||||||||||||||||||
If hci_pd_receive was called with foo as
one of the phrase arguments, then the phrase-match
and its continuation are called with this keylist:
{{status ok} {n {3 3}} {d {7 14}} {end {22 15}}}
The regions have a zero origin. The end
key
describes where the foo
phrase ends, at offset 22.
It also describes how much data is in the input buffer after that (15 characters).
This shows the basic reason for the end
key to hci_pd_accept. Remove
only the portion of the input buffer that corresponds to the message being accepted.
The remaining portion of the input buffer can contain other messages.
In this case, hci_pd_accept is called with:
{{text {{7 14}}} {end 22}}
The first message is extracted from the input buffer and sent to the engine. In this case, the only required operation is to accept the one phrase. The PD module automatically calls again when it sees there is still data in the input buffer after the current READ operation completes.