예제 #1
0
/**
* @brief Gets the preprogrammed EUI node address from the module in HEX.
* @param Buffer to read into.
* @param Buffer size.
* @return Returns the number of bytes written or 0 in case of error..
*/
uint8_t RN2483::getHWEUI(uint8_t* buffer, uint8_t size)
{
    _RN2483.printf(STR_CMD_GET_HWEUI);
    _RN2483.printf(CRLF);

    // TODO move to general "read hex" method
    uint8_t inputIndex = 0;
    uint8_t outputIndex = 0;
    Timer t;
    t.start();

    int start = t.read_ms ();
    while (t.read_ms () < start + DEFAULT_TIMEOUT) {
        if (readLn() > 0) {
            while (outputIndex < size
                    && inputIndex + 1 < this->inputBufferSize
                    && this->inputBuffer[inputIndex] != 0
                    && this->inputBuffer[inputIndex + 1] != 0) {
                buffer[outputIndex] = HEX_PAIR_TO_BYTE(
                                          this->inputBuffer[inputIndex],
                                          this->inputBuffer[inputIndex + 1]);
                inputIndex += 2;
                outputIndex++;
            }
            t.stop();
            return outputIndex;
        }
    }
    t.stop();
    return 0;
}
예제 #2
0
/**
* @brief Copies the latest received packet (optionally starting from the "payloadStartPosition" of the payload).
* @param Buffer to read into.
* @param Buffer size.
* @return Returns the number of bytes written or 0 if no packet is received since last transmission.
*/
uint16_t RN2483::receive(uint8_t* buffer, uint16_t size,
                         uint16_t payloadStartPosition)
{

    if (!this->packetReceived) {
        return 0;
    }

    uint16_t inputIndex = payloadStartPosition * 2; // payloadStartPosition is in bytes, not hex char pairs
    uint16_t outputIndex = 0;

    // check that the asked starting position is within bounds
    if (inputIndex >= this->receivedPayloadBufferSize) {
        return 0;
    }

    // stop at the first string termination char, or if output buffer is over, or if payload buffer is over
    while (outputIndex < size
            && inputIndex + 1 < this->receivedPayloadBufferSize
            && this->receivedPayloadBuffer[inputIndex] != 0
            && this->receivedPayloadBuffer[inputIndex + 1] != 0) {
        buffer[outputIndex] = HEX_PAIR_TO_BYTE(
                                  this->receivedPayloadBuffer[inputIndex],
                                  this->receivedPayloadBuffer[inputIndex + 1]);

        inputIndex += 2;
        outputIndex++;
    }

    // Note: if the payload has an odd length, the last char is discarded

    buffer[outputIndex] = 0; // terminate the string

    return outputIndex;
}
예제 #3
0
bool Sodaq_RN2483::getSysParam(const char* paramName, uint8_t* paramValue, uint8_t size)
{
	debugPrint("[getSysParam] ");
    debugPrint(paramName);
	debugPrint("? ");

    this->loraStream->print(STR_SYS_GET);
    this->loraStream->print(paramName);
    this->loraStream->print(CRLF);

    uint16_t len = readLn();
    if (len > 0) {
	    for (uint16_t i = 0; i < len; i+=2) {
			paramValue[i/2] = HEX_PAIR_TO_BYTE(this->inputBuffer[i],this->inputBuffer[i+1]);			
		}
		
		return true;
	}
	debugPrintLn(" ERROR!");
	return false;
	
}
예제 #4
0
// Gets the preprogrammed EUI node address from the module.
// Returns the number of bytes written or 0 in case of error.
uint8_t Sodaq_RN2483::getHWEUI(uint8_t* buffer, uint8_t size)
{
    debugPrintLn("[getHWEUI]");

    this->loraStream->print(STR_CMD_GET_HWEUI);
    this->loraStream->print(CRLF);

    // TODO move to general "read hex" method
    uint8_t inputIndex = 0;
    uint8_t outputIndex = 0;

    unsigned long start = millis();
    while (millis() < start + DEFAULT_TIMEOUT) {
        sodaq_wdt_reset();
        debugPrint(".");

        if (readLn() > 0) {
            debugPrintLn(this->inputBuffer);
            while (outputIndex < size
                && inputIndex + 1 < this->inputBufferSize
                && this->inputBuffer[inputIndex] != 0
                && this->inputBuffer[inputIndex + 1] != 0) {
                buffer[outputIndex] = HEX_PAIR_TO_BYTE(
                    this->inputBuffer[inputIndex],
                    this->inputBuffer[inputIndex + 1]);
                inputIndex += 2;
                outputIndex++;
            }

            debugPrint("[getHWEUI] count: "); debugPrintLn(outputIndex);
            return outputIndex;
        }
    }

    debugPrint("[getHWEUI] Timed out without a response!");
    return 0;
}