Table of Contents Previous Chapter
The purpose of the collection of command and parameter block format reader classes is to extract bit-packed fields from buffers containing commands or parameter blocks loaded into the instrument. These classes are produced by a code-generator. This section describes the template for these classes.
The details of the command packet and parameter block formats are shown in the "ACIS Instrument Program and Command List," MIT 36-01410 (IP&CL).
All generated command readers are a subclass of Protocols::CmdPkt (see Section TBD). All generated parameter block readers are a subclass of Protocols::Pblock (see Section TBD). The name of a given command packet reader class is the name of the record type, as listed in the IP&CL, with spaces replaced with underscores, and prepended with the name CmdPkt_. The name of a parameter block reader is the same, except it is prepended with the name Pb_.
FIGURE 88. Command and Parameter Block Reader Relationships
Protocols::CmdPkt - This class is a member of the Protocols class category and represents a generic command packet. It provides functions used by its subclasses to determine the total number of 16-bit words in the packet (getPacketLength) and to read a bit-field from within the packet's buffer (getField). This class is described in more detail in Section TBD.
Protocols::Pblock - This class is a member of the Protocols class category and represents a generic parameter block. It provides functions used by its subclasses to determine the total number of 16-bit words within the block (getWordCnt) and to read a bit-field from within the blocks buffer (getField). This class is described in more detail in Section TBD.
CmdPkt_[IPCL_Record_Name] - This represents a generic template for the various types of command packet classes, where "[IPCL_Record_Name]" is the name of the command packet record definition within the IP&CL database (spaces within the record name are replaced with "_" in the class name). Each class definition provides one member function for each field defined within the record (get_[IPCL_Field_Name], get_[IPCL_Indexed_Field_Name]). For fields which are part of an array, this member function takes a single index argument, indicating which element of the array to read. For command packet records which end with a variable length array, the class provides a function which returns the number of elements within the array (get_CountOf_[IPCL_Field_Name]).
Pb_[IPCL_Record_Name] - This represents a generic template for the various types of parameter block classes, where "[IPCL_Record_Name]" is the name of the parameter block record definition within the IP&CL database (spaces within the record name are replaced with "_" in the class name). Each class definition provides one member function for each field defined within the record (get_[IPCL_Field_Name], get_[IPCL_Indexed_Field_Name]). For fields which are part of an array, this member function takes a single index argument, indicating which element of the array to read. For parameter blocks which end with a variable length array, the class provides a function which returns the number of elements within the array (get_CountOf_[IPCL_Field_Name]).
This section lists some of the assumptions made by the command packet and parameter block reader classes.
Two approaches were considered when building the code-generator. One is to have the code-generator produce already customized code, which optimally read fields from the packet's or block's input buffer. The other approach has the code-generator producing standard code which relies on the compiler to optimize of the inline expansions of getField() member function calls. The current design takes the second approach.
The general form for every get_[IPCL_Field_Name] function consists of the following:
unsigned out; out = getField(BITOFFSET, BITWIDTH, BITMASK, index, ARRAYWIDTH); return out; OR return int(out << (16 - BITWIDTH- 1)) >> (16 - BITWIDTH - 1));
Where BITOFFSET is the bit position of the field from the start of the packet or block. If the field is within an array, BITOFFSET is the offset to the field within the first array element. BITWIDTH is the number of bits in the field and must be less than or equal to 32. BITMASK is a right-justified mask of the field (1's correspond to bits in the field). If the field is within an array, index is an argument which selects which array element to access and ARRAYWIDTH is the number of bits within one element of the array. If the field is not within an array, index and ARRAYWIDTH will be zero set to 0 by the code-generator.
The code-generator produces constants for all parameters to getField() except index. Given an appropriately written getField() member function, the compiler's optimizer can very efficient code when it is expanded.
Functions which return the number of elements in a variable length array at the end of a record consists of a converted version of the dimension formula of the field defining the array within the IP&CL. For Command Packets, these formula ususlly consist of the following:
((CmdPkt::getPacketLength() * 16) - ARRAYOFFSET) / ARRAYWIDTH
where ARRAYOFFSET is the bit-offset of the first element of the array from the start of the command packet, and ARRAYWIDTH is the number of bits within each element of the array. The factor of 16 converts the number of words in the packet to the number of bits.
The formula for parameter blocks is similar, except that they call Pblock::getWordCnt() instead of CmdPkt::getPacketLength().
Hierarchy:
Superclasses:
CmdPkt
Public Interface:
Operations:
get_CountOf_[IPCL_Field_Name]() get_[IPCL_Field_Name]() get_[IPCL_Indexed_Field_Name]()
Arguments:
unsigned index
Documentation:
These functions return the value of the named field from within an array of structures. index indicates which structure to select.
Hierarchy:
Superclasses:
Pblock
Public Interface:
Operations:
get_CountOf_[IPCL_Field_Name]() get_[IPCL_Field_Name]() get_[IPCL_Indexed_Field_Name]()
Arguments:
unsigned index
Documentation:
These functions returns the value of the named field from within an array of structures. index indicates which structure to select.