File size: 2,631 Bytes
69c3cbe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | /*
###############################################################################
#
# Temboo CoAP Edge Device library
#
# Copyright (C) 2017, Temboo Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
###############################################################################
*/
#ifndef COAPRRLAYER_H_
#define COAPRRLAYER_H_
#include "CoapMessageLayer.h"
#include "CoapMsg.h"
/**
* CoapRRLayer (Request/Response layer) is a middle layer of the CoAP stack. It is responsible for
* sending requests and receiving responses to those requests. Note that it does not handle
* ACKs or RESETs. Those are handled at the CoapMessageLayer.
*
* This class is intended to implement the CoAP Client Request/Response Layer FSM as described
* by Kovatsch et al. in https://tools.ietf.org/html/draft-kovatsch-lwig-coap-01
*
* Note that this design only implements the client functionality as our application does not
* serve anything.
*/
class CoapRRLayer {
public:
enum Result {
NO_ERROR = 0,
RESPONSE_RECEIVED,
ACK_RECEIVED,
CON_RECEIVED,
ERROR_IMPROPER_STATE,
ERROR_SENDING_MSG,
ERROR_RECEIVING_RESPONSE,
RST_RECEIVED
};
enum State {
STATE_IDLE,
STATE_WAITING
};
CoapRRLayer(CoapMessageLayer& messageLayer, uint8_t* rxBuffer, uint16_t rxBufferLen);
Result reliableSend(CoapMsg& msg, char* token, IPAddress addr, uint16_t port);
Result send(CoapMsg& msg, char* token, IPAddress addr, uint16_t port);
Result loop();
Result getLastResult() {return m_lastResult;}
void setState(State state) {m_state = state;}
int16_t getRxByteCount() {return m_rxByteCount;}
protected:
CoapMessageLayer& m_messageLayer;
State m_state;
Result m_lastResult;
char* m_token;
uint8_t* m_rxBuffer;
int16_t m_rxByteCount;
uint16_t m_rxBufferLen;
bool rxTokenMatches(CoapMsg& msg);
};
#endif
|