Add “meth:convert_seconds method to katcp client classes that converts seconds into the device timestamp format.
Fix memory leak in sample reactor, other minor fixes.
Minor bugfixes and stability improvements
First stable release supporting (a subset of) KATCP v5. No updates apart from documentation since 0.5.0a0; please refer to the 0.5.0a release notes below.
First alpha release supporting (a subset of) KATCP v5. The KATCP v5 spec brings a number of backward incompatible changes, and hence requires care. This library implements support for both KATCP v5 and for the older dialect. Some API changes have also been made, mainly in aid of fool-proof support of the Message ID feature of KATCP v5. The changes do, however, also eliminate a category of potential bugs for older versions of the spec. See also CHANGELOG.
Renamed request() to callback_request() to be more consistent with superclass API.
The function signature used for request handler methods in previous versions of this library were request_requestname(self, sock, msg), where sock is a raw python socket object and msg is a katcp Message object. The sock object was never used directly by the request handler, but was passed to methods on the server to send inform or reply messages.
Before:
class MyServer(DeviceServer):
def request_echo(self, sock, msg):
self.inform(sock, Message.inform('echo', len(msg.arguments)))
return Message.reply('echo', 'ok', *msg.arguments)
The old method requires the name of the request to be repeated several times, inviting error and cluttering code. The user is also required to instantiate katcp Message object each time a reply is made. The new method passes a request-bound connection object that knows to what request it is replying, and that automatically constructs Message objects.
Now:
class MyServer(DeviceServer):
def request_echo(self, req, msg):
req.inform(len(msg.arguments)))
return req.make_reply('ok', *msg.arguments)
A req.reply() method with the same signature as req.make_reply() is also available for asyncronous reply handlers, and req.reply_with_message() which takes a Message instance rather than message arguments. These methods replace the use of DeviceServer.reply().
The request object also contains the katcp request Message object (req.msg), and the equivalent of a socket object (req.client_connection). See the next section for a description of client_connection.
Using the server methods with a req object in place of sock will still work as before, but will log deprecation warnings.
Previously, the server classes internally used each connection’s low-level sock object as an identifier for the connection. In the interest of abstracting out the transport backend, the sock object has been replaced by a ClientConnectionTCP object. This object is passed to all server handler functions (apart from request handlers) instead of the sock object. The connection object be used in the same places where sock was previously used. It also defines inform(), reply_inform() and reply() methods for sending Message objects to a client.
Excerpted from NRF-KAT7-6.0-IFCE-002-Rev5.pdf:
All core messages involving time (i.e. timestamp or period specifications) have changed from using milliseconds to seconds. This provides consistency with SI units. Note also that from version five timestamps should always be specified in UTC time.
Excerpted from NRF-KAT7-6.0-IFCE-002-Rev5.pdf:
Message identifiers were introduced in version 5 of the protocol to allow replies to be uniquely associated with a particular request. If a client sends a request with a message identifier the server must include the same identifier in the reply. Message identifiers are limited to integers in the range 1 to 231 − 1 inclusive. It is the client’s job to construct suitable identifiers – a server should not assume that these are unique. Clients that need to determine whether a server supports message identifiers should examine the #version-connect message returned by the server when the client connects (see Section 4). If no #version-connect message is received the client may assume message identifiers are not supported.
also:
If the request contained a message id each inform that forms part of the response should be marked with the original message id.
Support for message IDs is optional. A properly implemented server should never use mids in replies unless the client request has an mid. Similarly, a client should be able to detect whether a server supports MIDs by checking the #version-connect informs sent by the server, or by doing a !version-list request. Furthermore, a KATCP v5 server should never send #build-state or #version informs.
The DeviceClient client uses the presence of #build-state or #version informs as a heuristic to detect pre-v5 servers, and the presence of #version-connect informs to detect v5+ servers. If mixed messages are received the client gives up auto-detection and disconnects. In this case preset_protocol_flags() can be used to configure the client before calling start().
This release implements the majority of the KATCP v5 spec; excluded parts are: