mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-13 18:30:43 +01:00
Simplify code in radio classes
This commit is contained in:
@@ -128,23 +128,21 @@ void HoymilesRadio_CMT::loop()
|
|||||||
if (_packetReceived) {
|
if (_packetReceived) {
|
||||||
Hoymiles.getMessageOutput()->println("Interrupt received");
|
Hoymiles.getMessageOutput()->println("Interrupt received");
|
||||||
while (_radio->available()) {
|
while (_radio->available()) {
|
||||||
if (!(_rxBuffer.size() > FRAGMENT_BUFFER_SIZE)) {
|
if (_rxBuffer.size() > FRAGMENT_BUFFER_SIZE) {
|
||||||
fragment_t f;
|
|
||||||
memset(f.fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
|
|
||||||
f.len = _radio->getDynamicPayloadSize();
|
|
||||||
f.channel = _radio->getChannel();
|
|
||||||
f.rssi = _radio->getRssiDBm();
|
|
||||||
f.wasReceived = false;
|
|
||||||
f.mainCmd = 0x00;
|
|
||||||
if (f.len > MAX_RF_PAYLOAD_SIZE) {
|
|
||||||
f.len = MAX_RF_PAYLOAD_SIZE;
|
|
||||||
}
|
|
||||||
_radio->read(f.fragment, f.len);
|
|
||||||
_rxBuffer.push(f);
|
|
||||||
} else {
|
|
||||||
Hoymiles.getMessageOutput()->println("CMT: Buffer full");
|
Hoymiles.getMessageOutput()->println("CMT: Buffer full");
|
||||||
_radio->flush_rx();
|
_radio->flush_rx();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fragment_t f;
|
||||||
|
memset(f.fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
|
||||||
|
f.len = std::min<uint8_t>(_radio->getDynamicPayloadSize(), MAX_RF_PAYLOAD_SIZE);
|
||||||
|
f.channel = _radio->getChannel();
|
||||||
|
f.rssi = _radio->getRssiDBm();
|
||||||
|
f.wasReceived = false;
|
||||||
|
f.mainCmd = 0x00;
|
||||||
|
_radio->read(f.fragment, f.len);
|
||||||
|
_rxBuffer.push(f);
|
||||||
}
|
}
|
||||||
_radio->flush_rx();
|
_radio->flush_rx();
|
||||||
_packetReceived = false;
|
_packetReceived = false;
|
||||||
|
|||||||
@@ -50,20 +50,19 @@ void HoymilesRadio_NRF::loop()
|
|||||||
if (_packetReceived) {
|
if (_packetReceived) {
|
||||||
Hoymiles.getMessageOutput()->println("Interrupt received");
|
Hoymiles.getMessageOutput()->println("Interrupt received");
|
||||||
while (_radio->available()) {
|
while (_radio->available()) {
|
||||||
if (!(_rxBuffer.size() > FRAGMENT_BUFFER_SIZE)) {
|
if (_rxBuffer.size() > FRAGMENT_BUFFER_SIZE) {
|
||||||
fragment_t f;
|
|
||||||
memset(f.fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
|
|
||||||
f.len = _radio->getDynamicPayloadSize();
|
|
||||||
f.channel = _radio->getChannel();
|
|
||||||
f.rssi = _radio->testRPD() ? -30 : -80;
|
|
||||||
if (f.len > MAX_RF_PAYLOAD_SIZE)
|
|
||||||
f.len = MAX_RF_PAYLOAD_SIZE;
|
|
||||||
_radio->read(f.fragment, f.len);
|
|
||||||
_rxBuffer.push(f);
|
|
||||||
} else {
|
|
||||||
Hoymiles.getMessageOutput()->println("NRF: Buffer full");
|
Hoymiles.getMessageOutput()->println("NRF: Buffer full");
|
||||||
_radio->flush_rx();
|
_radio->flush_rx();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fragment_t f;
|
||||||
|
memset(f.fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
|
||||||
|
f.len = std::min<uint8_t>(_radio->getDynamicPayloadSize(), MAX_RF_PAYLOAD_SIZE);
|
||||||
|
f.channel = _radio->getChannel();
|
||||||
|
f.rssi = _radio->testRPD() ? -30 : -80;
|
||||||
|
_radio->read(f.fragment, f.len);
|
||||||
|
_rxBuffer.push(f);
|
||||||
}
|
}
|
||||||
_packetReceived = false;
|
_packetReceived = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user