Skip to content

Commit

Permalink
[SX127x] Fixed copy-pasted code snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Nov 21, 2023
1 parent 4aadd7a commit 81c59f6
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/modules/SX127x/SX127x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,43 +152,32 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {

int16_t modem = getActiveModem();
uint32_t start = 0;
uint32_t timeout = 0;
if(modem == RADIOLIB_SX127X_LORA) {
// calculate timeout (150 % of expected time-on-air)
uint32_t timeout = getTimeOnAir(len) * 1.5;

// start transmission
state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state);

// wait for packet transmission or timeout
start = this->mod->hal->micros();
while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
this->mod->hal->yield();
if(this->mod->hal->micros() - start > timeout) {
finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT);
}
}
timeout = getTimeOnAir(len) * 1.5;

} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
// calculate timeout (5ms + 500 % of expected time-on-air)
uint32_t timeout = 5000 + getTimeOnAir(len) * 5;

// start transmission
state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state);
timeout = 5000 + getTimeOnAir(len) * 5;

// wait for transmission end or timeout
start = this->mod->hal->micros();
while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
this->mod->hal->yield();
if(this->mod->hal->micros() - start > timeout) {
finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT);
}
}
} else {
return(RADIOLIB_ERR_UNKNOWN);

}

// start transmission
state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state);

// wait for packet transmission or timeout
start = this->mod->hal->micros();
while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
this->mod->hal->yield();
if(this->mod->hal->micros() - start > timeout) {
finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT);
}
}

// update data rate
Expand Down

0 comments on commit 81c59f6

Please sign in to comment.