TransmitResult internalSend(const uint8_t *buff, const size_t &length, bool requestAck) { Serial.print("Start sending "); Serial.print(length); Serial.println('B'); uint8_t setupRetr = readRegVal(RFM73_REG_SETUP_RETR); uint32_t maxTimeoutUs = (uint32_t)(((setupRetr & 0b11110000) >> 4) + 1) * 250UL * (uint32_t)(setupRetr & 0b00001111); maxTimeoutUs += maxTimeoutUs / 2UL; if (maxTimeoutUs == 0) maxTimeoutUs = 250; CE_HIGH; TransmitResult result; result.status = Success; result.bytesSent = 0; const int maxPacketAttempts = 50; for (size_t i = 0; i < length; i += RFM73_MAX_PACKET_LEN) { int packetAttempts = maxPacketAttempts; while (packetAttempts--) { if (result.status != Success) { Serial.print("Packet send error: "); Serial.print((int)result.status); Serial.print(", retrying ("); Serial.print(maxPacketAttempts - packetAttempts); Serial.print('/'); Serial.print(maxPacketAttempts); Serial.println(")..."); } result += internalSendPacket(buff + i, MIN(length - i, RFM73_MAX_PACKET_LEN), maxTimeoutUs, requestAck); if (result.status == Success) { break; } else if (result.status == FifoFull) { flushTxFIFO(); } _delay_ms(100); } if (result.status != Success) { break; } } CE_LOW; return result; }
/** * boolean send(char*) : function to enqueue a packet for transmission * returns: true, false **/ void RFM70::send(uint8_t* s, uint8_t len) { //switch to tx mode cliTxDs(); setMode(MODE_PTX); if (txTimeout()) { flushTxFIFO(); cliTimeout(); } sendPayload(s, len); //wait for packet to be sent _delay_us(SEND_DELAY); //switch to rx mode cliRxDr(); setMode(MODE_PRX); }
/** * boolean send(char*) : function to enqueue a packet for transmission * returns: true, false **/ void RFM70::send(uint8_t* s, uint8_t len) { // Switch to tx mode pthread_mutex_lock(&g_mutex); cliTxDs(); setMode(MODE_PTX); if (txTimeout()) { flushTxFIFO(); cliTimeout(); } sendPayload(s, len); //wait for packet to be sent usleep(SEND_DELAY); //switch to rx mode cliRxDr(); setMode(MODE_PRX); pthread_mutex_unlock(&g_mutex); }