-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
Add Channel Activity Detection ability. #334
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e75fd5b
Add Channel Activity Detection function and examples.
w-ockham d8a2c0a
Add Channel Activity Detection avility.
w-ockham 98b1259
Merge branch 'master' of https://github.com/w-ockham/arduino-LoRa
w-ockham dcbc9a9
Change method CAD(void) to channelActivityDetection(void).
w-ockham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.channelActivityDetection(); | ||
} | ||
|
||
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.channelActivityDetection(); | ||
} | ||
} | ||
|
||
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.channelActivityDetection(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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. :-)