示例#1
0
def create_block_2_response(data, request):
    """Generate a block 2 response for a specific request.

    Args:
        request (piccata.message.Message): A request received.

    Returns:
        piccata.message.Message: A response generated.
    """
    data_block, more = extract_block(data, request.opt.block2.num,
                                     request.opt.block2.szx)

    if data_block == None:
        raise ValueError("Block 2 request number out of bound.")

    if request.mtype == CON:
        response = Message.AckMessage(request,
                                      code=CONTENT,
                                      payload=data_block)
    else:
        response = Message(mtype=NON,
                           code=CONTENT,
                           payload=data_block,
                           token=request.token)

    response.opt.block2 = (request.opt.block2.num, more,
                           request.opt.block2.szx)
    return response
示例#2
0
    def _handle_trigger_request(self, request):
        response = None
        if request.mtype == piccata.constants.CON:
            response = Message.AckMessage(
                request, constants.CONTENT,
                _make_trigger(self.init_resource.data,
                              self.image_resource.data, False,
                              self.opts.reset_suppress))
        else:
            if self.opts.mcast_dfu:
                address = self.REALM_LOCAL_ADDR
            else:
                address = request.remote.addr

            self.trigger(address, 3)

        return response
示例#3
0
    def receive_request(self, request):
        '''Request callback called by the CoAP toolkit. Note that the function
           signature (name, args) is expected by the CoAP toolkit.'''

        # TODO: remove hardcoded URIs
        handlers = {
            'image':
            self._handle_image_request,
            'init':
            self._handle_init_request,
            'trig':
            lambda request: Message.AckMessage(request, constants.CONTENT, self
                                               .trigger_payload)
        }

        for uri, handler in handlers.items():
            if request.opt.uri_path == _uri_string_to_list(self.uri_prefix +
                                                           '/' + uri):
                response = handler(request)

        return response
示例#4
0
 def _handle_trigger_request(self, request):
     response = Message.AckMessage(
         request, constants.CONTENT,
         _make_trigger(self.init_resource.data, self.image_resource.data,
                       self.opts.mcast_dfu, self.opts.reset_suppress))
     return response