MCPcopy Create free account
hub / github.com/attermann/microReticulum / loop

Method loop

examples/common/lora_interface/LoRaInterface.cpp:198–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198void LoRaInterface::loop() {
199
200 if (_online) {
201#ifdef ARDUINO
202 // checkIrq() polls the hardware IRQ register — no ISR required
203 if (_radio->checkIrq(RADIOLIB_IRQ_RX_DONE)) {
204 int len = _radio->getPacketLength();
205
206 uint8_t rxBuf[255];
207 int state = _radio->readData(rxBuf, len);
208
209 if (state == RADIOLIB_ERR_NONE && len > 1) {
210 Serial.println("RSSI: " + String(_radio->getRSSI()));
211 Serial.println("Snr: " + String(_radio->getSNR()));
212
213 uint8_t hdr = rxBuf[0];
214 uint8_t seq = packetSequence(hdr);
215
216 if (isSplitPacket(hdr)) {
217 if (_rx_seq == SEQ_UNSET || _rx_seq != seq) {
218 // First part of a split (or restart after a lost first part)
219 _rx_seq = seq;
220 buffer.clear();
221 buffer.append(rxBuf + 1, len - 1);
222 } else {
223 // Second part — sequence matches; assemble and deliver
224 buffer.append(rxBuf + 1, len - 1);
225 _rx_seq = SEQ_UNSET;
226 on_incoming(buffer);
227 }
228 } else {
229 // Non-split: discard any stale partial reassembly, deliver immediately
230 if (_rx_seq != SEQ_UNSET) {
231 buffer.clear();
232 _rx_seq = SEQ_UNSET;
233 }
234 buffer.clear();
235 buffer.append(rxBuf + 1, len - 1);
236 on_incoming(buffer);
237 }
238 } else if (state != RADIOLIB_ERR_NONE) {
239 DEBUGF("LoRaInterface: readData failed, code %d", state);
240 }
241
242 // Re-arm receive mode (required after every packet on SX1262;
243 // harmless on SX1276)
244 _radio->startReceive();
245 }
246#endif
247 }
248}
249
250/*virtual*/ bool LoRaInterface::send_outgoing(const Bytes& data) {
251 DEBUGF("%s.on_outgoing: data: %s", toString().c_str(), data.toHex().c_str());

Callers

nothing calls this directly

Calls 4

packetSequenceFunction · 0.85
isSplitPacketFunction · 0.85
appendMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected