Library for handling subset of coap functionality by radio transmitter.

Dependencies:   nRF24L01P cantcoap

Dependents:   server2

Revision:
1:1d936c763440
Parent:
0:6a6f97ca5572
Child:
2:c3ca8b8526e0
--- a/coapServer.cpp	Fri Jan 18 14:12:24 2019 +0000
+++ b/coapServer.cpp	Sun Jan 20 13:48:02 2019 +0000
@@ -26,8 +26,8 @@
                 int requestUriLen = 0;
                 request.getURI(requestUri, 32, &requestUriLen);
                 bool foundMatchingUri = false;
-                for (int i = 0; i < urisNumber(); ++i) {
-                    if(std::strcmp(requestUri, (*(this->uris))[i].data()) == 0) {
+                for (int i = 0; i < urisNumber; ++i) {
+                    if(std::strcmp(requestUri, this->uris[i].data()) == 0) {
                         *uriNumber = i;
                         foundMatchingUri = true;
                     }
@@ -44,18 +44,12 @@
     return 0;
 }
 
-
-
-int CoapServer::urisNumber() {
-    return sizeof(*uris)/ sizeof(std::string);
-}
-
 int CoapServer::respond(int uri, uint8_t* buffer, int len, CoapPDU::Code responseCode) {
     CoapPDU response = CoapPDU();
     prepareAckPDU(response);
     response.setCode(responseCode);
     response.setPayload(buffer, len);
-    response.setURI((char*) uris[uri]->data(), (int)uris[uri]->size());
+    response.setURI((char*) uris[uri].data(), (int)uris[uri].size());
     int ret = radioWrapper.write(response.getPDUPointer(), response.getPDULength());
     if(ret < 0) {
         return RADIO_NOT_WORKING;
@@ -69,3 +63,6 @@
     coapPDU.setMessageID(this->lastMessageId);
     coapPDU.setToken(this->lastMessageToken, 4);
 }
+
+CoapServer::CoapServer(int timeout, std::string* uris, int urisNumber, int channel, unsigned long long rx_address,  unsigned long long tx_address): 
+listeningTimeout(timeout), radioWrapper(channel, rx_address, tx_address), urisNumber(urisNumber), uris(uris) {}
\ No newline at end of file