client version of coap
Dependencies: nRF24L01P cantcoap3
Diff: coapClient.h
- Revision:
- 0:6a6f97ca5572
- Child:
- 1:1d936c763440
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/coapClient.h Fri Jan 18 14:12:24 2019 +0000 @@ -0,0 +1,46 @@ +// +// Created by Kamil Mykitiuk on 2019-01-17. +// + +#ifndef COAPCLIENT_H +#define COAPCLIENT_H + + +#include <cstdint> +#include <tic.h> +#include "cantcoap.h" +#include "radioWrapper.h" + +class CoapClient { +public: + enum ERROR { + SERVER_RESPONSE_AMBIGOUS = -1, + SERVER_TIMED_OUT = -2, + SMALL_BUFFER = -3, + RADIO_NOT_WORKING = -4 + }; + +private: + uint8_t token[4]; + uint16_t message_counter; + int retransmissionLimit; + RadioWrapper radioWrapper; + int listeningTimeout; + +public: + CoapClient(uint8_t token[4], int retransmissionLimit, int timeout, RadioWrapper& radio); + + int get(uint8_t buffer[], int len, char* uri); + + int post(uint8_t buffer[], int len, char* uri); + + +private: + uint16_t preparePDU(CoapPDU& coapPDU); + + bool isAck(CoapPDU& coapPDU, uint16_t message_id, char* uri); + + int sendReset(uint16_t message_id); +}; + +#endif //COAPCLIENT_H