Library for handling subset of coap functionality by radio transmitter.

Dependencies:   nRF24L01P cantcoap

Dependents:   server2

coapServer.h

Committer:
Ka_myk
Date:
2019-01-20
Revision:
1:1d936c763440
Parent:
0:6a6f97ca5572
Child:
2:c3ca8b8526e0

File content as of revision 1:1d936c763440:

//
// Created by Kamil Mykitiuk on 2019-01-18.
//

#ifndef SLAVE_COAPSERVER_H
#define SLAVE_COAPSERVER_H

#include "cantcoap.h"
#include "radioWrapper.h"
#include <string>

class CoapServer {
public:

    enum ERROR {
        SMALL_BUFFER = -3,
        RADIO_NOT_WORKING = -4,
        UNKNOWN_URI = -5
    };

    enum METHOD {
        GET = 1,
        POST = 2
    };

private:
    uint16_t lastMessageId;
    uint8_t lastMessageToken[4];
    int listeningTimeout;
    RadioWrapper radioWrapper;
    int urisNumber;
    std::string *uris;


public:
    CoapServer(int timeout, std::string* uris, int urisNumber, int channel, unsigned long long rx_address,  unsigned long long tx_address);

    int listen(uint8_t* buffer, int len, METHOD* requestMethod, int* uriNumber);

    int respond(int uri, uint8_t* buffer, int len, CoapPDU::Code responseCode);

    void prepareAckPDU(CoapPDU& coapPDU);


};

#endif //SLAVE_COAPSERVER_H