-
-
Notifications
You must be signed in to change notification settings - Fork 652
Add Channel Activity Detection ability. #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e75fd5b
d8a2c0a
98b1259
dcbc9a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <SPI.h> | ||
#include "LoRa.h" | ||
|
||
#ifdef ARDUINO_SAMD_MKRWAN1300 | ||
#error "This example is not compatible with the Arduino MKR WAN 1300 board!" | ||
#endif | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
while (!Serial); | ||
|
||
Serial.println("LoRa Receiver Callback"); | ||
|
||
if (!LoRa.begin(915E6)) { | ||
Serial.println("Starting LoRa failed!"); | ||
while (1); | ||
} | ||
|
||
// register the channel activity dectection callback | ||
LoRa.onCadDone(onCadDone); | ||
// register the receive callback | ||
LoRa.onReceive(onReceive); | ||
// put the radio into CAD mode | ||
LoRa.CAD(); | ||
} | ||
|
||
void loop() { | ||
// do nothing | ||
} | ||
|
||
void onCadDone(boolean signalDetected) { | ||
// detect preamble | ||
if (signalDetected) { | ||
Serial.println("Signal detected"); | ||
// put the radio into continuous receive mode | ||
LoRa.receive(); | ||
} else { | ||
// try next activity dectection | ||
LoRa.CAD(); | ||
} | ||
} | ||
|
||
void onReceive(int packetSize) { | ||
// received a packet | ||
Serial.print("Received packet '"); | ||
|
||
// read packet | ||
for (int i = 0; i < packetSize; i++) { | ||
Serial.print((char)LoRa.read()); | ||
} | ||
|
||
// print RSSI of packet | ||
Serial.print("' with RSSI "); | ||
Serial.println(LoRa.packetRssi()); | ||
|
||
// put the radio into CAD mode | ||
LoRa.CAD(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,9 +57,11 @@ class LoRaClass : public Stream { | |
|
||
#ifndef ARDUINO_SAMD_MKRWAN1300 | ||
void onReceive(void(*callback)(int)); | ||
void onCadDone(void(*callback)(boolean)); | ||
void onTxDone(void(*callback)()); | ||
|
||
void receive(int size = 0); | ||
void CAD(void); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on making this lower case or expanded to something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't it stand for Channel Activity Detection? Additionally, I thought the other day this should be named to make it clear this is CAD DONE, as there is also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about this? these methods are well self-descriptive enough IMHO. channelActivityDetection switch the receiver to CAD mode, onCadDone register a callback function for CADDone interrupts.
|
||
#endif | ||
void idle(); | ||
void sleep(); | ||
|
@@ -118,6 +120,7 @@ class LoRaClass : public Stream { | |
int _packetIndex; | ||
int _implicitHeaderMode; | ||
void (*_onReceive)(int); | ||
void (*_onCadDone)(boolean); | ||
void (*_onTxDone)(); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative name suggestions:
onCollisionActivityDetectComplete
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe CAD in Semtech LoRa is Channel Activity Detection.
There is someone sending the data. and it may be not a collision, right?
In page 44, it says "Once the calculation is finished the modem generates the CadDone interrupt. If the correlation was successful, CadDetected is generated simultaneously."
So the name should be onCadDone or onCadDetected.
My 2 cents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But those interrupts are generated on different pins, if you check Table 18, CadDone is raised on DIO0 & DIO3 and CadDetected is raised on DIO1. They also have different functions. CAD is just the process to see if there is any activity on the channel, CadDone raised when it's done. CadDetect is only fired if activity is detected.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then onCadDone is fine or onChannelActivityDetectionDone (quite long).
As channel activity doesnt imply channel collission.
When there is channel avtivity and we are sending other packets, then there is collission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer onCadDone since it's quite simpler than on24Done. :-)