// Sends the given payload with acknowledgement. // Returns 0 (NoError) when transmission is successful or one of the MacTransmitErrorCodes otherwise. uint8_t Sodaq_RN2483::sendReqAck(uint8_t port, const uint8_t* payload, uint8_t size, uint8_t maxRetries) { debugPrintLn("[sendReqAck]"); if (!setMacParam(STR_RETRIES, maxRetries)) { // not a fatal error -just show a debug message debugPrintLn("[sendReqAck] Non-fatal error: setting number of retries failed."); } return macTransmit(STR_CONFIRMED, port, payload, size); }
/** * @brief Sends the given payload with acknowledgement. * @param Port to use for transmission. * @param Payload buffer * @param Payload buffer size * @param Number of transmission retries in event of network transmission failure. * @return Returns 0 (NoError) when network acks transmission, otherwise returns MacTransmitErrorCode. */ uint8_t RN2483::sendReqAck(uint8_t port, const uint8_t* payload, uint8_t size, uint8_t maxRetries) { // Need to implement retries! mac set retx return macTransmit(STR_CONFIRMED, port, payload, size); }
/** * @brief Sends the given payload without acknowledgement. * @param Port to use for transmission. * @param Payload buffer * @param Payload buffer size * @return Returns 0 (NoError) when data was sucessfully fowarded to radio, otherwise returns MacTransmitErrorCode. */ uint8_t RN2483::send(uint8_t port, const uint8_t* payload, uint8_t size) { return macTransmit(STR_UNCONFIRMED, port, payload, size); }
// Provides a quick test of several methods as a pseudo-unit test. void Sodaq_RN2483::runTestSequence(Stream& stream) { debugPrint("free ram: "); debugPrintLn(freeRam()); init(stream); this->loraStream = &stream; this->diagStream = &stream; // expectString debugPrintLn("write \"testString\" and then CRLF"); if (expectString("testString", 5000)) { debugPrintLn("[expectString] positive case works!"); } debugPrintLn(""); debugPrintLn("write something other than \"testString\" and then CRLF"); if (!expectString("testString", 5000)) { debugPrintLn("[expectString] negative case works!"); } debugPrint("free ram: "); debugPrintLn(freeRam()); // setMacParam(array) debugPrintLn(""); debugPrintLn(""); uint8_t testValue[] = {0x01, 0x02, 0xDE, 0xAD, 0xBE, 0xEF}; setMacParam("testParam ", testValue, ARRAY_SIZE(testValue)); // macTransmit debugPrintLn(""); debugPrintLn(""); uint8_t testValue2[] = {0x01, 0x02, 0xDE, 0xAD, 0xBE, 0xEF}; macTransmit(STR_CONFIRMED, 1, testValue2, ARRAY_SIZE(testValue2)); debugPrint("free ram: "); debugPrintLn(freeRam()); // receive debugPrintLn(""); debugPrintLn("==== receive"); char mockResult[] = "303132333435363738"; memcpy(this->receivedPayloadBuffer, mockResult, strlen(mockResult) + 1); uint8_t payload[64]; debugPrintLn("* without having received packet"); uint8_t length = receive(payload, sizeof(payload)); debugPrintLn(reinterpret_cast<char*>(payload)); debugPrint("Length: "); debugPrintLn(length); debugPrintLn("* having received packet"); this->packetReceived = true; length = receive(payload, sizeof(payload)); debugPrintLn(reinterpret_cast<char*>(payload)); debugPrint("Length: "); debugPrintLn(length); // onMacRX debugPrintLn(""); debugPrintLn("==== onMacRX"); char mockRx[] = "mac_rx 1 303132333435363738"; memcpy(this->inputBuffer, mockRx, strlen(mockRx) + 1); this->packetReceived = false;// reset debugPrint("Input buffer now is: "); debugPrintLn(this->inputBuffer); debugPrint("onMacRX result code: "); debugPrintLn(onMacRX()); uint8_t payload2[64]; if (receive(payload2, sizeof(payload2)) != 9) { debugPrintLn("len is wrong!"); } debugPrintLn(reinterpret_cast<char*>(payload2)); if (receive(payload2, sizeof(payload2), 2) != 7) { debugPrintLn("len is wrong!"); } debugPrintLn(reinterpret_cast<char*>(payload2)); if (receive(payload2, sizeof(payload2), 3) != 6) { debugPrintLn("len is wrong!"); } debugPrintLn(reinterpret_cast<char*>(payload2)); debugPrint("free ram: "); debugPrintLn(freeRam()); // lookup error debugPrintLn(""); debugPrintLn(""); debugPrint("empty string: "); debugPrintLn((lookupMacTransmitError("") == NoResponse) ? "passed" : "wrong"); debugPrint("\"random\": "); debugPrintLn((lookupMacTransmitError("random") == NoResponse) ? "passed" : "wrong"); debugPrint("\"invalid_param\": "); debugPrintLn((lookupMacTransmitError("invalid_param") == InternalError) ? "passed" : "wrong"); debugPrint("\"not_joined\": "); debugPrintLn((lookupMacTransmitError("not_joined") == NotConnected) ? "passed" : "wrong"); debugPrint("\"busy\": "); debugPrintLn((lookupMacTransmitError("busy") == Busy) ? "passed" : "wrong"); debugPrint("\"invalid_param\": "); debugPrintLn((lookupMacTransmitError("invalid_param") == InternalError) ? "passed" : "wrong"); debugPrint("free ram: "); debugPrintLn(freeRam()); }
// Sends the given payload without acknowledgement. // Returns 0 (NoError) when transmission is successful or one of the MacTransmitErrorCodes otherwise. uint8_t Sodaq_RN2483::send(uint8_t port, const uint8_t* payload, uint8_t size) { debugPrintLn("[send]"); return macTransmit(STR_UNCONFIRMED, port, payload, size); }