hci_pd_send phrase data contns

This writes a phrase onto the line, where:

  • phrase is the name of the phrase to write.
  • data is a keylist that maps the phrase’s field names to values to write.
  • contns is a keylist describing what to do when the write completes.

    contns should minimally provide continuation procedures for ok and error. These continuations are called, respectively, on successful write and some kind of device error processes. The continuations are passed an empty argument keylist.

Timeouts are not supported for write operations. PDC 3 passes a status key to the continuations, and a type key to the error continuation, with a value of device or format.

Example: foo phrase

define phrase foo;
"-->;"; 
field n = variable-array(digit);
";";
field d = variable-array(not(<cr>);
<cr>
end phrase;

In using the foo phrase, you can cause an instance of this phrase to write to the device. The d field is completed with the contents of the message object named message3. The n field completed with the literal string 001 using:

hci_pd_send foo {{d {message message3}}
{n {literal 001}}} \ 
{{ok wrote_fine} {error write_error}}

Typically, the message comes from the value associated with the msg key in the argument to the hci_pd.write procedure.

If the data contents of message3 are Attack at Dawn, then this is written to the device:

-->;001;Attack at Dawn \ r

\ r denotes the ASCII character with code 13 decimal (xod hex).

The typical usage extracts the message name from the arguments to the function.

Example: Using sequential numbers

proc hci_pd.write {msg} { 
global seq_num 
# increment the current sequence number
set seq_num [expr $seq_num + 1] 
# send a packet with the new sequence number
hci_pd_send in_sequence_phrase \
[list [list header [list literal \
[format "%03d" $seq_num]]] \ 
[list data [list message \
[keylget msg message]]]] \ 
{{ok wrote_ok}} } 

The Tcl environment provides the format function.