Library for handling subset of coap functionality by radio transmitter.

Dependencies:   nRF24L01P cantcoap

Dependents:   server2

Revision:
0:6a6f97ca5572
Child:
1:1d936c763440
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/radioWrapper.cpp	Fri Jan 18 14:12:24 2019 +0000
@@ -0,0 +1,41 @@
+#include "radioWrapper.h"
+#include "mbed.h"
+
+int RadioWrapper::read(uin8_t* buffer, int len, int timeout) {
+    Timer t;
+    t.start()
+    // check if buffor is large enough to conaint packet.
+    if (len < TRANSFER_SIZE) {
+        return -1;
+    }
+    int ret = radio.read(NRF24L01P_PIPE_P0, (char*) buffer, packetSize());
+    while(ret == 0 && t.read_ms() < timeout) {    
+        wait_ms(10);
+        ret = radio.read(NRF24L01P_PIPE_P0, (char*) buffer, packetSize());
+    }
+    return ret;
+}
+
+int RadioWrapper::write(uin8_t* buffer, int len) {
+    // check if buffor is small enough to send in one package
+    if (len > TRANSFER_SIZE) {
+        return -1;
+    }
+    int ret = radio.write(NRF24L01P_PIPE_P0, (char*) buffer, packetSize());
+    return ret;
+}
+
+RadioWrapper::RadioWrapper(int channel, unsigned long long rx_address, unsigned long long tx_address) {
+    radio.powerDown();
+    radio.powerUp();
+
+    radio.setAirDataRate(DATA_RATE);
+    radio.setRfOutputPower(POWER);
+    radio.setRfFrequency(NRF24L01P_MIN_RF_FREQUENCY + 4 * channel);
+
+    radio.setCrcWidth(NRF24L01P_CRC_8_BIT);
+
+    radio.setTxAddress(tx_address, 4);
+    radio.setRxAddress(rx_address, 4, NRF24L01P_PIPE_P0);
+    radio.setTransferSize(packetSize(), NRF24L01P_PIPE_P0);
+}